-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Rework dyn trait lowering to stop being so intertwined with trait alias expansion #133830
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
Conversation
HIR ty lowering was modified cc @fmease |
b72f1d9
to
d7c6ee0
Compare
This comment has been minimized.
This comment has been minimized.
d7c6ee0
to
af94314
Compare
compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs
Outdated
Show resolved
Hide resolved
second commit is more than I thought, might take a few days to fully review that one |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Rework dyn trait lowering to stop being so intertwined with trait alias expansion This PR reworks the trait object lowering code to stop handling trait aliases so funky, and removes the `TraitAliasExpander` in favor of a much simpler design. This refactoring is important for making the code that I'm writing in rust-lang#133397 understandable and easy to maintain, so the diagnostics regressions are IMO inevitable. ##### First commit: We used to use Span to maintain a per-principal list of missing associated types. We don't support multiple object principals, and I don't believe we intend to do so anytime soon. Let's remove this to greatly simplify the bookkeeping of this function. ##### Second commit: In the old trait object lowering code, we used to be a bit sloppy with the lists of traits in their unexpanded and expanded forms. This PR largely rewrites this logic to expand the trait aliases *once* and handle them more responsibly throughout afterwards. Please review both of these with whitespace disabled. r? lcnr
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (b020ef4): comparison URL. Overall result: no relevant changes - 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 benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (primary -1.0%)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 (secondary -1.5%)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 sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 767.015s -> 767.953s (0.12%) |
c91411b
to
9ec2929
Compare
This comment has been minimized.
This comment has been minimized.
9ec2929
to
4a38b55
Compare
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.
a few nits and (more than a few) further cleanups, though all of them should hopefully be mechanical.
for (base_trait_ref, original_span) in regular_traits_refs_spans { | ||
let base_pred: ty::Predicate<'tcx> = base_trait_ref.upcast(tcx); | ||
let mut needed_associated_types = FxIndexSet::default(); | ||
if let Some((principal_trait, spans)) = &principal_trait { |
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.
can you move this into a separate fn collect_needed_associated_types
function?
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.
also, the comment further down is incorrect, preexisting, but pls fix
// Here, the user could theoretically write `dyn MyTrait<Output = X>`,
should be
// Here, the user could theoretically write `dyn MyTrait<MyOutput = X>`,
compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs
Outdated
Show resolved
Hide resolved
*span, | ||
crate::errors::UnusedAssociatedTypeBounds { span: *span }, | ||
span, | ||
crate::errors::UnusedAssociatedTypeBounds { span }, | ||
); | ||
} | ||
} | ||
|
||
if let Err(guar) = self.check_for_required_assoc_tys( |
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 feel like this should be part of fn check_for_required_assoc_tys
which should get moved to this file?
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 gonna do this I think.
@@ -254,7 +233,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | |||
.args | |||
.iter() | |||
.enumerate() | |||
.skip(1) // Remove `Self` for `ExistentialPredicate`. | |||
// Skip `Self` | |||
.skip(1) |
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.
can you move the
// Verify that `dummy_self` did not leak inside default type parameters. This
// could not be done at path creation, since we need to see through trait aliases.
part into a sub-fn
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 don't think I will do this.
) | ||
let mut v = principal_trait_ref | ||
.into_iter() | ||
.chain(existential_projections) | ||
.chain(auto_trait_predicates) | ||
.collect::<SmallVec<[_; 8]>>(); | ||
v.sort_by(|a, b| a.skip_binder().stable_cmp(tcx, &b.skip_binder())); |
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.
can you move the // Use explicitly-specified region bound, unless the bound is missing.
part into a sub-fn as well?
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 don't think I will do this.
@rustbot author |
4a38b55
to
824a867
Compare
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (cd805f0): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (primary 5.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.
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: 763.46s -> 764.328s (0.11%) |
This PR reworks the trait object lowering code to stop handling trait aliases so funky, and removes the
TraitAliasExpander
in favor of a much simpler design. This refactoring is important for making the code that I'm writing in #133397 understandable and easy to maintain, so the diagnostics regressions are IMO inevitable.In the old trait object lowering code, we used to be a bit sloppy with the lists of traits in their unexpanded and expanded forms. This PR largely rewrites this logic to expand the trait aliases once and handle them more responsibly throughout afterwards.
Please review this with whitespace disabled.
r? lcnr