Skip to content

Commit 3e7218b

Browse files
committed
Reduce the chance of accidentally calling functions in CTFE
previously miri had a check for const fn and other cases that CTFE requires. Instead the function call is completely processed inside the machine. This allows CTFE to have full control over what is called and miri to not have useless CTFE-checks in normal mode.
1 parent c8b5e6e commit 3e7218b

File tree

6 files changed

+59
-574
lines changed

6 files changed

+59
-574
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ compiletest_rs = "0.2.6"
3535

3636
[workspace]
3737
members = ["src/librustc_mir"]
38+
exclude = ["xargo"]

miri/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ use rustc::ty::{self, TyCtxt};
1717
use rustc::hir::def_id::DefId;
1818
use rustc::mir;
1919

20+
use syntax::codemap::Span;
21+
2022
use std::collections::{
2123
HashMap,
2224
BTreeMap,
@@ -25,7 +27,7 @@ use std::collections::{
2527
extern crate rustc_miri;
2628
pub use rustc_miri::interpret::*;
2729

28-
mod missing_fns;
30+
mod fn_call;
2931
mod operator;
3032

3133
pub fn eval_main<'a, 'tcx: 'a>(
@@ -304,17 +306,19 @@ impl<'b, 'a, 'tcx> MemoryMut<'b, 'a, 'tcx> {
304306
impl<'tcx> Machine<'tcx> for Evaluator {
305307
type Data = EvaluatorData;
306308
type MemoryData = MemoryData<'tcx>;
309+
307310
/// Returns Ok() when the function was handled, fail otherwise
308-
fn call_missing_fn<'a>(
311+
fn eval_fn_call<'a>(
309312
ecx: &mut rustc_miri::interpret::EvalContext<'a, 'tcx, Self>,
310313
instance: ty::Instance<'tcx>,
311314
destination: Option<(Lvalue<'tcx>, mir::BasicBlock)>,
312315
arg_operands: &[mir::Operand<'tcx>],
316+
span: Span,
313317
sig: ty::FnSig<'tcx>,
314-
path: String,
315-
) -> EvalResult<'tcx> {
316-
EvalContext(ecx).call_missing_fn(instance, destination, arg_operands, sig, path)
318+
) -> EvalResult<'tcx, bool> {
319+
EvalContext(ecx).eval_fn_call(instance, destination, arg_operands, span, sig)
317320
}
321+
318322
fn ptr_op<'a>(
319323
ecx: &rustc_miri::interpret::EvalContext<'a, 'tcx, Self>,
320324
bin_op: mir::BinOp,
@@ -325,8 +329,4 @@ impl<'tcx> Machine<'tcx> for Evaluator {
325329
) -> EvalResult<'tcx, Option<(PrimVal, bool)>> {
326330
ImmEvalContext(ecx).ptr_op(bin_op, left, left_ty, right, right_ty)
327331
}
328-
329-
fn check_non_const_fn_call(_instance: ty::Instance<'tcx>) -> EvalResult<'tcx> {
330-
Ok(())
331-
}
332332
}

0 commit comments

Comments
 (0)