1
Fork 0

Auto merge of #118189 - compiler-errors:cache-flags-for-const, r=nnethercote

Cache flags for `ty::Const`

Not sure if this has been attempted yet, but worth a shot. It does make the code simpler in `rustc_type_ir`, since we can assume that consts have a `flags` method that is no-cost.

r? `@ghost`
This commit is contained in:
bors 2023-11-24 04:54:35 +00:00
commit 41fe75ec6b
9 changed files with 92 additions and 43 deletions

View file

@ -160,14 +160,12 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for MaxEscapingBoundVarVisitor {
}
fn visit_const(&mut self, ct: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
match ct.kind() {
ty::ConstKind::Bound(debruijn, _) if debruijn >= self.outer_index => {
self.escaping =
self.escaping.max(debruijn.as_usize() - self.outer_index.as_usize());
ControlFlow::Continue(())
}
_ => ct.super_visit_with(self),
if ct.outer_exclusive_binder() > self.outer_index {
self.escaping = self
.escaping
.max(ct.outer_exclusive_binder().as_usize() - self.outer_index.as_usize());
}
ControlFlow::Continue(())
}
}