diff --git a/Compiler/test/AbstractInterpreter.jl b/Compiler/test/AbstractInterpreter.jl index 81659443038e4..df0dad79c156f 100644 --- a/Compiler/test/AbstractInterpreter.jl +++ b/Compiler/test/AbstractInterpreter.jl @@ -1,14 +1,8 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license -using Test +module test_AbstractInterpreter -if !@isdefined(Compiler) - if Base.identify_package("Compiler") === nothing - import Base.Compiler: Compiler - else - import Compiler - end -end +using Test include("irutils.jl") include("newinterp.jl") @@ -542,3 +536,5 @@ let interp = DebugInterp() end @test found end + +end # module test_AbstractInterpreter diff --git a/Compiler/test/EAUtils.jl b/Compiler/test/EAUtils.jl index cec33ca265a80..5a5c42fc89106 100644 --- a/Compiler/test/EAUtils.jl +++ b/Compiler/test/EAUtils.jl @@ -2,13 +2,7 @@ module EAUtils export code_escapes, @code_escapes, __clear_cache! -if !@isdefined(Compiler) - if Base.identify_package("Compiler") === nothing - import Base.Compiler: Compiler - else - import Compiler - end -end +include("setup_Compiler.jl") using ..EscapeAnalysis const EA = EscapeAnalysis @@ -267,22 +261,22 @@ end function print_with_info(preprint, postprint, io::IO, ir::IRCode, source::Bool) io = IOContext(io, :displaysize=>displaysize(io)) - used = Base.IRShow.stmts_used(io, ir) + used = Compiler.IRShow.stmts_used(io, ir) if source line_info_preprinter = function (io::IO, indent::String, idx::Int) - r = Base.IRShow.inline_linfo_printer(ir)(io, indent, idx) + r = Compiler.IRShow.inline_linfo_printer(ir)(io, indent, idx) idx ≠ 0 && preprint(io, idx) return r end else - line_info_preprinter = Base.IRShow.lineinfo_disabled + line_info_preprinter = Compiler.IRShow.lineinfo_disabled end - line_info_postprinter = Base.IRShow.default_expr_type_printer + line_info_postprinter = Compiler.IRShow.default_expr_type_printer preprint(io) bb_idx_prev = bb_idx = 1 for idx = 1:length(ir.stmts) preprint(io, idx) - bb_idx = Base.IRShow.show_ir_stmt(io, ir, idx, line_info_preprinter, line_info_postprinter, ir.sptypes, used, ir.cfg, bb_idx) + bb_idx = Compiler.IRShow.show_ir_stmt(io, ir, idx, line_info_preprinter, line_info_postprinter, ir.sptypes, used, ir.cfg, bb_idx) postprint(io, idx, bb_idx != bb_idx_prev) bb_idx_prev = bb_idx end diff --git a/Compiler/test/codegen.jl b/Compiler/test/codegen.jl index 90ec16ca3b7ac..0e425a8d553b4 100644 --- a/Compiler/test/codegen.jl +++ b/Compiler/test/codegen.jl @@ -2,17 +2,14 @@ # 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 -end +include("setup_Compiler.jl") const opt_level = Base.JLOptions().opt_level const coverage = (Base.JLOptions().code_coverage > 0) || (Base.JLOptions().malloc_log > 0) @@ -1032,3 +1029,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 a636ab8172d63..4aa8532c4cca7 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 08dc68ba42b34..a162f3367f9e3 100644 --- a/Compiler/test/contextual.jl +++ b/Compiler/test/contextual.jl @@ -1,15 +1,10 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license +module test_contextual + # N.B.: This file is also run from interpreter.jl, so needs to be standalone-executable using Test - -if !@isdefined(Compiler) - if Base.identify_package("Compiler") === nothing - import Base.Compiler: Compiler - else - import Compiler - end -end +include("setup_Compiler.jl") # Cassette # ======== @@ -131,3 +126,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 6b37d7c89e684..608e4e770998a 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_Compiler.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 e4677daf0c483..d4647f81d1911 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 a4854f85d7ef2..764d97529d6e2 100644 --- a/Compiler/test/inference.jl +++ b/Compiler/test/inference.jl @@ -1,9 +1,13 @@ # 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 -import .Compiler: Const, Conditional, ⊑, ReturnNode, GotoIfNot +using .Compiler: Conditional, ⊑ isdispatchelem(@nospecialize x) = !isa(x, Type) || Compiler.isdispatchelem(x) using Random, Core.IR @@ -823,7 +827,7 @@ end # Issue 19641 foo19641() = let a = 1.0 - Compiler.return_type(x -> x + a, Tuple{Float64}) + Core.Compiler.return_type(x -> x + a, Tuple{Float64}) end @inferred foo19641() @@ -1721,7 +1725,7 @@ g_test_constant() = (f_constant(3) == 3 && f_constant(4) == 4 ? true : "BAD") f_pure_add() = (1 + 1 == 2) ? true : "FAIL" @test @inferred f_pure_add() -import Core: Const +using Core: Const mutable struct ARef{T} @atomic x::T end @@ -1762,7 +1766,7 @@ let getfield_tfunc(@nospecialize xs...) = @test getfield_tfunc(ARef{Int},Const(:x),Bool,Bool) === Union{} end -import .Compiler: Const +using Core: Const mutable struct XY{X,Y} x::X y::Y @@ -2765,10 +2769,10 @@ end |> only === Int # `apply_type_tfunc` accuracy for constrained type construction # https://github.com/JuliaLang/julia/issues/47089 -import Core: Const -import .Compiler: apply_type_tfunc struct Issue47089{A<:Number,B<:Number} end -let 𝕃 = Compiler.fallback_lattice +let apply_type_tfunc = Compiler.apply_type_tfunc + 𝕃 = Compiler.fallback_lattice + Const = Core.Const A = Type{<:Integer} @test apply_type_tfunc(𝕃, Const(Issue47089), A, A) <: (Type{Issue47089{A,B}} where {A<:Integer, B<:Integer}) @test apply_type_tfunc(𝕃, Const(Issue47089), Const(Int), Const(Int), Const(Int)) === Union{} @@ -4554,7 +4558,8 @@ end |> only == Tuple{Int,Int} end |> only == Int # form PartialStruct for mutables with `const` field -import .Compiler: Const, ⊑ +using Core: Const +using .Compiler: ⊑ mutable struct PartialMutable{S,T} const s::S t::T @@ -5698,7 +5703,8 @@ let x = 1, _Any = Any end # Issue #51927 -let 𝕃 = Compiler.fallback_lattice +let apply_type_tfunc = Compiler.apply_type_tfunc + 𝕃 = Compiler.fallback_lattice @test apply_type_tfunc(𝕃, Const(Tuple{Vararg{Any,N}} where N), Int) == Type{NTuple{_A, Any}} where _A end @@ -6071,3 +6077,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 aedaed603f2e0..a9f5be68aa8e9 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 @@ -1857,7 +1859,7 @@ let i::Int, continue_::Bool ir = Compiler.ssa_inlining_pass!(ir, inlining, false) @test findfirst(isinvoke(:func_mul_int), ir.stmts.stmt) === nothing @test (i = findfirst(iscall((ir, Core.Intrinsics.mul_int)), ir.stmts.stmt)) !== nothing - lins = Base.IRShow.buildLineInfoNode(ir.debuginfo, nothing, i) + lins = Compiler.IRShow.buildLineInfoNode(ir.debuginfo, nothing, i) @test (continue_ = length(lins) == 2) # :multi_inlining1 -> :func_mul_int if continue_ def1 = lins[1].method @@ -1881,7 +1883,7 @@ let i::Int, continue_::Bool ir = Compiler.ssa_inlining_pass!(ir, inlining, false) @test findfirst(isinvoke(:func_mul_int), ir.stmts.stmt) === nothing @test (i = findfirst(iscall((ir, Core.Intrinsics.mul_int)), ir.stmts.stmt)) !== nothing - lins = Base.IRShow.buildLineInfoNode(ir.debuginfo, nothing, i) + lins = Compiler.IRShow.buildLineInfoNode(ir.debuginfo, nothing, i) @test_broken (continue_ = length(lins) == 3) # see TODO in `ir_inline_linetable!` if continue_ def1 = lins[1].method @@ -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 65f42a0c7b89b..4972df1a27202 100644 --- a/Compiler/test/interpreter_exec.jl +++ b/Compiler/test/interpreter_exec.jl @@ -1,17 +1,11 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license # tests that interpreter matches codegen +include("setup_Compiler.jl") + using Test using Core.IR -if !@isdefined(Compiler) - if Base.identify_package("Compiler") === nothing - import Base.Compiler: Compiler - else - import Compiler - end -end - # test that interpreter correctly handles PhiNodes (#29262) let m = Meta.@lower 1 + 1 @assert Meta.isexpr(m, :thunk) diff --git a/Compiler/test/invalidation.jl b/Compiler/test/invalidation.jl index c986cb298369f..3f283fece4767 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 # ----- @@ -104,7 +106,7 @@ begin let rt = only(Base.return_types(pr48932_callee, (Any,))) @test rt === Any effects = Base.infer_effects(pr48932_callee, (Any,)) - @test Compiler.Effects(effects) == Compiler.Effects() + @test effects == Compiler.Effects() end # run inference on both `pr48932_caller` and `pr48932_callee` @@ -171,7 +173,7 @@ begin take!(GLOBAL_BUFFER) let rt = only(Base.return_types(pr48932_callee_inferable, (Any,))) @test rt === Int effects = Base.infer_effects(pr48932_callee_inferable, (Any,)) - @test Compiler.Effects(effects) == Compiler.Effects() + @test effects == Compiler.Effects() end # run inference on both `pr48932_caller` and `pr48932_callee`: @@ -233,7 +235,7 @@ begin take!(GLOBAL_BUFFER) let rt = only(Base.return_types(pr48932_callee_inlined, (Any,))) @test rt === Any effects = Base.infer_effects(pr48932_callee_inlined, (Any,)) - @test Compiler.Effects(effects) == Compiler.Effects() + @test effects == Compiler.Effects() end # run inference on `pr48932_caller_inlined` and `pr48932_callee_inlined` @@ -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 412ff3b98cb19..0668cd7764bf7 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 f519395647835..d70d289a6a2da 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_Compiler.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 ea3df3aa2855d..6a38fce678ba0 100644 --- a/Compiler/test/runtests.jl +++ b/Compiler/test/runtests.jl @@ -3,7 +3,10 @@ using Test, Compiler using InteractiveUtils: @activate @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_Compiler.jl b/Compiler/test/setup_Compiler.jl new file mode 100644 index 0000000000000..a28a3f918aaf9 --- /dev/null +++ b/Compiler/test/setup_Compiler.jl @@ -0,0 +1,9 @@ +# This file is a part of Julia. License is MIT: https://julialang.org/license + +if !@isdefined(Compiler) + if Base.REFLECTION_COMPILER[] === nothing + using Base.Compiler: Compiler + else + const Compiler = Base.REFLECTION_COMPILER[] + end +end diff --git a/Compiler/test/ssair.jl b/Compiler/test/ssair.jl index d6707e4dec9c2..17f25dd2c8a73 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) @@ -393,13 +395,7 @@ f_if_typecheck() = (if nothing; end; unsafe_load(Ptr{Int}(0))) let # https://github.com/JuliaLang/julia/issues/42258 code = """ - if !@isdefined(Compiler) - if Base.identify_package("Compiler") === nothing - import Base.Compiler: Compiler - else - import Compiler - end - end + using Base: Compiler function foo() a = @noinline rand(rand(0:10)) @@ -824,3 +820,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 49124bdf650fe..4fe46374a7f79 100644 --- a/Compiler/test/tarjan.jl +++ b/Compiler/test/tarjan.jl @@ -1,5 +1,9 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license +module test_tarjan + +using Test + include("irutils.jl") using .Compiler: CFGReachability, DomTree, CFG, BasicBlock, StmtRange, dominates, @@ -165,3 +169,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 38dfa9705d542..2d5dbe68e3e96 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_Compiler.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