-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-miriArea: The miri toolArea: The miri toolC-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: PRs that clean code up or issues documenting cleanup.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Miri, CTFE, and const-prop are implemented by using a MIR interpreter that can be customized by implementing the Machine
trait. Currently, the CTFE and const-prop machines have quite a bit of common code that is duplicated. It would be nice to reduce the code duplication.
One idea that could be used to reduce the code duplication would be to add a new trait CommonMachine
and put all the common implementation into it:
pub trait CommonMachine<'mir, 'tcx>: Sized {
/// Borrow the current thread's stack.
fn stack(
ecx: &'a InterpCx<'mir, 'tcx, Self>,
) -> &'a [Frame<'mir, 'tcx, (), ()>];
/// Mutably borrow the current thread's stack.
fn stack_mut(
ecx: &'a mut InterpCx<'mir, 'tcx, Self>,
) -> &'a mut Vec<Frame<'mir, 'tcx, (), ()>>;
// Other methods that require custom implementations for the CTFE and const-prop machines.
}
impl<'mir, 'tcx, T: CommonMachine<'mir, 'tcx>> super::machine::Machine<'mir, 'tcx> for T {
type MemoryKind = !;
type PointerTag = ();
type ExtraFnVal = !;
type FrameExtra = ();
type MemoryExtra = ();
type AllocExtra = ();
#[inline(always)]
fn enforce_alignment(_memory_extra: &Self::MemoryExtra) -> bool {
false
}
/// Borrow the current thread's stack.
fn stack(
ecx: &'a InterpCx<'mir, 'tcx, Self>,
) -> &'a [Frame<'mir, 'tcx, (), ()>] {
CommonMachine::stack(ecx)
}
/// Mutably borrow the current thread's stack.
fn stack_mut(
ecx: &'a mut InterpCx<'mir, 'tcx, Self>,
) -> &'a mut Vec<Frame<'mir, 'tcx, (), ()>> {
CommonMachine::stack_mut(ecx)
}
// TODO: other methods
}
Metadata
Metadata
Assignees
Labels
A-miriArea: The miri toolArea: The miri toolC-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: PRs that clean code up or issues documenting cleanup.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.