@@ -309,15 +309,12 @@ fn fn_abi_of_fn_ptr<'tcx>(
309
309
query : ty:: PseudoCanonicalInput < ' tcx , ( ty:: PolyFnSig < ' tcx > , & ' tcx ty:: List < Ty < ' tcx > > ) > ,
310
310
) -> Result < & ' tcx FnAbi < ' tcx , Ty < ' tcx > > , & ' tcx FnAbiError < ' tcx > > {
311
311
let ty:: PseudoCanonicalInput { typing_env, value : ( sig, extra_args) } = query;
312
-
313
- let cx = LayoutCx :: new ( tcx, typing_env) ;
314
312
fn_abi_new_uncached (
315
- & cx,
313
+ tcx,
314
+ & LayoutCx :: new ( tcx, typing_env) ,
316
315
tcx. instantiate_bound_regions_with_erased ( sig) ,
317
316
extra_args,
318
317
None ,
319
- None ,
320
- false ,
321
318
)
322
319
}
323
320
@@ -326,19 +323,12 @@ fn fn_abi_of_instance<'tcx>(
326
323
query : ty:: PseudoCanonicalInput < ' tcx , ( ty:: Instance < ' tcx > , & ' tcx ty:: List < Ty < ' tcx > > ) > ,
327
324
) -> Result < & ' tcx FnAbi < ' tcx , Ty < ' tcx > > , & ' tcx FnAbiError < ' tcx > > {
328
325
let ty:: PseudoCanonicalInput { typing_env, value : ( instance, extra_args) } = query;
329
-
330
- let sig = fn_sig_for_fn_abi ( tcx, instance, typing_env) ;
331
-
332
- let caller_location =
333
- instance. def . requires_caller_location ( tcx) . then ( || tcx. caller_location_ty ( ) ) ;
334
-
335
326
fn_abi_new_uncached (
327
+ tcx,
336
328
& LayoutCx :: new ( tcx, typing_env) ,
337
- sig ,
329
+ fn_sig_for_fn_abi ( tcx , instance , typing_env ) ,
338
330
extra_args,
339
- caller_location,
340
- Some ( instance. def_id ( ) ) ,
341
- matches ! ( instance. def, ty:: InstanceKind :: Virtual ( ..) ) ,
331
+ Some ( instance) ,
342
332
)
343
333
}
344
334
@@ -547,18 +537,24 @@ fn fn_abi_sanity_check<'tcx>(
547
537
fn_arg_sanity_check ( cx, fn_abi, spec_abi, & fn_abi. ret ) ;
548
538
}
549
539
550
- // FIXME(eddyb) perhaps group the signature/type-containing (or all of them?)
551
- // arguments of this method, into a separate `struct`.
552
- #[ tracing:: instrument( level = "debug" , skip( cx, caller_location, fn_def_id, force_thin_self_ptr) ) ]
540
+ #[ tracing:: instrument( level = "debug" , skip( tcx, cx, instance) ) ]
553
541
fn fn_abi_new_uncached < ' tcx > (
542
+ tcx : TyCtxt < ' tcx > ,
554
543
cx : & LayoutCx < ' tcx > ,
555
544
sig : ty:: FnSig < ' tcx > ,
556
545
extra_args : & [ Ty < ' tcx > ] ,
557
- caller_location : Option < Ty < ' tcx > > ,
558
- fn_def_id : Option < DefId > ,
559
- // FIXME(eddyb) replace this with something typed, like an `enum`.
560
- force_thin_self_ptr : bool ,
546
+ instance : Option < ty:: Instance < ' tcx > > ,
561
547
) -> Result < & ' tcx FnAbi < ' tcx , Ty < ' tcx > > , & ' tcx FnAbiError < ' tcx > > {
548
+ // FIXME(eddyb) replace this with something typed, like an `enum`.
549
+ let ( caller_location, fn_def_id, is_virtual_call) = if let Some ( instance) = instance {
550
+ (
551
+ instance. def . requires_caller_location ( tcx) . then ( || tcx. caller_location_ty ( ) ) ,
552
+ Some ( instance. def_id ( ) ) ,
553
+ matches ! ( instance. def, ty:: InstanceKind :: Virtual ( ..) ) ,
554
+ )
555
+ } else {
556
+ ( None , None , false )
557
+ } ;
562
558
let tcx = cx. tcx ( ) ;
563
559
let sig = tcx. normalize_erasing_regions ( cx. typing_env , sig) ;
564
560
@@ -603,7 +599,7 @@ fn fn_abi_new_uncached<'tcx>(
603
599
} ) ;
604
600
605
601
let layout = cx. layout_of ( ty) . map_err ( |err| & * tcx. arena . alloc ( FnAbiError :: Layout ( * err) ) ) ?;
606
- let layout = if force_thin_self_ptr && arg_idx == Some ( 0 ) {
602
+ let layout = if is_virtual_call && arg_idx == Some ( 0 ) {
607
603
// Don't pass the vtable, it's not an argument of the virtual fn.
608
604
// Instead, pass just the data pointer, but give it the type `*const/mut dyn Trait`
609
605
// or `&/&mut dyn Trait` because this is special-cased elsewhere in codegen
@@ -648,7 +644,15 @@ fn fn_abi_new_uncached<'tcx>(
648
644
conv,
649
645
can_unwind : fn_can_unwind ( cx. tcx ( ) , fn_def_id, sig. abi ) ,
650
646
} ;
651
- fn_abi_adjust_for_abi ( cx, & mut fn_abi, sig. abi , fn_def_id) ;
647
+ fn_abi_adjust_for_abi (
648
+ cx,
649
+ & mut fn_abi,
650
+ sig. abi ,
651
+ // If this is a virtual call, we cannot pass the `fn_def_id`, as it might call other
652
+ // functions from vtable. Internally, `deduced_param_attrs` attempts to infer attributes by
653
+ // visit the function body.
654
+ fn_def_id. filter ( |_| !is_virtual_call) ,
655
+ ) ;
652
656
debug ! ( "fn_abi_new_uncached = {:?}" , fn_abi) ;
653
657
fn_abi_sanity_check ( cx, & fn_abi, sig. abi ) ;
654
658
Ok ( tcx. arena . alloc ( fn_abi) )
0 commit comments