Skip to content

Rustup #364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 30 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2671cf3
Update to some cleanups in rustc
oli-obk Dec 15, 2017
a23e587
stop using Instance::def_ty
arielb1 Dec 17, 2017
5147655
Merge branch 'master' into def_ty
oli-obk Dec 19, 2017
30496f5
update compiletest dependency
dwrensha Dec 31, 2017
03aa876
pass typecheck
dwrensha Jan 2, 2018
cabdc55
update log deps
dwrensha Jan 6, 2018
33af320
update for rust/47205
dwrensha Jan 15, 2018
d289c0f
partially deal with rust/46479
dwrensha Jan 15, 2018
9e04368
Rustup
bjorn3 Jan 14, 2018
3e339bc
rustup
bjorn3 Jan 27, 2018
9be04c0
Rustup
bjorn3 Mar 17, 2018
a204cb4
Add stack guard shim
bjorn3 Mar 17, 2018
aa5972d
Get the tests one step further
oli-obk Mar 18, 2018
1e094e5
WIP fix alignment issue
bjorn3 Mar 18, 2018
3038274
Dont claim to have marked static initialized
bjorn3 Mar 19, 2018
bad9fa5
Use elem align as src align in copy intrinsic
bjorn3 Mar 19, 2018
5db2aba
Hack: copy init_static from rustc CompileTimeEvaluator to try to fix …
bjorn3 Mar 19, 2018
896996b
Maybe prevent marking statics as immutable
bjorn3 Mar 19, 2018
907e67f
Fix init_static
bjorn3 Mar 23, 2018
5831309
travis: cache build dir
bjorn3 Mar 23, 2018
a86348b
Fix it
bjorn3 Mar 23, 2018
57e63b8
Fix (try 2)
bjorn3 Mar 23, 2018
654cd94
FIx (try 3)
bjorn3 Mar 23, 2018
6e60b79
Fix (try 4)
bjorn3 Mar 23, 2018
3656c03
Partially fix it
bjorn3 Mar 24, 2018
2137351
Rustup
bjorn3 Mar 31, 2018
5b8781c
Fix some more tests with some unsafe code
bjorn3 Apr 4, 2018
054b0db
Remove unsafe code
bjorn3 Apr 7, 2018
77413d7
Some cleanups
bjorn3 Apr 7, 2018
2e1b165
Update Cargo.lock and some improvements
bjorn3 Apr 7, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 22 additions & 63 deletions miri/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ pub struct MemoryData<'tcx> {
/// Only mutable (static mut, heap, stack) allocations have an entry in this map.
/// The entry is created when allocating the memory and deleted after deallocation.
locks: HashMap<AllocId, RangeMap<LockInfo<'tcx>>>,

mut_statics: HashMap<GlobalId<'tcx>, AllocId>,
}

impl<'mir, 'tcx: 'mir> Machine<'mir, 'tcx> for Evaluator<'tcx> {
Expand Down Expand Up @@ -268,69 +270,26 @@ impl<'mir, 'tcx: 'mir> Machine<'mir, 'tcx> for Evaluator<'tcx> {
ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
cid: GlobalId<'tcx>,
) -> EvalResult<'tcx, AllocId> {
let tcx = self.tcx.tcx;
let mir = None;
let param_env = ty::ParamEnv::reveal_all();
// we start out with the best span we have
// and try improving it down the road when more information is available
let res = (|| {
let mut mir = match mir {
Some(mir) => mir,
None => ecx.load_mir(cid.instance.def)?,
};
if let Some(index) = cid.promoted {
mir = &mir.promoted[index];
}
span = mir.span;
let layout = ecx.layout_of(mir.return_ty().subst(tcx, cid.instance.substs))?;
let alloc = tcx.interpret_interner.get_cached(cid.instance.def_id());
let is_static = tcx.is_static(cid.instance.def_id()).is_some();
let alloc = match alloc {
Some(alloc) => {
assert!(cid.promoted.is_none());
assert!(param_env.caller_bounds.is_empty());
alloc
},
None => {
assert!(!layout.is_unsized());
let ptr = ecx.memory.allocate(
layout.size.bytes(),
layout.align,
None,
)?;
if is_static {
tcx.interpret_interner.cache(cid.instance.def_id(), ptr.alloc_id);
}
let internally_mutable = !layout.ty.is_freeze(tcx, param_env, mir.span);
let mutability = tcx.is_static(cid.instance.def_id());
let mutability = if mutability == Some(hir::Mutability::MutMutable) || internally_mutable {
Mutability::Mutable
} else {
Mutability::Immutable
};
let cleanup = StackPopCleanup::MarkStatic(mutability);
let name = ty::tls::with(|tcx| tcx.item_path_str(cid.instance.def_id()));
let prom = cid.promoted.map_or(String::new(), |p| format!("::promoted[{:?}]", p));
trace!("const_eval: pushing stack frame for global: {}{}", name, prom);
assert!(mir.arg_count == 0);
ecx.push_stack_frame(
cid.instance,
mir.span,
mir,
Place::from_ptr(ptr, layout.align),
cleanup,
)?;

while ecx.step()? {}
ptr.alloc_id
}
};
let ptr = MemoryPointer::new(alloc, 0).into();
// always try to read the value and report errors
Ok((ptr, layout.ty))
})();
let (mem_ptr, _) = res?;
Ok(mem_ptr.alloc_id)
if let Some(alloc_id) = ecx.memory.data.get(&cid) {
return Ok(alloc_id);
}
let mir = ecx.load_mir(cid.instance.def)?;
let layout = ecx.layout_of(mir.return_ty().subst(tcx, cid.instance.substs))?;
let to_ptr = ecx.memory.allocate(
layout.size.bytes(),
layout.align,
None,
)?;
ecx.const_eval(cid)?;
let ptr = ecx
.tcx
.interpret_interner
.get_cached(cid.instance.def_id())
.expect("uncached static");
ecx.memory.copy(ptr, layout.align, to_ptr.into(), layout.align, layout.size.bytes(), true)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work, because the memory might contain references into other statics. We also can't implement it as deep copies, because then we'd duplicate some other static's memory instead of referring to it.

Instead of calling ecx.const_eval do the code you had above, just without the interpret_interner accesses (instead to the machine caching as you do it here)

ecx.memory.mark_static_initialized(to_ptr.alloc_id, ::syntax::ast::Mutability::Mutable)?;
assert!(ecx.memory.data.insert(cid, to_ptr.alloc_id).is_none());
Ok(to_ptr.alloc_id)
}

fn box_alloc<'a>(
Expand Down