Skip to content

Commit 95156a6

Browse files
authored
Unbreak primitivetype & abstracttype (#61)
#60 introduced an important bugfix, but it inadvertently introduced new bugs for primitivetype & abstracttype. Fixes timholy/Revise.jl#611
1 parent a825f56 commit 95156a6

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
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 <[email protected]>"]
4-
version = "1.2.8"
4+
version = "1.2.9"
55

66
[deps]
77
JuliaInterpreter = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"

src/utils.jl

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,29 @@ function typedef_range(src::CodeInfo, idx)
128128
istart >= 1 || error("no initial :global found")
129129
stmt.head structheads && return istart:idx
130130
iend, n = idx, length(src.code)
131+
have_typebody = have_equivtypedef = false
131132
while iend <= n
132133
stmt = src.code[iend]
133134
if isa(stmt, Expr)
134135
(stmt.head === :global || stmt.head === :return) && break
135-
if stmt.head === :call && (is_global_ref(stmt.args[1], Core, :_typebody!) ||
136-
isdefined(Core, :_typebody!) && is_quotenode(stmt.args[1], Core._typebody!))
137-
iend += 1 # compensate for the `iend-1` in the return
138-
break
136+
if stmt.head === :call
137+
if (is_global_ref(stmt.args[1], Core, :_typebody!) ||
138+
isdefined(Core, :_typebody!) && is_quotenode(stmt.args[1], Core._typebody!))
139+
have_typebody = true
140+
elseif (is_global_ref(stmt.args[1], Core, :_equiv_typedef) ||
141+
isdefined(Core, :_equiv_typedef) && is_quotenode(stmt.args[1], Core._equiv_typedef))
142+
have_equivtypedef = true
143+
# Advance to the type-assignment
144+
while iend <= n
145+
stmt = src.code[iend]
146+
isexpr(stmt, :(=)) && break
147+
iend += 1
148+
end
149+
end
150+
if have_typebody && have_equivtypedef
151+
iend += 1 # compensate for the `iend-1` in the return
152+
break
153+
end
139154
end
140155
end
141156
is_return(stmt) && break

test/codeedges.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,17 @@ end
304304
lr = lines_required(idx, src, edges; exclude_named_typedefs=true)
305305
idx = findfirst(stmt->Meta.isexpr(stmt, :(=)) && Meta.isexpr(stmt.args[2], :call) && is_global_ref(stmt.args[2].args[1], Core, :Box), src.code)
306306
@test lr[idx]
307+
# but make sure we don't break primitivetype & abstracttype (https://github.com/timholy/Revise.jl/pull/611)
308+
if isdefined(Core, :_primitivetype)
309+
thk = Meta.lower(Main, quote
310+
primitive type WindowsRawSocket sizeof(Ptr) * 8 end
311+
end)
312+
src = thk.args[1]
313+
edges = CodeEdges(src)
314+
idx = findfirst(istypedef, src.code)
315+
r = LoweredCodeUtils.typedef_range(src, idx)
316+
@test last(r) == length(src.code) - 1
317+
end
307318

308319
@testset "Display" begin
309320
# worth testing because this has proven quite crucial for debugging and

0 commit comments

Comments
 (0)