1
Fork 0

reviews + rebase

This commit is contained in:
Boxy 2024-02-08 13:19:20 +00:00
parent b181a12623
commit f867742be8
11 changed files with 101 additions and 114 deletions

View file

@ -1032,7 +1032,6 @@ impl<'tcx> InferCtxt<'tcx> {
_ => {} _ => {}
} }
// FIXME(tree_universes): leaking placeholders
self.enter_forall(predicate, |ty::SubtypePredicate { a_is_expected, a, b }| { self.enter_forall(predicate, |ty::SubtypePredicate { a_is_expected, a, b }| {
Ok(self.at(cause, param_env).sub_exp(DefineOpaqueTypes::No, a_is_expected, a, b)) Ok(self.at(cause, param_env).sub_exp(DefineOpaqueTypes::No, a_is_expected, a, b))
}) })
@ -1043,7 +1042,6 @@ impl<'tcx> InferCtxt<'tcx> {
cause: &traits::ObligationCause<'tcx>, cause: &traits::ObligationCause<'tcx>,
predicate: ty::PolyRegionOutlivesPredicate<'tcx>, predicate: ty::PolyRegionOutlivesPredicate<'tcx>,
) { ) {
// FIXME(tree_universes): leaking placeholders
self.enter_forall(predicate, |ty::OutlivesPredicate(r_a, r_b)| { self.enter_forall(predicate, |ty::OutlivesPredicate(r_a, r_b)| {
let origin = SubregionOrigin::from_obligation_cause(cause, || { let origin = SubregionOrigin::from_obligation_cause(cause, || {
RelateRegionParamBound(cause.span) RelateRegionParamBound(cause.span)

View file

@ -49,7 +49,6 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
debug!("b_prime={:?}", sup_prime); debug!("b_prime={:?}", sup_prime);
// Compare types now that bound regions have been replaced. // Compare types now that bound regions have been replaced.
// FIXME(tree_universes): leaked universes
let result = self.sub(sub_is_expected).relate(sub_prime, sup_prime); let result = self.sub(sub_is_expected).relate(sub_prime, sup_prime);
if result.is_ok() { if result.is_ok() {
debug!("OK result={result:?}"); debug!("OK result={result:?}");
@ -70,7 +69,7 @@ impl<'tcx> InferCtxt<'tcx> {
/// This is the first step of checking subtyping when higher-ranked things are involved. /// This is the first step of checking subtyping when higher-ranked things are involved.
/// For more details visit the relevant sections of the [rustc dev guide]. /// For more details visit the relevant sections of the [rustc dev guide].
/// ///
/// `enter_forall` should be preferred over this method. /// `fn enter_forall` should be preferred over this method.
/// ///
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html
#[instrument(level = "debug", skip(self), ret)] #[instrument(level = "debug", skip(self), ret)]
@ -111,14 +110,14 @@ impl<'tcx> InferCtxt<'tcx> {
} }
/// Replaces all bound variables (lifetimes, types, and constants) bound by /// Replaces all bound variables (lifetimes, types, and constants) bound by
/// `binder` with placeholder variables in a new universe. This means that the /// `binder` with placeholder variables in a new universe and then calls the
/// new placeholders can only be named by inference variables created after /// closure `f` with the instantiated value. The new placeholders can only be
/// this method has been called. /// named by inference variables created inside of the closure `f` or afterwards.
/// ///
/// This is the first step of checking subtyping when higher-ranked things are involved. /// This is the first step of checking subtyping when higher-ranked things are involved.
/// For more details visit the relevant sections of the [rustc dev guide]. /// For more details visit the relevant sections of the [rustc dev guide].
/// ///
/// This method should be preferred over `enter_forall_and_leak_universe`. /// This method should be preferred over `fn enter_forall_and_leak_universe`.
/// ///
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html
#[instrument(level = "debug", skip(self, f))] #[instrument(level = "debug", skip(self, f))]
@ -126,6 +125,10 @@ impl<'tcx> InferCtxt<'tcx> {
where where
T: TypeFoldable<TyCtxt<'tcx>> + Copy, T: TypeFoldable<TyCtxt<'tcx>> + Copy,
{ {
// FIXME: currently we do nothing to prevent placeholders with the new universe being
// used after exiting `f`. For example region subtyping can result in outlives constraints
// that name placeholders created in this function. Nested goals from type relations can
// also contain placeholders created by this function.
let value = self.enter_forall_and_leak_universe(forall); let value = self.enter_forall_and_leak_universe(forall);
debug!("?value"); debug!("?value");
f(value) f(value)

View file

@ -261,15 +261,17 @@ where
Ok(a) Ok(a)
} }
#[instrument(skip(self), level = "debug")] fn enter_forall<T, U>(
fn enter_forall_and_leak_universe<T>(&mut self, binder: ty::Binder<'tcx, T>) -> T &mut self,
binder: ty::Binder<'tcx, T>,
f: impl FnOnce(&mut Self, T) -> U,
) -> U
where where
T: ty::TypeFoldable<TyCtxt<'tcx>> + Copy, T: ty::TypeFoldable<TyCtxt<'tcx>> + Copy,
{ {
if let Some(inner) = binder.no_bound_vars() { let value = if let Some(inner) = binder.no_bound_vars() {
return inner; inner
} } else {
let mut next_region = { let mut next_region = {
let nll_delegate = &mut self.delegate; let nll_delegate = &mut self.delegate;
let mut lazy_universe = None; let mut lazy_universe = None;
@ -303,21 +305,10 @@ where
}, },
}; };
let replaced = self.infcx.tcx.replace_bound_vars_uncached(binder, delegate); self.infcx.tcx.replace_bound_vars_uncached(binder, delegate)
debug!(?replaced); };
replaced debug!(?value);
}
fn enter_forall<T, U>(
&mut self,
binder: ty::Binder<'tcx, T>,
f: impl FnOnce(&mut Self, T) -> U,
) -> U
where
T: ty::TypeFoldable<TyCtxt<'tcx>> + Copy,
{
let value = self.enter_forall_and_leak_universe(binder);
f(self, value) f(self, value)
} }

View file

@ -59,7 +59,9 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait<'tcx>(
ty::Closure(_, args) => Ok(vec![ty::Binder::dummy(args.as_closure().tupled_upvars_ty())]), ty::Closure(_, args) => Ok(vec![ty::Binder::dummy(args.as_closure().tupled_upvars_ty())]),
ty::CoroutineClosure(_, args) => Ok(vec![args.as_coroutine_closure().tupled_upvars_ty()]), ty::CoroutineClosure(_, args) => {
Ok(vec![ty::Binder::dummy(args.as_coroutine_closure().tupled_upvars_ty())])
}
ty::Coroutine(_, args) => { ty::Coroutine(_, args) => {
let coroutine_args = args.as_coroutine(); let coroutine_args = args.as_coroutine();

View file

@ -480,7 +480,6 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
self.infcx.enter_forall(kind, |kind| { self.infcx.enter_forall(kind, |kind| {
let goal = goal.with(self.tcx(), ty::Binder::dummy(kind)); let goal = goal.with(self.tcx(), ty::Binder::dummy(kind));
self.add_goal(GoalSource::Misc, goal); self.add_goal(GoalSource::Misc, goal);
// FIXME(tree_universes): leaking universes
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
}) })
} }

View file

@ -31,7 +31,6 @@ impl<'tcx> InferCtxtSelectExt<'tcx> for InferCtxt<'tcx> {
) -> SelectionResult<'tcx, Selection<'tcx>> { ) -> SelectionResult<'tcx, Selection<'tcx>> {
assert!(self.next_trait_solver()); assert!(self.next_trait_solver());
// FIXME(tree_universes): leaking universes?
self.enter_forall(obligation.predicate, |pred| { self.enter_forall(obligation.predicate, |pred| {
let trait_goal = Goal::new(self.tcx, obligation.param_env, pred); let trait_goal = Goal::new(self.tcx, obligation.param_env, pred);

View file

@ -1060,7 +1060,6 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
constituent_tys(ecx, goal.predicate.self_ty())? constituent_tys(ecx, goal.predicate.self_ty())?
.into_iter() .into_iter()
.map(|ty| { .map(|ty| {
// FIXME(tree_universes): leaking universes
ecx.enter_forall(ty, |ty| { ecx.enter_forall(ty, |ty| {
goal.with(ecx.tcx(), goal.predicate.with_self_ty(ecx.tcx(), ty)) goal.with(ecx.tcx(), goal.predicate.with_self_ty(ecx.tcx(), ty))
}) })

View file

@ -4621,7 +4621,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
let ocx = ObligationCtxt::new(self); let ocx = ObligationCtxt::new(self);
self.enter_forall(pred, |pred| { self.enter_forall(pred, |pred| {
let pred = ocx.normalize(&ObligationCause::dummy(), param_env, pred); let pred = ocx.normalize(&ObligationCause::dummy(), param_env, pred);
// FIXME(tree_universes): universe leakage
ocx.register_obligation(Obligation::new( ocx.register_obligation(Obligation::new(
self.tcx, self.tcx,
ObligationCause::dummy(), ObligationCause::dummy(),

View file

@ -2049,7 +2049,6 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
for (obligation_arg, impl_arg) in for (obligation_arg, impl_arg) in
std::iter::zip(obligation_trait_ref.args, impl_trait_ref.args) std::iter::zip(obligation_trait_ref.args, impl_trait_ref.args)
{ {
// FIXME(tree_universes): universe leakage
if let Err(terr) = if let Err(terr) =
ocx.eq(&ObligationCause::dummy(), param_env, impl_arg, obligation_arg) ocx.eq(&ObligationCause::dummy(), param_env, impl_arg, obligation_arg)
{ {

View file

@ -728,9 +728,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
self.infcx.probe(|_snapshot| { self.infcx.probe(|_snapshot| {
let poly_trait_predicate = self.infcx.resolve_vars_if_possible(obligation.predicate); let poly_trait_predicate = self.infcx.resolve_vars_if_possible(obligation.predicate);
let placeholder_trait_predicate = self.infcx.enter_forall(poly_trait_predicate, |placeholder_trait_predicate| {
self.infcx.enter_forall_and_leak_universe(poly_trait_predicate);
let self_ty = placeholder_trait_predicate.self_ty(); let self_ty = placeholder_trait_predicate.self_ty();
let principal_trait_ref = match self_ty.kind() { let principal_trait_ref = match self_ty.kind() {
ty::Dynamic(data, ..) => { ty::Dynamic(data, ..) => {
@ -787,6 +785,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
candidates.vec.extend(candidate_supertraits); candidates.vec.extend(candidate_supertraits);
}) })
})
} }
/// Temporary migration for #89190 /// Temporary migration for #89190

View file

@ -163,8 +163,7 @@ pub enum RegionKind<I: Interner> {
/// A placeholder region -- the higher-ranked version of `ReLateParam`. /// A placeholder region -- the higher-ranked version of `ReLateParam`.
/// Should not exist outside of type inference. /// Should not exist outside of type inference.
/// ///
/// Used when instantiating a `forall` binder via /// Used when instantiating a `forall` binder via `infcx.enter_forall`.
/// `infcx.enter_forall` and `infcx.enter_forall_and_leak_universe`.
RePlaceholder(I::PlaceholderRegion), RePlaceholder(I::PlaceholderRegion),
/// Erased region, used by trait selection, in MIR and during codegen. /// Erased region, used by trait selection, in MIR and during codegen.