Reduce the usage of global paths

This commit is contained in:
Oliver Schneider 2017-07-20 16:40:57 +02:00
parent f02d9e63fd
commit 9b526d1c85
3 changed files with 16 additions and 14 deletions

View file

@ -18,6 +18,7 @@ use syntax::abi::Abi;
use error::{EvalError, EvalResult};
use lvalue::{Global, GlobalId, Lvalue, LvalueExtra};
use memory::{Memory, MemoryPointer, TlsKey, HasMemory};
use memory::Kind as MemoryKind;
use operator;
use value::{PrimVal, PrimValKind, Value, Pointer};
@ -153,7 +154,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
) -> EvalResult<'tcx, MemoryPointer> {
let size = self.type_size_with_substs(ty, substs)?.expect("cannot alloc memory for unsized type");
let align = self.type_align_with_substs(ty, substs)?;
self.memory.allocate(size, align, ::memory::Kind::Stack)
self.memory.allocate(size, align, MemoryKind::Stack)
}
pub fn memory(&self) -> &Memory<'a, 'tcx> {
@ -417,8 +418,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
// for a constant like `const FOO: &i32 = &1;` the local containing
// the `1` is referred to by the global. We transitively marked everything
// the global refers to as static itself, so we don't free it here
::memory::Kind::Static => {}
::memory::Kind::Stack => self.memory.deallocate(ptr, None, ::memory::Kind::Stack)?,
MemoryKind::Static => {}
MemoryKind::Stack => self.memory.deallocate(ptr, None, MemoryKind::Stack)?,
other => bug!("local contained non-stack memory: {:?}", other),
}
};
@ -696,7 +697,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
self.write_primval(dest, PrimVal::Bytes(align.into()), dest_ty)?;
} else {
let align = self.type_align(ty)?;
let ptr = self.memory.allocate(size, align, ::memory::Kind::Rust)?;
let ptr = self.memory.allocate(size, align, MemoryKind::Rust)?;
self.write_primval(dest, PrimVal::Ptr(ptr), dest_ty)?;
}
}
@ -1689,7 +1690,7 @@ pub fn eval_main<'a, 'tcx: 'a>(
}
// Return value
let ret_ptr = ecx.memory.allocate(ecx.tcx.data_layout.pointer_size.bytes(), ecx.tcx.data_layout.pointer_align.abi(), ::memory::Kind::Stack)?;
let ret_ptr = ecx.memory.allocate(ecx.tcx.data_layout.pointer_size.bytes(), ecx.tcx.data_layout.pointer_align.abi(), MemoryKind::Stack)?;
cleanup_ptr = Some(ret_ptr);
// Push our stack frame
@ -1731,7 +1732,7 @@ pub fn eval_main<'a, 'tcx: 'a>(
while ecx.step()? {}
if let Some(cleanup_ptr) = cleanup_ptr {
ecx.memory.deallocate(cleanup_ptr, None, ::memory::Kind::Stack)?;
ecx.memory.deallocate(cleanup_ptr, None, MemoryKind::Stack)?;
}
return Ok(());
}

View file

@ -7,11 +7,12 @@ use syntax::attr;
use syntax::abi::Abi;
use error::{EvalError, EvalResult};
use eval_context::{EvalContext, IntegerExt, StackPopCleanup, is_inhabited};
use eval_context::{EvalContext, IntegerExt, StackPopCleanup, is_inhabited, self};
use lvalue::Lvalue;
use memory::{MemoryPointer, TlsKey, Kind};
use value::{PrimVal, Value};
use rustc_data_structures::indexed_vec::Idx;
use const_eval;
use std::mem;
@ -86,7 +87,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
}
(instance, sig)
},
ty::TyFnDef(def_id, substs) => (::eval_context::resolve(self.tcx, def_id, substs), func_ty.fn_sig(self.tcx)),
ty::TyFnDef(def_id, substs) => (eval_context::resolve(self.tcx, def_id, substs), func_ty.fn_sig(self.tcx)),
_ => {
let msg = format!("can't handle callee of type {:?}", func_ty);
return Err(EvalError::Unimplemented(msg));
@ -104,9 +105,9 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
let lval = self.eval_lvalue(location)?;
let ty = self.lvalue_ty(location);
self.goto_block(target);
let ty = ::eval_context::apply_param_substs(self.tcx, self.substs(), &ty);
let ty = eval_context::apply_param_substs(self.tcx, self.substs(), &ty);
let instance = ::eval_context::resolve_drop_in_place(self.tcx, ty);
let instance = eval_context::resolve_drop_in_place(self.tcx, ty);
self.drop_lvalue(lval, instance, ty, terminator.source_info.span)?;
}
@ -869,7 +870,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
// compute global if not cached
let val = match self.globals.get(&cid).map(|glob| glob.value) {
Some(value) => self.value_to_primval(value, usize)?.to_u64()?,
None => ::const_eval::eval_body_as_primval(self.tcx, instance)?.0.to_u64()?,
None => const_eval::eval_body_as_primval(self.tcx, instance)?.0.to_u64()?,
};
if val == name {
result = Some(path_value);

View file

@ -1,6 +1,6 @@
use rustc::traits::{self, Reveal};
use eval_context::EvalContext;
use eval_context::{EvalContext, self};
use memory::{MemoryPointer, Kind};
use value::{Value, PrimVal};
@ -53,7 +53,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
let methods = ::rustc::traits::get_vtable_methods(self.tcx, trait_ref);
let vtable = self.memory.allocate(ptr_size * (3 + methods.count() as u64), ptr_size, Kind::UninitializedStatic)?;
let drop = ::eval_context::resolve_drop_in_place(self.tcx, ty);
let drop = eval_context::resolve_drop_in_place(self.tcx, ty);
let drop = self.memory.create_fn_alloc(drop);
self.memory.write_ptr(vtable, drop)?;
@ -62,7 +62,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
for (i, method) in ::rustc::traits::get_vtable_methods(self.tcx, trait_ref).enumerate() {
if let Some((def_id, substs)) = method {
let instance = ::eval_context::resolve(self.tcx, def_id, substs);
let instance = eval_context::resolve(self.tcx, def_id, substs);
let fn_ptr = self.memory.create_fn_alloc(instance);
self.memory.write_ptr(vtable.offset(ptr_size * (3 + i as u64), self.memory.layout)?, fn_ptr)?;
}