55//! purposes on a best-effort basis. We compute them here and store them into the crate metadata so
66//! dependent crates can use them.
77
8- use rustc_hir:: def_id:: LocalDefId ;
98use rustc_index:: bit_set:: DenseBitSet ;
109use rustc_middle:: mir:: visit:: { NonMutatingUseContext , PlaceContext , Visitor } ;
1110use rustc_middle:: mir:: { Body , Location , Operand , Place , RETURN_PLACE , Terminator , TerminatorKind } ;
12- use rustc_middle:: ty:: { self , DeducedParamAttrs , Ty , TyCtxt } ;
11+ use rustc_middle:: ty:: { self , DeducedParamAttrs , Instance , Ty , TyCtxt } ;
1312use rustc_session:: config:: OptLevel ;
1413
1514/// A visitor that determines which arguments have been mutated. We can't use the mutability field
@@ -123,7 +122,7 @@ fn type_will_always_be_passed_directly(ty: Ty<'_>) -> bool {
123122/// dependent crates can use them.
124123pub ( super ) fn deduced_param_attrs < ' tcx > (
125124 tcx : TyCtxt < ' tcx > ,
126- def_id : LocalDefId ,
125+ instance : Instance < ' tcx > ,
127126) -> & ' tcx [ DeducedParamAttrs ] {
128127 // This computation is unfortunately rather expensive, so don't do it unless we're optimizing.
129128 // Also skip it in incremental mode.
@@ -138,7 +137,7 @@ pub(super) fn deduced_param_attrs<'tcx>(
138137
139138 // Codegen won't use this information for anything if all the function parameters are passed
140139 // directly. Detect that and bail, for compilation speed.
141- let fn_ty = tcx. type_of ( def_id) . instantiate_identity ( ) ;
140+ let fn_ty = tcx. type_of ( instance . def_id ( ) ) . instantiate_identity ( ) ;
142141 if matches ! ( fn_ty. kind( ) , ty:: FnDef ( ..) )
143142 && fn_ty
144143 . fn_sig ( tcx)
@@ -151,13 +150,8 @@ pub(super) fn deduced_param_attrs<'tcx>(
151150 return & [ ] ;
152151 }
153152
154- // Don't deduce any attributes for functions that have no MIR.
155- if !tcx. is_mir_available ( def_id) {
156- return & [ ] ;
157- }
158-
159- // Grab the optimized MIR. Analyze it to determine which arguments have been mutated.
160- let body: & Body < ' tcx > = tcx. optimized_mir ( def_id) ;
153+ // Grab the codegen MIR. Analyze it to determine which arguments have been mutated.
154+ let body: & Body < ' tcx > = tcx. build_codegen_mir ( instance) ;
161155 let mut deduce_read_only = DeduceReadOnly :: new ( body. arg_count ) ;
162156 deduce_read_only. visit_body ( body) ;
163157
0 commit comments