Make lowering incremental, take 3/N#142830
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
@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.
|
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (a6b131d): 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 10.5%, secondary 10.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 2.5%, secondary 4.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary -0.1%, secondary -0.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 690.042s -> 689.298s (-0.11%) |
|
@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.
|
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (31325ff): 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 10.8%, secondary 10.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 2.1%, secondary 4.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary -0.1%, secondary -0.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 689.082s -> 688.79s (-0.04%) |
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.
90d6e58 to
2717632
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Some changes occurred in coverage instrumentation. cc @Zalathar These commits modify the If this was unintentional then you should revert the changes before this PR is merged. Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
|
I don't think I will be able to do much better in terms of perf. Meanwhile, it unblocks making progress on more incremental name resolution. r? @petrochenkov |
| #[derive(Debug)] | ||
| pub enum AstOwner { | ||
| NonOwner, | ||
| Synthetic(rustc_span::def_id::LocalDefId), |
There was a problem hiding this comment.
| Synthetic(rustc_span::def_id::LocalDefId), | |
| Synthetic(LocalDefId), |
| #[derive(Debug)] | ||
| pub enum AstOwner { | ||
| NonOwner, | ||
| Synthetic(rustc_span::def_id::LocalDefId), |
There was a problem hiding this comment.
This is used specifically for nested imports, maybe use a more specific name and add an explanation comment?
| query resolver_for_lowering_raw(_: ()) -> (&'tcx Steal<(ty::ResolverAstLowering<'tcx>, Arc<ast::Crate>)>, &'tcx ty::ResolverGlobalCtxt) { | ||
| query resolver_for_lowering_raw(_: ()) -> ( | ||
| &'tcx Steal<ty::ResolverAstLowering<'tcx>>, | ||
| &'tcx Steal<ast::Crate>, |
There was a problem hiding this comment.
It would be useful to add a comment telling why the Steals are used here.
| } | ||
|
|
||
| query index_ast(_: ()) -> &'tcx IndexVec<LocalDefId, Steal<( | ||
| Arc<ty::ResolverAstLowering<'tcx>>, |
There was a problem hiding this comment.
It would be useful to add a comment telling why the Arcs are used here.
| query lower_to_hir(key: LocalDefId) -> hir::MaybeOwner<'tcx> { | ||
| eval_always | ||
| desc { "lowering the delayed AST owner `{}`", tcx.def_path_str(def_id) } | ||
| desc { "lowering HIR for `{}`", tcx.def_path_str(key.to_def_id()) } |
There was a problem hiding this comment.
| desc { "lowering HIR for `{}`", tcx.def_path_str(key.to_def_id()) } | |
| desc { "lowering HIR for `{}`", tcx.def_path_str(def_id) } |
| /// Pre-computed hash of the full HIR. Used in the crate hash. Only present | ||
| /// when incr. comp. is enabled. | ||
| pub opt_hash_including_bodies: Option<Fingerprint>, | ||
| pub opt_hash: Option<Fingerprint>, |
There was a problem hiding this comment.
Does the hash still include bodies?
Is it not valuable to mention it? (Perhaps it can be mentioned in the comment above.)
|
Started reviewing today, starting from the easy parts, will continue on Monday. |
|
☔ The latest upstream changes (presumably #157504) made this pull request unmergeable. Please resolve the merge conflicts. |
| /// Runs all analyses that we guarantee to run, even if errors were reported in earlier analyses. | ||
| /// This function never fails. | ||
| fn run_required_analyses(tcx: TyCtxt<'_>) { | ||
| tcx.ensure_done().early_lint_checks(()); |
There was a problem hiding this comment.
Could you add a comment explaining why it's needed here?
| ident_and_label_to_local_id: Default::default(), | ||
| #[cfg(debug_assertions)] | ||
| node_id_to_local_id: Default::default(), | ||
| node_id_to_local_id: [(owner, hir::ItemLocalId::ZERO)].into_iter().collect(), |
There was a problem hiding this comment.
Note: this looks similar to 3a2ae6a, but in the opposite direction.
| span, | ||
| vis: Visibility { kind: VisibilityKind::Public, span, tokens: None }, | ||
| // Lacking a better choice, we replace the contents with a macro call. | ||
| // Unexpanded macros should never reach lowering, so this is not confusing. |
There was a problem hiding this comment.
Macro expansion uses the same approach (compiler\rustc_expand\src\placeholders.rs), maybe it can even be reused here.
| node: impl FnOnce(Box<Item<K>>) -> AstOwner, | ||
| ) { | ||
| let dummy = self.make_dummy(item.id, item.span, dummy); | ||
| let item = std::mem::replace(item, *dummy); |
There was a problem hiding this comment.
| let item = std::mem::replace(item, *dummy); | |
| let item = mem::replace(item, *dummy); |
Here and in other places (mem is already imported).
| pub type ForeignItem = Item<ForeignItemKind>; | ||
|
|
||
| #[derive(Debug)] | ||
| pub enum AstOwner { |
There was a problem hiding this comment.
If it's only used in AST lowering, then maybe it's better to move it there.
| .map(|kind| { | ||
| let id = id.take().unwrap_or_else(|| { | ||
| let next = self.next_node_id; | ||
| self.next_node_id.increment_by(1); |
There was a problem hiding this comment.
I'm not sure what's going on here.
Does this happen for nested use items?
What the old AST lowerer did in this case?
What are the implications of new node ids being created here?
There was a problem hiding this comment.
Looks like a replacement for the change in compiler/rustc_ast_lowering/src/block.rs.
Deserves a comment in any case.
| } else { | ||
| lowerer.lower_node(def_id); | ||
| let ast_index = tcx.index_ast(()); | ||
| let resolver_and_node = ast_index.get(def_id).map(Steal::steal); |
There was a problem hiding this comment.
In which cases the def_id is not in the map?
| let fallback_to_parent = |parent_id| { | ||
| // The item did not exist in the AST, it was created by its parent. | ||
| let mut parent_info = tcx.lower_to_hir(parent_id); | ||
| if let hir::MaybeOwner::NonOwner(hir_id) = parent_info { |
There was a problem hiding this comment.
I'm again trying to understand in which cases it's possible for the parent to be a non-owner.
Could you add a comment?
| AstOwner::ImplItem(item) => item_lowerer.lower_impl_item(&item), | ||
| AstOwner::ForeignItem(item) => item_lowerer.lower_foreign_item(&item), | ||
| AstOwner::Synthetic(parent_id) => fallback_to_parent(*parent_id), | ||
| AstOwner::NonOwner => fallback_to_parent(tcx.local_parent(def_id)), |
There was a problem hiding this comment.
In which cases AstOwner::NonOwners appear at all? Only during error recovery?
| let attrs = hir::AttributeMap { map: attrs, opt_hash: attrs_hash, define_opaque }; | ||
|
|
||
| self.arena.alloc(hir::OwnerInfo { nodes, parenting, attrs, trait_map, delayed_lints }) | ||
| let opt_hash = if self.tcx.needs_hir_hash() { |
There was a problem hiding this comment.
| let opt_hash = if self.tcx.needs_hir_hash() { | |
| let opt_hash = self.tcx.needs_hir_hash().then(|| ...); |
View all comments
Rebase of #88186 that was rebased by #127262
No real change in design, so I'm not expecting a perf miracle.
r? @ghost