Skip to content

Commit 0b6e349

Browse files
committed
automalically use start-fn if we have all the MIR
1 parent 186e42d commit 0b6e349

File tree

5 files changed

+16
-34
lines changed

5 files changed

+16
-34
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ script:
5050
# test `cargo miri`
5151
cd cargo-miri-test &&
5252
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
53-
cargo miri -q -- -Zmiri-start-fn
53+
cargo miri -q
5454
else
55-
cargo miri -q -- -Zmiri-start-fn >stdout.real 2>stderr.real &&
55+
cargo miri -q >stdout.real 2>stderr.real &&
5656
cat stdout.real stderr.real &&
5757
# Test `cargo miri` output. Not on mac because output redirecting doesn't
5858
# work. There is no error. It just stops CI.

src/bin/miri-rustc-tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn after_analysis<'a, 'tcx>(state: &mut CompileState<'a, 'tcx>) {
9595
if i.attrs.iter().any(|attr| attr.name() == "test") {
9696
let did = self.0.hir.body_owner_def_id(body_id);
9797
println!("running test: {}", self.0.def_path_debug_str(did));
98-
miri::eval_main(self.0, did, None, /*validate*/true);
98+
miri::eval_main(self.0, did, /*validate*/true);
9999
self.1.session.abort_if_errors();
100100
}
101101
}
@@ -106,7 +106,7 @@ fn after_analysis<'a, 'tcx>(state: &mut CompileState<'a, 'tcx>) {
106106
state.hir_crate.unwrap().visit_all_item_likes(&mut Visitor(tcx, state));
107107
} else if let Some((entry_node_id, _, _)) = *state.session.entry_fn.borrow() {
108108
let entry_def_id = tcx.hir.local_def_id(entry_node_id);
109-
miri::eval_main(tcx, entry_def_id, None, /*validate*/true);
109+
miri::eval_main(tcx, entry_def_id, /*validate*/true);
110110

111111
state.session.abort_if_errors();
112112
} else {

src/bin/miri.rs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ use std::path::PathBuf;
2626
struct MiriCompilerCalls {
2727
default: Box<RustcDefaultCalls>,
2828

29-
/// Whether to begin interpretation at the start_fn lang item or not.
30-
///
31-
/// If false, the interpretation begins at the `main` function.
32-
start_fn: bool,
33-
3429
/// Whether to enforce the validity invariant.
3530
validate: bool,
3631
}
@@ -90,10 +85,9 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
9085
let this = *self;
9186
let mut control = this.default.build_controller(sess, matches);
9287
control.after_hir_lowering.callback = Box::new(after_hir_lowering);
93-
let start_fn = this.start_fn;
9488
let validate = this.validate;
9589
control.after_analysis.callback =
96-
Box::new(move |state| after_analysis(state, start_fn, validate));
90+
Box::new(move |state| after_analysis(state, validate));
9791
control.after_analysis.stop = Compilation::Stop;
9892
control
9993
}
@@ -109,7 +103,6 @@ fn after_hir_lowering(state: &mut CompileState) {
109103

110104
fn after_analysis<'a, 'tcx>(
111105
state: &mut CompileState<'a, 'tcx>,
112-
use_start_fn: bool,
113106
validate: bool,
114107
) {
115108
state.session.abort_if_errors();
@@ -134,7 +127,7 @@ fn after_analysis<'a, 'tcx>(
134127
"running test: {}",
135128
self.tcx.def_path_debug_str(did),
136129
);
137-
miri::eval_main(self.tcx, did, None, self.validate);
130+
miri::eval_main(self.tcx, did, self.validate);
138131
self.state.session.abort_if_errors();
139132
}
140133
}
@@ -147,13 +140,7 @@ fn after_analysis<'a, 'tcx>(
147140
);
148141
} else if let Some((entry_node_id, _, _)) = *state.session.entry_fn.borrow() {
149142
let entry_def_id = tcx.hir.local_def_id(entry_node_id);
150-
// Use start_fn lang item if we have -Zmiri-start-fn set
151-
let start_wrapper = if use_start_fn {
152-
Some(tcx.lang_items().start_fn().unwrap())
153-
} else {
154-
None
155-
};
156-
miri::eval_main(tcx, entry_def_id, start_wrapper, validate);
143+
miri::eval_main(tcx, entry_def_id, validate);
157144

158145
state.session.abort_if_errors();
159146
} else {
@@ -231,14 +218,9 @@ fn main() {
231218
args.push(find_sysroot());
232219
}
233220

234-
let mut start_fn = false;
235221
let mut validate = true;
236222
args.retain(|arg| {
237223
match arg.as_str() {
238-
"-Zmiri-start-fn" => {
239-
start_fn = true;
240-
false
241-
},
242224
"-Zmiri-disable-validation" => {
243225
validate = false;
244226
false
@@ -251,7 +233,6 @@ fn main() {
251233
let result = rustc_driver::run(move || {
252234
rustc_driver::run_compiler(&args, Box::new(MiriCompilerCalls {
253235
default: Box::new(RustcDefaultCalls),
254-
start_fn,
255236
validate,
256237
}), None, None)
257238
});

src/lib.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ use mono_hash_map::MonoHashMap;
5050
pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>(
5151
tcx: TyCtxt<'a, 'tcx, 'tcx>,
5252
main_id: DefId,
53-
start_wrapper: Option<DefId>,
5453
validate: bool,
5554
) -> EvalResult<'tcx, EvalContext<'a, 'mir, 'tcx, Evaluator<'tcx>>> {
5655
let mut ecx = EvalContext::new(
@@ -70,8 +69,14 @@ pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>(
7069
));
7170
}
7271

73-
if let Some(start_id) = start_wrapper {
74-
let main_ret_ty = ecx.tcx.fn_sig(main_id).output();
72+
let libstd_has_mir = {
73+
let rustc_panic = ecx.resolve_path(&["std", "panicking", "rust_panic"])?;
74+
ecx.load_mir(rustc_panic.def).is_ok()
75+
};
76+
77+
if libstd_has_mir {
78+
let start_id = tcx.lang_items().start_fn().unwrap();
79+
let main_ret_ty = tcx.fn_sig(main_id).output();
7580
let main_ret_ty = main_ret_ty.no_late_bound_regions().unwrap();
7681
let start_instance = ty::Instance::resolve(
7782
ecx.tcx.tcx,
@@ -146,10 +151,9 @@ pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>(
146151
pub fn eval_main<'a, 'tcx: 'a>(
147152
tcx: TyCtxt<'a, 'tcx, 'tcx>,
148153
main_id: DefId,
149-
start_wrapper: Option<DefId>,
150154
validate: bool,
151155
) {
152-
let mut ecx = create_ecx(tcx, main_id, start_wrapper, validate).expect("Couldn't create ecx");
156+
let mut ecx = create_ecx(tcx, main_id, validate).expect("Couldn't create ecx");
153157

154158
let res: EvalResult = (|| {
155159
ecx.run()?;

tests/compiletest.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ fn miri_pass(sysroot: &Path, path: &str, target: &str, host: &str, need_fullmir:
100100
let mut flags = Vec::new();
101101
flags.push(format!("--sysroot {}", sysroot.display()));
102102
flags.push("-Dwarnings -Dunused".to_owned()); // overwrite the -Aunused in compiletest-rs
103-
if have_fullmir() {
104-
flags.push("-Zmiri-start-fn".to_owned());
105-
}
106103
if opt {
107104
// FIXME: Using level 1 (instead of 3) for now, as the optimizer is pretty broken
108105
// and crashes...

0 commit comments

Comments
 (0)