Skip to content

Commit cdf1450

Browse files
authored
Add an "egal" variant of is_quotenode (#411)
To prevent invalidations one wants to avoid `==` and use `===` in circumstances where types can't be inferred. I should have thought of this earlier, as it would have saved some uglification.
1 parent 9563883 commit cdf1450

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/commands.jl

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,14 @@ function maybe_step_through_kwprep!(@nospecialize(recurse), frame::Frame, istopl
261261
stmt1 = src.code[pc+1]
262262
# We deliberately check isexpr(stmt, :call) rather than is_call(stmt): if it's
263263
# assigned to a local, it's *not* kwarg preparation.
264-
if isexpr(stmt1, :call) && is_quotenode(stmt1.args[1], Core.apply_type) && is_quoted_type(stmt1.args[2], :NamedTuple)
264+
if isexpr(stmt1, :call) && is_quotenode_egal(stmt1.args[1], Core.apply_type) && is_quoted_type(stmt1.args[2], :NamedTuple)
265265
stmt4, stmt5 = src.code[pc+4], src.code[pc+5]
266-
if isexpr(stmt4, :call) && is_quotenode(stmt4.args[1], Core.kwfunc)
266+
if isexpr(stmt4, :call) && is_quotenode_egal(stmt4.args[1], Core.kwfunc)
267267
while pc < pccall
268268
pc = step_expr!(recurse, frame, istoplevel)
269269
end
270270
return frame
271-
elseif isexpr(stmt5, :call) && is_quotenode(stmt5.args[1], Core.kwfunc) && pccall+1 <= n
271+
elseif isexpr(stmt5, :call) && is_quotenode_egal(stmt5.args[1], Core.kwfunc) && pccall+1 <= n
272272
# This happens when the call is scoped by a module
273273
pccall += 1
274274
while pc < pccall
@@ -285,7 +285,7 @@ function maybe_step_through_kwprep!(@nospecialize(recurse), frame::Frame, istopl
285285
stmt1 = src.code[pc+1]
286286
if isexpr(stmt1, :call)
287287
f = stmt1.args[1]
288-
if is_quotenode(f, Base.pairs)
288+
if is_quotenode_egal(f, Base.pairs)
289289
# No supplied kwargs
290290
pcsplat = pc + 3
291291
if pcsplat <= n
@@ -300,20 +300,22 @@ function maybe_step_through_kwprep!(@nospecialize(recurse), frame::Frame, istopl
300300
pccall = pc + 2
301301
if pccall <= n
302302
stmt2 = src.code[pccall]
303-
if isexpr(stmt2, :call) && length(stmt2.args) >= 3 && stmt2.args[2] == SSAValue(pc+1) && stmt2.args[3] == SlotNumber(1)
304-
while pc < pccall
305-
pc = step_expr!(recurse, frame, istoplevel)
303+
if isa(stmt2, Expr)
304+
if stmt2.head === :call && length(stmt2.args) >= 3 && stmt2.args[2] === SSAValue(pc+1) && stmt2.args[3] === SlotNumber(1)
305+
while pc < pccall
306+
pc = step_expr!(recurse, frame, istoplevel)
307+
end
306308
end
307309
end
308310
end
309-
elseif is_quotenode(f, Base.merge) && ((pccall = pc + 7) <= n)
311+
elseif is_quotenode_egal(f, Base.merge) && ((pccall = pc + 7) <= n)
310312
stmtk = src.code[pccall-1]
311-
if isexpr(stmtk, :call) && is_quotenode(stmtk.args[1], Core.kwfunc)
313+
if isexpr(stmtk, :call) && is_quotenode_egal(stmtk.args[1], Core.kwfunc)
312314
for i = 1:4
313315
pc = step_expr!(recurse, frame, istoplevel)
314316
end
315317
stmti = src.code[pc]
316-
if isexpr(stmti, :call) && is_quotenode(stmti.args[1], Core.kwfunc)
318+
if isexpr(stmti, :call) && is_quotenode_egal(stmti.args[1], Core.kwfunc)
317319
pc = step_expr!(recurse, frame, istoplevel)
318320
end
319321
end

src/utils.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ Tests whether `g` is equal to `GlobalRef(mod, name)`.
160160
is_global_ref(@nospecialize(g), mod::Module, name::Symbol) = isa(g, GlobalRef) && g.mod === mod && g.name == name
161161

162162
is_quotenode(@nospecialize(q), @nospecialize(val)) = isa(q, QuoteNode) && q.value == val
163+
is_quotenode_egal(@nospecialize(q), @nospecialize(val)) = isa(q, QuoteNode) && q.value === val
163164

164165
function is_quoted_type(@nospecialize(a), name::Symbol)
165166
if isa(a, QuoteNode)
@@ -187,14 +188,14 @@ is_dummy(bpref::BreakpointRef) = bpref.stmtidx == 0 && bpref.err === nothing
187188

188189
if VERSION >= v"1.4.0-DEV.304"
189190
function unpack_splatcall(stmt)
190-
if isexpr(stmt, :call) && length(stmt.args) >= 3 && is_quotenode(stmt.args[1], Core._apply_iterate)
191+
if isexpr(stmt, :call) && length(stmt.args) >= 3 && is_quotenode_egal(stmt.args[1], Core._apply_iterate)
191192
return true, stmt.args[3]
192193
end
193194
return false, nothing
194195
end
195196
else
196197
function unpack_splatcall(stmt)
197-
if isexpr(stmt, :call) && length(stmt.args) >= 2 && is_quotenode(stmt.args[1], Core._apply)
198+
if isexpr(stmt, :call) && length(stmt.args) >= 2 && is_quotenode_egal(stmt.args[1], Core._apply)
198199
return true, stmt.args[2]
199200
end
200201
return false, nothing

0 commit comments

Comments
 (0)