Skip to content

Commit 05f25a1

Browse files
authored
Fix tests on 1.8 & nightly (#74)
This package never got updated for changes in lowering in Julia 1.8. Moreover, other changes in lowering were made for Julia 1.9. This gets the existing test suite passing, in part by disabling some of the specific tests on recent Julia versions. The disabled tests check for fairly specific features of lowering (which lines depend on which exact other lines), and those features have not proven to be particularly durable. Hopefully none of these tests were among our only ways of checking whether function is preserved (which is the more important metric of success). Revise will be a good testbed, but for it to pass we'll also need #73.
1 parent b71c05b commit 05f25a1

File tree

4 files changed

+71
-15
lines changed

4 files changed

+71
-15
lines changed

src/signatures.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,9 @@ function bodymethod(mkw::Method)
609609
has_self_call(src, src.code[id]) || return m
610610
end
611611
f = stmt.args[end-2]
612+
if isa(f, JuliaInterpreter.SSAValue)
613+
f = src.code[f.id]
614+
end
612615
else
613616
has_self_call(src, stmt) || return m
614617
end

src/utils.jl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,40 @@ ismethod3(frame::Frame) = ismethod3(pc_expr(frame))
6666
ismethod(stmt) = isexpr(stmt, :method)
6767
ismethod1(stmt) = isexpr(stmt, :method, 1)
6868
ismethod3(stmt) = isexpr(stmt, :method, 3)
69+
function ismethod_with_name(src, stmt, target::AbstractString; reentrant::Bool=false)
70+
if reentrant
71+
name = stmt
72+
else
73+
ismethod3(stmt) || return false
74+
name = stmt.args[1]
75+
if name === nothing
76+
name = stmt.args[2]
77+
end
78+
end
79+
isdone = false
80+
while !isdone
81+
if name isa AnySSAValue || name isa AnySlotNumber
82+
name = src.code[name.id]
83+
elseif isexpr(name, :call) && is_quotenode_egal(name.args[1], Core.svec)
84+
name = name.args[2]
85+
elseif isexpr(name, :call) && is_quotenode_egal(name.args[1], Core.apply_type)
86+
for arg in name.args[2:end]
87+
ismethod_with_name(src, arg, target; reentrant=true) && return true
88+
end
89+
isdone = true
90+
elseif isexpr(name, :call) && is_quotenode_egal(name.args[1], UnionAll)
91+
for arg in name.args[2:end]
92+
ismethod_with_name(src, arg, target; reentrant=true) && return true
93+
end
94+
isdone = true
95+
else
96+
isdone = true
97+
end
98+
end
99+
return match(Regex("(^|#)$target(\$|#)"), string(name)) !== nothing
100+
end
101+
102+
69103

70104
# anonymous function types are defined in a :thunk expr with a characteristic CodeInfo
71105
function isanonymous_typedef(stmt)

test/codeedges.jl

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ end
6565
# Check that the result of direct evaluation agrees with selective evaluation
6666
Core.eval(ModEval, ex)
6767
isrequired = lines_required(:x, src, edges)
68-
@test sum(isrequired) == 1
68+
@test sum(isrequired) == 1 + isdefined(Core, :get_binding_type) * 3 # get_binding_type + convert + typeassert
6969
selective_eval_fromstart!(frame, isrequired)
7070
@test ModSelective.x === ModEval.x
7171
@test allmissing(ModSelective, (:y, :z, :a, :b, :k))
@@ -204,7 +204,7 @@ end
204204
frame = Frame(ModSelective, ex)
205205
src = frame.framecode.src
206206
edges = CodeEdges(src)
207-
isrequired = minimal_evaluation(stmt->(LoweredCodeUtils.ismethod3(stmt)&&stmt.args[1]===:NoParam,false), src, edges) # initially mark only the constructor
207+
isrequired = minimal_evaluation(stmt->(LoweredCodeUtils.ismethod_with_name(src, stmt, "NoParam"),false), src, edges) # initially mark only the constructor
208208
selective_eval_fromstart!(frame, isrequired, true)
209209
@test isa(ModSelective.NoParam(), ModSelective.NoParam)
210210
# Parametric
@@ -216,7 +216,7 @@ end
216216
frame = Frame(ModSelective, ex)
217217
src = frame.framecode.src
218218
edges = CodeEdges(src)
219-
isrequired = minimal_evaluation(stmt->(LoweredCodeUtils.ismethod3(stmt)&&stmt.args[1]===:Struct,false), src, edges) # initially mark only the constructor
219+
isrequired = minimal_evaluation(stmt->(LoweredCodeUtils.ismethod_with_name(src, stmt, "Struct"),false), src, edges) # initially mark only the constructor
220220
selective_eval_fromstart!(frame, isrequired, true)
221221
@test isa(ModSelective.Struct([1,2,3]), ModSelective.Struct{Int})
222222
# Keyword constructor (this generates :copyast expressions)
@@ -341,29 +341,42 @@ end
341341
str = String(take!(io))
342342
@test occursin(r"slot 1:\n preds: ssas: \[\d+, \d+\], slots: ∅, names: ∅;\n succs: ssas: \[\d+, \d+, \d+\], slots: ∅, names: ∅;\n assign @: \[\d+, \d+\]", str)
343343
@test occursin(r"succs: ssas: ∅, slots: \[\d+\], names: ∅;", str)
344-
@test occursin(r"s:\n preds: ssas: \[\d+\], slots: ∅, names: ∅;\n succs: ssas: \[\d+, \d+, \d+\], slots: ∅, names: ∅;\n assign @: \[\d, \d+\]", str)
345-
@test occursin(r"\d+ preds: ssas: \[\d+\], slots: ∅, names: \[:s\];\n\d+ succs: ssas: ∅, slots: ∅, names: \[:s\];", str)
344+
@test occursin(r"s:\n preds: ssas: \[\d+\], slots: ∅, names: ∅;\n succs: ssas: \[\d+, \d+, \d+\], slots: ∅, names: ∅;\n assign @: \[\d, \d+\]", str) ||
345+
occursin(r"s:\n preds: ssas: \[\d+, \d+\], slots: ∅, names: ∅;\n succs: ssas: \[\d+, \d+, \d+\], slots: ∅, names: ∅;\n assign @: \[\d, \d+\]", str) # with global var inference
346+
if Base.VERSION < v"1.8" # changed by global var inference
347+
@test occursin(r"\d+ preds: ssas: \[\d+\], slots: ∅, names: \[:s\];\n\d+ succs: ssas: ∅, slots: ∅, names: \[:s\];", str)
348+
end
346349
LoweredCodeUtils.print_with_code(io, src, cl)
347350
str = String(take!(io))
348351
if isdefined(Base.IRShow, :show_ir_stmt)
349352
@test occursin(r"slot 1:\n preds: ssas: \[\d+, \d+\], slots: ∅, names: ∅;\n succs: ssas: \[\d+, \d+, \d+\], slots: ∅, names: ∅;\n assign @: \[\d+, \d+\]", str)
350353
@test occursin("# see name s", str)
351354
@test occursin("# see slot 1", str)
352-
@test occursin(r"# preds: ssas: \[\d+\], slots: ∅, names: \[:s\]; succs: ssas: ∅, slots: ∅, names: \[:s\];", str)
355+
if Base.VERSION < v"1.8" # changed by global var inference
356+
@test occursin(r"# preds: ssas: \[\d+\], slots: ∅, names: \[:s\]; succs: ssas: ∅, slots: ∅, names: \[:s\];", str)
357+
end
353358
else
354359
@test occursin("No IR statement printer", str)
355360
end
356361
# CodeEdges
357362
edges = CodeEdges(src)
358363
show(io, edges)
359364
str = String(take!(io))
360-
@test occursin(r"s: assigned on \[\d, \d+\], depends on \[\d+\], and used by \[\d+, \d+, \d+\]", str)
361-
@test count(occursin("statement $i depends on [1, $(i-1), $(i+1)] and is used by [1, $(i+1)]", str) for i = 1:length(src.code)) == 1
365+
@test occursin(r"s: assigned on \[\d, \d+\], depends on \[\d+\], and used by \[\d+, \d+, \d+\]", str) ||
366+
occursin(r"s: assigned on \[\d, \d+\], depends on \[\d+, \d+\], and used by \[\d+, \d+, \d+\]", str) # global var inference
367+
if Base.VERSION < v"1.9"
368+
@test (count(occursin("statement $i depends on [1, $(i-1), $(i+1)] and is used by [1, $(i+1)]", str) for i = 1:length(src.code)) == 1) ||
369+
(count(occursin("statement $i depends on [4, $(i-1), $(i+4)] and is used by [$(i+2)]", str) for i = 1:length(src.code)) == 1)
370+
end
362371
LoweredCodeUtils.print_with_code(io, src, edges)
363372
str = String(take!(io))
364373
if isdefined(Base.IRShow, :show_ir_stmt)
365-
@test occursin(r"s: assigned on \[\d, \d+\], depends on \[\d+\], and used by \[\d+, \d+, \d+\]", str)
366-
@test count(occursin("preds: [1, $(i-1), $(i+1)], succs: [1, $(i+1)]", str) for i = 1:length(src.code)) == 1
374+
@test occursin(r"s: assigned on \[\d, \d+\], depends on \[\d+\], and used by \[\d+, \d+, \d+\]", str) ||
375+
occursin(r"s: assigned on \[\d, \d+\], depends on \[\d+, \d+\], and used by \[\d+, \d+, \d+\]", str)
376+
if Base.VERSION < v"1.9"
377+
@test (count(occursin("preds: [1, $(i-1), $(i+1)], succs: [1, $(i+1)]", str) for i = 1:length(src.code)) == 1) ||
378+
(count(occursin("preds: [4, $(i-1), $(i+4)], succs: [$(i+2)]", str) for i = 1:length(src.code)) == 1) # global var inference
379+
end
367380
else
368381
@test occursin("No IR statement printer", str)
369382
end
@@ -373,8 +386,12 @@ end
373386
LoweredCodeUtils.print_with_code(io, frame, edges)
374387
str = String(take!(io))
375388
if isdefined(Base.IRShow, :show_ir_stmt)
376-
@test occursin(r"s: assigned on \[\d, \d+\], depends on \[\d+\], and used by \[\d+, \d+, \d+\]", str)
377-
@test count(occursin("preds: [1, $(i-1), $(i+1)], succs: [1, $(i+1)]", str) for i = 1:length(src.code)) == 1
389+
@test occursin(r"s: assigned on \[\d, \d+\], depends on \[\d+\], and used by \[\d+, \d+, \d+\]", str) ||
390+
occursin(r"s: assigned on \[\d, \d+\], depends on \[\d, \d+\], and used by \[\d+, \d+, \d+\]", str) # global var inference
391+
if Base.VERSION < v"1.9"
392+
@test (count(occursin("preds: [1, $(i-1), $(i+1)], succs: [1, $(i+1)]", str) for i = 1:length(src.code)) == 1) ||
393+
(count(occursin("preds: [4, $(i-1), $(i+4)], succs: [$(i+2)]", str) for i = 1:length(src.code)) == 1) # global var inference
394+
end
378395
else
379396
@test occursin("No IR statement printer", str)
380397
end

test/signatures.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ bodymethtest5(x, y=Dict(1=>2)) = 5
279279
rename_framemethods!(frame)
280280
empty!(signatures)
281281
methoddefs!(signatures, frame; define=false)
282-
@test length(signatures) >= 3
282+
@test length(signatures) >= 3 - isdefined(Core, :kwcall)
283283

284284
ex = :(typedsig(x) = 1)
285285
frame = Frame(Lowering, ex)
@@ -350,8 +350,10 @@ bodymethtest5(x, y=Dict(1=>2)) = 5
350350
@test length(ks) == 2
351351
@test dct[ks[1]] == dct[ks[2]]
352352
@test isdefined(Lowering, ks[1]) || isdefined(Lowering, ks[2])
353-
nms = filter(sym->occursin(r"#Items#\d+#\d+", String(sym)), names(Lowering; all=true))
354-
@test length(nms) == 1
353+
if !isdefined(Core, :kwcall)
354+
nms = filter(sym->occursin(r"#Items#\d+#\d+", String(sym)), names(Lowering; all=true))
355+
@test length(nms) == 1
356+
end
355357

356358
# https://github.com/timholy/Revise.jl/issues/422
357359
ex = :(@generated function fneg(x::T) where T<:LT{<:FloatingTypes}

0 commit comments

Comments
 (0)