mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-07 04:23:30 +00:00
Auto merge of #117139 - compiler-errors:vid-lifetimes, r=BoxyUwU
Get rid of `'tcx` lifetime on `ConstVid`, `EffectVid` These are simply newtyped numbers, so don't really have a reason (per se) to have a lifetime -- `TyVid` and `RegionVid` do not, for example. The only consequence of this is that we need to use a new key type for `UnifyKey` that mentions `'tcx`. This is already done for `RegionVid`, with `RegionVidKey<'tcx>`, but this `UnifyKey` trait implementation may have been the original reason to give `ConstVid` a lifetime. See the changes to `compiler/rustc_middle/src/infer/unify_key.rs` specifically. I consider the code cleaner this way, though -- we removed quite a few unnecessary `'tcx` in the process. This also makes it easier to uplift these two ids to `rustc_type_ir`, which I plan on doing in a follow-up PR. r? `@BoxyUwU`
This commit is contained in:
commit
2e4e2a8f28
@ -152,7 +152,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
CanonicalVarKind::Effect => {
|
CanonicalVarKind::Effect => {
|
||||||
let vid = self.inner.borrow_mut().effect_unification_table().new_key(None);
|
let vid = self.inner.borrow_mut().effect_unification_table().new_key(None).vid;
|
||||||
ty::Const::new_infer(self.tcx, ty::InferConst::EffectVar(vid), self.tcx.types.bool)
|
ty::Const::new_infer(self.tcx, ty::InferConst::EffectVar(vid), self.tcx.types.bool)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
@ -320,7 +320,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||||||
#[instrument(level = "debug", skip(self))]
|
#[instrument(level = "debug", skip(self))]
|
||||||
fn unify_const_variable(
|
fn unify_const_variable(
|
||||||
&self,
|
&self,
|
||||||
target_vid: ty::ConstVid<'tcx>,
|
target_vid: ty::ConstVid,
|
||||||
ct: ty::Const<'tcx>,
|
ct: ty::Const<'tcx>,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
) -> RelateResult<'tcx, ty::Const<'tcx>> {
|
) -> RelateResult<'tcx, ty::Const<'tcx>> {
|
||||||
@ -381,7 +381,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||||||
fn unify_effect_variable(
|
fn unify_effect_variable(
|
||||||
&self,
|
&self,
|
||||||
vid_is_expected: bool,
|
vid_is_expected: bool,
|
||||||
vid: ty::EffectVid<'tcx>,
|
vid: ty::EffectVid,
|
||||||
val: EffectVarValue<'tcx>,
|
val: EffectVarValue<'tcx>,
|
||||||
) -> RelateResult<'tcx, ty::Const<'tcx>> {
|
) -> RelateResult<'tcx, ty::Const<'tcx>> {
|
||||||
self.inner
|
self.inner
|
||||||
|
@ -42,7 +42,7 @@ pub struct TypeFreshener<'a, 'tcx> {
|
|||||||
ty_freshen_count: u32,
|
ty_freshen_count: u32,
|
||||||
const_freshen_count: u32,
|
const_freshen_count: u32,
|
||||||
ty_freshen_map: FxHashMap<ty::InferTy, Ty<'tcx>>,
|
ty_freshen_map: FxHashMap<ty::InferTy, Ty<'tcx>>,
|
||||||
const_freshen_map: FxHashMap<ty::InferConst<'tcx>, ty::Const<'tcx>>,
|
const_freshen_map: FxHashMap<ty::InferConst, ty::Const<'tcx>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
|
impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
|
||||||
@ -79,12 +79,12 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
|
|||||||
fn freshen_const<F>(
|
fn freshen_const<F>(
|
||||||
&mut self,
|
&mut self,
|
||||||
opt_ct: Option<ty::Const<'tcx>>,
|
opt_ct: Option<ty::Const<'tcx>>,
|
||||||
key: ty::InferConst<'tcx>,
|
key: ty::InferConst,
|
||||||
freshener: F,
|
freshener: F,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
) -> ty::Const<'tcx>
|
) -> ty::Const<'tcx>
|
||||||
where
|
where
|
||||||
F: FnOnce(u32) -> ty::InferConst<'tcx>,
|
F: FnOnce(u32) -> ty::InferConst,
|
||||||
{
|
{
|
||||||
if let Some(ct) = opt_ct {
|
if let Some(ct) = opt_ct {
|
||||||
return ct.fold_with(self);
|
return ct.fold_with(self);
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use rustc_middle::infer::unify_key::ConstVidKey;
|
||||||
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
|
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
|
||||||
use rustc_middle::ty::{self, ConstVid, FloatVid, IntVid, RegionVid, Ty, TyCtxt, TyVid};
|
use rustc_middle::ty::{self, ConstVid, FloatVid, IntVid, RegionVid, Ty, TyCtxt, TyVid};
|
||||||
|
|
||||||
@ -23,14 +24,14 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn const_vars_since_snapshot<'tcx>(
|
fn const_vars_since_snapshot<'tcx>(
|
||||||
table: &mut UnificationTable<'_, 'tcx, ConstVid<'tcx>>,
|
table: &mut UnificationTable<'_, 'tcx, ConstVidKey<'tcx>>,
|
||||||
snapshot_var_len: usize,
|
snapshot_var_len: usize,
|
||||||
) -> (Range<ConstVid<'tcx>>, Vec<ConstVariableOrigin>) {
|
) -> (Range<ConstVid>, Vec<ConstVariableOrigin>) {
|
||||||
let range = vars_since_snapshot(table, snapshot_var_len);
|
let range = vars_since_snapshot(table, snapshot_var_len);
|
||||||
(
|
(
|
||||||
range.start..range.end,
|
range.start.vid..range.end.vid,
|
||||||
(range.start.index..range.end.index)
|
(range.start.index()..range.end.index())
|
||||||
.map(|index| table.probe_value(ConstVid::from_index(index)).origin)
|
.map(|index| table.probe_value(ConstVid::from_u32(index)).origin)
|
||||||
.collect(),
|
.collect(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -172,7 +173,7 @@ pub struct InferenceFudger<'a, 'tcx> {
|
|||||||
int_vars: Range<IntVid>,
|
int_vars: Range<IntVid>,
|
||||||
float_vars: Range<FloatVid>,
|
float_vars: Range<FloatVid>,
|
||||||
region_vars: (Range<RegionVid>, Vec<RegionVariableOrigin>),
|
region_vars: (Range<RegionVid>, Vec<RegionVariableOrigin>),
|
||||||
const_vars: (Range<ConstVid<'tcx>>, Vec<ConstVariableOrigin>),
|
const_vars: (Range<ConstVid>, Vec<ConstVariableOrigin>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for InferenceFudger<'a, 'tcx> {
|
impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for InferenceFudger<'a, 'tcx> {
|
||||||
@ -235,7 +236,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for InferenceFudger<'a, 'tcx> {
|
|||||||
if self.const_vars.0.contains(&vid) {
|
if self.const_vars.0.contains(&vid) {
|
||||||
// This variable was created during the fudging.
|
// This variable was created during the fudging.
|
||||||
// Recreate it with a fresh variable here.
|
// Recreate it with a fresh variable here.
|
||||||
let idx = (vid.index - self.const_vars.0.start.index) as usize;
|
let idx = (vid.index() - self.const_vars.0.start.index()) as usize;
|
||||||
let origin = self.const_vars.1[idx];
|
let origin = self.const_vars.1[idx];
|
||||||
self.infcx.next_const_var(ct.ty(), origin)
|
self.infcx.next_const_var(ct.ty(), origin)
|
||||||
} else {
|
} else {
|
||||||
|
@ -17,7 +17,7 @@ pub(super) fn generalize<'tcx, D: GeneralizerDelegate<'tcx>, T: Into<Term<'tcx>>
|
|||||||
infcx: &InferCtxt<'tcx>,
|
infcx: &InferCtxt<'tcx>,
|
||||||
delegate: &mut D,
|
delegate: &mut D,
|
||||||
term: T,
|
term: T,
|
||||||
for_vid: impl Into<ty::TermVid<'tcx>>,
|
for_vid: impl Into<ty::TermVid>,
|
||||||
ambient_variance: ty::Variance,
|
ambient_variance: ty::Variance,
|
||||||
) -> RelateResult<'tcx, Generalization<T>> {
|
) -> RelateResult<'tcx, Generalization<T>> {
|
||||||
let (for_universe, root_vid) = match for_vid.into() {
|
let (for_universe, root_vid) = match for_vid.into() {
|
||||||
@ -27,7 +27,7 @@ pub(super) fn generalize<'tcx, D: GeneralizerDelegate<'tcx>, T: Into<Term<'tcx>>
|
|||||||
),
|
),
|
||||||
ty::TermVid::Const(ct_vid) => (
|
ty::TermVid::Const(ct_vid) => (
|
||||||
infcx.probe_const_var(ct_vid).unwrap_err(),
|
infcx.probe_const_var(ct_vid).unwrap_err(),
|
||||||
ty::TermVid::Const(infcx.inner.borrow_mut().const_unification_table().find(ct_vid)),
|
ty::TermVid::Const(infcx.inner.borrow_mut().const_unification_table().find(ct_vid).vid),
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ struct Generalizer<'me, 'tcx, D> {
|
|||||||
/// The vid of the type variable that is in the process of being
|
/// The vid of the type variable that is in the process of being
|
||||||
/// instantiated. If we find this within the value we are folding,
|
/// instantiated. If we find this within the value we are folding,
|
||||||
/// that means we would have created a cyclic value.
|
/// that means we would have created a cyclic value.
|
||||||
root_vid: ty::TermVid<'tcx>,
|
root_vid: ty::TermVid,
|
||||||
|
|
||||||
/// The universe of the type variable that is in the process of being
|
/// The universe of the type variable that is in the process of being
|
||||||
/// instantiated. If we find anything that this universe cannot name,
|
/// instantiated. If we find anything that this universe cannot name,
|
||||||
@ -376,7 +376,7 @@ where
|
|||||||
// `vid` are related and we'd be inferring an infinitely
|
// `vid` are related and we'd be inferring an infinitely
|
||||||
// deep const.
|
// deep const.
|
||||||
if ty::TermVid::Const(
|
if ty::TermVid::Const(
|
||||||
self.infcx.inner.borrow_mut().const_unification_table().find(vid),
|
self.infcx.inner.borrow_mut().const_unification_table().find(vid).vid,
|
||||||
) == self.root_vid
|
) == self.root_vid
|
||||||
{
|
{
|
||||||
return Err(self.cyclic_term_error());
|
return Err(self.cyclic_term_error());
|
||||||
@ -394,10 +394,14 @@ where
|
|||||||
if self.for_universe.can_name(universe) {
|
if self.for_universe.can_name(universe) {
|
||||||
Ok(c)
|
Ok(c)
|
||||||
} else {
|
} else {
|
||||||
let new_var_id = variable_table.new_key(ConstVarValue {
|
let new_var_id = variable_table
|
||||||
origin: var_value.origin,
|
.new_key(ConstVarValue {
|
||||||
val: ConstVariableValue::Unknown { universe: self.for_universe },
|
origin: var_value.origin,
|
||||||
});
|
val: ConstVariableValue::Unknown {
|
||||||
|
universe: self.for_universe,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.vid;
|
||||||
Ok(ty::Const::new_var(self.tcx(), new_var_id, c.ty()))
|
Ok(ty::Const::new_var(self.tcx(), new_var_id, c.ty()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,9 @@ pub use self::RegionVariableOrigin::*;
|
|||||||
pub use self::SubregionOrigin::*;
|
pub use self::SubregionOrigin::*;
|
||||||
pub use self::ValuePairs::*;
|
pub use self::ValuePairs::*;
|
||||||
pub use combine::ObligationEmittingRelation;
|
pub use combine::ObligationEmittingRelation;
|
||||||
|
use rustc_data_structures::captures::Captures;
|
||||||
use rustc_data_structures::undo_log::UndoLogs;
|
use rustc_data_structures::undo_log::UndoLogs;
|
||||||
|
use rustc_middle::infer::unify_key::{ConstVidKey, EffectVidKey};
|
||||||
|
|
||||||
use self::opaque_types::OpaqueTypeStorage;
|
use self::opaque_types::OpaqueTypeStorage;
|
||||||
pub(crate) use self::undo_log::{InferCtxtUndoLogs, Snapshot, UndoLog};
|
pub(crate) use self::undo_log::{InferCtxtUndoLogs, Snapshot, UndoLog};
|
||||||
@ -40,7 +42,6 @@ use rustc_span::{Span, DUMMY_SP};
|
|||||||
|
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::marker::PhantomData;
|
|
||||||
|
|
||||||
use self::combine::CombineFields;
|
use self::combine::CombineFields;
|
||||||
use self::error_reporting::TypeErrCtxt;
|
use self::error_reporting::TypeErrCtxt;
|
||||||
@ -85,7 +86,7 @@ pub struct InferOk<'tcx, T> {
|
|||||||
pub type InferResult<'tcx, T> = Result<InferOk<'tcx, T>, TypeError<'tcx>>;
|
pub type InferResult<'tcx, T> = Result<InferOk<'tcx, T>, TypeError<'tcx>>;
|
||||||
|
|
||||||
pub type UnitResult<'tcx> = RelateResult<'tcx, ()>; // "unify result"
|
pub type UnitResult<'tcx> = RelateResult<'tcx, ()>; // "unify result"
|
||||||
pub type FixupResult<'tcx, T> = Result<T, FixupError<'tcx>>; // "fixup result"
|
pub type FixupResult<T> = Result<T, FixupError>; // "fixup result"
|
||||||
|
|
||||||
pub(crate) type UnificationTable<'a, 'tcx, T> = ut::UnificationTable<
|
pub(crate) type UnificationTable<'a, 'tcx, T> = ut::UnificationTable<
|
||||||
ut::InPlace<T, &'a mut ut::UnificationStorage<T>, &'a mut InferCtxtUndoLogs<'tcx>>,
|
ut::InPlace<T, &'a mut ut::UnificationStorage<T>, &'a mut InferCtxtUndoLogs<'tcx>>,
|
||||||
@ -108,7 +109,7 @@ pub struct InferCtxtInner<'tcx> {
|
|||||||
type_variable_storage: type_variable::TypeVariableStorage<'tcx>,
|
type_variable_storage: type_variable::TypeVariableStorage<'tcx>,
|
||||||
|
|
||||||
/// Map from const parameter variable to the kind of const it represents.
|
/// Map from const parameter variable to the kind of const it represents.
|
||||||
const_unification_storage: ut::UnificationTableStorage<ty::ConstVid<'tcx>>,
|
const_unification_storage: ut::UnificationTableStorage<ConstVidKey<'tcx>>,
|
||||||
|
|
||||||
/// Map from integral variable to the kind of integer it represents.
|
/// Map from integral variable to the kind of integer it represents.
|
||||||
int_unification_storage: ut::UnificationTableStorage<ty::IntVid>,
|
int_unification_storage: ut::UnificationTableStorage<ty::IntVid>,
|
||||||
@ -117,7 +118,7 @@ pub struct InferCtxtInner<'tcx> {
|
|||||||
float_unification_storage: ut::UnificationTableStorage<ty::FloatVid>,
|
float_unification_storage: ut::UnificationTableStorage<ty::FloatVid>,
|
||||||
|
|
||||||
/// Map from effect variable to the effect param it represents.
|
/// Map from effect variable to the effect param it represents.
|
||||||
effect_unification_storage: ut::UnificationTableStorage<ty::EffectVid<'tcx>>,
|
effect_unification_storage: ut::UnificationTableStorage<EffectVidKey<'tcx>>,
|
||||||
|
|
||||||
/// Tracks the set of region variables and the constraints between them.
|
/// Tracks the set of region variables and the constraints between them.
|
||||||
///
|
///
|
||||||
@ -224,11 +225,11 @@ impl<'tcx> InferCtxtInner<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn const_unification_table(&mut self) -> UnificationTable<'_, 'tcx, ty::ConstVid<'tcx>> {
|
fn const_unification_table(&mut self) -> UnificationTable<'_, 'tcx, ConstVidKey<'tcx>> {
|
||||||
self.const_unification_storage.with_log(&mut self.undo_log)
|
self.const_unification_storage.with_log(&mut self.undo_log)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn effect_unification_table(&mut self) -> UnificationTable<'_, 'tcx, ty::EffectVid<'tcx>> {
|
fn effect_unification_table(&mut self) -> UnificationTable<'_, 'tcx, EffectVidKey<'tcx>> {
|
||||||
self.effect_unification_storage.with_log(&mut self.undo_log)
|
self.effect_unification_storage.with_log(&mut self.undo_log)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,7 +360,7 @@ impl<'tcx> ty::InferCtxtLike for InferCtxt<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn universe_of_ct(&self, ct: ty::InferConst<'tcx>) -> Option<ty::UniverseIndex> {
|
fn universe_of_ct(&self, ct: ty::InferConst) -> Option<ty::UniverseIndex> {
|
||||||
use ty::InferConst::*;
|
use ty::InferConst::*;
|
||||||
match ct {
|
match ct {
|
||||||
// Same issue as with `universe_of_ty`
|
// Same issue as with `universe_of_ty`
|
||||||
@ -548,11 +549,11 @@ pub enum NllRegionVariableOrigin {
|
|||||||
|
|
||||||
// FIXME(eddyb) investigate overlap between this and `TyOrConstInferVar`.
|
// FIXME(eddyb) investigate overlap between this and `TyOrConstInferVar`.
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub enum FixupError<'tcx> {
|
pub enum FixupError {
|
||||||
UnresolvedIntTy(IntVid),
|
UnresolvedIntTy(IntVid),
|
||||||
UnresolvedFloatTy(FloatVid),
|
UnresolvedFloatTy(FloatVid),
|
||||||
UnresolvedTy(TyVid),
|
UnresolvedTy(TyVid),
|
||||||
UnresolvedConst(ConstVid<'tcx>),
|
UnresolvedConst(ConstVid),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// See the `region_obligations` field for more information.
|
/// See the `region_obligations` field for more information.
|
||||||
@ -563,7 +564,7 @@ pub struct RegionObligation<'tcx> {
|
|||||||
pub origin: SubregionOrigin<'tcx>,
|
pub origin: SubregionOrigin<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> fmt::Display for FixupError<'tcx> {
|
impl fmt::Display for FixupError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
use self::FixupError::*;
|
use self::FixupError::*;
|
||||||
|
|
||||||
@ -794,7 +795,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||||||
let mut table = inner.effect_unification_table();
|
let mut table = inner.effect_unification_table();
|
||||||
|
|
||||||
(0..table.len())
|
(0..table.len())
|
||||||
.map(|i| ty::EffectVid { index: i as u32, phantom: PhantomData })
|
.map(|i| ty::EffectVid::from_usize(i))
|
||||||
.filter(|&vid| table.probe_value(vid).is_none())
|
.filter(|&vid| table.probe_value(vid).is_none())
|
||||||
.map(|v| {
|
.map(|v| {
|
||||||
ty::Const::new_infer(self.tcx, ty::InferConst::EffectVar(v), self.tcx.types.bool)
|
ty::Const::new_infer(self.tcx, ty::InferConst::EffectVar(v), self.tcx.types.bool)
|
||||||
@ -1072,15 +1073,20 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||||||
.inner
|
.inner
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.const_unification_table()
|
.const_unification_table()
|
||||||
.new_key(ConstVarValue { origin, val: ConstVariableValue::Unknown { universe } });
|
.new_key(ConstVarValue { origin, val: ConstVariableValue::Unknown { universe } })
|
||||||
|
.vid;
|
||||||
ty::Const::new_var(self.tcx, vid, ty)
|
ty::Const::new_var(self.tcx, vid, ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_const_var_id(&self, origin: ConstVariableOrigin) -> ConstVid<'tcx> {
|
pub fn next_const_var_id(&self, origin: ConstVariableOrigin) -> ConstVid {
|
||||||
self.inner.borrow_mut().const_unification_table().new_key(ConstVarValue {
|
self.inner
|
||||||
origin,
|
.borrow_mut()
|
||||||
val: ConstVariableValue::Unknown { universe: self.universe() },
|
.const_unification_table()
|
||||||
})
|
.new_key(ConstVarValue {
|
||||||
|
origin,
|
||||||
|
val: ConstVariableValue::Unknown { universe: self.universe() },
|
||||||
|
})
|
||||||
|
.vid
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_int_var_id(&self) -> IntVid {
|
fn next_int_var_id(&self) -> IntVid {
|
||||||
@ -1194,11 +1200,15 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||||||
),
|
),
|
||||||
span,
|
span,
|
||||||
};
|
};
|
||||||
let const_var_id =
|
let const_var_id = self
|
||||||
self.inner.borrow_mut().const_unification_table().new_key(ConstVarValue {
|
.inner
|
||||||
|
.borrow_mut()
|
||||||
|
.const_unification_table()
|
||||||
|
.new_key(ConstVarValue {
|
||||||
origin,
|
origin,
|
||||||
val: ConstVariableValue::Unknown { universe: self.universe() },
|
val: ConstVariableValue::Unknown { universe: self.universe() },
|
||||||
});
|
})
|
||||||
|
.vid;
|
||||||
ty::Const::new_var(
|
ty::Const::new_var(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
const_var_id,
|
const_var_id,
|
||||||
@ -1213,7 +1223,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn var_for_effect(&self, param: &ty::GenericParamDef) -> GenericArg<'tcx> {
|
pub fn var_for_effect(&self, param: &ty::GenericParamDef) -> GenericArg<'tcx> {
|
||||||
let effect_vid = self.inner.borrow_mut().effect_unification_table().new_key(None);
|
let effect_vid = self.inner.borrow_mut().effect_unification_table().new_key(None).vid;
|
||||||
let ty = self
|
let ty = self
|
||||||
.tcx
|
.tcx
|
||||||
.type_of(param.def_id)
|
.type_of(param.def_id)
|
||||||
@ -1333,12 +1343,12 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||||||
self.inner.borrow_mut().type_variables().root_var(var)
|
self.inner.borrow_mut().type_variables().root_var(var)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn root_const_var(&self, var: ty::ConstVid<'tcx>) -> ty::ConstVid<'tcx> {
|
pub fn root_const_var(&self, var: ty::ConstVid) -> ty::ConstVid {
|
||||||
self.inner.borrow_mut().const_unification_table().find(var)
|
self.inner.borrow_mut().const_unification_table().find(var).vid
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn root_effect_var(&self, var: ty::EffectVid<'tcx>) -> ty::EffectVid<'tcx> {
|
pub fn root_effect_var(&self, var: ty::EffectVid) -> ty::EffectVid {
|
||||||
self.inner.borrow_mut().effect_unification_table().find(var)
|
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,
|
/// Resolves an int var to a rigid int type, if it was constrained to one,
|
||||||
@ -1402,17 +1412,14 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||||||
value.visit_with(&mut resolve::UnresolvedTypeOrConstFinder::new(self)).break_value()
|
value.visit_with(&mut resolve::UnresolvedTypeOrConstFinder::new(self)).break_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn probe_const_var(
|
pub fn probe_const_var(&self, vid: ty::ConstVid) -> Result<ty::Const<'tcx>, ty::UniverseIndex> {
|
||||||
&self,
|
|
||||||
vid: ty::ConstVid<'tcx>,
|
|
||||||
) -> Result<ty::Const<'tcx>, ty::UniverseIndex> {
|
|
||||||
match self.inner.borrow_mut().const_unification_table().probe_value(vid).val {
|
match self.inner.borrow_mut().const_unification_table().probe_value(vid).val {
|
||||||
ConstVariableValue::Known { value } => Ok(value),
|
ConstVariableValue::Known { value } => Ok(value),
|
||||||
ConstVariableValue::Unknown { universe } => Err(universe),
|
ConstVariableValue::Unknown { universe } => Err(universe),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn probe_effect_var(&self, vid: EffectVid<'tcx>) -> Option<EffectVarValue<'tcx>> {
|
pub fn probe_effect_var(&self, vid: EffectVid) -> Option<EffectVarValue<'tcx>> {
|
||||||
self.inner.borrow_mut().effect_unification_table().probe_value(vid)
|
self.inner.borrow_mut().effect_unification_table().probe_value(vid)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1423,7 +1430,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||||||
///
|
///
|
||||||
/// This method is idempotent, but it not typically not invoked
|
/// This method is idempotent, but it not typically not invoked
|
||||||
/// except during the writeback phase.
|
/// except during the writeback phase.
|
||||||
pub fn fully_resolve<T: TypeFoldable<TyCtxt<'tcx>>>(&self, value: T) -> FixupResult<'tcx, T> {
|
pub fn fully_resolve<T: TypeFoldable<TyCtxt<'tcx>>>(&self, value: T) -> FixupResult<T> {
|
||||||
match resolve::fully_resolve(self, value) {
|
match resolve::fully_resolve(self, value) {
|
||||||
Ok(value) => {
|
Ok(value) => {
|
||||||
if value.has_non_region_infer() {
|
if value.has_non_region_infer() {
|
||||||
@ -1647,11 +1654,11 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_ty_infer_var_definitely_unchanged<'a>(
|
pub fn is_ty_infer_var_definitely_unchanged<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
) -> (impl Fn(TyOrConstInferVar<'tcx>) -> bool + 'a) {
|
) -> (impl Fn(TyOrConstInferVar) -> bool + Captures<'tcx> + 'a) {
|
||||||
// This hoists the borrow/release out of the loop body.
|
// This hoists the borrow/release out of the loop body.
|
||||||
let inner = self.inner.try_borrow();
|
let inner = self.inner.try_borrow();
|
||||||
|
|
||||||
return move |infer_var: TyOrConstInferVar<'tcx>| match (infer_var, &inner) {
|
return move |infer_var: TyOrConstInferVar| match (infer_var, &inner) {
|
||||||
(TyOrConstInferVar::Ty(ty_var), Ok(inner)) => {
|
(TyOrConstInferVar::Ty(ty_var), Ok(inner)) => {
|
||||||
use self::type_variable::TypeVariableValue;
|
use self::type_variable::TypeVariableValue;
|
||||||
|
|
||||||
@ -1674,7 +1681,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||||||
/// inference variables), and it handles both `Ty` and `ty::Const` without
|
/// inference variables), and it handles both `Ty` and `ty::Const` without
|
||||||
/// having to resort to storing full `GenericArg`s in `stalled_on`.
|
/// having to resort to storing full `GenericArg`s in `stalled_on`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn ty_or_const_infer_var_changed(&self, infer_var: TyOrConstInferVar<'tcx>) -> bool {
|
pub fn ty_or_const_infer_var_changed(&self, infer_var: TyOrConstInferVar) -> bool {
|
||||||
match infer_var {
|
match infer_var {
|
||||||
TyOrConstInferVar::Ty(v) => {
|
TyOrConstInferVar::Ty(v) => {
|
||||||
use self::type_variable::TypeVariableValue;
|
use self::type_variable::TypeVariableValue;
|
||||||
@ -1781,7 +1788,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
/// Helper for [InferCtxt::ty_or_const_infer_var_changed] (see comment on that), currently
|
/// Helper for [InferCtxt::ty_or_const_infer_var_changed] (see comment on that), currently
|
||||||
/// used only for `traits::fulfill`'s list of `stalled_on` inference variables.
|
/// used only for `traits::fulfill`'s list of `stalled_on` inference variables.
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub enum TyOrConstInferVar<'tcx> {
|
pub enum TyOrConstInferVar {
|
||||||
/// Equivalent to `ty::Infer(ty::TyVar(_))`.
|
/// Equivalent to `ty::Infer(ty::TyVar(_))`.
|
||||||
Ty(TyVid),
|
Ty(TyVid),
|
||||||
/// Equivalent to `ty::Infer(ty::IntVar(_))`.
|
/// Equivalent to `ty::Infer(ty::IntVar(_))`.
|
||||||
@ -1790,12 +1797,12 @@ pub enum TyOrConstInferVar<'tcx> {
|
|||||||
TyFloat(FloatVid),
|
TyFloat(FloatVid),
|
||||||
|
|
||||||
/// Equivalent to `ty::ConstKind::Infer(ty::InferConst::Var(_))`.
|
/// Equivalent to `ty::ConstKind::Infer(ty::InferConst::Var(_))`.
|
||||||
Const(ConstVid<'tcx>),
|
Const(ConstVid),
|
||||||
/// Equivalent to `ty::ConstKind::Infer(ty::InferConst::EffectVar(_))`.
|
/// Equivalent to `ty::ConstKind::Infer(ty::InferConst::EffectVar(_))`.
|
||||||
Effect(EffectVid<'tcx>),
|
Effect(EffectVid),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TyOrConstInferVar<'tcx> {
|
impl<'tcx> TyOrConstInferVar {
|
||||||
/// Tries to extract an inference variable from a type or a constant, returns `None`
|
/// Tries to extract an inference variable from a type or a constant, returns `None`
|
||||||
/// for types other than `ty::Infer(_)` (or `InferTy::Fresh*`) and
|
/// for types other than `ty::Infer(_)` (or `InferTy::Fresh*`) and
|
||||||
/// for constants other than `ty::ConstKind::Infer(_)` (or `InferConst::Fresh`).
|
/// for constants other than `ty::ConstKind::Infer(_)` (or `InferConst::Fresh`).
|
||||||
|
@ -192,7 +192,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for UnresolvedTypeOrConstFinder<'a, 'tc
|
|||||||
/// Full type resolution replaces all type and region variables with
|
/// Full type resolution replaces all type and region variables with
|
||||||
/// their concrete results. If any variable cannot be replaced (never unified, etc)
|
/// their concrete results. If any variable cannot be replaced (never unified, etc)
|
||||||
/// then an `Err` result is returned.
|
/// then an `Err` result is returned.
|
||||||
pub fn fully_resolve<'tcx, T>(infcx: &InferCtxt<'tcx>, value: T) -> FixupResult<'tcx, T>
|
pub fn fully_resolve<'tcx, T>(infcx: &InferCtxt<'tcx>, value: T) -> FixupResult<T>
|
||||||
where
|
where
|
||||||
T: TypeFoldable<TyCtxt<'tcx>>,
|
T: TypeFoldable<TyCtxt<'tcx>>,
|
||||||
{
|
{
|
||||||
@ -206,7 +206,7 @@ struct FullTypeResolver<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for FullTypeResolver<'a, 'tcx> {
|
impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for FullTypeResolver<'a, 'tcx> {
|
||||||
type Error = FixupError<'tcx>;
|
type Error = FixupError;
|
||||||
|
|
||||||
fn interner(&self) -> TyCtxt<'tcx> {
|
fn interner(&self) -> TyCtxt<'tcx> {
|
||||||
self.infcx.tcx
|
self.infcx.tcx
|
||||||
|
@ -3,7 +3,7 @@ use std::marker::PhantomData;
|
|||||||
use rustc_data_structures::snapshot_vec as sv;
|
use rustc_data_structures::snapshot_vec as sv;
|
||||||
use rustc_data_structures::undo_log::{Rollback, UndoLogs};
|
use rustc_data_structures::undo_log::{Rollback, UndoLogs};
|
||||||
use rustc_data_structures::unify as ut;
|
use rustc_data_structures::unify as ut;
|
||||||
use rustc_middle::infer::unify_key::RegionVidKey;
|
use rustc_middle::infer::unify_key::{ConstVidKey, EffectVidKey, RegionVidKey};
|
||||||
use rustc_middle::ty::{self, OpaqueHiddenType, OpaqueTypeKey};
|
use rustc_middle::ty::{self, OpaqueHiddenType, OpaqueTypeKey};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -21,10 +21,10 @@ pub struct Snapshot<'tcx> {
|
|||||||
pub(crate) enum UndoLog<'tcx> {
|
pub(crate) enum UndoLog<'tcx> {
|
||||||
OpaqueTypes(OpaqueTypeKey<'tcx>, Option<OpaqueHiddenType<'tcx>>),
|
OpaqueTypes(OpaqueTypeKey<'tcx>, Option<OpaqueHiddenType<'tcx>>),
|
||||||
TypeVariables(type_variable::UndoLog<'tcx>),
|
TypeVariables(type_variable::UndoLog<'tcx>),
|
||||||
ConstUnificationTable(sv::UndoLog<ut::Delegate<ty::ConstVid<'tcx>>>),
|
ConstUnificationTable(sv::UndoLog<ut::Delegate<ConstVidKey<'tcx>>>),
|
||||||
IntUnificationTable(sv::UndoLog<ut::Delegate<ty::IntVid>>),
|
IntUnificationTable(sv::UndoLog<ut::Delegate<ty::IntVid>>),
|
||||||
FloatUnificationTable(sv::UndoLog<ut::Delegate<ty::FloatVid>>),
|
FloatUnificationTable(sv::UndoLog<ut::Delegate<ty::FloatVid>>),
|
||||||
EffectUnificationTable(sv::UndoLog<ut::Delegate<ty::EffectVid<'tcx>>>),
|
EffectUnificationTable(sv::UndoLog<ut::Delegate<EffectVidKey<'tcx>>>),
|
||||||
RegionConstraintCollector(region_constraints::UndoLog<'tcx>),
|
RegionConstraintCollector(region_constraints::UndoLog<'tcx>),
|
||||||
RegionUnificationTable(sv::UndoLog<ut::Delegate<RegionVidKey<'tcx>>>),
|
RegionUnificationTable(sv::UndoLog<ut::Delegate<RegionVidKey<'tcx>>>),
|
||||||
ProjectionCache(traits::UndoLog<'tcx>),
|
ProjectionCache(traits::UndoLog<'tcx>),
|
||||||
@ -56,9 +56,9 @@ impl_from! {
|
|||||||
IntUnificationTable(sv::UndoLog<ut::Delegate<ty::IntVid>>),
|
IntUnificationTable(sv::UndoLog<ut::Delegate<ty::IntVid>>),
|
||||||
|
|
||||||
FloatUnificationTable(sv::UndoLog<ut::Delegate<ty::FloatVid>>),
|
FloatUnificationTable(sv::UndoLog<ut::Delegate<ty::FloatVid>>),
|
||||||
EffectUnificationTable(sv::UndoLog<ut::Delegate<ty::EffectVid<'tcx>>>),
|
EffectUnificationTable(sv::UndoLog<ut::Delegate<EffectVidKey<'tcx>>>),
|
||||||
|
|
||||||
ConstUnificationTable(sv::UndoLog<ut::Delegate<ty::ConstVid<'tcx>>>),
|
ConstUnificationTable(sv::UndoLog<ut::Delegate<ConstVidKey<'tcx>>>),
|
||||||
|
|
||||||
RegionUnificationTable(sv::UndoLog<ut::Delegate<RegionVidKey<'tcx>>>),
|
RegionUnificationTable(sv::UndoLog<ut::Delegate<RegionVidKey<'tcx>>>),
|
||||||
ProjectionCache(traits::UndoLog<'tcx>),
|
ProjectionCache(traits::UndoLog<'tcx>),
|
||||||
|
@ -141,18 +141,30 @@ pub struct ConstVarValue<'tcx> {
|
|||||||
pub val: ConstVariableValue<'tcx>,
|
pub val: ConstVariableValue<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> UnifyKey for ty::ConstVid<'tcx> {
|
#[derive(PartialEq, Copy, Clone, Debug)]
|
||||||
|
pub struct ConstVidKey<'tcx> {
|
||||||
|
pub vid: ty::ConstVid,
|
||||||
|
pub phantom: PhantomData<ty::Const<'tcx>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'tcx> From<ty::ConstVid> for ConstVidKey<'tcx> {
|
||||||
|
fn from(vid: ty::ConstVid) -> Self {
|
||||||
|
ConstVidKey { vid, phantom: PhantomData }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'tcx> UnifyKey for ConstVidKey<'tcx> {
|
||||||
type Value = ConstVarValue<'tcx>;
|
type Value = ConstVarValue<'tcx>;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self) -> u32 {
|
fn index(&self) -> u32 {
|
||||||
self.index
|
self.vid.as_u32()
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_index(i: u32) -> Self {
|
fn from_index(i: u32) -> Self {
|
||||||
ty::ConstVid { index: i, phantom: PhantomData }
|
ConstVidKey::from(ty::ConstVid::from_u32(i))
|
||||||
}
|
}
|
||||||
fn tag() -> &'static str {
|
fn tag() -> &'static str {
|
||||||
"ConstVid"
|
"ConstVidKey"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,17 +236,29 @@ impl<'tcx> UnifyValue for EffectVarValue<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> UnifyKey for ty::EffectVid<'tcx> {
|
#[derive(PartialEq, Copy, Clone, Debug)]
|
||||||
|
pub struct EffectVidKey<'tcx> {
|
||||||
|
pub vid: ty::EffectVid,
|
||||||
|
pub phantom: PhantomData<EffectVarValue<'tcx>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'tcx> From<ty::EffectVid> for EffectVidKey<'tcx> {
|
||||||
|
fn from(vid: ty::EffectVid) -> Self {
|
||||||
|
EffectVidKey { vid, phantom: PhantomData }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'tcx> UnifyKey for EffectVidKey<'tcx> {
|
||||||
type Value = Option<EffectVarValue<'tcx>>;
|
type Value = Option<EffectVarValue<'tcx>>;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self) -> u32 {
|
fn index(&self) -> u32 {
|
||||||
self.index
|
self.vid.as_u32()
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_index(i: u32) -> Self {
|
fn from_index(i: u32) -> Self {
|
||||||
ty::EffectVid { index: i, phantom: PhantomData }
|
EffectVidKey::from(ty::EffectVid::from_u32(i))
|
||||||
}
|
}
|
||||||
fn tag() -> &'static str {
|
fn tag() -> &'static str {
|
||||||
"EffectVid"
|
"EffectVidKey"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ impl<'tcx> Const<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_var(tcx: TyCtxt<'tcx>, infer: ty::ConstVid<'tcx>, ty: Ty<'tcx>) -> Const<'tcx> {
|
pub fn new_var(tcx: TyCtxt<'tcx>, infer: ty::ConstVid, ty: Ty<'tcx>) -> Const<'tcx> {
|
||||||
Const::new(tcx, ty::ConstKind::Infer(ty::InferConst::Var(infer)), ty)
|
Const::new(tcx, ty::ConstKind::Infer(ty::InferConst::Var(infer)), ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ impl<'tcx> Const<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_infer(tcx: TyCtxt<'tcx>, infer: ty::InferConst<'tcx>, ty: Ty<'tcx>) -> Const<'tcx> {
|
pub fn new_infer(tcx: TyCtxt<'tcx>, infer: ty::InferConst, ty: Ty<'tcx>) -> Const<'tcx> {
|
||||||
Const::new(tcx, ty::ConstKind::Infer(infer), ty)
|
Const::new(tcx, ty::ConstKind::Infer(infer), ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,19 +80,19 @@ static_assert_size!(super::ConstKind<'_>, 32);
|
|||||||
|
|
||||||
/// An inference variable for a const, for use in const generics.
|
/// An inference variable for a const, for use in const generics.
|
||||||
#[derive(Copy, Clone, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable, Hash)]
|
#[derive(Copy, Clone, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable, Hash)]
|
||||||
pub enum InferConst<'tcx> {
|
pub enum InferConst {
|
||||||
/// Infer the value of the const.
|
/// Infer the value of the const.
|
||||||
Var(ty::ConstVid<'tcx>),
|
Var(ty::ConstVid),
|
||||||
/// Infer the value of the effect.
|
/// Infer the value of the effect.
|
||||||
///
|
///
|
||||||
/// For why this is separate from the `Var` variant above, see the
|
/// For why this is separate from the `Var` variant above, see the
|
||||||
/// documentation on `EffectVid`.
|
/// documentation on `EffectVid`.
|
||||||
EffectVar(ty::EffectVid<'tcx>),
|
EffectVar(ty::EffectVid),
|
||||||
/// A fresh const variable. See `infer::freshen` for more details.
|
/// A fresh const variable. See `infer::freshen` for more details.
|
||||||
Fresh(u32),
|
Fresh(u32),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<CTX> HashStable<CTX> for InferConst<'_> {
|
impl<CTX> HashStable<CTX> for InferConst {
|
||||||
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
|
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
|
||||||
match self {
|
match self {
|
||||||
InferConst::Var(_) | InferConst::EffectVar(_) => {
|
InferConst::Var(_) | InferConst::EffectVar(_) => {
|
||||||
|
@ -100,7 +100,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
|
|||||||
type PolyFnSig = PolyFnSig<'tcx>;
|
type PolyFnSig = PolyFnSig<'tcx>;
|
||||||
type AllocId = crate::mir::interpret::AllocId;
|
type AllocId = crate::mir::interpret::AllocId;
|
||||||
type Const = ty::Const<'tcx>;
|
type Const = ty::Const<'tcx>;
|
||||||
type InferConst = ty::InferConst<'tcx>;
|
type InferConst = ty::InferConst;
|
||||||
type AliasConst = ty::UnevaluatedConst<'tcx>;
|
type AliasConst = ty::UnevaluatedConst<'tcx>;
|
||||||
type PlaceholderConst = ty::PlaceholderConst<'tcx>;
|
type PlaceholderConst = ty::PlaceholderConst<'tcx>;
|
||||||
type ParamConst = ty::ParamConst;
|
type ParamConst = ty::ParamConst;
|
||||||
|
@ -1084,19 +1084,19 @@ impl ParamTerm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
||||||
pub enum TermVid<'tcx> {
|
pub enum TermVid {
|
||||||
Ty(ty::TyVid),
|
Ty(ty::TyVid),
|
||||||
Const(ty::ConstVid<'tcx>),
|
Const(ty::ConstVid),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ty::TyVid> for TermVid<'_> {
|
impl From<ty::TyVid> for TermVid {
|
||||||
fn from(value: ty::TyVid) -> Self {
|
fn from(value: ty::TyVid) -> Self {
|
||||||
TermVid::Ty(value)
|
TermVid::Ty(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> From<ty::ConstVid<'tcx>> for TermVid<'tcx> {
|
impl From<ty::ConstVid> for TermVid {
|
||||||
fn from(value: ty::ConstVid<'tcx>) -> Self {
|
fn from(value: ty::ConstVid) -> Self {
|
||||||
TermVid::Const(value)
|
TermVid::Const(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1194,7 +1194,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn const_infer_name(&self, _: ty::ConstVid<'tcx>) -> Option<Symbol> {
|
fn const_infer_name(&self, _: ty::ConstVid) -> Option<Symbol> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1742,7 +1742,7 @@ pub struct FmtPrinterData<'a, 'tcx> {
|
|||||||
pub region_highlight_mode: RegionHighlightMode<'tcx>,
|
pub region_highlight_mode: RegionHighlightMode<'tcx>,
|
||||||
|
|
||||||
pub ty_infer_name_resolver: Option<Box<dyn Fn(ty::TyVid) -> Option<Symbol> + 'a>>,
|
pub ty_infer_name_resolver: Option<Box<dyn Fn(ty::TyVid) -> Option<Symbol> + 'a>>,
|
||||||
pub const_infer_name_resolver: Option<Box<dyn Fn(ty::ConstVid<'tcx>) -> Option<Symbol> + 'a>>,
|
pub const_infer_name_resolver: Option<Box<dyn Fn(ty::ConstVid) -> Option<Symbol> + 'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> Deref for FmtPrinter<'a, 'tcx> {
|
impl<'a, 'tcx> Deref for FmtPrinter<'a, 'tcx> {
|
||||||
@ -2082,7 +2082,7 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
|
|||||||
self.printed_type_count = 0;
|
self.printed_type_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn const_infer_name(&self, id: ty::ConstVid<'tcx>) -> Option<Symbol> {
|
fn const_infer_name(&self, id: ty::ConstVid) -> Option<Symbol> {
|
||||||
self.0.const_infer_name_resolver.as_ref().and_then(|func| func(id))
|
self.0.const_infer_name_resolver.as_ref().and_then(|func| func(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,18 +128,6 @@ impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::FnSig<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> fmt::Debug for ty::ConstVid<'tcx> {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
write!(f, "?{}c", self.index)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for ty::EffectVid<'_> {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
write!(f, "?{}e", self.index)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> fmt::Debug for ty::TraitRef<'tcx> {
|
impl<'tcx> fmt::Debug for ty::TraitRef<'tcx> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
with_no_trimmed_paths!(fmt::Display::fmt(self, f))
|
with_no_trimmed_paths!(fmt::Display::fmt(self, f))
|
||||||
@ -251,7 +239,7 @@ impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for AliasTy<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> fmt::Debug for ty::InferConst<'tcx> {
|
impl fmt::Debug for ty::InferConst {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
InferConst::Var(var) => write!(f, "{var:?}"),
|
InferConst::Var(var) => write!(f, "{var:?}"),
|
||||||
@ -260,7 +248,7 @@ impl<'tcx> fmt::Debug for ty::InferConst<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::InferConst<'tcx> {
|
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::InferConst {
|
||||||
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
|
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
|
||||||
this: WithInfcx<'_, Infcx, &Self>,
|
this: WithInfcx<'_, Infcx, &Self>,
|
||||||
f: &mut core::fmt::Formatter<'_>,
|
f: &mut core::fmt::Formatter<'_>,
|
||||||
@ -269,8 +257,8 @@ impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::InferConst<'tcx> {
|
|||||||
match this.infcx.universe_of_ct(*this.data) {
|
match this.infcx.universe_of_ct(*this.data) {
|
||||||
None => write!(f, "{:?}", this.data),
|
None => write!(f, "{:?}", this.data),
|
||||||
Some(universe) => match *this.data {
|
Some(universe) => match *this.data {
|
||||||
Var(vid) => write!(f, "?{}_{}c", vid.index, universe.index()),
|
Var(vid) => write!(f, "?{}_{}c", vid.index(), universe.index()),
|
||||||
EffectVar(vid) => write!(f, "?{}_{}e", vid.index, universe.index()),
|
EffectVar(vid) => write!(f, "?{}_{}e", vid.index(), universe.index()),
|
||||||
Fresh(_) => {
|
Fresh(_) => {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
@ -862,7 +850,7 @@ impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for ty::Const<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for InferConst<'tcx> {
|
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for InferConst {
|
||||||
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
|
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
|
||||||
self,
|
self,
|
||||||
_folder: &mut F,
|
_folder: &mut F,
|
||||||
@ -871,7 +859,7 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for InferConst<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for InferConst<'tcx> {
|
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for InferConst {
|
||||||
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(
|
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(
|
||||||
&self,
|
&self,
|
||||||
_visitor: &mut V,
|
_visitor: &mut V,
|
||||||
|
@ -29,7 +29,6 @@ use std::assert_matches::debug_assert_matches;
|
|||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::marker::PhantomData;
|
|
||||||
use std::ops::{ControlFlow, Deref, Range};
|
use std::ops::{ControlFlow, Deref, Range};
|
||||||
use ty::util::IntTypeExt;
|
use ty::util::IntTypeExt;
|
||||||
|
|
||||||
@ -1583,26 +1582,22 @@ impl fmt::Debug for EarlyBoundRegion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A **`const`** **v**ariable **ID**.
|
rustc_index::newtype_index! {
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
/// A **`const`** **v**ariable **ID**.
|
||||||
#[derive(HashStable, TyEncodable, TyDecodable)]
|
#[debug_format = "?{}c"]
|
||||||
pub struct ConstVid<'tcx> {
|
pub struct ConstVid {}
|
||||||
pub index: u32,
|
|
||||||
pub phantom: PhantomData<&'tcx ()>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An **effect** **v**ariable **ID**.
|
rustc_index::newtype_index! {
|
||||||
///
|
/// An **effect** **v**ariable **ID**.
|
||||||
/// Handling effect infer variables happens separately from const infer variables
|
///
|
||||||
/// because we do not want to reuse any of the const infer machinery. If we try to
|
/// Handling effect infer variables happens separately from const infer variables
|
||||||
/// relate an effect variable with a normal one, we would ICE, which can catch bugs
|
/// because we do not want to reuse any of the const infer machinery. If we try to
|
||||||
/// where we are not correctly using the effect var for an effect param. Fallback
|
/// relate an effect variable with a normal one, we would ICE, which can catch bugs
|
||||||
/// is also implemented on top of having separate effect and normal const variables.
|
/// where we are not correctly using the effect var for an effect param. Fallback
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
/// is also implemented on top of having separate effect and normal const variables.
|
||||||
#[derive(TyEncodable, TyDecodable)]
|
#[debug_format = "?{}e"]
|
||||||
pub struct EffectVid<'tcx> {
|
pub struct EffectVid {}
|
||||||
pub index: u32,
|
|
||||||
pub phantom: PhantomData<&'tcx ()>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rustc_index::newtype_index! {
|
rustc_index::newtype_index! {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use crate::infer::{InferCtxt, TyOrConstInferVar};
|
use crate::infer::{InferCtxt, TyOrConstInferVar};
|
||||||
|
use rustc_data_structures::captures::Captures;
|
||||||
use rustc_data_structures::obligation_forest::ProcessResult;
|
use rustc_data_structures::obligation_forest::ProcessResult;
|
||||||
use rustc_data_structures::obligation_forest::{Error, ForestObligation, Outcome};
|
use rustc_data_structures::obligation_forest::{Error, ForestObligation, Outcome};
|
||||||
use rustc_data_structures::obligation_forest::{ObligationForest, ObligationProcessor};
|
use rustc_data_structures::obligation_forest::{ObligationForest, ObligationProcessor};
|
||||||
@ -68,7 +69,7 @@ pub struct PendingPredicateObligation<'tcx> {
|
|||||||
// should mostly optimize for reading speed, while modifying is not as relevant.
|
// should mostly optimize for reading speed, while modifying is not as relevant.
|
||||||
//
|
//
|
||||||
// For whatever reason using a boxed slice is slower than using a `Vec` here.
|
// For whatever reason using a boxed slice is slower than using a `Vec` here.
|
||||||
pub stalled_on: Vec<TyOrConstInferVar<'tcx>>,
|
pub stalled_on: Vec<TyOrConstInferVar>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// `PendingPredicateObligation` is used a lot. Make sure it doesn't unintentionally get bigger.
|
// `PendingPredicateObligation` is used a lot. Make sure it doesn't unintentionally get bigger.
|
||||||
@ -669,7 +670,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
trait_obligation: PolyTraitObligation<'tcx>,
|
trait_obligation: PolyTraitObligation<'tcx>,
|
||||||
stalled_on: &mut Vec<TyOrConstInferVar<'tcx>>,
|
stalled_on: &mut Vec<TyOrConstInferVar>,
|
||||||
) -> ProcessResult<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>> {
|
) -> ProcessResult<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>> {
|
||||||
let infcx = self.selcx.infcx;
|
let infcx = self.selcx.infcx;
|
||||||
if obligation.predicate.is_global() && !self.selcx.is_intercrate() {
|
if obligation.predicate.is_global() && !self.selcx.is_intercrate() {
|
||||||
@ -722,7 +723,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
project_obligation: PolyProjectionObligation<'tcx>,
|
project_obligation: PolyProjectionObligation<'tcx>,
|
||||||
stalled_on: &mut Vec<TyOrConstInferVar<'tcx>>,
|
stalled_on: &mut Vec<TyOrConstInferVar>,
|
||||||
) -> ProcessResult<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>> {
|
) -> ProcessResult<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>> {
|
||||||
let tcx = self.selcx.tcx();
|
let tcx = self.selcx.tcx();
|
||||||
|
|
||||||
@ -775,7 +776,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
|
|||||||
fn args_infer_vars<'a, 'tcx>(
|
fn args_infer_vars<'a, 'tcx>(
|
||||||
selcx: &SelectionContext<'a, 'tcx>,
|
selcx: &SelectionContext<'a, 'tcx>,
|
||||||
args: ty::Binder<'tcx, GenericArgsRef<'tcx>>,
|
args: ty::Binder<'tcx, GenericArgsRef<'tcx>>,
|
||||||
) -> impl Iterator<Item = TyOrConstInferVar<'tcx>> {
|
) -> impl Iterator<Item = TyOrConstInferVar> + Captures<'tcx> {
|
||||||
selcx
|
selcx
|
||||||
.infcx
|
.infcx
|
||||||
.resolve_vars_if_possible(args)
|
.resolve_vars_if_possible(args)
|
||||||
|
Loading…
Reference in New Issue
Block a user