Skip to content

Commit

Permalink
Move compiler tests to Compiler package (#56522)
Browse files Browse the repository at this point in the history
This does not yet make the compiler tests independently runnable using
`] test Compiler`; it only moves the files and wires them up to continue
running as part of the Base test runner.

---------

Co-authored-by: Shuhei Kadowaki <aviatesk@gmail.com>
  • Loading branch information
Keno and aviatesk authored Nov 12, 2024
1 parent 001c666 commit 45c5c9b
Show file tree
Hide file tree
Showing 35 changed files with 64 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Compiler/src/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ include("ssair/slot2ssa.jl")
include("ssair/inlining.jl")
include("ssair/verify.jl")
include("ssair/legacy.jl")
include("ssair/EscapeAnalysis/EscapeAnalysis.jl")
include("ssair/EscapeAnalysis.jl")
include("ssair/passes.jl")
include("ssair/irinterp.jl")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ using ..Compiler: # Core.Compiler specific definitions
function include(x)
if !isdefined(_TOP_MOD.Base, :end_base_include)
# During bootstrap, all includes are relative to `base/`
x = ccall(:jl_prepend_string, Ref{String}, (Any, Any), "ssair/EscapeAnalysis/", x)
x = ccall(:jl_prepend_string, Ref{String}, (Any, Any), "ssair/", x)
end
_TOP_MOD.include(@__MODULE__, x)
end
Expand Down
File renamed without changes.
3 changes: 0 additions & 3 deletions Compiler/src/ssair/heap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
# Heap operations on flat vectors
# -------------------------------


# Binary heap indexing
heapleft(i::Integer) = 2i
heapright(i::Integer) = 2i + 1
heapparent(i::Integer) = div(i, 2)


# Binary min-heap percolate down.
function percolate_down!(xs::Vector, i::Integer, x, o::Ordering, len::Integer=length(xs))
@inbounds while (l = heapleft(i)) <= len
Expand Down Expand Up @@ -60,7 +58,6 @@ function heappush!(xs::Vector, x, o::Ordering)
return xs
end


"""
heapify!(v, ord::Ordering)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module test_EA

const use_core_compiler = true
global use_core_compiler::Bool = true

if use_core_compiler
const EscapeAnalysis = Core.Compiler.EscapeAnalysis
else
include(normpath(Sys.BINDIR, "..", "..", "base", "compiler", "ssair", "EscapeAnalysis", "EscapeAnalysis.jl"))
include(normpath(Sys.BINDIR, "..", "..", "Compiler", "src", "ssair", "EscapeAnalysis.jl"))
end

include("EAUtils.jl")
include("../irutils.jl")
include("irutils.jl")

using Test, .EscapeAnalysis, .EAUtils
using .EscapeAnalysis: ignore_argescape
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/compiler/inline.jl → Compiler/test/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ let code = code_typed(f_pointerref, Tuple{Type{Int}})[1][1].code
@test !any_ptrref
end

# Test that inlining can inline _applys of builtins/_applys on SimpleVectors
# Test that inlining can inline _apply_iterate of builtins/_apply_iterate on SimpleVectors
function foo_apply_apply_type_svec()
A = (Tuple, Float32)
B = Tuple{Float32, Float32}
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/compiler/irpasses.jl → Compiler/test/irpasses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ let src = code_typed1() do
@test count(isnew, src.code) == 1
end

# should eliminate allocation whose address isn't taked even if it has uninitialized field(s)
# should eliminate allocation whose address isn't taken even if it has uninitialized field(s)
mutable struct BadRef
x::String
y::String
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions Compiler/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license
using Test, Compiler

for file in readlines(joinpath(@__DIR__, "testgroups"))
include(file * ".jl")
end
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions Compiler/test/testgroups
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
AbstractInterpreter
EscapeAnalysis
codegen
compact
contextual
datastructures
effects
inference
inline
interpreter_exec
invalidation
irpasses
newinterp
ssair
tarjan
validation
File renamed without changes.
4 changes: 2 additions & 2 deletions doc/src/devdocs/EscapeAnalysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ defines the convenience entries `code_escapes` and `@code_escapes` for testing a
```@repl EAUtils
let JULIA_DIR = normpath(Sys.BINDIR, "..", "share", "julia")
# load `EscapeAnalysis` module to define the core analysis code
include(normpath(JULIA_DIR, "base", "compiler", "ssair", "EscapeAnalysis", "EscapeAnalysis.jl"))
include(normpath(JULIA_DIR, "Compiler", "src", "ssair", "EscapeAnalysis.jl"))
using .EscapeAnalysis
# load `EAUtils` module to define the utilities
include(normpath(JULIA_DIR, "test", "compiler", "EscapeAnalysis", "EAUtils.jl"))
include(normpath(JULIA_DIR, "Compiler", "test", "EAUtils.jl"))
using .EAUtils
end
Expand Down
2 changes: 1 addition & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export JULIA_LOAD_PATH := @$(PATHSEP)@stdlib
unexport JULIA_PROJECT :=
unexport JULIA_BINDIR :=

TESTGROUPS = unicode strings compiler
TESTGROUPS = unicode strings compiler Compiler
TESTS = all default stdlib $(TESTGROUPS) \
$(patsubst $(STDLIBDIR)/%/,%,$(dir $(wildcard $(STDLIBDIR)/*/.))) \
$(filter-out runtests testdefs relocatedepot, \
Expand Down
4 changes: 2 additions & 2 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using Random, LinearAlgebra

include("compiler/irutils.jl")
include(joinpath(@__DIR__,"../Compiler/test/irutils.jl"))

isdefined(Main, :InfiniteArrays) || @eval Main include("testhelpers/InfiniteArrays.jl")
using .Main.InfiniteArrays
Expand Down Expand Up @@ -1885,7 +1885,7 @@ end
end

module IRUtils
include("compiler/irutils.jl")
include(joinpath(@__DIR__,"../Compiler/test/irutils.jl"))
end

function check_pointer_strides(A::AbstractArray)
Expand Down
30 changes: 20 additions & 10 deletions test/choosetests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ const INTERNET_REQUIRED_LIST = [

const NETWORK_REQUIRED_LIST = vcat(INTERNET_REQUIRED_LIST, ["Sockets"])

function test_path(test)
t = split(test, '/')
if t[1] in STDLIBS
if length(t) == 2
return joinpath(STDLIB_DIR, t[1], "test", t[2])
else
return joinpath(STDLIB_DIR, t[1], "test", "runtests")
end
elseif t[1] == "Compiler"
testpath = length(t) >= 2 ? t[2:end] : ("runtests",)
return joinpath(@__DIR__, "..", t[1], "test", testpath...)
else
return joinpath(@__DIR__, test)
end
end

"""
`(; tests, net_on, exit_on_error, seed) = choosetests(choices)` selects a set of tests to be
run. `choices` should be a vector of test names; if empty or set to
Expand Down Expand Up @@ -154,13 +170,7 @@ function choosetests(choices = [])
"strings/io", "strings/types", "strings/annotated"])
# do subarray before sparse but after linalg
filtertests!(tests, "subarray")
filtertests!(tests, "compiler", [
"compiler/datastructures", "compiler/inference", "compiler/effects", "compiler/compact",
"compiler/validation", "compiler/ssair", "compiler/irpasses", "compiler/tarjan",
"compiler/codegen", "compiler/inline", "compiler/contextual", "compiler/invalidation",
"compiler/AbstractInterpreter", "compiler/EscapeAnalysis/EscapeAnalysis"])
filtertests!(tests, "compiler/EscapeAnalysis", [
"compiler/EscapeAnalysis/EscapeAnalysis"])
filtertests!(tests, "compiler", ["Compiler"])
filtertests!(tests, "stdlib", STDLIBS)
filtertests!(tests, "internet_required", INTERNET_REQUIRED_LIST)
# do ambiguous first to avoid failing if ambiguities are introduced by other tests
Expand Down Expand Up @@ -207,8 +217,8 @@ function choosetests(choices = [])

