Skip to content

Commit d31027d

Browse files
committed
Introduce and use TypedConstVal for Repeat
1 parent c786091 commit d31027d

File tree

6 files changed

+18
-10
lines changed

6 files changed

+18
-10
lines changed

src/librustc/mir/repr.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ pub enum Rvalue<'tcx> {
683683
Use(Operand<'tcx>),
684684

685685
// [x; 32]
686-
Repeat(Operand<'tcx>, Constant<'tcx>),
686+
Repeat(Operand<'tcx>, TypedConstVal<'tcx>),
687687

688688
// &x or &mut x
689689
Ref(Region, BorrowKind, Lvalue<'tcx>),
@@ -891,6 +891,13 @@ pub struct Constant<'tcx> {
891891
pub literal: Literal<'tcx>,
892892
}
893893

894+
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
895+
pub struct TypedConstVal<'tcx> {
896+
pub ty: Ty<'tcx>,
897+
pub span: Span,
898+
pub value: ConstVal
899+
}
900+
894901
#[derive(Clone, Copy, Debug, PartialEq, RustcEncodable, RustcDecodable)]
895902
pub enum ItemKind {
896903
Constant,

src/librustc/mir/visit.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,8 @@ macro_rules! make_mir_visitor {
213213
}
214214

215215
Rvalue::Repeat(ref $($mutability)* value,
216-
ref $($mutability)* len) => {
216+
_) => {
217217
self.visit_operand(value);
218-
self.visit_constant(len);
219218
}
220219

221220
Rvalue::Ref(r, bk, ref $($mutability)* path) => {

src/librustc_mir/hair/cx/expr.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use hair::cx::block;
1515
use hair::cx::to_ref::ToRef;
1616
use rustc::front::map;
1717
use rustc::middle::def::Def;
18+
use rustc::middle::const_eval;
1819
use rustc::middle::region::CodeExtent;
1920
use rustc::middle::pat_util;
2021
use rustc::middle::ty::{self, VariantDef, Ty};
@@ -325,10 +326,10 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
325326

326327
hir::ExprRepeat(ref v, ref c) => ExprKind::Repeat {
327328
value: v.to_ref(),
328-
count: Constant {
329+
count: TypedConstVal {
329330
ty: cx.tcx.expr_ty(c),
330331
span: c.span,
331-
literal: cx.const_eval_literal(c)
332+
value: const_eval::eval_const_expr(cx.tcx, c)
332333
}
333334
},
334335
hir::ExprRet(ref v) =>

src/librustc_mir/hair/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
//! unit-tested and separated from the Rust source and compiler data
1515
//! structures.
1616
17-
use rustc::mir::repr::{Constant, BinOp, BorrowKind, Field, Literal, Mutability, UnOp, ItemKind};
17+
use rustc::mir::repr::{BinOp, BorrowKind, Field, Literal, Mutability, UnOp, ItemKind,
18+
TypedConstVal};
1819
use rustc::middle::const_eval::ConstVal;
1920
use rustc::middle::def_id::DefId;
2021
use rustc::middle::region::CodeExtent;
@@ -213,7 +214,7 @@ pub enum ExprKind<'tcx> {
213214
},
214215
Repeat {
215216
value: ExprRef<'tcx>,
216-
count: Constant<'tcx>,
217+
count: TypedConstVal<'tcx>,
217218
},
218219
Vec {
219220
fields: Vec<ExprRef<'tcx>>,
@@ -338,6 +339,7 @@ pub struct FieldPattern<'tcx> {
338339
pub field: Field,
339340
pub pattern: Pattern<'tcx>,
340341
}
342+
341343
///////////////////////////////////////////////////////////////////////////
342344
// The Mirror trait
343345

src/librustc_mir/transform/erase_regions.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,8 @@ impl<'a, 'tcx> EraseRegions<'a, 'tcx> {
143143
Rvalue::Use(ref mut operand) => {
144144
self.erase_regions_operand(operand)
145145
}
146-
Rvalue::Repeat(ref mut operand, ref mut constant) => {
146+
Rvalue::Repeat(ref mut operand, _) => {
147147
self.erase_regions_operand(operand);
148-
self.erase_regions_constant(constant);
149148
}
150149
Rvalue::Ref(ref mut region, _, ref mut lvalue) => {
151150
*region = ty::ReStatic;

src/librustc_trans/trans/mir/rvalue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
8989

9090
mir::Rvalue::Repeat(ref elem, ref count) => {
9191
let elem = self.trans_operand(bcx, elem);
92-
let size = self.trans_constant(bcx, count).immediate();
92+
let size = self.trans_constval(bcx, &count.value, count.ty).immediate();
9393
let base = expr::get_dataptr(bcx, dest.llval);
9494
tvec::iter_vec_raw(bcx, base, elem.ty, size, |bcx, llslot, _| {
9595
self.store_operand(bcx, llslot, elem);

0 commit comments

Comments
 (0)