@@ -45,15 +45,20 @@ impl<'tcx> MirPass<'tcx> for Inline {
45
45
// based function.
46
46
debug ! ( "function inlining is disabled when compiling with `instrument_coverage`" ) ;
47
47
} else {
48
- Inliner { tcx, codegen_fn_attrs : tcx. codegen_fn_attrs ( body. source . def_id ( ) ) }
49
- . run_pass ( body) ;
48
+ Inliner {
49
+ tcx,
50
+ param_env : tcx. param_env_reveal_all_normalized ( body. source . def_id ( ) ) ,
51
+ codegen_fn_attrs : tcx. codegen_fn_attrs ( body. source . def_id ( ) ) ,
52
+ }
53
+ . run_pass ( body) ;
50
54
}
51
55
}
52
56
}
53
57
}
54
58
55
59
struct Inliner < ' tcx > {
56
60
tcx : TyCtxt < ' tcx > ,
61
+ param_env : ParamEnv < ' tcx > ,
57
62
codegen_fn_attrs : & ' tcx CodegenFnAttrs ,
58
63
}
59
64
@@ -75,17 +80,13 @@ impl Inliner<'tcx> {
75
80
76
81
let def_id = caller_body. source . def_id ( ) ;
77
82
78
- let param_env = self . tcx . param_env_reveal_all_normalized ( def_id) ;
79
-
80
83
// Only do inlining into fn bodies.
81
84
let self_hir_id = self . tcx . hir ( ) . local_def_id_to_hir_id ( def_id. expect_local ( ) ) ;
82
85
if self . tcx . hir ( ) . body_owner_kind ( self_hir_id) . is_fn_or_closure ( )
83
86
&& caller_body. source . promoted . is_none ( )
84
87
{
85
88
for ( bb, bb_data) in caller_body. basic_blocks ( ) . iter_enumerated ( ) {
86
- if let Some ( callsite) =
87
- self . get_valid_function_call ( bb, bb_data, caller_body, param_env)
88
- {
89
+ if let Some ( callsite) = self . get_valid_function_call ( bb, bb_data, caller_body) {
89
90
callsites. push_back ( callsite) ;
90
91
}
91
92
}
@@ -131,7 +132,7 @@ impl Inliner<'tcx> {
131
132
let callee_body = if self . consider_optimizing ( callsite, callee_body) {
132
133
self . tcx . subst_and_normalize_erasing_regions (
133
134
& callsite. substs ,
134
- param_env,
135
+ self . param_env ,
135
136
callee_body,
136
137
)
137
138
} else {
@@ -159,7 +160,7 @@ impl Inliner<'tcx> {
159
160
// Add callsites from inlined function
160
161
for ( bb, bb_data) in caller_body. basic_blocks ( ) . iter_enumerated ( ) . skip ( start) {
161
162
if let Some ( new_callsite) =
162
- self . get_valid_function_call ( bb, bb_data, caller_body, param_env )
163
+ self . get_valid_function_call ( bb, bb_data, caller_body)
163
164
{
164
165
// Don't inline the same function multiple times.
165
166
if callsite. callee != new_callsite. callee {
@@ -190,7 +191,6 @@ impl Inliner<'tcx> {
190
191
bb : BasicBlock ,
191
192
bb_data : & BasicBlockData < ' tcx > ,
192
193
caller_body : & Body < ' tcx > ,
193
- param_env : ParamEnv < ' tcx > ,
194
194
) -> Option < CallSite < ' tcx > > {
195
195
// Don't inline calls that are in cleanup blocks.
196
196
if bb_data. is_cleanup {
@@ -201,8 +201,9 @@ impl Inliner<'tcx> {
201
201
let terminator = bb_data. terminator ( ) ;
202
202
if let TerminatorKind :: Call { func : ref op, .. } = terminator. kind {
203
203
if let ty:: FnDef ( callee_def_id, substs) = * op. ty ( caller_body, self . tcx ) . kind ( ) {
204
- let instance =
205
- Instance :: resolve ( self . tcx , param_env, callee_def_id, substs) . ok ( ) . flatten ( ) ?;
204
+ let instance = Instance :: resolve ( self . tcx , self . param_env , callee_def_id, substs)
205
+ . ok ( )
206
+ . flatten ( ) ?;
206
207
207
208
if let InstanceDef :: Virtual ( ..) = instance. def {
208
209
return None ;
@@ -300,9 +301,6 @@ impl Inliner<'tcx> {
300
301
debug ! ( " final inline threshold = {}" , threshold) ;
301
302
302
303
// FIXME: Give a bonus to functions with only a single caller
303
-
304
- let param_env = tcx. param_env ( callee_body. source . def_id ( ) ) ;
305
-
306
304
let mut first_block = true ;
307
305
let mut cost = 0 ;
308
306
@@ -335,7 +333,7 @@ impl Inliner<'tcx> {
335
333
// If the place doesn't actually need dropping, treat it like
336
334
// a regular goto.
337
335
let ty = place. ty ( callee_body, tcx) . subst ( tcx, callsite. substs ) . ty ;
338
- if ty. needs_drop ( tcx, param_env) {
336
+ if ty. needs_drop ( tcx, self . param_env ) {
339
337
cost += CALL_PENALTY ;
340
338
if let Some ( unwind) = unwind {
341
339
cost += LANDINGPAD_PENALTY ;
@@ -400,7 +398,7 @@ impl Inliner<'tcx> {
400
398
let ty = v. ty . subst ( tcx, callsite. substs ) ;
401
399
// Cost of the var is the size in machine-words, if we know
402
400
// it.
403
- if let Some ( size) = type_size_of ( tcx, param_env, ty) {
401
+ if let Some ( size) = type_size_of ( tcx, self . param_env , ty) {
404
402
cost += ( size / ptr_size) as usize ;
405
403
} else {
406
404
cost += UNKNOWN_SIZE_COST ;
0 commit comments