From d31027d3bf9003f376d7f73df90cb4592d81084a Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Wed, 20 Jan 2016 23:14:00 +0100 Subject: [PATCH] Introduce and use TypedConstVal for Repeat --- src/librustc/mir/repr.rs | 9 ++++++++- src/librustc/mir/visit.rs | 3 +-- src/librustc_mir/hair/cx/expr.rs | 5 +++-- src/librustc_mir/hair/mod.rs | 6 ++++-- src/librustc_mir/transform/erase_regions.rs | 3 +-- src/librustc_trans/trans/mir/rvalue.rs | 2 +- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/librustc/mir/repr.rs b/src/librustc/mir/repr.rs index 8496f606b7b..ed6b174e463 100644 --- a/src/librustc/mir/repr.rs +++ b/src/librustc/mir/repr.rs @@ -683,7 +683,7 @@ pub enum Rvalue<'tcx> { Use(Operand<'tcx>), // [x; 32] - Repeat(Operand<'tcx>, Constant<'tcx>), + Repeat(Operand<'tcx>, TypedConstVal<'tcx>), // &x or &mut x Ref(Region, BorrowKind, Lvalue<'tcx>), @@ -891,6 +891,13 @@ pub struct Constant<'tcx> { pub literal: Literal<'tcx>, } +#[derive(Clone, Debug, RustcEncodable, RustcDecodable)] +pub struct TypedConstVal<'tcx> { + pub ty: Ty<'tcx>, + pub span: Span, + pub value: ConstVal +} + #[derive(Clone, Copy, Debug, PartialEq, RustcEncodable, RustcDecodable)] pub enum ItemKind { Constant, diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 7c8ea22de8e..a38ef078c6f 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -213,9 +213,8 @@ macro_rules! make_mir_visitor { } Rvalue::Repeat(ref $($mutability)* value, - ref $($mutability)* len) => { + _) => { self.visit_operand(value); - self.visit_constant(len); } Rvalue::Ref(r, bk, ref $($mutability)* path) => { diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index 121b9c70ec3..d8a1930fd5c 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -15,6 +15,7 @@ use hair::cx::block; use hair::cx::to_ref::ToRef; use rustc::front::map; use rustc::middle::def::Def; +use rustc::middle::const_eval; use rustc::middle::region::CodeExtent; use rustc::middle::pat_util; use rustc::middle::ty::{self, VariantDef, Ty}; @@ -325,10 +326,10 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr { hir::ExprRepeat(ref v, ref c) => ExprKind::Repeat { value: v.to_ref(), - count: Constant { + count: TypedConstVal { ty: cx.tcx.expr_ty(c), span: c.span, - literal: cx.const_eval_literal(c) + value: const_eval::eval_const_expr(cx.tcx, c) } }, hir::ExprRet(ref v) => diff --git a/src/librustc_mir/hair/mod.rs b/src/librustc_mir/hair/mod.rs index 0c673b4a644..d87b25a094e 100644 --- a/src/librustc_mir/hair/mod.rs +++ b/src/librustc_mir/hair/mod.rs @@ -14,7 +14,8 @@ //! unit-tested and separated from the Rust source and compiler data //! structures. -use rustc::mir::repr::{Constant, BinOp, BorrowKind, Field, Literal, Mutability, UnOp, ItemKind}; +use rustc::mir::repr::{BinOp, BorrowKind, Field, Literal, Mutability, UnOp, ItemKind, + TypedConstVal}; use rustc::middle::const_eval::ConstVal; use rustc::middle::def_id::DefId; use rustc::middle::region::CodeExtent; @@ -213,7 +214,7 @@ pub enum ExprKind<'tcx> { }, Repeat { value: ExprRef<'tcx>, - count: Constant<'tcx>, + count: TypedConstVal<'tcx>, }, Vec { fields: Vec>, @@ -338,6 +339,7 @@ pub struct FieldPattern<'tcx> { pub field: Field, pub pattern: Pattern<'tcx>, } + /////////////////////////////////////////////////////////////////////////// // The Mirror trait diff --git a/src/librustc_mir/transform/erase_regions.rs b/src/librustc_mir/transform/erase_regions.rs index 9679654d958..a964f9ccf0c 100644 --- a/src/librustc_mir/transform/erase_regions.rs +++ b/src/librustc_mir/transform/erase_regions.rs @@ -143,9 +143,8 @@ impl<'a, 'tcx> EraseRegions<'a, 'tcx> { Rvalue::Use(ref mut operand) => { self.erase_regions_operand(operand) } - Rvalue::Repeat(ref mut operand, ref mut constant) => { + Rvalue::Repeat(ref mut operand, _) => { self.erase_regions_operand(operand); - self.erase_regions_constant(constant); } Rvalue::Ref(ref mut region, _, ref mut lvalue) => { *region = ty::ReStatic; diff --git a/src/librustc_trans/trans/mir/rvalue.rs b/src/librustc_trans/trans/mir/rvalue.rs index f53653d7cad..fa925241c72 100644 --- a/src/librustc_trans/trans/mir/rvalue.rs +++ b/src/librustc_trans/trans/mir/rvalue.rs @@ -89,7 +89,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { mir::Rvalue::Repeat(ref elem, ref count) => { let elem = self.trans_operand(bcx, elem); - let size = self.trans_constant(bcx, count).immediate(); + let size = self.trans_constval(bcx, &count.value, count.ty).immediate(); let base = expr::get_dataptr(bcx, dest.llval); tvec::iter_vec_raw(bcx, base, elem.ty, size, |bcx, llslot, _| { self.store_operand(bcx, llslot, elem);