5
5
//! purposes on a best-effort basis. We compute them here and store them into the crate metadata so
6
6
//! dependent crates can use them.
7
7
8
- use rustc_hir:: def_id:: LocalDefId ;
9
8
use rustc_index:: bit_set:: DenseBitSet ;
10
9
use rustc_middle:: mir:: visit:: { NonMutatingUseContext , PlaceContext , Visitor } ;
11
10
use 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 } ;
13
12
use rustc_session:: config:: OptLevel ;
14
13
15
14
/// 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 {
123
122
/// dependent crates can use them.
124
123
pub ( super ) fn deduced_param_attrs < ' tcx > (
125
124
tcx : TyCtxt < ' tcx > ,
126
- def_id : LocalDefId ,
125
+ instance : Instance < ' tcx > ,
127
126
) -> & ' tcx [ DeducedParamAttrs ] {
128
127
// This computation is unfortunately rather expensive, so don't do it unless we're optimizing.
129
128
// Also skip it in incremental mode.
@@ -138,7 +137,7 @@ pub(super) fn deduced_param_attrs<'tcx>(
138
137
139
138
// Codegen won't use this information for anything if all the function parameters are passed
140
139
// 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 ( ) ;
142
141
if matches ! ( fn_ty. kind( ) , ty:: FnDef ( ..) )
143
142
&& fn_ty
144
143
. fn_sig ( tcx)
@@ -151,13 +150,8 @@ pub(super) fn deduced_param_attrs<'tcx>(
151
150
return & [ ] ;
152
151
}
153
152
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) ;
161
155
let mut deduce_read_only = DeduceReadOnly :: new ( body. arg_count ) ;
162
156
deduce_read_only. visit_body ( body) ;
163
157
0 commit comments