From 65d4b1b2fa7bd53a71dae138fb197ed87a37543b Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki Date: Thu, 21 Nov 2024 21:30:33 +0900 Subject: [PATCH] separate module context for Compiler.jl tests xref: This also allows us to execute each file standalone, which might be useful for debugging. --- Compiler/test/AbstractInterpreter.jl | 14 ++++++++------ Compiler/test/codegen.jl | 15 +++++++++------ Compiler/test/compact.jl | 16 +++++++++------- Compiler/test/contextual.jl | 14 +++++--------- Compiler/test/datastructures.jl | 10 ++-------- Compiler/test/effects.jl | 4 ++++ Compiler/test/inference.jl | 6 ++++++ Compiler/test/inline.jl | 4 ++++ Compiler/test/interpreter_exec.jl | 11 ++--------- Compiler/test/invalidation.jl | 4 ++++ Compiler/test/irpasses.jl | 4 ++++ Compiler/test/irutils.jl | 10 ++-------- Compiler/test/runtests.jl | 9 ++++++--- Compiler/test/setup.jl | 11 +++++++++++ Compiler/test/ssair.jl | 8 ++++++-- Compiler/test/tarjan.jl | 4 ++++ Compiler/test/validation.jl | 12 +++++------- 17 files changed, 91 insertions(+), 65 deletions(-) create mode 100644 Compiler/test/setup.jl diff --git a/Compiler/test/AbstractInterpreter.jl b/Compiler/test/AbstractInterpreter.jl index 81659443038e49..f2c5ce7365290b 100644 --- a/Compiler/test/AbstractInterpreter.jl +++ b/Compiler/test/AbstractInterpreter.jl @@ -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") @@ -542,3 +542,5 @@ let interp = DebugInterp() end @test found end + +end # module test_AbstractInterpreter diff --git a/Compiler/test/codegen.jl b/Compiler/test/codegen.jl index 90ec16ca3b7ac1..38873c9514e337 100644 --- a/Compiler/test/codegen.jl +++ b/Compiler/test/codegen.jl @@ -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 @@ -1032,3 +1033,5 @@ for a in ((@noinline Ref{Int}(2)), @test ex === a end end + +end # test_codegen diff --git a/Compiler/test/compact.jl b/Compiler/test/compact.jl index a636ab8172d63f..4aa8532c4cca72 100644 --- a/Compiler/test/compact.jl +++ b/Compiler/test/compact.jl @@ -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 @@ -57,3 +57,5 @@ end verify_ir(new_ir) @test length(new_ir.cfg.blocks) == 1 end + +end # module test_compact diff --git a/Compiler/test/contextual.jl b/Compiler/test/contextual.jl index 08dc68ba42b34c..10b2c4a5cce3bf 100644 --- a/Compiler/test/contextual.jl +++ b/Compiler/test/contextual.jl @@ -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 # ======== @@ -131,3 +125,5 @@ f() = 2 foo(i) = i+bar(Val(1)) @test @inferred(overdub(Ctx(), foo, 1)) == 43 + +end # module test_contextual diff --git a/Compiler/test/datastructures.jl b/Compiler/test/datastructures.jl index 6b37d7c89e684d..d1987fecd9bcad 100644 --- a/Compiler/test/datastructures.jl +++ b/Compiler/test/datastructures.jl @@ -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` diff --git a/Compiler/test/effects.jl b/Compiler/test/effects.jl index e4677daf0c483d..d4647f81d19117 100644 --- a/Compiler/test/effects.jl +++ b/Compiler/test/effects.jl @@ -1,3 +1,5 @@ +module test_effects + using Test include("irutils.jl") @@ -1382,3 +1384,5 @@ end |> Compiler.is_nothrow @test Base.infer_effects() do @ccall unsafecall()::Cvoid end == Compiler.EFFECTS_UNKNOWN + +end # module test_effects diff --git a/Compiler/test/inference.jl b/Compiler/test/inference.jl index a4854f85d7ef20..033966511536ad 100644 --- a/Compiler/test/inference.jl +++ b/Compiler/test/inference.jl @@ -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 @@ -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 diff --git a/Compiler/test/inline.jl b/Compiler/test/inline.jl index aedaed603f2e0c..00f567528b490d 100644 --- a/Compiler/test/inline.jl +++ b/Compiler/test/inline.jl @@ -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 @@ -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 diff --git a/Compiler/test/interpreter_exec.jl b/Compiler/test/interpreter_exec.jl index 65f42a0c7b89b5..a8870a1d354784 100644 --- a/Compiler/test/interpreter_exec.jl +++ b/Compiler/test/interpreter_exec.jl @@ -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 diff --git a/Compiler/test/invalidation.jl b/Compiler/test/invalidation.jl index c986cb298369ff..7cce8cc3b17ea0 100644 --- a/Compiler/test/invalidation.jl +++ b/Compiler/test/invalidation.jl @@ -1,5 +1,7 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license +module test_invalidation + # setup # ----- @@ -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 diff --git a/Compiler/test/irpasses.jl b/Compiler/test/irpasses.jl index 412ff3b98cb193..0668cd7764bf7f 100644 --- a/Compiler/test/irpasses.jl +++ b/Compiler/test/irpasses.jl @@ -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 @@ -1996,3 +1998,5 @@ let code = Any[ ir = Compiler.domsort_ssa!(ir, domtree) Compiler.verify_ir(ir) end + +end # module test_irpasses diff --git a/Compiler/test/irutils.jl b/Compiler/test/irutils.jl index f5193956478353..69fc8719994941 100644 --- a/Compiler/test/irutils.jl +++ b/Compiler/test/irutils.jl @@ -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 @@ -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, diff --git a/Compiler/test/runtests.jl b/Compiler/test/runtests.jl index ef1da1eec9f9ed..58e8634d86b158 100644 --- a/Compiler/test/runtests.jl +++ b/Compiler/test/runtests.jl @@ -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 diff --git a/Compiler/test/setup.jl b/Compiler/test/setup.jl new file mode 100644 index 00000000000000..dd5bb325b89eb1 --- /dev/null +++ b/Compiler/test/setup.jl @@ -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 diff --git a/Compiler/test/ssair.jl b/Compiler/test/ssair.jl index d6707e4dec9c24..8e7fad02d1e21b 100644 --- a/Compiler/test/ssair.jl +++ b/Compiler/test/ssair.jl @@ -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) @@ -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 diff --git a/Compiler/test/tarjan.jl b/Compiler/test/tarjan.jl index 49124bdf650fea..0119e30fc69fa4 100644 --- a/Compiler/test/tarjan.jl +++ b/Compiler/test/tarjan.jl @@ -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, @@ -165,3 +167,5 @@ end test_reachability(100, 150; all_checks=false) test_reachability(100, 1000; all_checks=false) end + +end # module test_tarjan diff --git a/Compiler/test/validation.jl b/Compiler/test/validation.jl index 38dfa9705d542b..14cd3d01e7d8d3 100644 --- a/Compiler/test/validation.jl +++ b/Compiler/test/validation.jl @@ -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 @@ -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