-
Notifications
You must be signed in to change notification settings - Fork 13k
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
resolve: Feed the def_kind
query immediately on DefId
creation
#118188
Conversation
r? @TaKO8Ki (rustbot has picked a reviewer for you, use r? to override) |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
[WIP] resolve: Feed the `opt_def_kind` query immediately on `DefId` creation ... for most `DefId`s. Right now the def kind query requires building HIR for no good reason, in this PR I'm trying to change that. In two cases the `DefKind` is not known early enough. - Choosing between `DefKind::Closure` and `DefKind::Coroutine` requires analyzing (expanded) closure body, which cannot be done in def collector. I think `DefKind::Coroutine` should be merged into `DefKind::Closure`, it's more useful to have all `DefKind`s early in resolver (perhaps even merge them with `DefPathData`s) than to make this specific distinction. - `opt_def_kind` should report `None` instead of `Some(DefKind::AnonConst)` for some specific subset of anonymous constants not know in def collector, otherwise code in other parts of the compiler panics. I'll try to get rid of this oddity in a separate PR. Submitting this in a WIP state for preliminary benchmarking.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (9c24e80): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 675.709s -> 674.594s (-0.17%) |
rustc: Make `def_kind` mandatory for all `DefId`s Prerequisite for rust-lang#118188.
And move declarative macro compilation to an earlier point in def collector, which is required for rust-lang#118188.
resolve: Avoid clones of `MacroData` And move declarative macro compilation to an earlier point in def collector, which is required for rust-lang#118188.
resolve: Avoid clones of `MacroData` And move declarative macro compilation to an earlier point in def collector, which is required for rust-lang#118188.
resolve: Avoid clones of `MacroData` And move declarative macro compilation to an earlier point in def collector, which is required for rust-lang#118188.
Rollup merge of rust-lang#118272 - petrochenkov:macrodata, r=cjgillot resolve: Avoid clones of `MacroData` And move declarative macro compilation to an earlier point in def collector, which is required for rust-lang#118188.
…errors rustc: Make `def_kind` mandatory for all `DefId`s Prerequisite for rust-lang#118188.
rustc: `hir().local_def_id_to_hir_id()` -> `tcx.local_def_id_to_hir_id()` cleanup Noticed this while working on rust-lang#118188. The history here is that the method was moved from HIR map to tcx in rust-lang#93373 as a part of incremental compilation work, so it's unlikely to go back.
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.
r=me with a nit
|
||
// FIXME: The namespace is incorrect for foreign types. |
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.
Please fix it as a drive-by.
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.
Fixed in the second commit.
@bors r=cjgillot |
☀️ Test successful - checks-actions |
Finished benchmarking commit (5facb42): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 672.731s -> 673.885s (0.17%) |
…e_3, r=<try> revert for benchmark This PR reverts rust-lang#118311 and rust-lang#118188, with the intent to assess the performance impact brought about by rust-lang#118311
@@ -171,6 +172,9 @@ impl<'tcx> Queries<'tcx> { | |||
))); | |||
feed.crate_for_resolver(tcx.arena.alloc(Steal::new((krate, pre_configured_attrs)))); | |||
feed.output_filenames(Arc::new(outputs)); | |||
|
|||
let feed = tcx.feed_local_def_id(CRATE_DEF_ID); | |||
feed.def_kind(DefKind::Mod); |
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 have a question regarding incremental builds: when referring to queries such as the results of tcx.def_kind(LocalDefId)
or tcx.def_kind(DefId)
, does this mean the results are retrieved directly here?
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.
Here the result is put directly into the query cache.
So when tcx.def_kind(def_id)
is called it will look into the query cache first, and will always find the result there, and will never call the query implementation (which now would panic because providers.def_kind
is not set).
rustc: Make `def_kind` mandatory for all `DefId`s Prerequisite for rust-lang/rust#118188.
rustc: Harmonize `DefKind` and `DefPathData` Follow up to rust-lang#118188. `DefPathData::(ClosureExpr,ImplTrait)` are renamed to match `DefKind::(Closure,OpaqueTy)`. `DefPathData::ImplTraitAssocTy` is replaced with `DefPathData::TypeNS(kw::Empty)` because both correspond to `DefKind::AssocTy`. It's possible that introducing `(DefKind,DefPathData)::AssocOpaqueTy` instead could be a better solution, but that would be a much more invasive change. Const generic parameters introduced for effects are moved from `DefPathData::TypeNS` to `DefPathData::ValueNS`, because constants are values. `DefPathData` is no longer passed to `create_def` functions to avoid redundancy.
Rollup merge of rust-lang#118573 - petrochenkov:pathdatakind, r=TaKO8Ki rustc: Harmonize `DefKind` and `DefPathData` Follow up to rust-lang#118188. `DefPathData::(ClosureExpr,ImplTrait)` are renamed to match `DefKind::(Closure,OpaqueTy)`. `DefPathData::ImplTraitAssocTy` is replaced with `DefPathData::TypeNS(kw::Empty)` because both correspond to `DefKind::AssocTy`. It's possible that introducing `(DefKind,DefPathData)::AssocOpaqueTy` instead could be a better solution, but that would be a much more invasive change. Const generic parameters introduced for effects are moved from `DefPathData::TypeNS` to `DefPathData::ValueNS`, because constants are values. `DefPathData` is no longer passed to `create_def` functions to avoid redundancy.
[WIP] resolve: Use def_kind query to cleanup some code Follow up to rust-lang#118188. Similar attempts to use queries in resolver resulted in perf regressions in the past, so this needs a perf run first.
rustc: Harmonize `DefKind` and `DefPathData` Follow up to rust-lang/rust#118188. `DefPathData::(ClosureExpr,ImplTrait)` are renamed to match `DefKind::(Closure,OpaqueTy)`. `DefPathData::ImplTraitAssocTy` is replaced with `DefPathData::TypeNS(kw::Empty)` because both correspond to `DefKind::AssocTy`. It's possible that introducing `(DefKind,DefPathData)::AssocOpaqueTy` instead could be a better solution, but that would be a much more invasive change. Const generic parameters introduced for effects are moved from `DefPathData::TypeNS` to `DefPathData::ValueNS`, because constants are values. `DefPathData` is no longer passed to `create_def` functions to avoid redundancy.
…rrors resolve: Use `def_kind` query to cleanup some code Follow up to rust-lang#118188. Similar attempts to use queries in resolver resulted in perf regressions in the past, so this needs a perf run first.
Rollup merge of rust-lang#118620 - petrochenkov:defeed2, r=compiler-errors resolve: Use `def_kind` query to cleanup some code Follow up to rust-lang#118188. Similar attempts to use queries in resolver resulted in perf regressions in the past, so this needs a perf run first.
Before this PR the def kind query required building HIR for no good reason, with this PR def kinds are instead assigned immediately when
DefId
s are created.Some PRs previously refactored things to make all def kinds to be available early enough - #118250, #118272, #118311.