Move MIR body loading to a machine function
This commit is contained in:
parent
f6d54aa0c1
commit
caeb3d525d
4 changed files with 34 additions and 10 deletions
|
@ -200,6 +200,22 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
|
||||||
|
|
||||||
type MemoryExtra = MemoryExtra;
|
type MemoryExtra = MemoryExtra;
|
||||||
|
|
||||||
|
fn load_mir(
|
||||||
|
ecx: &InterpCx<'mir, 'tcx, Self>,
|
||||||
|
instance: ty::InstanceDef<'tcx>,
|
||||||
|
) -> InterpResult<'tcx, &'tcx mir::Body<'tcx>> {
|
||||||
|
match instance {
|
||||||
|
ty::InstanceDef::Item(def) => {
|
||||||
|
if ecx.tcx.is_ctfe_mir_available(def.did) {
|
||||||
|
Ok(ecx.tcx.mir_for_ctfe_opt_const_arg(def))
|
||||||
|
} else {
|
||||||
|
throw_unsup!(NoMirFor(def.did))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => Ok(ecx.tcx.instance_mir(instance)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn find_mir_or_eval_fn(
|
fn find_mir_or_eval_fn(
|
||||||
ecx: &mut InterpCx<'mir, 'tcx, Self>,
|
ecx: &mut InterpCx<'mir, 'tcx, Self>,
|
||||||
instance: ty::Instance<'tcx>,
|
instance: ty::Instance<'tcx>,
|
||||||
|
|
|
@ -477,16 +477,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
if let Some(promoted) = promoted {
|
if let Some(promoted) = promoted {
|
||||||
return Ok(&self.tcx.promoted_mir_opt_const_arg(def)[promoted]);
|
return Ok(&self.tcx.promoted_mir_opt_const_arg(def)[promoted]);
|
||||||
}
|
}
|
||||||
match instance {
|
M::load_mir(self, instance)
|
||||||
ty::InstanceDef::Item(def) => {
|
|
||||||
if self.tcx.is_ctfe_mir_available(def.did) {
|
|
||||||
Ok(self.tcx.mir_for_ctfe_opt_const_arg(def))
|
|
||||||
} else {
|
|
||||||
throw_unsup!(NoMirFor(def.did))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => Ok(self.tcx.instance_mir(instance)),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Call this on things you got out of the MIR (so it is as generic as the current
|
/// Call this on things you got out of the MIR (so it is as generic as the current
|
||||||
|
|
|
@ -131,6 +131,16 @@ pub trait Machine<'mir, 'tcx>: Sized {
|
||||||
/// Whether to enforce the validity invariant
|
/// Whether to enforce the validity invariant
|
||||||
fn enforce_validity(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
|
fn enforce_validity(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
|
||||||
|
|
||||||
|
/// Entry point for obtaining the MIR of anything that should get evaluated.
|
||||||
|
/// So not just functions and shims, but also const/static initializers, anonymous
|
||||||
|
/// constants, ...
|
||||||
|
fn load_mir(
|
||||||
|
ecx: &InterpCx<'mir, 'tcx, Self>,
|
||||||
|
instance: ty::InstanceDef<'tcx>,
|
||||||
|
) -> InterpResult<'tcx, &'tcx mir::Body<'tcx>> {
|
||||||
|
Ok(ecx.tcx.instance_mir(instance))
|
||||||
|
}
|
||||||
|
|
||||||
/// Entry point to all function calls.
|
/// Entry point to all function calls.
|
||||||
///
|
///
|
||||||
/// Returns either the mir to use for the call, or `None` if execution should
|
/// Returns either the mir to use for the call, or `None` if execution should
|
||||||
|
|
|
@ -184,6 +184,13 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx>
|
||||||
|
|
||||||
type MemoryExtra = ();
|
type MemoryExtra = ();
|
||||||
|
|
||||||
|
fn load_mir(
|
||||||
|
_ecx: &InterpCx<'mir, 'tcx, Self>,
|
||||||
|
_instance: ty::InstanceDef<'tcx>,
|
||||||
|
) -> InterpResult<'tcx, &'tcx Body<'tcx>> {
|
||||||
|
throw_machine_stop_str!("calling functions isn't supported in ConstProp")
|
||||||
|
}
|
||||||
|
|
||||||
fn find_mir_or_eval_fn(
|
fn find_mir_or_eval_fn(
|
||||||
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
|
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
|
||||||
_instance: ty::Instance<'tcx>,
|
_instance: ty::Instance<'tcx>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue