@@ -285,7 +285,7 @@ plus_saturate(x::Int, y::Int) = max(x, y, x+y)
285285# known return type
286286isknowntype (@nospecialize T) = (T === Union{}) || isa (T, Const) || isconcretetype (widenconst (T))
287287
288- function statement_cost (ex:: Expr , line:: Int , src:: CodeInfo , sptypes:: Vector{Any} , slottypes:: Vector{Any} , params:: OptimizationParams )
288+ function statement_cost (ex:: Expr , line:: Int , src:: CodeInfo , sptypes:: Vector{Any} , slottypes:: Vector{Any} , params:: OptimizationParams , error_path :: Bool = false )
289289 head = ex. head
290290 if is_meta_expr_head (head)
291291 return 0
@@ -320,7 +320,7 @@ function statement_cost(ex::Expr, line::Int, src::CodeInfo, sptypes::Vector{Any}
320320 return 0
321321 elseif (f === Main. Core. arrayref || f === Main. Core. const_arrayref) && length (ex. args) >= 3
322322 atyp = argextype (ex. args[3 ], src, sptypes, slottypes)
323- return isknowntype (atyp) ? 4 : params. inline_nonleaf_penalty
323+ return isknowntype (atyp) ? 4 : error_path ? params . inline_error_path_cost : params. inline_nonleaf_penalty
324324 end
325325 fidx = find_tfunc (f)
326326 if fidx === nothing
@@ -330,7 +330,11 @@ function statement_cost(ex::Expr, line::Int, src::CodeInfo, sptypes::Vector{Any}
330330 end
331331 return T_FFUNC_COST[fidx]
332332 end
333- return params. inline_nonleaf_penalty
333+ extyp = line == - 1 ? Any : src. ssavaluetypes[line]
334+ if extyp === Union{}
335+ return 0
336+ end
337+ return error_path ? params. inline_error_path_cost : params. inline_nonleaf_penalty
334338 elseif head === :foreigncall || head === :invoke
335339 # Calls whose "return type" is Union{} do not actually return:
336340 # they are errors. Since these are not part of the typical
@@ -347,7 +351,7 @@ function statement_cost(ex::Expr, line::Int, src::CodeInfo, sptypes::Vector{Any}
347351 end
348352 a = ex. args[2 ]
349353 if a isa Expr
350- cost = plus_saturate (cost, statement_cost (a, - 1 , src, sptypes, slottypes, params))
354+ cost = plus_saturate (cost, statement_cost (a, - 1 , src, sptypes, slottypes, params, error_path ))
351355 end
352356 return cost
353357 elseif head === :copyast
@@ -365,10 +369,11 @@ end
365369function inline_worthy (body:: Array{Any,1} , src:: CodeInfo , sptypes:: Vector{Any} , slottypes:: Vector{Any} ,
366370 params:: OptimizationParams , cost_threshold:: Integer = params. inline_cost_threshold)
367371 bodycost:: Int = 0
372+ throw_blocks = find_throw_blocks (body)
368373 for line = 1 : length (body)
369374 stmt = body[line]
370375 if stmt isa Expr
371- thiscost = statement_cost (stmt, line, src, sptypes, slottypes, params):: Int
376+ thiscost = statement_cost (stmt, line, src, sptypes, slottypes, params, line in throw_blocks ):: Int
372377 elseif stmt isa GotoNode
373378 # loops are generally always expensive
374379 # but assume that forward jumps are already counted for from
0 commit comments