Skip to content

Commit ec93909

Browse files
committed
prepare_fn_for_calleval_callee_and_args, +EvaluatedCalleeAndArgs
Small refactor required by review.
1 parent 6fa5dfd commit ec93909

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

compiler/rustc_const_eval/src/interpret/terminator.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ impl<'tcx, Prov: Provenance> FnArg<'tcx, Prov> {
4242
}
4343
}
4444

45+
struct EvaluatedCalleeAndArgs<'tcx, 'mir, M: Machine<'mir, 'tcx>> {
46+
callee: FnVal<'tcx, M::ExtraFnVal>,
47+
args: Vec<FnArg<'tcx, <M as Machine<'mir, 'tcx>>::Provenance>>,
48+
fn_sig: ty::FnSig<'tcx>,
49+
fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>,
50+
/// True if the function is marked as `#[track_caller]` ([`ty::InstanceDef::requires_caller_location`])
51+
with_caller_location: bool,
52+
}
53+
4554
impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
4655
/// Make a copy of the given fn_arg. Any `InPlace` are degenerated to copies, no protection of the
4756
/// original memory occurs.
@@ -123,12 +132,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
123132
let old_stack = self.frame_idx();
124133
let old_loc = self.frame().loc;
125134

126-
let (fn_val, args, fn_sig, fn_abi, with_caller_location) =
127-
self.prepare_fn_for_call(terminator, func, args)?;
135+
let EvaluatedCalleeAndArgs { callee, args, fn_sig, fn_abi, with_caller_location } =
136+
self.eval_callee_and_args(terminator, func, args)?;
128137

129138
let destination = self.eval_place(destination)?;
130139
self.eval_fn_call(
131-
fn_val,
140+
callee,
132141
(fn_sig.abi, fn_abi),
133142
&args,
134143
with_caller_location,
@@ -146,8 +155,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
146155
TailCall { ref func, ref args, fn_span: _ } => {
147156
let old_frame_idx = self.frame_idx();
148157

149-
let (fn_val, args, fn_sig, fn_abi, with_caller_location) =
150-
self.prepare_fn_for_call(terminator, func, args)?;
158+
let EvaluatedCalleeAndArgs { callee, args, fn_sig, fn_abi, with_caller_location } =
159+
self.eval_callee_and_args(terminator, func, args)?;
151160

152161
// This is the "canonical" implementation of tails calls,
153162
// a pop of the current stack frame, followed by a normal call
@@ -170,7 +179,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
170179
};
171180

172181
self.eval_fn_call(
173-
fn_val,
182+
callee,
174183
(fn_sig.abi, fn_abi),
175184
&args,
176185
with_caller_location,
@@ -507,22 +516,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
507516
}
508517

509518
/// Shared part of `Call` and `TailCall` implementation — finding and evaluating all the
510-
/// necessary information about callee to make a call.
511-
fn prepare_fn_for_call(
519+
/// necessary information about callee and arguments to make a call.
520+
fn eval_callee_and_args(
512521
&self,
513522
terminator: &mir::Terminator<'tcx>,
514523
func: &mir::Operand<'tcx>,
515524
args: &[Spanned<mir::Operand<'tcx>>],
516-
) -> InterpResult<
517-
'tcx,
518-
(
519-
FnVal<'tcx, M::ExtraFnVal>,
520-
Vec<FnArg<'tcx, <M as Machine<'mir, 'tcx>>::Provenance>>,
521-
ty::FnSig<'tcx>,
522-
&'tcx FnAbi<'tcx, Ty<'tcx>>,
523-
bool,
524-
),
525-
> {
525+
) -> InterpResult<'tcx, EvaluatedCalleeAndArgs<'tcx, 'mir, M>> {
526526
let func = self.eval_operand(func, None)?;
527527
let args = self.eval_fn_call_arguments(args)?;
528528

@@ -532,7 +532,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
532532
let extra_args =
533533
self.tcx.mk_type_list_from_iter(extra_args.iter().map(|arg| arg.layout().ty));
534534

535-
let (fn_val, fn_abi, with_caller_location) = match *func.layout.ty.kind() {
535+
let (callee, fn_abi, with_caller_location) = match *func.layout.ty.kind() {
536536
ty::FnPtr(_sig) => {
537537
let fn_ptr = self.read_pointer(&func)?;
538538
let fn_val = self.get_ptr_fn(fn_ptr)?;
@@ -551,7 +551,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
551551
}
552552
};
553553

554-
Ok((fn_val, args, fn_sig, fn_abi, with_caller_location))
554+
Ok(EvaluatedCalleeAndArgs { callee, args, fn_sig, fn_abi, with_caller_location })
555555
}
556556

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

0 commit comments

Comments
 (0)