@@ -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 , info:: 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,7 +1054,7 @@ function inline_invoke!(ir::IRCode, idx::Int, sig::Signature, info::InvokeCallIn
10641054 atypes = atypes[4 : end ]
10651055 pushfirst! (atypes, atype0)
10661056
1067- result = analyze_method! (info. match, atypes, state, calltype)
1057+ result = analyze_method! (info. match, atypes, state, calltype, flag )
10681058 handle_single_case! (ir, stmt, idx, result, true , todo)
10691059 return nothing
10701060end
@@ -1159,7 +1149,7 @@ end
11591149
11601150function analyze_single_call! (ir:: IRCode , todo:: Vector{Pair{Int, Any}} , idx:: Int , @nospecialize (stmt),
11611151 sig:: Signature , @nospecialize (calltype), infos:: Vector{MethodMatchInfo} ,
1162- state:: InliningState )
1152+ state:: InliningState , flag :: UInt8 )
11631153 cases = Pair{Any, Any}[]
11641154 signature_union = Union{}
11651155 only_method = nothing # keep track of whether there is one matching method
@@ -1192,7 +1182,7 @@ function analyze_single_call!(ir::IRCode, todo::Vector{Pair{Int, Any}}, idx::Int
11921182 fully_covered = false
11931183 continue
11941184 end
1195- case = analyze_method! (match, sig. atypes, state, calltype)
1185+ case = analyze_method! (match, sig. atypes, state, calltype, flag )
11961186 if case === nothing
11971187 fully_covered = false
11981188 continue
@@ -1219,7 +1209,7 @@ function analyze_single_call!(ir::IRCode, todo::Vector{Pair{Int, Any}}, idx::Int
12191209 match = meth[1 ]
12201210 end
12211211 fully_covered = true
1222- case = analyze_method! (match, sig. atypes, state, calltype)
1212+ case = analyze_method! (match, sig. atypes, state, calltype, flag )
12231213 case === nothing && return
12241214 push! (cases, Pair {Any,Any} (match. spec_types, case))
12251215 end
@@ -1241,7 +1231,7 @@ end
12411231
12421232function maybe_handle_const_call! (ir:: IRCode , idx:: Int , stmt:: Expr ,
12431233 info:: ConstCallInfo , sig:: Signature , @nospecialize (calltype),
1244- state:: InliningState ,
1234+ state:: InliningState , flag :: UInt8 ,
12451235 isinvoke:: Bool , todo:: Vector{Pair{Int, Any}} )
12461236 # when multiple matches are found, bail out and later inliner will union-split this signature
12471237 # TODO effectively use multiple constant analysis results here
@@ -1253,7 +1243,7 @@ function maybe_handle_const_call!(ir::IRCode, idx::Int, stmt::Expr,
12531243 validate_sparams (item. mi. sparam_vals) || return true
12541244 mthd_sig = item. mi. def. sig
12551245 mistypes = item. mi. specTypes
1256- state. mi_cache != = nothing && (item = resolve_todo (item, state))
1246+ state. mi_cache != = nothing && (item = resolve_todo (item, state, flag ))
12571247 if sig. atype <: mthd_sig
12581248 handle_single_case! (ir, stmt, idx, item, isinvoke, todo)
12591249 return true
@@ -1291,6 +1281,8 @@ function assemble_inline_todo!(ir::IRCode, state::InliningState)
12911281 info = info. info
12921282 end
12931283
1284+ flag = ir. stmts[idx][:flag ]
1285+
12941286 # Inference determined this couldn't be analyzed. Don't question it.
12951287 if info === false
12961288 continue
@@ -1300,23 +1292,24 @@ function assemble_inline_todo!(ir::IRCode, state::InliningState)
13001292 # it'll have performed a specialized analysis for just this case. Use its
13011293 # result.
13021294 if isa (info, ConstCallInfo)
1303- if maybe_handle_const_call! (ir, idx, stmt, info, sig, calltype, state, sig. f === Core. invoke, todo)
1295+ if ! is_stmt_noinline (flag) && maybe_handle_const_call! (
1296+ ir, idx, stmt, info, sig, calltype, state, flag, sig. f === Core. invoke, todo)
13041297 continue
13051298 else
13061299 info = info. call
13071300 end
13081301 end
13091302
13101303 if isa (info, OpaqueClosureCallInfo)
1311- result = analyze_method! (info. match, sig. atypes, state, calltype)
1304+ result = analyze_method! (info. match, sig. atypes, state, calltype, flag )
13121305 handle_single_case! (ir, stmt, idx, result, false , todo)
13131306 continue
13141307 end
13151308
13161309 # Handle invoke
13171310 if sig. f === Core. invoke
13181311 if isa (info, InvokeCallInfo)
1319- inline_invoke! (ir, idx, sig, info, state, todo)
1312+ inline_invoke! (ir, idx, sig, info, state, todo, flag )
13201313 end
13211314 continue
13221315 end
@@ -1330,7 +1323,7 @@ function assemble_inline_todo!(ir::IRCode, state::InliningState)
13301323 continue
13311324 end
13321325
1333- analyze_single_call! (ir, todo, idx, stmt, sig, calltype, infos, state)
1326+ analyze_single_call! (ir, todo, idx, stmt, sig, calltype, infos, state, flag )
13341327 end
13351328 todo
13361329end
0 commit comments