Remove ConstVariableOriginKind

This commit is contained in:
Michael Goulet 2024-03-24 18:52:03 -04:00
parent 34bce07e8e
commit eb6f856169
10 changed files with 26 additions and 63 deletions

View File

@ -354,10 +354,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let ty::ConstKind::Infer(_) = ct.kind() { if let ty::ConstKind::Infer(_) = ct.kind() {
self.next_const_var( self.next_const_var(
ct.ty(), ct.ty(),
ConstVariableOrigin { ConstVariableOrigin { param_def_id: None, span: DUMMY_SP },
kind: ConstVariableOriginKind::MiscVariable,
span: DUMMY_SP,
},
) )
} else { } else {
ct ct

View File

@ -17,7 +17,7 @@ use rustc_infer::infer;
use rustc_infer::infer::error_reporting::sub_relations::SubRelations; use rustc_infer::infer::error_reporting::sub_relations::SubRelations;
use rustc_infer::infer::error_reporting::TypeErrCtxt; use rustc_infer::infer::error_reporting::TypeErrCtxt;
use rustc_infer::infer::type_variable::TypeVariableOrigin; use rustc_infer::infer::type_variable::TypeVariableOrigin;
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind}; use rustc_middle::infer::unify_key::ConstVariableOrigin;
use rustc_middle::ty::{self, Const, Ty, TyCtxt, TypeVisitableExt}; use rustc_middle::ty::{self, Const, Ty, TyCtxt, TypeVisitableExt};
use rustc_session::Session; use rustc_session::Session;
use rustc_span::symbol::Ident; use rustc_span::symbol::Ident;
@ -255,10 +255,7 @@ impl<'a, 'tcx> HirTyLowerer<'tcx> for FnCtxt<'a, 'tcx> {
}, },
) => self.var_for_effect(param).as_const().unwrap(), ) => self.var_for_effect(param).as_const().unwrap(),
Some(param) => self.var_for_def(span, param).as_const().unwrap(), Some(param) => self.var_for_def(span, param).as_const().unwrap(),
None => self.next_const_var( None => self.next_const_var(ty, ConstVariableOrigin { span, param_def_id: None }),
ty,
ConstVariableOrigin { kind: ConstVariableOriginKind::ConstInference, span },
),
} }
} }

View File

@ -23,7 +23,7 @@ use rustc_hir::PatKind::Binding;
use rustc_hir::PathSegment; use rustc_hir::PathSegment;
use rustc_hir::{ExprKind, Node, QPath}; use rustc_hir::{ExprKind, Node, QPath};
use rustc_infer::infer::{self, type_variable::TypeVariableOrigin, RegionVariableOrigin}; use rustc_infer::infer::{self, type_variable::TypeVariableOrigin, RegionVariableOrigin};
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind}; use rustc_middle::infer::unify_key::ConstVariableOrigin;
use rustc_middle::ty::fast_reject::DeepRejectCtxt; use rustc_middle::ty::fast_reject::DeepRejectCtxt;
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams}; use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
use rustc_middle::ty::print::{with_crate_prefix, with_forced_trimmed_paths}; use rustc_middle::ty::print::{with_crate_prefix, with_forced_trimmed_paths};
@ -1859,7 +1859,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
arg.ty(), arg.ty(),
ConstVariableOrigin { ConstVariableOrigin {
span: rustc_span::DUMMY_SP, span: rustc_span::DUMMY_SP,
kind: ConstVariableOriginKind::MiscVariable, param_def_id: None,
}, },
) )
.into(), .into(),

View File

