-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Seperate HIR owner from LocalDefId in the type system #85587
Conversation
r? @jackh726 (rust-highfive has picked a reviewer for you, use r? to override) |
r? @cjgillot |
a931dd9
to
bfca4e9
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
d7ce673
to
79f4394
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
513d3b8
to
7622b46
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
9e11425
to
33e3db1
Compare
This comment has been minimized.
This comment has been minimized.
@@ -2890,7 +2890,7 @@ pub struct ForeignItemRef<'hir> { | |||
pub struct ForeignItem<'hir> { | |||
pub ident: Ident, | |||
pub kind: ForeignItemKind<'hir>, | |||
pub def_id: LocalDefId, | |||
pub def_id: HirOwner, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think owner
would be a better name now for this field here and elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already a struct Owner here
rust/compiler/rustc_middle/src/hir/mod.rs
Lines 34 to 37 in fbf1b1a
#[derive(Debug)] | |
pub struct Owner<'tcx> { | |
node: Node<'tcx>, | |
} |
@@ -189,7 +194,7 @@ impl<'tcx> Visitor<'tcx> for ReturnBreakContinueMacroVisitor { | |||
} else { | |||
rustc_hir::intravisit::walk_expr(self, ex); | |||
} | |||
}, | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please revert all those formatting changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't notice I am reverting it.
This comment has been minimized.
This comment has been minimized.
cf4d985
to
70920c6
Compare
☔ The latest upstream changes (presumably #85266) made this pull request unmergeable. Please resolve the merge conflicts. |
@ABouttefeux Ping from triage. There's merge conflict now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR @ABouttefeux and sorry for the delay!
Overall, this is going in the right direction.
There is still a lot of back-and-forth between HirOwner and LocalDefId. I left a few comment to reduce the conversion glue.
@@ -1512,18 +1514,26 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { | |||
}; | |||
|
|||
trace!("lower_opaque_impl_trait: {:#?}", opaque_ty_def_id); | |||
lctx.generate_opaque_type(opaque_ty_def_id, opaque_ty_item, span, opaque_ty_span); | |||
lctx.generate_opaque_type( | |||
HirOwner { def_id: opaque_ty_def_id }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allocate_hir_id_counter
should return a HirOwner you can use here instead of constructing it each time.
@@ -2015,7 +2025,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { | |||
}; | |||
|
|||
trace!("exist ty from async fn def id: {:#?}", opaque_ty_def_id); | |||
this.generate_opaque_type(opaque_ty_def_id, opaque_ty_item, span, opaque_ty_span); | |||
this.generate_opaque_type( | |||
HirOwner { def_id: opaque_ty_def_id }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise
use std::fmt; | ||
|
||
#[derive(Copy, Clone, PartialEq, Eq, Debug, PartialOrd, Ord, Hash)] | ||
pub struct HirOwner { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bikeshed: would OwnerId be more consistent?
@@ -322,7 +322,7 @@ pub fn lower_crate<'a, 'hir>( | |||
anonymous_lifetime_mode: AnonymousLifetimeMode::PassThrough, | |||
type_def_lifetime_params: Default::default(), | |||
current_module: CRATE_DEF_ID, | |||
current_hir_id_owner: (CRATE_DEF_ID, 0), | |||
current_hir_id_owner: (HirOwner { def_id: CRATE_DEF_ID }, 0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A CRATE_OWNER_ID const could be handy.
} | ||
} | ||
|
||
impl rustc_index::vec::Idx for HirOwner { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HirOwner shoud not implement Idx, since not all HirOwner values are semantically valid.
self.def_id | ||
} | ||
|
||
pub fn to_def_id(&self) -> DefId { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This deserves to be #[inline]
.
} | ||
|
||
impl HirOwner { | ||
pub fn def_id(&self) -> LocalDefId { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this method useful?
It deserves to be #[inline]
.
@@ -308,6 +308,13 @@ mod sealed { | |||
self.to_def_id() | |||
} | |||
} | |||
|
|||
impl IntoQueryParam<DefId> for HirOwner { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea!
An impl IntoQueryParam<LocalDefId>
can also help a lot.
@@ -698,7 +698,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { | |||
{ | |||
let opt_suggestions = path_segment | |||
.hir_id | |||
.map(|path_hir_id| self.infcx.tcx.typeck(path_hir_id.owner)) | |||
.map(|path_hir_id| self.infcx.tcx.typeck(path_hir_id.owner.def_id)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can typeck
take a HirOwner?
@@ -804,7 +804,7 @@ fn for_each_late_bound_region_defined_on<'tcx>( | |||
) { | |||
if let Some((owner, late_bounds)) = tcx.is_late_bound_map(fn_def_id.expect_local()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this owner
be a HirOwner
directly?
Sorry, currently I am hospitalized and I am not able to work in this PR. |
@ABouttefeux Hope you feel better soon! |
@ABouttefeux Ping from triage! Any updates on this? |
I am still in the hospital and unable to work on it. It may take a while before I am able to work on it. |
Ping from triage: @ABouttefeux closing this as inactive. Please feel free to reopen when you are ready to continue. |
closes #83158
Separate definitions and HIR owners in the type system