Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@opt_out function checking is evil #545

Closed
mzgubic opened this issue Feb 21, 2022 · 0 comments · Fixed by #546
Closed

@opt_out function checking is evil #545

mzgubic opened this issue Feb 21, 2022 · 0 comments · Fixed by #546

Comments

@mzgubic
Copy link
Member

mzgubic commented Feb 21, 2022

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant