Skip to content

Commit 144227d

Browse files
committed
Auto merge of #99232 - lcnr:no-bound-vars-check, r=jackh726
`replace_bound_vars` fast path: check predicates, don't check consts split out from #98900 `ty::Const` doesn't have precomputed type flags, so computing `has_vars_bound_at_or_above` for constants requires us to visit the const and its contained types and constants. A noop fold should be pretty much equally as fast so removing it prevents us from walking the constant twice in case it contains bound vars. r? `@jackh726`
2 parents 9ed0bf9 + 864d2f3 commit 144227d

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Diff for: compiler/rustc_middle/src/ty/fold.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,13 @@ impl<'a, 'tcx> TypeFolder<'tcx> for BoundVarReplacer<'a, 'tcx> {
445445
let ct = (self.fld_c)(bound_const, ct.ty());
446446
ty::fold::shift_vars(self.tcx, ct, self.current_index.as_u32())
447447
}
448-
_ if ct.has_vars_bound_at_or_above(self.current_index) => ct.super_fold_with(self),
449-
_ => ct,
448+
_ => ct.super_fold_with(self),
450449
}
451450
}
451+
452+
fn fold_predicate(&mut self, p: ty::Predicate<'tcx>) -> ty::Predicate<'tcx> {
453+
if p.has_vars_bound_at_or_above(self.current_index) { p.super_fold_with(self) } else { p }
454+
}
452455
}
453456

454457
impl<'tcx> TyCtxt<'tcx> {

Diff for: compiler/rustc_trait_selection/src/traits/project.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -753,10 +753,13 @@ impl<'tcx> TypeFolder<'tcx> for BoundVarReplacer<'_, 'tcx> {
753753
.tcx
754754
.mk_const(ty::ConstS { kind: ty::ConstKind::Placeholder(p), ty: ct.ty() })
755755
}
756-
_ if ct.has_vars_bound_at_or_above(self.current_index) => ct.super_fold_with(self),
757-
_ => ct,
756+
_ => ct.super_fold_with(self),
758757
}
759758
}
759+
760+
fn fold_predicate(&mut self, p: ty::Predicate<'tcx>) -> ty::Predicate<'tcx> {
761+
if p.has_vars_bound_at_or_above(self.current_index) { p.super_fold_with(self) } else { p }
762+
}
760763
}
761764

762765
// The inverse of `BoundVarReplacer`: replaces placeholders with the bound vars from which they came.

0 commit comments

Comments
 (0)