Skip to content

Commit

Permalink
Add an "egal" variant of is_quotenode (#411)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
timholy authored Jun 22, 2020
1 parent 9563883 commit cdf1450
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
22 changes: 12 additions & 10 deletions src/commands.jl
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,14 @@ function maybe_step_through_kwprep!(@nospecialize(recurse), frame::Frame, istopl
stmt1 = src.code[pc+1]
# We deliberately check isexpr(stmt, :call) rather than is_call(stmt): if it's
# assigned to a local, it's *not* kwarg preparation.
if isexpr(stmt1, :call) && is_quotenode(stmt1.args[1], Core.apply_type) && is_quoted_type(stmt1.args[2], :NamedTuple)
if isexpr(stmt1, :call) && is_quotenode_egal(stmt1.args[1], Core.apply_type) && is_quoted_type(stmt1.args[2], :NamedTuple)
stmt4, stmt5 = src.code[pc+4], src.code[pc+5]
if isexpr(stmt4, :call) && is_quotenode(stmt4.args[1], Core.kwfunc)
if isexpr(stmt4, :call) && is_quotenode_egal(stmt4.args[1], Core.kwfunc)
while pc < pccall
pc = step_expr!(recurse, frame, istoplevel)
end
return frame
elseif isexpr(stmt5, :call) && is_quotenode(stmt5.args[1], Core.kwfunc) && pccall+1 <= n
elseif isexpr(stmt5, :call) && is_quotenode_egal(stmt5.args[1], Core.kwfunc) && pccall+1 <= n
# This happens when the call is scoped by a module
pccall += 1
while pc < pccall
Expand All @@ -285,7 +285,7 @@ function maybe_step_through_kwprep!(@nospecialize(recurse), frame::Frame, istopl
stmt1 = src.code[pc+1]
if isexpr(stmt1, :call)
f = stmt1.args[1]
if is_quotenode(f, Base.pairs)
if is_quotenode_egal(f, Base.pairs)
# No supplied kwargs
pcsplat = pc + 3
if pcsplat <= n
Expand All @@ -300,20 +300,22 @@ function maybe_step_through_kwprep!(@nospecialize(recurse), frame::Frame, istopl
pccall = pc + 2
if pccall <= n
stmt2 = src.code[pccall]
if isexpr(stmt2, :call) && length(stmt2.args) >= 3 && stmt2.args[2] == SSAValue(pc+1) && stmt2.args[3] == SlotNumber(1)
while pc < pccall
pc = step_expr!(recurse, frame, istoplevel)
if isa(stmt2, Expr)
if stmt2.head === :call && length(stmt2.args) >= 3 && stmt2.args[2] === SSAValue(pc+1) && stmt2.args[3] === SlotNumber(1)
while pc < pccall
pc = step_expr!(recurse, frame, istoplevel)
end
end
end
end
elseif is_quotenode(f, Base.merge) && ((pccall = pc + 7) <= n)
elseif is_quotenode_egal(f, Base.merge) && ((pccall = pc + 7) <= n)
stmtk = src.code[pccall-1]
if isexpr(stmtk, :call) && is_quotenode(stmtk.args[1], Core.kwfunc)
if isexpr(stmtk, :call) && is_quotenode_egal(stmtk.args[1], Core.kwfunc)
for i = 1:4
pc = step_expr!(recurse, frame, istoplevel)
end
stmti = src.code[pc]
if isexpr(stmti, :call) && is_quotenode(stmti.args[1], Core.kwfunc)
if isexpr(stmti, :call) && is_quotenode_egal(stmti.args[1], Core.kwfunc)
pc = step_expr!(recurse, frame, istoplevel)
end
end
Expand Down
5 changes: 3 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ Tests whether `g` is equal to `GlobalRef(mod, name)`.
is_global_ref(@nospecialize(g), mod::Module, name::Symbol) = isa(g, GlobalRef) && g.mod === mod && g.name == name

is_quotenode(@nospecialize(q), @nospecialize(val)) = isa(q, QuoteNode) && q.value == val
is_quotenode_egal(@nospecialize(q), @nospecialize(val)) = isa(q, QuoteNode) && q.value === val

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

if VERSION >= v"1.4.0-DEV.304"
function unpack_splatcall(stmt)
if isexpr(stmt, :call) && length(stmt.args) >= 3 && is_quotenode(stmt.args[1], Core._apply_iterate)
if isexpr(stmt, :call) && length(stmt.args) >= 3 && is_quotenode_egal(stmt.args[1], Core._apply_iterate)
return true, stmt.args[3]
end
return false, nothing
end
else
function unpack_splatcall(stmt)
if isexpr(stmt, :call) && length(stmt.args) >= 2 && is_quotenode(stmt.args[1], Core._apply)
if isexpr(stmt, :call) && length(stmt.args) >= 2 && is_quotenode_egal(stmt.args[1], Core._apply)
return true, stmt.args[2]
end
return false, nothing
Expand Down

0 comments on commit cdf1450

Please sign in to comment.