-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
add some "no invalidations" tests for the sysimage #57884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nsajko
wants to merge
1
commit into
JuliaLang:master
Choose a base branch
from
nsajko:test_for_no_invalidations
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# This file is a part of Julia. License is MIT: https://julialang.org/license | ||
|
||
using Test | ||
|
||
module ThereAreNoInvalidations | ||
function julia_expr_cmd(expr::Expr) | ||
`$(Base.julia_cmd()) -e $expr` | ||
end | ||
function readline_julia_expr_cmd(expr::Expr) | ||
open(readline, julia_expr_cmd(expr)) | ||
end | ||
function invalidations_expr(expr::Expr) | ||
quote | ||
try | ||
let invs = ccall(:jl_debug_method_invalidation, Any, (Cint,), 1) | ||
@eval $expr | ||
invs | ||
end | ||
finally | ||
ccall(:jl_debug_method_invalidation, Any, (Cint,), 0) | ||
end | ||
end | ||
end | ||
function there_are_no_invalidations_expr(expr::Expr) | ||
e = invalidations_expr(expr) | ||
quote | ||
let invalidations = $e | ||
show(isempty(invalidations)) | ||
end | ||
end | ||
end | ||
function there_are_no_invalidations(expr::Expr) | ||
e = there_are_no_invalidations_expr(expr) | ||
s = readline_julia_expr_cmd(e) | ||
parse(Bool, s) | ||
end | ||
end | ||
|
||
function type_expr(f, supertype::Type) | ||
type_name = :T | ||
rest = f(type_name) | ||
quote | ||
struct $type_name <: $supertype end | ||
$rest | ||
end | ||
end | ||
|
||
function test_expr(f, supertype::Type) | ||
e = type_expr(f, supertype) | ||
ThereAreNoInvalidations.there_are_no_invalidations(e) | ||
end | ||
|
||
@testset "no invalidations test set" begin | ||
concrete_subtypes_integer = (Bool, Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, Int128, UInt128, BigInt) | ||
abstract_subtypes_number = (Signed, Unsigned, Integer, AbstractFloat, AbstractIrrational, Real, Number) | ||
@testset "2-arg `show` for various new types" begin | ||
stypes = (Any, AbstractString, Function, abstract_subtypes_number...) | ||
broken = (AbstractString, Function) | ||
@testset "S: $S" for S ∈ stypes | ||
@test test_expr((n -> :(function Base.show(::IO, ::$n) end)), S) broken=(S ∈ broken) | ||
end | ||
end | ||
@testset "new subtype of `AbstractString`" begin | ||
@testset "`print`" begin | ||
@test test_expr((n -> :(function Base.print(::IO, ::$n) end)), AbstractString) broken=true | ||
end | ||
@testset "index-related" begin | ||
fs = (thisind, prevind, nextind) | ||
broken = (thisind, prevind, nextind) | ||
@testset "f: $f" for f ∈ fs | ||
@test test_expr((n -> :(function Base.$f(::$n, ::Int) end)), AbstractString) broken=(f ∈ broken) | ||
end | ||
end | ||
end | ||
@testset "new subtype of `Integer`" begin | ||
@testset "construction of old int type from new type" begin | ||
broken = (UInt16, Int, UInt) | ||
(Int === Int64) && (broken = (broken..., Int32)) | ||
@testset "T: $T" for T ∈ concrete_subtypes_integer | ||
@test test_expr((n -> :(function Base.$T(::$n) end)), Integer) broken=(T ∈ broken) | ||
end | ||
end | ||
@testset "construction of new int type from old type" begin | ||
broken = () | ||
@testset "T: $T" for T ∈ concrete_subtypes_integer | ||
@test test_expr((n -> :(function $n(::$T) end)), Integer) broken=(T ∈ broken) | ||
end | ||
end | ||
@testset "arithmetic between old int types and new int type" begin | ||
ops = (:+, :*, :<<, :>>, :>>>) | ||
broken = () | ||
@testset "T: $T" for T ∈ concrete_subtypes_integer | ||
@testset "op: $op" for op ∈ ops | ||
@test ( | ||
test_expr((n -> :(function Base.$op(::$n, ::$T) end)), Integer) && | ||
test_expr((n -> :(function Base.$op(::$T, ::$n) end)), Integer) | ||
) broken=((T, op) ∈ broken) | ||
end | ||
end | ||
end | ||
@testset "promotion between old int types and new int type" begin | ||
broken = (Bool, UInt8, Int) | ||
@testset "T: $T" for T ∈ concrete_subtypes_integer | ||
@test ( | ||
test_expr((n -> :(function Base.promote_rule(::Type{$T}, ::Type{$n}) end)), Integer) && | ||
test_expr((n -> :(function Base.promote_rule(::Type{$n}, ::Type{$T}) end)), Integer) | ||
) broken=(T ∈ broken) | ||
end | ||
end | ||
@testset "unary functions" begin | ||
fs = (zero, one) | ||
broken = (zero, one) | ||
@testset "f: $f" for f ∈ fs | ||
@test test_expr((n -> :(function Base.$f(::$n) end)), Integer) broken=(f ∈ broken) | ||
end | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.