Skip to content

Commit

Permalink
Handle deeper call nesting in struct (#379)
Browse files Browse the repository at this point in the history
PR #363 broke certain types of structure definition.
  • Loading branch information
timholy committed Feb 17, 2020
1 parent a0e209e commit 69fdd41
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,18 @@ function set_structtype_const(mod::Module, name::Symbol)
ccall(:jl_set_const, Cvoid, (Any, Any, Any), mod, dt.name.name, dt.name.wrapper)
end

function inplace_lookup!(ex, i, frame)
a = ex.args[i]
if isa(a, SSAValue) || isa(a, SlotNumber)
ex.args[i] = lookup_var(frame, a)
elseif isexpr(a, :call)
for j = 1:length(a.args)
inplace_lookup!(a, j, frame)
end
end
return ex
end

function evaluate_structtype(@nospecialize(recurse), frame, node)
grsvec!(ex::Expr) = (ex.args[1] = GlobalRef(Core, :svec); return ex)

Expand All @@ -302,16 +314,7 @@ function evaluate_structtype(@nospecialize(recurse), frame, node)
for idx in (2, 3, 5)
ex = newstructexpr.args[idx] = grsvec!(copy(node.args[idx]))
for i = 2:length(ex.args)
a = ex.args[i]
if isa(a, SSAValue) || isa(a, SlotNumber)
ex.args[i] = lookup_var(frame, a)
elseif isexpr(a, :call)
for (j, aa) in enumerate(a.args)
if isa(aa, SSAValue) || isa(aa, SlotNumber)
a.args[j] = lookup_var(frame, aa)
end
end
end
inplace_lookup!(ex, i, frame)
end
end
Core.eval(mod, newstructexpr)
Expand Down
16 changes: 16 additions & 0 deletions test/toplevel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,19 @@ end
JuliaInterpreter.finish!(frame, true)
@test Toplevel.RecursiveType(Vector{Toplevel.RecursiveType}()) isa Toplevel.RecursiveType
end

# https://github.com/timholy/Revise.jl/issues/420
module ToplevelParameters
Base.@kwdef struct MyStruct
x::Array{<:Real, 1} = [.05]
end
end
@testset "Nested references in type definitions" begin
ex = quote
Base.@kwdef struct MyStruct
x::Array{<:Real, 1} = [.05]
end
end
frame = JuliaInterpreter.prepare_thunk(ToplevelParameters, ex)
@test JuliaInterpreter.finish!(frame, true) === nothing
end

0 comments on commit 69fdd41

Please sign in to comment.