1
Fork 0

Auto merge of #108020 - nnethercote:opt-mk_region, r=compiler-errors

Optimize `mk_region`

PR #107869 avoiding some interning under `mk_ty` by special-casing `Ty` variants with simple (integer) bodies. This PR does something similar for regions.

r? `@compiler-errors`
This commit is contained in:
bors 2023-02-16 16:11:54 +00:00
commit c5d1b3ea96
40 changed files with 254 additions and 186 deletions

View file

@ -527,8 +527,7 @@ fn virtual_call_violation_for_method<'tcx>(
}
}
let trait_object_ty =
object_ty_for_trait(tcx, trait_def_id, tcx.mk_region(ty::ReStatic));
let trait_object_ty = object_ty_for_trait(tcx, trait_def_id, tcx.lifetimes.re_static);
// e.g., `Rc<dyn Trait>`
let trait_object_receiver =

View file

@ -767,7 +767,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for BoundVarReplacer<'_, 'tcx> {
let universe = self.universe_for(debruijn);
let p = ty::PlaceholderRegion { universe, name: br.kind };
self.mapped_regions.insert(p, br);
self.infcx.tcx.mk_region(ty::RePlaceholder(p))
self.infcx.tcx.mk_re_placeholder(p)
}
_ => r,
}
@ -888,7 +888,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for PlaceholderReplacer<'_, 'tcx> {
let db = ty::DebruijnIndex::from_usize(
self.universe_indices.len() - index + self.current_index.as_usize() - 1,
);
self.interner().mk_region(ty::ReLateBound(db, *replace_var))
self.interner().mk_re_late_bound(db, *replace_var)
}
None => r1,
}

View file

@ -540,13 +540,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let kind = ty::BoundRegionKind::BrNamed(param.def_id, param.name);
let bound_var = ty::BoundVariableKind::Region(kind);
bound_vars.push(bound_var);
tcx.mk_region(ty::ReLateBound(
tcx.mk_re_late_bound(
ty::INNERMOST,
ty::BoundRegion {
var: ty::BoundVar::from_usize(bound_vars.len() - 1),
kind,
},
))
)
.into()
}
GenericParamDefKind::Const { .. } => {

View file

@ -3023,7 +3023,7 @@ fn bind_generator_hidden_types_above<'tcx>(
kind: ty::BrAnon(counter, None),
};
counter += 1;
r = tcx.mk_region(ty::ReLateBound(current_depth, br));
r = tcx.mk_re_late_bound(current_depth, br);
}
r
})