Skip to content

Commit 3a6078d

Browse files
authored
methoddefs!: check signature equality (#46)
* methoddefs!: check signature equality Formerly, our "noop" signature addition (which failed to advance pc) did not check exact signature-equality in the manner of what had been implicitly assumed to be a condition for this branch. This "mostly-one-line" change fixes that. Fixes timholy/Revise.jl#550 Fixes timholy/Revise.jl#547 * Make usage of CBinding conditional on Julia version
1 parent c8fb669 commit 3a6078d

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

Project.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LoweredCodeUtils"
22
uuid = "6f1432cf-f94c-5a45-995e-cdbf5db27b0b"
33
authors = ["Tim Holy <tim.holy@gmail.com>"]
4-
version = "1.2.2"
4+
version = "1.2.3"
55

66
[deps]
77
JuliaInterpreter = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"
@@ -13,7 +13,8 @@ julia = "1"
1313
[extras]
1414
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
1515
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
16+
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
1617
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1718

1819
[targets]
19-
test = ["InteractiveUtils", "Parameters", "Test"]
20+
test = ["InteractiveUtils", "Parameters", "Pkg", "Test"]

src/signatures.jl

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -441,22 +441,27 @@ function methoddef!(@nospecialize(recurse), signatures, frame::Frame, @nospecial
441441
pc = step_expr!(recurse, frame, stmt, true)
442442
meth = whichtt(sigt)
443443
end
444-
if isa(meth, Method)
444+
if isa(meth, Method) && (meth.sig <: sigt && sigt <: meth.sig)
445445
push!(signatures, meth.sig)
446-
elseif arg1 === false || arg1 === nothing
447-
# If it's anonymous and not defined, define it
448-
pc = step_expr!(recurse, frame, stmt, true)
449-
meth = whichtt(sigt)
450-
isa(meth, Method) && push!(signatures, meth.sig)
451-
return pc, pc3
452446
else
453-
# guard against busted lookup, e.g., https://github.com/JuliaLang/julia/issues/31112
454-
code = framecode.src
455-
codeloc = codelocation(code, pc)
456-
loc = linetable(code, codeloc)
457-
ft = Base.unwrap_unionall((Base.unwrap_unionall(sigt)::DataType).parameters[1])
458-
if !startswith(String(ft.name.name), "##")
459-
@warn "file $(loc.file), line $(loc.line): no method found for $sigt"
447+
if arg1 === false || arg1 === nothing
448+
# If it's anonymous and not defined, define it
449+
pc = step_expr!(recurse, frame, stmt, true)
450+
meth = whichtt(sigt)
451+
isa(meth, Method) && push!(signatures, meth.sig)
452+
return pc, pc3
453+
else
454+
# guard against busted lookup, e.g., https://github.com/JuliaLang/julia/issues/31112
455+
code = framecode.src
456+
codeloc = codelocation(code, pc)
457+
loc = linetable(code, codeloc)
458+
ft = Base.unwrap_unionall((Base.unwrap_unionall(sigt)::DataType).parameters[1])
459+
if !startswith(String(ft.name.name), "##")
460+
@warn "file $(loc.file), line $(loc.line): no method found for $sigt"
461+
end
462+
if pc == pc3
463+
pc = next_or_nothing!(frame)
464+
end
460465
end
461466
end
462467
frame.pc = pc

test/signatures.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ const LT{T} = Union{LVec{<:Any, T}, T}
1919
const FloatingTypes = Union{Float32, Float64}
2020
end
2121

22+
# Stuff for https://github.com/timholy/Revise.jl/issues/550
23+
if Base.VERSION >= v"1.1"
24+
try
25+
using CBinding
26+
catch
27+
@info "Adding CBinding to the environment for test purposes"
28+
using Pkg
29+
Pkg.add("CBinding") # not available for Julia 1.0
30+
end
31+
eval(:(module Lowering550
32+
using CBinding
33+
end))
34+
end
35+
2236
bodymethtest0(x) = 0
2337
function bodymethtest0(x)
2438
y = 2x
@@ -371,6 +385,19 @@ bodymethtest5(x, y=Dict(1=>2)) = 5
371385
pc = methoddefs!(signatures, frame; define=false)
372386
@test typeof(Lowering422.fneg) Set(Base.unwrap_unionall(sig).parameters[1] for sig in signatures)
373387

388+
# https://github.com/timholy/Revise.jl/issues/550
389+
if Base.VERSION >= v"1.1"
390+
ex = :(@cstruct S {
391+
val::Int8
392+
})
393+
empty!(signatures)
394+
Core.eval(Lowering550, ex)
395+
frame = Frame(Lowering550, ex)
396+
rename_framemethods!(frame)
397+
pc = methoddefs!(signatures, frame; define=false)
398+
@test !isempty(signatures) # really we just need to know that `methoddefs!` completed without getting stuck
399+
end
400+
374401
# Undefined names
375402
# This comes from FileWatching; WindowsRawSocket is only defined on Windows
376403
ex = quote

0 commit comments

Comments
 (0)