Skip to content

Commit 8111eee

Browse files
committed
Rustup to rustc 1.30.0-nightly (02cb8f2 2018-08-29)
1 parent 6f58f94 commit 8111eee

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/base.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ fn trans_fn<'a, 'tcx: 'a>(
117117
// TODO: cranelift doesn't yet support some of the things needed
118118
if should_codegen(tcx.sess) {
119119
caches.context.func = func;
120-
module.define_function(func_id, &mut caches.context).unwrap();
120+
module
121+
.define_function(func_id, &mut caches.context)
122+
.unwrap();
121123
caches.context.clear();
122124
}
123125
}

src/constant.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use cranelift_module::*;
22
use crate::prelude::*;
3-
use rustc::mir::interpret::{read_target_uint, AllocId, AllocType, ConstValue, GlobalId};
3+
use rustc::mir::interpret::{
4+
read_target_uint, AllocId, AllocType, Allocation, ConstValue, EvalResult, GlobalId,
5+
};
46
use rustc::ty::Const;
5-
use rustc_mir::interpret::{CompileTimeEvaluator, Memory};
7+
use rustc_mir::interpret::{CompileTimeEvaluator, EvalContext, Memory, MemoryKind};
68
use syntax::ast::Mutability as AstMutability;
79

810
#[derive(Default)]
@@ -120,7 +122,22 @@ fn trans_const_place<'a, 'tcx: 'a>(
120122
fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
121123
const_: &'tcx Const<'tcx>,
122124
) -> CPlace<'tcx> {
123-
let alloc = fx.tcx.const_to_allocation(const_);
125+
// Adapted from https://github.com/rust-lang/rust/pull/53671/files#diff-e0b58bb6712edaa8595ad7237542c958L551
126+
let result = || -> EvalResult<'tcx, &'tcx Allocation> {
127+
let mut ecx = EvalContext::new(
128+
fx.tcx.at(DUMMY_SP),
129+
ty::ParamEnv::reveal_all(),
130+
CompileTimeEvaluator,
131+
(),
132+
);
133+
let op = ecx.const_to_op(const_)?;
134+
let ptr = ecx.allocate(op.layout, MemoryKind::Stack)?;
135+
ecx.copy_op(op, ptr.into())?;
136+
let alloc = ecx.memory.get(ptr.to_ptr()?.alloc_id)?;
137+
Ok(fx.tcx.intern_const_alloc(alloc.clone()))
138+
};
139+
let alloc = result().expect("unable to convert ConstValue to Allocation");
140+
124141
//println!("const value: {:?} allocation: {:?}", value, alloc);
125142
let alloc_id = fx.tcx.alloc_map.lock().allocate(alloc);
126143
fx.constants.todo.insert(TodoItem::Alloc(alloc_id));
@@ -190,7 +207,7 @@ fn define_all_allocs<'a, 'tcx: 'a, B: Backend + 'a>(
190207
let const_ = tcx.const_eval(ParamEnv::reveal_all().and(cid)).unwrap();
191208

192209
let alloc = match const_.val {
193-
ConstValue::ByRef(alloc, n) if n.bytes() == 0 => alloc,
210+
ConstValue::ByRef(_alloc_id, alloc, n) if n.bytes() == 0 => alloc,
194211
_ => bug!("static const eval returned {:#?}", const_),
195212
};
196213

@@ -208,7 +225,7 @@ fn define_all_allocs<'a, 'tcx: 'a, B: Backend + 'a>(
208225

209226
data_ctx.define(
210227
alloc.bytes.to_vec().into_boxed_slice(),
211-
match alloc.runtime_mutability {
228+
match alloc.mutability {
212229
AstMutability::Mutable => Writability::Writable,
213230
AstMutability::Immutable => Writability::Readonly,
214231
},

0 commit comments

Comments
 (0)