Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oscardssmith committed Sep 19, 2023
1 parent 2ce7a3c commit 059a30c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 29 deletions.
6 changes: 3 additions & 3 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ end

array_new_memory(mem::Memory, newlen::Int) = typeof(mem)(undef, newlen) # TODO: when implemented, this should use a memory growing call

function _growbeg!(a::Vector, delta::Integer)
@assume_effects :terminates_locally function _growbeg!(a::Vector, delta::Integer)
delta = Int(delta)
delta == 0 && return # avoid attempting to index off the end
delta >= 0 || throw(ArgumentError("grow requires delta >= 0"))
Expand Down Expand Up @@ -1156,7 +1156,7 @@ function _growbeg!(a::Vector, delta::Integer)
return
end

function _growend!(a::Vector, delta::Integer)
@assume_effects :terminates_locally function _growend!(a::Vector, delta::Integer)
delta = Int(delta)
delta >= 0 || throw(ArgumentError("grow requires delta >= 0"))
ref = a.ref
Expand Down Expand Up @@ -1193,7 +1193,7 @@ function _growend!(a::Vector, delta::Integer)
return
end

function _growat!(a::Vector, i::Integer, delta::Integer)
@assume_effects :terminates_locally function _growat!(a::Vector, i::Integer, delta::Integer)
delta = Int(delta)
i == 1 && return _growbeg!(a, delta)
len = length(a)
Expand Down
34 changes: 19 additions & 15 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1562,28 +1562,32 @@ end
f_typeof_tfunc(x) = typeof(x)
@test Base.return_types(f_typeof_tfunc, (Union{<:T, Int} where T<:Complex,)) == Any[Union{Type{Int}, Type{Complex{T}} where T<:Real}]

# arrayref / arrayset / arraysize
# memoryref, memoryrefget_tfunc / memoryrefset_tfunc
import Core.Compiler: Const
let memoryrefget_tfunc(@nospecialize xs...) = Core.Compiler.memoryrefget_tfunc(Core.Compiler.fallback_lattice, xs...)
let memoryref_tfunc(@nospecialize xs...) = Core.Compiler.memoryref_tfunc(Core.Compiler.fallback_lattice, xs...)
memoryrefget_tfunc(@nospecialize xs...) = Core.Compiler.memoryrefget_tfunc(Core.Compiler.fallback_lattice, xs...)
memoryrefset_tfunc(@nospecialize xs...) = Core.Compiler.memoryrefset_tfunc(Core.Compiler.fallback_lattice, xs...)
@test memoryrefget_tfunc(Vector{Int}, Symbol, Bool) === Int
@test memoryrefget_tfunc(Vector{<:Integer}, Symbol, Bool) === Integer
@test memoryrefget_tfunc(Vector, Symbol, Bool) === Any
@test memoryref_tfunc(Memory{Int}) == MemoryRef{:not_atomic, Int}
@test memoryref_tfunc(Memory{Integer}) == MemoryRef{:not_atomic, Integer}
@test memoryref_tfunc(MemoryRef{:not_atomic, Int}, Int) == MemoryRef{:not_atomic, Int}
@test_broken memoryref_tfunc(Memory{Int}, Int) == MemoryRef{:not_atomic, Int}
@test memoryrefget_tfunc(MemoryRef{:not_atomic, Int}, Symbol, Bool) === Int
@test memoryrefget_tfunc(MemoryRef{:not_atomic, <:Integer}, Symbol, Bool) === Integer
@test memoryrefget_tfunc(MemoryRef, Symbol, Bool) === Any
@test memoryrefget_tfunc(Vector{Int}, Symbol, Bool) === Union{}
@test memoryrefget_tfunc(String, Symbol, Bool) === Union{}
@test memoryrefget_tfunc(Vector{Int}, Symbol, Bool) === Union{}
@test memoryrefget_tfunc(Vector{Int}, Int, Int, Symbol, Bool) === Union{}
@test memoryrefset_tfunc(Vector{Int}, Int, Symbol, Bool) === Vector{Int}
let ua = Vector{<:Integer}
@test memoryrefget_tfunc(String, Symbol, Bool) === Union{}
@test_throws MethodError memoryrefget_tfunc(MemoryRef{:not_atomic, Int}, Int, Int, Symbol, Bool) === Union{}
@test memoryrefset_tfunc(MemoryRef{:not_atomic, Int}, Int, Symbol, Bool) === MemoryRef{:not_atomic, Int}
let ua = MemoryRef{:not_atomic, <:Integer}
@test memoryrefset_tfunc(ua, Int, Symbol, Bool) === ua
end
@test memoryrefset_tfunc(Vector, Int, Symbol, Bool) === Vector
@test memoryrefset_tfunc(MemoryRef, Int, Symbol, Bool) === MemoryRef
@test memoryrefset_tfunc(Any, Int, Symbol, Bool) === Any
@test memoryrefset_tfunc(Vector{String}, Symbol, Bool) === Union{}
@test_throws MethodError memoryrefset_tfunc(MemoryRef{:not_atomic, String}, Symbol, Bool) === Union{}
@test memoryrefset_tfunc(String, Char, Symbol, Bool) === Union{}
@test memoryrefset_tfunc(Vector{Int}, Float64, Symbol, Bool) === Union{}
@test memoryrefset_tfunc(Vector{Int}, Int, Int, Symbol, Bool) === Union{}
@test memoryrefset_tfunc(Vector{Int}, Float64, Symbol, Bool) === Union{}
@test memoryrefset_tfunc(MemoryRef{:not_atomic, Int}, Float64, Symbol, Bool) === Union{}
@test_throws MethodError memoryrefset_tfunc(MemoryRef{:not_atomic, Int}, Int, Int, Symbol, Bool) === Union{}
@test memoryrefset_tfunc(MemoryRef{:not_atomic, Int}, Float64, Symbol, Bool) === Union{}
end

let tuple_tfunc(@nospecialize xs...) =
Expand Down
24 changes: 13 additions & 11 deletions test/compiler/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1564,20 +1564,22 @@ end
# optimize `[push!|pushfirst!](::Vector{Any}, x...)`
@testset "optimize `$f(::Vector{Any}, x...)`" for f = Any[push!, pushfirst!]
@eval begin
let src = code_typed1((Vector{Any}, Any)) do xs, x
$f(xs, x)
for T in [Int, Any]
let src = code_typed1((Vector{T}, T)) do xs, x
$f(xs, x)
end
@test count(iscall((src, $f)), src.code) == 0
end
@test count(iscall((src, $f)), src.code) == 0
end
let effects = Base.infer_effects((Vector{Any}, Any)) do xs, x
$f(xs, x)
let effects = Base.infer_effects((Vector{T}, T)) do xs, x
$f(xs, x)
end
@test Core.Compiler.Core.Compiler.is_terminates(effects)
end
@test Core.Compiler.Core.Compiler.is_terminates(effects)
end
let src = code_typed1((Vector{Any}, Any, Any)) do xs, x, y
$f(xs, x, y)
let src = code_typed1((Vector{T}, T, T)) do xs, x, y
$f(xs, x, y)
end
@test count(iscall((src, $f)), src.code) == 0
end
@test count(iscall((src, $f)), src.code) == 0
end
let xs = Any[]
$f(xs, :x, "y", 'z')
Expand Down

0 comments on commit 059a30c

Please sign in to comment.