Skip to content

Commit b47d969

Browse files
committed
Implement translation for ConstVal::{Array,Repeat}
1 parent 1a1f474 commit b47d969

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

src/librustc_trans/trans/consts.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,13 @@ pub fn const_lit(cx: &CrateContext, e: &hir::Expr, lit: &ast::Lit)
108108
}
109109
}
110110

111-
pub fn trans_constval<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
111+
pub fn trans_constval<'blk, 'tcx>(bcx: common::Block<'blk, 'tcx>,
112112
cv: &ConstVal,
113113
ty: Ty<'tcx>,
114114
param_substs: &'tcx Substs<'tcx>)
115115
-> ValueRef
116116
{
117+
let ccx = bcx.ccx();
117118
let llty = type_of::type_of(ccx, ty);
118119
match *cv {
119120
ConstVal::Float(v) => C_floating_f64(v, llty),
@@ -123,19 +124,17 @@ pub fn trans_constval<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
123124
ConstVal::Str(ref v) => C_str_slice(ccx, v.clone()),
124125
ConstVal::ByteStr(ref v) => addr_of(ccx, C_bytes(ccx, v), 1, "byte_str"),
125126
ConstVal::Struct(id) | ConstVal::Tuple(id) => {
126-
let expr = ccx.tcx().map.expect_expr(id);
127+
let expr = bcx.tcx().map.expect_expr(id);
127128
match const_expr(ccx, expr, param_substs, None, TrueConst::Yes) {
128129
Ok((val, _)) => val,
129130
Err(e) => panic!("const eval failure: {}", e.description()),
130131
}
131132
},
132-
ConstVal::Function(_) => {
133-
unimplemented!()
134-
},
135-
ConstVal::Array(..) => {
136-
unimplemented!()
133+
ConstVal::Array(id, _) | ConstVal::Repeat(id, _) => {
134+
let expr = ccx.tcx().map.expect_expr(id);
135+
expr::trans(bcx, expr).datum.val
137136
},
138-
ConstVal::Repeat(..) => {
137+
ConstVal::Function(_) => {
139138
unimplemented!()
140139
},
141140
}

src/librustc_trans/trans/mir/constant.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
2626
-> OperandRef<'tcx>
2727
{
2828
let ccx = bcx.ccx();
29-
let val = consts::trans_constval(ccx, cv, ty, bcx.fcx.param_substs);
29+
let val = consts::trans_constval(bcx, cv, ty, bcx.fcx.param_substs);
3030
let val = if common::type_is_immediate(ccx, ty) {
31-
Immediate(val)
31+
OperandValue::Immediate(val)
3232
} else {
33-
Ref(val)
33+
OperandValue::Ref(val)
3434
};
3535

3636
assert!(!ty.has_erasable_regions());

src/librustc_trans/trans/mir/did.rs

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
4949
let did = inline::maybe_instantiate_inline(bcx.ccx(), did);
5050
let expr = const_eval::lookup_const_by_id(bcx.tcx(), did, None)
5151
.expect("def was const, but lookup_const_by_id failed");
52+
// FIXME: this is falling back to translating from HIR. This is not easy to fix,
53+
// because we would have somehow adapt const_eval to work on MIR rather than HIR.
5254
let d = expr::trans(bcx, expr);
5355
OperandRef::from_rvalue_datum(d.datum.to_rvalue_datum(d.bcx, "").datum)
5456
}

0 commit comments

Comments
 (0)