@@ -67,30 +67,35 @@ pub fn priv_should_inline(
67
67
let config = db. function_declaration_inline_config (
68
68
function_id. function_with_body_id ( db) . base_semantic_function ( db) ,
69
69
) ?;
70
-
71
- Ok ( match db. optimization_config ( ) . inlining_strategy {
72
- InliningStrategy :: Default => match config {
73
- InlineConfiguration :: Never ( _) => false ,
74
- InlineConfiguration :: Should ( _) => true ,
75
- InlineConfiguration :: Always ( _) => true ,
76
- InlineConfiguration :: None => should_inline_lowered ( db, function_id) ?,
77
- } ,
78
- InliningStrategy :: Avoid => matches ! ( config, InlineConfiguration :: Always ( _) ) ,
70
+ Ok ( match ( db. optimization_config ( ) . inlining_strategy , config) {
71
+ ( _, InlineConfiguration :: Always ( _) ) => true ,
72
+ ( InliningStrategy :: Avoid , _) | ( _, InlineConfiguration :: Never ( _) ) => false ,
73
+ ( _, InlineConfiguration :: Should ( _) ) => true ,
74
+ ( InliningStrategy :: Default , InlineConfiguration :: None ) => {
75
+ /// The default threshold for inlining small functions. Decided according to sample
76
+ /// contracts profiling.
77
+ const DEFAULT_INLINE_SMALL_FUNCTIONS_THRESHOLD : usize = 24 ;
78
+ should_inline_lowered ( db, function_id, DEFAULT_INLINE_SMALL_FUNCTIONS_THRESHOLD ) ?
79
+ }
80
+ ( InliningStrategy :: InlineSmallFunctions ( threshold) , InlineConfiguration :: None ) => {
81
+ should_inline_lowered ( db, function_id, threshold) ?
82
+ }
79
83
} )
80
84
}
81
85
82
86
// A heuristic to decide if a function without an inline attribute should be inlined.
83
87
fn should_inline_lowered (
84
88
db : & dyn LoweringGroup ,
85
89
function_id : ConcreteFunctionWithBodyId ,
90
+ inline_small_functions_threshold : usize ,
86
91
) -> Maybe < bool > {
87
92
let lowered = db. inlined_function_with_body_lowered ( function_id) ?;
88
93
// The inline heuristics optimization flag only applies to non-trivial small functions.
89
94
// Functions which contains only a call or a literal are always inlined.
90
95
91
96
let weight_of_blocks = ApproxCasmInlineWeight :: new ( db, & lowered) . lowered_weight ( & lowered) ;
92
97
93
- if weight_of_blocks < inline_small_functions_threshold ( db ) . into_or_panic ( ) {
98
+ if weight_of_blocks < inline_small_functions_threshold. into_or_panic ( ) {
94
99
return Ok ( true ) ;
95
100
}
96
101
@@ -99,7 +104,7 @@ fn should_inline_lowered(
99
104
// Functions which contains only a call or a literal are always inlined.
100
105
let num_of_statements: usize =
101
106
lowered. blocks . iter ( ) . map ( |( _, block) | block. statements . len ( ) ) . sum ( ) ;
102
- if num_of_statements < inline_small_functions_threshold ( db ) {
107
+ if num_of_statements < inline_small_functions_threshold {
103
108
return Ok ( true ) ;
104
109
}
105
110
@@ -369,9 +374,3 @@ pub fn apply_inlining(
369
374
}
370
375
Ok ( ( ) )
371
376
}
372
-
373
- /// Returns the threshold, in number of lowering statements, below which a function is marked as
374
- /// `should_inline`.
375
- fn inline_small_functions_threshold ( db : & dyn LoweringGroup ) -> usize {
376
- db. optimization_config ( ) . inline_small_functions_threshold
377
- }
0 commit comments