Skip to content

Commit

Permalink
prepare_fn_for_calleval_callee_and_args, +`EvaluatedCalleeAndA…
Browse files Browse the repository at this point in the history
…rgs`

Small refactor required by review.
  • Loading branch information
WaffleLapkin committed Jul 11, 2023
1 parent 6d1e2d8 commit 406bd6b
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions compiler/rustc_const_eval/src/interpret/terminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ use super::{
};
use crate::fluent_generated as fluent;

struct EvaluatedCalleeAndArgs<'tcx, 'mir, M: Machine<'mir, 'tcx>> {
fn_val: FnVal<'tcx, M::ExtraFnVal>,
args: Vec<OpTy<'tcx, M::Provenance>>,
fn_sig: ty::FnSig<'tcx>,
fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>,
/// True if the function is marked as `#[track_caller]` ([`ty::InstanceDef::requires_caller_location`])
with_caller_location: bool,
}

impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
pub(super) fn eval_terminator(
&mut self,
Expand Down Expand Up @@ -68,8 +77,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let old_stack = self.frame_idx();
let old_loc = self.frame().loc;

let (fn_val, args, fn_sig, fn_abi, with_caller_location) =
self.prepare_fn_for_call(terminator, func, args)?;
let EvaluatedCalleeAndArgs { fn_val, args, fn_sig, fn_abi, with_caller_location } =
self.eval_callee_and_args(terminator, func, args)?;

let destination = self.eval_place(destination)?;
self.eval_fn_call(
Expand All @@ -91,8 +100,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
TailCall { ref func, ref args, fn_span: _ } => {
let old_frame_idx = self.frame_idx();

let (fn_val, args, fn_sig, fn_abi, with_caller_location) =
self.prepare_fn_for_call(terminator, func, args)?;
let EvaluatedCalleeAndArgs { fn_val, args, fn_sig, fn_abi, with_caller_location } =
self.eval_callee_and_args(terminator, func, args)?;

// This is the "canonical" implementation of tails calls,
// a pop of the current stack frame, followed by a normal call
Expand Down Expand Up @@ -347,22 +356,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
}

/// Shared part of `Call` and `TailCall` implementation — finding and evaluating all the
/// necessary information about callee to make a call.
fn prepare_fn_for_call(
/// necessary information about callee and arguments to make a call.
fn eval_callee_and_args(
&self,
terminator: &mir::Terminator<'tcx>,
func: &mir::Operand<'tcx>,
args: &[mir::Operand<'tcx>],
) -> InterpResult<
'tcx,
(
FnVal<'tcx, M::ExtraFnVal>,
Vec<OpTy<'tcx, M::Provenance>>,
ty::FnSig<'tcx>,
&'tcx FnAbi<'tcx, Ty<'tcx>>,
bool,
),
> {
) -> InterpResult<'tcx, EvaluatedCalleeAndArgs<'tcx, 'mir, M>> {
let func = self.eval_operand(func, None)?;
let args = self.eval_operands(args)?;

Expand Down Expand Up @@ -393,7 +393,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
),
};

Ok((fn_val, args, fn_sig, fn_abi, with_caller_location))
Ok(EvaluatedCalleeAndArgs { fn_val, args, fn_sig, fn_abi, with_caller_location })
}

/// Call this function -- pushing the stack frame and initializing the arguments.
Expand Down

0 comments on commit 406bd6b

Please sign in to comment.