Skip to content

Commit 37d1458

Browse files
Kenotimholy
authored andcommitted
Track GlobalRef consistently
Companion PR to JuliaDebug/LoweredCodeUtils.jl#107. With both of these and JuliaDebug/JuliaInterpreter.jl#634, basic Revise functionality is working for me again on Julia master.
1 parent 54ee94a commit 37d1458

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

Diff for: src/lowered.jl

+21-12
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ Since the contents of such expression are difficult to analyze, it is generally
8585
safest to execute all such evals.
8686
"""
8787
function minimal_evaluation!(@nospecialize(predicate), methodinfo, mod::Module, src::Core.CodeInfo, mode::Symbol)
88-
edges = CodeEdges(src)
88+
edges = CodeEdges(mod, src)
8989
# LoweredCodeUtils.print_with_code(stdout, src, edges)
9090
isrequired = fill(false, length(src.code))
91-
namedconstassigned = Dict{Symbol,Bool}()
91+
namedconstassigned = Dict{GlobalRef,Bool}()
9292
evalassign = false
9393
for (i, stmt) in enumerate(src.code)
9494
if !isrequired[i]
@@ -99,18 +99,24 @@ function minimal_evaluation!(@nospecialize(predicate), methodinfo, mod::Module,
9999
end
100100
end
101101
if isexpr(stmt, :const)
102-
name = stmt.args[1]::Symbol
103-
namedconstassigned[name] = false
102+
name = stmt.args[1]
103+
if isa(name, Symbol)
104+
name = GlobalRef(mod, name)
105+
end
106+
namedconstassigned[name::GlobalRef] = false
104107
elseif isexpr(stmt, :(=))
105108
lhs = (stmt::Expr).args[1]
106109
if isa(lhs, Symbol)
110+
lhs = GlobalRef(mod, name)
111+
end
112+
if isa(lhs, GlobalRef)
107113
if haskey(namedconstassigned, lhs)
108114
namedconstassigned[lhs] = true
109115
end
110116
end
111117
if mode === :evalassign
112118
evalassign = isrequired[i] = true
113-
if isa(lhs, Symbol)
119+
if isa(lhs, GlobalRef)
114120
isrequired[edges.byname[lhs].succs] .= true # mark any `const` statements or other "uses" in this block
115121
end
116122
end
@@ -119,7 +125,7 @@ function minimal_evaluation!(@nospecialize(predicate), methodinfo, mod::Module,
119125
if mode === :sigs
120126
for (name, isassigned) in namedconstassigned
121127
isassigned || continue
122-
if isdefined(mod, name)
128+
if isdefined(name.mod, name.name)
123129
empty!(edges.byname[name].succs) # avoid redefining `consts` in `:sigs` mode (fixes #789)
124130
end
125131
end
@@ -225,7 +231,7 @@ function methods_by_execution!(@nospecialize(recurse), methodinfo, docexprs, mod
225231
Core.eval(mod, ex)
226232
catch err
227233
(always_rethrow || isa(err, InterruptException)) && rethrow(err)
228-
loc = location_string(whereis(frame)...)
234+
loc = location_string(whereis(frame))
229235
bt = trim_toplevel!(catch_backtrace())
230236
throw(ReviseEvalException(loc, err, Any[(sf, 1) for sf in stacktrace(bt)]))
231237
end
@@ -248,7 +254,7 @@ function methods_by_execution!(@nospecialize(recurse), methodinfo, docexprs, mod
248254
methods_by_execution!(recurse, methodinfo, docexprs, frame, isrequired; mode=mode, kwargs...)
249255
catch err
250256
(always_rethrow || isa(err, InterruptException)) && (disablebp && foreach(enable, active_bp_refs); rethrow(err))
251-
loc = location_string(whereis(frame)...)
257+
loc = location_string(whereis(frame))
252258
sfs = [] # crafted for interaction with Base.show_backtrace
253259
frame = JuliaInterpreter.leaf(frame)
254260
while frame !== nothing
@@ -309,10 +315,13 @@ function methods_by_execution!(@nospecialize(recurse), methodinfo, docexprs, fra
309315
# However, it might have been followed by a thunk that defined a
310316
# method (issue #435), so we still need to check for additions.
311317
if !isempty(signatures)
312-
file, line = whereis(frame.framecode, pc)
313-
lnn = LineNumberNode(Int(line), Symbol(file))
314-
for sig in signatures
315-
add_signature!(methodinfo, sig, lnn)
318+
loc = whereis(frame.framecode, pc)
319+
if loc !== nothing
320+
file, line = loc
321+
lnn = LineNumberNode(Int(line), Symbol(file))
322+
for sig in signatures
323+
add_signature!(methodinfo, sig, lnn)
324+
end
316325
end
317326
end
318327
pc = next_or_nothing!(frame)

Diff for: src/parsing.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function process_source!(mod_exprs_sigs::ModuleExprsSigs, ex, filename, mod::Mod
5858
catch err
5959
bt = trim_toplevel!(catch_backtrace())
6060
lnn = firstline(ex)
61-
loc = location_string(lnn.file, lnn.line)
61+
loc = location_string((lnn.file, lnn.line))
6262
throw(ReviseEvalException(loc, err, Any[(sf, 1) for sf in stacktrace(bt)]))
6363
end
6464
end

Diff for: src/utils.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ firstline(rex::RelocatableExpr) = firstline(rex.ex)
5959

6060
newloc(methloc::LineNumberNode, ln, lno) = fixpath(ln)
6161

62-
location_string(file::AbstractString, line) = abspath(file)*':'*string(line)
63-
location_string(file::Symbol, line) = location_string(string(file), line)
62+
location_string((file, line)::Tuple{AbstractString, Any},) = abspath(file)*':'*string(line)
63+
location_string((file, line)::Tuple{Symbol, Any},) = location_string(string(file), line)
64+
location_string(::Nothing) = "unknown location"
6465

6566
function linediff(la::LineNumberNode, lb::LineNumberNode)
6667
(isa(la.file, Symbol) && isa(lb.file, Symbol) && (la.file::Symbol === lb.file::Symbol)) || return typemax(Int)

0 commit comments

Comments
 (0)