@@ -600,6 +600,7 @@ function rewrite_apply_exprargs!(ir::IRCode, todo::Vector{Pair{Int, Any}}, idx::
600600 argexprs:: Vector{Any} , atypes:: Vector{Any} , arginfos:: Vector{Any} ,
601601 arg_start:: Int , istate:: InliningState )
602602
603+ flag = ir. stmts[idx][:flag ]
603604 new_argexprs = Any[argexprs[arg_start]]
604605 new_atypes = Any[atypes[arg_start]]
605606 # loop over original arguments and flatten any known iterators
@@ -655,8 +656,9 @@ function rewrite_apply_exprargs!(ir::IRCode, todo::Vector{Pair{Int, Any}}, idx::
655656 info = call. info
656657 handled = false
657658 if isa (info, ConstCallInfo)
658- if maybe_handle_const_call! (ir, state1. id, new_stmt, info, new_sig,
659- call. rt, istate, false , todo)
659+ if ! is_stmt_noinline (flag) && maybe_handle_const_call! (
660+ ir, state1. id, new_stmt, info, new_sig,call. rt, istate, flag, false , todo)
661+
660662 handled = true
661663 else
662664 info = info. call
@@ -667,7 +669,7 @@ function rewrite_apply_exprargs!(ir::IRCode, todo::Vector{Pair{Int, Any}}, idx::
667669 MethodMatchInfo[info] : info. matches
668670 # See if we can inline this call to `iterate`
669671 analyze_single_call! (ir, todo, state1. id, new_stmt,
670- new_sig, call. rt, info, istate)
672+ new_sig, call. rt, info, istate, flag )
671673 end
672674 if i != length (thisarginfo. each)
673675 valT = getfield_tfunc (call. rt, Const (1 ))
@@ -716,16 +718,16 @@ function compileable_specialization(et::Union{EdgeTracker, Nothing}, result::Inf
716718 return mi
717719end
718720
719- function resolve_todo (todo:: InliningTodo , state:: InliningState )
720- spec = todo. spec:: DelayedInliningSpec
721+ function resolve_todo (todo:: InliningTodo , state:: InliningState , flag :: UInt8 )
722+ (; match) = todo. spec:: DelayedInliningSpec
721723
722724 # XXX : update_valid_age!(min_valid[1], max_valid[1], sv)
723725 isconst, src = false , nothing
724- if isa (spec . match, InferenceResult)
725- let inferred_src = spec . match. src
726+ if isa (match, InferenceResult)
727+ let inferred_src = match. src
726728 if isa (inferred_src, Const)
727729 if ! is_inlineable_constant (inferred_src. val)
728- return compileable_specialization (state. et, spec . match)
730+ return compileable_specialization (state. et, match)
729731 end
730732 isconst, src = true , quoted (inferred_src. val)
731733 else
@@ -753,12 +755,10 @@ function resolve_todo(todo::InliningTodo, state::InliningState)
753755 return ConstantCase (src)
754756 end
755757
756- if src != = nothing
757- src = state. policy (src)
758- end
758+ src = state. policy (src, flag, match)
759759
760760 if src === nothing
761- return compileable_specialization (et, spec . match)
761+ return compileable_specialization (et, match)
762762 end
763763
764764 if isa (src, IRCode)
@@ -769,17 +769,9 @@ function resolve_todo(todo::InliningTodo, state::InliningState)
769769 return InliningTodo (todo. mi, src)
770770end
771771
772- function resolve_todo (todo:: UnionSplit , state:: InliningState )
772+ function resolve_todo (todo:: UnionSplit , state:: InliningState , flag :: UInt8 )
773773 UnionSplit (todo. fully_covered, todo. atype,
774- Pair{Any,Any}[sig=> resolve_todo (item, state) for (sig, item) in todo. cases])
775- end
776-
777- function resolve_todo! (todo:: Vector{Pair{Int, Any}} , state:: InliningState )
778- for i = 1 : length (todo)
779- idx, item = todo[i]
780- todo[i] = idx=> resolve_todo (item, state)
781- end
782- todo
774+ Pair{Any,Any}[sig=> resolve_todo (item, state, flag) for (sig, item) in todo. cases])
783775end
784776
785777function validate_sparams (sparams:: SimpleVector )
@@ -790,7 +782,7 @@ function validate_sparams(sparams::SimpleVector)
790782end
791783
792784function analyze_method! (match:: MethodMatch , atypes:: Vector{Any} ,
793- state:: InliningState , @nospecialize (stmttyp))
785+ state:: InliningState , @nospecialize (stmttyp), flag :: UInt8 )
794786 method = match. method
795787 methsig = method. sig
796788
@@ -806,11 +798,9 @@ function analyze_method!(match::MethodMatch, atypes::Vector{Any},
806798 end
807799
808800 # Bail out if any static parameters are left as TypeVar
809- ok = true
810801 validate_sparams (match. sparams) || return nothing
811802
812-
813- if ! state. params. inlining
803+ if ! state. params. inlining || is_stmt_noinline (flag)
814804 return compileable_specialization (state. et, match)
815805 end
816806
@@ -824,7 +814,7 @@ function analyze_method!(match::MethodMatch, atypes::Vector{Any},
824814 # If we don't have caches here, delay resolving this MethodInstance
825815 # until the batch inlining step (or an external post-processing pass)
826816 state. mi_cache === nothing && return todo
827- return resolve_todo (todo, state)
817+ return resolve_todo (todo, state, flag )
828818end
829819
830820function InliningTodo (mi:: MethodInstance , ir:: IRCode )
@@ -1050,7 +1040,7 @@ is_builtin(s::Signature) =
10501040 s. ft ⊑ Builtin
10511041
10521042function inline_invoke! (ir:: IRCode , idx:: Int , sig:: Signature , (; match, result):: InvokeCallInfo ,
1053- state:: InliningState , todo:: Vector{Pair{Int, Any}} )
1043+ state:: InliningState , todo:: Vector{Pair{Int, Any}} , flag :: UInt8 )
10541044 stmt = ir. stmts[idx][:inst ]
10551045 calltype = ir. stmts[idx][:type ]
10561046
@@ -1064,17 +1054,17 @@ function inline_invoke!(ir::IRCode, idx::Int, sig::Signature, (; match, result):
10641054 atypes = atypes[4 : end ]
10651055 pushfirst! (atypes, atype0)
10661056
1067- if isa (result, InferenceResult)
1057+ if isa (result, InferenceResult) && ! is_stmt_noinline (flag)
10681058 item = InliningTodo (result, atypes, calltype)
10691059 validate_sparams (item. mi. sparam_vals) || return nothing
10701060 if argtypes_to_type (atypes) <: item.mi.def.sig
1071- state. mi_cache != = nothing && (item = resolve_todo (item, state))
1061+ state. mi_cache != = nothing && (item = resolve_todo (item, state, flag ))
10721062 handle_single_case! (ir, stmt, idx, item, true , todo)
10731063 return nothing
10741064 end
10751065 end
10761066
1077- result = analyze_method! (match, atypes, state, calltype)
1067+ result = analyze_method! (match, atypes, state, calltype, flag )
10781068 handle_single_case! (ir, stmt, idx, result, true , todo)
10791069 return nothing
10801070end
@@ -1169,7 +1159,7 @@ end
11691159
11701160function analyze_single_call! (ir:: IRCode , todo:: Vector{Pair{Int, Any}} , idx:: Int , @nospecialize (stmt),
11711161 sig:: Signature , @nospecialize (calltype), infos:: Vector{MethodMatchInfo} ,
1172- state:: InliningState )
1162+ state:: InliningState , flag :: UInt8 )
11731163 cases = Pair{Any, Any}[]
11741164 signature_union = Union{}
11751165 only_method = nothing # keep track of whether there is one matching method
@@ -1202,7 +1192,7 @@ function analyze_single_call!(ir::IRCode, todo::Vector{Pair{Int, Any}}, idx::Int
12021192 fully_covered = false
12031193 continue
12041194 end
1205- case = analyze_method! (match, sig. atypes, state, calltype)
1195+ case = analyze_method! (match, sig. atypes, state, calltype, flag )
12061196 if case === nothing
12071197 fully_covered = false
12081198 continue
@@ -1229,7 +1219,7 @@ function analyze_single_call!(ir::IRCode, todo::Vector{Pair{Int, Any}}, idx::Int
12291219 match = meth[1 ]
12301220 end
12311221 fully_covered = true
1232- case = analyze_method! (match, sig. atypes, state, calltype)
1222+ case = analyze_method! (match, sig. atypes, state, calltype, flag )
12331223 case === nothing && return
12341224 push! (cases, Pair {Any,Any} (match. spec_types, case))
12351225 end
@@ -1251,7 +1241,7 @@ end
12511241
12521242function maybe_handle_const_call! (ir:: IRCode , idx:: Int , stmt:: Expr ,
12531243 info:: ConstCallInfo , sig:: Signature , @nospecialize (calltype),
1254- state:: InliningState ,
1244+ state:: InliningState , flag :: UInt8 ,
12551245 isinvoke:: Bool , todo:: Vector{Pair{Int, Any}} )
12561246 # when multiple matches are found, bail out and later inliner will union-split this signature
12571247 # TODO effectively use multiple constant analysis results here
@@ -1263,7 +1253,7 @@ function maybe_handle_const_call!(ir::IRCode, idx::Int, stmt::Expr,
12631253 validate_sparams (item. mi. sparam_vals) || return true
12641254 mthd_sig = item. mi. def. sig
12651255 mistypes = item. mi. specTypes
1266- state. mi_cache != = nothing && (item = resolve_todo (item, state))
1256+ state. mi_cache != = nothing && (item = resolve_todo (item, state, flag ))
12671257 if sig. atype <: mthd_sig
12681258 handle_single_case! (ir, stmt, idx, item, isinvoke, todo)
12691259 return true
@@ -1301,6 +1291,8 @@ function assemble_inline_todo!(ir::IRCode, state::InliningState)
13011291 info = info. info
13021292 end
13031293
1294+ flag = ir. stmts[idx][:flag ]
1295+
13041296 # Inference determined this couldn't be analyzed. Don't question it.
13051297 if info === false
13061298 continue
@@ -1310,23 +1302,24 @@ function assemble_inline_todo!(ir::IRCode, state::InliningState)
13101302 # it'll have performed a specialized analysis for just this case. Use its
13111303 # result.
13121304 if isa (info, ConstCallInfo)
1313- if maybe_handle_const_call! (ir, idx, stmt, info, sig, calltype, state, sig. f === Core. invoke, todo)
1305+ if ! is_stmt_noinline (flag) && maybe_handle_const_call! (
1306+ ir, idx, stmt, info, sig, calltype, state, flag, sig. f === Core. invoke, todo)
13141307 continue
13151308 else
13161309 info = info. call
13171310 end
13181311 end
13191312
13201313 if isa (info, OpaqueClosureCallInfo)
1321- result = analyze_method! (info. match, sig. atypes, state, calltype)
1314+ result = analyze_method! (info. match, sig. atypes, state, calltype, flag )
13221315 handle_single_case! (ir, stmt, idx, result, false , todo)
13231316 continue
13241317 end
13251318
13261319 # Handle invoke
13271320 if sig. f === Core. invoke
13281321 if isa (info, InvokeCallInfo)
1329- inline_invoke! (ir, idx, sig, info, state, todo)
1322+ inline_invoke! (ir, idx, sig, info, state, todo, flag )
13301323 end
13311324 continue
13321325 end
@@ -1340,7 +1333,7 @@ function assemble_inline_todo!(ir::IRCode, state::InliningState)
13401333 continue
13411334 end
13421335
1343- analyze_single_call! (ir, todo, idx, stmt, sig, calltype, infos, state)
1336+ analyze_single_call! (ir, todo, idx, stmt, sig, calltype, infos, state, flag )
13441337 end
13451338 todo
13461339end
0 commit comments