Skip to content

Commit fe8376e

Browse files
authored
Ensure SlotNumbers are assigned when deciding top of signature (#25)
Fixes timholy/Revise.jl#422
1 parent 190dd07 commit fe8376e

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/LoweredCodeUtils.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,14 @@ function get_running_name(@nospecialize(recurse), frame, pc, name, parentname)
455455
return name, pc, nothing
456456
end
457457
pctop, isgen = nameinfo
458+
# Sometimes signature_top---which follows SSAValue links backwards to find the first
459+
# line needed to define the signature---misses out on a SlotNumber assignment.
460+
# Fix https://github.com/timholy/Revise.jl/issues/422
461+
stmt = pc_expr(frame, pctop)
462+
while pctop > 1 && isa(stmt, SlotNumber) && !isassigned(frame.framedata.locals, pctop)
463+
pctop -= 1
464+
stmt = pc_expr(frame, pctop)
465+
end # end fix
458466
sigtparent, lastpcparent = signature(recurse, frame, pctop)
459467
sigtparent === nothing && return name, pc, lastpcparent
460468
methparent = whichtt(sigtparent)

test/runtests.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ struct Caller end
1313
struct Gen{T} end
1414
end
1515

16+
# Stuff for https://github.com/timholy/Revise.jl/issues/422
17+
module Lowering422
18+
const LVec{N, T} = NTuple{N, Base.VecElement{T}}
19+
const LT{T} = Union{LVec{<:Any, T}, T}
20+
const FloatingTypes = Union{Float32, Float64}
21+
end
22+
1623
bodymethtest0(x) = 0
1724
function bodymethtest0(x)
1825
y = 2x
@@ -324,4 +331,22 @@ bodymethtest5(x, y=Dict(1=>2)) = 5
324331
@test length(ks) == 2
325332
@test dct[ks[1]] == dct[ks[2]]
326333
@test isdefined(Lowering, ks[1]) || isdefined(Lowering, ks[2])
334+
335+
# https://github.com/timholy/Revise.jl/issues/422
336+
ex = :(@generated function fneg(x::T) where T<:LT{<:FloatingTypes}
337+
s = """
338+
%2 = fneg $(llvm_type(T)) %0
339+
ret $(llvm_type(T)) %2
340+
"""
341+
return :(
342+
$(Expr(:meta, :inline));
343+
Base.llvmcall($s, T, Tuple{T}, x)
344+
)
345+
end)
346+
empty!(signatures)
347+
Core.eval(Lowering422, ex)
348+
frame = JuliaInterpreter.prepare_thunk(Lowering422, ex)
349+
rename_framemethods!(frame)
350+
pc = methoddefs!(signatures, frame; define=false)
351+
@test typeof(Lowering422.fneg) Set(Base.unwrap_unionall(sig).parameters[1] for sig in signatures)
327352
end

0 commit comments

Comments
 (0)