Skip to content

Commit 12dd3bf

Browse files
committed
a bit of refactoring for find_mir_or_eval_fn
1 parent e611211 commit 12dd3bf

File tree

3 files changed

+15
-43
lines changed

3 files changed

+15
-43
lines changed

src/tools/miri/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ pub use crate::shims::os_str::EvalContextExt as _;
9494
pub use crate::shims::panic::{CatchUnwindData, EvalContextExt as _};
9595
pub use crate::shims::time::EvalContextExt as _;
9696
pub use crate::shims::tls::TlsData;
97-
pub use crate::shims::EvalContextExt as _;
9897

9998
pub use crate::borrow_tracker::stacked_borrows::{
10099
EvalContextExt as _, Item, Permission, Stack, Stacks,

src/tools/miri/src/machine.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,21 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
920920
ret: Option<mir::BasicBlock>,
921921
unwind: mir::UnwindAction,
922922
) -> InterpResult<'tcx, Option<(&'mir mir::Body<'tcx>, ty::Instance<'tcx>)>> {
923-
ecx.find_mir_or_eval_fn(instance, abi, args, dest, ret, unwind)
923+
// For foreign items, try to see if we can emulate them.
924+
if ecx.tcx.is_foreign_item(instance.def_id()) {
925+
// An external function call that does not have a MIR body. We either find MIR elsewhere
926+
// or emulate its effect.
927+
// This will be Ok(None) if we're emulating the intrinsic entirely within Miri (no need
928+
// to run extra MIR), and Ok(Some(body)) if we found MIR to run for the
929+
// foreign function
930+
// Any needed call to `goto_block` will be performed by `emulate_foreign_item`.
931+
let args = ecx.copy_fn_args(args)?; // FIXME: Should `InPlace` arguments be reset to uninit?
932+
let link_name = ecx.item_link_name(instance.def_id());
933+
return ecx.emulate_foreign_item(link_name, abi, &args, dest, ret, unwind);
934+
}
935+
936+
// Otherwise, load the MIR.
937+
Ok(Some((ecx.load_mir(instance.def, None)?, instance)))
924938
}
925939

926940
#[inline(always)]

src/tools/miri/src/shims/mod.rs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,3 @@ pub mod os_str;
1515
pub mod panic;
1616
pub mod time;
1717
pub mod tls;
18-
19-
// End module management, begin local code
20-
21-
use log::trace;
22-
23-
use rustc_middle::{mir, ty};
24-
use rustc_target::spec::abi::Abi;
25-
26-
use crate::*;
27-
28-
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir, 'tcx> {}
29-
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
30-
fn find_mir_or_eval_fn(
31-
&mut self,
32-
instance: ty::Instance<'tcx>,
33-
abi: Abi,
34-
args: &[FnArg<'tcx, Provenance>],
35-
dest: &PlaceTy<'tcx, Provenance>,
36-
ret: Option<mir::BasicBlock>,
37-
unwind: mir::UnwindAction,
38-
) -> InterpResult<'tcx, Option<(&'mir mir::Body<'tcx>, ty::Instance<'tcx>)>> {
39-
let this = self.eval_context_mut();
40-
trace!("eval_fn_call: {:#?}, {:?}", instance, dest);
41-
42-
// For foreign items, try to see if we can emulate them.
43-
if this.tcx.is_foreign_item(instance.def_id()) {
44-
// An external function call that does not have a MIR body. We either find MIR elsewhere
45-
// or emulate its effect.
46-
// This will be Ok(None) if we're emulating the intrinsic entirely within Miri (no need
47-
// to run extra MIR), and Ok(Some(body)) if we found MIR to run for the
48-
// foreign function
49-
// Any needed call to `goto_block` will be performed by `emulate_foreign_item`.
50-
let args = this.copy_fn_args(args)?; // FIXME: Should `InPlace` arguments be reset to uninit?
51-
let link_name = this.item_link_name(instance.def_id());
52-
return this.emulate_foreign_item(link_name, abi, &args, dest, ret, unwind);
53-
}
54-
55-
// Otherwise, load the MIR.
56-
Ok(Some((this.load_mir(instance.def, None)?, instance)))
57-
}
58-
}

0 commit comments

Comments
 (0)