@@ -331,7 +331,7 @@ fn fn_abi_of_fn_ptr<'tcx>(
331331) -> Result < & ' tcx FnAbi < ' tcx , Ty < ' tcx > > , & ' tcx FnAbiError < ' tcx > > {
332332 let ( param_env, ( sig, extra_args) ) = query. into_parts ( ) ;
333333
334- let cx = LayoutCx { tcx, param_env } ;
334+ let cx = LayoutCx :: new ( tcx, param_env) ;
335335 fn_abi_new_uncached ( & cx, sig, extra_args, None , None , false )
336336}
337337
@@ -347,7 +347,7 @@ fn fn_abi_of_instance<'tcx>(
347347 instance. def . requires_caller_location ( tcx) . then ( || tcx. caller_location_ty ( ) ) ;
348348
349349 fn_abi_new_uncached (
350- & LayoutCx { tcx, param_env } ,
350+ & LayoutCx :: new ( tcx, param_env) ,
351351 sig,
352352 extra_args,
353353 caller_location,
@@ -386,12 +386,14 @@ fn adjust_for_rust_scalar<'tcx>(
386386 attrs. set ( ArgAttribute :: NonNull ) ;
387387 }
388388
389+ let tcx = cx. tcx ( ) ;
390+
389391 if let Some ( pointee) = layout. pointee_info_at ( & cx, offset) {
390392 let kind = if let Some ( kind) = pointee. safe {
391393 Some ( kind)
392394 } else if let Some ( pointee) = drop_target_pointee {
393395 // 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 ( ) ) } )
395397 } else {
396398 None
397399 } ;
@@ -415,12 +417,12 @@ fn adjust_for_rust_scalar<'tcx>(
415417 // The aliasing rules for `Box<T>` are still not decided, but currently we emit
416418 // `noalias` for it. This can be turned off using an unstable flag.
417419 // 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 ;
419421
420422 // LLVM prior to version 12 had known miscompiles in the presence of noalias attributes
421423 // (see #54878), so it was conditionally disabled, but we don't support earlier
422424 // 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 ;
424426
425427 // `&T` where `T` contains no `UnsafeCell<U>` is immutable, and can be marked as both
426428 // `readonly` and `noalias`, as LLVM's definition of `noalias` is based solely on memory
@@ -458,6 +460,7 @@ fn fn_abi_sanity_check<'tcx>(
458460 spec_abi : SpecAbi ,
459461 arg : & ArgAbi < ' tcx , Ty < ' tcx > > ,
460462 ) {
463+ let tcx = cx. tcx ( ) ;
461464 match & arg. mode {
462465 PassMode :: Ignore => { }
463466 PassMode :: Direct ( _) => {
@@ -484,7 +487,7 @@ fn fn_abi_sanity_check<'tcx>(
484487 // It needs to switch to something else before stabilization can happen.
485488 // (See issue: https://github.com/rust-lang/rust/issues/117271)
486489 assert ! (
487- matches!( & * cx . tcx. sess. target. arch, "wasm32" | "wasm64" )
490+ matches!( & * tcx. sess. target. arch, "wasm32" | "wasm64" )
488491 || matches!( spec_abi, SpecAbi :: PtxKernel | SpecAbi :: Unadjusted ) ,
489492 "`PassMode::Direct` for aggregates only allowed for \" unadjusted\" and \" ptx-kernel\" functions and on wasm\n \
490493 Problematic type: {:#?}",
@@ -516,7 +519,7 @@ fn fn_abi_sanity_check<'tcx>(
516519 // With metadata. Must be unsized and not on the stack.
517520 assert ! ( arg. layout. is_unsized( ) && !on_stack) ;
518521 // 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 ( ) ) ;
520523 if matches ! ( tail. kind( ) , ty:: Foreign ( ..) ) {
521524 // These types do not have metadata, so having `meta_attrs` is bogus.
522525 // Conceptually, unsized arguments must be copied around, which requires dynamically
@@ -546,7 +549,8 @@ fn fn_abi_new_uncached<'tcx>(
546549 // FIXME(eddyb) replace this with something typed, like an `enum`.
547550 force_thin_self_ptr : bool ,
548551) -> 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) ;
550554
551555 let conv = conv_from_spec_abi ( cx. tcx ( ) , sig. abi , sig. c_variadic ) ;
552556
@@ -576,7 +580,7 @@ fn fn_abi_new_uncached<'tcx>(
576580 } ;
577581
578582 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 ) ) ;
580584
581585 let arg_of = |ty : Ty < ' tcx > , arg_idx : Option < usize > | -> Result < _ , & ' tcx FnAbiError < ' tcx > > {
582586 let span = tracing:: debug_span!( "arg_of" ) ;
@@ -588,8 +592,7 @@ fn fn_abi_new_uncached<'tcx>(
588592 _ => bug ! ( "argument to drop_in_place is not a raw ptr: {:?}" , ty) ,
589593 } ) ;
590594
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) ) ) ?;
593596 let layout = if force_thin_self_ptr && arg_idx == Some ( 0 ) {
594597 // Don't pass the vtable, it's not an argument of the virtual fn.
595598 // 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>(
638641 fn_abi_adjust_for_abi ( cx, & mut fn_abi, sig. abi , fn_def_id) ?;
639642 debug ! ( "fn_abi_new_uncached = {:?}" , fn_abi) ;
640643 fn_abi_sanity_check ( cx, & fn_abi, sig. abi ) ;
641- Ok ( cx . tcx . arena . alloc ( fn_abi) )
644+ Ok ( tcx. arena . alloc ( fn_abi) )
642645}
643646
644647#[ tracing:: instrument( level = "trace" , skip( cx) ) ]
@@ -670,17 +673,18 @@ fn fn_abi_adjust_for_abi<'tcx>(
670673 return Ok ( ( ) ) ;
671674 }
672675
676+ let tcx = cx. tcx ( ) ;
677+
673678 if abi == SpecAbi :: Rust || abi == SpecAbi :: RustCall || abi == SpecAbi :: RustIntrinsic {
674679 // Look up the deduced parameter attributes for this function, if we have its def ID and
675680 // we're optimizing in non-incremental mode. We'll tag its parameters with those attributes
676681 // 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+ } ;
684688
685689 let fixup = |arg : & mut ArgAbi < ' tcx , Ty < ' tcx > > , arg_idx : Option < usize > | {
686690 if arg. is_ignore ( ) {
@@ -689,7 +693,7 @@ fn fn_abi_adjust_for_abi<'tcx>(
689693
690694 // Avoid returning floats in x87 registers on x86 as loading and storing from x87
691695 // registers will quiet signalling NaNs.
692- if cx . tcx . sess . target . arch == "x86"
696+ if tcx. sess . target . arch == "x86"
693697 && arg_idx. is_none ( )
694698 // Intrinsics themselves are not actual "real" functions, so theres no need to
695699 // change their ABIs.
@@ -744,7 +748,7 @@ fn fn_abi_adjust_for_abi<'tcx>(
744748 // that's how we connect up to LLVM and it's unstable
745749 // anyway, we control all calls to it in libstd.
746750 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 =>
748752 {
749753 arg. make_indirect ( ) ;
750754 return ;
@@ -793,7 +797,7 @@ fn fn_abi_adjust_for_abi<'tcx>(
793797 } else {
794798 fn_abi
795799 . 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) ) ) ?;
797801 }
798802
799803 Ok ( ( ) )
0 commit comments