Skip to content

@opt_out function checking is evil #545

Closed
@mzgubic

Description

@mzgubic

Found in FluxML/Zygote.jl#1146 (comment) It will complain if the wrong function name is defined

julia> ChainRulesCore.@opt_out myrrule(::typeof(Base.:*), ::MyMatrix, ::AbstractMatrix{<:Real})
ERROR: LoadError: Unexpected opt-out target. Exprected frule or rrule, got: myrrule
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] _no_rule_target_rewrite!(call_target::Symbol)
   @ ChainRulesCore ~/JuliaEnvs/Zygote.jl/dev/ChainRulesCore/src/rule_definition_tools.jl:520
 [3] _no_rule_target_rewrite!(expr::Expr)
   @ ChainRulesCore ~/JuliaEnvs/Zygote.jl/dev/ChainRulesCore/src/rule_definition_tools.jl:505
 [4] var"@opt_out"(__source__::LineNumberNode, __module__::Module, expr::Any)
   @ ChainRulesCore ~/JuliaEnvs/Zygote.jl/dev/ChainRulesCore/src/rule_definition_tools.jl:493
in expression starting at REPL[14]:1

But not if rrule (rather than ChainRulesCore.rrule) is used, when it does the wrong thing:

julia> ChainRulesCore.@opt_out rrule(::typeof(Base.:*), ::MyMatrix, ::AbstractMatrix{<:Real})
rrule (generic function with 1 method)

julia> methods(rrule)
# 1 method for generic function "rrule":
[1] rrule(::typeof(*), ::MyMatrix, ::AbstractMatrix{<:Real}) in Main

:trollface:

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