new_tests = String[]
for test in tests
if test in STDLIBS
testfile = joinpath(STDLIB_DIR, test, "test", "testgroups")
if test in STDLIBS || test == "Compiler"
testfile = test_path("$test/testgroups")
if isfile(testfile)
testgroups = readlines(testfile)
length(testgroups) == 0 && error("no testgroups defined for $test")
Expand All @@ -218,7 +228,7 @@ function choosetests(choices = [])
end
end
end
filter!(x -> (x != "stdlib" && !(x in STDLIBS)) , tests)
filter!(x -> (x != "stdlib" && !(x in STDLIBS) && x != "Compiler") , tests)
append!(tests, new_tests)

requested_all || explicit_pkg || filter!(x -> x != "Pkg", tests)
Expand Down
4 changes: 3 additions & 1 deletion test/interpreter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ end
@test success(pipeline(`$(Base.julia_cmd()) --compile=min -E 'include("staged.jl")'`; stderr))

# Test contextual execution mechanism in interpreter (#54360)
@test success(pipeline(`$(Base.julia_cmd()) --compile=min -E 'include("compiler/contextual.jl")'`; stderr))
let compiler_contextual_test = escape_string(joinpath(@__DIR__,"../Compiler/test/contextual.jl"))
@test success(pipeline(`$(Base.julia_cmd()) --compile=min -E "include(\"$compiler_contextual_test\")"`; stderr))
end
2 changes: 1 addition & 1 deletion test/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using Random: randstring

