@@ -67,30 +67,35 @@ pub fn priv_should_inline(
6767 let config = db. function_declaration_inline_config (
6868 function_id. function_with_body_id ( db) . base_semantic_function ( db) ,
6969 ) ?;
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+ }
7983 } )
8084}
8185
8286// A heuristic to decide if a function without an inline attribute should be inlined.
8387fn should_inline_lowered (
8488 db : & dyn LoweringGroup ,
8589 function_id : ConcreteFunctionWithBodyId ,
90+ inline_small_functions_threshold : usize ,
8691) -> Maybe < bool > {
8792 let lowered = db. inlined_function_with_body_lowered ( function_id) ?;
8893 // The inline heuristics optimization flag only applies to non-trivial small functions.
8994 // Functions which contains only a call or a literal are always inlined.
9095
9196 let weight_of_blocks = ApproxCasmInlineWeight :: new ( db, & lowered) . lowered_weight ( & lowered) ;
9297
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 ( ) {
9499 return Ok ( true ) ;
95100 }
96101
@@ -99,7 +104,7 @@ fn should_inline_lowered(
99104 // Functions which contains only a call or a literal are always inlined.
100105 let num_of_statements: usize =
101106 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 {
103108 return Ok ( true ) ;
104109 }
105110
@@ -369,9 +374,3 @@ pub fn apply_inlining(
369374 }
370375 Ok ( ( ) )
371376}
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