@@ -309,15 +309,11 @@ 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
+ & LayoutCx :: new ( tcx , typing_env ) ,
316
314
tcx. instantiate_bound_regions_with_erased ( sig) ,
317
315
extra_args,
318
316
None ,
319
- None ,
320
- false ,
321
317
)
322
318
}
323
319
@@ -326,19 +322,11 @@ fn fn_abi_of_instance<'tcx>(
326
322
query : ty:: PseudoCanonicalInput < ' tcx , ( ty:: Instance < ' tcx > , & ' tcx ty:: List < Ty < ' tcx > > ) > ,
327
323
) -> Result < & ' tcx FnAbi < ' tcx , Ty < ' tcx > > , & ' tcx FnAbiError < ' tcx > > {
328
324
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
325
fn_abi_new_uncached (
336
326
& LayoutCx :: new ( tcx, typing_env) ,
337
- sig ,
327
+ fn_sig_for_fn_abi ( tcx , instance , typing_env ) ,
338
328
extra_args,
339
- caller_location,
340
- Some ( instance. def_id ( ) ) ,
341
- matches ! ( instance. def, ty:: InstanceKind :: Virtual ( ..) ) ,
329
+ Some ( instance) ,
342
330
)
343
331
}
344
332
@@ -547,19 +535,23 @@ fn fn_abi_sanity_check<'tcx>(
547
535
fn_arg_sanity_check ( cx, fn_abi, spec_abi, & fn_abi. ret ) ;
548
536
}
549
537
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) ) ]
538
+ #[ tracing:: instrument( level = "debug" , skip( cx, instance) ) ]
553
539
fn fn_abi_new_uncached < ' tcx > (
554
540
cx : & LayoutCx < ' tcx > ,
555
541
sig : ty:: FnSig < ' tcx > ,
556
542
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 ,
543
+ instance : Option < ty:: Instance < ' tcx > > ,
561
544
) -> Result < & ' tcx FnAbi < ' tcx , Ty < ' tcx > > , & ' tcx FnAbiError < ' tcx > > {
562
545
let tcx = cx. tcx ( ) ;
546
+ let ( caller_location, fn_def_id, is_virtual_call) = if let Some ( instance) = instance {
547
+ (
548
+ instance. def . requires_caller_location ( tcx) . then ( || tcx. caller_location_ty ( ) ) ,
549
+ Some ( instance. def_id ( ) ) ,
550
+ matches ! ( instance. def, ty:: InstanceKind :: Virtual ( ..) ) ,
551
+ )
552
+ } else {
553
+ ( None , None , false )
554
+ } ;
563
555
let sig = tcx. normalize_erasing_regions ( cx. typing_env , sig) ;
564
556
565
557
let conv = conv_from_spec_abi ( cx. tcx ( ) , sig. abi , sig. c_variadic ) ;
@@ -568,16 +560,11 @@ fn fn_abi_new_uncached<'tcx>(
568
560
let extra_args = if sig. abi == ExternAbi :: RustCall {
569
561
assert ! ( !sig. c_variadic && extra_args. is_empty( ) ) ;
570
562
571
- if let Some ( input) = sig. inputs ( ) . last ( ) {
572
- if let ty:: Tuple ( tupled_arguments) = input. kind ( ) {
573
- inputs = & sig. inputs ( ) [ 0 ..sig. inputs ( ) . len ( ) - 1 ] ;
574
- tupled_arguments
575
- } else {
576
- bug ! (
577
- "argument to function with \" rust-call\" ABI \
578
- is not a tuple"
579
- ) ;
580
- }
563
+ if let Some ( input) = sig. inputs ( ) . last ( )
564
+ && let ty:: Tuple ( tupled_arguments) = input. kind ( )
565
+ {
566
+ inputs = & sig. inputs ( ) [ 0 ..sig. inputs ( ) . len ( ) - 1 ] ;
567
+ tupled_arguments
581
568
} else {
582
569
bug ! (
583
570
"argument to function with \" rust-call\" ABI \
@@ -603,7 +590,7 @@ fn fn_abi_new_uncached<'tcx>(
603
590
} ) ;
604
591
605
592
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 ) {
593
+ let layout = if is_virtual_call && arg_idx == Some ( 0 ) {
607
594
// Don't pass the vtable, it's not an argument of the virtual fn.
608
595
// Instead, pass just the data pointer, but give it the type `*const/mut dyn Trait`
609
596
// or `&/&mut dyn Trait` because this is special-cased elsewhere in codegen
@@ -648,7 +635,15 @@ fn fn_abi_new_uncached<'tcx>(
648
635
conv,
649
636
can_unwind : fn_can_unwind ( cx. tcx ( ) , fn_def_id, sig. abi ) ,
650
637
} ;
651
- fn_abi_adjust_for_abi ( cx, & mut fn_abi, sig. abi , fn_def_id) ;
638
+ fn_abi_adjust_for_abi (
639
+ cx,
640
+ & mut fn_abi,
641
+ sig. abi ,
642
+ // If this is a virtual call, we cannot pass the `fn_def_id`, as it might call other
643
+ // functions from vtable. Internally, `deduced_param_attrs` attempts to infer attributes by
644
+ // visit the function body.
645
+ fn_def_id. filter ( |_| !is_virtual_call) ,
646
+ ) ;
652
647
debug ! ( "fn_abi_new_uncached = {:?}" , fn_abi) ;
653
648
fn_abi_sanity_check ( cx, & fn_abi, sig. abi ) ;
654
649
Ok ( tcx. arena . alloc ( fn_abi) )
0 commit comments