julia> eval(:($(Symbol(""))))
ERROR: syntax: all-underscore identifier used as rvalue around REPL[30]:2
There is no all-underscore identifier used here.
Came up in https://github.com/JuliaDebug/Debugger.jl/issues/20 when trying to update the local variables in the frame:
julia> bar(x; y=false) = nothing;
julia> ci = @code_lowered Core.kwfunc(bar)((y = 1.0,), bar, 3.0);
julia> ci.slotnames
6-element Array{Any,1}:
Symbol("#unused#")
Symbol("#temp#")
Symbol("")
:x
:y
Symbol("#temp#")
which contains the Symbol("")
.
There is no all-underscore identifier used here.
Isn't there? Which letter in ""
is not an underscore? :trollface:
This is what happens when a mathematician writes a parser :joy:
Can easily be worked around on the Debugger.jl side so feel free to close if this is cba-to-care territory.
So, I don't fully know what's going on in Debugger.jl here, but eval'ing symbols from slotnames
seems like a problem since those names aren't unique; they're basically debug info. For example this function has two :x
s in its slotnames:
function f(x)
let x = x
x
end
end
Would it make sense to just change what is considered an "all-underscore identifier" and require it to contain at least one underscore, even though technically ""
is all underscores?
Yes, sure. I imagine that code was written assuming empty symbols would not occur.
but eval'ing symbols from slotnames seems like a problem since those names aren't unique; they're basically debug info.
Is it strange for a debugger to use the debug info? And whole they aren't unique, we know which one of them that was last assigned.
By "debug info" I meant information for display, that is not part of the program's meaning. So it depends on how the debugger uses it. Anyway, I just wanted to call attention to that in case it was surprising.
Not a problem because they get two different symbolsslots:
julia> @code_lowered f(1)
CodeInfo(
1 ─ %1 = x@_2
│ x@_3 = %1
└── return x@_3
)
JuliaInterpreter keeps a Dict
called last_reference
that holds the slot number to which x
was last assigned.
@JeffBezanson, can I ask you to look at this related question? https://github.com/JuliaDebug/JuliaInterpreter.jl/pull/54#discussion_r260738406 Nvm, I think your example above was enough for me to figure this out.
This is part of the functionality where you can evaluate code (and thereby update variables in a frame that is being interpreter). The code that gets evaluated is something like
let x = x0, y = y0, z = z0...
ret = <input code to be evaluated>
ret, (x, y, z)
end
<update the slots with the new x, y, z>
where x, y, z
are local variables with the values x0, y0, z0
. In this frame it just happened that there was a local variable with the name Symbol("")
that made this expression invalid.
Most helpful comment
Isn't there? Which letter in
""
is not an underscore? :trollface: