Skip to content

Commit 428c018

Browse files
authored
Merge pull request #59 from aviatesk/inferrabilitynerd
minor inferrability tweaks
2 parents 2f4f2dc + 3d6c2db commit 428c018

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

src/codeedges.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function postprint_linelinks(io::IO, idx::Int, src::CodeInfo, cl::CodeLinks, bbc
169169
stmt = src.code[idx]
170170
if isexpr(stmt, :(=))
171171
lhs = stmt.args[1]
172-
if isslotnum(lhs)
172+
if @issslotnum(lhs)
173173
# id = lhs.id
174174
# preds, succs = cl.slotpreds[id], cl.slotsuccs[id]
175175
printstyled(io, "see slot ", lhs.id, '\n', color=:yellow)
@@ -246,7 +246,7 @@ function direct_links!(cl::CodeLinks, src::CodeInfo)
246246
# An assignment
247247
stmt = stmt::Expr
248248
lhs, rhs = stmt.args[1], stmt.args[2]
249-
if isslotnum(lhs)
249+
if @issslotnum(lhs)
250250
lhs = lhs::AnySlotNumber
251251
id = lhs.id
252252
target = P(SlotNumber(id), cl.slotpreds[id])
@@ -278,11 +278,11 @@ function add_links!(target::Pair{Union{SSAValue,SlotNumber,NamedVar},Links}, @no
278278
_targetid, targetstore = target
279279
targetid = _targetid::Union{SSAValue,SlotNumber,NamedVar}
280280
# Adds bidirectional edges
281-
if isssa(stmt)
281+
if @isssa(stmt)
282282
stmt = stmt::AnySSAValue
283283
push!(targetstore, SSAValue(stmt.id)) # forward edge
284284
push!(cl.ssasuccs[stmt.id], targetid) # backward edge
285-
elseif isslotnum(stmt)
285+
elseif @issslotnum(stmt)
286286
stmt = stmt::AnySlotNumber
287287
push!(targetstore, SlotNumber(stmt.id))
288288
push!(cl.slotsuccs[stmt.id], targetid)
@@ -298,7 +298,7 @@ function add_links!(target::Pair{Union{SSAValue,SlotNumber,NamedVar},Links}, @no
298298
arng = 1:length(stmt.args)
299299
if stmt.head === :call
300300
f = stmt.args[1]
301-
if !isssa(f) && !isslotnum(f)
301+
if !@isssa(f) && !@issslotnum(f)
302302
# Avoid putting named callees on the namestore
303303
arng = 2:length(stmt.args)
304304
end
@@ -418,7 +418,7 @@ function CodeEdges(src::CodeInfo, cl::CodeLinks)
418418
stmt = stmt::Expr
419419
lhs = stmt.args[1]
420420
# Mark predecessors and successors of this line by following ssas & named assignments
421-
if isslotnum(lhs)
421+
if @issslotnum(lhs)
422422
lhs = lhs::AnySlotNumber
423423
# This line assigns a slot. Mark all predecessors.
424424
id = lhs.id
@@ -796,7 +796,7 @@ function selective_eval!(@nospecialize(recurse), frame::Frame, isrequired::Abstr
796796
pcexec = te ? pc : pcexec
797797
end
798798
isa(pc, BreakpointRef) && return pc
799-
pcexec = pcexec === nothing ? pclast : pcexec
799+
pcexec = (pcexec === nothing ? pclast : pcexec)::Int
800800
frame.pc = pcexec
801801
node = pc_expr(frame)
802802
is_return(node) && return lookup_return(frame, node)

src/utils.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
const AnySSAValue = Union{Core.Compiler.SSAValue,JuliaInterpreter.SSAValue}
22
const AnySlotNumber = Union{Core.Compiler.SlotNumber,JuliaInterpreter.SlotNumber}
33

4-
isssa(stmt) = isa(stmt, Core.Compiler.SSAValue) | isa(stmt, JuliaInterpreter.SSAValue)
5-
isslotnum(stmt) = isa(stmt, Core.Compiler.SlotNumber) | isa(stmt, JuliaInterpreter.SlotNumber)
4+
# to circumvent https://github.com/JuliaLang/julia/issues/37342, we inline these `isa`
5+
# condition checks at surface AST level
6+
# https://github.com/JuliaLang/julia/pull/38905 will get rid of the need of these hacks
7+
macro isssa(stmt)
8+
:($(GlobalRef(Core, :isa))($(esc(stmt)), $(GlobalRef(Core.Compiler, :SSAValue))) ||
9+
$(GlobalRef(Core, :isa))($(esc(stmt)), $(GlobalRef(JuliaInterpreter, :SSAValue))))
10+
end
11+
macro issslotnum(stmt)
12+
:($(GlobalRef(Core, :isa))($(esc(stmt)), $(GlobalRef(Core.Compiler, :SlotNumber))) ||
13+
$(GlobalRef(Core, :isa))($(esc(stmt)), $(GlobalRef(JuliaInterpreter, :SlotNumber))))
14+
end
615

716
"""
817
iscallto(stmt, name)

0 commit comments

Comments
 (0)