-
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
Mark span parent in def_collector. #127241
base: master
Are you sure you want to change the base?
Conversation
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Mark span parent in def_collector. The current device of marking spans with a parent def-id during lowering has been frustrating me for quite some time, as it's very easy to forget marking some spans. This PR moves such marking to the def_collector, which is responsible for creating def-ids on partially expanded AST. This is much more robust as long as visitors are exhaustive. r? ghost
This comment has been minimized.
This comment has been minimized.
95dc7f7
to
585fe45
Compare
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Mark span parent in def_collector. The current device of marking spans with a parent def-id during lowering has been frustrating me for quite some time, as it's very easy to forget marking some spans. This PR moves such marking to the def_collector, which is responsible for creating def-ids on partially expanded AST. This is much more robust as long as visitors are exhaustive. r? ghost
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 (04122fb): comparison URL. Overall result: ❌✅ regressions and improvements - 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. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @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)Results (primary 0.3%, secondary -0.7%)This 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.
CyclesResults (primary 0.6%, secondary 3.2%)This 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 sizeResults (primary -0.2%, secondary -0.2%)This 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.
Bootstrap: 695.108s -> 697.834s (0.39%) |
), | ||
span: p.segments[..proj_start] | ||
.last() | ||
.map_or(path_span_lo, |segment| path_span_lo.to(segment.span())), |
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.
It would appear that half the regression in incr-unchecked comes from Span::to
in this line. The other half comes from using a MutVisitor in DefCollector, which had to be expected.
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.
The other half comes from using a MutVisitor in DefCollector
I tried to address this in #127371, not sure if it will help.
This comment has been minimized.
This comment has been minimized.
@petrochenkov do I need to add something to this PR to handle metavar spans, or is this pass enough? |
9b82411
to
928d08d
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.
compiler/rustc_ast/src/mut_visit.rs
Outdated
GenericBound::Trait(ty, _modifier) => vis.visit_poly_trait_ref(ty), | ||
GenericBound::Trait(ty, modifier) => { | ||
vis.visit_poly_trait_ref(ty); | ||
visit_trait_bound_modifier(modifier, vis); |
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.
Could you visit things in the standard order (e.g. nodes in source code order, spans last, etc)?
@@ -513,6 +513,17 @@ impl MultiSpan { | |||
pub fn clone_ignoring_labels(&self) -> Self { | |||
Self { primary_spans: self.primary_spans.clone(), ..MultiSpan::new() } | |||
} | |||
|
|||
pub fn clone_ignoring_parents(&self) -> Self { |
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.
This commit needs some explanation.
@@ -183,7 +183,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { | |||
|
|||
pub(crate) fn build_reduced_graph( | |||
&mut self, | |||
fragment: &AstFragment, | |||
fragment: &mut AstFragment, |
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 admit I dislike the mutable def collector a lot.
Maybe make a separate small mut visitor for span marking instead of turning def collector mutable?
Def collector has only 12 calls to with_parent
, shouldn't be hard to reproduce.
ExprKind::Index(el, er, brackets_span) => hir::ExprKind::Index( | ||
self.lower_expr(el), | ||
self.lower_expr(er), | ||
self.lower_span(*brackets_span), |
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.
Not sure why new lower_span
s are added here if they are removed in a next commit.
@@ -128,6 +128,10 @@ impl<'a, 'b, 'tcx> DefCollector<'a, 'b, 'tcx> { | |||
} | |||
|
|||
impl<'a, 'b, 'tcx> mut_visit::MutVisitor for DefCollector<'a, 'b, 'tcx> { | |||
fn visit_span(&mut self, span: &mut Span) { | |||
*span = span.with_parent(Some(self.parent_def)); |
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.
As I understand all the old spans here should have no parent, maybe add an assert?
(Can be turned into a debug assert before merging.)
As I understand this change doesn't obsolete the invocation span parent setting logic in |
Def collector also doesn't enable It would generally make sense to parent token spans in macro definitions, but that's sort of an offtopic for this PR. It would also make sense to parent token spans in macro arguments as well (which we don't do due to #127241 (comment), in addition to |
Due to the comments above, I think both key and value spans in the So probably nothing to do right now. |
Once this work is generally ready it's probably better to split it into multiple parts (in any order)
|
Finished benchmarking commit (83cb4f9): comparison URL. Overall result: ❌✅ regressions and improvements - 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. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @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)Results (primary -1.8%, secondary -3.3%)This 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.
CyclesResults (primary 0.1%, secondary -1.2%)This 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 sizeResults (primary -0.1%, secondary -0.1%)This 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.
Bootstrap: 697.439s -> 698.541s (0.16%) |
I wonder if it would be possible to assign span parents even earlier, during parsing. That way we'd automatically "visit" everything including tokens in macros, and also avoided mutating AST (if immutable arena-allocated AST is a goal). We'd keep a current parent id in the parser state and update it when recusing into things like items. Upd: if we do this and remove nonterminals (AST pieces inside tokens), then we'd be able to remove |
I don't see how: that would need to assign a parent even before the parent def-id is created. |
Do not call source_span when not tracking dependencies. Split from rust-lang#127241
…enkov Do not call source_span when not tracking dependencies. Split from rust-lang#127241
…enkov Do not call source_span when not tracking dependencies. Split from rust-lang#127241
…enkov Do not call source_span when not tracking dependencies. Split from rust-lang#127241
…enkov Do not call source_span when not tracking dependencies. Split from rust-lang#127241
…enkov Do not call source_span when not tracking dependencies. Split from rust-lang#127241
…enkov Do not call source_span when not tracking dependencies. Split from rust-lang#127241
Do not call source_span when not tracking dependencies. Split from rust-lang/rust#127241
928d08d
to
9159cc6
Compare
The current device of marking spans with a parent def-id during lowering has been frustrating me for quite some time, as it's very easy to forget marking some spans.
This PR moves such marking to the def_collector, which is responsible for creating def-ids on partially expanded AST. This is much more robust as long as visitors are exhaustive.
r? ghost