1
Fork 0

use Constant for repetition count in mir::Repeat

This commit is contained in:
Simonas Kazlauskas 2015-11-10 23:52:23 +02:00
parent cba6561de2
commit db89a75a80
5 changed files with 26 additions and 6 deletions

View file

@ -44,8 +44,8 @@ impl<'a,'tcx> Builder<'a,'tcx> {
} }
ExprKind::Repeat { value, count } => { ExprKind::Repeat { value, count } => {
let value_operand = unpack!(block = this.as_operand(block, value)); let value_operand = unpack!(block = this.as_operand(block, value));
let count_operand = unpack!(block = this.as_operand(block, count)); let count = this.as_constant(count);
block.and(Rvalue::Repeat(value_operand, count_operand)) block.and(Rvalue::Repeat(value_operand, count))
} }
ExprKind::Borrow { region, borrow_kind, arg } => { ExprKind::Borrow { region, borrow_kind, arg } => {
let arg_lvalue = unpack!(block = this.as_lvalue(block, arg)); let arg_lvalue = unpack!(block = this.as_lvalue(block, arg));

View file

@ -546,7 +546,7 @@ pub enum Rvalue<'tcx> {
Use(Operand<'tcx>), Use(Operand<'tcx>),
// [x; 32] // [x; 32]
Repeat(Operand<'tcx>, Operand<'tcx>), Repeat(Operand<'tcx>, Constant<'tcx>),
// &x or &mut x // &x or &mut x
Ref(Region, BorrowKind, Lvalue<'tcx>), Ref(Region, BorrowKind, Lvalue<'tcx>),

View file

@ -134,7 +134,7 @@ pub trait Visitor<'tcx> {
Rvalue::Repeat(ref value, ref len) => { Rvalue::Repeat(ref value, ref len) => {
self.visit_operand(value); self.visit_operand(value);
self.visit_operand(len); self.visit_constant(len);
} }
Rvalue::Ref(r, bk, ref path) => { Rvalue::Ref(r, bk, ref path) => {

View file

@ -51,9 +51,9 @@ 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_operand(bcx, count); let size = self.trans_constant(bcx, count);
let base = expr::get_dataptr(bcx, lldest); let base = expr::get_dataptr(bcx, lldest);
tvec::iter_vec_raw(bcx, base, elem.ty, size.llval, |b, vref, _| { tvec::iter_vec_raw(bcx, base, elem.ty, size, |b, vref, _| {
build::Store(b, elem.llval, vref); build::Store(b, elem.llval, vref);
b b
}) })

View file

@ -0,0 +1,20 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(rustc_attrs)]
#[rustc_mir]
fn into_inner(x: u64) -> [u64; 1024] {
[x; 2*4*8*16]
}
fn main(){
let x: &[u64] = &[42; 1024];
assert_eq!(&into_inner(42)[..], x);
}