Skip to content

Commit

Permalink
separate module context for Compiler.jl tests
Browse files Browse the repository at this point in the history
xref: <#56632 (review)>

This also allows us to execute each file standalone, which might be
useful for debugging.
  • Loading branch information
aviatesk committed Nov 21, 2024
1 parent 43f687e commit 65d4b1b
Show file tree
Hide file tree
Showing 17 changed files with 91 additions and 65 deletions.
14 changes: 8 additions & 6 deletions Compiler/test/AbstractInterpreter.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

module test_AbstractInterpreter

using Test

if !@isdefined(Compiler)
if Base.identify_package("Compiler") === nothing
import Base.Compiler: Compiler
else
import Compiler
end
if Base.identify_package("Compiler") === nothing
using Base.Compiler: Compiler
else
using Compiler: Compiler
end

include("irutils.jl")
Expand Down Expand Up @@ -542,3 +542,5 @@ let interp = DebugInterp()
end
@test found
end

end # module test_AbstractInterpreter
15 changes: 9 additions & 6 deletions Compiler/test/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

# tests for codegen and optimizations

module test_codegen

using Random
using InteractiveUtils
using Libdl
using Test

if !@isdefined(Compiler)
if Base.identify_package("Compiler") === nothing
import Base.Compiler: Compiler
else
import Compiler
end
if Base.identify_package("Compiler") === nothing
using Base.Compiler: Compiler
else
using Compiler: Compiler
end

const opt_level = Base.JLOptions().opt_level
Expand Down Expand Up @@ -1032,3 +1033,5 @@ for a in ((@noinline Ref{Int}(2)),
@test ex === a
end
end

end # test_codegen
16 changes: 9 additions & 7 deletions Compiler/test/compact.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
if !@isdefined(Compiler)
if Base.identify_package("Compiler") === nothing
import Base.Compiler: Compiler
else
import Compiler
end
end
# This file is a part of Julia. License is MIT: https://julialang.org/license

module test_compact

using Test

include("irutils.jl")

using .Compiler: IncrementalCompact, insert_node_here!, finish,
NewInstruction, verify_ir, ReturnNode, SSAValue
Expand Down Expand Up @@ -57,3 +57,5 @@ end
verify_ir(new_ir)
@test length(new_ir.cfg.blocks) == 1
end

end # module test_compact
14 changes: 5 additions & 9 deletions Compiler/test/contextual.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

# N.B.: This file is also run from interpreter.jl, so needs to be standalone-executable
using Test
module test_contextual

if !@isdefined(Compiler)
if Base.identify_package("Compiler") === nothing
import Base.Compiler: Compiler
else
import Compiler
end
end
# N.B.: This file is also run from interpreter.jl, so needs to be standalone-executable
include("setup.jl")

# Cassette
# ========
Expand Down Expand Up @@ -131,3 +125,5 @@ f() = 2
foo(i) = i+bar(Val(1))

@test @inferred(overdub(Ctx(), foo, 1)) == 43

end # module test_contextual
10 changes: 2 additions & 8 deletions Compiler/test/datastructures.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
using Test
# This file is a part of Julia. License is MIT: https://julialang.org/license

if !@isdefined(Compiler)
if Base.identify_package("Compiler") === nothing
import Base.Compiler: Compiler
else
import Compiler
end
end
include("setup.jl")

@testset "CachedMethodTable" begin
# cache result should be separated per `limit` and `sig`
Expand Down
4 changes: 4 additions & 0 deletions Compiler/test/effects.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module test_effects

using Test
include("irutils.jl")

Expand Down Expand Up @@ -1382,3 +1384,5 @@ end |> Compiler.is_nothrow
@test Base.infer_effects() do
@ccall unsafecall()::Cvoid
end == Compiler.EFFECTS_UNKNOWN

end # module test_effects
6 changes: 6 additions & 0 deletions Compiler/test/inference.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

module test_inference

using Test

include("irutils.jl")

# tests for Compiler correctness and precision
Expand Down Expand Up @@ -6071,3 +6075,5 @@ function issue56387(nt::NamedTuple, field::Symbol=:a)
types[index]
end
@test Base.infer_return_type(issue56387, (typeof((;a=1)),)) == Type{Int}

end # module test_inference
4 changes: 4 additions & 0 deletions Compiler/test/inline.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

module test_inline

using Test
using Base.Meta
using Core: ReturnNode
Expand Down Expand Up @@ -2309,3 +2311,5 @@ g_noinline_invoke(x) = f_noinline_invoke(x)
let src = code_typed1(g_noinline_invoke, (Union{Symbol,Nothing},))
@test !any(@nospecialize(x)->isa(x,GlobalRef), src.code)
end

end # module test_inline
11 changes: 2 additions & 9 deletions Compiler/test/interpreter_exec.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

# tests that interpreter matches codegen
using Test
using Core.IR
include("setup.jl")

if !@isdefined(Compiler)
if Base.identify_package("Compiler") === nothing
import Base.Compiler: Compiler
else
import Compiler
end
end
using Core.IR

# test that interpreter correctly handles PhiNodes (#29262)
let m = Meta.@lower 1 + 1
Expand Down
4 changes: 4 additions & 0 deletions Compiler/test/invalidation.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

module test_invalidation

# setup
# -----

Expand Down Expand Up @@ -283,3 +285,5 @@ begin take!(GLOBAL_BUFFER)
@test isnothing(pr48932_caller_inlined(42))
@test "42" == String(take!(GLOBAL_BUFFER))
end

end # module test_invalidation
4 changes: 4 additions & 0 deletions Compiler/test/irpasses.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

module test_irpasses

using Test
using Base.Meta
using Core.IR
Expand Down Expand Up @@ -1996,3 +1998,5 @@ let code = Any[
ir = Compiler.domsort_ssa!(ir, domtree)
Compiler.verify_ir(ir)
end

end # module test_irpasses
10 changes: 2 additions & 8 deletions Compiler/test/irutils.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

if !@isdefined(Compiler)
if Base.identify_package("Compiler") === nothing
import Base.Compiler: Compiler
else
import Compiler
end
end
include("setup.jl")

using Core.IR
using .Compiler: IRCode, IncrementalCompact, singleton_type, VarState
Expand Down Expand Up @@ -68,7 +62,7 @@ macro fully_eliminated(ex0...)
end

let m = Meta.@lower 1 + 1
@assert Meta.isexpr(m, :thunk)
@assert isexpr(m, :thunk)
orig_src = m.args[1]::CodeInfo
global function make_codeinfo(code::Vector{Any};
ssavaluetypes::Union{Nothing,Vector{Any}}=nothing,
Expand Down
9 changes: 6 additions & 3 deletions Compiler/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ using Test, Compiler
using InteractiveUtils
@activate Compiler

for file in readlines(joinpath(@__DIR__, "testgroups"))
file == "special_loading" && continue # Only applicable to Base.Compiler
include(file * ".jl")
@testset "Compiler.jl" begin
for file in readlines(joinpath(@__DIR__, "testgroups"))
file == "special_loading" && continue # Only applicable to Base.Compiler
testfile = file * ".jl"
@eval @testset $testfile include($testfile)
end
end
11 changes: 11 additions & 0 deletions Compiler/test/setup.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

using Test

if !@isdefined(Compiler)
if Base.identify_package("Compiler") === nothing
using Base.Compiler: Compiler
else
using Compiler: Compiler
end
end
8 changes: 6 additions & 2 deletions Compiler/test/ssair.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

module test_ssair

include("irutils.jl")

using Base.Meta
using Core.IR
using Test

using .Compiler: CFG, BasicBlock, NewSSAValue

make_bb(preds, succs) = BasicBlock(Compiler.StmtRange(0, 0), preds, succs)
Expand Down Expand Up @@ -824,3 +826,5 @@ let cl = Int32[32, 1, 1, 1000, 240, 230]
cl2 = ccall(:jl_uncompress_codelocs, Any, (Any, Int), str, 2)
@test cl == cl2
end

end # module test_ssair
4 changes: 4 additions & 0 deletions Compiler/test/tarjan.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

module test_tarjan

include("irutils.jl")

using .Compiler: CFGReachability, DomTree, CFG, BasicBlock, StmtRange, dominates,
Expand Down Expand Up @@ -165,3 +167,5 @@ end
test_reachability(100, 150; all_checks=false)
test_reachability(100, 1000; all_checks=false)
end

end # module test_tarjan
12 changes: 5 additions & 7 deletions Compiler/test/validation.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

module test_validation

using Test, Core.IR

if !@isdefined(Compiler)
if Base.identify_package("Compiler") === nothing
import Base.Compiler: Compiler
else
import Compiler
end
end
include("setup.jl")

function f22938(a, b, x...)
nothing
Expand Down Expand Up @@ -145,3 +141,5 @@ end
@test count(e.kind === Compiler.SLOTNAMES_NARGS_MISMATCH for e in errors) == 1
@test count(e.kind === Compiler.SIGNATURE_NARGS_MISMATCH for e in errors) == 1
end

end # module test_validation

0 comments on commit 65d4b1b

Please sign in to comment.