Auto merge of #124203 - lukas-code:delete-deleting-caches, r=compiler-errors
Some checks failed
CI / auto - ${{ matrix.name }} (map[], mingw-check, ubuntu-20.04-4core-16gb) (push) Waiting to run
CI / bors build finished (push) Blocked by required conditions
CI / try - ${{ matrix.name }} (map[CODEGEN_BACKENDS:llvm,cranelift], dist-x86_64-linux, ubuntu-20.04-16core-64gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], x86_64-gnu-nopt, ubuntu-20.04-4core-16gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], x86_64-gnu-distcheck, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], x86_64-gnu-debug, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], x86_64-gnu-aux, ubuntu-20.04-4core-16gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], x86_64-gnu, ubuntu-20.04-4core-16gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], test-various, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], i686-gnu-nopt, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], i686-gnu, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], dist-x86_64-netbsd, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], dist-x86_64-illumos, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], dist-x86_64-freebsd, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], dist-various-2, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], dist-various-1, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], dist-s390x-linux, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], dist-riscv64-linux, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], dist-powerpc64le-linux, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], dist-powerpc64-linux, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], dist-powerpc-linux, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], dist-ohos, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], dist-loongarch64-linux, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], dist-i686-linux, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], dist-i586-gnu-i586-i686-musl, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], dist-armv7-linux, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], dist-armhf-linux, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], dist-arm-linux, ubuntu-20.04-16core-64gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], dist-android, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], armhf-gnu, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[], arm-android, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[RUST_CONFIGURE_ARGS:--build=x86_64-pc-windows-msvc --enable-profiler SCRIPT:make ci-msvc], x86_64-msvc, windows-2019-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[RUST_CONFIGURE_ARGS:--build=x86_64-pc-windows-msvc --enable-extended --enable-profiler SCRIPT:python x.py dist bootstrap --include-default-paths], dist-x86_64-msvc-alt, windows-2019-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[RUST_CONFIGURE_ARGS:--build=i686-pc-windows-msvc SCRIPT:make ci-msvc], i686-msvc, windows-2019-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[RUST_BACKTRACE:1], x86_64-gnu-llvm-18, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[RUST_BACKTRACE:1], x86_64-gnu-llvm-17, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[MACOSX_DEPLOYMENT_TARGET:11 MACOSX_STD_DEPLOYMENT_TARGET:11 NO_DEBUG_ASSERTIONS:1 NO_LLVM_ASSERTIONS:1 NO_OVERFLOW_CHECKS:1 RUSTC_RETRY_LINKER_ON_SEGFAULT:1 RUST_CONFIGURE_ARGS:--enable-sanitizers --enable-profiler --set … (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[MACOSX_DEPLOYMENT_TARGET:10.12 NO_DEBUG_ASSERTIONS:1 NO_LLVM_ASSERTIONS:1 NO_OVERFLOW_CHECKS:1 RUSTC_RETRY_LINKER_ON_SEGFAULT:1 RUST_CONFIGURE_ARGS:--enable-sanitizers --enable-profiler --set rust.jemalloc SCRIPT:./x.py d… (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[MACOSX_DEPLOYMENT_TARGET:10.12 MACOSX_STD_DEPLOYMENT_TARGET:10.12 NO_DEBUG_ASSERTIONS:1 NO_LLVM_ASSERTIONS:1 NO_OVERFLOW_CHECKS:1 RUSTC_RETRY_LINKER_ON_SEGFAULT:1 RUST_CONFIGURE_ARGS:--build=x86_64-apple-darwin --enable-s… (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[DIST_REQUIRE_ALL_TOOLS:1 RUST_CONFIGURE_ARGS:--build=x86_64-pc-windows-msvc --host=x86_64-pc-windows-msvc --target=x86_64-pc-windows-msvc --enable-full-tools --enable-profiler --set rust.codegen-units=1 SCRIPT:python x.py… (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[DIST_REQUIRE_ALL_TOOLS:1 RUST_CONFIGURE_ARGS:--build=x86_64-pc-windows-msvc --host=aarch64-pc-windows-msvc --enable-full-tools --enable-profiler SCRIPT:python x.py dist bootstrap --include-default-paths], dist-aarch64-msv… (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[DIST_REQUIRE_ALL_TOOLS:1 RUST_CONFIGURE_ARGS:--build=i686-pc-windows-msvc --host=i686-pc-windows-msvc --target=i686-pc-windows-msvc,i586-pc-windows-msvc --enable-full-tools --enable-profiler SCRIPT:python x.py dist bootst… (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[DIST_REQUIRE_ALL_TOOLS:1 MACOSX_DEPLOYMENT_TARGET:11 MACOSX_STD_DEPLOYMENT_TARGET:11 NO_DEBUG_ASSERTIONS:1 NO_LLVM_ASSERTIONS:1 NO_OVERFLOW_CHECKS:1 RUSTC_RETRY_LINKER_ON_SEGFAULT:1 RUST_CONFIGURE_ARGS:--enable-full-tools… (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[DEPLOY_TOOLSTATES_JSON:toolstates-windows.json HOST_TARGET:x86_64-pc-windows-msvc RUST_CONFIGURE_ARGS:--build=x86_64-pc-windows-msvc --enable-lld --save-toolstates=/tmp/toolstate/toolstates.json SCRIPT:python x.py --stage… (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[DEPLOY_TOOLSTATES_JSON:toolstates-linux.json], x86_64-gnu-tools, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[CUSTOM_MINGW:1 NO_DOWNLOAD_CI_LLVM:1 RUST_CONFIGURE_ARGS:--build=x86_64-pc-windows-gnu --enable-profiler SCRIPT:make ci-mingw], x86_64-mingw, windows-2019-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[CUSTOM_MINGW:1 NO_DOWNLOAD_CI_LLVM:1 RUST_CONFIGURE_ARGS:--build=i686-pc-windows-gnu SCRIPT:make ci-mingw], i686-mingw, windows-2019-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[CUSTOM_MINGW:1 DIST_REQUIRE_ALL_TOOLS:1 NO_DOWNLOAD_CI_LLVM:1 RUST_CONFIGURE_ARGS:--build=x86_64-pc-windows-gnu --enable-full-tools --enable-profiler SCRIPT:python x.py dist bootstrap --include-default-paths], dist-x86_64… (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[CUSTOM_MINGW:1 DIST_REQUIRE_ALL_TOOLS:1 NO_DOWNLOAD_CI_LLVM:1 RUST_CONFIGURE_ARGS:--build=i686-pc-windows-gnu --enable-full-tools --enable-profiler SCRIPT:python x.py dist bootstrap --include-default-paths], dist-i686-min… (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[CODEGEN_BACKENDS:llvm,cranelift], dist-x86_64-musl, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[CODEGEN_BACKENDS:llvm,cranelift], dist-x86_64-linux, ubuntu-20.04-16core-64gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[CODEGEN_BACKENDS:llvm,cranelift], dist-aarch64-linux, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[CODEGEN_BACKENDS:llvm,cranelift IMAGE:dist-x86_64-linux], dist-x86_64-linux-alt, ubuntu-20.04-16core-64gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[CODEGEN_BACKENDS:llvm,cranelift DIST_REQUIRE_ALL_TOOLS:1 MACOSX_DEPLOYMENT_TARGET:10.12 NO_DEBUG_ASSERTIONS:1 NO_LLVM_ASSERTIONS:1 NO_OVERFLOW_CHECKS:1 RUSTC_RETRY_LINKER_ON_SEGFAULT:1 RUST_CONFIGURE_ARGS:--enable-full-to… (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[CI_ONLY_WHEN_CHANNEL:nightly], x86_64-gnu-integration, ubuntu-20.04-8core-32gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (map[CI_ONLY_WHEN_CHANNEL:nightly IMAGE:x86_64-gnu RUST_CI_OVERRIDE_RELEASE_CHANNEL:stable], x86_64-gnu-stable, ubuntu-20.04-4core-16gb) (push) Waiting to run
CI / auto - ${{ matrix.name }} (aarch64-gnu, [self-hosted ARM64 linux]) (push) Waiting to run
CI / Calculate job matrix (push) Failing after 15s
CI / master (push) Has been skipped
CI / PR - ${{ matrix.name }} (push) Has been skipped

fix normalizing in different `ParamEnv`s with the same `InferCtxt`

This PR changes the key of the projection cache from just `AliasTy` to `(AliasTy, ParamEnv)` to allow normalizing in different `ParamEnv`s without resetting caches. Previously, normalizing the same alias in different param envs would always reuse the cached result from the first normalization, which is incorrect if the projection clauses in the param env have changed.

Fixing this bug allows us to get rid of `InferCtxt::clear_caches`, which was only used by the `AutoTraitFinder`, because it requires normalizing in different param envs.

r? `@fmease`
This commit is contained in:
bors 2024-04-21 19:05:08 +00:00
commit 1b3fba066c
8 changed files with 25 additions and 29 deletions

View File

@ -4,7 +4,7 @@
use rustc_hir as hir;
use rustc_infer::traits::util;
use rustc_middle::ty::GenericArgs;
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeFolder};
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable};
use rustc_span::def_id::{DefId, LocalDefId};
use rustc_span::Span;
@ -214,7 +214,7 @@ fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
{
self.tcx.type_of(projection_ty.def_id).instantiate(self.tcx, projection_ty.args)
} else {
ty
ty.super_fold_with(self)
}
}
}

View File

@ -1521,15 +1521,6 @@ pub fn closure_kind(&self, closure_ty: Ty<'tcx>) -> Option<ty::ClosureKind> {
closure_kind_ty.to_opt_closure_kind()
}
/// Clears the selection, evaluation, and projection caches. This is useful when
/// repeatedly attempting to select an `Obligation` while changing only
/// its `ParamEnv`, since `FulfillmentContext` doesn't use probing.
pub fn clear_caches(&self) {
self.selection_cache.clear();
self.evaluation_cache.clear();
self.inner.borrow_mut().projection_cache().clear();
}
pub fn universe(&self) -> ty::UniverseIndex {
self.universe.get()
}

View File

@ -78,11 +78,12 @@ pub struct ProjectionCacheStorage<'tcx> {
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
pub struct ProjectionCacheKey<'tcx> {
ty: ty::AliasTy<'tcx>,
param_env: ty::ParamEnv<'tcx>,
}
impl<'tcx> ProjectionCacheKey<'tcx> {
pub fn new(ty: ty::AliasTy<'tcx>) -> Self {
Self { ty }
pub fn new(ty: ty::AliasTy<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Self {
Self { ty, param_env }
}
}

View File

@ -152,7 +152,6 @@ pub fn find_auto_trait_generics<A>(
with {:?}",
trait_ref, full_env
);
infcx.clear_caches();
// At this point, we already have all of the bounds we need. FulfillmentContext is used
// to store all of the necessary region/lifetime bounds in the InferContext, as well as
@ -176,9 +175,7 @@ pub fn find_auto_trait_generics<A>(
AutoTraitResult::PositiveImpl(auto_trait_callback(info))
}
}
impl<'tcx> AutoTraitFinder<'tcx> {
/// The core logic responsible for computing the bounds for our synthesized impl.
///
/// To calculate the bounds, we call `SelectionContext.select` in a loop. Like
@ -255,8 +252,6 @@ fn evaluate_predicates(
let dummy_cause = ObligationCause::dummy();
while let Some(pred) = predicates.pop_front() {
infcx.clear_caches();
if !already_visited.insert(pred) {
continue;
}

View File

@ -758,9 +758,9 @@ fn process_projection_obligation(
// no type variables present, can use evaluation for better caching.
// FIXME: consider caching errors too.
if self.selcx.infcx.predicate_must_hold_considering_regions(obligation) {
if let Some(key) = ProjectionCacheKey::from_poly_projection_predicate(
if let Some(key) = ProjectionCacheKey::from_poly_projection_obligation(
&mut self.selcx,
project_obligation.predicate,
&project_obligation,
) {
// If `predicate_must_hold_considering_regions` succeeds, then we've
// evaluated all sub-obligations. We can therefore mark the 'root'

View File

@ -344,7 +344,7 @@ pub(super) fn opt_normalize_projection_type<'a, 'b, 'tcx>(
let use_cache = !selcx.is_intercrate();
let projection_ty = infcx.resolve_vars_if_possible(projection_ty);
let cache_key = ProjectionCacheKey::new(projection_ty);
let cache_key = ProjectionCacheKey::new(projection_ty, param_env);
// FIXME(#20304) For now, I am caching here, which is good, but it
// means we don't capture the type variables that are created in
@ -2105,27 +2105,28 @@ fn assoc_ty_own_obligations<'cx, 'tcx>(
}
pub(crate) trait ProjectionCacheKeyExt<'cx, 'tcx>: Sized {
fn from_poly_projection_predicate(
fn from_poly_projection_obligation(
selcx: &mut SelectionContext<'cx, 'tcx>,
predicate: ty::PolyProjectionPredicate<'tcx>,
obligation: &PolyProjectionObligation<'tcx>,
) -> Option<Self>;
}
impl<'cx, 'tcx> ProjectionCacheKeyExt<'cx, 'tcx> for ProjectionCacheKey<'tcx> {
fn from_poly_projection_predicate(
fn from_poly_projection_obligation(
selcx: &mut SelectionContext<'cx, 'tcx>,
predicate: ty::PolyProjectionPredicate<'tcx>,
obligation: &PolyProjectionObligation<'tcx>,
) -> Option<Self> {
let infcx = selcx.infcx;
// We don't do cross-snapshot caching of obligations with escaping regions,
// so there's no cache key to use
predicate.no_bound_vars().map(|predicate| {
obligation.predicate.no_bound_vars().map(|predicate| {
ProjectionCacheKey::new(
// We don't attempt to match up with a specific type-variable state
// from a specific call to `opt_normalize_projection_type` - if
// there's no precise match, the original cache entry is "stranded"
// anyway.
infcx.resolve_vars_if_possible(predicate.projection_ty),
obligation.param_env,
)
})
}

View File

@ -815,7 +815,10 @@ fn evaluate_predicate_recursively<'o>(
// `EvaluatedToOkModuloRegions`), and skip re-evaluating the
// sub-obligations.
if let Some(key) =
ProjectionCacheKey::from_poly_projection_predicate(self, data)
ProjectionCacheKey::from_poly_projection_obligation(
self,
&project_obligation,
)
{
if let Some(cached_res) = self
.infcx
@ -844,8 +847,9 @@ fn evaluate_predicate_recursively<'o>(
&& (eval_rslt == EvaluatedToOk
|| eval_rslt == EvaluatedToOkModuloRegions)
&& let Some(key) =
ProjectionCacheKey::from_poly_projection_predicate(
self, data,
ProjectionCacheKey::from_poly_projection_obligation(
self,
&project_obligation,
)
{
// If the result is something that we can cache, then mark this

View File

@ -6,6 +6,10 @@ trait Foo {
fn foo() -> impl Deref<Target = impl Deref<Target = impl Sized>> {
&&()
}
fn bar() -> impl Deref<Target = Option<impl Sized>> {
&Some(())
}
}
fn main() {}