Skip to content

@overlay lowering unimplemented with keyword arguments #58700

Open
@mlechu

Description

@mlechu

As of #58076, Base.Experimental.@overlay returns the newly-created method (or, in the case of optional positional arguments, the method with the largest number of positional arguments). This isn't implemented for functions taking keyword arguments.

julia> function f end
f (generic function with 0 methods)

julia> y = Base.Experimental.@overlay nothing f(x) = x
f(x)
     @ Main REPL[1]:1

julia> y = Base.Experimental.@overlay nothing f(x; kw1) = x

julia> typeof(ans)
Nothing

We also end up with a lisp s-expression as the first argument to Expr(:method, ...)

julia> Meta.@lower Base.Experimental.@overlay nothing f(x; kw1) = x
:($(Expr(:thunk, CodeInfo(
1 ─       $(Expr(:method, :(Main.:(var"#(overlay nothing f)#2"))))
│         $(Expr(:latestworld))
│         $(Expr(:latestworld))
│         $(Expr(:latestworld))
│   %5  = Main.:(var"#(overlay nothing f)#2")
│   %6  =   builtin Core.typeof(%5)
│   %7  = Main.f
│   %8  =   dynamic Core.Typeof(%7)
│   %9  =   builtin Core.svec(%6, Core.Any, %8, Core.Any)
│   %10 =   builtin Core.svec()
│   %11 =   builtin Core.svec(%9, %10, $(QuoteNode(:(#= REPL[4]:1 =#))))
│         $(Expr(:method, :(Main.:(var"#(overlay nothing f)#2")), :(%11), CodeInfo(
    @ REPL[4]:1 within `unknown scope`
1 ─      $(Expr(:meta, :nkw, 1))
│   %2 = x
└──      return %2
)))
│         $(Expr(:latestworld))
│   %14 = Main.f
│   %15 =   dynamic Core.Typeof(%14)
│   %16 =   builtin Core.svec(%15, Core.Any)
│   %17 =   builtin Core.svec()
│   %18 =   builtin Core.svec(%16, %17, $(QuoteNode(:(#= REPL[4]:1 =#))))
│         $(Expr(:method, :(Main.nothing), :(%18), CodeInfo(
    @ REPL[4]:1 within `unknown scope`
1 ─ %1 =   dynamic Core.UndefKeywordError(:kw1)
│   %2 =   builtin Core.throw(%1)
│        kw1 = %2
│   %4 = Main.:(var"#(overlay nothing f)#2")
│   %5 = kw1
│   %6 =   dynamic (%4)(%5, #self#, x)
└──      return %6
)))
│         $(Expr(:latestworld))
│   %21 = Main.f
│   %22 =   dynamic Core.Typeof(%21)
│   %23 =   dynamic Core.kwftype(%22)
│   %24 = Main.f
│   %25 =   dynamic Core.Typeof(%24)
│   %26 =   builtin Core.svec(%23, Core.NamedTuple, %25, Core.Any)
│   %27 =   builtin Core.svec()
│   %28 =   builtin Core.svec(%26, %27, $(QuoteNode(:(#= REPL[4]:1 =#))))
│         $(Expr(:method, :(Main.nothing), :(%28), CodeInfo(
    @ REPL[4]:1 within `unknown scope`
1 ─       Core.NewvarNode(:(@_5))
│   %2  =   builtin Core.isdefined(@_2, :kw1)
└──       goto #3 if not %2
2 ─       @_5 = Core.getfield(@_2, :kw1)
└──       goto #4
3 ─ %6  =   dynamic Core.UndefKeywordError(:kw1)
└──       @_5 = Core.throw(%6)
4 ┄ %8  = @_5
│         kw1 = %8
│   %10 =   dynamic Base.keys(@_2)
│   %11 =   builtin Core.tuple(:kw1)
│   %12 =   dynamic Base.diff_names(%10, %11)
│   %13 =   dynamic Base.isempty(%12)
└──       goto #6 if not %13
5 ─       goto #7
6 ─         dynamic Base.kwerr(@_2, @_3, x)
7 ┄ %17 = Main.:(var"#(overlay nothing f)#2")
│   %18 = kw1
│   %19 =   dynamic (%17)(%18, @_3, x)
└──       return %19
)))
│         $(Expr(:latestworld))
│   %31 =   builtin Core.ifelse(false, false, nothing)
└──       return %31
))))

julia> names(Main; all=true)
11-element Vector{Symbol}:
 Symbol("##(overlay nothing f)#1")
 Symbol("##meta#64")
 Symbol("#(overlay nothing f)#1")
 Symbol("#f")
 ...

This was noticed while trying to address #58630.

Metadata

Metadata

Assignees

No one assigned

    Labels

    compiler:loweringSyntax lowering (compiler front end, 2nd stage)keyword argumentsf(x; keyword=arguments)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions