Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix interpreter_exec.jl test #53218

Merged
merged 6 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3304,6 +3304,10 @@ function typeinf_local(interp::AbstractInterpreter, frame::InferenceState)
end
if rt === Bottom
ssavaluetypes[currpc] = Bottom
# Special case: Bottom-typed PhiNodes do not error (but must also be unused)
if isa(stmt, PhiNode)
continue
end
@goto find_next_bb
end
if changes !== nothing
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ function convert_to_ircode(ci::CodeInfo, sv::OptimizationState)
idx += 1
prevloc = codeloc
end
if ssavaluetypes[idx] === Union{} && !(oldidx in sv.unreachable)
if ssavaluetypes[idx] === Union{} && !(oldidx in sv.unreachable) && !isa(code[idx], PhiNode)
# We should have converted any must-throw terminators to an equivalent w/o control-flow edges
@assert !isterminator(code[idx])

Expand Down
15 changes: 9 additions & 6 deletions base/compiler/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -415,15 +415,15 @@ function find_ssavalue_uses(body::Vector{Any}, nvals::Int)
if isa(e, SSAValue)
push!(uses[e.id], line)
elseif isa(e, Expr)
find_ssavalue_uses(e, uses, line)
find_ssavalue_uses!(uses, e, line)
elseif isa(e, PhiNode)
find_ssavalue_uses(e, uses, line)
find_ssavalue_uses!(uses, e, line)
end
end
return uses
end

function find_ssavalue_uses(e::Expr, uses::Vector{BitSet}, line::Int)
function find_ssavalue_uses!(uses::Vector{BitSet}, e::Expr, line::Int)
head = e.head
is_meta_expr_head(head) && return
skiparg = (head === :(=))
Expand All @@ -433,13 +433,16 @@ function find_ssavalue_uses(e::Expr, uses::Vector{BitSet}, line::Int)
elseif isa(a, SSAValue)
push!(uses[a.id], line)
elseif isa(a, Expr)
find_ssavalue_uses(a, uses, line)
find_ssavalue_uses!(uses, a, line)
end
end
end

function find_ssavalue_uses(e::PhiNode, uses::Vector{BitSet}, line::Int)
for val in e.values
function find_ssavalue_uses!(uses::Vector{BitSet}, e::PhiNode, line::Int)
values = e.values
for i = 1:length(values)
isassigned(values, i) || continue
val = values[i]
if isa(val, SSAValue)
push!(uses[val.id], line)
end
Expand Down
42 changes: 22 additions & 20 deletions test/compiler/interpreter_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ let m = Meta.@lower 1 + 1
ReturnNode(SSAValue(6)),
]
nstmts = length(src.code)
src.ssavaluetypes = Any[ Any for _ = 1:nstmts ]
src.ssavaluetypes = nstmts
src.ssaflags = fill(UInt8(0x00), nstmts)
src.codelocs = fill(Int32(1), nstmts)
vtjnash marked this conversation as resolved.
Show resolved Hide resolved
src.inferred = true
@test !src.inferred
Core.Compiler.verify_ir(Core.Compiler.inflate_ir(src))
global test29262 = true
@test :a === @eval $m
compile_mode = @ccall jl_get_module_compile(@__MODULE__()::Module)::Cint
if compile_mode == 3
# implies `Base.Experimental.@compiler_options compile=min`
@test !src.inferred
end
global test29262 = false
@test :b === @eval $m
end
Expand Down Expand Up @@ -61,13 +66,19 @@ let m = Meta.@lower 1 + 1
ReturnNode(SSAValue(18)),
]
nstmts = length(src.code)
src.ssavaluetypes = Any[ Any for _ = 1:nstmts ]
src.ssavaluetypes = nstmts
src.ssaflags = fill(UInt8(0x00), nstmts)
src.codelocs = fill(Int32(1), nstmts)
src.inferred = true
@test !src.inferred
Core.Compiler.verify_ir(Core.Compiler.inflate_ir(src))
global test29262 = true
@test (:b, :a, :c, :c) === @eval $m
compile_mode = @ccall jl_get_module_compile(@__MODULE__()::Module)::Cint
if compile_mode == 3
# implies `Base.Experimental.@compiler_options compile=min`
@test !src.inferred
end
src.ssavaluetypes = nstmts
global test29262 = false
@test (:b, :a, :c, :b) === @eval $m
end
Expand Down Expand Up @@ -98,27 +109,18 @@ let m = Meta.@lower 1 + 1
ReturnNode(SSAValue(11)),
]
nstmts = length(src.code)
src.ssavaluetypes = Any[ Any for _ = 1:nstmts ]
src.ssavaluetypes = nstmts
src.ssaflags = fill(UInt8(0x00), nstmts)
src.codelocs = fill(Int32(1), nstmts)
src.inferred = true
@test !src.inferred
Core.Compiler.verify_ir(Core.Compiler.inflate_ir(src))
global test29262 = true
@test :a === @eval $m
compile_mode = @ccall jl_get_module_compile(@__MODULE__()::Module)::Cint
if compile_mode == 3
# implies `Base.Experimental.@compiler_options compile=min`
@test !src.inferred
end
global test29262 = false
@test :b === @eval $m
end

# https://github.com/JuliaLang/julia/issues/47065
# `Core.Compiler.sort!` should be able to handle a big list
let n = 1000
ex = :(return 1)
for _ in 1:n
ex = :(rand() < .1 && $(ex))
end
@eval global function f_1000_blocks()
$ex
return 0
end
end
@test f_1000_blocks() == 0
14 changes: 14 additions & 0 deletions test/compiler/irpasses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1787,3 +1787,17 @@ let code = Any[
@test !any(iscall((ir, getfield)), ir.stmts.stmt)
@test length(ir.cfg.blocks[end].stmts) == 1
end

# https://github.com/JuliaLang/julia/issues/47065
# `Core.Compiler.sort!` should be able to handle a big list
let n = 1000
ex = :(return 1)
for _ in 1:n
ex = :(rand() < .1 && $(ex))
end
@eval global function f_1000_blocks()
$ex
return 0
end
end
@test f_1000_blocks() == 0
14 changes: 9 additions & 5 deletions test/compiler/ssair.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,15 @@ let cfg = CFG(BasicBlock[
end
end

for compile in ("min", "yes")
cmd = `$(Base.julia_cmd()) --compile=$compile interpreter_exec.jl`
if !success(pipeline(Cmd(cmd, dir=@__DIR__); stdout=stdout, stderr=stderr))
error("Interpreter test failed, cmd : $cmd")
end
# test code execution with the default compile-mode
module CompilerExecTest
include("interpreter_exec.jl")
end

# test code execution with the interpreter mode (compile=min)
module InterpreterExecTest
Base.Experimental.@compiler_options compile=min
include("interpreter_exec.jl")
end

# PR #32145
Expand Down