about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorSimonas Kazlauskas <git@kazlauskas.me>2015-12-05 20:35:00 +0200
committerSimonas Kazlauskas <git@kazlauskas.me>2015-12-15 12:25:09 +0200
commitb3720ea93342e02fe288eee6b5eb232c063eb0b9 (patch)
tree3b6008c9f65941f3a9b7bca31318e6051bf8368b /src
parenta5e7a61c490ce619010f585006880b84f3174cd4 (diff)
downloadrust-b3720ea93342e02fe288eee6b5eb232c063eb0b9.tar.gz
rust-b3720ea93342e02fe288eee6b5eb232c063eb0b9.zip
Implement translation for ConstVal::{Array,Repeat}
Diffstat (limited to 'src')
-rw-r--r--src/librustc_trans/trans/consts.rs15
-rw-r--r--src/librustc_trans/trans/mir/constant.rs6
-rw-r--r--src/librustc_trans/trans/mir/did.rs2
3 files changed, 12 insertions, 11 deletions
diff --git a/src/librustc_trans/trans/consts.rs b/src/librustc_trans/trans/consts.rs
index 5284911340b..406eaafb3f5 100644
--- a/src/librustc_trans/trans/consts.rs
+++ b/src/librustc_trans/trans/consts.rs
@@ -108,12 +108,13 @@ pub fn const_lit(cx: &CrateContext, e: &hir::Expr, lit: &ast::Lit)
     }
 }
 
-pub fn trans_constval<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+pub fn trans_constval<'blk, 'tcx>(bcx: common::Block<'blk, 'tcx>,
                                 cv: &ConstVal,
                                 ty: Ty<'tcx>,
                                 param_substs: &'tcx Substs<'tcx>)
                                 -> ValueRef
 {
+    let ccx = bcx.ccx();
     let llty = type_of::type_of(ccx, ty);
     match *cv {
         ConstVal::Float(v) => C_floating_f64(v, llty),
@@ -123,19 +124,17 @@ pub fn trans_constval<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
         ConstVal::Str(ref v) => C_str_slice(ccx, v.clone()),
         ConstVal::ByteStr(ref v) => addr_of(ccx, C_bytes(ccx, v), 1, "byte_str"),
         ConstVal::Struct(id) | ConstVal::Tuple(id) => {
-            let expr = ccx.tcx().map.expect_expr(id);
+            let expr = bcx.tcx().map.expect_expr(id);
             match const_expr(ccx, expr, param_substs, None, TrueConst::Yes) {
                 Ok((val, _)) => val,
                 Err(e) => panic!("const eval failure: {}", e.description()),
             }
         },
-        ConstVal::Function(_) => {
-            unimplemented!()
-        },
-        ConstVal::Array(..) => {
-            unimplemented!()
+        ConstVal::Array(id, _) | ConstVal::Repeat(id, _) => {
+            let expr = ccx.tcx().map.expect_expr(id);
+            expr::trans(bcx, expr).datum.val
         },
-        ConstVal::Repeat(..) => {
+        ConstVal::Function(_) => {
             unimplemented!()
         },
     }
diff --git a/src/librustc_trans/trans/mir/constant.rs b/src/librustc_trans/trans/mir/constant.rs
index cbcc1c3c47d..38fab1dbf07 100644
--- a/src/librustc_trans/trans/mir/constant.rs
+++ b/src/librustc_trans/trans/mir/constant.rs
@@ -26,11 +26,11 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
                           -> OperandRef<'tcx>
     {
         let ccx = bcx.ccx();
-        let val = consts::trans_constval(ccx, cv, ty, bcx.fcx.param_substs);
+        let val = consts::trans_constval(bcx, cv, ty, bcx.fcx.param_substs);
         let val = if common::type_is_immediate(ccx, ty) {
-            Immediate(val)
+            OperandValue::Immediate(val)
         } else {
-            Ref(val)
+            OperandValue::Ref(val)
         };
 
         assert!(!ty.has_erasable_regions());
diff --git a/src/librustc_trans/trans/mir/did.rs b/src/librustc_trans/trans/mir/did.rs
index 28a7ca3f72f..368708d470b 100644
--- a/src/librustc_trans/trans/mir/did.rs
+++ b/src/librustc_trans/trans/mir/did.rs
@@ -50,6 +50,8 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
                 let did = inline::maybe_instantiate_inline(bcx.ccx(), did);
                 let expr = const_eval::lookup_const_by_id(bcx.tcx(), did, None)
                             .expect("def was const, but lookup_const_by_id failed");
+                // FIXME: this is falling back to translating from HIR. This is not easy to fix,
+                // because we would have somehow adapt const_eval to work on MIR rather than HIR.
                 let d = expr::trans(bcx, expr);
                 OperandRef::from_rvalue_datum(d.datum.to_rvalue_datum(d.bcx, "").datum)
             }