Skip to content

Constprop & specialization annotations are inconsistently applied to kw methods #45050

@timholy

Description

@timholy

Case 1: missing constprop annotation on kw method

julia> Base.@constprop :none f(@nospecialize(A); x::Int=1) = 2x
f (generic function with 1 method)

julia> m = only(methods(f))
f(A; x) in Main at REPL[1]:1

julia> m.constprop
0x02

julia> m.nospecialize
1

julia> fkw = Core.kwfunc(f)
f##kw (generic function with 1 method)

julia> mkw = only(methods(fkw))
(::var"#f##kw")(::Any, ::typeof(f), A) in Main at REPL[1]:1

julia> mkw.constprop
0x00                                               # should be 0x02

julia> mkw.nospecialize
4

Case 2: arg-wide @nospecialize does not propagate to kw method

julia> Base.@constprop :none f(A; x::Int=1) = (@nospecialize; 2x)
f (generic function with 1 method)

julia> m = only(methods(f))
f(A; x) in Main at REPL[1]:1

julia> m.constprop
0x02

julia> m.nospecialize
-1

julia> fkw = Core.kwfunc(f)
f##kw (generic function with 1 method)

julia> mkw = only(methods(fkw))
(::var"#f##kw")(::Any, ::typeof(f), A) in Main at REPL[1]:1

julia> mkw.constprop
0x00                                         # should be 0x02

julia> mkw.nospecialize
0                                               # should be -1

Metadata

Metadata

Assignees

No one assigned

    Labels

    compiler:loweringSyntax lowering (compiler front end, 2nd stage)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions