Skip to content

Commit 35768c2

Browse files
Kenoaviateskvtjnash
authored
Fix interpreter_exec.jl test (#53218)
This test was supposed to check that we correctly handled PhiNodes in uninferred code in both the interpreter and the compiler. However, the compiler path wasn't actually exercised, because the `inferred=true` part of this forced it to be skipped. Drop that and fix the exposed issues in the compiler where we didn't handle PhiNodes properly. --------- Co-authored-by: Shuhei Kadowaki <[email protected]> Co-authored-by: Jameson Nash <[email protected]> Co-authored-by: Shuhei Kadowaki <[email protected]>
1 parent 3a283d9 commit 35768c2

File tree

6 files changed

+59
-32
lines changed

6 files changed

+59
-32
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3304,6 +3304,10 @@ function typeinf_local(interp::AbstractInterpreter, frame::InferenceState)
33043304
end
33053305
if rt === Bottom
33063306
ssavaluetypes[currpc] = Bottom
3307+
# Special case: Bottom-typed PhiNodes do not error (but must also be unused)
3308+
if isa(stmt, PhiNode)
3309+
continue
3310+
end
33073311
@goto find_next_bb
33083312
end
33093313
if changes !== nothing

base/compiler/optimize.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ function convert_to_ircode(ci::CodeInfo, sv::OptimizationState)
10861086
idx += 1
10871087
prevloc = codeloc
10881088
end
1089-
if ssavaluetypes[idx] === Union{} && !(oldidx in sv.unreachable)
1089+
if ssavaluetypes[idx] === Union{} && !(oldidx in sv.unreachable) && !isa(code[idx], PhiNode)
10901090
# We should have converted any must-throw terminators to an equivalent w/o control-flow edges
10911091
@assert !isterminator(code[idx])
10921092

base/compiler/utilities.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -415,15 +415,15 @@ function find_ssavalue_uses(body::Vector{Any}, nvals::Int)
415415
if isa(e, SSAValue)
416416
push!(uses[e.id], line)
417417
elseif isa(e, Expr)
418-
find_ssavalue_uses(e, uses, line)
418+
find_ssavalue_uses!(uses, e, line)
419419
elseif isa(e, PhiNode)
420-
find_ssavalue_uses(e, uses, line)
420+
find_ssavalue_uses!(uses, e, line)
421421
end
422422
end
423423
return uses
424424
end
425425

426-
function find_ssavalue_uses(e::Expr, uses::Vector{BitSet}, line::Int)
426+
function find_ssavalue_uses!(uses::Vector{BitSet}, e::Expr, line::Int)
427427
head = e.head
428428
is_meta_expr_head(head) && return
429429
skiparg = (head === :(=))
@@ -433,13 +433,16 @@ function find_ssavalue_uses(e::Expr, uses::Vector{BitSet}, line::Int)
433433
elseif isa(a, SSAValue)
434434
push!(uses[a.id], line)
435435
elseif isa(a, Expr)
436-
find_ssavalue_uses(a, uses, line)
436+
find_ssavalue_uses!(uses, a, line)
437437
end
438438
end
439439
end
440440

441-
function find_ssavalue_uses(e::PhiNode, uses::Vector{BitSet}, line::Int)
442-
for val in e.values
441+
function find_ssavalue_uses!(uses::Vector{BitSet}, e::PhiNode, line::Int)
442+
values = e.values
443+
for i = 1:length(values)
444+
isassigned(values, i) || continue
445+
val = values[i]
443446
if isa(val, SSAValue)
444447
push!(uses[val.id], line)
445448
end

test/compiler/interpreter_exec.jl

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@ let m = Meta.@lower 1 + 1
2020
ReturnNode(SSAValue(6)),
2121
]
2222
nstmts = length(src.code)
23-
src.ssavaluetypes = Any[ Any for _ = 1:nstmts ]
23+
src.ssavaluetypes = nstmts
2424
src.ssaflags = fill(UInt8(0x00), nstmts)
2525
src.codelocs = fill(Int32(1), nstmts)
26-
src.inferred = true
26+
@test !src.inferred
2727
Core.Compiler.verify_ir(Core.Compiler.inflate_ir(src))
2828
global test29262 = true
2929
@test :a === @eval $m
30+
compile_mode = @ccall jl_get_module_compile(@__MODULE__()::Module)::Cint
31+
if compile_mode == 3
32+
# implies `Base.Experimental.@compiler_options compile=min`
33+
@test !src.inferred
34+
end
3035
global test29262 = false
3136
@test :b === @eval $m
3237
end
@@ -61,13 +66,19 @@ let m = Meta.@lower 1 + 1
6166
ReturnNode(SSAValue(18)),
6267
]
6368
nstmts = length(src.code)
64-
src.ssavaluetypes = Any[ Any for _ = 1:nstmts ]
69+
src.ssavaluetypes = nstmts
6570
src.ssaflags = fill(UInt8(0x00), nstmts)
6671
src.codelocs = fill(Int32(1), nstmts)
67-
src.inferred = true
72+
@test !src.inferred
6873
Core.Compiler.verify_ir(Core.Compiler.inflate_ir(src))
6974
global test29262 = true
7075
@test (:b, :a, :c, :c) === @eval $m
76+
compile_mode = @ccall jl_get_module_compile(@__MODULE__()::Module)::Cint
77+
if compile_mode == 3
78+
# implies `Base.Experimental.@compiler_options compile=min`
79+
@test !src.inferred
80+
end
81+
src.ssavaluetypes = nstmts
7182
global test29262 = false
7283
@test (:b, :a, :c, :b) === @eval $m
7384
end
@@ -98,27 +109,18 @@ let m = Meta.@lower 1 + 1
98109
ReturnNode(SSAValue(11)),
99110
]
100111
nstmts = length(src.code)
101-
src.ssavaluetypes = Any[ Any for _ = 1:nstmts ]
112+
src.ssavaluetypes = nstmts
102113
src.ssaflags = fill(UInt8(0x00), nstmts)
103114
src.codelocs = fill(Int32(1), nstmts)
104-
src.inferred = true
115+
@test !src.inferred
105116
Core.Compiler.verify_ir(Core.Compiler.inflate_ir(src))
106117
global test29262 = true
107118
@test :a === @eval $m
119+
compile_mode = @ccall jl_get_module_compile(@__MODULE__()::Module)::Cint
120+
if compile_mode == 3
121+
# implies `Base.Experimental.@compiler_options compile=min`
122+
@test !src.inferred
123+
end
108124
global test29262 = false
109125
@test :b === @eval $m
110126
end
111-
112-
# https://github.com/JuliaLang/julia/issues/47065
113-
# `Core.Compiler.sort!` should be able to handle a big list
114-
let n = 1000
115-
ex = :(return 1)
116-
for _ in 1:n
117-
ex = :(rand() < .1 && $(ex))
118-
end
119-
@eval global function f_1000_blocks()
120-
$ex
121-
return 0
122-
end
123-
end
124-
@test f_1000_blocks() == 0

test/compiler/irpasses.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,3 +1787,17 @@ let code = Any[
17871787
@test !any(iscall((ir, getfield)), ir.stmts.stmt)
17881788
@test length(ir.cfg.blocks[end].stmts) == 1
17891789
end
1790+
1791+
# https://github.com/JuliaLang/julia/issues/47065
1792+
# `Core.Compiler.sort!` should be able to handle a big list
1793+
let n = 1000
1794+
ex = :(return 1)
1795+
for _ in 1:n
1796+
ex = :(rand() < .1 && $(ex))
1797+
end
1798+
@eval global function f_1000_blocks()
1799+
$ex
1800+
return 0
1801+
end
1802+
end
1803+
@test f_1000_blocks() == 0

test/compiler/ssair.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,15 @@ let cfg = CFG(BasicBlock[
9292
end
9393
end
9494

95-
for compile in ("min", "yes")
96-
cmd = `$(Base.julia_cmd()) --compile=$compile interpreter_exec.jl`
97-
if !success(pipeline(Cmd(cmd, dir=@__DIR__); stdout=stdout, stderr=stderr))
98-
error("Interpreter test failed, cmd : $cmd")
99-
end
95+
# test code execution with the default compile-mode
96+
module CompilerExecTest
97+
include("interpreter_exec.jl")
98+
end
99+
100+
# test code execution with the interpreter mode (compile=min)
101+
module InterpreterExecTest
102+
Base.Experimental.@compiler_options compile=min
103+
include("interpreter_exec.jl")
100104
end
101105

102106
# PR #32145

0 commit comments

Comments
 (0)