Skip to content

Commit 79b1df2

Browse files
authored
Support GotoIfNot & ReturnNode (#38)
xref JuliaLang/julia#36318
1 parent 155da9f commit 79b1df2

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
name = "LoweredCodeUtils"
22
uuid = "6f1432cf-f94c-5a45-995e-cdbf5db27b0b"
33
authors = ["Tim Holy <[email protected]>"]
4-
version = "1.1.2"
4+
version = "1.1.3"
55

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

99
[compat]
10-
JuliaInterpreter = "0.7.16"
10+
JuliaInterpreter = "0.7.23"
1111
julia = "1"
1212

1313
[extras]

src/LoweredCodeUtils.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ module LoweredCodeUtils
1212
using JuliaInterpreter
1313
using JuliaInterpreter: SSAValue, SlotNumber, Frame
1414
using JuliaInterpreter: @lookup, moduleof, pc_expr, step_expr!, is_global_ref, is_quotenode, whichtt,
15-
next_until!, finish_and_return!, get_return, nstatements, codelocation, linetable
15+
next_until!, finish_and_return!, get_return, nstatements, codelocation, linetable,
16+
is_return, lookup_return, is_GotoIfNot, is_ReturnNode
1617

1718
include("packagedef.jl")
1819

src/codeedges.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ function add_links!(target::Pair{Union{SSAValue,SlotNumber,NamedVar},Links}, @no
304304
end
305305
elseif isa(stmt, QuoteNode)
306306
add_links!(target, stmt.value, cl)
307+
elseif is_GotoIfNot(stmt)
308+
add_links!(target, (stmt::Core.GotoIfNot).cond, cl)
309+
elseif is_ReturnNode(stmt)
310+
add_links!(target, (stmt::Core.ReturnNode).val, cl)
307311
end
308312
return nothing
309313
end
@@ -787,7 +791,7 @@ function selective_eval!(@nospecialize(recurse), frame::Frame, isrequired::Abstr
787791
pcexec = pcexec === nothing ? pclast : pcexec
788792
frame.pc = pcexec
789793
node = pc_expr(frame)
790-
isexpr(node, :return) && return @lookup(frame, (node::Expr).args[1])
794+
is_return(node) && return lookup_return(frame, node)
791795
isassigned(frame.framedata.ssavalues, pcexec) && return frame.framedata.ssavalues[pcexec]
792796
return nothing
793797
end

src/signatures.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,11 @@ function identify_framemethod_calls(frame)
142142
tsrc = stmt.args[1]::CodeInfo
143143
if length(tsrc.code) == 1
144144
tstmt = tsrc.code[1]
145-
if isa(tstmt, Expr)
146-
if tstmt.head === :return && length(tstmt.args) == 1
147-
tex = tstmt.args[1]
148-
if isa(tex, Expr)
149-
if tex.head === :method && (methname = tex.args[1]; isa(methname, Symbol))
150-
push!(refs, methname=>i)
151-
end
145+
if is_return(tstmt)
146+
tex = isa(tstmt, Expr) ? tstmt.args[1] : tstmt.val
147+
if isa(tex, Expr)
148+
if tex.head === :method && (methname = tex.args[1]; isa(methname, Symbol))
149+
push!(refs, methname=>i)
152150
end
153151
end
154152
end

src/utils.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ function typedef_range(src::CodeInfo, idx)
122122
if isa(stmt, Expr)
123123
(stmt.head === :global || stmt.head === :return) && break
124124
end
125+
is_return(stmt) && break
125126
iend += 1
126127
end
127128
iend <= n || (@show src; error("no final :global found"))

0 commit comments

Comments
 (0)