Skip to content

Commit

Permalink
fix #19897, regression in generated function reflection
Browse files Browse the repository at this point in the history
due to #19846
  • Loading branch information
JeffBezanson committed Jan 6, 2017
1 parent 5b6ff4a commit b8e0e06
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
6 changes: 2 additions & 4 deletions base/methodshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ function arg_decl_parts(m::Method)
else
tv = Any[tv...]
end
if m.isstaged
src = m.unspecialized.inferred
elseif isdefined(m, :source)
if isdefined(m, :source)
src = m.source
else
src = nothing
Expand All @@ -63,7 +61,7 @@ function kwarg_decl(m::Method, kwtype::DataType)
kwli = ccall(:jl_methtable_lookup, Any, (Any, Any, UInt), kwtype.name.mt, sig, max_world(m))
if kwli !== nothing
kwli = kwli::Method
src = kwli.isstaged ? kwli.unspecialized.inferred : kwli.source
src = kwli.source
kws = filter(x->!('#' in string(x)), src.slotnames[kwli.nargs+1:end])
# ensure the kwarg... is always printed last. The order of the arguments are not
# necessarily the same as defined in the function
Expand Down
2 changes: 1 addition & 1 deletion base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ Returns an array of lowered ASTs for the methods matching the given generic func
function code_lowered(f::ANY, t::ANY=Tuple)
asts = map(methods(f, t)) do m
m = m::Method
return uncompressed_ast(m, m.isstaged ? m.unspecialized.inferred : m.source)
return uncompressed_ast(m, m.source)
end
return asts
end
Expand Down
11 changes: 3 additions & 8 deletions base/serialize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,7 @@ function serialize(s::AbstractSerializer, meth::Method)
serialize(s, meth.nargs)
serialize(s, meth.isva)
serialize(s, meth.isstaged)
if meth.isstaged
serialize(s, uncompressed_ast(meth, meth.unspecialized.inferred))
else
serialize(s, uncompressed_ast(meth, meth.source))
end
serialize(s, uncompressed_ast(meth, meth.source))
nothing
end

Expand Down Expand Up @@ -642,13 +638,12 @@ function deserialize(s::AbstractSerializer, ::Type{Method})
meth.nargs = nargs
meth.isva = isva
# TODO: compress template
meth.source = template
if isstaged
linfo = ccall(:jl_new_method_instance_uninit, Ref{Core.MethodInstance}, ())
linfo.specTypes = Tuple
linfo.inferred = template
meth.unspecialized = linfo
else
meth.source = template
meth.generator = linfo
end
ftype = ccall(:jl_first_argument_datatype, Any, (Any,), sig)::DataType
if isdefined(ftype.name, :mt) && nothing === ccall(:jl_methtable_lookup, Any, (Any, Any, UInt), ftype.name.mt, sig, typemax(UInt))
Expand Down
2 changes: 1 addition & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ end

function show(io::IO, l::Core.MethodInstance)
if isdefined(l, :def)
if l.def.isstaged && l === l.def.unspecialized
if l.def.isstaged && l === l.def.generator
print(io, "MethodInstance generator for ")
show(io, l.def)
else
Expand Down
3 changes: 3 additions & 0 deletions test/staged.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,6 @@ let
decorate(bar)
@test in(typeof(bar), decorated)
end

# issue #19897
@test code_lowered(staged_t1, (Int,Int)) isa Array # check no error thrown

0 comments on commit b8e0e06

Please sign in to comment.