Remove associated type based effects logic
This commit is contained in:
parent
8aca4bab08
commit
a16d491054
73 changed files with 85 additions and 1519 deletions
|
@ -489,17 +489,6 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
ty::ConstKind::Infer(InferConst::EffectVar(vid)) => {
|
||||
match self.infcx.unwrap().probe_effect_var(vid) {
|
||||
Some(value) => return self.fold_const(value),
|
||||
None => {
|
||||
return self.canonicalize_const_var(
|
||||
CanonicalVarInfo { kind: CanonicalVarKind::Effect },
|
||||
ct,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
ty::ConstKind::Infer(InferConst::Fresh(_)) => {
|
||||
bug!("encountered a fresh const during canonicalization")
|
||||
}
|
||||
|
@ -700,8 +689,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
|
|||
.iter()
|
||||
.map(|v| CanonicalVarInfo {
|
||||
kind: match v.kind {
|
||||
CanonicalVarKind::Ty(CanonicalTyVarKind::Int | CanonicalTyVarKind::Float)
|
||||
| CanonicalVarKind::Effect => {
|
||||
CanonicalVarKind::Ty(CanonicalTyVarKind::Int | CanonicalTyVarKind::Float) => {
|
||||
return *v;
|
||||
}
|
||||
CanonicalVarKind::Ty(CanonicalTyVarKind::General(u)) => {
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
pub use instantiate::CanonicalExt;
|
||||
use rustc_index::IndexVec;
|
||||
pub use rustc_middle::infer::canonical::*;
|
||||
use rustc_middle::infer::unify_key::EffectVarValue;
|
||||
use rustc_middle::ty::fold::TypeFoldable;
|
||||
use rustc_middle::ty::{self, GenericArg, List, Ty, TyCtxt};
|
||||
use rustc_span::Span;
|
||||
|
@ -145,15 +144,6 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
CanonicalVarKind::Const(ui) => {
|
||||
self.next_const_var_in_universe(span, universe_map(ui)).into()
|
||||
}
|
||||
CanonicalVarKind::Effect => {
|
||||
let vid = self
|
||||
.inner
|
||||
.borrow_mut()
|
||||
.effect_unification_table()
|
||||
.new_key(EffectVarValue::Unknown)
|
||||
.vid;
|
||||
ty::Const::new_infer(self.tcx, ty::InferConst::EffectVar(vid)).into()
|
||||
}
|
||||
CanonicalVarKind::PlaceholderConst(ty::PlaceholderConst { universe, bound }) => {
|
||||
let universe_mapped = universe_map(universe);
|
||||
let placeholder_mapped = ty::PlaceholderConst { universe: universe_mapped, bound };
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
///! Definition of `InferCtxtLike` from the librarified type layer.
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_middle::infer::unify_key::EffectVarValue;
|
||||
use rustc_middle::traits::ObligationCause;
|
||||
use rustc_middle::traits::solve::SolverMode;
|
||||
use rustc_middle::ty::fold::TypeFoldable;
|
||||
|
@ -88,15 +87,6 @@ impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn opportunistic_resolve_effect_var(&self, vid: ty::EffectVid) -> ty::Const<'tcx> {
|
||||
match self.probe_effect_var(vid) {
|
||||
Some(ct) => ct,
|
||||
None => {
|
||||
ty::Const::new_infer(self.tcx, ty::InferConst::EffectVar(self.root_effect_var(vid)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn opportunistic_resolve_lt_var(&self, vid: ty::RegionVid) -> ty::Region<'tcx> {
|
||||
self.inner.borrow_mut().unwrap_region_constraints().opportunistic_resolve_var(self.tcx, vid)
|
||||
}
|
||||
|
@ -152,10 +142,6 @@ impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> {
|
|||
self.inner.borrow_mut().const_unification_table().union(a, b);
|
||||
}
|
||||
|
||||
fn equate_effect_vids_raw(&self, a: rustc_type_ir::EffectVid, b: rustc_type_ir::EffectVid) {
|
||||
self.inner.borrow_mut().effect_unification_table().union(a, b);
|
||||
}
|
||||
|
||||
fn instantiate_ty_var_raw<R: PredicateEmittingRelation<Self>>(
|
||||
&self,
|
||||
relation: &mut R,
|
||||
|
@ -189,13 +175,6 @@ impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> {
|
|||
self.inner.borrow_mut().float_unification_table().union_value(vid, value);
|
||||
}
|
||||
|
||||
fn instantiate_effect_var_raw(&self, vid: rustc_type_ir::EffectVid, value: ty::Const<'tcx>) {
|
||||
self.inner
|
||||
.borrow_mut()
|
||||
.effect_unification_table()
|
||||
.union_value(vid, EffectVarValue::Known(value));
|
||||
}
|
||||
|
||||
fn instantiate_const_var_raw<R: PredicateEmittingRelation<Self>>(
|
||||
&self,
|
||||
relation: &mut R,
|
||||
|
|
|
@ -153,15 +153,6 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for TypeFreshener<'a, 'tcx> {
|
|||
drop(inner);
|
||||
self.freshen_const(input, ty::InferConst::Fresh)
|
||||
}
|
||||
ty::ConstKind::Infer(ty::InferConst::EffectVar(v)) => {
|
||||
let mut inner = self.infcx.inner.borrow_mut();
|
||||
let input =
|
||||
inner.effect_unification_table().probe_value(v).known().ok_or_else(|| {
|
||||
ty::InferConst::EffectVar(inner.effect_unification_table().find(v).vid)
|
||||
});
|
||||
drop(inner);
|
||||
self.freshen_const(input, ty::InferConst::Fresh)
|
||||
}
|
||||
ty::ConstKind::Infer(ty::InferConst::Fresh(i)) => {
|
||||
if i >= self.const_freshen_count {
|
||||
bug!(
|
||||
|
|
|
@ -26,9 +26,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
|
|||
use rustc_macros::extension;
|
||||
pub use rustc_macros::{TypeFoldable, TypeVisitable};
|
||||
use rustc_middle::infer::canonical::{CanonicalQueryInput, CanonicalVarValues};
|
||||
use rustc_middle::infer::unify_key::{
|
||||
ConstVariableOrigin, ConstVariableValue, ConstVidKey, EffectVarValue, EffectVidKey,
|
||||
};
|
||||
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableValue, ConstVidKey};
|
||||
use rustc_middle::mir::ConstraintCategory;
|
||||
use rustc_middle::mir::interpret::{ErrorHandled, EvalToValTreeResult};
|
||||
use rustc_middle::traits::select;
|
||||
|
@ -39,7 +37,7 @@ use rustc_middle::ty::fold::{
|
|||
};
|
||||
use rustc_middle::ty::visit::TypeVisitableExt;
|
||||
use rustc_middle::ty::{
|
||||
self, ConstVid, EffectVid, FloatVid, GenericArg, GenericArgKind, GenericArgs, GenericArgsRef,
|
||||
self, ConstVid, FloatVid, GenericArg, GenericArgKind, GenericArgs, GenericArgsRef,
|
||||
GenericParamDefKind, InferConst, IntVid, Ty, TyCtxt, TyVid,
|
||||
};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
|
@ -117,9 +115,6 @@ pub struct InferCtxtInner<'tcx> {
|
|||
/// Map from floating variable to the kind of float it represents.
|
||||
float_unification_storage: ut::UnificationTableStorage<ty::FloatVid>,
|
||||
|
||||
/// Map from effect variable to the effect param it represents.
|
||||
effect_unification_storage: ut::UnificationTableStorage<EffectVidKey<'tcx>>,
|
||||
|
||||
/// Tracks the set of region variables and the constraints between them.
|
||||
///
|
||||
/// This is initially `Some(_)` but when
|
||||
|
@ -176,7 +171,6 @@ impl<'tcx> InferCtxtInner<'tcx> {
|
|||
const_unification_storage: Default::default(),
|
||||
int_unification_storage: Default::default(),
|
||||
float_unification_storage: Default::default(),
|
||||
effect_unification_storage: Default::default(),
|
||||
region_constraint_storage: Some(Default::default()),
|
||||
region_obligations: vec![],
|
||||
opaque_type_storage: Default::default(),
|
||||
|
@ -228,10 +222,6 @@ impl<'tcx> InferCtxtInner<'tcx> {
|
|||
self.const_unification_storage.with_log(&mut self.undo_log)
|
||||
}
|
||||
|
||||
fn effect_unification_table(&mut self) -> UnificationTable<'_, 'tcx, EffectVidKey<'tcx>> {
|
||||
self.effect_unification_storage.with_log(&mut self.undo_log)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn unwrap_region_constraints(&mut self) -> RegionConstraintCollector<'_, 'tcx> {
|
||||
self.region_constraint_storage
|
||||
|
@ -524,7 +514,6 @@ impl fmt::Display for FixupError {
|
|||
),
|
||||
Ty(_) => write!(f, "unconstrained type"),
|
||||
Const(_) => write!(f, "unconstrained const value"),
|
||||
Effect(_) => write!(f, "unconstrained effect value"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -726,17 +715,6 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
vars
|
||||
}
|
||||
|
||||
pub fn unsolved_effects(&self) -> Vec<ty::Const<'tcx>> {
|
||||
let mut inner = self.inner.borrow_mut();
|
||||
let mut table = inner.effect_unification_table();
|
||||
|
||||
(0..table.len())
|
||||
.map(|i| ty::EffectVid::from_usize(i))
|
||||
.filter(|&vid| table.probe_value(vid).is_unknown())
|
||||
.map(|v| ty::Const::new_infer(self.tcx, ty::InferConst::EffectVar(v)))
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
pub fn sub_regions(
|
||||
&self,
|
||||
|
@ -899,13 +877,6 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
ty::Const::new_var(self.tcx, vid)
|
||||
}
|
||||
|
||||
fn next_effect_var(&self) -> ty::Const<'tcx> {
|
||||
let effect_vid =
|
||||
self.inner.borrow_mut().effect_unification_table().new_key(EffectVarValue::Unknown).vid;
|
||||
|
||||
ty::Const::new_infer(self.tcx, ty::InferConst::EffectVar(effect_vid))
|
||||
}
|
||||
|
||||
pub fn next_int_var(&self) -> Ty<'tcx> {
|
||||
let next_int_var_id =
|
||||
self.inner.borrow_mut().int_unification_table().new_key(ty::IntVarValue::Unknown);
|
||||
|
@ -991,10 +962,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
|
||||
Ty::new_var(self.tcx, ty_var_id).into()
|
||||
}
|
||||
GenericParamDefKind::Const { is_host_effect, .. } => {
|
||||
if is_host_effect {
|
||||
return self.var_for_effect(param);
|
||||
}
|
||||
GenericParamDefKind::Const { .. } => {
|
||||
let origin = ConstVariableOrigin { param_def_id: Some(param.def_id), span };
|
||||
let const_var_id = self
|
||||
.inner
|
||||
|
@ -1007,16 +975,6 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn var_for_effect(&self, param: &ty::GenericParamDef) -> GenericArg<'tcx> {
|
||||
let ty = self
|
||||
.tcx
|
||||
.type_of(param.def_id)
|
||||
.no_bound_vars()
|
||||
.expect("const parameter types cannot be generic");
|
||||
debug_assert_eq!(self.tcx.types.bool, ty);
|
||||
self.next_effect_var().into()
|
||||
}
|
||||
|
||||
/// Given a set of generics defined on a type or impl, returns the generic parameters mapping
|
||||
/// each type/region parameter to a fresh inference variable.
|
||||
pub fn fresh_args_for_item(&self, span: Span, def_id: DefId) -> GenericArgsRef<'tcx> {
|
||||
|
@ -1142,13 +1100,6 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
.probe_value(vid)
|
||||
.known()
|
||||
.unwrap_or(ct),
|
||||
InferConst::EffectVar(vid) => self
|
||||
.inner
|
||||
.borrow_mut()
|
||||
.effect_unification_table()
|
||||
.probe_value(vid)
|
||||
.known()
|
||||
.unwrap_or(ct),
|
||||
InferConst::Fresh(_) => ct,
|
||||
},
|
||||
ty::ConstKind::Param(_)
|
||||
|
@ -1169,10 +1120,6 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
self.inner.borrow_mut().const_unification_table().find(var).vid
|
||||
}
|
||||
|
||||
pub fn root_effect_var(&self, var: ty::EffectVid) -> ty::EffectVid {
|
||||
self.inner.borrow_mut().effect_unification_table().find(var).vid
|
||||
}
|
||||
|
||||
/// Resolves an int var to a rigid int type, if it was constrained to one,
|
||||
/// or else the root int var in the unification table.
|
||||
pub fn opportunistic_resolve_int_var(&self, vid: ty::IntVid) -> Ty<'tcx> {
|
||||
|
@ -1238,10 +1185,6 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn probe_effect_var(&self, vid: EffectVid) -> Option<ty::Const<'tcx>> {
|
||||
self.inner.borrow_mut().effect_unification_table().probe_value(vid).known()
|
||||
}
|
||||
|
||||
/// Attempts to resolve all type/region/const variables in
|
||||
/// `value`. Region inference must have been run already (e.g.,
|
||||
/// by calling `resolve_regions_and_report_errors`). If some
|
||||
|
@ -1511,14 +1454,6 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
ConstVariableValue::Known { .. } => true,
|
||||
}
|
||||
}
|
||||
|
||||
TyOrConstInferVar::Effect(v) => {
|
||||
// If `probe_value` returns `Some`, it never equals
|
||||
// `ty::ConstKind::Infer(ty::InferConst::Effect(v))`.
|
||||
//
|
||||
// Not `inlined_probe_value(v)` because this call site is colder.
|
||||
self.probe_effect_var(v).is_some()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1545,8 +1480,6 @@ pub enum TyOrConstInferVar {
|
|||
|
||||
/// Equivalent to `ty::ConstKind::Infer(ty::InferConst::Var(_))`.
|
||||
Const(ConstVid),
|
||||
/// Equivalent to `ty::ConstKind::Infer(ty::InferConst::EffectVar(_))`.
|
||||
Effect(EffectVid),
|
||||
}
|
||||
|
||||
impl<'tcx> TyOrConstInferVar {
|
||||
|
@ -1577,7 +1510,6 @@ impl<'tcx> TyOrConstInferVar {
|
|||
fn maybe_from_const(ct: ty::Const<'tcx>) -> Option<Self> {
|
||||
match ct.kind() {
|
||||
ty::ConstKind::Infer(InferConst::Var(v)) => Some(TyOrConstInferVar::Const(v)),
|
||||
ty::ConstKind::Infer(InferConst::EffectVar(v)) => Some(TyOrConstInferVar::Effect(v)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -660,7 +660,6 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
ty::ConstKind::Infer(InferConst::EffectVar(_)) => Ok(c),
|
||||
// FIXME: Unevaluated constants are also not rigid, so the current
|
||||
// approach of always relating them structurally is incomplete.
|
||||
//
|
||||
|
|
|
@ -176,9 +176,6 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for FullTypeResolver<'a, 'tcx> {
|
|||
ty::ConstKind::Infer(InferConst::Fresh(_)) => {
|
||||
bug!("Unexpected const in full const resolver: {:?}", c);
|
||||
}
|
||||
ty::ConstKind::Infer(InferConst::EffectVar(evid)) => {
|
||||
return Err(FixupError { unresolved: super::TyOrConstInferVar::Effect(evid) });
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
c.try_super_fold_with(self)
|
||||
|
|
|
@ -4,7 +4,6 @@ use rustc_data_structures::{snapshot_vec as sv, unify as ut};
|
|||
use rustc_middle::infer::unify_key::{ConstVariableValue, ConstVidKey};
|
||||
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
|
||||
use rustc_middle::ty::{self, ConstVid, FloatVid, IntVid, RegionVid, Ty, TyCtxt, TyVid};
|
||||
use rustc_type_ir::EffectVid;
|
||||
use rustc_type_ir::visit::TypeVisitableExt;
|
||||
use tracing::instrument;
|
||||
use ut::UnifyKey;
|
||||
|
@ -129,7 +128,6 @@ struct SnapshotVarData {
|
|||
int_vars: Range<IntVid>,
|
||||
float_vars: Range<FloatVid>,
|
||||
const_vars: (Range<ConstVid>, Vec<ConstVariableOrigin>),
|
||||
effect_vars: Range<EffectVid>,
|
||||
}
|
||||
|
||||
impl SnapshotVarData {
|
||||
|
@ -148,30 +146,16 @@ impl SnapshotVarData {
|
|||
&mut inner.const_unification_table(),
|
||||
vars_pre_snapshot.const_var_len,
|
||||
);
|
||||
let effect_vars = vars_since_snapshot(
|
||||
&inner.effect_unification_table(),
|
||||
vars_pre_snapshot.effect_var_len,
|
||||
);
|
||||
let effect_vars = effect_vars.start.vid..effect_vars.end.vid;
|
||||
|
||||
SnapshotVarData { region_vars, type_vars, int_vars, float_vars, const_vars, effect_vars }
|
||||
SnapshotVarData { region_vars, type_vars, int_vars, float_vars, const_vars }
|
||||
}
|
||||
|
||||
fn is_empty(&self) -> bool {
|
||||
let SnapshotVarData {
|
||||
region_vars,
|
||||
type_vars,
|
||||
int_vars,
|
||||
float_vars,
|
||||
const_vars,
|
||||
effect_vars,
|
||||
} = self;
|
||||
let SnapshotVarData { region_vars, type_vars, int_vars, float_vars, const_vars } = self;
|
||||
region_vars.0.is_empty()
|
||||
&& type_vars.0.is_empty()
|
||||
&& int_vars.is_empty()
|
||||
&& float_vars.is_empty()
|
||||
&& const_vars.0.is_empty()
|
||||
&& effect_vars.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -258,13 +242,6 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for InferenceFudger<'a, 'tcx> {
|
|||
ct
|
||||
}
|
||||
}
|
||||
ty::InferConst::EffectVar(vid) => {
|
||||
if self.snapshot_vars.effect_vars.contains(&vid) {
|
||||
self.infcx.next_effect_var()
|
||||
} else {
|
||||
ct
|
||||
}
|
||||
}
|
||||
ty::InferConst::Fresh(_) => {
|
||||
unreachable!("unexpected fresh infcx var")
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ struct VariableLengths {
|
|||
int_var_len: usize,
|
||||
float_var_len: usize,
|
||||
const_var_len: usize,
|
||||
effect_var_len: usize,
|
||||
}
|
||||
|
||||
impl<'tcx> InferCtxt<'tcx> {
|
||||
|
@ -35,7 +34,6 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
int_var_len: inner.int_unification_table().len(),
|
||||
float_var_len: inner.float_unification_table().len(),
|
||||
const_var_len: inner.const_unification_table().len(),
|
||||
effect_var_len: inner.effect_unification_table().len(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::marker::PhantomData;
|
|||
|
||||
use rustc_data_structures::undo_log::{Rollback, UndoLogs};
|
||||
use rustc_data_structures::{snapshot_vec as sv, unify as ut};
|
||||
use rustc_middle::infer::unify_key::{ConstVidKey, EffectVidKey, RegionVidKey};
|
||||
use rustc_middle::infer::unify_key::{ConstVidKey, RegionVidKey};
|
||||
use rustc_middle::ty::{self, OpaqueHiddenType, OpaqueTypeKey};
|
||||
use tracing::debug;
|
||||
|
||||
|
@ -22,7 +22,6 @@ pub(crate) enum UndoLog<'tcx> {
|
|||
ConstUnificationTable(sv::UndoLog<ut::Delegate<ConstVidKey<'tcx>>>),
|
||||
IntUnificationTable(sv::UndoLog<ut::Delegate<ty::IntVid>>),
|
||||
FloatUnificationTable(sv::UndoLog<ut::Delegate<ty::FloatVid>>),
|
||||
EffectUnificationTable(sv::UndoLog<ut::Delegate<EffectVidKey<'tcx>>>),
|
||||
RegionConstraintCollector(region_constraints::UndoLog<'tcx>),
|
||||
RegionUnificationTable(sv::UndoLog<ut::Delegate<RegionVidKey<'tcx>>>),
|
||||
ProjectionCache(traits::UndoLog<'tcx>),
|
||||
|
@ -50,7 +49,6 @@ impl_from! {
|
|||
FloatUnificationTable(sv::UndoLog<ut::Delegate<ty::FloatVid>>),
|
||||
|
||||
ConstUnificationTable(sv::UndoLog<ut::Delegate<ConstVidKey<'tcx>>>),
|
||||
EffectUnificationTable(sv::UndoLog<ut::Delegate<EffectVidKey<'tcx>>>),
|
||||
|
||||
RegionUnificationTable(sv::UndoLog<ut::Delegate<RegionVidKey<'tcx>>>),
|
||||
ProjectionCache(traits::UndoLog<'tcx>),
|
||||
|
@ -65,7 +63,6 @@ impl<'tcx> Rollback<UndoLog<'tcx>> for InferCtxtInner<'tcx> {
|
|||
UndoLog::ConstUnificationTable(undo) => self.const_unification_storage.reverse(undo),
|
||||
UndoLog::IntUnificationTable(undo) => self.int_unification_storage.reverse(undo),
|
||||
UndoLog::FloatUnificationTable(undo) => self.float_unification_storage.reverse(undo),
|
||||
UndoLog::EffectUnificationTable(undo) => self.effect_unification_storage.reverse(undo),
|
||||
UndoLog::RegionConstraintCollector(undo) => {
|
||||
self.region_constraint_storage.as_mut().unwrap().reverse(undo)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue