Don't borrow the interpret_interner for anything but a direct function call

This commit is contained in:
Oliver Schneider 2018-01-25 12:12:07 +01:00
parent 1d438f87e7
commit 37d8b9a86c
No known key found for this signature in database
GPG Key ID: A69F8D225B3AD7D9
5 changed files with 19 additions and 19 deletions

View File

@ -796,15 +796,14 @@ impl<'enc, 'a, 'tcx, E> SpecializedEncoder<interpret::AllocId> for CacheEncoder<
// cache the allocation shorthand now, because the allocation itself might recursively
// point to itself.
self.interpret_alloc_shorthands.insert(*alloc_id, start);
let interpret_interner = self.tcx.interpret_interner.borrow();
if let Some(alloc) = interpret_interner.get_alloc(*alloc_id) {
if let Some(alloc) = self.tcx.interpret_interner.borrow().get_alloc(*alloc_id) {
trace!("encoding {:?} with {:#?}", alloc_id, alloc);
usize::max_value().encode(self)?;
alloc.encode(self)?;
interpret_interner
self.tcx.interpret_interner.borrow()
.get_corresponding_static_def_id(*alloc_id)
.encode(self)?;
} else if let Some(fn_instance) = interpret_interner.get_fn(*alloc_id) {
} else if let Some(fn_instance) = self.tcx.interpret_interner.borrow().get_fn(*alloc_id) {
trace!("encoding {:?} with {:#?}", alloc_id, fn_instance);
(usize::max_value() - 1).encode(self)?;
fn_instance.encode(self)?;

View File

@ -205,15 +205,14 @@ impl<'a, 'tcx> SpecializedEncoder<interpret::AllocId> for EncodeContext<'a, 'tcx
// cache the allocation shorthand now, because the allocation itself might recursively
// point to itself.
self.interpret_alloc_shorthands.insert(*alloc_id, start);
let interpret_interner = self.tcx.interpret_interner.borrow();
if let Some(alloc) = interpret_interner.get_alloc(*alloc_id) {
if let Some(alloc) = self.tcx.interpret_interner.borrow().get_alloc(*alloc_id) {
trace!("encoding {:?} with {:#?}", alloc_id, alloc);
usize::max_value().encode(self)?;
alloc.encode(self)?;
interpret_interner
self.tcx.interpret_interner.borrow()
.get_corresponding_static_def_id(*alloc_id)
.encode(self)?;
} else if let Some(fn_instance) = interpret_interner.get_fn(*alloc_id) {
} else if let Some(fn_instance) = self.tcx.interpret_interner.borrow().get_fn(*alloc_id) {
trace!("encoding {:?} with {:#?}", alloc_id, fn_instance);
(usize::max_value() - 1).encode(self)?;
fn_instance.encode(self)?;
@ -1155,7 +1154,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
_ => None,
},
mir: match item.node {
hir::ItemStatic(..) if self.tcx.sess.opts.debugging_opts.always_encode_mir => {
hir::ItemStatic(..) => {
self.encode_optimized_mir(def_id)
}
hir::ItemConst(..) => self.encode_optimized_mir(def_id),

View File

@ -375,11 +375,10 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
None => match self.uninitialized_statics.get(&id) {
Some(a) => (a, " (static in the process of initialization)".to_owned()),
None => {
let int = self.tcx.interpret_interner.borrow();
// static alloc?
match int.get_alloc(id) {
match self.tcx.interpret_interner.borrow().get_alloc(id) {
Some(a) => (a, "(immutable)".to_owned()),
None => if let Some(func) = int.get_fn(id) {
None => if let Some(func) = self.tcx.interpret_interner.borrow().get_fn(id) {
trace!("{} {}", msg, func);
continue;
} else {

View File

@ -1117,13 +1117,12 @@ fn collect_miri<'a, 'tcx>(
alloc_id: AllocId,
output: &mut Vec<MonoItem<'tcx>>,
) {
let interpret_interner = tcx.interpret_interner.borrow();
if let Some(alloc) = interpret_interner.get_alloc(alloc_id) {
if let Some(alloc) = tcx.interpret_interner.borrow().get_alloc(alloc_id) {
trace!("collecting {:?} with {:#?}", alloc_id, alloc);
for &inner in alloc.relocations.values() {
collect_miri(tcx, inner, output);
}
} else if let Some(fn_instance) = interpret_interner.get_fn(alloc_id) {
} else if let Some(fn_instance) = tcx.interpret_interner.borrow().get_fn(alloc_id) {
if should_monomorphize_locally(tcx, &fn_instance) {
trace!("collecting {:?} with {:#?}", alloc_id, fn_instance);
output.push(create_fn_mono_item(fn_instance));

View File

@ -151,15 +151,19 @@ pub fn primval_to_llvm(cx: &CodegenCx,
}
},
PrimVal::Ptr(ptr) => {
let interpret_interner = cx.tcx.interpret_interner.borrow();
if let Some(fn_instance) = interpret_interner.get_fn(ptr.alloc_id) {
if let Some(fn_instance) = cx.tcx.interpret_interner.borrow().get_fn(ptr.alloc_id) {
callee::get_fn(cx, fn_instance)
} else {
let static_ = interpret_interner.get_corresponding_static_def_id(ptr.alloc_id);
let static_ = cx
.tcx
.interpret_interner
.borrow()
.get_corresponding_static_def_id(ptr.alloc_id);
let base_addr = if let Some(def_id) = static_ {
assert!(cx.tcx.is_static(def_id).is_some());
consts::get_static(cx, def_id)
} else if let Some(alloc) = interpret_interner.get_alloc(ptr.alloc_id) {
} else if let Some(alloc) = cx.tcx.interpret_interner.borrow()
.get_alloc(ptr.alloc_id) {
let init = global_initializer(cx, alloc);
if alloc.mutable {
consts::addr_of_mut(cx, init, alloc.align, "byte_str")