@@ -42,6 +42,15 @@ impl<'tcx, Prov: Provenance> FnArg<'tcx, Prov> {
42
42
}
43
43
}
44
44
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
+
45
54
impl < ' mir , ' tcx : ' mir , M : Machine < ' mir , ' tcx > > InterpCx < ' mir , ' tcx , M > {
46
55
/// Make a copy of the given fn_arg. Any `InPlace` are degenerated to copies, no protection of the
47
56
/// original memory occurs.
@@ -123,12 +132,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
123
132
let old_stack = self . frame_idx ( ) ;
124
133
let old_loc = self . frame ( ) . loc ;
125
134
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) ?;
128
137
129
138
let destination = self . eval_place ( destination) ?;
130
139
self . eval_fn_call (
131
- fn_val ,
140
+ callee ,
132
141
( fn_sig. abi , fn_abi) ,
133
142
& args,
134
143
with_caller_location,
@@ -146,8 +155,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
146
155
TailCall { ref func, ref args, fn_span : _ } => {
147
156
let old_frame_idx = self . frame_idx ( ) ;
148
157
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) ?;
151
160
152
161
// This is the "canonical" implementation of tails calls,
153
162
// 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> {
170
179
} ;
171
180
172
181
self . eval_fn_call (
173
- fn_val ,
182
+ callee ,
174
183
( fn_sig. abi , fn_abi) ,
175
184
& args,
176
185
with_caller_location,
@@ -507,22 +516,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
507
516
}
508
517
509
518
/// 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 (
512
521
& self ,
513
522
terminator : & mir:: Terminator < ' tcx > ,
514
523
func : & mir:: Operand < ' tcx > ,
515
524
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 > > {
526
526
let func = self . eval_operand ( func, None ) ?;
527
527
let args = self . eval_fn_call_arguments ( args) ?;
528
528
@@ -532,7 +532,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
532
532
let extra_args =
533
533
self . tcx . mk_type_list_from_iter ( extra_args. iter ( ) . map ( |arg| arg. layout ( ) . ty ) ) ;
534
534
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 ( ) {
536
536
ty:: FnPtr ( _sig) => {
537
537
let fn_ptr = self . read_pointer ( & func) ?;
538
538
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> {
551
551
}
552
552
} ;
553
553
554
- Ok ( ( fn_val , args, fn_sig, fn_abi, with_caller_location) )
554
+ Ok ( EvaluatedCalleeAndArgs { callee , args, fn_sig, fn_abi, with_caller_location } )
555
555
}
556
556
557
557
/// Call this function -- pushing the stack frame and initializing the arguments.
0 commit comments