@@ -331,7 +331,7 @@ fn fn_abi_of_fn_ptr<'tcx>(
331
331
) -> Result < & ' tcx FnAbi < ' tcx , Ty < ' tcx > > , & ' tcx FnAbiError < ' tcx > > {
332
332
let ( param_env, ( sig, extra_args) ) = query. into_parts ( ) ;
333
333
334
- let cx = LayoutCx { tcx, param_env } ;
334
+ let cx = LayoutCx :: new ( tcx, param_env) ;
335
335
fn_abi_new_uncached ( & cx, sig, extra_args, None , None , false )
336
336
}
337
337
@@ -347,7 +347,7 @@ fn fn_abi_of_instance<'tcx>(
347
347
instance. def . requires_caller_location ( tcx) . then ( || tcx. caller_location_ty ( ) ) ;
348
348
349
349
fn_abi_new_uncached (
350
- & LayoutCx { tcx, param_env } ,
350
+ & LayoutCx :: new ( tcx, param_env) ,
351
351
sig,
352
352
extra_args,
353
353
caller_location,
@@ -386,12 +386,14 @@ fn adjust_for_rust_scalar<'tcx>(
386
386
attrs. set ( ArgAttribute :: NonNull ) ;
387
387
}
388
388
389
+ let tcx = cx. tcx ( ) ;
390
+
389
391
if let Some ( pointee) = layout. pointee_info_at ( & cx, offset) {
390
392
let kind = if let Some ( kind) = pointee. safe {
391
393
Some ( kind)
392
394
} else if let Some ( pointee) = drop_target_pointee {
393
395
// The argument to `drop_in_place` is semantically equivalent to a mutable reference.
394
- Some ( PointerKind :: MutableRef { unpin : pointee. is_unpin ( cx . tcx , cx. param_env ( ) ) } )
396
+ Some ( PointerKind :: MutableRef { unpin : pointee. is_unpin ( tcx, cx. param_env ( ) ) } )
395
397
} else {
396
398
None
397
399
} ;
@@ -415,12 +417,12 @@ fn adjust_for_rust_scalar<'tcx>(
415
417
// The aliasing rules for `Box<T>` are still not decided, but currently we emit
416
418
// `noalias` for it. This can be turned off using an unstable flag.
417
419
// See https://github.com/rust-lang/unsafe-code-guidelines/issues/326
418
- let noalias_for_box = cx . tcx . sess . opts . unstable_opts . box_noalias ;
420
+ let noalias_for_box = tcx. sess . opts . unstable_opts . box_noalias ;
419
421
420
422
// LLVM prior to version 12 had known miscompiles in the presence of noalias attributes
421
423
// (see #54878), so it was conditionally disabled, but we don't support earlier
422
424
// versions at all anymore. We still support turning it off using -Zmutable-noalias.
423
- let noalias_mut_ref = cx . tcx . sess . opts . unstable_opts . mutable_noalias ;
425
+ let noalias_mut_ref = tcx. sess . opts . unstable_opts . mutable_noalias ;
424
426
425
427
// `&T` where `T` contains no `UnsafeCell<U>` is immutable, and can be marked as both
426
428
// `readonly` and `noalias`, as LLVM's definition of `noalias` is based solely on memory
@@ -458,6 +460,7 @@ fn fn_abi_sanity_check<'tcx>(
458
460
spec_abi : SpecAbi ,
459
461
arg : & ArgAbi < ' tcx , Ty < ' tcx > > ,
460
462
) {
463
+ let tcx = cx. tcx ( ) ;
461
464
match & arg. mode {
462
465
PassMode :: Ignore => { }
463
466
PassMode :: Direct ( _) => {
@@ -484,7 +487,7 @@ fn fn_abi_sanity_check<'tcx>(
484
487
// It needs to switch to something else before stabilization can happen.
485
488
// (See issue: https://github.com/rust-lang/rust/issues/117271)
486
489
assert ! (
487
- matches!( & * cx . tcx. sess. target. arch, "wasm32" | "wasm64" )
490
+ matches!( & * tcx. sess. target. arch, "wasm32" | "wasm64" )
488
491
|| matches!( spec_abi, SpecAbi :: PtxKernel | SpecAbi :: Unadjusted ) ,
489
492
"`PassMode::Direct` for aggregates only allowed for \" unadjusted\" and \" ptx-kernel\" functions and on wasm\n \
490
493
Problematic type: {:#?}",
@@ -516,7 +519,7 @@ fn fn_abi_sanity_check<'tcx>(
516
519
// With metadata. Must be unsized and not on the stack.
517
520
assert ! ( arg. layout. is_unsized( ) && !on_stack) ;
518
521
// Also, must not be `extern` type.
519
- let tail = cx . tcx . struct_tail_for_codegen ( arg. layout . ty , cx. param_env ( ) ) ;
522
+ let tail = tcx. struct_tail_for_codegen ( arg. layout . ty , cx. param_env ( ) ) ;
520
523
if matches ! ( tail. kind( ) , ty:: Foreign ( ..) ) {
521
524
// These types do not have metadata, so having `meta_attrs` is bogus.
522
525
// Conceptually, unsized arguments must be copied around, which requires dynamically
@@ -546,7 +549,8 @@ fn fn_abi_new_uncached<'tcx>(
546
549
// FIXME(eddyb) replace this with something typed, like an `enum`.
547
550
force_thin_self_ptr : bool ,
548
551
) -> Result < & ' tcx FnAbi < ' tcx , Ty < ' tcx > > , & ' tcx FnAbiError < ' tcx > > {
549
- let sig = cx. tcx . normalize_erasing_late_bound_regions ( cx. param_env , sig) ;
552
+ let tcx = cx. tcx ( ) ;
553
+ let sig = tcx. normalize_erasing_late_bound_regions ( cx. param_env , sig) ;
550
554
551
555
let conv = conv_from_spec_abi ( cx. tcx ( ) , sig. abi , sig. c_variadic ) ;
552
556
@@ -576,7 +580,7 @@ fn fn_abi_new_uncached<'tcx>(
576
580
} ;
577
581
578
582
let is_drop_in_place =
579
- fn_def_id. is_some_and ( |def_id| cx . tcx . is_lang_item ( def_id, LangItem :: DropInPlace ) ) ;
583
+ fn_def_id. is_some_and ( |def_id| tcx. is_lang_item ( def_id, LangItem :: DropInPlace ) ) ;
580
584
581
585
let arg_of = |ty : Ty < ' tcx > , arg_idx : Option < usize > | -> Result < _ , & ' tcx FnAbiError < ' tcx > > {
582
586
let span = tracing:: debug_span!( "arg_of" ) ;
@@ -588,8 +592,7 @@ fn fn_abi_new_uncached<'tcx>(
588
592
_ => bug ! ( "argument to drop_in_place is not a raw ptr: {:?}" , ty) ,
589
593
} ) ;
590
594
591
- let layout =
592
- cx. layout_of ( ty) . map_err ( |err| & * cx. tcx . arena . alloc ( FnAbiError :: Layout ( * err) ) ) ?;
595
+ let layout = cx. layout_of ( ty) . map_err ( |err| & * tcx. arena . alloc ( FnAbiError :: Layout ( * err) ) ) ?;
593
596
let layout = if force_thin_self_ptr && arg_idx == Some ( 0 ) {
594
597
// Don't pass the vtable, it's not an argument of the virtual fn.
595
598
// Instead, pass just the data pointer, but give it the type `*const/mut dyn Trait`
@@ -638,7 +641,7 @@ fn fn_abi_new_uncached<'tcx>(
638
641
fn_abi_adjust_for_abi ( cx, & mut fn_abi, sig. abi , fn_def_id) ?;
639
642
debug ! ( "fn_abi_new_uncached = {:?}" , fn_abi) ;
640
643
fn_abi_sanity_check ( cx, & fn_abi, sig. abi ) ;
641
- Ok ( cx . tcx . arena . alloc ( fn_abi) )
644
+ Ok ( tcx. arena . alloc ( fn_abi) )
642
645
}
643
646
644
647
#[ tracing:: instrument( level = "trace" , skip( cx) ) ]
@@ -670,17 +673,18 @@ fn fn_abi_adjust_for_abi<'tcx>(
670
673
return Ok ( ( ) ) ;
671
674
}
672
675
676
+ let tcx = cx. tcx ( ) ;
677
+
673
678
if abi == SpecAbi :: Rust || abi == SpecAbi :: RustCall || abi == SpecAbi :: RustIntrinsic {
674
679
// Look up the deduced parameter attributes for this function, if we have its def ID and
675
680
// we're optimizing in non-incremental mode. We'll tag its parameters with those attributes
676
681
// as appropriate.
677
- let deduced_param_attrs = if cx. tcx . sess . opts . optimize != OptLevel :: No
678
- && cx. tcx . sess . opts . incremental . is_none ( )
679
- {
680
- fn_def_id. map ( |fn_def_id| cx. tcx . deduced_param_attrs ( fn_def_id) ) . unwrap_or_default ( )
681
- } else {
682
- & [ ]
683
- } ;
682
+ let deduced_param_attrs =
683
+ if tcx. sess . opts . optimize != OptLevel :: No && tcx. sess . opts . incremental . is_none ( ) {
684
+ fn_def_id. map ( |fn_def_id| tcx. deduced_param_attrs ( fn_def_id) ) . unwrap_or_default ( )
685
+ } else {
686
+ & [ ]
687
+ } ;
684
688
685
689
let fixup = |arg : & mut ArgAbi < ' tcx , Ty < ' tcx > > , arg_idx : Option < usize > | {
686
690
if arg. is_ignore ( ) {
@@ -689,7 +693,7 @@ fn fn_abi_adjust_for_abi<'tcx>(
689
693
690
694
// Avoid returning floats in x87 registers on x86 as loading and storing from x87
691
695
// registers will quiet signalling NaNs.
692
- if cx . tcx . sess . target . arch == "x86"
696
+ if tcx. sess . target . arch == "x86"
693
697
&& arg_idx. is_none ( )
694
698
// Intrinsics themselves are not actual "real" functions, so theres no need to
695
699
// change their ABIs.
@@ -744,7 +748,7 @@ fn fn_abi_adjust_for_abi<'tcx>(
744
748
// that's how we connect up to LLVM and it's unstable
745
749
// anyway, we control all calls to it in libstd.
746
750
Abi :: Vector { .. }
747
- if abi != SpecAbi :: RustIntrinsic && cx . tcx . sess . target . simd_types_indirect =>
751
+ if abi != SpecAbi :: RustIntrinsic && tcx. sess . target . simd_types_indirect =>
748
752
{
749
753
arg. make_indirect ( ) ;
750
754
return ;
@@ -793,7 +797,7 @@ fn fn_abi_adjust_for_abi<'tcx>(
793
797
} else {
794
798
fn_abi
795
799
. adjust_for_foreign_abi ( cx, abi)
796
- . map_err ( |err| & * cx . tcx . arena . alloc ( FnAbiError :: AdjustForForeignAbi ( err) ) ) ?;
800
+ . map_err ( |err| & * tcx. arena . alloc ( FnAbiError :: AdjustForForeignAbi ( err) ) ) ?;
797
801
}
798
802
799
803
Ok ( ( ) )
0 commit comments