Skip to content

Commit d439cac

Browse files
authored
A couple of invalidation fixes and nospecialize annotations (#29)
1 parent b92890e commit d439cac

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/LoweredCodeUtils.jl

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ export signature, rename_framemethods!, methoddef!, methoddefs!, bodymethod
1414
1515
Returns `true` is `stmt` is a call expression to `name`.
1616
"""
17-
function iscallto(stmt, name)
17+
function iscallto(@nospecialize(stmt), name)
1818
if isexpr(stmt, :call)
1919
a = stmt.args[1]
20-
a == name && return true
21-
return is_global_ref(a, Core, :_apply) && stmt.args[2] == name
20+
a === name && return true
21+
return is_global_ref(a, Core, :_apply) && stmt.args[2] === name
2222
end
2323
return false
2424
end
@@ -28,7 +28,7 @@ end
2828
2929
Returns the function (or Symbol) being called in a :call expression.
3030
"""
31-
function getcallee(stmt)
31+
function getcallee(@nospecialize(stmt))
3232
if isexpr(stmt, :call)
3333
a = stmt.args[1]
3434
is_global_ref(a, Core, :_apply) && return stmt.args[2]
@@ -149,7 +149,7 @@ end
149149
signature(@nospecialize(recurse), frame::Frame, pc) = signature(recurse, frame, pc_expr(frame, pc), pc)
150150
signature(frame::Frame, pc) = signature(finish_and_return!, frame, pc)
151151

152-
function minid(node, stmts, id)
152+
function minid(@nospecialize(node), stmts, id)
153153
if isa(node, SSAValue)
154154
id = min(id, node.id)
155155
stmt = stmts[node.id]
@@ -162,7 +162,7 @@ function minid(node, stmts, id)
162162
return id
163163
end
164164

165-
function signature_top(frame, stmt, pc)
165+
function signature_top(frame, stmt::Expr, pc)
166166
@assert ismethod3(stmt)
167167
return minid(stmt.args[2], frame.framecode.src.code, pc)
168168
end
@@ -185,7 +185,7 @@ function isanonymous_typedef(src::CodeInfo)
185185
end
186186
end
187187

188-
function define_anonymous(@nospecialize(recurse), frame, stmt)
188+
function define_anonymous(@nospecialize(recurse), frame, @nospecialize(stmt))
189189
while !isexpr(stmt, :method)
190190
pc = step_expr!(recurse, frame, stmt, true)
191191
stmt = pc_expr(frame, pc)
@@ -248,7 +248,7 @@ function identify_framemethod_calls(frame)
248248
end
249249
end
250250
elseif ismethod1(stmt)
251-
key = stmt.args[1]
251+
key = stmt.args[1]::Symbol
252252
mi = get(methodinfos, key, nothing)
253253
if mi === nothing
254254
methodinfos[key] = MethodInfo(i)
@@ -268,12 +268,14 @@ function identify_framemethod_calls(frame)
268268
for (j, mstmt) in enumerate(msrc.code)
269269
if isexpr(mstmt, :call)
270270
mkey = mstmt.args[1]
271-
isa(key, Expr) && @show mkey
272-
haskey(methodinfos, mkey) && push!(selfcalls, (linetop=i, linebody=j, callee=mkey, caller=key))
271+
if isa(mkey, Symbol)
272+
# Could be a GlobalRef but then it's outside frame
273+
haskey(methodinfos, mkey) && push!(selfcalls, (linetop=i, linebody=j, callee=mkey, caller=key))
274+
end
273275
elseif isexpr(mstmt, :meta) && mstmt.args[1] == :generated
274276
newex = mstmt.args[2]
275277
if isexpr(newex, :new) && length(newex.args) >= 2 && is_global_ref(newex.args[1], Core, :GeneratedFunctionStub)
276-
mkey = newex.args[2]
278+
mkey = newex.args[2]::Symbol
277279
haskey(methodinfos, mkey) && push!(selfcalls, (linetop=i, linebody=j, callee=mkey, caller=key))
278280
end
279281
end
@@ -391,7 +393,7 @@ function find_corrected_name(@nospecialize(recurse), frame, pc, name, parentname
391393
stmt = pc_expr(frame, pc)
392394
end
393395
body = stmt.args[3]
394-
if stmt.args[1] != name && isa(body, SSAValue)
396+
if stmt.args[1] !== name && isa(body, SSAValue)
395397
# OK, we can't skip all the stuff that might define the body
396398
# See https://github.com/timholy/Revise.jl/issues/398
397399
pc = pc0
@@ -403,10 +405,10 @@ function find_corrected_name(@nospecialize(recurse), frame, pc, name, parentname
403405
end
404406
body = @lookup(frame, stmt.args[3])
405407
end
406-
if stmt.args[1] != name && isa(body, CodeInfo)
408+
if stmt.args[1] !== name && isa(body, CodeInfo)
407409
# This might be the GeneratedFunctionStub for a @generated method
408410
for (i, bodystmt) in enumerate(body.code)
409-
if isexpr(bodystmt, :meta) && bodystmt.args[1] == :generated
411+
if isexpr(bodystmt, :meta) && bodystmt.args[1] === :generated
410412
return signature_top(frame, stmt, pc), true
411413
end
412414
i >= 5 && break # we should find this early
@@ -529,7 +531,7 @@ function methoddef!(@nospecialize(recurse), signatures, frame::Frame, @nospecial
529531
end
530532
if isa(meth, Method)
531533
push!(signatures, meth.sig)
532-
elseif stmt.args[1] == false
534+
elseif stmt.args[1] === false
533535
# If it's anonymous and not defined, define it
534536
pc = step_expr!(recurse, frame, stmt, true)
535537
meth = whichtt(sigt)
@@ -553,6 +555,7 @@ function methoddef!(@nospecialize(recurse), signatures, frame::Frame, @nospecial
553555
if isa(name, Bool)
554556
error("not valid for anonymous methods")
555557
end
558+
name = name::Symbol
556559
while true # methods containing inner methods may need multiple trips through this loop
557560
sigt, pc = signature(recurse, frame, stmt, pc)
558561
stmt = pc_expr(frame, pc)
@@ -570,7 +573,7 @@ function methoddef!(@nospecialize(recurse), signatures, frame::Frame, @nospecial
570573
pc = define ? step_expr!(recurse, frame, stmt, true) : next_or_nothing!(frame)
571574
meth = whichtt(sigt)
572575
isa(meth, Method) && push!(signatures, meth.sig) # inner methods are not visible
573-
name == name3 && return pc, pc3 # if this was an inner method we should keep going
576+
name === name3 && return pc, pc3 # if this was an inner method we should keep going
574577
stmt = pc_expr(frame, pc) # there *should* be more statements in this frame
575578
end
576579
end
@@ -614,7 +617,7 @@ function _methoddefs!(@nospecialize(recurse), signatures, frame::Frame, pc; defi
614617
return pc
615618
end
616619

617-
function is_self_call(stmt, slotnames, argno=1)
620+
function is_self_call(@nospecialize(stmt), slotnames, argno=1)
618621
if isa(stmt, Expr)
619622
if stmt.head == :call
620623
a = stmt.args[argno]

0 commit comments

Comments
 (0)