From f346350c40ff9e0c260df06d11db7515562aab69 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Wed, 28 Dec 2022 16:13:35 +0000 Subject: [PATCH] Stop renumbering statements in inference proper I don't think there's any good reason to try to delete the statements here. The very next thing we do is to convert to IRCode which drops dead code anyway, so this just seems redundant. In addition, it complicates Cthulhu-like analysis, which now has to track an extra set of statement numbers. --- base/compiler/typeinfer.jl | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/base/compiler/typeinfer.jl b/base/compiler/typeinfer.jl index 29c4a7e6e477a3..8cbc086112e1a1 100644 --- a/base/compiler/typeinfer.jl +++ b/base/compiler/typeinfer.jl @@ -556,8 +556,7 @@ function finish(me::InferenceState, interp::AbstractInterpreter) # annotate fulltree with type information, # either because we are the outermost code, or we might use this later doopt = (me.cached || me.parent !== nothing) - changemap = type_annotate!(interp, me, doopt) - recompute_cfg = changemap !== nothing + recompute_cfg = type_annotate!(interp, me, doopt) if doopt && may_optimize(interp) me.result.src = OptimizationState(me, OptimizationParams(interp), interp, recompute_cfg) else @@ -715,6 +714,7 @@ function type_annotate!(interp::AbstractInterpreter, sv::InferenceState, run_opt slotflags = src.slotflags nslots = length(slotflags) undefs = fill(false, nslots) + any_unreachable = false # this statement traversal does five things: # 1. introduce temporary `TypedSlot`s that are supposed to be replaced with π-nodes later @@ -742,13 +742,9 @@ function type_annotate!(interp::AbstractInterpreter, sv::InferenceState, run_opt body[i] = annotate_slot_load!(undefs, i, sv, expr) # 1&2 ssavaluetypes[i] = widenslotwrapper(ssavaluetypes[i]) # 4 else # i.e. any runtime execution will never reach this statement + any_unreachable = true if is_meta_expr(expr) # keep any lexically scoped expressions ssavaluetypes[i] = Any # 4 - elseif run_optimizer - if changemap === nothing - changemap = fill(0, nexpr) - end - changemap[i] = -1 # 3&4: mark for the bulk deletion else ssavaluetypes[i] = Bottom # 4 body[i] = Const(expr) # annotate that this statement actually is dead @@ -763,19 +759,7 @@ function type_annotate!(interp::AbstractInterpreter, sv::InferenceState, run_opt end end - # do the bulk deletion of unreached statements - if changemap !== nothing - inds = Int[i for (i,v) in enumerate(changemap) if v == -1] - deleteat!(body, inds) - deleteat!(ssavaluetypes, inds) - deleteat!(codelocs, inds) - deleteat!(stmt_info, inds) - deleteat!(ssaflags, inds) - renumber_ir_elements!(body, changemap) - return changemap - else - return nothing - end + return any_unreachable end # at the end, all items in b's cycle