Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/choosetests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function choosetests(choices = [])
filtertests!(tests, "subarray")
filtertests!(tests, "compiler", [
"compiler/datastructures", "compiler/inference", "compiler/effects",
"compiler/validation", "compiler/sort", "compiler/ssair", "compiler/irpasses",
"compiler/validation", "compiler/ssair", "compiler/irpasses",
"compiler/codegen", "compiler/inline", "compiler/contextual",
"compiler/AbstractInterpreter", "compiler/EscapeAnalysis/local",
"compiler/EscapeAnalysis/interprocedural"])
Expand Down
51 changes: 42 additions & 9 deletions test/compiler/datastructures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,47 @@ end
end
end

# Make sure that the compiler can sort things.
# https://github.com/JuliaLang/julia/issues/47065
@testset "Compiler Sorting" begin
for len in (0, 1, 10, 100, 10000)
v = Core.Compiler.sort!(rand(Int8,len))
@test length(v) == len
@test issorted(v)
Core.Compiler.sort!(v, by=abs)
@test issorted(v, by=abs)
@testset "searchsorted" begin
@test Core.Compiler.searchsorted([1, 1, 2, 2, 3, 3], 0) === Core.Compiler.UnitRange(1, 0)
@test Core.Compiler.searchsorted([1, 1, 2, 2, 3, 3], 1) === Core.Compiler.UnitRange(1, 2)
@test Core.Compiler.searchsorted([1, 1, 2, 2, 3, 3], 2) === Core.Compiler.UnitRange(3, 4)
@test Core.Compiler.searchsorted([1, 1, 2, 2, 3, 3], 4) === Core.Compiler.UnitRange(7, 6)
@test Core.Compiler.searchsorted([1, 1, 2, 2, 3, 3], 2.5; lt=<) === Core.Compiler.UnitRange(5, 4)

@test Core.Compiler.searchsorted(Core.Compiler.UnitRange(1, 3), 0) === Core.Compiler.UnitRange(1, 0)
@test Core.Compiler.searchsorted(Core.Compiler.UnitRange(1, 3), 1) === Core.Compiler.UnitRange(1, 1)
@test Core.Compiler.searchsorted(Core.Compiler.UnitRange(1, 3), 2) === Core.Compiler.UnitRange(2, 2)
@test Core.Compiler.searchsorted(Core.Compiler.UnitRange(1, 3), 4) === Core.Compiler.UnitRange(4, 3)

@test Core.Compiler.searchsorted([1:10;], 1, by=(x -> x >= 5)) === Core.Compiler.UnitRange(1, 4)
@test Core.Compiler.searchsorted([1:10;], 10, by=(x -> x >= 5)) === Core.Compiler.UnitRange(5, 10)
@test Core.Compiler.searchsorted([1:5; 1:5; 1:5], 1, 6, 10, Core.Compiler.Forward) === Core.Compiler.UnitRange(6, 6)
@test Core.Compiler.searchsorted(fill(1, 15), 1, 6, 10, Core.Compiler.Forward) === Core.Compiler.UnitRange(6, 10)

for (rg,I) in Any[(Core.Compiler.UnitRange(49, 57), 47:59),
(Core.Compiler.StepRange(1, 2, 17), -1:19)]
rg_r = Core.Compiler.reverse(rg)
rgv, rgv_r = Core.Compiler.collect(rg), Core.Compiler.collect(rg_r)
for i = I
@test Core.Compiler.searchsorted(rg,i) === Core.Compiler.searchsorted(rgv,i)
@test Core.Compiler.searchsorted(rg_r,i,rev=true) === Core.Compiler.searchsorted(rgv_r,i,rev=true)
end
end
end

@testset "basic sort" begin
v = [3,1,2]
@test v == [3,1,2]
@test Core.Compiler.sort!(v) === v == [1,2,3]
@test Core.Compiler.sort!(v, by = x -> -x) === v == [3,2,1]
@test Core.Compiler.sort!(v, by = x -> -x, < = >) === v == [1,2,3]
end

@testset "randomized sorting tests" begin
for n in [0, 1, 3, 10, 30, 100, 300], k in [0, 30, 2n]
v = rand(-1:k, n)
for by in [identity, x -> -x, x -> x^2 + .1x], lt in [<, >]
@test sort(v; by, lt) == Core.Compiler.sort!(copy(v); by, < = lt)
end
end
end
18 changes: 8 additions & 10 deletions test/compiler/interpreter_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,16 @@ let m = Meta.@lower 1 + 1
@test :b === @eval $m
end

@testset "many basic blocks" begin
n = 1000
# 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 = :(if rand()<.1
$(ex) end)
ex = :(rand() < .1 && $(ex))
end
@eval begin
function f_1000()
$ex
return 0
end
@eval global function f_1000_blocks()
$ex
return 0
end
@test f_1000()===0
end
@test f_1000_blocks() == 0
44 changes: 0 additions & 44 deletions test/compiler/sort.jl

This file was deleted.