1
Fork 0

Auto merge of #118968 - aliemjay:canon-static, r=lcnr

unify query canonicalization mode

Exclude from canonicalization only the static lifetimes that appear in the param env because of #118965 . Any other occurrence can be canonicalized safely AFAICT.

r? `@lcnr`
This commit is contained in:
bors 2024-01-09 09:20:33 +00:00
commit be00c5a9b8
8 changed files with 35 additions and 75 deletions

View file

@ -41,7 +41,33 @@ impl<'tcx> InferCtxt<'tcx> {
where
V: TypeFoldable<TyCtxt<'tcx>>,
{
self.canonicalize_query_with_mode(value, query_state, &CanonicalizeAllFreeRegions)
let (param_env, value) = value.into_parts();
let param_env = self.tcx.canonical_param_env_cache.get_or_insert(
self.tcx,
param_env,
query_state,
|tcx, param_env, query_state| {
// FIXME(#118965): We don't canonicalize the static lifetimes that appear in the
// `param_env` beacause they are treated differently by trait selection.
Canonicalizer::canonicalize(
param_env,
None,
tcx,
&CanonicalizeFreeRegionsOtherThanStatic,
query_state,
)
},
);
Canonicalizer::canonicalize_with_base(
param_env,
value,
Some(self),
self.tcx,
&CanonicalizeAllFreeRegions,
query_state,
)
.unchecked_map(|(param_env, value)| param_env.and(value))
}
/// Canonicalizes a query *response* `V`. When we canonicalize a
@ -96,61 +122,6 @@ impl<'tcx> InferCtxt<'tcx> {
&mut query_state,
)
}
/// A variant of `canonicalize_query` that does not
/// canonicalize `'static`. This is useful when
/// the query implementation can perform more efficient
/// handling of `'static` regions (e.g. trait evaluation).
pub fn canonicalize_query_keep_static<V>(
&self,
value: ty::ParamEnvAnd<'tcx, V>,
query_state: &mut OriginalQueryValues<'tcx>,
) -> Canonical<'tcx, ty::ParamEnvAnd<'tcx, V>>
where
V: TypeFoldable<TyCtxt<'tcx>>,
{
self.canonicalize_query_with_mode(
value,
query_state,
&CanonicalizeFreeRegionsOtherThanStatic,
)
}
fn canonicalize_query_with_mode<V>(
&self,
value: ty::ParamEnvAnd<'tcx, V>,
query_state: &mut OriginalQueryValues<'tcx>,
canonicalize_region_mode: &dyn CanonicalizeMode,
) -> Canonical<'tcx, ty::ParamEnvAnd<'tcx, V>>
where
V: TypeFoldable<TyCtxt<'tcx>>,
{
let (param_env, value) = value.into_parts();
let base = self.tcx.canonical_param_env_cache.get_or_insert(
self.tcx,
param_env,
query_state,
|tcx, param_env, query_state| {
Canonicalizer::canonicalize(
param_env,
None,
tcx,
&CanonicalizeFreeRegionsOtherThanStatic,
query_state,
)
},
);
Canonicalizer::canonicalize_with_base(
base,
value,
Some(self),
self.tcx,
canonicalize_region_mode,
query_state,
)
.unchecked_map(|(param_env, value)| param_env.and(value))
}
}
/// Controls how we canonicalize "free regions" that are not inference