ty-aware delayed AST -> HIR lowering#153489
ty-aware delayed AST -> HIR lowering#153489aerooneqq wants to merge 12 commits intorust-lang:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
|
cc @oli-obk you may be interested in this, because this likely intersects with incremental AST lowering. |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
TY-aware delayed HIR lowering
|
|
||
| #[extension(trait ResolverAstLoweringExt)] | ||
| impl ResolverAstLowering { | ||
| impl ResolverAstLowering<'_> { |
There was a problem hiding this comment.
I went down a slightly different route: c98471e
That gets rid of the extension trait entirely and allows adding custom information that doesn't need to be crate global.
There was a problem hiding this comment.
I've tried to eliminate ResolverAstLoweringExt trait and use splitted (into readonly and mutable part) resolver in hir_crate, unfortunately it led to perf regressions, as before this change we modified maps in-place and after we have to check two maps to find LocalDefId for NodeId. Now I've abstracted resolver through R: ResolverAstLoweringExt where R is a generic type parameter, thanks to this we can steal resolver and modify it in-place during hir_crate and during delayed lowering of delegations we can use splitted resolver, as we can't steal resolver during delayed lowering. Abstraction changes are in #153656, in perfect scenario we would like to have resolver-per-owner, as you tried to do in your PRs, then there will be no need for this abstraction through generic param, however it is out of scope of this PR, as our main goal is to give access to ty-level queries during delegation lowering.
| providers.hir_module_items = map::hir_module_items; | ||
| providers.local_def_id_to_hir_id = |tcx, def_id| match tcx.hir_crate(()).owners[def_id] { | ||
| providers.get_delayed_child_owner = |_, _| MaybeOwner::Phantom; | ||
| providers.local_def_id_to_hir_id = |tcx, def_id| match tcx.hir_crate(()).owner(tcx, def_id) { |
There was a problem hiding this comment.
Just this change adding an owner method seems sth nice to do on main
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (a77c1ae): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 4.3%, secondary 3.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 2.7%, secondary 3.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.0%, secondary 0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 480.442s -> 479.934s (-0.11%) |
…o-hir-arena, r=petrochenkov Replace Box<[TraitCandidate]> with &'hir [TraitCandidate<'hir>] This PR allocates trait candidates on HIR arena and replaces `remove` with `get` in `ResolverAstLowering`. First step for rust-lang#153489. r? @petrochenkov
…, r=petrochenkov Replace Box<[TraitCandidate]> with &'hir [TraitCandidate<'hir>] This PR allocates trait candidates on HIR arena and replaces `remove` with `get` in `ResolverAstLowering`. First step for #153489. r? @petrochenkov
…o-hir-arena, r=petrochenkov Replace Box<[TraitCandidate]> with &'hir [TraitCandidate<'hir>] This PR allocates trait candidates on HIR arena and replaces `remove` with `get` in `ResolverAstLowering`. First step for rust-lang#153489. r? @petrochenkov
Rollup merge of #153494 - aerooneqq:boxed-trait-candidates-to-hir-arena, r=petrochenkov Replace Box<[TraitCandidate]> with &'hir [TraitCandidate<'hir>] This PR allocates trait candidates on HIR arena and replaces `remove` with `get` in `ResolverAstLowering`. First step for #153489. r? @petrochenkov
This comment has been minimized.
This comment has been minimized.
13219bc to
aa935ef
Compare
This comment has been minimized.
This comment has been minimized.
|
@bors try @rust-timer queue |
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.
|
Finished benchmarking commit (60f2f8d): comparison URL. Overall result: ❌ regressions - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 2.1%, secondary 1.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeResults (primary -0.0%, secondary -0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 479.559s -> 482.365s (0.59%) |
This comment has been minimized.
This comment has been minimized.
…, do not update mu part on every lowering
e4d67ca to
065c1d3
Compare
This comment has been minimized.
This comment has been minimized.
065c1d3 to
aae6dda
Compare
aae6dda to
167e829
Compare
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ty-aware delayed AST -> HIR lowering
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (a964ec5): comparison URL. Overall result: ❌✅ regressions and improvements - no action neededBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 0.7%, secondary -0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -3.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 481.08s -> 484.081s (0.62%) |
View all comments
This PR implements a prototype of ty-aware delayed AST -> HIR lowering. Part of #118212.
r? @petrochenkov
Motivation
When lowering delegation in perfect scenario we would like to access the ty-level information, in particular, queries like
generics_of,type_of,fn_sigfor proper HIR generation with less hacks. For example, we do not want to generate more lifetimes than needed, because without ty-level queries we do not know which delegee's lifetimes are late-bound. Next, consider recursive delegations, for their proper support without ty we would have to either duplicate generics inheritance code in AST -> HIR lowering or create stubs for parts of the HIR and materialize them later. We already use those queries when interacting with external crates, however when dealing with compilation of a local crate we should use resolver for similar purposes. Finally, access to ty-level queries is expected to help supporting delegation to inherent impls, as we can not resolve such calls during AST -> HIR stage.Benefits
We eliminate almost all code that uses resolver in delegation lowering:
tcx.fn_sigtcx.fn_sigis_methodfunction now usestcx.associated_iteminstead of resolverget_external_genericsthat usestcx.generics_of. Generics for recursive delegations should also workDelegationIdsthat stored paths for recursive delegations is removed, we now use onlydelegee_idast_indexis no more usedNext steps
High level design overview
Queries
We store ids of delayed items to lower in
Cratestruct. During first stage of lowering, owners that correspond to delayed items are filled withMaybeOwner::Phantom.Next, we define three new queries:
lower_to_hir_delayed,get_delayed_child_ownerandforce_delayed_hir_lowering.The first query is used when lowering known (which is in
delayed_ids) delayed owner.The second is feeded with children that were obtained during lowering of a delayed owner (note that the result of lowering of a single
LocalDefIdis not a singleMaybeOwner, its a list of(LocalDefId, MaybeOwner)where the firstMaybeOwnercorresponds to delayedLocalDefIdand others to children that were obtained during lowering (i.e. generic params)). By defaultget_delayed_child_ownerreturnsMaybeOwner::Phantom. As we do not want to predict the whole list of children which will be obtained after lowering of a single delayed item, we need to store those children somewhere. There are several options:lower_to_hir_delayedto beFxIndexMap<LocalDefId, MaybeOwner>and search children here. Search will be either linear or we can introduce a map somewhere which will track parent-child relations between a single delayedLocalDefIdand its children.LocalDefIdsand their children. In this case there will be problems with delayed items that require information about other delayed items.By using such queries we handle the second concern, and in case of acyclic dependencies between delayed ids it automatically works, moreover we use queries as cache for delayed
MaybeOwners. The only invariant here is that queries which are invoked during delayed HIR lowering of someLocalDefIdshould not in any way access children of other, yet unlowered, delayedLocalDefId, they should firstly materialize it.The third query
force_delayed_hir_loweringforces lowering of all delayed items and now integrated inhir_crate_itemsquery.Resolver for lowering
We split resolver for lowering into two parts: the first part is a readonly part that came to us from resolve, the second part is a mutable part that can be used to add or overwrite values in the readonly part. Such splitted resolver is used during delayed delegation lowering, as we can't steal it.
AST index
Lowering uses an AST index. It is created in
lower_to_hirfunction and it references parts of AST. We want to avoid reindexing AST on every delayedLocalDefIdlowering, however now it is not clear how to properly do it. As delayed HIR lowering is used only for delegation unstable feature it should not affect other use-cases of the compiler. But it will be reworked sooner or later.