Skip to content

Commit

Permalink
Merge pull request #120 from JuliaDebug/kc/getfield
Browse files Browse the repository at this point in the history
only do the getfield optimization when it is safe
  • Loading branch information
timholy authored Mar 7, 2019
2 parents a1b0efd + 3566a9d commit 9e6b118
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/JuliaInterpreter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,10 @@ function lookup_global_refs!(ex::Expr)
for (i, a) in enumerate(ex.args)
ex.head == :(=) && i == 1 && continue # Don't look up globalrefs on the LHS of an assignment (issue #98)
if isa(a, GlobalRef)
r = getfield(a.mod, a.name)
ex.args[i] = QuoteNode(r)
if isdefined(a.mod, a.name) && isconst(a.mod, a.name)
r = getfield(a.mod, a.name)
ex.args[i] = QuoteNode(r)
end
elseif isa(a, Expr)
lookup_global_refs!(a)
end
Expand Down
18 changes: 18 additions & 0 deletions test/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,21 @@ f113(;x) = x
@test length(locals) == 3
@test JuliaInterpreter.Variable(3, :x, false) in locals
end

@testset "getfield replacements" begin
f_gf(x) = false ? some_undef_var_zzzzzzz : x
@test @interpret f_gf(2) == 2

function g_gf()
eval(:(z = 2))
return z
end
@test @interpret g_gf() == 2

global q_gf = 0
function h_gf()
eval(:(q_gf = 2))
return q_gf
end
@test @interpret h_gf() == 2
end

0 comments on commit 9e6b118

Please sign in to comment.