@ -21,7 +21,7 @@
//! //!
//! [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html //! [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html
use crate::infer::{ConstVariableOrigin, ConstVariableOriginKind}; use crate::infer::ConstVariableOrigin;
use crate::infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin}; use crate::infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin};
use rustc_index::IndexVec; use rustc_index::IndexVec;
use rustc_middle::infer::unify_key::EffectVarValue; use rustc_middle::infer::unify_key::EffectVarValue;
@ -148,7 +148,7 @@ impl<'tcx> InferCtxt<'tcx> {
CanonicalVarKind::Const(ui, ty) => self CanonicalVarKind::Const(ui, ty) => self
.next_const_var_in_universe( .next_const_var_in_universe(
ty, ty,
ConstVariableOrigin { kind: ConstVariableOriginKind::MiscVariable, span }, ConstVariableOrigin { param_def_id: None, span },
universe_map(ui), universe_map(ui),
) )
.into(), .into(),

View File

@ -13,9 +13,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{Body, Closure, Expr, ExprKind, FnRetTy, HirId, LetStmt, LocalSource}; use rustc_hir::{Body, Closure, Expr, ExprKind, FnRetTy, HirId, LetStmt, LocalSource};
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
use rustc_middle::infer::unify_key::{ use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableValue};
ConstVariableOrigin, ConstVariableOriginKind, ConstVariableValue,
};
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Print, Printer}; use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Print, Printer};
use rustc_middle::ty::{ use rustc_middle::ty::{
@ -217,8 +215,8 @@ fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'tcx>, ns: Namespace) -> FmtPrinte
None None
} }
ConstVariableValue::Unknown { origin, universe: _ } => { ConstVariableValue::Unknown { origin, universe: _ } => {
if let ConstVariableOriginKind::ConstParameterDefinition(name, _) = origin.kind { if let Some(def_id) = origin.param_def_id {
return Some(name); Some(infcx.tcx.item_name(def_id))
} else { } else {
None None
} }
@ -341,11 +339,9 @@ impl<'tcx> InferCtxt<'tcx> {
} }
ConstVariableValue::Unknown { origin, universe: _ } => origin, ConstVariableValue::Unknown { origin, universe: _ } => origin,
}; };
if let ConstVariableOriginKind::ConstParameterDefinition(name, def_id) = if let Some(def_id) = origin.param_def_id {
origin.kind
{
return InferenceDiagnosticsData { return InferenceDiagnosticsData {
name: name.to_string(), name: self.tcx.item_name(def_id).to_string(),
span: Some(origin.span), span: Some(origin.span),
kind: UnderspecifiedArgKind::Const { is_parameter: true }, kind: UnderspecifiedArgKind::Const { is_parameter: true },
parent: InferenceDiagnosticsParentData::for_def_id(self.tcx, def_id), parent: InferenceDiagnosticsParentData::for_def_id(self.tcx, def_id),
@ -555,10 +551,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
GenericArgKind::Const(arg) => self GenericArgKind::Const(arg) => self
.next_const_var( .next_const_var(
arg.ty(), arg.ty(),
ConstVariableOrigin { ConstVariableOrigin { span: DUMMY_SP, param_def_id: None },
span: DUMMY_SP,
kind: ConstVariableOriginKind::MiscVariable,
},
) )
.into(), .into(),
} }

View File

@ -30,7 +30,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_middle::infer::canonical::{Canonical, CanonicalVarValues}; use rustc_middle::infer::canonical::{Canonical, CanonicalVarValues};
use rustc_middle::infer::unify_key::ConstVariableValue; use rustc_middle::infer::unify_key::ConstVariableValue;
use rustc_middle::infer::unify_key::EffectVarValue; use rustc_middle::infer::unify_key::EffectVarValue;
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind, ToType}; use rustc_middle::infer::unify_key::{ConstVariableOrigin, ToType};
use rustc_middle::infer::unify_key::{ConstVidKey, EffectVidKey}; use rustc_middle::infer::unify_key::{ConstVidKey, EffectVidKey};
use rustc_middle::mir::interpret::{ErrorHandled, EvalToValTreeResult}; use rustc_middle::mir::interpret::{ErrorHandled, EvalToValTreeResult};
use rustc_middle::mir::ConstraintCategory; use rustc_middle::mir::ConstraintCategory;
@ -1120,13 +1120,7 @@ impl<'tcx> InferCtxt<'tcx> {
if is_host_effect { if is_host_effect {
return self.var_for_effect(param); return self.var_for_effect(param);
} }
let origin = ConstVariableOrigin { let origin = ConstVariableOrigin { param_def_id: Some(param.def_id), span };
kind: ConstVariableOriginKind::ConstParameterDefinition(
param.name,
param.def_id,
),
span,
};
let const_var_id = self let const_var_id = self
.inner .inner
.borrow_mut() .borrow_mut()
@ -1417,10 +1411,7 @@ impl<'tcx> InferCtxt<'tcx> {
self.infcx self.infcx
.next_const_var( .next_const_var(
ty, ty,
ConstVariableOrigin { ConstVariableOrigin { param_def_id: None, span: self.span },
kind: ConstVariableOriginKind::MiscVariable,
span: self.span,
},
) )
.into() .into()
}) })

View File

@ -1,4 +1,4 @@
use rustc_middle::infer::unify_key::{ConstVariableOriginKind, ConstVariableValue, ConstVidKey}; use rustc_middle::infer::unify_key::{ConstVariableValue, 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};
@ -33,10 +33,9 @@ fn const_vars_since_snapshot<'tcx>(
range.start.vid..range.end.vid, range.start.vid..range.end.vid,
(range.start.index()..range.end.index()) (range.start.index()..range.end.index())
.map(|index| match table.probe_value(ConstVid::from_u32(index)) { .map(|index| match table.probe_value(ConstVid::from_u32(index)) {
ConstVariableValue::Known { value: _ } => ConstVariableOrigin { ConstVariableValue::Known { value: _ } => {
kind: ConstVariableOriginKind::MiscVariable, ConstVariableOrigin { param_def_id: None, span: rustc_span::DUMMY_SP }
span: rustc_span::DUMMY_SP, }
},
ConstVariableValue::Unknown { origin, universe: _ } => origin, ConstVariableValue::Unknown { origin, universe: _ } => origin,
}) })
.collect(), .collect(),

