Skip to content

Commit

Permalink
refactors interpreter_exec.jl further
Browse files Browse the repository at this point in the history
This commit refines `interpreter_exec.jl` further, on top of #53218.
In detail, by using `Base.Experimental.@compiler_options compile=min`,
it's now possible to mimic the effect of `julia --compile=[min|yes]`.
This commit is leveraging it and includes `interpreter_exec.jl` from
`test/compiler/ssair.jl`, allowing us to get better stack traces and
test summaries.

In addition, I've introduced several tests concerning the `src.inferred`
values and have relocated the tests from #47066 within
`interpreter_exec.jl` to `test/compiler/irpasses.jl`, since it is
related to Julia-level compilation and not to interpreter execution.
  • Loading branch information
aviatesk committed Feb 8, 2024
1 parent dfdb1d7 commit c4dfacf
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 19 deletions.
32 changes: 18 additions & 14 deletions test/compiler/interpreter_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ let m = Meta.@lower 1 + 1
src.ssavaluetypes = nstmts
src.ssaflags = fill(UInt8(0x00), nstmts)
src.codelocs = fill(Int32(1), nstmts)
@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 @@ -63,9 +69,15 @@ let m = Meta.@lower 1 + 1
src.ssavaluetypes = nstmts
src.ssaflags = fill(UInt8(0x00), nstmts)
src.codelocs = fill(Int32(1), nstmts)
@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
Expand Down Expand Up @@ -100,23 +112,15 @@ let m = Meta.@lower 1 + 1
src.ssavaluetypes = nstmts
src.ssaflags = fill(UInt8(0x00), nstmts)
src.codelocs = fill(Int32(1), nstmts)
@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 @@ -99,11 +99,15 @@ let
# XXX: missing @test
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

0 comments on commit c4dfacf

Please sign in to comment.