Skip to content

Initialize MemoryExtra with StdRng #799

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

Merged
merged 10 commits into from
Jul 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24a9bcbb7cb0d8bdc11b8252a9c13f7562c7e4ca
481068a707679257e2a738b40987246e0420e787
19 changes: 10 additions & 9 deletions src/eval.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Main evaluator loop and setting up the initial stack frame.

use rand::rngs::StdRng;
use rand::SeedableRng;

Expand Down Expand Up @@ -29,23 +31,22 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
main_id: DefId,
config: MiriConfig,
) -> InterpResult<'tcx, InterpCx<'mir, 'tcx, Evaluator<'tcx>>> {
let mut ecx = InterpCx::new(
tcx.at(syntax::source_map::DUMMY_SP),
ty::ParamEnv::reveal_all(),
Evaluator::new(),
);

// FIXME(https://github.com/rust-lang/miri/pull/803): no validation on Windows.
let target_os = ecx.tcx.tcx.sess.target.target.target_os.to_lowercase();
let target_os = tcx.sess.target.target.target_os.to_lowercase();
let validate = if target_os == "windows" {
false
} else {
config.validate
};

// FIXME: InterpCx::new should take an initial MemoryExtra
ecx.memory_mut().extra = MemoryExtra::new(config.seed.map(StdRng::seed_from_u64), validate);

let mut ecx = InterpCx::new(
tcx.at(syntax::source_map::DUMMY_SP),
ty::ParamEnv::reveal_all(),
Evaluator::new(),
MemoryExtra::new(config.seed.map(StdRng::seed_from_u64), validate),
);

let main_instance = ty::Instance::mono(ecx.tcx.tcx, main_id);
let main_mir = ecx.load_mir(main_instance.def)?;

Expand Down
5 changes: 4 additions & 1 deletion src/machine.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! Global machine state as well as implementation of the interpreter engine
//! `Machine` trait.

use std::rc::Rc;
use std::borrow::Cow;
use std::collections::HashMap;
Expand Down Expand Up @@ -48,7 +51,7 @@ pub struct AllocExtra {
}

/// Extra global memory data
#[derive(Default, Clone, Debug)]
#[derive(Clone, Debug)]
pub struct MemoryExtra {
pub stacked_borrows: stacked_borrows::MemoryExtra,
pub intptrcast: intptrcast::MemoryExtra,
Expand Down
7 changes: 2 additions & 5 deletions src/range_map.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(unused)]

//! Implements a map from integer indices to data.
//! Rather than storing data for every index, internally, this maps entire ranges to the data.
//! To this end, the APIs all work on ranges, not on individual integers. Ranges are split as
Expand All @@ -8,7 +6,6 @@
//! via the iteration APIs.

use std::ops;
use std::num::NonZeroU64;

use rustc::ty::layout::Size;

Expand Down Expand Up @@ -158,7 +155,7 @@ impl<T> RangeMap<T> {
let mut end_idx = first_idx; // when the loop is done, this is the first excluded element.
loop {
// Compute if `end` is the last element we need to look at.
let done = (self.v[end_idx].range.end >= offset+len);
let done = self.v[end_idx].range.end >= offset+len;
// We definitely need to include `end`, so move the index.
end_idx += 1;
debug_assert!(done || end_idx < self.v.len(), "iter_mut: end-offset {} is out-of-bounds", offset+len);
Expand Down Expand Up @@ -284,7 +281,7 @@ mod tests {
.map(|&t| t).collect::<Vec<_>>(), vec![19, 19]);

// A NOP `iter_mut` should trigger merging.
for x in map.iter_mut(Size::from_bytes(15), Size::from_bytes(5)) { }
for _ in map.iter_mut(Size::from_bytes(15), Size::from_bytes(5)) { }
assert_eq!(map.v.len(), 5);
assert_eq!(
to_vec(&map, 10, 10),
Expand Down
2 changes: 2 additions & 0 deletions src/shims/tls.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Implement thread-local storage.

use std::collections::BTreeMap;

use rustc_target::abi::LayoutOf;
Expand Down
3 changes: 3 additions & 0 deletions src/stacked_borrows.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! Implements "Stacked Borrows". See <https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md>
//! for further information.

use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
use std::rc::Rc;
Expand Down
2 changes: 2 additions & 0 deletions tests/run-pass/move-undef-primval.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(deprecated)]

struct Foo {
_inner: i32,
}
Expand Down