-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Improve bound const handling #144677
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
base: master
Are you sure you want to change the base?
Improve bound const handling #144677
Conversation
|
changes to the core type system HIR ty lowering was modified cc @fmease |
The third commit in particular is total cargo cult programming, me looking at the type handling code and assuming that doing the same thing for consts is reasonable. Let me know if that's wrong! |
This comment has been minimized.
This comment has been minimized.
8e58035
to
c43a0de
Compare
compiler/rustc_type_ir/src/binder.rs
Outdated
} | ||
|
||
impl<I: Interner> ValidateBoundVars<I> { | ||
pub fn new(bound_vars: I::BoundVarKinds) -> Self { | ||
ValidateBoundVars { | ||
bound_vars, | ||
binder_index: ty::INNERMOST, | ||
visited: SsoHashSet::default(), | ||
visited_tys: SsoHashSet::default(), |
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 cache is only for perf. I think we generally only cache tys as visiting consts has to go through a ty at some point.
We have a bunch of Ty
based caches in folders regardless of whether they treat tys and consts the same
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.
So should I just remove visited_consts
and the || !self.visited_consts.insert((self.binder_index, c))
part of the condition?
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.
yeah, remove the caching in visit_const
r=me after nit |
c43a0de
to
0a606b9
Compare
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Improve bound const handling
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (301f9b5): comparison URL. Overall result: no relevant changes - 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 countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesResults (primary 2.0%)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: 468.729s -> 467.982s (-0.16%) |
compiler/rustc_type_ir/src/binder.rs
Outdated
// A cache for types. We may encounter the same variable at different levels of binding, so | ||
// this can't just be `Ty`. | ||
visited_tys: SsoHashSet<(ty::DebruijnIndex, I::Ty)>, |
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.
hmm, I feel like this comment/name is now more confusing. I think keeping it as visited
is better, but feel free to add a comment for "we only cache types as any complex const will have to step through a type at some point anyways".
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.
done
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.
final nit
Type folders can only modify a few "types of interest": `Binder`, `Ty`, `Predicate`, `Clauses`, `Region`, `Const`. Likewise for type visitors, but they can also visit errors (via `ErrorGuaranteed`). Currently the impls of `try_super_fold_with`, `super_fold_with`, and `super_visit_with` do more than they need to -- they fold/visit values that cannot contain any types of interest. This commit removes those unnecessary fold/visit operations, which makes these impls more similar to the impls for `Ty`. It also removes the now-unnecessary derived impls for the no-longer-visited types.
Currently there is `Ty` and `BoundTy`, and `Region` and `BoundRegion`, and `Const` and... `BoundVar`. An annoying inconsistency. This commit repurposes the existing `BoundConst`, which was barely used, so it's the partner to `Const`. Unlike `BoundTy`/`BoundRegion` it lacks a `kind` field but it's still nice to have because it makes the const code more similar to the ty/region code everywhere. The commit also removes `impl From<BoundVar> for BoundTy`, which has a single use and doesn't seem worth it. These changes fix the "FIXME: We really should have a separate `BoundConst` for consts".
Alongside the existing type and region checking.
0a606b9
to
64be8bb
Compare
@bors r=lcnr |
A few changes to make const handling more similar to type handling.
r? @compiler-errors -errors