diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-03-06 10:21:27 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-04-08 15:00:26 +0000 |
| commit | 19bd91d128d921522287314925c027ea4aea1e45 (patch) | |
| tree | ae967187c8e6852719217f645c6decb7cddca4d6 /compiler/rustc_middle/src | |
| parent | ea44ce059b9f10394a08e369cd856192984d0ca0 (diff) | |
| download | rust-19bd91d128d921522287314925c027ea4aea1e45.tar.gz rust-19bd91d128d921522287314925c027ea4aea1e45.zip | |
Pass list of defineable opaque types into canonical queries
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/infer/canonical.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/query/plumbing.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/traits/mod.rs | 15 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/traits/solve.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/context.rs | 1 |
5 files changed, 18 insertions, 20 deletions
diff --git a/compiler/rustc_middle/src/infer/canonical.rs b/compiler/rustc_middle/src/infer/canonical.rs index acea89e4aab..2a51cfc5e7c 100644 --- a/compiler/rustc_middle/src/infer/canonical.rs +++ b/compiler/rustc_middle/src/infer/canonical.rs @@ -33,6 +33,7 @@ use std::ops::Index; use crate::infer::MemberConstraint; use crate::mir::ConstraintCategory; +use crate::traits::DefiningAnchor; use crate::ty::GenericArg; use crate::ty::{self, BoundVar, List, Region, Ty, TyCtxt, TypeFlags, TypeVisitableExt}; @@ -153,11 +154,6 @@ pub struct QueryResponse<'tcx, R> { pub var_values: CanonicalVarValues<'tcx>, pub region_constraints: QueryRegionConstraints<'tcx>, pub certainty: Certainty, - /// List of opaque types which we tried to compare to another type. - /// Inside the query we don't know yet whether the opaque type actually - /// should get its hidden type inferred. So we bubble the opaque type - /// and the type it was compared against upwards and let the query caller - /// handle it. pub opaque_types: Vec<(ty::OpaqueTypeKey<'tcx>, Ty<'tcx>)>, pub value: R, } @@ -316,6 +312,7 @@ impl<'tcx> CanonicalParamEnvCache<'tcx> { &self, tcx: TyCtxt<'tcx>, key: ty::ParamEnv<'tcx>, + defining_anchor: DefiningAnchor<'tcx>, state: &mut OriginalQueryValues<'tcx>, canonicalize_op: fn( TyCtxt<'tcx>, @@ -330,6 +327,7 @@ impl<'tcx> CanonicalParamEnvCache<'tcx> { max_universe: ty::UniverseIndex::ROOT, variables: List::empty(), value: key, + defining_anchor, }; } @@ -344,7 +342,8 @@ impl<'tcx> CanonicalParamEnvCache<'tcx> { *canonical } Entry::Vacant(e) => { - let canonical = canonicalize_op(tcx, key, state); + let mut canonical = canonicalize_op(tcx, key, state); + canonical.defining_anchor = defining_anchor; let OriginalQueryValues { var_values, universe_map } = state; assert_eq!(universe_map.len(), 1); e.insert((canonical, tcx.arena.alloc_slice(var_values))); diff --git a/compiler/rustc_middle/src/query/plumbing.rs b/compiler/rustc_middle/src/query/plumbing.rs index 8cb4ee7bd41..b14ecad83cc 100644 --- a/compiler/rustc_middle/src/query/plumbing.rs +++ b/compiler/rustc_middle/src/query/plumbing.rs @@ -338,10 +338,10 @@ macro_rules! define_callbacks { pub type Storage<'tcx> = <$($K)* as keys::Key>::Cache<Erase<$V>>; - // Ensure that keys grow no larger than 64 bytes + // Ensure that keys grow no larger than 72 bytes #[cfg(all(any(target_arch = "x86_64", target_arch="aarch64"), target_pointer_width = "64"))] const _: () = { - if mem::size_of::<Key<'static>>() > 64 { + if mem::size_of::<Key<'static>>() > 72 { panic!("{}", concat!( "the query `", stringify!($name), @@ -352,10 +352,10 @@ macro_rules! define_callbacks { } }; - // Ensure that values grow no larger than 64 bytes + // Ensure that values grow no larger than 72 bytes #[cfg(all(any(target_arch = "x86_64", target_arch="aarch64"), target_pointer_width = "64"))] const _: () = { - if mem::size_of::<Value<'static>>() > 64 { + if mem::size_of::<Value<'static>>() > 72 { panic!("{}", concat!( "the query `", stringify!($name), diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index ee816791919..58aff27266d 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -1004,6 +1004,7 @@ pub enum CodegenObligationError { /// opaques are replaced with inference vars eagerly in the old solver (e.g. /// in projection, and in the signature during function type-checking). #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, HashStable, TypeFoldable, TypeVisitable)] +#[derive(TyEncodable, TyDecodable)] pub enum DefiningAnchor<'tcx> { /// Define opaques which are in-scope of the current item being analyzed. /// Also, eagerly replace these opaque types in `replace_opaque_types_with_inference_vars`. @@ -1012,14 +1013,12 @@ pub enum DefiningAnchor<'tcx> { /// errors when handling opaque types, and also should be used when we would /// otherwise reveal opaques (such as [`Reveal::All`] reveal mode). Bind(&'tcx ty::List<LocalDefId>), - /// In contexts where we don't currently know what opaques are allowed to be - /// defined, such as (old solver) canonical queries, we will simply allow - /// opaques to be defined, but "bubble" them up in the canonical response or - /// otherwise treat them to be handled later. - /// - /// We do not eagerly replace opaque types in `replace_opaque_types_with_inference_vars`, - /// which may affect what predicates pass and fail in the old trait solver. - Bubble, +} + +impl Default for DefiningAnchor<'_> { + fn default() -> Self { + Self::Bind(ty::List::empty()) + } } impl<'tcx> DefiningAnchor<'tcx> { diff --git a/compiler/rustc_middle/src/traits/solve.rs b/compiler/rustc_middle/src/traits/solve.rs index 6dcea2aaff1..13504c6ae93 100644 --- a/compiler/rustc_middle/src/traits/solve.rs +++ b/compiler/rustc_middle/src/traits/solve.rs @@ -4,7 +4,7 @@ use rustc_span::def_id::DefId; use crate::infer::canonical::{CanonicalVarValues, QueryRegionConstraints}; use crate::traits::query::NoSolution; -use crate::traits::{Canonical, DefiningAnchor}; +use crate::traits::Canonical; use crate::ty::{ self, FallibleTypeFolder, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeVisitable, TypeVisitor, @@ -114,7 +114,6 @@ impl MaybeCause { #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, HashStable, TypeFoldable, TypeVisitable)] pub struct QueryInput<'tcx, T> { pub goal: Goal<'tcx, T>, - pub anchor: DefiningAnchor<'tcx>, pub predefined_opaques_in_body: PredefinedOpaques<'tcx>, } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 1db9bce73a6..36fad95715c 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -84,6 +84,7 @@ use std::ops::{Bound, Deref}; #[allow(rustc::usage_of_ty_tykind)] impl<'tcx> Interner for TyCtxt<'tcx> { type DefId = DefId; + type DefiningAnchor = traits::DefiningAnchor<'tcx>; type AdtDef = ty::AdtDef<'tcx>; type GenericArgs = ty::GenericArgsRef<'tcx>; type GenericArg = ty::GenericArg<'tcx>; |