include("compiler/irutils.jl")
include(joinpath(@__DIR__,"../Compiler/test/irutils.jl"))

@testset "ifelse" begin
@test ifelse(true, 1, 2) == 1
Expand Down
4 changes: 2 additions & 2 deletions test/precompile_absint1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ precompile_test_harness() do load_path
basic_caller(x) = basic_callee(x)
end) |> string)

newinterp_path = abspath("compiler/newinterp.jl")
newinterp_path = abspath(joinpath(@__DIR__,"../Compiler/test/newinterp.jl"))
write(joinpath(load_path, "TestAbsIntPrecompile1.jl"), :(module TestAbsIntPrecompile1
import SimpleModule: basic_caller, basic_callee

module Custom
include("$($newinterp_path)")
include($newinterp_path)
@newinterp PrecompileInterpreter
end

Expand Down
4 changes: 2 additions & 2 deletions test/precompile_absint2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ precompile_test_harness() do load_path
basic_caller(x) = basic_callee(x)
end) |> string)

newinterp_path = abspath("compiler/newinterp.jl")
newinterp_path = abspath(joinpath(@__DIR__,"../Compiler/test/newinterp.jl"))
write(joinpath(load_path, "TestAbsIntPrecompile2.jl"), :(module TestAbsIntPrecompile2
import SimpleModule: basic_caller, basic_callee

module Custom
const CC = Core.Compiler
include("$($newinterp_path)")
include($newinterp_path)
@newinterp PrecompileInterpreter
struct CustomData
inferred
Expand Down
2 changes: 1 addition & 1 deletion test/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using Test

include("compiler/irutils.jl")
include(joinpath(@__DIR__,"../Compiler/test/irutils.jl"))

# code_native / code_llvm (issue #8239)
# It's hard to really test these, but just running them should be
Expand Down
13 changes: 0 additions & 13 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,6 @@ else
end
limited_worker_rss = max_worker_rss != typemax(Csize_t)

function test_path(test)
t = split(test, '/')
if t[1] in STDLIBS
if length(t) == 2
return joinpath(STDLIB_DIR, t[1], "test", t[2])
else
return joinpath(STDLIB_DIR, t[1], "test", "runtests")
end
else
return joinpath(@__DIR__, test)
end
end

# Check all test files exist
isfiles = isfile.(test_path.(tests) .* ".jl")
if !all(isfiles)
Expand Down
2 changes: 1 addition & 1 deletion test/scopedvalues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using Base.ScopedValues

include("compiler/irutils.jl")
include(joinpath(@__DIR__,"../Compiler/test/irutils.jl"))

@testset "errors" begin
@test ScopedValue{Float64}(1)[] == 1.0
Expand Down

0 comments on commit 45c5c9b

Please sign in to comment.