1
Fork 0

Introduce and use TypedConstVal for Repeat

This commit is contained in:
Florian Hahn 2016-01-20 23:14:00 +01:00
parent c78609134c
commit d31027d3bf
6 changed files with 18 additions and 10 deletions

View file

@ -683,7 +683,7 @@ pub enum Rvalue<'tcx> {
Use(Operand<'tcx>), Use(Operand<'tcx>),
// [x; 32] // [x; 32]
Repeat(Operand<'tcx>, Constant<'tcx>), Repeat(Operand<'tcx>, TypedConstVal<'tcx>),
// &x or &mut x // &x or &mut x
Ref(Region, BorrowKind, Lvalue<'tcx>), Ref(Region, BorrowKind, Lvalue<'tcx>),
@ -891,6 +891,13 @@ pub struct Constant<'tcx> {
pub literal: Literal<'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)] #[derive(Clone, Copy, Debug, PartialEq, RustcEncodable, RustcDecodable)]
pub enum ItemKind { pub enum ItemKind {
Constant, Constant,

View file

@ -213,9 +213,8 @@ macro_rules! make_mir_visitor {
} }
Rvalue::Repeat(ref $($mutability)* value, Rvalue::Repeat(ref $($mutability)* value,
ref $($mutability)* len) => { _) => {
self.visit_operand(value); self.visit_operand(value);
self.visit_constant(len);
} }
Rvalue::Ref(r, bk, ref $($mutability)* path) => { Rvalue::Ref(r, bk, ref $($mutability)* path) => {

View file

@ -15,6 +15,7 @@ use hair::cx::block;
use hair::cx::to_ref::ToRef; use hair::cx::to_ref::ToRef;
use rustc::front::map; use rustc::front::map;
use rustc::middle::def::Def; use rustc::middle::def::Def;
use rustc::middle::const_eval;
use rustc::middle::region::CodeExtent; use rustc::middle::region::CodeExtent;
use rustc::middle::pat_util; use rustc::middle::pat_util;
use rustc::middle::ty::{self, VariantDef, Ty}; 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 { hir::ExprRepeat(ref v, ref c) => ExprKind::Repeat {
value: v.to_ref(), value: v.to_ref(),
count: Constant { count: TypedConstVal {
ty: cx.tcx.expr_ty(c), ty: cx.tcx.expr_ty(c),
span: c.span, span: c.span,
literal: cx.const_eval_literal(c) value: const_eval::eval_const_expr(cx.tcx, c)
} }
}, },
hir::ExprRet(ref v) => hir::ExprRet(ref v) =>

View file

@ -14,7 +14,8 @@
//! unit-tested and separated from the Rust source and compiler data //! unit-tested and separated from the Rust source and compiler data
//! structures. //! 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::const_eval::ConstVal;
use rustc::middle::def_id::DefId; use rustc::middle::def_id::DefId;
use rustc::middle::region::CodeExtent; use rustc::middle::region::CodeExtent;
@ -213,7 +214,7 @@ pub enum ExprKind<'tcx> {
}, },
Repeat { Repeat {
value: ExprRef<'tcx>, value: ExprRef<'tcx>,
count: Constant<'tcx>, count: TypedConstVal<'tcx>,
}, },
Vec { Vec {
fields: Vec<ExprRef<'tcx>>, fields: Vec<ExprRef<'tcx>>,
@ -338,6 +339,7 @@ pub struct FieldPattern<'tcx> {
pub field: Field, pub field: Field,
pub pattern: Pattern<'tcx>, pub pattern: Pattern<'tcx>,
} }
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// The Mirror trait // The Mirror trait

View file

@ -143,9 +143,8 @@ impl<'a, 'tcx> EraseRegions<'a, 'tcx> {
Rvalue::Use(ref mut operand) => { Rvalue::Use(ref mut operand) => {
self.erase_regions_operand(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_operand(operand);
self.erase_regions_constant(constant);
} }
Rvalue::Ref(ref mut region, _, ref mut lvalue) => { Rvalue::Ref(ref mut region, _, ref mut lvalue) => {
*region = ty::ReStatic; *region = ty::ReStatic;

View file

@ -89,7 +89,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
mir::Rvalue::Repeat(ref elem, ref count) => { mir::Rvalue::Repeat(ref elem, ref count) => {
let elem = self.trans_operand(bcx, elem); 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); let base = expr::get_dataptr(bcx, dest.llval);
tvec::iter_vec_raw(bcx, base, elem.ty, size, |bcx, llslot, _| { tvec::iter_vec_raw(bcx, base, elem.ty, size, |bcx, llslot, _| {
self.store_operand(bcx, llslot, elem); self.store_operand(bcx, llslot, elem);