diff --git a/src/librustc/ich/impls_mir.rs b/src/librustc/ich/impls_mir.rs index 9a061da177ebad8d3b1ab624e3b1e065dc66df0c..dce1639b375b781587fb1be335e0d94045312478 100644 --- a/src/librustc/ich/impls_mir.rs +++ b/src/librustc/ich/impls_mir.rs @@ -493,10 +493,6 @@ fn hash_stable(&self, hasher: &mut StableHasher) { mem::discriminant(self).hash_stable(hcx, hasher); match *self { - mir::Literal::Item { def_id, substs } => { - def_id.hash_stable(hcx, hasher); - substs.hash_stable(hcx, hasher); - } mir::Literal::Value { ref value } => { value.hash_stable(hcx, hasher); } diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index d9ca5ddf46b055b4df50df7fcea331b98ed23f82..38dfe010c153cc14af61ca38ad7cbc07c2e6f829 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -1479,10 +1479,6 @@ pub struct Constant<'tcx> { #[derive(Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] pub enum Literal<'tcx> { - Item { - def_id: DefId, - substs: &'tcx Substs<'tcx>, - }, Value { value: &'tcx ty::Const<'tcx>, }, @@ -1502,9 +1498,6 @@ impl<'tcx> Debug for Literal<'tcx> { fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { use self::Literal::*; match *self { - Item { def_id, substs } => { - ppaux::parameterized(fmt, substs, def_id, &[]) - } Value { value } => { write!(fmt, "const ")?; fmt_const_val(fmt, &value.val) @@ -2002,17 +1995,16 @@ fn super_visit_with>(&self, visitor: &mut V) -> bool { impl<'tcx> TypeFoldable<'tcx> for Literal<'tcx> { fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { match *self { - Literal::Item { def_id, substs } => Literal::Item { - def_id, - substs: substs.fold_with(folder) + Literal::Value { value } => Literal::Value { + value: value.fold_with(folder) }, - _ => self.clone() + Literal::Promoted { index } => Literal::Promoted { index } } } fn super_visit_with>(&self, visitor: &mut V) -> bool { match *self { - Literal::Item { substs, .. } => substs.visit_with(visitor), - _ => false + Literal::Value { value } => value.visit_with(visitor), + Literal::Promoted { .. } => false } } } diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 22d93c1a276508b79a0cb954e61aac944e47b398..37c97ad3dad9058aa763e8f15c84ef0bb485705f 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -724,11 +724,6 @@ fn super_literal(&mut self, literal: & $($mutability)* Literal<'tcx>, location: Location) { match *literal { - Literal::Item { ref $($mutability)* def_id, - ref $($mutability)* substs } => { - self.visit_def_id(def_id, location); - self.visit_substs(substs, location); - } Literal::Value { ref $($mutability)* value } => { self.visit_const(value, location); } diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index 23e6fbd2b7e23a0fc38eea52b0e2632e43b83022..45449103c8083fde0b139e22f1b5e2450dbf3c97 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -643,9 +643,11 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, Def::Const(def_id) | Def::AssociatedConst(def_id) => ExprKind::Literal { - literal: Literal::Item { - def_id, - substs, + literal: Literal::Value { + value: cx.tcx.mk_const(ty::Const { + val: ConstVal::Unevaluated(def_id, substs), + ty: cx.tables().node_id_to_type(expr.hir_id) + }), }, }, diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 2267e611531f3f0f342fa37952760861b8dc8ab2..5550fb2788eaf088dfe1e564489d2630ee7db6c4 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -20,6 +20,7 @@ use rustc::hir; use rustc::hir::map as hir_map; use rustc::hir::def_id::DefId; +use rustc::middle::const_val::ConstVal; use rustc::traits::{self, Reveal}; use rustc::ty::{self, TyCtxt, Ty, TypeFoldable}; use rustc::ty::cast::CastTy; @@ -622,10 +623,12 @@ fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) { } } Operand::Constant(ref constant) => { - if let Literal::Item { def_id, substs: _ } = constant.literal { + if let Literal::Value { + value: &ty::Const { val: ConstVal::Unevaluated(def_id, _), ty } + } = constant.literal { // Don't peek inside trait associated constants. if self.tcx.trait_of_item(def_id).is_some() { - self.add_type(constant.ty); + self.add_type(ty); } else { let (bits, _) = self.tcx.at(constant.span).mir_const_qualif(def_id); @@ -635,7 +638,7 @@ fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) { // Just in case the type is more specific than // the definition, e.g. impl associated const // with type parameters, take it into account. - self.qualif.restrict(constant.ty, self.tcx, self.param_env); + self.qualif.restrict(ty, self.tcx, self.param_env); } // Let `const fn` transitively have destructors, diff --git a/src/librustc_passes/mir_stats.rs b/src/librustc_passes/mir_stats.rs index 91203a91be51d3e3637e5a4d0542a26948e8d690..1fa49614580a3a19b091faf077d6361062a0e75a 100644 --- a/src/librustc_passes/mir_stats.rs +++ b/src/librustc_passes/mir_stats.rs @@ -235,7 +235,6 @@ fn visit_literal(&mut self, location: Location) { self.record("Literal", literal); self.record(match *literal { - Literal::Item { .. } => "Literal::Item", Literal::Value { .. } => "Literal::Value", Literal::Promoted { .. } => "Literal::Promoted", }, literal); diff --git a/src/librustc_trans/collector.rs b/src/librustc_trans/collector.rs index b56fa34e348e5f7f8b3abd140e1c7a6c444c2987..3bf709ff7ba9d227fa679e3d2edc7fa022c5754e 100644 --- a/src/librustc_trans/collector.rs +++ b/src/librustc_trans/collector.rs @@ -193,6 +193,7 @@ use rustc::hir::map as hir_map; use rustc::hir::def_id::DefId; +use rustc::middle::const_val::ConstVal; use rustc::middle::lang_items::{ExchangeMallocFnLangItem}; use rustc::traits; use rustc::ty::subst::Substs; @@ -564,24 +565,17 @@ fn visit_rvalue(&mut self, rvalue: &mir::Rvalue<'tcx>, location: Location) { self.super_rvalue(rvalue, location); } - fn visit_constant(&mut self, constant: &mir::Constant<'tcx>, location: Location) { - debug!("visiting constant {:?} @ {:?}", *constant, location); + fn visit_const(&mut self, constant: &&'tcx ty::Const<'tcx>, location: Location) { + debug!("visiting const {:?} @ {:?}", *constant, location); - if let ty::TyFnDef(..) = constant.ty.sty { - // function definitions are zero-sized, and only generate - // IR when they are called/reified. - self.super_constant(constant, location); - return - } - - if let mir::Literal::Item { def_id, substs } = constant.literal { + if let ConstVal::Unevaluated(def_id, substs) = constant.val { let substs = self.scx.tcx().trans_apply_param_substs(self.param_substs, &substs); let instance = monomorphize::resolve(self.scx, def_id, substs); collect_neighbours(self.scx, instance, true, self.output); } - self.super_constant(constant, location); + self.super_const(constant); } fn visit_terminator_kind(&mut self, diff --git a/src/librustc_trans/mir/constant.rs b/src/librustc_trans/mir/constant.rs index 6e975941e8e89347e516d1f27928cebd54ee826f..4c3326a466d3a4f919ecebd1789fada6c78b1619 100644 --- a/src/librustc_trans/mir/constant.rs +++ b/src/librustc_trans/mir/constant.rs @@ -510,16 +510,17 @@ fn const_operand(&self, operand: &mir::Operand<'tcx>, span: Span) mir::Operand::Constant(ref constant) => { let ty = self.monomorphize(&constant.ty); match constant.literal.clone() { - mir::Literal::Item { def_id, substs } => { - let substs = self.monomorphize(&substs); - MirConstContext::trans_def(self.ccx, def_id, substs, IndexVec::new()) - } mir::Literal::Promoted { index } => { let mir = &self.mir.promoted[index]; MirConstContext::new(self.ccx, mir, self.substs, IndexVec::new()).trans() } mir::Literal::Value { value } => { - Ok(Const::from_constval(self.ccx, &value.val, ty)) + if let ConstVal::Unevaluated(def_id, substs) = value.val { + let substs = self.monomorphize(&substs); + MirConstContext::trans_def(self.ccx, def_id, substs, IndexVec::new()) + } else { + Ok(Const::from_constval(self.ccx, &value.val, ty)) + } } } } @@ -960,16 +961,17 @@ pub fn trans_constant(&mut self, debug!("trans_constant({:?})", constant); let ty = self.monomorphize(&constant.ty); let result = match constant.literal.clone() { - mir::Literal::Item { def_id, substs } => { - let substs = self.monomorphize(&substs); - MirConstContext::trans_def(bcx.ccx, def_id, substs, IndexVec::new()) - } mir::Literal::Promoted { index } => { let mir = &self.mir.promoted[index]; MirConstContext::new(bcx.ccx, mir, self.param_substs, IndexVec::new()).trans() } mir::Literal::Value { value } => { - Ok(Const::from_constval(bcx.ccx, &value.val, ty)) + if let ConstVal::Unevaluated(def_id, substs) = value.val { + let substs = self.monomorphize(&substs); + MirConstContext::trans_def(bcx.ccx, def_id, substs, IndexVec::new()) + } else { + Ok(Const::from_constval(bcx.ccx, &value.val, ty)) + } } };