Skip to content

Commit 9710ff4

Browse files
authored
Merge pull request #264 from oli-obk/paths
Reduce the usage of global paths
2 parents f822ad5 + 9b526d1 commit 9710ff4

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

src/eval_context.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use syntax::abi::Abi;
1818
use error::{EvalError, EvalResult};
1919
use lvalue::{Global, GlobalId, Lvalue, LvalueExtra};
2020
use memory::{Memory, MemoryPointer, TlsKey, HasMemory};
21+
use memory::Kind as MemoryKind;
2122
use operator;
2223
use value::{PrimVal, PrimValKind, Value, Pointer};
2324

@@ -153,7 +154,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
153154
) -> EvalResult<'tcx, MemoryPointer> {
154155
let size = self.type_size_with_substs(ty, substs)?.expect("cannot alloc memory for unsized type");
155156
let align = self.type_align_with_substs(ty, substs)?;
156-
self.memory.allocate(size, align, ::memory::Kind::Stack)
157+
self.memory.allocate(size, align, MemoryKind::Stack)
157158
}
158159

159160
pub fn memory(&self) -> &Memory<'a, 'tcx> {
@@ -417,8 +418,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
417418
// for a constant like `const FOO: &i32 = &1;` the local containing
418419
// the `1` is referred to by the global. We transitively marked everything
419420
// the global refers to as static itself, so we don't free it here
420-
::memory::Kind::Static => {}
421-
::memory::Kind::Stack => self.memory.deallocate(ptr, None, ::memory::Kind::Stack)?,
421+
MemoryKind::Static => {}
422+
MemoryKind::Stack => self.memory.deallocate(ptr, None, MemoryKind::Stack)?,
422423
other => bug!("local contained non-stack memory: {:?}", other),
423424
}
424425
};
@@ -696,7 +697,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
696697
self.write_primval(dest, PrimVal::Bytes(align.into()), dest_ty)?;
697698
} else {
698699
let align = self.type_align(ty)?;
699-
let ptr = self.memory.allocate(size, align, ::memory::Kind::Rust)?;
700+
let ptr = self.memory.allocate(size, align, MemoryKind::Rust)?;
700701
self.write_primval(dest, PrimVal::Ptr(ptr), dest_ty)?;
701702
}
702703
}
@@ -1689,7 +1690,7 @@ pub fn eval_main<'a, 'tcx: 'a>(
16891690
}
16901691

16911692
// Return value
1692-
let ret_ptr = ecx.memory.allocate(ecx.tcx.data_layout.pointer_size.bytes(), ecx.tcx.data_layout.pointer_align.abi(), ::memory::Kind::Stack)?;
1693+
let ret_ptr = ecx.memory.allocate(ecx.tcx.data_layout.pointer_size.bytes(), ecx.tcx.data_layout.pointer_align.abi(), MemoryKind::Stack)?;
16931694
cleanup_ptr = Some(ret_ptr);
16941695

16951696
// Push our stack frame
@@ -1731,7 +1732,7 @@ pub fn eval_main<'a, 'tcx: 'a>(
17311732

17321733
while ecx.step()? {}
17331734
if let Some(cleanup_ptr) = cleanup_ptr {
1734-
ecx.memory.deallocate(cleanup_ptr, None, ::memory::Kind::Stack)?;
1735+
ecx.memory.deallocate(cleanup_ptr, None, MemoryKind::Stack)?;
17351736
}
17361737
return Ok(());
17371738
}

src/terminator/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ use syntax::attr;
77
use syntax::abi::Abi;
88

99
use error::{EvalError, EvalResult};
10-
use eval_context::{EvalContext, IntegerExt, StackPopCleanup, is_inhabited};
10+
use eval_context::{EvalContext, IntegerExt, StackPopCleanup, is_inhabited, self};
1111
use lvalue::Lvalue;
1212
use memory::{MemoryPointer, TlsKey, Kind};
1313
use value::{PrimVal, Value};
1414
use rustc_data_structures::indexed_vec::Idx;
15+
use const_eval;
1516

1617
use std::mem;
1718

@@ -86,7 +87,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
8687
}
8788
(instance, sig)
8889
},
89-
ty::TyFnDef(def_id, substs) => (::eval_context::resolve(self.tcx, def_id, substs), func_ty.fn_sig(self.tcx)),
90+
ty::TyFnDef(def_id, substs) => (eval_context::resolve(self.tcx, def_id, substs), func_ty.fn_sig(self.tcx)),
9091
_ => {
9192
let msg = format!("can't handle callee of type {:?}", func_ty);
9293
return Err(EvalError::Unimplemented(msg));
@@ -104,9 +105,9 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
104105
let lval = self.eval_lvalue(location)?;
105106
let ty = self.lvalue_ty(location);
106107
self.goto_block(target);
107-
let ty = ::eval_context::apply_param_substs(self.tcx, self.substs(), &ty);
108+
let ty = eval_context::apply_param_substs(self.tcx, self.substs(), &ty);
108109

109-
let instance = ::eval_context::resolve_drop_in_place(self.tcx, ty);
110+
let instance = eval_context::resolve_drop_in_place(self.tcx, ty);
110111
self.drop_lvalue(lval, instance, ty, terminator.source_info.span)?;
111112
}
112113

@@ -869,7 +870,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
869870
// compute global if not cached
870871
let val = match self.globals.get(&cid).map(|glob| glob.value) {
871872
Some(value) => self.value_to_primval(value, usize)?.to_u64()?,
872-
None => ::const_eval::eval_body_as_primval(self.tcx, instance)?.0.to_u64()?,
873+
None => const_eval::eval_body_as_primval(self.tcx, instance)?.0.to_u64()?,
873874
};
874875
if val == name {
875876
result = Some(path_value);

src/traits.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc::traits::{self, Reveal};
22

3-
use eval_context::EvalContext;
3+
use eval_context::{EvalContext, self};
44
use memory::{MemoryPointer, Kind};
55
use value::{Value, PrimVal};
66

@@ -53,7 +53,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
5353
let methods = ::rustc::traits::get_vtable_methods(self.tcx, trait_ref);
5454
let vtable = self.memory.allocate(ptr_size * (3 + methods.count() as u64), ptr_size, Kind::UninitializedStatic)?;
5555

56-
let drop = ::eval_context::resolve_drop_in_place(self.tcx, ty);
56+
let drop = eval_context::resolve_drop_in_place(self.tcx, ty);
5757
let drop = self.memory.create_fn_alloc(drop);
5858
self.memory.write_ptr(vtable, drop)?;
5959

@@ -62,7 +62,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
6262

6363
for (i, method) in ::rustc::traits::get_vtable_methods(self.tcx, trait_ref).enumerate() {
6464
if let Some((def_id, substs)) = method {
65-
let instance = ::eval_context::resolve(self.tcx, def_id, substs);
65+
let instance = eval_context::resolve(self.tcx, def_id, substs);
6666
let fn_ptr = self.memory.create_fn_alloc(instance);
6767
self.memory.write_ptr(vtable.offset(ptr_size * (3 + i as u64), self.memory.layout)?, fn_ptr)?;
6868
}

0 commit comments

Comments
 (0)