Add ConstValue::Placeholder

This commit is contained in:
varkor 2019-03-12 20:25:41 +00:00
parent 245a474ab7
commit f5712d2de0
10 changed files with 24 additions and 7 deletions

View File

@ -499,11 +499,13 @@ fn canonicalize<V>(
let needs_canonical_flags = if canonicalize_region_mode.any() {
TypeFlags::KEEP_IN_LOCAL_TCX |
TypeFlags::HAS_FREE_REGIONS | // `HAS_RE_PLACEHOLDER` implies `HAS_FREE_REGIONS`
TypeFlags::HAS_TY_PLACEHOLDER
TypeFlags::HAS_TY_PLACEHOLDER |
TypeFlags::HAS_CT_PLACEHOLDER
} else {
TypeFlags::KEEP_IN_LOCAL_TCX |
TypeFlags::HAS_RE_PLACEHOLDER |
TypeFlags::HAS_TY_PLACEHOLDER
TypeFlags::HAS_TY_PLACEHOLDER |
TypeFlags::HAS_CT_PLACEHOLDER
};
let gcx = tcx.global_tcx();

View File

@ -253,7 +253,8 @@ fn fold_const(&mut self, ct: &'tcx ty::LazyConst<'tcx>) -> &'tcx ty::LazyConst<'
return ct;
}
ConstValue::Infer(ty::InferConst::Canonical(..)) => {
ConstValue::Infer(ty::InferConst::Canonical(..)) |
ConstValue::Placeholder(_) => {
bug!("unexpected const {:?}", ct)
}

View File

@ -58,6 +58,7 @@ pub fn try_to_scalar(&self) -> Option<Scalar> {
match *self {
ConstValue::Param(_) |
ConstValue::Infer(_) |
ConstValue::Placeholder(_) |
ConstValue::ByRef(..) |
ConstValue::Unevaluated(..) |
ConstValue::Slice(..) => None,

View File

@ -254,6 +254,9 @@ fn add_const(&mut self, c: &ty::Const<'_>) {
ConstValue::Param(_) => {
self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES | TypeFlags::HAS_PARAMS);
}
ConstValue::Placeholder(_) => {
self.add_flags(TypeFlags::HAS_FREE_REGIONS | TypeFlags::HAS_CT_PLACEHOLDER);
}
_ => {},
}
}

View File

@ -97,7 +97,11 @@ fn needs_infer(&self) -> bool {
)
}
fn has_placeholders(&self) -> bool {
self.has_type_flags(TypeFlags::HAS_RE_PLACEHOLDER | TypeFlags::HAS_TY_PLACEHOLDER)
self.has_type_flags(
TypeFlags::HAS_RE_PLACEHOLDER |
TypeFlags::HAS_TY_PLACEHOLDER |
TypeFlags::HAS_CT_PLACEHOLDER
)
}
fn needs_subst(&self) -> bool {
self.has_type_flags(TypeFlags::NEEDS_SUBST)

View File

@ -455,6 +455,7 @@ pub struct TypeFlags: u32 {
const HAS_TY_PLACEHOLDER = 1 << 14;
const HAS_CT_INFER = 1 << 15;
const HAS_CT_PLACEHOLDER = 1 << 16;
const NEEDS_SUBST = TypeFlags::HAS_PARAMS.bits |
TypeFlags::HAS_SELF.bits |
@ -477,7 +478,8 @@ pub struct TypeFlags: u32 {
TypeFlags::HAS_FREE_LOCAL_NAMES.bits |
TypeFlags::KEEP_IN_LOCAL_TCX.bits |
TypeFlags::HAS_RE_LATE_BOUND.bits |
TypeFlags::HAS_TY_PLACEHOLDER.bits;
TypeFlags::HAS_TY_PLACEHOLDER.bits |
TypeFlags::HAS_CT_PLACEHOLDER.bits;
}
}

View File

@ -615,6 +615,9 @@ pub fn super_relate_consts<'a, 'gcx, 'tcx, R>(
(ConstValue::Param(a_p), ConstValue::Param(b_p)) if a_p.index == b_p.index => {
Ok(a)
}
(ConstValue::Placeholder(p1), ConstValue::Placeholder(p2)) if p1 == p2 => {
Ok(a)
}
(ConstValue::Scalar(Scalar::Bits { .. }), _) if a == b => {
Ok(a)
}

View File

@ -79,6 +79,7 @@ pub fn from_const<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
ConstValue::Unevaluated(..) => bug!("unevaluated constant in `OperandRef::from_const`"),
ConstValue::Param(_) => bug!("encountered a ConstValue::Param in codegen"),
ConstValue::Infer(_) => bug!("encountered a ConstValue::Infer in codegen"),
ConstValue::Placeholder(_) => bug!("encountered a ConstValue::Placeholder in codegen"),
ConstValue::Scalar(x) => {
let scalar = match layout.abi {
layout::Abi::Scalar(ref x) => x,

View File

@ -524,7 +524,7 @@ pub(super) fn eval_operands(
layout: Option<TyLayout<'tcx>>,
) -> EvalResult<'tcx, OpTy<'tcx, M::PointerTag>> {
let op = match val.val {
ConstValue::Param(_) | ConstValue::Infer(_) => bug!(),
ConstValue::Param(_) | ConstValue::Infer(_) | ConstValue::Placeholder(_) => bug!(),
ConstValue::ByRef(ptr, alloc) => {
// We rely on mutability being set correctly in that allocation to prevent writes
// where none should happen -- and for `static mut`, we copy on demand anyway.

View File

@ -397,7 +397,7 @@ pub fn push_type_name(&self, t: Ty<'tcx>, output: &mut String, debug: bool) {
// FIXME(const_generics): handle debug printing.
pub fn push_const_name(&self, c: &Const<'tcx>, output: &mut String, debug: bool) {
match c.val {
ConstValue::Infer(..) => output.push_str("_"),
ConstValue::Infer(..) | ConstValue::Placeholder(_) => output.push_str("_"),
ConstValue::Param(ParamConst { name, .. }) => {
write!(output, "{}", name).unwrap();
}