Skip to content

Commit

Permalink
Fix #5752: Julia: Fix inclusion of methods of imported functions and …
Browse files Browse the repository at this point in the history
…handling of… (#5768)

… parametric methods

If the code contains a method, specializing a function that is defined
in a different module (e.g. Base), then the method would be ignored.

The `names` function offers the `imported` parameter, which leads to
inclusion of imported functions. However, this also leads to inclusion
of many methods that are not defined in the given code. To only consider
the methods from the input code, the input module `m` is passed to the
method searching call `methods(fun, m)`.

While debugging, another bug surfaced: methods with parametric types
would lead to an error, because the type for these methods is
represented differently. In this cases, `specTypes` is of type
`UnionAll`, which does not have a member `parameters`, but the members
`var` and `body` to represent the parametric structure of the type. Also
see https://docs.julialang.org/en/v1/devdocs/types/#UnionAll-types By
checking the `specType` member for the type `UnionAll`, this can be
fixed.

Fixes #5752

Co-authored-by: Alex Wiens <alex.wiens@uni-paderborn.de>
  • Loading branch information
aw32 and Alex Wiens committed Nov 21, 2023
1 parent e19d6ef commit 13e80af
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions etc/scripts/julia_wrapper.jl
Expand Up @@ -72,16 +72,22 @@ Base.include(m, input_file)

# Find functions and method specializations
m_methods = Any[]
for name in names(m, all=true)
for name in names(m, all=true, imported=true)
local fun = getfield(m, name)
if fun isa Function
if verbose
println("Function: ", fun)
end
for me in methods(fun)
# only show methods found in input module
for me in methods(fun, m)
for s in me.specializations
if s != nothing
me_types = getindex(s.specTypes.parameters, 2:length(s.specTypes.parameters))
spec_types = s.specTypes
# In case of a parametric type, see https://docs.julialang.org/en/v1/devdocs/types/#UnionAll-types
while typeof(spec_types) == UnionAll
spec_types = spec_types.body
end
me_types = getindex(spec_types.parameters, 2:length(spec_types.parameters))
push!(m_methods, (fun, me_types, me))
if verbose
println(" Method types: ", me_types)
Expand Down

0 comments on commit 13e80af

Please sign in to comment.