View File

@ -1,7 +1,6 @@
use crate::ty::{self, Ty, TyCtxt}; use crate::ty::{self, Ty, TyCtxt};
use rustc_data_structures::unify::{NoError, UnifyKey, UnifyValue}; use rustc_data_structures::unify::{NoError, UnifyKey, UnifyValue};
use rustc_span::def_id::DefId; use rustc_span::def_id::DefId;
use rustc_span::symbol::Symbol;
use rustc_span::Span; use rustc_span::Span;
use std::cmp; use std::cmp;
use std::marker::PhantomData; use std::marker::PhantomData;
@ -106,16 +105,9 @@ impl ToType for ty::FloatVarValue {
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub struct ConstVariableOrigin { pub struct ConstVariableOrigin {
pub kind: ConstVariableOriginKind,
pub span: Span, pub span: Span,
} // `DefId` of the const parameter this was instantiated for, if any.
pub param_def_id: Option<DefId>,
/// Reasons to create a const inference variable
#[derive(Copy, Clone, Debug)]
pub enum ConstVariableOriginKind {
MiscVariable,
ConstInference,
ConstParameterDefinition(Symbol, DefId),
} }
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]

View File

@ -10,7 +10,7 @@ use rustc_infer::traits::query::NoSolution;
use rustc_infer::traits::solve::{MaybeCause, NestedNormalizationGoals}; use rustc_infer::traits::solve::{MaybeCause, NestedNormalizationGoals};
use rustc_infer::traits::ObligationCause; use rustc_infer::traits::ObligationCause;
use rustc_middle::infer::canonical::CanonicalVarInfos; use rustc_middle::infer::canonical::CanonicalVarInfos;
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind}; use rustc_middle::infer::unify_key::ConstVariableOrigin;
use rustc_middle::traits::solve::inspect; use rustc_middle::traits::solve::inspect;
use rustc_middle::traits::solve::{ use rustc_middle::traits::solve::{
CanonicalInput, CanonicalResponse, Certainty, PredefinedOpaques, PredefinedOpaquesData, CanonicalInput, CanonicalResponse, Certainty, PredefinedOpaques, PredefinedOpaquesData,
@ -591,10 +591,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
} }
pub(super) fn next_const_infer(&self, ty: Ty<'tcx>) -> ty::Const<'tcx> { pub(super) fn next_const_infer(&self, ty: Ty<'tcx>) -> ty::Const<'tcx> {
self.infcx.next_const_var( self.infcx.next_const_var(ty, ConstVariableOrigin { param_def_id: None, span: DUMMY_SP })
ty,
ConstVariableOrigin { kind: ConstVariableOriginKind::MiscVariable, span: DUMMY_SP },
)
} }
/// Returns a ty infer or a const infer depending on whether `kind` is a `Ty` or `Const`. /// Returns a ty infer or a const infer depending on whether `kind` is a `Ty` or `Const`.

View File

@ -7,7 +7,7 @@ use rustc_infer::infer::type_variable::TypeVariableOrigin;
use rustc_infer::infer::InferCtxt; use rustc_infer::infer::InferCtxt;
use rustc_infer::traits::TraitEngineExt; use rustc_infer::traits::TraitEngineExt;
use rustc_infer::traits::{FulfillmentError, Obligation, TraitEngine}; use rustc_infer::traits::{FulfillmentError, Obligation, TraitEngine};
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind}; use rustc_middle::infer::unify_key::ConstVariableOrigin;
use rustc_middle::traits::ObligationCause; use rustc_middle::traits::ObligationCause;
use rustc_middle::ty::{self, AliasTy, Ty, TyCtxt, UniverseIndex}; use rustc_middle::ty::{self, AliasTy, Ty, TyCtxt, UniverseIndex};
use rustc_middle::ty::{FallibleTypeFolder, TypeFolder, TypeSuperFoldable}; use rustc_middle::ty::{FallibleTypeFolder, TypeFolder, TypeSuperFoldable};
@ -122,10 +122,7 @@ impl<'tcx> NormalizationFolder<'_, 'tcx> {
let new_infer_ct = infcx.next_const_var( let new_infer_ct = infcx.next_const_var(
ty, ty,
ConstVariableOrigin { ConstVariableOrigin { param_def_id: None, span: self.at.cause.span },
kind: ConstVariableOriginKind::MiscVariable,
span: self.at.cause.span,
},
); );
let obligation = Obligation::new( let obligation = Obligation::new(
tcx, tcx,