Seperate HIR owner from LocalDefId in the type system#85587
Seperate HIR owner from LocalDefId in the type system#85587ABouttefeux wants to merge 8 commits intorust-lang:masterfrom
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.
compiler/rustc_hir/src/hir.rs
Outdated
There was a problem hiding this comment.
I think owner would be a better name now for this field here and elsewhere.
There was a problem hiding this comment.
There is already a struct Owner here
rust/compiler/rustc_middle/src/hir/mod.rs
Lines 34 to 37 in fbf1b1a
There was a problem hiding this comment.
Can you please revert all those formatting changes?
There was a problem hiding this comment.
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. |
cjgillot
left a comment
There was a problem hiding this comment.
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.
| 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.
allocate_hir_id_counter should return a HirOwner you can use here instead of constructing it each time.
| 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 }, |
| use std::fmt; | ||
|
|
||
| #[derive(Copy, Clone, PartialEq, Eq, Debug, PartialOrd, Ord, Hash)] | ||
| pub struct HirOwner { |
There was a problem hiding this comment.
bikeshed: would OwnerId be more consistent?
| 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.
A CRATE_OWNER_ID const could be handy.
| } | ||
| } | ||
|
|
||
| impl rustc_index::vec::Idx for HirOwner { |
There was a problem hiding this comment.
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.
This deserves to be #[inline].
| } | ||
|
|
||
| impl HirOwner { | ||
| pub fn def_id(&self) -> LocalDefId { |
There was a problem hiding this comment.
Is this method useful?
It deserves to be #[inline].
| } | ||
| } | ||
|
|
||
| impl IntoQueryParam<DefId> for HirOwner { |
There was a problem hiding this comment.
Great idea!
An impl IntoQueryParam<LocalDefId> can also help a lot.
| 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.
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.
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