From 8111eee37a6e60abc49e95646bb654efd3af0fb6 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 30 Aug 2018 20:14:56 +0200 Subject: [PATCH] Rustup to rustc 1.30.0-nightly (02cb8f2a4 2018-08-29) --- src/base.rs | 4 +++- src/constant.rs | 27 ++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/base.rs b/src/base.rs index e6302684c54..8627cf66a83 100644 --- a/src/base.rs +++ b/src/base.rs @@ -117,7 +117,9 @@ fn trans_fn<'a, 'tcx: 'a>( // TODO: cranelift doesn't yet support some of the things needed if should_codegen(tcx.sess) { caches.context.func = func; - module.define_function(func_id, &mut caches.context).unwrap(); + module + .define_function(func_id, &mut caches.context) + .unwrap(); caches.context.clear(); } } diff --git a/src/constant.rs b/src/constant.rs index f7bfdaf2d55..b5ce5f198f4 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -1,8 +1,10 @@ use cranelift_module::*; use crate::prelude::*; -use rustc::mir::interpret::{read_target_uint, AllocId, AllocType, ConstValue, GlobalId}; +use rustc::mir::interpret::{ + read_target_uint, AllocId, AllocType, Allocation, ConstValue, EvalResult, GlobalId, +}; use rustc::ty::Const; -use rustc_mir::interpret::{CompileTimeEvaluator, Memory}; +use rustc_mir::interpret::{CompileTimeEvaluator, EvalContext, Memory, MemoryKind}; use syntax::ast::Mutability as AstMutability; #[derive(Default)] @@ -120,7 +122,22 @@ fn trans_const_place<'a, 'tcx: 'a>( fx: &mut FunctionCx<'a, 'tcx, impl Backend>, const_: &'tcx Const<'tcx>, ) -> CPlace<'tcx> { - let alloc = fx.tcx.const_to_allocation(const_); + // Adapted from https://github.com/rust-lang/rust/pull/53671/files#diff-e0b58bb6712edaa8595ad7237542c958L551 + let result = || -> EvalResult<'tcx, &'tcx Allocation> { + let mut ecx = EvalContext::new( + fx.tcx.at(DUMMY_SP), + ty::ParamEnv::reveal_all(), + CompileTimeEvaluator, + (), + ); + let op = ecx.const_to_op(const_)?; + let ptr = ecx.allocate(op.layout, MemoryKind::Stack)?; + ecx.copy_op(op, ptr.into())?; + let alloc = ecx.memory.get(ptr.to_ptr()?.alloc_id)?; + Ok(fx.tcx.intern_const_alloc(alloc.clone())) + }; + let alloc = result().expect("unable to convert ConstValue to Allocation"); + //println!("const value: {:?} allocation: {:?}", value, alloc); let alloc_id = fx.tcx.alloc_map.lock().allocate(alloc); fx.constants.todo.insert(TodoItem::Alloc(alloc_id)); @@ -190,7 +207,7 @@ fn define_all_allocs<'a, 'tcx: 'a, B: Backend + 'a>( let const_ = tcx.const_eval(ParamEnv::reveal_all().and(cid)).unwrap(); let alloc = match const_.val { - ConstValue::ByRef(alloc, n) if n.bytes() == 0 => alloc, + ConstValue::ByRef(_alloc_id, alloc, n) if n.bytes() == 0 => alloc, _ => bug!("static const eval returned {:#?}", const_), }; @@ -208,7 +225,7 @@ fn define_all_allocs<'a, 'tcx: 'a, B: Backend + 'a>( data_ctx.define( alloc.bytes.to_vec().into_boxed_slice(), - match alloc.runtime_mutability { + match alloc.mutability { AstMutability::Mutable => Writability::Writable, AstMutability::Immutable => Writability::Readonly, },