Skip to content

Commit

Permalink
Eliminate :code_coverage_effect exprs
Browse files Browse the repository at this point in the history
Julia 1.5 introduced annotations to improve line-coverage analysis (see 
JuliaLang/julia#34254). We just have to make 
sure these don't contaminate our tests.
  • Loading branch information
timholy committed Feb 4, 2020
1 parent 73c7e0d commit 2724703
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
11 changes: 11 additions & 0 deletions test/common.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Random
using Base.Meta: isexpr

const rseed = Ref(Random.GLOBAL_RNG) # to get new random directories (see julia #24445)
if isempty(methods(Random.seed!, Tuple{typeof(rseed[])}))
Expand Down Expand Up @@ -51,3 +52,13 @@ function get_docstring(obj)
end
return obj
end

function get_code(f, typ)
# Julia 1.5 introduces ":code_coverage_effect" exprs
ci = code_typed(f, typ)[1].first
code = copy(ci.code)
while !isempty(code) && isexpr(code[1], :code_coverage_effect)
popfirst!(code)
end
return code
end
32 changes: 16 additions & 16 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -921,14 +921,14 @@ end
@test PerfAnnotations.check_hasnoinline(3) == 3
@test PerfAnnotations.check_notannot1(3) == 3
@test PerfAnnotations.check_notannot2(3) == 3
ci = code_typed(PerfAnnotations.check_hasinline, Tuple{Int})[1].first
@test length(ci.code) == 1 && ci.code[1] == Expr(:return, Core.SlotNumber(2))
ci = code_typed(PerfAnnotations.check_hasnoinline, Tuple{Int})[1].first
@test length(ci.code) == 2 && ci.code[1].head == :invoke
ci = code_typed(PerfAnnotations.check_notannot1, Tuple{Int})[1].first
@test length(ci.code) == 1 && ci.code[1] == Expr(:return, Core.SlotNumber(2))
ci = code_typed(PerfAnnotations.check_notannot2, Tuple{Int})[1].first
@test length(ci.code) == 1 && ci.code[1] == Expr(:return, Core.SlotNumber(2))
code = get_code(PerfAnnotations.check_hasinline, Tuple{Int})
@test length(code) == 1 && code[1] == Expr(:return, Core.SlotNumber(2))
code = get_code(PerfAnnotations.check_hasnoinline, Tuple{Int})
@test length(code) == 2 && code[1].head == :invoke
code = get_code(PerfAnnotations.check_notannot1, Tuple{Int})
@test length(code) == 1 && code[1] == Expr(:return, Core.SlotNumber(2))
code = get_code(PerfAnnotations.check_notannot2, Tuple{Int})
@test length(code) == 1 && code[1] == Expr(:return, Core.SlotNumber(2))
open(joinpath(dn, "PerfAnnotations.jl"), "w") do io
println(io, """
module PerfAnnotations
Expand All @@ -953,14 +953,14 @@ end
@test PerfAnnotations.check_hasnoinline(3) == 3
@test PerfAnnotations.check_notannot1(3) == 3
@test PerfAnnotations.check_notannot2(3) == 3
ci = code_typed(PerfAnnotations.check_hasinline, Tuple{Int})[1].first
@test length(ci.code) == 1 && ci.code[1] == Expr(:return, Core.SlotNumber(2))
ci = code_typed(PerfAnnotations.check_hasnoinline, Tuple{Int})[1].first
@test length(ci.code) == 1 && ci.code[1] == Expr(:return, Core.SlotNumber(2))
ci = code_typed(PerfAnnotations.check_notannot1, Tuple{Int})[1].first
@test length(ci.code) == 1 && ci.code[1] == Expr(:return, Core.SlotNumber(2))
ci = code_typed(PerfAnnotations.check_notannot2, Tuple{Int})[1].first
@test length(ci.code) == 2 && ci.code[1].head == :invoke
code = get_code(PerfAnnotations.check_hasinline, Tuple{Int})
@test length(code) == 1 && code[1] == Expr(:return, Core.SlotNumber(2))
code = get_code(PerfAnnotations.check_hasnoinline, Tuple{Int})
@test length(code) == 1 && code[1] == Expr(:return, Core.SlotNumber(2))
code = get_code(PerfAnnotations.check_notannot1, Tuple{Int})
@test length(code) == 1 && code[1] == Expr(:return, Core.SlotNumber(2))
code = get_code(PerfAnnotations.check_notannot2, Tuple{Int})
@test length(code) == 2 && code[1].head == :invoke
rm_precompile("PerfAnnotations")

pop!(LOAD_PATH)
Expand Down

0 comments on commit 2724703

Please sign in to comment.