mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Create intermediate enum ty::ConstKind.
This commit is contained in:
parent
5dda3ee931
commit
e5fb784823
@ -10,7 +10,6 @@ use crate::infer::canonical::{
|
|||||||
OriginalQueryValues,
|
OriginalQueryValues,
|
||||||
};
|
};
|
||||||
use crate::infer::InferCtxt;
|
use crate::infer::InferCtxt;
|
||||||
use crate::mir::interpret::ConstValue;
|
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use crate::ty::fold::{TypeFoldable, TypeFolder};
|
use crate::ty::fold::{TypeFoldable, TypeFolder};
|
||||||
use crate::ty::subst::GenericArg;
|
use crate::ty::subst::GenericArg;
|
||||||
@ -441,7 +440,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
|
|||||||
|
|
||||||
fn fold_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
|
fn fold_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
|
||||||
match ct.val {
|
match ct.val {
|
||||||
ConstValue::Infer(InferConst::Var(vid)) => {
|
ty::ConstKind::Infer(InferConst::Var(vid)) => {
|
||||||
debug!("canonical: const var found with vid {:?}", vid);
|
debug!("canonical: const var found with vid {:?}", vid);
|
||||||
match self.infcx.unwrap().probe_const_var(vid) {
|
match self.infcx.unwrap().probe_const_var(vid) {
|
||||||
Ok(c) => {
|
Ok(c) => {
|
||||||
@ -465,17 +464,17 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ConstValue::Infer(InferConst::Fresh(_)) => {
|
ty::ConstKind::Infer(InferConst::Fresh(_)) => {
|
||||||
bug!("encountered a fresh const during canonicalization")
|
bug!("encountered a fresh const during canonicalization")
|
||||||
}
|
}
|
||||||
ConstValue::Bound(debruijn, _) => {
|
ty::ConstKind::Bound(debruijn, _) => {
|
||||||
if debruijn >= self.binder_index {
|
if debruijn >= self.binder_index {
|
||||||
bug!("escaping bound type during canonicalization")
|
bug!("escaping bound type during canonicalization")
|
||||||
} else {
|
} else {
|
||||||
return ct;
|
return ct;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ConstValue::Placeholder(placeholder) => {
|
ty::ConstKind::Placeholder(placeholder) => {
|
||||||
return self.canonicalize_const_var(
|
return self.canonicalize_const_var(
|
||||||
CanonicalVarInfo {
|
CanonicalVarInfo {
|
||||||
kind: CanonicalVarKind::PlaceholderConst(placeholder),
|
kind: CanonicalVarKind::PlaceholderConst(placeholder),
|
||||||
@ -700,7 +699,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
|
|||||||
let var = self.canonical_var(info, const_var.into());
|
let var = self.canonical_var(info, const_var.into());
|
||||||
self.tcx().mk_const(
|
self.tcx().mk_const(
|
||||||
ty::Const {
|
ty::Const {
|
||||||
val: ConstValue::Bound(self.binder_index, var.into()),
|
val: ty::ConstKind::Bound(self.binder_index, var.into()),
|
||||||
ty: self.fold_ty(const_var.ty),
|
ty: self.fold_ty(const_var.ty),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
use crate::infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin, TypeVariableOriginKind};
|
use crate::infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin, TypeVariableOriginKind};
|
||||||
use crate::infer::{ConstVariableOrigin, ConstVariableOriginKind};
|
use crate::infer::{ConstVariableOrigin, ConstVariableOriginKind};
|
||||||
use crate::infer::region_constraints::MemberConstraint;
|
use crate::infer::region_constraints::MemberConstraint;
|
||||||
use crate::mir::interpret::ConstValue;
|
|
||||||
use rustc_index::vec::IndexVec;
|
use rustc_index::vec::IndexVec;
|
||||||
use rustc_macros::HashStable;
|
use rustc_macros::HashStable;
|
||||||
use rustc_serialize::UseSpecializedDecodable;
|
use rustc_serialize::UseSpecializedDecodable;
|
||||||
@ -447,7 +446,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||||||
};
|
};
|
||||||
self.tcx.mk_const(
|
self.tcx.mk_const(
|
||||||
ty::Const {
|
ty::Const {
|
||||||
val: ConstValue::Placeholder(placeholder_mapped),
|
val: ty::ConstKind::Placeholder(placeholder_mapped),
|
||||||
ty: self.tcx.types.err, // FIXME(const_generics)
|
ty: self.tcx.types.err, // FIXME(const_generics)
|
||||||
}
|
}
|
||||||
).into()
|
).into()
|
||||||
@ -510,7 +509,7 @@ impl<'tcx> CanonicalVarValues<'tcx> {
|
|||||||
GenericArgKind::Const(ct) => {
|
GenericArgKind::Const(ct) => {
|
||||||
tcx.mk_const(ty::Const {
|
tcx.mk_const(ty::Const {
|
||||||
ty: ct.ty,
|
ty: ct.ty,
|
||||||
val: ConstValue::Bound(ty::INNERMOST, ty::BoundVar::from_u32(i)),
|
val: ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from_u32(i)),
|
||||||
}).into()
|
}).into()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -16,7 +16,6 @@ use crate::infer::canonical::{
|
|||||||
use crate::infer::region_constraints::{Constraint, RegionConstraintData};
|
use crate::infer::region_constraints::{Constraint, RegionConstraintData};
|
||||||
use crate::infer::InferCtxtBuilder;
|
use crate::infer::InferCtxtBuilder;
|
||||||
use crate::infer::{InferCtxt, InferOk, InferResult};
|
use crate::infer::{InferCtxt, InferOk, InferResult};
|
||||||
use crate::mir::interpret::ConstValue;
|
|
||||||
use rustc_index::vec::Idx;
|
use rustc_index::vec::Idx;
|
||||||
use rustc_index::vec::IndexVec;
|
use rustc_index::vec::IndexVec;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
@ -493,7 +492,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
GenericArgKind::Const(result_value) => {
|
GenericArgKind::Const(result_value) => {
|
||||||
if let ty::Const { val: ConstValue::Bound(debrujin, b), .. } = result_value {
|
if let ty::Const { val: ty::ConstKind::Bound(debrujin, b), .. } = result_value {
|
||||||
// ...in which case we would set `canonical_vars[0]` to `Some(const X)`.
|
// ...in which case we would set `canonical_vars[0]` to `Some(const X)`.
|
||||||
|
|
||||||
// We only allow a `ty::INNERMOST` index in substitutions.
|
// We only allow a `ty::INNERMOST` index in substitutions.
|
||||||
|
@ -33,7 +33,6 @@ use super::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
|
|||||||
use super::unify_key::replace_if_possible;
|
use super::unify_key::replace_if_possible;
|
||||||
|
|
||||||
use crate::hir::def_id::DefId;
|
use crate::hir::def_id::DefId;
|
||||||
use crate::mir::interpret::ConstValue;
|
|
||||||
use crate::ty::{IntType, UintType};
|
use crate::ty::{IntType, UintType};
|
||||||
use crate::ty::{self, Ty, TyCtxt, InferConst};
|
use crate::ty::{self, Ty, TyCtxt, InferConst};
|
||||||
use crate::ty::error::TypeError;
|
use crate::ty::error::TypeError;
|
||||||
@ -137,8 +136,8 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
|
|||||||
let a_is_expected = relation.a_is_expected();
|
let a_is_expected = relation.a_is_expected();
|
||||||
|
|
||||||
match (a.val, b.val) {
|
match (a.val, b.val) {
|
||||||
(ConstValue::Infer(InferConst::Var(a_vid)),
|
(ty::ConstKind::Infer(InferConst::Var(a_vid)),
|
||||||
ConstValue::Infer(InferConst::Var(b_vid))) => {
|
ty::ConstKind::Infer(InferConst::Var(b_vid))) => {
|
||||||
self.const_unification_table
|
self.const_unification_table
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.unify_var_var(a_vid, b_vid)
|
.unify_var_var(a_vid, b_vid)
|
||||||
@ -147,16 +146,16 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// All other cases of inference with other variables are errors.
|
// All other cases of inference with other variables are errors.
|
||||||
(ConstValue::Infer(InferConst::Var(_)), ConstValue::Infer(_)) |
|
(ty::ConstKind::Infer(InferConst::Var(_)), ty::ConstKind::Infer(_)) |
|
||||||
(ConstValue::Infer(_), ConstValue::Infer(InferConst::Var(_))) => {
|
(ty::ConstKind::Infer(_), ty::ConstKind::Infer(InferConst::Var(_))) => {
|
||||||
bug!("tried to combine ConstValue::Infer/ConstValue::Infer(InferConst::Var)")
|
bug!("tried to combine ConstKind::Infer/ConstKind::Infer(InferConst::Var)")
|
||||||
}
|
}
|
||||||
|
|
||||||
(ConstValue::Infer(InferConst::Var(vid)), _) => {
|
(ty::ConstKind::Infer(InferConst::Var(vid)), _) => {
|
||||||
return self.unify_const_variable(a_is_expected, vid, b);
|
return self.unify_const_variable(a_is_expected, vid, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
(_, ConstValue::Infer(InferConst::Var(vid))) => {
|
(_, ty::ConstKind::Infer(InferConst::Var(vid))) => {
|
||||||
return self.unify_const_variable(!a_is_expected, vid, a);
|
return self.unify_const_variable(!a_is_expected, vid, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -603,7 +602,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
|
|||||||
assert_eq!(c, c2); // we are abusing TypeRelation here; both LHS and RHS ought to be ==
|
assert_eq!(c, c2); // we are abusing TypeRelation here; both LHS and RHS ought to be ==
|
||||||
|
|
||||||
match c.val {
|
match c.val {
|
||||||
ConstValue::Infer(InferConst::Var(vid)) => {
|
ty::ConstKind::Infer(InferConst::Var(vid)) => {
|
||||||
let mut variable_table = self.infcx.const_unification_table.borrow_mut();
|
let mut variable_table = self.infcx.const_unification_table.borrow_mut();
|
||||||
let var_value = variable_table.probe_value(vid);
|
let var_value = variable_table.probe_value(vid);
|
||||||
match var_value.val {
|
match var_value.val {
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
//! variable only once, and it does so as soon as it can, so it is reasonable to ask what the type
|
//! variable only once, and it does so as soon as it can, so it is reasonable to ask what the type
|
||||||
//! inferencer knows "so far".
|
//! inferencer knows "so far".
|
||||||
|
|
||||||
use crate::mir::interpret::ConstValue;
|
|
||||||
use crate::ty::{self, Ty, TyCtxt, TypeFoldable};
|
use crate::ty::{self, Ty, TyCtxt, TypeFoldable};
|
||||||
use crate::ty::fold::TypeFolder;
|
use crate::ty::fold::TypeFolder;
|
||||||
use crate::util::nodemap::FxHashMap;
|
use crate::util::nodemap::FxHashMap;
|
||||||
@ -227,7 +226,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
|
|||||||
|
|
||||||
fn fold_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
|
fn fold_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
|
||||||
match ct.val {
|
match ct.val {
|
||||||
ConstValue::Infer(ty::InferConst::Var(v)) => {
|
ty::ConstKind::Infer(ty::InferConst::Var(v)) => {
|
||||||
let opt_ct = self.infcx.const_unification_table
|
let opt_ct = self.infcx.const_unification_table
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.probe_value(v)
|
.probe_value(v)
|
||||||
@ -240,7 +239,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
|
|||||||
ct.ty,
|
ct.ty,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
ConstValue::Infer(ty::InferConst::Fresh(i)) => {
|
ty::ConstKind::Infer(ty::InferConst::Fresh(i)) => {
|
||||||
if i >= self.const_freshen_count {
|
if i >= self.const_freshen_count {
|
||||||
bug!(
|
bug!(
|
||||||
"Encountered a freshend const with id {} \
|
"Encountered a freshend const with id {} \
|
||||||
@ -252,16 +251,14 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
|
|||||||
return ct;
|
return ct;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstValue::Bound(..) |
|
ty::ConstKind::Bound(..) |
|
||||||
ConstValue::Placeholder(_) => {
|
ty::ConstKind::Placeholder(_) => {
|
||||||
bug!("unexpected const {:?}", ct)
|
bug!("unexpected const {:?}", ct)
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstValue::Param(_) |
|
ty::ConstKind::Param(_) |
|
||||||
ConstValue::Scalar(_) |
|
ty::ConstKind::Value(_) |
|
||||||
ConstValue::Slice { .. } |
|
ty::ConstKind::Unevaluated(..) => {}
|
||||||
ConstValue::ByRef { .. } |
|
|
||||||
ConstValue::Unevaluated(..) => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ct.super_fold_with(self)
|
ct.super_fold_with(self)
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use crate::ty::{self, Ty, TyCtxt, TyVid, IntVid, FloatVid, RegionVid, ConstVid};
|
use crate::ty::{self, Ty, TyCtxt, TyVid, IntVid, FloatVid, RegionVid, ConstVid};
|
||||||
use crate::ty::fold::{TypeFoldable, TypeFolder};
|
use crate::ty::fold::{TypeFoldable, TypeFolder};
|
||||||
use crate::mir::interpret::ConstValue;
|
|
||||||
|
|
||||||
use super::InferCtxt;
|
use super::InferCtxt;
|
||||||
use super::{RegionVariableOrigin, ConstVariableOrigin};
|
use super::{RegionVariableOrigin, ConstVariableOrigin};
|
||||||
@ -198,7 +197,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for InferenceFudger<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn fold_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
|
fn fold_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
|
||||||
if let ty::Const { val: ConstValue::Infer(ty::InferConst::Var(vid)), ty } = ct {
|
if let ty::Const { val: ty::ConstKind::Infer(ty::InferConst::Var(vid)), ty } = ct {
|
||||||
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.
|
||||||
|
@ -7,7 +7,6 @@ use super::{HigherRankedType, InferCtxt, PlaceholderMap};
|
|||||||
use crate::infer::CombinedSnapshot;
|
use crate::infer::CombinedSnapshot;
|
||||||
use crate::ty::relate::{Relate, RelateResult, TypeRelation};
|
use crate::ty::relate::{Relate, RelateResult, TypeRelation};
|
||||||
use crate::ty::{self, Binder, TypeFoldable};
|
use crate::ty::{self, Binder, TypeFoldable};
|
||||||
use crate::mir::interpret::ConstValue;
|
|
||||||
|
|
||||||
impl<'a, 'tcx> CombineFields<'a, 'tcx> {
|
impl<'a, 'tcx> CombineFields<'a, 'tcx> {
|
||||||
pub fn higher_ranked_sub<T>(
|
pub fn higher_ranked_sub<T>(
|
||||||
@ -103,7 +102,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
let fld_c = |bound_var: ty::BoundVar, ty| {
|
let fld_c = |bound_var: ty::BoundVar, ty| {
|
||||||
self.tcx.mk_const(
|
self.tcx.mk_const(
|
||||||
ty::Const {
|
ty::Const {
|
||||||
val: ConstValue::Placeholder(ty::PlaceholderConst {
|
val: ty::ConstKind::Placeholder(ty::PlaceholderConst {
|
||||||
universe: next_universe,
|
universe: next_universe,
|
||||||
name: bound_var,
|
name: bound_var,
|
||||||
}),
|
}),
|
||||||
|
@ -14,7 +14,6 @@ use crate::infer::unify_key::{ConstVarValue, ConstVariableValue};
|
|||||||
use crate::middle::free_region::RegionRelations;
|
use crate::middle::free_region::RegionRelations;
|
||||||
use crate::middle::lang_items;
|
use crate::middle::lang_items;
|
||||||
use crate::middle::region;
|
use crate::middle::region;
|
||||||
use crate::mir::interpret::ConstValue;
|
|
||||||
use crate::session::config::BorrowckMode;
|
use crate::session::config::BorrowckMode;
|
||||||
use crate::traits::{self, ObligationCause, PredicateObligations, TraitEngine};
|
use crate::traits::{self, ObligationCause, PredicateObligations, TraitEngine};
|
||||||
use crate::ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric};
|
use crate::ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric};
|
||||||
@ -1662,7 +1661,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for ShallowResolver<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn fold_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
|
fn fold_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
|
||||||
if let ty::Const { val: ConstValue::Infer(InferConst::Var(vid)), .. } = ct {
|
if let ty::Const { val: ty::ConstKind::Infer(InferConst::Var(vid)), .. } = ct {
|
||||||
self.infcx.const_unification_table
|
self.infcx.const_unification_table
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.probe_value(*vid)
|
.probe_value(*vid)
|
||||||
|
@ -29,7 +29,6 @@ use crate::ty::relate::{self, Relate, RelateResult, TypeRelation};
|
|||||||
use crate::ty::subst::GenericArg;
|
use crate::ty::subst::GenericArg;
|
||||||
use crate::ty::{self, Ty, TyCtxt, InferConst};
|
use crate::ty::{self, Ty, TyCtxt, InferConst};
|
||||||
use crate::infer::{ConstVariableValue, ConstVarValue};
|
use crate::infer::{ConstVariableValue, ConstVarValue};
|
||||||
use crate::mir::interpret::ConstValue;
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
@ -626,7 +625,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
match b.val {
|
match b.val {
|
||||||
ConstValue::Infer(InferConst::Var(_)) if D::forbid_inference_vars() => {
|
ty::ConstKind::Infer(InferConst::Var(_)) if D::forbid_inference_vars() => {
|
||||||
// Forbid inference variables in the RHS.
|
// Forbid inference variables in the RHS.
|
||||||
bug!("unexpected inference var {:?}", b)
|
bug!("unexpected inference var {:?}", b)
|
||||||
}
|
}
|
||||||
@ -999,13 +998,13 @@ where
|
|||||||
_: &'tcx ty::Const<'tcx>,
|
_: &'tcx ty::Const<'tcx>,
|
||||||
) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> {
|
) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> {
|
||||||
match a.val {
|
match a.val {
|
||||||
ConstValue::Infer(InferConst::Var(_)) if D::forbid_inference_vars() => {
|
ty::ConstKind::Infer(InferConst::Var(_)) if D::forbid_inference_vars() => {
|
||||||
bug!(
|
bug!(
|
||||||
"unexpected inference variable encountered in NLL generalization: {:?}",
|
"unexpected inference variable encountered in NLL generalization: {:?}",
|
||||||
a
|
a
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
ConstValue::Infer(InferConst::Var(vid)) => {
|
ty::ConstKind::Infer(InferConst::Var(vid)) => {
|
||||||
let mut variable_table = self.infcx.const_unification_table.borrow_mut();
|
let mut variable_table = self.infcx.const_unification_table.borrow_mut();
|
||||||
let var_value = variable_table.probe_value(vid);
|
let var_value = variable_table.probe_value(vid);
|
||||||
match var_value.val.known() {
|
match var_value.val.known() {
|
||||||
|
@ -4,7 +4,6 @@ use crate::hir::Node;
|
|||||||
use crate::infer::outlives::free_region_map::FreeRegionRelations;
|
use crate::infer::outlives::free_region_map::FreeRegionRelations;
|
||||||
use crate::infer::{self, InferCtxt, InferOk, TypeVariableOrigin, TypeVariableOriginKind};
|
use crate::infer::{self, InferCtxt, InferOk, TypeVariableOrigin, TypeVariableOriginKind};
|
||||||
use crate::middle::region;
|
use crate::middle::region;
|
||||||
use crate::mir::interpret::ConstValue;
|
|
||||||
use crate::traits::{self, PredicateObligation};
|
use crate::traits::{self, PredicateObligation};
|
||||||
use crate::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder, TypeVisitor};
|
use crate::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder, TypeVisitor};
|
||||||
use crate::ty::subst::{InternalSubsts, GenericArg, SubstsRef, GenericArgKind};
|
use crate::ty::subst::{InternalSubsts, GenericArg, SubstsRef, GenericArgKind};
|
||||||
@ -945,7 +944,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {
|
|||||||
trace!("checking const {:?}", ct);
|
trace!("checking const {:?}", ct);
|
||||||
// Find a const parameter
|
// Find a const parameter
|
||||||
match ct.val {
|
match ct.val {
|
||||||
ConstValue::Param(..) => {
|
ty::ConstKind::Param(..) => {
|
||||||
// Look it up in the substitution list.
|
// Look it up in the substitution list.
|
||||||
match self.map.get(&ct.into()).map(|k| k.unpack()) {
|
match self.map.get(&ct.into()).map(|k| k.unpack()) {
|
||||||
// Found it in the substitution list, replace with the parameter from the
|
// Found it in the substitution list, replace with the parameter from the
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use super::{InferCtxt, FixupError, FixupResult, Span};
|
use super::{InferCtxt, FixupError, FixupResult, Span};
|
||||||
use super::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
use super::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||||
use crate::mir::interpret::ConstValue;
|
|
||||||
use crate::ty::{self, Ty, Const, TyCtxt, TypeFoldable, InferConst};
|
use crate::ty::{self, Ty, Const, TyCtxt, TypeFoldable, InferConst};
|
||||||
use crate::ty::fold::{TypeFolder, TypeVisitor};
|
use crate::ty::fold::{TypeFolder, TypeVisitor};
|
||||||
|
|
||||||
@ -230,11 +229,11 @@ impl<'a, 'tcx> TypeFolder<'tcx> for FullTypeResolver<'a, 'tcx> {
|
|||||||
} else {
|
} else {
|
||||||
let c = self.infcx.shallow_resolve(c);
|
let c = self.infcx.shallow_resolve(c);
|
||||||
match c.val {
|
match c.val {
|
||||||
ConstValue::Infer(InferConst::Var(vid)) => {
|
ty::ConstKind::Infer(InferConst::Var(vid)) => {
|
||||||
self.err = Some(FixupError::UnresolvedConst(vid));
|
self.err = Some(FixupError::UnresolvedConst(vid));
|
||||||
return self.tcx().consts.err;
|
return self.tcx().consts.err;
|
||||||
}
|
}
|
||||||
ConstValue::Infer(InferConst::Fresh(_)) => {
|
ty::ConstKind::Infer(InferConst::Fresh(_)) => {
|
||||||
bug!("Unexpected const in full const resolver: {:?}", c);
|
bug!("Unexpected const in full const resolver: {:?}", c);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
use crate::ty::{self, FloatVarValue, IntVarValue, Ty, TyCtxt, InferConst};
|
use crate::ty::{self, FloatVarValue, IntVarValue, Ty, TyCtxt, InferConst};
|
||||||
use crate::mir::interpret::ConstValue;
|
|
||||||
use rustc_data_structures::unify::{NoError, EqUnifyValue, UnifyKey, UnifyValue, UnificationTable};
|
use rustc_data_structures::unify::{NoError, EqUnifyValue, UnifyKey, UnifyValue, UnificationTable};
|
||||||
use rustc_data_structures::unify::InPlace;
|
use rustc_data_structures::unify::InPlace;
|
||||||
use syntax_pos::{Span, DUMMY_SP};
|
use syntax_pos::{Span, DUMMY_SP};
|
||||||
@ -180,7 +179,7 @@ pub fn replace_if_possible(
|
|||||||
mut table: RefMut<'_, UnificationTable<InPlace<ty::ConstVid<'tcx>>>>,
|
mut table: RefMut<'_, UnificationTable<InPlace<ty::ConstVid<'tcx>>>>,
|
||||||
c: &'tcx ty::Const<'tcx>
|
c: &'tcx ty::Const<'tcx>
|
||||||
) -> &'tcx ty::Const<'tcx> {
|
) -> &'tcx ty::Const<'tcx> {
|
||||||
if let ty::Const { val: ConstValue::Infer(InferConst::Var(vid)), .. } = c {
|
if let ty::Const { val: ty::ConstKind::Infer(InferConst::Var(vid)), .. } = c {
|
||||||
match table.probe_value(*vid).val.known() {
|
match table.probe_value(*vid).val.known() {
|
||||||
Some(c) => c,
|
Some(c) => c,
|
||||||
None => c,
|
None => c,
|
||||||
|
@ -2,10 +2,7 @@ use std::fmt;
|
|||||||
use rustc_macros::HashStable;
|
use rustc_macros::HashStable;
|
||||||
use rustc_apfloat::{Float, ieee::{Double, Single}};
|
use rustc_apfloat::{Float, ieee::{Double, Single}};
|
||||||
|
|
||||||
use crate::ty::{Ty, InferConst, ParamConst, layout::{HasDataLayout, Size}, subst::SubstsRef};
|
use crate::ty::{Ty, layout::{HasDataLayout, Size}};
|
||||||
use crate::ty::PlaceholderConst;
|
|
||||||
use crate::hir::def_id::DefId;
|
|
||||||
use crate::ty::{BoundVar, DebruijnIndex};
|
|
||||||
|
|
||||||
use super::{InterpResult, Pointer, PointerArithmetic, Allocation, AllocId, sign_extend, truncate};
|
use super::{InterpResult, Pointer, PointerArithmetic, Allocation, AllocId, sign_extend, truncate};
|
||||||
|
|
||||||
@ -23,18 +20,6 @@ pub struct RawConst<'tcx> {
|
|||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord,
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord,
|
||||||
RustcEncodable, RustcDecodable, Hash, HashStable)]
|
RustcEncodable, RustcDecodable, Hash, HashStable)]
|
||||||
pub enum ConstValue<'tcx> {
|
pub enum ConstValue<'tcx> {
|
||||||
/// A const generic parameter.
|
|
||||||
Param(ParamConst),
|
|
||||||
|
|
||||||
/// Infer the value of the const.
|
|
||||||
Infer(InferConst<'tcx>),
|
|
||||||
|
|
||||||
/// Bound const variable, used only when preparing a trait query.
|
|
||||||
Bound(DebruijnIndex, BoundVar),
|
|
||||||
|
|
||||||
/// A placeholder const - universally quantified higher-ranked const.
|
|
||||||
Placeholder(PlaceholderConst),
|
|
||||||
|
|
||||||
/// Used only for types with `layout::abi::Scalar` ABI and ZSTs.
|
/// Used only for types with `layout::abi::Scalar` ABI and ZSTs.
|
||||||
///
|
///
|
||||||
/// Not using the enum `Value` to encode that this must not be `Undef`.
|
/// Not using the enum `Value` to encode that this must not be `Undef`.
|
||||||
@ -55,10 +40,6 @@ pub enum ConstValue<'tcx> {
|
|||||||
/// Offset into `alloc`
|
/// Offset into `alloc`
|
||||||
offset: Size,
|
offset: Size,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Used in the HIR by using `Unevaluated` everywhere and later normalizing to one of the other
|
|
||||||
/// variants when the code is monomorphic enough for that.
|
|
||||||
Unevaluated(DefId, SubstsRef<'tcx>),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
@ -68,26 +49,21 @@ impl<'tcx> ConstValue<'tcx> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn try_to_scalar(&self) -> Option<Scalar> {
|
pub fn try_to_scalar(&self) -> Option<Scalar> {
|
||||||
match *self {
|
match *self {
|
||||||
ConstValue::Param(_) |
|
|
||||||
ConstValue::Infer(_) |
|
|
||||||
ConstValue::Bound(..) |
|
|
||||||
ConstValue::Placeholder(_) |
|
|
||||||
ConstValue::ByRef { .. } |
|
ConstValue::ByRef { .. } |
|
||||||
ConstValue::Unevaluated(..) |
|
|
||||||
ConstValue::Slice { .. } => None,
|
ConstValue::Slice { .. } => None,
|
||||||
ConstValue::Scalar(val) => Some(val),
|
ConstValue::Scalar(val) => Some(val),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//
|
||||||
#[inline]
|
// #[inline]
|
||||||
pub fn try_to_bits(&self, size: Size) -> Option<u128> {
|
// pub fn try_to_bits(&self, size: Size) -> Option<u128> {
|
||||||
self.try_to_scalar()?.to_bits(size).ok()
|
// self.try_to_scalar()?.to_bits(size).ok()
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
#[inline]
|
// #[inline]
|
||||||
pub fn try_to_ptr(&self) -> Option<Pointer> {
|
// pub fn try_to_ptr(&self) -> Option<Pointer> {
|
||||||
self.try_to_scalar()?.to_ptr().ok()
|
// self.try_to_scalar()?.to_ptr().ok()
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A `Scalar` represents an immediate, primitive value existing outside of a
|
/// A `Scalar` represents an immediate, primitive value existing outside of a
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
use crate::hir::def::{CtorKind, Namespace};
|
use crate::hir::def::{CtorKind, Namespace};
|
||||||
use crate::hir::def_id::DefId;
|
use crate::hir::def_id::DefId;
|
||||||
use crate::hir::{self, InlineAsm as HirInlineAsm};
|
use crate::hir::{self, InlineAsm as HirInlineAsm};
|
||||||
use crate::mir::interpret::{ConstValue, PanicInfo, Scalar};
|
use crate::mir::interpret::{PanicInfo, Scalar};
|
||||||
use crate::mir::visit::MirVisitable;
|
use crate::mir::visit::MirVisitable;
|
||||||
use crate::ty::adjustment::PointerCast;
|
use crate::ty::adjustment::PointerCast;
|
||||||
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
|
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
|
||||||
@ -1506,10 +1506,11 @@ impl<'tcx> TerminatorKind<'tcx> {
|
|||||||
values
|
values
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&u| {
|
.map(|&u| {
|
||||||
tcx.mk_const(ty::Const {
|
ty::Const::from_scalar(
|
||||||
val: ConstValue::Scalar(Scalar::from_uint(u, size).into()),
|
tcx,
|
||||||
ty: switch_ty,
|
Scalar::from_uint(u, size).into(),
|
||||||
})
|
switch_ty,
|
||||||
|
)
|
||||||
.to_string()
|
.to_string()
|
||||||
.into()
|
.into()
|
||||||
})
|
})
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use crate::ty::{self, Ty, TyCtxt, InferConst};
|
use crate::ty::{self, Ty, TyCtxt, InferConst};
|
||||||
use crate::ty::error::TypeError;
|
use crate::ty::error::TypeError;
|
||||||
use crate::ty::relate::{self, Relate, TypeRelation, RelateResult};
|
use crate::ty::relate::{self, Relate, TypeRelation, RelateResult};
|
||||||
use crate::mir::interpret::ConstValue;
|
|
||||||
|
|
||||||
/// A type "A" *matches* "B" if the fresh types in B could be
|
/// A type "A" *matches* "B" if the fresh types in B could be
|
||||||
/// substituted with values so as to make it equal to A. Matching is
|
/// substituted with values so as to make it equal to A. Matching is
|
||||||
@ -92,11 +91,11 @@ impl TypeRelation<'tcx> for Match<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
match (a.val, b.val) {
|
match (a.val, b.val) {
|
||||||
(_, ConstValue::Infer(InferConst::Fresh(_))) => {
|
(_, ty::ConstKind::Infer(InferConst::Fresh(_))) => {
|
||||||
return Ok(a);
|
return Ok(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
(ConstValue::Infer(_), _) | (_, ConstValue::Infer(_)) => {
|
(ty::ConstKind::Infer(_), _) | (_, ty::ConstKind::Infer(_)) => {
|
||||||
return Err(TypeError::ConstMismatch(relate::expected_found(self, &a, &b)));
|
return Err(TypeError::ConstMismatch(relate::expected_found(self, &a, &b)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -885,7 +885,7 @@ impl CanonicalUserType<'tcx> {
|
|||||||
},
|
},
|
||||||
|
|
||||||
GenericArgKind::Const(ct) => match ct.val {
|
GenericArgKind::Const(ct) => match ct.val {
|
||||||
ConstValue::Bound(debruijn, b) => {
|
ty::ConstKind::Bound(debruijn, b) => {
|
||||||
// We only allow a `ty::INNERMOST` index in substitutions.
|
// We only allow a `ty::INNERMOST` index in substitutions.
|
||||||
assert_eq!(debruijn, ty::INNERMOST);
|
assert_eq!(debruijn, ty::INNERMOST);
|
||||||
cvar == b
|
cvar == b
|
||||||
@ -986,7 +986,7 @@ impl<'tcx> CommonConsts<'tcx> {
|
|||||||
|
|
||||||
CommonConsts {
|
CommonConsts {
|
||||||
err: mk_const(ty::Const {
|
err: mk_const(ty::Const {
|
||||||
val: ConstValue::Scalar(Scalar::zst()),
|
val: ty::ConstKind::Value(ConstValue::Scalar(Scalar::zst())),
|
||||||
ty: types.err,
|
ty: types.err,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
@ -2534,7 +2534,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn mk_const_var(self, v: ConstVid<'tcx>, ty: Ty<'tcx>) -> &'tcx Const<'tcx> {
|
pub fn mk_const_var(self, v: ConstVid<'tcx>, ty: Ty<'tcx>) -> &'tcx Const<'tcx> {
|
||||||
self.mk_const(ty::Const {
|
self.mk_const(ty::Const {
|
||||||
val: ConstValue::Infer(InferConst::Var(v)),
|
val: ty::ConstKind::Infer(InferConst::Var(v)),
|
||||||
ty,
|
ty,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -2561,7 +2561,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
) -> &'tcx ty::Const<'tcx> {
|
) -> &'tcx ty::Const<'tcx> {
|
||||||
self.mk_const(ty::Const {
|
self.mk_const(ty::Const {
|
||||||
val: ConstValue::Infer(ic),
|
val: ty::ConstKind::Infer(ic),
|
||||||
ty,
|
ty,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -2579,7 +2579,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
ty: Ty<'tcx>
|
ty: Ty<'tcx>
|
||||||
) -> &'tcx Const<'tcx> {
|
) -> &'tcx Const<'tcx> {
|
||||||
self.mk_const(ty::Const {
|
self.mk_const(ty::Const {
|
||||||
val: ConstValue::Param(ParamConst { index, name }),
|
val: ty::ConstKind::Param(ParamConst { index, name }),
|
||||||
ty,
|
ty,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use crate::ty::subst::{SubstsRef, GenericArgKind};
|
use crate::ty::subst::{SubstsRef, GenericArgKind};
|
||||||
use crate::ty::{self, Ty, TypeFlags, InferConst};
|
use crate::ty::{self, Ty, TypeFlags, InferConst};
|
||||||
use crate::mir::interpret::ConstValue;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct FlagComputation {
|
pub struct FlagComputation {
|
||||||
@ -232,29 +231,27 @@ impl FlagComputation {
|
|||||||
fn add_const(&mut self, c: &ty::Const<'_>) {
|
fn add_const(&mut self, c: &ty::Const<'_>) {
|
||||||
self.add_ty(c.ty);
|
self.add_ty(c.ty);
|
||||||
match c.val {
|
match c.val {
|
||||||
ConstValue::Unevaluated(_, substs) => {
|
ty::ConstKind::Unevaluated(_, substs) => {
|
||||||
self.add_substs(substs);
|
self.add_substs(substs);
|
||||||
self.add_flags(TypeFlags::HAS_PROJECTION);
|
self.add_flags(TypeFlags::HAS_PROJECTION);
|
||||||
},
|
},
|
||||||
ConstValue::Infer(infer) => {
|
ty::ConstKind::Infer(infer) => {
|
||||||
self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES | TypeFlags::HAS_CT_INFER);
|
self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES | TypeFlags::HAS_CT_INFER);
|
||||||
match infer {
|
match infer {
|
||||||
InferConst::Fresh(_) => {}
|
InferConst::Fresh(_) => {}
|
||||||
InferConst::Var(_) => self.add_flags(TypeFlags::KEEP_IN_LOCAL_TCX),
|
InferConst::Var(_) => self.add_flags(TypeFlags::KEEP_IN_LOCAL_TCX),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ConstValue::Bound(debruijn, _) => self.add_binder(debruijn),
|
ty::ConstKind::Bound(debruijn, _) => self.add_binder(debruijn),
|
||||||
ConstValue::Param(_) => {
|
ty::ConstKind::Param(_) => {
|
||||||
self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES);
|
self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES);
|
||||||
self.add_flags(TypeFlags::HAS_PARAMS);
|
self.add_flags(TypeFlags::HAS_PARAMS);
|
||||||
}
|
}
|
||||||
ConstValue::Placeholder(_) => {
|
ty::ConstKind::Placeholder(_) => {
|
||||||
self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES);
|
self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES);
|
||||||
self.add_flags(TypeFlags::HAS_CT_PLACEHOLDER);
|
self.add_flags(TypeFlags::HAS_CT_PLACEHOLDER);
|
||||||
}
|
}
|
||||||
ConstValue::Scalar(_) => {}
|
ty::ConstKind::Value(_) => {}
|
||||||
ConstValue::Slice { .. } => {}
|
|
||||||
ConstValue::ByRef { .. } => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
//! looking for, and does not need to visit anything else.
|
//! looking for, and does not need to visit anything else.
|
||||||
|
|
||||||
use crate::hir::def_id::DefId;
|
use crate::hir::def_id::DefId;
|
||||||
use crate::mir::interpret::ConstValue;
|
|
||||||
use crate::ty::{self, Binder, Ty, TyCtxt, TypeFlags, flags::FlagComputation};
|
use crate::ty::{self, Binder, Ty, TyCtxt, TypeFlags, flags::FlagComputation};
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
@ -521,7 +520,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for BoundVarReplacer<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn fold_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
|
fn fold_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
|
||||||
if let ty::Const { val: ConstValue::Bound(debruijn, bound_const), ty } = *ct {
|
if let ty::Const { val: ty::ConstKind::Bound(debruijn, bound_const), ty } = *ct {
|
||||||
if debruijn == self.current_index {
|
if debruijn == self.current_index {
|
||||||
let fld_c = &mut self.fld_c;
|
let fld_c = &mut self.fld_c;
|
||||||
let ct = fld_c(bound_const, ty);
|
let ct = fld_c(bound_const, ty);
|
||||||
@ -568,7 +567,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
let fld_t = |bound_ty| self.mk_ty(ty::Bound(ty::INNERMOST, bound_ty));
|
let fld_t = |bound_ty| self.mk_ty(ty::Bound(ty::INNERMOST, bound_ty));
|
||||||
let fld_c = |bound_ct, ty| {
|
let fld_c = |bound_ct, ty| {
|
||||||
self.mk_const(ty::Const {
|
self.mk_const(ty::Const {
|
||||||
val: ConstValue::Bound(ty::INNERMOST, bound_ct),
|
val: ty::ConstKind::Bound(ty::INNERMOST, bound_ct),
|
||||||
ty,
|
ty,
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
@ -801,7 +800,7 @@ impl TypeFolder<'tcx> for Shifter<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn fold_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
|
fn fold_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
|
||||||
if let ty::Const { val: ConstValue::Bound(debruijn, bound_ct), ty } = *ct {
|
if let ty::Const { val: ty::ConstKind::Bound(debruijn, bound_ct), ty } = *ct {
|
||||||
if self.amount == 0 || debruijn < self.current_index {
|
if self.amount == 0 || debruijn < self.current_index {
|
||||||
ct
|
ct
|
||||||
} else {
|
} else {
|
||||||
@ -813,7 +812,7 @@ impl TypeFolder<'tcx> for Shifter<'tcx> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
self.tcx.mk_const(ty::Const {
|
self.tcx.mk_const(ty::Const {
|
||||||
val: ConstValue::Bound(debruijn, bound_ct),
|
val: ty::ConstKind::Bound(debruijn, bound_ct),
|
||||||
ty,
|
ty,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -919,7 +918,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasEscapingVarsVisitor {
|
|||||||
// const, as it has types/regions embedded in a lot of other
|
// const, as it has types/regions embedded in a lot of other
|
||||||
// places.
|
// places.
|
||||||
match ct.val {
|
match ct.val {
|
||||||
ConstValue::Bound(debruijn, _) if debruijn >= self.outer_index => true,
|
ty::ConstKind::Bound(debruijn, _) if debruijn >= self.outer_index => true,
|
||||||
_ => ct.super_visit_with(self),
|
_ => ct.super_visit_with(self),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ pub use self::sty::{InferTy, ParamTy, ParamConst, InferConst, ProjectionTy, Exis
|
|||||||
pub use self::sty::{ClosureSubsts, GeneratorSubsts, UpvarSubsts, TypeAndMut};
|
pub use self::sty::{ClosureSubsts, GeneratorSubsts, UpvarSubsts, TypeAndMut};
|
||||||
pub use self::sty::{TraitRef, TyKind, PolyTraitRef};
|
pub use self::sty::{TraitRef, TyKind, PolyTraitRef};
|
||||||
pub use self::sty::{ExistentialTraitRef, PolyExistentialTraitRef};
|
pub use self::sty::{ExistentialTraitRef, PolyExistentialTraitRef};
|
||||||
pub use self::sty::{ExistentialProjection, PolyExistentialProjection, Const};
|
pub use self::sty::{ExistentialProjection, PolyExistentialProjection, Const, ConstKind};
|
||||||
pub use self::sty::{BoundRegion, EarlyBoundRegion, FreeRegion, Region};
|
pub use self::sty::{BoundRegion, EarlyBoundRegion, FreeRegion, Region};
|
||||||
pub use self::sty::RegionKind;
|
pub use self::sty::RegionKind;
|
||||||
pub use self::sty::{TyVid, IntVid, FloatVid, ConstVid, RegionVid};
|
pub use self::sty::{TyVid, IntVid, FloatVid, ConstVid, RegionVid};
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
//! FIXME(eddyb) implement a custom `PrettyPrinter` for this.
|
//! FIXME(eddyb) implement a custom `PrettyPrinter` for this.
|
||||||
|
|
||||||
use rustc::hir::def_id::DefId;
|
use rustc::hir::def_id::DefId;
|
||||||
use rustc::mir::interpret::ConstValue;
|
|
||||||
use rustc::ty::subst::SubstsRef;
|
use rustc::ty::subst::SubstsRef;
|
||||||
use rustc::ty::{self, Const, Instance, Ty, TyCtxt};
|
use rustc::ty::{self, Const, Instance, Ty, TyCtxt};
|
||||||
use rustc::{bug, hir};
|
use rustc::{bug, hir};
|
||||||
@ -170,21 +169,16 @@ impl DefPathBasedNames<'tcx> {
|
|||||||
// If `debug` is true, usually-unprintable consts (such as `Infer`) will be printed,
|
// If `debug` is true, usually-unprintable consts (such as `Infer`) will be printed,
|
||||||
// as well as the unprintable types of constants (see `push_type_name` for more details).
|
// as well as the unprintable types of constants (see `push_type_name` for more details).
|
||||||
pub fn push_const_name(&self, c: &Const<'tcx>, output: &mut String, debug: bool) {
|
pub fn push_const_name(&self, c: &Const<'tcx>, output: &mut String, debug: bool) {
|
||||||
match c.val {
|
if let ty::ConstKind::Value(_) = c.val {
|
||||||
ConstValue::Scalar(..) | ConstValue::Slice { .. } | ConstValue::ByRef { .. } => {
|
// FIXME(const_generics): we could probably do a better job here.
|
||||||
// FIXME(const_generics): we could probably do a better job here.
|
write!(output, "{:?}", c).unwrap()
|
||||||
write!(output, "{:?}", c).unwrap()
|
} else if debug {
|
||||||
}
|
write!(output, "{:?}", c).unwrap()
|
||||||
_ => {
|
} else {
|
||||||
if debug {
|
bug!(
|
||||||
write!(output, "{:?}", c).unwrap()
|
"DefPathBasedNames: trying to create const name for unexpected const: {:?}",
|
||||||
} else {
|
c,
|
||||||
bug!(
|
);
|
||||||
"DefPathBasedNames: trying to create const name for unexpected const: {:?}",
|
|
||||||
c,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
output.push_str(": ");
|
output.push_str(": ");
|
||||||
self.push_type_name(c.ty, output, debug);
|
self.push_type_name(c.ty, output, debug);
|
||||||
|
@ -699,7 +699,7 @@ pub trait PrettyPrinter<'tcx>:
|
|||||||
p!(write("["), print(ty), write("; "));
|
p!(write("["), print(ty), write("; "));
|
||||||
if self.tcx().sess.verbose() {
|
if self.tcx().sess.verbose() {
|
||||||
p!(write("{:?}", sz));
|
p!(write("{:?}", sz));
|
||||||
} else if let ConstValue::Unevaluated(..) = sz.val {
|
} else if let ty::ConstKind::Unevaluated(..) = sz.val {
|
||||||
// do not try to evalute unevaluated constants. If we are const evaluating an
|
// do not try to evalute unevaluated constants. If we are const evaluating an
|
||||||
// array length anon const, rustc will (with debug assertions) print the
|
// array length anon const, rustc will (with debug assertions) print the
|
||||||
// constant's path. Which will end up here again.
|
// constant's path. Which will end up here again.
|
||||||
@ -865,7 +865,7 @@ pub trait PrettyPrinter<'tcx>:
|
|||||||
|
|
||||||
match (ct.val, &ct.ty.kind) {
|
match (ct.val, &ct.ty.kind) {
|
||||||
(_, ty::FnDef(did, substs)) => p!(print_value_path(*did, substs)),
|
(_, ty::FnDef(did, substs)) => p!(print_value_path(*did, substs)),
|
||||||
(ConstValue::Unevaluated(did, substs), _) => {
|
(ty::ConstKind::Unevaluated(did, substs), _) => {
|
||||||
match self.tcx().def_kind(did) {
|
match self.tcx().def_kind(did) {
|
||||||
| Some(DefKind::Static)
|
| Some(DefKind::Static)
|
||||||
| Some(DefKind::Const)
|
| Some(DefKind::Const)
|
||||||
@ -882,15 +882,15 @@ pub trait PrettyPrinter<'tcx>:
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(ConstValue::Infer(..), _) => p!(write("_: "), print(ct.ty)),
|
(ty::ConstKind::Infer(..), _) => p!(write("_: "), print(ct.ty)),
|
||||||
(ConstValue::Param(ParamConst { name, .. }), _) => p!(write("{}", name)),
|
(ty::ConstKind::Param(ParamConst { name, .. }), _) => p!(write("{}", name)),
|
||||||
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Bool) =>
|
(ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw { data, .. })), ty::Bool) =>
|
||||||
p!(write("{}", if data == 0 { "false" } else { "true" })),
|
p!(write("{}", if data == 0 { "false" } else { "true" })),
|
||||||
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Float(ast::FloatTy::F32)) =>
|
(ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw { data, .. })), ty::Float(ast::FloatTy::F32)) =>
|
||||||
p!(write("{}f32", Single::from_bits(data))),
|
p!(write("{}f32", Single::from_bits(data))),
|
||||||
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Float(ast::FloatTy::F64)) =>
|
(ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw { data, .. })), ty::Float(ast::FloatTy::F64)) =>
|
||||||
p!(write("{}f64", Double::from_bits(data))),
|
p!(write("{}f64", Double::from_bits(data))),
|
||||||
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Uint(ui)) => {
|
(ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw { data, .. })), ty::Uint(ui)) => {
|
||||||
let bit_size = Integer::from_attr(&self.tcx(), UnsignedInt(*ui)).size();
|
let bit_size = Integer::from_attr(&self.tcx(), UnsignedInt(*ui)).size();
|
||||||
let max = truncate(u128::max_value(), bit_size);
|
let max = truncate(u128::max_value(), bit_size);
|
||||||
|
|
||||||
@ -901,7 +901,7 @@ pub trait PrettyPrinter<'tcx>:
|
|||||||
p!(write("{}{}", data, ui_str))
|
p!(write("{}{}", data, ui_str))
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Int(i)) => {
|
(ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw { data, .. })), ty::Int(i)) => {
|
||||||
let bit_size = Integer::from_attr(&self.tcx(), SignedInt(*i))
|
let bit_size = Integer::from_attr(&self.tcx(), SignedInt(*i))
|
||||||
.size().bits() as u128;
|
.size().bits() as u128;
|
||||||
let min = 1u128 << (bit_size - 1);
|
let min = 1u128 << (bit_size - 1);
|
||||||
@ -918,10 +918,10 @@ pub trait PrettyPrinter<'tcx>:
|
|||||||
_ => p!(write("{}{}", sign_extend(data, size) as i128, i_str))
|
_ => p!(write("{}{}", sign_extend(data, size) as i128, i_str))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Char) =>
|
(ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw { data, .. })), ty::Char) =>
|
||||||
p!(write("{:?}", ::std::char::from_u32(data as u32).unwrap())),
|
p!(write("{:?}", ::std::char::from_u32(data as u32).unwrap())),
|
||||||
(ConstValue::Scalar(_), ty::RawPtr(_)) => p!(write("{{pointer}}")),
|
(ty::ConstKind::Value(ConstValue::Scalar(_)), ty::RawPtr(_)) => p!(write("{{pointer}}")),
|
||||||
(ConstValue::Scalar(Scalar::Ptr(ptr)), ty::FnPtr(_)) => {
|
(ty::ConstKind::Value(ConstValue::Scalar(Scalar::Ptr(ptr))), ty::FnPtr(_)) => {
|
||||||
let instance = {
|
let instance = {
|
||||||
let alloc_map = self.tcx().alloc_map.lock();
|
let alloc_map = self.tcx().alloc_map.lock();
|
||||||
alloc_map.unwrap_fn(ptr.alloc_id)
|
alloc_map.unwrap_fn(ptr.alloc_id)
|
||||||
@ -931,14 +931,14 @@ pub trait PrettyPrinter<'tcx>:
|
|||||||
_ => {
|
_ => {
|
||||||
let printed = if let ty::Ref(_, ref_ty, _) = ct.ty.kind {
|
let printed = if let ty::Ref(_, ref_ty, _) = ct.ty.kind {
|
||||||
let byte_str = match (ct.val, &ref_ty.kind) {
|
let byte_str = match (ct.val, &ref_ty.kind) {
|
||||||
(ConstValue::Scalar(Scalar::Ptr(ptr)), ty::Array(t, n)) if *t == u8 => {
|
(ty::ConstKind::Value(ConstValue::Scalar(Scalar::Ptr(ptr))), ty::Array(t, n)) if *t == u8 => {
|
||||||
let n = n.eval_usize(self.tcx(), ty::ParamEnv::empty());
|
let n = n.eval_usize(self.tcx(), ty::ParamEnv::empty());
|
||||||
Some(self.tcx()
|
Some(self.tcx()
|
||||||
.alloc_map.lock()
|
.alloc_map.lock()
|
||||||
.unwrap_memory(ptr.alloc_id)
|
.unwrap_memory(ptr.alloc_id)
|
||||||
.get_bytes(&self.tcx(), ptr, Size::from_bytes(n)).unwrap())
|
.get_bytes(&self.tcx(), ptr, Size::from_bytes(n)).unwrap())
|
||||||
},
|
},
|
||||||
(ConstValue::Slice { data, start, end }, ty::Slice(t)) if *t == u8 => {
|
(ty::ConstKind::Value(ConstValue::Slice { data, start, end }), ty::Slice(t)) if *t == u8 => {
|
||||||
// The `inspect` here is okay since we checked the bounds, and there are
|
// The `inspect` here is okay since we checked the bounds, and there are
|
||||||
// no relocations (we have an active slice reference here). We don't use
|
// no relocations (we have an active slice reference here). We don't use
|
||||||
// this result to affect interpreter execution.
|
// this result to affect interpreter execution.
|
||||||
@ -956,7 +956,7 @@ pub trait PrettyPrinter<'tcx>:
|
|||||||
}
|
}
|
||||||
p!(write("\""));
|
p!(write("\""));
|
||||||
true
|
true
|
||||||
} else if let (ConstValue::Slice { data, start, end }, ty::Str) =
|
} else if let (ty::ConstKind::Value(ConstValue::Slice { data, start, end }), ty::Str) =
|
||||||
(ct.val, &ref_ty.kind)
|
(ct.val, &ref_ty.kind)
|
||||||
{
|
{
|
||||||
// The `inspect` here is okay since we checked the bounds, and there are no
|
// The `inspect` here is okay since we checked the bounds, and there are no
|
||||||
|
@ -561,51 +561,62 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
|
|||||||
// and those that derive both `PartialEq` and `Eq`, corresponding
|
// and those that derive both `PartialEq` and `Eq`, corresponding
|
||||||
// to `structural_match` types.
|
// to `structural_match` types.
|
||||||
let new_const_val = match (eagerly_eval(a), eagerly_eval(b)) {
|
let new_const_val = match (eagerly_eval(a), eagerly_eval(b)) {
|
||||||
(ConstValue::Infer(_), _) | (_, ConstValue::Infer(_)) => {
|
(ty::ConstKind::Infer(_), _) | (_, ty::ConstKind::Infer(_)) => {
|
||||||
// The caller should handle these cases!
|
// The caller should handle these cases!
|
||||||
bug!("var types encountered in super_relate_consts: {:?} {:?}", a, b)
|
bug!("var types encountered in super_relate_consts: {:?} {:?}", a, b)
|
||||||
}
|
}
|
||||||
(ConstValue::Param(a_p), ConstValue::Param(b_p)) if a_p.index == b_p.index => {
|
(ty::ConstKind::Param(a_p), ty::ConstKind::Param(b_p)) if a_p.index == b_p.index => {
|
||||||
return Ok(a);
|
return Ok(a);
|
||||||
}
|
}
|
||||||
(ConstValue::Placeholder(p1), ConstValue::Placeholder(p2)) if p1 == p2 => {
|
(ty::ConstKind::Placeholder(p1), ty::ConstKind::Placeholder(p2)) if p1 == p2 => {
|
||||||
return Ok(a);
|
return Ok(a);
|
||||||
}
|
}
|
||||||
(ConstValue::Scalar(a_val), ConstValue::Scalar(b_val)) if a.ty == b.ty => {
|
(ty::ConstKind::Value(a_val), ty::ConstKind::Value(b_val)) => {
|
||||||
if a_val == b_val {
|
let new_val = match (a_val, b_val) {
|
||||||
Ok(ConstValue::Scalar(a_val))
|
(ConstValue::Scalar(a_val), ConstValue::Scalar(b_val)) if a.ty == b.ty => {
|
||||||
} else if let ty::FnPtr(_) = a.ty.kind {
|
if a_val == b_val {
|
||||||
let alloc_map = tcx.alloc_map.lock();
|
Ok(ConstValue::Scalar(a_val))
|
||||||
let a_instance = alloc_map.unwrap_fn(a_val.to_ptr().unwrap().alloc_id);
|
} else if let ty::FnPtr(_) = a.ty.kind {
|
||||||
let b_instance = alloc_map.unwrap_fn(b_val.to_ptr().unwrap().alloc_id);
|
let alloc_map = tcx.alloc_map.lock();
|
||||||
if a_instance == b_instance {
|
let a_instance = alloc_map.unwrap_fn(a_val.to_ptr().unwrap().alloc_id);
|
||||||
Ok(ConstValue::Scalar(a_val))
|
let b_instance = alloc_map.unwrap_fn(b_val.to_ptr().unwrap().alloc_id);
|
||||||
} else {
|
if a_instance == b_instance {
|
||||||
Err(TypeError::ConstMismatch(expected_found(relation, &a, &b)))
|
Ok(ConstValue::Scalar(a_val))
|
||||||
|
} else {
|
||||||
|
Err(TypeError::ConstMismatch(expected_found(relation, &a, &b)))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err(TypeError::ConstMismatch(expected_found(relation, &a, &b)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Err(TypeError::ConstMismatch(expected_found(relation, &a, &b)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
(a_val @ ConstValue::Slice { .. }, b_val @ ConstValue::Slice { .. }) => {
|
(a_val @ ConstValue::Slice { .. }, b_val @ ConstValue::Slice { .. }) => {
|
||||||
let a_bytes = get_slice_bytes(&tcx, a_val);
|
let a_bytes = get_slice_bytes(&tcx, a_val);
|
||||||
let b_bytes = get_slice_bytes(&tcx, b_val);
|
let b_bytes = get_slice_bytes(&tcx, b_val);
|
||||||
if a_bytes == b_bytes {
|
if a_bytes == b_bytes {
|
||||||
Ok(a_val)
|
Ok(a_val)
|
||||||
} else {
|
} else {
|
||||||
Err(TypeError::ConstMismatch(expected_found(relation, &a, &b)))
|
Err(TypeError::ConstMismatch(expected_found(relation, &a, &b)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(const_generics): handle `ConstValue::ByRef`.
|
// FIXME(const_generics): handle `ConstValue::ByRef`.
|
||||||
|
|
||||||
|
_ => Err(TypeError::ConstMismatch(expected_found(relation, &a, &b))),
|
||||||
|
};
|
||||||
|
|
||||||
|
match new_val {
|
||||||
|
Ok(val) => Ok(ty::ConstKind::Value(val)),
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// FIXME(const_generics): this is wrong, as it is a projection
|
// FIXME(const_generics): this is wrong, as it is a projection
|
||||||
(ConstValue::Unevaluated(a_def_id, a_substs),
|
(ty::ConstKind::Unevaluated(a_def_id, a_substs),
|
||||||
ConstValue::Unevaluated(b_def_id, b_substs)) if a_def_id == b_def_id => {
|
ty::ConstKind::Unevaluated(b_def_id, b_substs)) if a_def_id == b_def_id => {
|
||||||
let substs =
|
let substs =
|
||||||
relation.relate_with_variance(ty::Variance::Invariant, &a_substs, &b_substs)?;
|
relation.relate_with_variance(ty::Variance::Invariant, &a_substs, &b_substs)?;
|
||||||
Ok(ConstValue::Unevaluated(a_def_id, &substs))
|
Ok(ty::ConstKind::Unevaluated(a_def_id, &substs))
|
||||||
}
|
}
|
||||||
_ => Err(TypeError::ConstMismatch(expected_found(relation, &a, &b))),
|
_ => Err(TypeError::ConstMismatch(expected_found(relation, &a, &b))),
|
||||||
};
|
};
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
use crate::hir::def::Namespace;
|
use crate::hir::def::Namespace;
|
||||||
use crate::mir::ProjectionKind;
|
use crate::mir::ProjectionKind;
|
||||||
use crate::mir::interpret::ConstValue;
|
|
||||||
use crate::ty::{self, Lift, Ty, TyCtxt, InferConst};
|
use crate::ty::{self, Lift, Ty, TyCtxt, InferConst};
|
||||||
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
|
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
|
||||||
use crate::ty::print::{FmtPrinter, Printer};
|
use crate::ty::print::{FmtPrinter, Printer};
|
||||||
@ -1378,26 +1377,25 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Const<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeFoldable<'tcx> for ConstValue<'tcx> {
|
impl<'tcx> TypeFoldable<'tcx> for ty::ConstKind<'tcx> {
|
||||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||||
match *self {
|
match *self {
|
||||||
ConstValue::Infer(ic) => ConstValue::Infer(ic.fold_with(folder)),
|
ty::ConstKind::Infer(ic) => ty::ConstKind::Infer(ic.fold_with(folder)),
|
||||||
ConstValue::Param(p) => ConstValue::Param(p.fold_with(folder)),
|
ty::ConstKind::Param(p) => ty::ConstKind::Param(p.fold_with(folder)),
|
||||||
ConstValue::Unevaluated(did, substs)
|
ty::ConstKind::Unevaluated(did, substs)
|
||||||
=> ConstValue::Unevaluated(did, substs.fold_with(folder)),
|
=> ty::ConstKind::Unevaluated(did, substs.fold_with(folder)),
|
||||||
ConstValue::ByRef { .. } | ConstValue::Bound(..) | ConstValue::Placeholder(..)
|
ty::ConstKind::Value(_) | ty::ConstKind::Bound(..)
|
||||||
| ConstValue::Scalar(..) | ConstValue::Slice { .. } => *self,
|
| ty::ConstKind::Placeholder(..) => *self,
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
ConstValue::Infer(ic) => ic.visit_with(visitor),
|
ty::ConstKind::Infer(ic) => ic.visit_with(visitor),
|
||||||
ConstValue::Param(p) => p.visit_with(visitor),
|
ty::ConstKind::Param(p) => p.visit_with(visitor),
|
||||||
ConstValue::Unevaluated(_, substs) => substs.visit_with(visitor),
|
ty::ConstKind::Unevaluated(_, substs) => substs.visit_with(visitor),
|
||||||
ConstValue::ByRef { .. } | ConstValue::Bound(..) | ConstValue::Placeholder(_)
|
ty::ConstKind::Value(_) | ty::ConstKind::Bound(..)
|
||||||
| ConstValue::Scalar(_) | ConstValue::Slice { .. } => false,
|
| ty::ConstKind::Placeholder(_) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2257,17 +2257,17 @@ impl<'tcx> TyS<'tcx> {
|
|||||||
pub struct Const<'tcx> {
|
pub struct Const<'tcx> {
|
||||||
pub ty: Ty<'tcx>,
|
pub ty: Ty<'tcx>,
|
||||||
|
|
||||||
pub val: ConstValue<'tcx>,
|
pub val: ConstKind<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
static_assert_size!(Const<'_>, 40);
|
static_assert_size!(Const<'_>, 48);
|
||||||
|
|
||||||
impl<'tcx> Const<'tcx> {
|
impl<'tcx> Const<'tcx> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_scalar(tcx: TyCtxt<'tcx>, val: Scalar, ty: Ty<'tcx>) -> &'tcx Self {
|
pub fn from_scalar(tcx: TyCtxt<'tcx>, val: Scalar, ty: Ty<'tcx>) -> &'tcx Self {
|
||||||
tcx.mk_const(Self {
|
tcx.mk_const(Self {
|
||||||
val: ConstValue::Scalar(val),
|
val: ConstKind::Value(ConstValue::Scalar(val)),
|
||||||
ty,
|
ty,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -2317,7 +2317,7 @@ impl<'tcx> Const<'tcx> {
|
|||||||
// FIXME(const_generics): this doesn't work right now,
|
// FIXME(const_generics): this doesn't work right now,
|
||||||
// because it tries to relate an `Infer` to a `Param`.
|
// because it tries to relate an `Infer` to a `Param`.
|
||||||
match self.val {
|
match self.val {
|
||||||
ConstValue::Unevaluated(did, substs) => {
|
ConstKind::Unevaluated(did, substs) => {
|
||||||
// if `substs` has no unresolved components, use and empty param_env
|
// if `substs` has no unresolved components, use and empty param_env
|
||||||
let (param_env, substs) = param_env.with_reveal_all().and(substs).into_parts();
|
let (param_env, substs) = param_env.with_reveal_all().and(substs).into_parts();
|
||||||
// try to resolve e.g. associated constants to their definition on an impl
|
// try to resolve e.g. associated constants to their definition on an impl
|
||||||
@ -2363,6 +2363,54 @@ impl<'tcx> Const<'tcx> {
|
|||||||
|
|
||||||
impl<'tcx> rustc_serialize::UseSpecializedDecodable for &'tcx Const<'tcx> {}
|
impl<'tcx> rustc_serialize::UseSpecializedDecodable for &'tcx Const<'tcx> {}
|
||||||
|
|
||||||
|
/// Represents a constant in Rust.
|
||||||
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord,
|
||||||
|
RustcEncodable, RustcDecodable, Hash, HashStable)]
|
||||||
|
pub enum ConstKind<'tcx> {
|
||||||
|
/// A const generic parameter.
|
||||||
|
Param(ParamConst),
|
||||||
|
|
||||||
|
/// Infer the value of the const.
|
||||||
|
Infer(InferConst<'tcx>),
|
||||||
|
|
||||||
|
/// Bound const variable, used only when preparing a trait query.
|
||||||
|
Bound(DebruijnIndex, BoundVar),
|
||||||
|
|
||||||
|
/// A placeholder const - universally quantified higher-ranked const.
|
||||||
|
Placeholder(ty::PlaceholderConst),
|
||||||
|
|
||||||
|
/// Used in the HIR by using `Unevaluated` everywhere and later normalizing to one of the other
|
||||||
|
/// variants when the code is monomorphic enough for that.
|
||||||
|
Unevaluated(DefId, SubstsRef<'tcx>),
|
||||||
|
|
||||||
|
/// Used to hold computed value.
|
||||||
|
Value(ConstValue<'tcx>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
static_assert_size!(ConstKind<'_>, 40);
|
||||||
|
|
||||||
|
impl<'tcx> ConstKind<'tcx> {
|
||||||
|
#[inline]
|
||||||
|
pub fn try_to_scalar(&self) -> Option<Scalar> {
|
||||||
|
if let ConstKind::Value(val) = self {
|
||||||
|
val.try_to_scalar()
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn try_to_bits(&self, size: ty::layout::Size) -> Option<u128> {
|
||||||
|
self.try_to_scalar()?.to_bits(size).ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
//#[inline]
|
||||||
|
//pub fn try_to_ptr(&self) -> Option<mir::interpret::Pointer> {
|
||||||
|
// self.try_to_scalar()?.to_ptr().ok()
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
/// 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, Debug, Eq, PartialEq, PartialOrd,
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd,
|
||||||
Ord, RustcEncodable, RustcDecodable, Hash, HashStable)]
|
Ord, RustcEncodable, RustcDecodable, Hash, HashStable)]
|
||||||
|
@ -4,7 +4,6 @@ use crate::hir::def_id::DefId;
|
|||||||
use crate::infer::canonical::Canonical;
|
use crate::infer::canonical::Canonical;
|
||||||
use crate::ty::{self, Lift, List, Ty, TyCtxt, ParamConst};
|
use crate::ty::{self, Lift, List, Ty, TyCtxt, ParamConst};
|
||||||
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
|
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
|
||||||
use crate::mir::interpret::ConstValue;
|
|
||||||
use crate::ty::sty::{ClosureSubsts, GeneratorSubsts};
|
use crate::ty::sty::{ClosureSubsts, GeneratorSubsts};
|
||||||
|
|
||||||
use rustc_serialize::{self, Encodable, Encoder, Decodable, Decoder};
|
use rustc_serialize::{self, Encodable, Encoder, Decodable, Decoder};
|
||||||
@ -234,7 +233,7 @@ impl<'a, 'tcx> InternalSubsts<'tcx> {
|
|||||||
|
|
||||||
ty::GenericParamDefKind::Const => {
|
ty::GenericParamDefKind::Const => {
|
||||||
tcx.mk_const(ty::Const {
|
tcx.mk_const(ty::Const {
|
||||||
val: ConstValue::Bound(ty::INNERMOST, ty::BoundVar::from(param.index)),
|
val: ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from(param.index)),
|
||||||
ty: tcx.type_of(def_id),
|
ty: tcx.type_of(def_id),
|
||||||
}).into()
|
}).into()
|
||||||
}
|
}
|
||||||
@ -578,7 +577,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let ConstValue::Param(p) = c.val {
|
if let ty::ConstKind::Param(p) = c.val {
|
||||||
self.const_for_param(p, c)
|
self.const_for_param(p, c)
|
||||||
} else {
|
} else {
|
||||||
c.super_fold_with(self)
|
c.super_fold_with(self)
|
||||||
|
@ -12,7 +12,6 @@ use crate::ty::subst::{Subst, InternalSubsts, SubstsRef, GenericArgKind};
|
|||||||
use crate::ty::query::TyCtxtAt;
|
use crate::ty::query::TyCtxtAt;
|
||||||
use crate::ty::TyKind::*;
|
use crate::ty::TyKind::*;
|
||||||
use crate::ty::layout::{Integer, IntegerExt};
|
use crate::ty::layout::{Integer, IntegerExt};
|
||||||
use crate::mir::interpret::ConstValue;
|
|
||||||
use crate::util::common::ErrorReported;
|
use crate::util::common::ErrorReported;
|
||||||
use crate::middle::lang_items;
|
use crate::middle::lang_items;
|
||||||
|
|
||||||
@ -566,7 +565,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
!impl_generics.type_param(pt, self).pure_wrt_drop
|
!impl_generics.type_param(pt, self).pure_wrt_drop
|
||||||
}
|
}
|
||||||
GenericArgKind::Const(&ty::Const {
|
GenericArgKind::Const(&ty::Const {
|
||||||
val: ConstValue::Param(ref pc),
|
val: ty::ConstKind::Param(ref pc),
|
||||||
..
|
..
|
||||||
}) => {
|
}) => {
|
||||||
!impl_generics.const_param(pc, self).pure_wrt_drop
|
!impl_generics.const_param(pc, self).pure_wrt_drop
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
use crate::ty::{self, Ty};
|
use crate::ty::{self, Ty};
|
||||||
use smallvec::{self, SmallVec};
|
use smallvec::{self, SmallVec};
|
||||||
use crate::mir::interpret::ConstValue;
|
|
||||||
|
|
||||||
// The TypeWalker's stack is hot enough that it's worth going to some effort to
|
// The TypeWalker's stack is hot enough that it's worth going to some effort to
|
||||||
// avoid heap allocations.
|
// avoid heap allocations.
|
||||||
@ -75,7 +74,7 @@ fn push_subtypes<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent_ty: Ty<'tcx>) {
|
|||||||
ty::Placeholder(..) | ty::Bound(..) | ty::Foreign(..) => {
|
ty::Placeholder(..) | ty::Bound(..) | ty::Foreign(..) => {
|
||||||
}
|
}
|
||||||
ty::Array(ty, len) => {
|
ty::Array(ty, len) => {
|
||||||
if let ConstValue::Unevaluated(_, substs) = len.val {
|
if let ty::ConstKind::Unevaluated(_, substs) = len.val {
|
||||||
stack.extend(substs.types().rev());
|
stack.extend(substs.types().rev());
|
||||||
}
|
}
|
||||||
stack.push(len.ty);
|
stack.push(len.ty);
|
||||||
|
@ -8,7 +8,6 @@ use std::iter::once;
|
|||||||
use syntax::symbol::{kw, Ident};
|
use syntax::symbol::{kw, Ident};
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
use crate::middle::lang_items;
|
use crate::middle::lang_items;
|
||||||
use crate::mir::interpret::ConstValue;
|
|
||||||
|
|
||||||
/// Returns the set of obligations needed to make `ty` well-formed.
|
/// Returns the set of obligations needed to make `ty` well-formed.
|
||||||
/// If `ty` contains unresolved inference variables, this may include
|
/// If `ty` contains unresolved inference variables, this may include
|
||||||
@ -363,7 +362,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
|||||||
/// Pushes the obligations required for an array length to be WF
|
/// Pushes the obligations required for an array length to be WF
|
||||||
/// into `self.out`.
|
/// into `self.out`.
|
||||||
fn compute_array_len(&mut self, constant: ty::Const<'tcx>) {
|
fn compute_array_len(&mut self, constant: ty::Const<'tcx>) {
|
||||||
if let ConstValue::Unevaluated(def_id, substs) = constant.val {
|
if let ty::ConstKind::Unevaluated(def_id, substs) = constant.val {
|
||||||
let obligations = self.nominal_obligations(def_id, substs);
|
let obligations = self.nominal_obligations(def_id, substs);
|
||||||
self.out.extend(obligations);
|
self.out.extend(obligations);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user