stop categorizing inference variables as diverging when created
Instead, we now rely on the code that looks for a NeverToAny adjustment.
This commit is contained in:
parent
1c004f2d43
commit
bc2ece2a8d
5 changed files with 17 additions and 63 deletions
|
@ -22,6 +22,7 @@
|
||||||
// is also useful to track which value is the "expected" value in
|
// is also useful to track which value is the "expected" value in
|
||||||
// terms of error reporting.
|
// terms of error reporting.
|
||||||
|
|
||||||
|
use super::equate::Equate;
|
||||||
use super::glb::Glb;
|
use super::glb::Glb;
|
||||||
use super::lub::Lub;
|
use super::lub::Lub;
|
||||||
use super::sub::Sub;
|
use super::sub::Sub;
|
||||||
|
@ -29,7 +30,6 @@ use super::type_variable::TypeVariableValue;
|
||||||
use super::unify_key::replace_if_possible;
|
use super::unify_key::replace_if_possible;
|
||||||
use super::unify_key::{ConstVarValue, ConstVariableValue};
|
use super::unify_key::{ConstVarValue, ConstVariableValue};
|
||||||
use super::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
|
use super::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
|
||||||
use super::{equate::Equate, type_variable::Diverging};
|
|
||||||
use super::{InferCtxt, MiscVariable, TypeTrace};
|
use super::{InferCtxt, MiscVariable, TypeTrace};
|
||||||
|
|
||||||
use crate::traits::{Obligation, PredicateObligations};
|
use crate::traits::{Obligation, PredicateObligations};
|
||||||
|
@ -645,7 +645,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
|
||||||
.inner
|
.inner
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.type_variables()
|
.type_variables()
|
||||||
.new_var(self.for_universe, Diverging::NotDiverging, origin);
|
.new_var(self.for_universe, origin);
|
||||||
let u = self.tcx().mk_ty_var(new_var_id);
|
let u = self.tcx().mk_ty_var(new_var_id);
|
||||||
|
|
||||||
// Record that we replaced `vid` with `new_var_id` as part of a generalization
|
// Record that we replaced `vid` with `new_var_id` as part of a generalization
|
||||||
|
@ -885,11 +885,12 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
|
||||||
|
|
||||||
let origin =
|
let origin =
|
||||||
*self.infcx.inner.borrow_mut().type_variables().var_origin(vid);
|
*self.infcx.inner.borrow_mut().type_variables().var_origin(vid);
|
||||||
let new_var_id = self.infcx.inner.borrow_mut().type_variables().new_var(
|
let new_var_id = self
|
||||||
self.for_universe,
|
.infcx
|
||||||
Diverging::NotDiverging,
|
.inner
|
||||||
origin,
|
.borrow_mut()
|
||||||
);
|
.type_variables()
|
||||||
|
.new_var(self.for_universe, origin);
|
||||||
let u = self.tcx().mk_ty_var(new_var_id);
|
let u = self.tcx().mk_ty_var(new_var_id);
|
||||||
debug!(
|
debug!(
|
||||||
"ConstInferUnifier: replacing original vid={:?} with new={:?}",
|
"ConstInferUnifier: replacing original vid={:?} with new={:?}",
|
||||||
|
|
|
@ -46,7 +46,7 @@ use self::region_constraints::{GenericKind, RegionConstraintData, VarInfos, Veri
|
||||||
use self::region_constraints::{
|
use self::region_constraints::{
|
||||||
RegionConstraintCollector, RegionConstraintStorage, RegionSnapshot,
|
RegionConstraintCollector, RegionConstraintStorage, RegionSnapshot,
|
||||||
};
|
};
|
||||||
use self::type_variable::{Diverging, TypeVariableOrigin, TypeVariableOriginKind};
|
use self::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||||
|
|
||||||
pub mod at;
|
pub mod at;
|
||||||
pub mod canonical;
|
pub mod canonical;
|
||||||
|
@ -701,23 +701,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
t.fold_with(&mut self.freshener())
|
t.fold_with(&mut self.freshener())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether `ty` is a diverging type variable or not.
|
|
||||||
/// (If `ty` is not a type variable at all, returns not diverging.)
|
|
||||||
///
|
|
||||||
/// No attempt is made to resolve `ty`.
|
|
||||||
pub fn type_var_diverges(&'a self, ty: Ty<'_>) -> Diverging {
|
|
||||||
match *ty.kind() {
|
|
||||||
ty::Infer(ty::TyVar(vid)) => self.ty_vid_diverges(vid),
|
|
||||||
_ => Diverging::NotDiverging,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if the type inference variable `vid` was created
|
|
||||||
/// as a diverging type variable. No attempt is made to resolve `vid`.
|
|
||||||
pub fn ty_vid_diverges(&'a self, vid: ty::TyVid) -> Diverging {
|
|
||||||
self.inner.borrow_mut().type_variables().var_diverges(vid)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the origin of the type variable identified by `vid`, or `None`
|
/// Returns the origin of the type variable identified by `vid`, or `None`
|
||||||
/// if this is not a type variable.
|
/// if this is not a type variable.
|
||||||
///
|
///
|
||||||
|
@ -1081,12 +1064,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
self.inner.borrow_mut().type_variables().num_vars()
|
self.inner.borrow_mut().type_variables().num_vars()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_ty_var_id(&self, diverging: Diverging, origin: TypeVariableOrigin) -> TyVid {
|
pub fn next_ty_var_id(&self, origin: TypeVariableOrigin) -> TyVid {
|
||||||
self.inner.borrow_mut().type_variables().new_var(self.universe(), diverging, origin)
|
self.inner.borrow_mut().type_variables().new_var(self.universe(), origin)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_ty_var(&self, origin: TypeVariableOrigin) -> Ty<'tcx> {
|
pub fn next_ty_var(&self, origin: TypeVariableOrigin) -> Ty<'tcx> {
|
||||||
self.tcx.mk_ty_var(self.next_ty_var_id(Diverging::NotDiverging, origin))
|
self.tcx.mk_ty_var(self.next_ty_var_id(origin))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_ty_var_in_universe(
|
pub fn next_ty_var_in_universe(
|
||||||
|
@ -1094,18 +1077,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
origin: TypeVariableOrigin,
|
origin: TypeVariableOrigin,
|
||||||
universe: ty::UniverseIndex,
|
universe: ty::UniverseIndex,
|
||||||
) -> Ty<'tcx> {
|
) -> Ty<'tcx> {
|
||||||
let vid = self.inner.borrow_mut().type_variables().new_var(
|
let vid = self.inner.borrow_mut().type_variables().new_var(universe, origin);
|
||||||
universe,
|
|
||||||
Diverging::NotDiverging,
|
|
||||||
origin,
|
|
||||||
);
|
|
||||||
self.tcx.mk_ty_var(vid)
|
self.tcx.mk_ty_var(vid)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_diverging_ty_var(&self, origin: TypeVariableOrigin) -> Ty<'tcx> {
|
|
||||||
self.tcx.mk_ty_var(self.next_ty_var_id(Diverging::Diverges, origin))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn next_const_var(
|
pub fn next_const_var(
|
||||||
&self,
|
&self,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
|
@ -1217,7 +1192,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
// as the substitutions for the default, `(T, U)`.
|
// as the substitutions for the default, `(T, U)`.
|
||||||
let ty_var_id = self.inner.borrow_mut().type_variables().new_var(
|
let ty_var_id = self.inner.borrow_mut().type_variables().new_var(
|
||||||
self.universe(),
|
self.universe(),
|
||||||
Diverging::NotDiverging,
|
|
||||||
TypeVariableOrigin {
|
TypeVariableOrigin {
|
||||||
kind: TypeVariableOriginKind::TypeParameterDefinition(
|
kind: TypeVariableOriginKind::TypeParameterDefinition(
|
||||||
param.name,
|
param.name,
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
//! constituents)
|
//! constituents)
|
||||||
|
|
||||||
use crate::infer::combine::ConstEquateRelation;
|
use crate::infer::combine::ConstEquateRelation;
|
||||||
use crate::infer::type_variable::Diverging;
|
|
||||||
use crate::infer::InferCtxt;
|
use crate::infer::InferCtxt;
|
||||||
use crate::infer::{ConstVarValue, ConstVariableValue};
|
use crate::infer::{ConstVarValue, ConstVariableValue};
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
|
@ -927,8 +926,7 @@ where
|
||||||
// Replacing with a new variable in the universe `self.universe`,
|
// Replacing with a new variable in the universe `self.universe`,
|
||||||
// it will be unified later with the original type variable in
|
// it will be unified later with the original type variable in
|
||||||
// the universe `_universe`.
|
// the universe `_universe`.
|
||||||
let new_var_id =
|
let new_var_id = variables.new_var(self.universe, origin);
|
||||||
variables.new_var(self.universe, Diverging::NotDiverging, origin);
|
|
||||||
|
|
||||||
let u = self.tcx().mk_ty_var(new_var_id);
|
let u = self.tcx().mk_ty_var(new_var_id);
|
||||||
debug!("generalize: replacing original vid={:?} with new={:?}", vid, u);
|
debug!("generalize: replacing original vid={:?} with new={:?}", vid, u);
|
||||||
|
|
|
@ -139,13 +139,6 @@ pub enum TypeVariableOriginKind {
|
||||||
|
|
||||||
pub(crate) struct TypeVariableData {
|
pub(crate) struct TypeVariableData {
|
||||||
origin: TypeVariableOrigin,
|
origin: TypeVariableOrigin,
|
||||||
diverging: Diverging,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
|
||||||
pub enum Diverging {
|
|
||||||
NotDiverging,
|
|
||||||
Diverges,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
@ -195,14 +188,6 @@ impl<'tcx> TypeVariableStorage<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeVariableTable<'_, 'tcx> {
|
impl<'tcx> TypeVariableTable<'_, 'tcx> {
|
||||||
/// Returns the diverges flag given when `vid` was created.
|
|
||||||
///
|
|
||||||
/// Note that this function does not return care whether
|
|
||||||
/// `vid` has been unified with something else or not.
|
|
||||||
pub fn var_diverges(&self, vid: ty::TyVid) -> Diverging {
|
|
||||||
self.storage.values.get(vid.index()).diverging
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the origin that was given when `vid` was created.
|
/// Returns the origin that was given when `vid` was created.
|
||||||
///
|
///
|
||||||
/// Note that this function does not return care whether
|
/// Note that this function does not return care whether
|
||||||
|
@ -264,7 +249,6 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
|
||||||
pub fn new_var(
|
pub fn new_var(
|
||||||
&mut self,
|
&mut self,
|
||||||
universe: ty::UniverseIndex,
|
universe: ty::UniverseIndex,
|
||||||
diverging: Diverging,
|
|
||||||
origin: TypeVariableOrigin,
|
origin: TypeVariableOrigin,
|
||||||
) -> ty::TyVid {
|
) -> ty::TyVid {
|
||||||
let eq_key = self.eq_relations().new_key(TypeVariableValue::Unknown { universe });
|
let eq_key = self.eq_relations().new_key(TypeVariableValue::Unknown { universe });
|
||||||
|
@ -272,13 +256,10 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
|
||||||
let sub_key = self.sub_relations().new_key(());
|
let sub_key = self.sub_relations().new_key(());
|
||||||
assert_eq!(eq_key.vid, sub_key);
|
assert_eq!(eq_key.vid, sub_key);
|
||||||
|
|
||||||
let index = self.values().push(TypeVariableData { origin, diverging });
|
let index = self.values().push(TypeVariableData { origin });
|
||||||
assert_eq!(eq_key.vid.as_u32(), index as u32);
|
assert_eq!(eq_key.vid.as_u32(), index as u32);
|
||||||
|
|
||||||
debug!(
|
debug!("new_var(index={:?}, universe={:?}, origin={:?}", eq_key.vid, universe, origin,);
|
||||||
"new_var(index={:?}, universe={:?}, diverging={:?}, origin={:?}",
|
|
||||||
eq_key.vid, universe, diverging, origin,
|
|
||||||
);
|
|
||||||
|
|
||||||
eq_key.vid
|
eq_key.vid
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
!self.typeck_results.borrow().adjustments().contains_key(expr.hir_id),
|
!self.typeck_results.borrow().adjustments().contains_key(expr.hir_id),
|
||||||
"expression with never type wound up being adjusted"
|
"expression with never type wound up being adjusted"
|
||||||
);
|
);
|
||||||
let adj_ty = self.next_diverging_ty_var(TypeVariableOrigin {
|
let adj_ty = self.next_ty_var(TypeVariableOrigin {
|
||||||
kind: TypeVariableOriginKind::AdjustmentType,
|
kind: TypeVariableOriginKind::AdjustmentType,
|
||||||
span: expr.span,
|
span: expr.span,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue