Skip to content

Commit 068c448

Browse files
committed
Add communicate field to evaluator and fix formatting
1 parent 655f9af commit 068c448

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

benches/helpers/miri_helper.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ impl rustc_driver::Callbacks for MiriCompilerCalls<'_> {
2525
);
2626

2727
self.bencher.iter(|| {
28-
let config = miri::MiriConfig { validate: true, communicate: false, args: vec![], seed: None };
28+
let config = miri::MiriConfig {
29+
validate: true,
30+
communicate: false,
31+
args: vec![],
32+
seed: None,
33+
};
2934
eval_main(tcx, entry_def_id, config);
3035
});
3136
});

src/bin/miri-rustc-tests.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
4848
fn visit_item(&mut self, i: &'hir hir::Item) {
4949
if let hir::ItemKind::Fn(.., body_id) = i.node {
5050
if i.attrs.iter().any(|attr| attr.check_name(syntax::symbol::sym::test)) {
51-
let config = MiriConfig { validate: true, communicate: false, args: vec![], seed: None };
51+
let config = MiriConfig {
52+
validate: true,
53+
communicate: false,
54+
args: vec![],
55+
seed: None,
56+
};
5257
let did = self.0.hir().body_owner_def_id(body_id);
5358
println!("running test: {}", self.0.def_path_debug_str(did));
5459
miri::eval_main(self.0, did, config);
@@ -62,7 +67,12 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
6267
tcx.hir().krate().visit_all_item_likes(&mut Visitor(tcx));
6368
} else if let Some((entry_def_id, _)) = tcx.entry_fn(LOCAL_CRATE) {
6469

65-
let config = MiriConfig { validate: true, communicate: false, args: vec![], seed: None };
70+
let config = MiriConfig {
71+
validate: true,
72+
communicate: false,
73+
args: vec![],
74+
seed: None
75+
};
6676
miri::eval_main(tcx, entry_def_id, config);
6777

6878
compiler.session().abort_if_errors();

src/eval.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ use crate::{
1818
#[derive(Clone)]
1919
pub struct MiriConfig {
2020
pub validate: bool,
21+
/// Determines if communication with the host environment is enabled.
2122
pub communicate: bool,
2223
pub args: Vec<String>,
2324

24-
// The seed to use when non-determinism is required (e.g. getrandom())
25+
/// The seed to use when non-determinism is required (e.g. getrandom())
2526
pub seed: Option<u64>,
2627
}
2728

@@ -34,7 +35,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
3435
let mut ecx = InterpCx::new(
3536
tcx.at(syntax::source_map::DUMMY_SP),
3637
ty::ParamEnv::reveal_all(),
37-
Evaluator::new(),
38+
Evaluator::new(config.communicate),
3839
MemoryExtra::new(StdRng::seed_from_u64(config.seed.unwrap_or(0)), config.validate),
3940
);
4041

src/machine.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,21 @@ pub struct Evaluator<'tcx> {
9393

9494
/// TLS state.
9595
pub(crate) tls: TlsData<'tcx>,
96+
97+
/// If enabled, the `env_vars` field is populated with the host env vars during initialization.
98+
pub(crate) communicate: bool,
9699
}
97100

98101
impl<'tcx> Evaluator<'tcx> {
99-
pub(crate) fn new() -> Self {
102+
pub(crate) fn new(communicate: bool) -> Self {
100103
Evaluator {
101104
env_vars: HashMap::default(),
102105
argc: None,
103106
argv: None,
104107
cmd_line: None,
105108
last_error: 0,
106109
tls: TlsData::default(),
110+
communicate,
107111
}
108112
}
109113
}

0 commit comments

Comments
 (0)