Skip to content

code_ircode does not distinguish varags from tuples #58753

Closed
@mhauru

Description

@mhauru

The IR returned by code_ircode and code_ircode_by_type seems to not distinguish between functions that take tuple arguments and ones that take varags. This is giving me a headache when working with code that gets the IR of a function, modifies it, and creates an OpaqueClosure based on it; The varargs nature of a function is lost in the process.

To illustrate:

julia> module MWE

       f(tup) = tup[1] + tup[2]
       ir_f = Base.code_ircode_by_type(Tuple{typeof(f), Tuple{Float64, Float64}})[1][1]
       oc_f = Core.OpaqueClosure(ir_f)
       @show typeof(oc_f)
       @show oc_f((0.1, 0.2))

       g(args...) = args[1] + args[2]
       ir_g = Base.code_ircode_by_type(Tuple{typeof(g), Float64, Float64})[1][1]
       oc_g = Core.OpaqueClosure(ir_g)
       @show typeof(oc_g)
       @show oc_g(0.1, 0.2)

       end
WARNING: replacing module MWE.
typeof(oc_f) = Core.OpaqueClosure{Tuple{Tuple{Float64, Float64}}, Float64}
oc_f((0.1, 0.2)) = 0.30000000000000004
typeof(oc_g) = Core.OpaqueClosure{Tuple{Tuple{Float64, Float64}}, Float64}
ERROR: MethodError: no method matching (::Core.OpaqueClosure{Tuple{Tuple{Float64, Float64}}, Float64})(::Float64, ::Float64)
This error has been manually thrown, explicitly, so the method may exist but be intentionally marked as unimplemented.

Closest candidates are:
  (::Core.OpaqueClosure{Tuple{Tuple{Float64, Float64}}, Float64})(::Tuple{Float64, Float64}) (method too new to be called from this world context.)
   @ Core :0

Is this intended behaviour? If so, is there a recommended way to work around the OpaqueClosure issue I'm having?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions