Skip to content

Commit

Permalink
Stop renumbering statements in inference proper
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Keno committed Dec 28, 2022
1 parent 82fbf54 commit f346350
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f346350

Please sign in to comment.