Eliminate DefiningAnchor
now that is just a single-variant enum
This commit is contained in:
parent
dd72bf922a
commit
2f2350e577
@ -4,7 +4,6 @@
|
||||
use rustc_index::{IndexSlice, IndexVec};
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_middle::mir::{Body, Promoted};
|
||||
use rustc_middle::traits::DefiningAnchor;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use std::rc::Rc;
|
||||
|
||||
@ -106,7 +105,7 @@ pub fn get_body_with_borrowck_facts(
|
||||
options: ConsumerOptions,
|
||||
) -> BodyWithBorrowckFacts<'_> {
|
||||
let (input_body, promoted) = tcx.mir_promoted(def);
|
||||
let infcx = tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::bind(tcx, def)).build();
|
||||
let infcx = tcx.infer_ctxt().with_opaque_type_inference(def).build();
|
||||
let input_body: &Body<'_> = &input_body.borrow();
|
||||
let promoted: &IndexSlice<_, _> = &promoted.borrow();
|
||||
*super::do_mir_borrowck(&infcx, input_body, promoted, Some(options)).1.unwrap()
|
||||
|
@ -32,7 +32,6 @@
|
||||
use rustc_middle::mir::tcx::PlaceTy;
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::traits::DefiningAnchor;
|
||||
use rustc_middle::ty::{self, ParamEnv, RegionVid, TyCtxt};
|
||||
use rustc_session::lint::builtin::UNUSED_MUT;
|
||||
use rustc_span::{Span, Symbol};
|
||||
@ -126,7 +125,7 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> &BorrowCheckResult<'_> {
|
||||
return tcx.arena.alloc(result);
|
||||
}
|
||||
|
||||
let infcx = tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::bind(tcx, def)).build();
|
||||
let infcx = tcx.infer_ctxt().with_opaque_type_inference(def).build();
|
||||
let promoted: &IndexSlice<_, _> = &promoted.borrow();
|
||||
let opt_closure_req = do_mir_borrowck(&infcx, input_body, promoted, None).0;
|
||||
debug!("mir_borrowck done");
|
||||
|
@ -7,7 +7,6 @@
|
||||
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin};
|
||||
use rustc_infer::traits::{Obligation, ObligationCause};
|
||||
use rustc_macros::extension;
|
||||
use rustc_middle::traits::DefiningAnchor;
|
||||
use rustc_middle::ty::visit::TypeVisitableExt;
|
||||
use rustc_middle::ty::{self, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable};
|
||||
use rustc_middle::ty::{GenericArgKind, GenericArgs};
|
||||
@ -333,13 +332,13 @@ fn check_opaque_type_well_formed<'tcx>(
|
||||
parent_def_id = tcx.local_parent(parent_def_id);
|
||||
}
|
||||
|
||||
// FIXME(-Znext-solver): We probably should use `DefiningAnchor::Bind(&[])`
|
||||
// FIXME(-Znext-solver): We probably should use `&[]` instead of
|
||||
// and prepopulate this `InferCtxt` with known opaque values, rather than
|
||||
// using the `Bind` anchor here. For now it's fine.
|
||||
// allowing opaque types to be defined and checking them after the fact.
|
||||
let infcx = tcx
|
||||
.infer_ctxt()
|
||||
.with_next_trait_solver(next_trait_solver)
|
||||
.with_opaque_type_inference(DefiningAnchor::bind(tcx, parent_def_id))
|
||||
.with_opaque_type_inference(parent_def_id)
|
||||
.build();
|
||||
let ocx = ObligationCtxt::new(&infcx);
|
||||
let identity_args = GenericArgs::identity_for_item(tcx, def_id);
|
||||
|
@ -13,7 +13,7 @@
|
||||
use rustc_infer::traits::{Obligation, TraitEngineExt as _};
|
||||
use rustc_lint_defs::builtin::REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS;
|
||||
use rustc_middle::middle::stability::EvalResult;
|
||||
use rustc_middle::traits::{DefiningAnchor, ObligationCauseCode};
|
||||
use rustc_middle::traits::ObligationCauseCode;
|
||||
use rustc_middle::ty::fold::BottomUpFolder;
|
||||
use rustc_middle::ty::layout::{LayoutError, MAX_SIMD_LANES};
|
||||
use rustc_middle::ty::util::{Discr, InspectCoroutineFields, IntTypeExt};
|
||||
@ -345,10 +345,7 @@ fn check_opaque_meets_bounds<'tcx>(
|
||||
};
|
||||
let param_env = tcx.param_env(defining_use_anchor);
|
||||
|
||||
let infcx = tcx
|
||||
.infer_ctxt()
|
||||
.with_opaque_type_inference(DefiningAnchor::bind(tcx, defining_use_anchor))
|
||||
.build();
|
||||
let infcx = tcx.infer_ctxt().with_opaque_type_inference(defining_use_anchor).build();
|
||||
let ocx = ObligationCtxt::new(&infcx);
|
||||
|
||||
let args = match *origin {
|
||||
@ -1567,7 +1564,7 @@ pub(super) fn check_coroutine_obligations(
|
||||
.ignoring_regions()
|
||||
// Bind opaque types to type checking root, as they should have been checked by borrowck,
|
||||
// but may show up in some cases, like when (root) obligations are stalled in the new solver.
|
||||
.with_opaque_type_inference(DefiningAnchor::bind(tcx, typeck.hir_owner.def_id))
|
||||
.with_opaque_type_inference(typeck.hir_owner.def_id)
|
||||
.build();
|
||||
|
||||
let mut fulfillment_cx = <dyn TraitEngine<'_>>::new(&infcx);
|
||||
|
@ -5,7 +5,6 @@
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_hir::HirIdMap;
|
||||
use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt};
|
||||
use rustc_middle::traits::DefiningAnchor;
|
||||
use rustc_middle::ty::visit::TypeVisitableExt;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_span::def_id::LocalDefIdMap;
|
||||
@ -78,11 +77,7 @@ impl<'tcx> TypeckRootCtxt<'tcx> {
|
||||
pub fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self {
|
||||
let hir_owner = tcx.local_def_id_to_hir_id(def_id).owner;
|
||||
|
||||
let infcx = tcx
|
||||
.infer_ctxt()
|
||||
.ignoring_regions()
|
||||
.with_opaque_type_inference(DefiningAnchor::bind(tcx, def_id))
|
||||
.build();
|
||||
let infcx = tcx.infer_ctxt().ignoring_regions().with_opaque_type_inference(def_id).build();
|
||||
let typeck_results = RefCell::new(ty::TypeckResults::new(hir_owner));
|
||||
|
||||
TypeckRootCtxt {
|
||||
|
@ -75,7 +75,7 @@ pub fn fork(&self) -> Self {
|
||||
pub fn fork_with_intercrate(&self, intercrate: bool) -> Self {
|
||||
Self {
|
||||
tcx: self.tcx,
|
||||
defining_use_anchor: self.defining_use_anchor,
|
||||
defining_opaque_types: self.defining_opaque_types,
|
||||
considering_regions: self.considering_regions,
|
||||
skip_leak_check: self.skip_leak_check,
|
||||
inner: self.inner.clone(),
|
||||
|
@ -45,7 +45,7 @@ pub fn canonicalize_query<V>(
|
||||
let param_env = self.tcx.canonical_param_env_cache.get_or_insert(
|
||||
self.tcx,
|
||||
param_env,
|
||||
self.defining_use_anchor,
|
||||
self.defining_opaque_types,
|
||||
query_state,
|
||||
|tcx, param_env, query_state| {
|
||||
// FIXME(#118965): We don't canonicalize the static lifetimes that appear in the
|
||||
@ -541,7 +541,7 @@ fn canonicalize<V>(
|
||||
max_universe: ty::UniverseIndex::ROOT,
|
||||
variables: List::empty(),
|
||||
value: (),
|
||||
defining_anchor: infcx.map(|i| i.defining_use_anchor).unwrap_or_default(),
|
||||
defining_opaque_types: infcx.map(|i| i.defining_opaque_types).unwrap_or_default(),
|
||||
};
|
||||
Canonicalizer::canonicalize_with_base(
|
||||
base,
|
||||
@ -615,7 +615,7 @@ fn canonicalize_with_base<U, V>(
|
||||
max_universe,
|
||||
variables: canonical_variables,
|
||||
value: (base.value, out_value),
|
||||
defining_anchor: base.defining_anchor,
|
||||
defining_opaque_types: base.defining_opaque_types,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@
|
||||
use rustc_middle::infer::unify_key::{ConstVidKey, EffectVidKey};
|
||||
use rustc_middle::mir::interpret::{ErrorHandled, EvalToValTreeResult};
|
||||
use rustc_middle::mir::ConstraintCategory;
|
||||
use rustc_middle::traits::{select, DefiningAnchor};
|
||||
use rustc_middle::traits::select;
|
||||
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
||||
use rustc_middle::ty::fold::BoundVarReplacerDelegate;
|
||||
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
|
||||
@ -244,11 +244,7 @@ pub struct InferCtxt<'tcx> {
|
||||
pub tcx: TyCtxt<'tcx>,
|
||||
|
||||
/// The `DefIds` of the opaque types that may have their hidden types constrained.
|
||||
///
|
||||
/// Its default value is `DefiningAnchor::Bind(&[])`, which means no opaque types may be defined.
|
||||
/// This way it is easier to catch errors that
|
||||
/// might come up during inference or typeck.
|
||||
pub defining_use_anchor: DefiningAnchor<'tcx>,
|
||||
pub defining_opaque_types: &'tcx ty::List<LocalDefId>,
|
||||
|
||||
/// Whether this inference context should care about region obligations in
|
||||
/// the root universe. Most notably, this is used during hir typeck as region
|
||||
@ -396,8 +392,8 @@ fn probe_ct_var(&self, vid: ConstVid) -> Option<ty::Const<'tcx>> {
|
||||
self.probe_const_var(vid).ok()
|
||||
}
|
||||
|
||||
fn defining_anchor(&self) -> DefiningAnchor<'tcx> {
|
||||
self.defining_use_anchor
|
||||
fn defining_opaque_types(&self) -> &'tcx ty::List<LocalDefId> {
|
||||
self.defining_opaque_types
|
||||
}
|
||||
}
|
||||
|
||||
@ -613,7 +609,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
/// Used to configure inference contexts before their creation.
|
||||
pub struct InferCtxtBuilder<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
defining_use_anchor: DefiningAnchor<'tcx>,
|
||||
defining_opaque_types: &'tcx ty::List<LocalDefId>,
|
||||
considering_regions: bool,
|
||||
skip_leak_check: bool,
|
||||
/// Whether we are in coherence mode.
|
||||
@ -628,7 +624,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
fn infer_ctxt(self) -> InferCtxtBuilder<'tcx> {
|
||||
InferCtxtBuilder {
|
||||
tcx: self,
|
||||
defining_use_anchor: DefiningAnchor::Bind(ty::List::empty()),
|
||||
defining_opaque_types: ty::List::empty(),
|
||||
considering_regions: true,
|
||||
skip_leak_check: false,
|
||||
intercrate: false,
|
||||
@ -644,8 +640,16 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
|
||||
/// It is only meant to be called in two places, for typeck
|
||||
/// (via `Inherited::build`) and for the inference context used
|
||||
/// in mir borrowck.
|
||||
pub fn with_opaque_type_inference(mut self, defining_use_anchor: DefiningAnchor<'tcx>) -> Self {
|
||||
self.defining_use_anchor = defining_use_anchor;
|
||||
pub fn with_opaque_type_inference(mut self, defining_anchor: LocalDefId) -> Self {
|
||||
self.defining_opaque_types = self.tcx.opaque_types_defined_by(defining_anchor);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_defining_opaque_types(
|
||||
mut self,
|
||||
defining_opaque_types: &'tcx ty::List<LocalDefId>,
|
||||
) -> Self {
|
||||
self.defining_opaque_types = defining_opaque_types;
|
||||
self
|
||||
}
|
||||
|
||||
@ -684,7 +688,7 @@ pub fn build_with_canonical<T>(
|
||||
where
|
||||
T: TypeFoldable<TyCtxt<'tcx>>,
|
||||
{
|
||||
let infcx = self.with_opaque_type_inference(canonical.defining_anchor).build();
|
||||
let infcx = self.with_defining_opaque_types(canonical.defining_opaque_types).build();
|
||||
let (value, args) = infcx.instantiate_canonical(span, canonical);
|
||||
(infcx, value, args)
|
||||
}
|
||||
@ -692,7 +696,7 @@ pub fn build_with_canonical<T>(
|
||||
pub fn build(&mut self) -> InferCtxt<'tcx> {
|
||||
let InferCtxtBuilder {
|
||||
tcx,
|
||||
defining_use_anchor,
|
||||
defining_opaque_types,
|
||||
considering_regions,
|
||||
skip_leak_check,
|
||||
intercrate,
|
||||
@ -700,7 +704,7 @@ pub fn build(&mut self) -> InferCtxt<'tcx> {
|
||||
} = *self;
|
||||
InferCtxt {
|
||||
tcx,
|
||||
defining_use_anchor,
|
||||
defining_opaque_types,
|
||||
considering_regions,
|
||||
skip_leak_check,
|
||||
inner: RefCell::new(InferCtxtInner::new()),
|
||||
|
@ -8,7 +8,7 @@
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_hir as hir;
|
||||
use rustc_middle::traits::{DefiningAnchor, ObligationCause};
|
||||
use rustc_middle::traits::ObligationCause;
|
||||
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
||||
use rustc_middle::ty::fold::BottomUpFolder;
|
||||
use rustc_middle::ty::GenericArgKind;
|
||||
@ -106,47 +106,44 @@ pub fn handle_opaque_type(
|
||||
b,
|
||||
));
|
||||
}
|
||||
match self.defining_use_anchor {
|
||||
DefiningAnchor::Bind(_) => {
|
||||
// Check that this is `impl Trait` type is
|
||||
// declared by `parent_def_id` -- i.e., one whose
|
||||
// value we are inferring. At present, this is
|
||||
// always true during the first phase of
|
||||
// type-check, but not always true later on during
|
||||
// NLL. Once we support named opaque types more fully,
|
||||
// this same scenario will be able to arise during all phases.
|
||||
//
|
||||
// Here is an example using type alias `impl Trait`
|
||||
// that indicates the distinction we are checking for:
|
||||
//
|
||||
// ```rust
|
||||
// mod a {
|
||||
// pub type Foo = impl Iterator;
|
||||
// pub fn make_foo() -> Foo { .. }
|
||||
// }
|
||||
//
|
||||
// mod b {
|
||||
// fn foo() -> a::Foo { a::make_foo() }
|
||||
// }
|
||||
// ```
|
||||
//
|
||||
// Here, the return type of `foo` references an
|
||||
// `Opaque` indeed, but not one whose value is
|
||||
// presently being inferred. You can get into a
|
||||
// similar situation with closure return types
|
||||
// today:
|
||||
//
|
||||
// ```rust
|
||||
// fn foo() -> impl Iterator { .. }
|
||||
// fn bar() {
|
||||
// let x = || foo(); // returns the Opaque assoc with `foo`
|
||||
// }
|
||||
// ```
|
||||
if self.opaque_type_origin(def_id).is_none() {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
// Check that this is `impl Trait` type is
|
||||
// declared by `parent_def_id` -- i.e., one whose
|
||||
// value we are inferring. At present, this is
|
||||
// always true during the first phase of
|
||||
// type-check, but not always true later on during
|
||||
// NLL. Once we support named opaque types more fully,
|
||||
// this same scenario will be able to arise during all phases.
|
||||
//
|
||||
// Here is an example using type alias `impl Trait`
|
||||
// that indicates the distinction we are checking for:
|
||||
//
|
||||
// ```rust
|
||||
// mod a {
|
||||
// pub type Foo = impl Iterator;
|
||||
// pub fn make_foo() -> Foo { .. }
|
||||
// }
|
||||
//
|
||||
// mod b {
|
||||
// fn foo() -> a::Foo { a::make_foo() }
|
||||
// }
|
||||
// ```
|
||||
//
|
||||
// Here, the return type of `foo` references an
|
||||
// `Opaque` indeed, but not one whose value is
|
||||
// presently being inferred. You can get into a
|
||||
// similar situation with closure return types
|
||||
// today:
|
||||
//
|
||||
// ```rust
|
||||
// fn foo() -> impl Iterator { .. }
|
||||
// fn bar() {
|
||||
// let x = || foo(); // returns the Opaque assoc with `foo`
|
||||
// }
|
||||
// ```
|
||||
if self.opaque_type_origin(def_id).is_none() {
|
||||
return None;
|
||||
}
|
||||
|
||||
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }) = *b.kind() {
|
||||
// We could accept this, but there are various ways to handle this situation, and we don't
|
||||
// want to make a decision on it right now. Likely this case is so super rare anyway, that
|
||||
@ -371,13 +368,9 @@ pub fn register_member_constraints(
|
||||
/// in its defining scope.
|
||||
#[instrument(skip(self), level = "trace", ret)]
|
||||
pub fn opaque_type_origin(&self, def_id: LocalDefId) -> Option<OpaqueTyOrigin> {
|
||||
let defined_opaque_types = match self.defining_use_anchor {
|
||||
DefiningAnchor::Bind(bind) => bind,
|
||||
};
|
||||
|
||||
let origin = self.tcx.opaque_type_origin(def_id);
|
||||
|
||||
defined_opaque_types.contains(&def_id).then_some(origin)
|
||||
self.defining_opaque_types.contains(&def_id).then_some(origin)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::sync::Lock;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_macros::HashStable;
|
||||
use rustc_type_ir::Canonical as IrCanonical;
|
||||
use rustc_type_ir::CanonicalVarInfo as IrCanonicalVarInfo;
|
||||
@ -33,7 +34,6 @@
|
||||
|
||||
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};
|
||||
|
||||
@ -312,7 +312,7 @@ pub fn get_or_insert(
|
||||
&self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
key: ty::ParamEnv<'tcx>,
|
||||
defining_anchor: DefiningAnchor<'tcx>,
|
||||
defining_opaque_types: &'tcx ty::List<LocalDefId>,
|
||||
state: &mut OriginalQueryValues<'tcx>,
|
||||
canonicalize_op: fn(
|
||||
TyCtxt<'tcx>,
|
||||
@ -327,7 +327,7 @@ pub fn get_or_insert(
|
||||
max_universe: ty::UniverseIndex::ROOT,
|
||||
variables: List::empty(),
|
||||
value: key,
|
||||
defining_anchor,
|
||||
defining_opaque_types,
|
||||
};
|
||||
}
|
||||
|
||||
@ -343,7 +343,7 @@ pub fn get_or_insert(
|
||||
}
|
||||
Entry::Vacant(e) => {
|
||||
let mut canonical = canonicalize_op(tcx, key, state);
|
||||
canonical.defining_anchor = defining_anchor;
|
||||
canonical.defining_opaque_types = defining_opaque_types;
|
||||
let OriginalQueryValues { var_values, universe_map } = state;
|
||||
assert_eq!(universe_map.len(), 1);
|
||||
e.insert((canonical, tcx.arena.alloc_slice(var_values)));
|
||||
|
@ -12,8 +12,8 @@
|
||||
use crate::infer::canonical::Canonical;
|
||||
use crate::mir::ConstraintCategory;
|
||||
use crate::ty::abstract_const::NotConstEvaluatable;
|
||||
use crate::ty::GenericArgsRef;
|
||||
use crate::ty::{self, AdtKind, Ty};
|
||||
use crate::ty::{GenericArgsRef, TyCtxt};
|
||||
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_errors::{Applicability, Diag, EmissionGuarantee};
|
||||
@ -997,32 +997,3 @@ pub enum CodegenObligationError {
|
||||
Unimplemented,
|
||||
FulfillmentError,
|
||||
}
|
||||
|
||||
/// Defines the treatment of opaque types in a given inference context.
|
||||
///
|
||||
/// This affects both what opaques are allowed to be defined, but also whether
|
||||
/// 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`.
|
||||
///
|
||||
/// If the list is empty, do not allow any opaques to be defined. This is used to catch type mismatch
|
||||
/// 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>),
|
||||
}
|
||||
|
||||
impl Default for DefiningAnchor<'_> {
|
||||
fn default() -> Self {
|
||||
Self::Bind(ty::List::empty())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> DefiningAnchor<'tcx> {
|
||||
pub fn bind(tcx: TyCtxt<'tcx>, item: LocalDefId) -> Self {
|
||||
Self::Bind(tcx.opaque_types_defined_by(item))
|
||||
}
|
||||
}
|
||||
|
@ -443,6 +443,12 @@ fn decode(decoder: &mut D) -> &'tcx Self {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for &'tcx ty::List<LocalDefId> {
|
||||
fn decode(d: &mut D) -> Self {
|
||||
RefDecodable::decode(d)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D>
|
||||
for ty::List<(VariantIdx, FieldIdx)>
|
||||
{
|
||||
|
@ -84,7 +84,7 @@
|
||||
#[allow(rustc::usage_of_ty_tykind)]
|
||||
impl<'tcx> Interner for TyCtxt<'tcx> {
|
||||
type DefId = DefId;
|
||||
type DefiningAnchor = traits::DefiningAnchor<'tcx>;
|
||||
type DefiningOpaqueTypes = &'tcx ty::List<LocalDefId>;
|
||||
type AdtDef = ty::AdtDef<'tcx>;
|
||||
type GenericArgs = ty::GenericArgsRef<'tcx>;
|
||||
type GenericArg = ty::GenericArg<'tcx>;
|
||||
|
@ -55,6 +55,12 @@ struct ListSkeleton<H, T> {
|
||||
data: [T; 0],
|
||||
}
|
||||
|
||||
impl<T> Default for &List<T> {
|
||||
fn default() -> Self {
|
||||
List::empty()
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
/// A dummy type used to force `List` to be unsized while not requiring
|
||||
/// references to it be wide pointers.
|
||||
|
@ -69,8 +69,8 @@ pub fn canonicalize<T: TypeFoldable<I>>(
|
||||
|
||||
let (max_universe, variables) = canonicalizer.finalize();
|
||||
|
||||
let defining_anchor = infcx.defining_anchor();
|
||||
Canonical { defining_anchor, max_universe, variables, value }
|
||||
let defining_opaque_types = infcx.defining_opaque_types();
|
||||
Canonical { defining_opaque_types, max_universe, variables, value }
|
||||
}
|
||||
|
||||
fn finalize(self) -> (ty::UniverseIndex, I::CanonicalVars) {
|
||||
|
@ -316,6 +316,6 @@ fn response_no_constraints_raw<'tcx>(
|
||||
external_constraints: tcx.mk_external_constraints(ExternalConstraintsData::default()),
|
||||
certainty,
|
||||
},
|
||||
defining_anchor: Default::default(),
|
||||
defining_opaque_types: Default::default(),
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
pub struct Canonical<I: Interner, V> {
|
||||
pub value: V,
|
||||
pub max_universe: UniverseIndex,
|
||||
pub defining_anchor: I::DefiningAnchor,
|
||||
pub defining_opaque_types: I::DefiningOpaqueTypes,
|
||||
pub variables: I::CanonicalVars,
|
||||
}
|
||||
|
||||
@ -45,8 +45,8 @@ impl<I: Interner, V> Canonical<I, V> {
|
||||
/// let b: Canonical<I, (T, Ty<I>)> = a.unchecked_map(|v| (v, ty));
|
||||
/// ```
|
||||
pub fn unchecked_map<W>(self, map_op: impl FnOnce(V) -> W) -> Canonical<I, W> {
|
||||
let Canonical { defining_anchor, max_universe, variables, value } = self;
|
||||
Canonical { defining_anchor, max_universe, variables, value: map_op(value) }
|
||||
let Canonical { defining_opaque_types, max_universe, variables, value } = self;
|
||||
Canonical { defining_opaque_types, max_universe, variables, value: map_op(value) }
|
||||
}
|
||||
|
||||
/// Allows you to map the `value` of a canonical while keeping the same set of
|
||||
@ -55,8 +55,8 @@ pub fn unchecked_map<W>(self, map_op: impl FnOnce(V) -> W) -> Canonical<I, W> {
|
||||
/// **WARNING:** This function is very easy to mis-use, hence the name! See
|
||||
/// the comment of [Canonical::unchecked_map] for more details.
|
||||
pub fn unchecked_rebind<W>(self, value: W) -> Canonical<I, W> {
|
||||
let Canonical { defining_anchor, max_universe, variables, value: _ } = self;
|
||||
Canonical { defining_anchor, max_universe, variables, value }
|
||||
let Canonical { defining_opaque_types, max_universe, variables, value: _ } = self;
|
||||
Canonical { defining_opaque_types, max_universe, variables, value }
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,32 +64,32 @@ impl<I: Interner, V: Eq> Eq for Canonical<I, V> {}
|
||||
|
||||
impl<I: Interner, V: PartialEq> PartialEq for Canonical<I, V> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
let Self { value, max_universe, variables, defining_anchor } = self;
|
||||
let Self { value, max_universe, variables, defining_opaque_types } = self;
|
||||
*value == other.value
|
||||
&& *max_universe == other.max_universe
|
||||
&& *variables == other.variables
|
||||
&& *defining_anchor == other.defining_anchor
|
||||
&& *defining_opaque_types == other.defining_opaque_types
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: Interner, V: fmt::Display> fmt::Display for Canonical<I, V> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let Self { value, max_universe, variables, defining_anchor } = self;
|
||||
let Self { value, max_universe, variables, defining_opaque_types } = self;
|
||||
write!(
|
||||
f,
|
||||
"Canonical {{ value: {value}, max_universe: {max_universe:?}, variables: {variables:?}, defining_anchor: {defining_anchor:?} }}",
|
||||
"Canonical {{ value: {value}, max_universe: {max_universe:?}, variables: {variables:?}, defining_opaque_types: {defining_opaque_types:?} }}",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: Interner, V: fmt::Debug> fmt::Debug for Canonical<I, V> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let Self { value, max_universe, variables, defining_anchor } = self;
|
||||
let Self { value, max_universe, variables, defining_opaque_types } = self;
|
||||
f.debug_struct("Canonical")
|
||||
.field("value", &value)
|
||||
.field("max_universe", &max_universe)
|
||||
.field("variables", &variables)
|
||||
.field("defining_anchor", &defining_anchor)
|
||||
.field("defining_opaque_types", &defining_opaque_types)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
@ -105,7 +105,7 @@ fn try_fold_with<F: FallibleTypeFolder<I>>(self, folder: &mut F) -> Result<Self,
|
||||
value: self.value.try_fold_with(folder)?,
|
||||
max_universe: self.max_universe.try_fold_with(folder)?,
|
||||
variables: self.variables.try_fold_with(folder)?,
|
||||
defining_anchor: self.defining_anchor,
|
||||
defining_opaque_types: self.defining_opaque_types,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -115,10 +115,10 @@ impl<I: Interner, V: TypeVisitable<I>> TypeVisitable<I> for Canonical<I, V>
|
||||
I::CanonicalVars: TypeVisitable<I>,
|
||||
{
|
||||
fn visit_with<F: TypeVisitor<I>>(&self, folder: &mut F) -> F::Result {
|
||||
let Self { value, max_universe, variables, defining_anchor } = self;
|
||||
let Self { value, max_universe, variables, defining_opaque_types } = self;
|
||||
try_visit!(value.visit_with(folder));
|
||||
try_visit!(max_universe.visit_with(folder));
|
||||
try_visit!(defining_anchor.visit_with(folder));
|
||||
try_visit!(defining_opaque_types.visit_with(folder));
|
||||
variables.visit_with(folder)
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ fn probe_ct_var(&self, _vid: ConstVid) -> Option<I::Const> {
|
||||
None
|
||||
}
|
||||
|
||||
fn defining_anchor(&self) -> <Self::Interner as Interner>::DefiningAnchor {
|
||||
fn defining_opaque_types(&self) -> <Self::Interner as Interner>::DefiningOpaqueTypes {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
@ -38,5 +38,5 @@ fn opportunistic_resolve_lt_var(
|
||||
/// Resolve `ConstVid` to its inferred type, if it has been equated with a non-infer type.
|
||||
fn probe_ct_var(&self, vid: ConstVid) -> Option<<Self::Interner as Interner>::Const>;
|
||||
|
||||
fn defining_anchor(&self) -> <Self::Interner as Interner>::DefiningAnchor;
|
||||
fn defining_opaque_types(&self) -> <Self::Interner as Interner>::DefiningOpaqueTypes;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
pub trait Interner: Sized + Copy {
|
||||
type DefId: Copy + Debug + Hash + Eq;
|
||||
type DefiningAnchor: Copy + Debug + Hash + Default + Eq + TypeVisitable<Self>;
|
||||
type DefiningOpaqueTypes: Copy + Debug + Hash + Default + Eq + TypeVisitable<Self>;
|
||||
type AdtDef: Copy + Debug + Hash + Eq;
|
||||
|
||||
type GenericArgs: Copy
|
||||
|
Loading…
Reference in New Issue
Block a user