Auto merge of #147138 - jackh726:split-canonical-bound, r=lcnr

Split Bound index into Canonical and Bound

See [#t-types/trait-system-refactor > perf `async-closures/post-mono-higher-ranked-hang.rs`](https://rust-lang.zulipchat.com/#narrow/channel/364551-t-types.2Ftrait-system-refactor/topic/perf.20.60async-closures.2Fpost-mono-higher-ranked-hang.2Ers.60/with/541535613) for context

Things compile and tests pass, but not sure if this actually solves the perf issue (edit: it does). Opening up this to do a perf (and maybe crater) run.

r? lcnr
This commit is contained in:
bors
2025-10-02 08:09:33 +00:00
45 changed files with 391 additions and 247 deletions

View File

@@ -830,7 +830,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for EraseEscapingBoundRegions<'tcx> {
}
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
if let ty::ReBound(debruijn, _) = r.kind()
if let ty::ReBound(ty::BoundVarIndexKind::Bound(debruijn), _) = r.kind()
&& debruijn < self.binder
{
r

View File

@@ -145,7 +145,9 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for MaxEscapingBoundVarVisitor {
#[inline]
fn visit_region(&mut self, r: ty::Region<'tcx>) {
match r.kind() {
ty::ReBound(debruijn, _) if debruijn > self.outer_index => {
ty::ReBound(ty::BoundVarIndexKind::Bound(debruijn), _)
if debruijn > self.outer_index =>
{
self.escaping =
self.escaping.max(debruijn.as_usize() - self.outer_index.as_usize());
}