Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/librustc/mir/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>),
Expand Down Expand Up @@ -891,6 +891,20 @@ pub struct Constant<'tcx> {
pub literal: Literal<'tcx>,
}

#[derive(Clone, RustcEncodable, RustcDecodable)]
pub struct TypedConstVal<'tcx> {
pub ty: Ty<'tcx>,
pub span: Span,
pub value: ConstVal
}

impl<'tcx> Debug for TypedConstVal<'tcx> {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
try!(write!(fmt, "const "));
fmt_const_val(fmt, &self.value)
}
}

#[derive(Clone, Copy, Debug, PartialEq, RustcEncodable, RustcDecodable)]
pub enum ItemKind {
Constant,
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
1 change: 0 additions & 1 deletion src/librustc_mir/build/expr/as_rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ impl<'a,'tcx> Builder<'a,'tcx> {
}
ExprKind::Repeat { value, count } => {
let value_operand = unpack!(block = this.as_operand(block, value));
let count = this.as_constant(count);
block.and(Rvalue::Repeat(value_operand, count))
}
ExprKind::Borrow { region, borrow_kind, arg } => {
Expand Down
10 changes: 4 additions & 6 deletions src/librustc_mir/hair/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -325,14 +326,11 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {

hir::ExprRepeat(ref v, ref c) => ExprKind::Repeat {
value: v.to_ref(),
count: Expr {
count: TypedConstVal {
ty: cx.tcx.expr_ty(c),
temp_lifetime: None,
span: c.span,
kind: ExprKind::Literal {
literal: cx.const_eval_literal(c)
}
}.to_ref()
value: const_eval::eval_const_expr(cx.tcx, c)
}
},
hir::ExprRet(ref v) =>
ExprKind::Return { value: v.to_ref() },
Expand Down
8 changes: 3 additions & 5 deletions src/librustc_mir/hair/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
//! unit-tested and separated from the Rust source and compiler data
//! structures.

use rustc::mir::repr::{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;
Expand Down Expand Up @@ -213,10 +214,7 @@ pub enum ExprKind<'tcx> {
},
Repeat {
value: ExprRef<'tcx>,
// FIXME(#29789): Add a separate hair::Constant<'tcx> so this could be more explicit about
// its contained data. Currently this should only contain expression of ExprKind::Literal
// kind.
count: ExprRef<'tcx>,
count: TypedConstVal<'tcx>,
},
Vec {
fields: Vec<ExprRef<'tcx>>,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/erase_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ 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, ref mut value) => {
self.erase_regions_operand(operand);
self.erase_regions_constant(constant);
value.ty = self.tcx.erase_regions(&value.ty);
}
Rvalue::Ref(ref mut region, _, ref mut lvalue) => {
*region = ty::ReStatic;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down