From f5712d2de09e2c35843150b05fdf3672534dff00 Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 12 Mar 2019 20:25:41 +0000 Subject: [PATCH] Add `ConstValue::Placeholder` --- src/librustc/infer/canonical/canonicalizer.rs | 6 ++++-- src/librustc/infer/freshen.rs | 3 ++- src/librustc/mir/interpret/value.rs | 1 + src/librustc/ty/flags.rs | 3 +++ src/librustc/ty/fold.rs | 6 +++++- src/librustc/ty/mod.rs | 4 +++- src/librustc/ty/relate.rs | 3 +++ src/librustc_codegen_ssa/mir/operand.rs | 1 + src/librustc_mir/interpret/operand.rs | 2 +- src/librustc_mir/monomorphize/item.rs | 2 +- 10 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/librustc/infer/canonical/canonicalizer.rs b/src/librustc/infer/canonical/canonicalizer.rs index 0fc13bdaee6..22e5767df33 100644 --- a/src/librustc/infer/canonical/canonicalizer.rs +++ b/src/librustc/infer/canonical/canonicalizer.rs @@ -499,11 +499,13 @@ fn canonicalize( 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(); diff --git a/src/librustc/infer/freshen.rs b/src/librustc/infer/freshen.rs index b43f78efffb..aa1a8636196 100644 --- a/src/librustc/infer/freshen.rs +++ b/src/librustc/infer/freshen.rs @@ -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) } diff --git a/src/librustc/mir/interpret/value.rs b/src/librustc/mir/interpret/value.rs index 18c82ecd38e..12178196cef 100644 --- a/src/librustc/mir/interpret/value.rs +++ b/src/librustc/mir/interpret/value.rs @@ -58,6 +58,7 @@ pub fn try_to_scalar(&self) -> Option { match *self { ConstValue::Param(_) | ConstValue::Infer(_) | + ConstValue::Placeholder(_) | ConstValue::ByRef(..) | ConstValue::Unevaluated(..) | ConstValue::Slice(..) => None, diff --git a/src/librustc/ty/flags.rs b/src/librustc/ty/flags.rs index cb4724adc93..8d7e7e16e85 100644 --- a/src/librustc/ty/flags.rs +++ b/src/librustc/ty/flags.rs @@ -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); + } _ => {}, } } diff --git a/src/librustc/ty/fold.rs b/src/librustc/ty/fold.rs index 13b5885f51d..5d3c71f3eab 100644 --- a/src/librustc/ty/fold.rs +++ b/src/librustc/ty/fold.rs @@ -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) diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 6b938ea2fcc..09fd7f2e79a 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -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; } } diff --git a/src/librustc/ty/relate.rs b/src/librustc/ty/relate.rs index 5b5eb783f57..e60edfeba1c 100644 --- a/src/librustc/ty/relate.rs +++ b/src/librustc/ty/relate.rs @@ -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) } diff --git a/src/librustc_codegen_ssa/mir/operand.rs b/src/librustc_codegen_ssa/mir/operand.rs index c2b1021f816..3b8e5b44953 100644 --- a/src/librustc_codegen_ssa/mir/operand.rs +++ b/src/librustc_codegen_ssa/mir/operand.rs @@ -79,6 +79,7 @@ pub fn from_const>( 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, diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index 55c1bfb17de..df6d4568ab3 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -524,7 +524,7 @@ pub(super) fn eval_operands( layout: Option>, ) -> 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. diff --git a/src/librustc_mir/monomorphize/item.rs b/src/librustc_mir/monomorphize/item.rs index 2fc0e08834a..b001a09529e 100644 --- a/src/librustc_mir/monomorphize/item.rs +++ b/src/librustc_mir/monomorphize/item.rs @@ -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(); } -- 2.44.0