-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
rustc: use LocalDefId instead of DefIndex where possible. #66131
Conversation
This comment has been minimized.
This comment has been minimized.
Is enforcing the invariant through type system the end goal here, or this is a part of some larger plan? |
|
I don't remember very well why I started this precisely, but I believe Probably the immediate next step would be to make I should mention that other than the invariant, Speaking of which: @bors try @rust-timer queue |
Awaiting bors try build completion |
rustc: use LocalDefId instead of DefIndex where possible. That is, wherever `DefIndex` always referred to a "def" in the local crate, I replaced it with `LocalDefId`. While `LocalDefId` already existed, it wasn't used a lot, but I hope I'm on the right track. Unresolved questions: * should `LocalDefId` implement `rustc_index::Idx`? * this would get rid of a couple more `DefIndex` uses * should `LocalDefId` be encoded/decoded as just a `DefIndex`? * right now it's a bit messy, `LocalDefId` encodes/decodes like `DefId` * should `DefId::assert_local` be named something else, like `expect_local`? * what do we do with `tcx.hir().local_def_id(...)`? * right now it returns `DefId`, but changing it in this PR would be noisy * ideally it would return `LocalDefId` to spare the caller of `.assert_local()` r? @michaelwoerister cc @nikomatsakis @petrochenkov @Zoxc
☀️ Try build successful - checks-azure |
@rust-timer build 5e1cb0a |
Queued 5e1cb0a with parent 3f0e164, future comparison URL. |
Finished benchmarking try commit 5e1cb0a, comparison URL. |
☔ The latest upstream changes (presumably #66225) made this pull request unmergeable. Please resolve the merge conflicts. |
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.
Very nice! Thanks, @eddyb.
I left a few comments.
Regarding your questions:
should LocalDefId implement rustc_index::Idx?
Yes, I think that would be a good idea.
should LocalDefId be encoded/decoded as just a DefIndex?
In the incr. comp. cache we need to encode in the form of a DefPathHash
for remapping. I'm not sure about crate metadata. Encoding as a DefId might make the code more consistent? How many cases are there where we encode a LocalDefId
in crate metadata?
should DefId::assert_local be named something else, like expect_local?
As mentioned below, I also like expect_local
more than assert_local
.
what do we do with tcx.hir().local_def_id(...)?
Yeah, I'd also like this to return a LocalDefId
. If it's too much for this PR, I'm fine with doing it later (maybe leave a FIXME, just in case).
src/librustc/hir/lowering/item.rs
Outdated
@@ -1272,7 +1272,7 @@ impl LoweringContext<'_> { | |||
AnonymousLifetimeMode::PassThrough, | |||
|this, idty| this.lower_fn_decl( | |||
&sig.decl, | |||
Some((fn_def_id, idty)), | |||
Some((fn_def_id.to_def_id(), idty)), |
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'm starting to wonder if this method should be called to_global_def_id
...
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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@bors r=petrochenkov |
📌 Commit 16e25f0 has been approved by |
☀️ Test successful - checks-azure |
Rustup to rust-lang/rust#66131 changelog: none
Rollup of 4 pull requests Successful merges: - #5326 (rustup rust-lang/rust#69838) - #5333 (rustup rust-lang/rust#69189) - #5336 (rustup rust-lang/rust#69920) - #5341 (Rustup to rust-lang/rust#66131) Failed merges: r? @ghost
Rollup of 4 pull requests Successful merges: - #5326 (rustup rust-lang/rust#69838) - #5333 (rustup rust-lang/rust#69189) - #5336 (rustup rust-lang/rust#69920) - #5341 (Rustup to rust-lang/rust#66131) Failed merges: r? @ghost changelog: none
Rollup of 4 pull requests Successful merges: - #5326 (rustup rust-lang/rust#69838) - #5333 (rustup rust-lang/rust#69189) - #5336 (rustup rust-lang/rust#69920) - #5341 (Rustup to rust-lang/rust#66131) Failed merges: r? @ghost changelog: none
Rollup of 4 pull requests Successful merges: - #5326 (rustup rust-lang/rust#69838) - #5333 (rustup rust-lang/rust#69189) - #5336 (rustup rust-lang/rust#69920) - #5341 (Rustup to rust-lang/rust#66131) Failed merges: r? @ghost changelog: none
Rollup of 4 pull requests Successful merges: - #5326 (rustup rust-lang/rust#69838) - #5333 (rustup rust-lang/rust#69189) - #5336 (rustup rust-lang/rust#69920) - #5341 (Rustup to rust-lang/rust#66131) Failed merges: r? @ghost changelog: none
Fix oudated comment for NamedRegionMap `ResolveLifetimes` uses a `LocalDefId` since rust-lang#66131.
Fix oudated comment for NamedRegionMap `ResolveLifetimes` uses a `LocalDefId` since rust-lang#66131.
Fix oudated comment for NamedRegionMap `ResolveLifetimes` uses a `LocalDefId` since rust-lang#66131.
Fix oudated comment for NamedRegionMap `ResolveLifetimes` uses a `LocalDefId` since rust-lang#66131.
That is, wherever
DefIndex
always referred to a "def" in the local crate, I replaced it withLocalDefId
.While
LocalDefId
already existed, it wasn't used a lot, but I hope I'm on the right track.Unresolved questions:
shouldLocalDefId
implementrustc_index::Idx
?this would get rid of a couple moreDefIndex
usesshouldLocalDefId
be encoded/decoded as just aDefIndex
?right now it's a bit messy,LocalDefId
encodes/decodes likeDefId
shouldDefId::assert_local
be named something else, likeexpect_local
?A future PR should change
tcx.hir().local_def_id(...)
to returnLocalDefId
instead ofDefId
, as changing it in this PR would be too noisy.r? @michaelwoerister cc @nikomatsakis @petrochenkov @Zoxc