ChainRulesCore.jl icon indicating copy to clipboard operation
ChainRulesCore.jl copied to clipboard

`@opt_out` scope problem

Open mcabbott opened this issue 4 years ago • 1 comments

This macro only accepts a few functions. But if the ones it accepts aren't imported, it quietly does the wrong thing. Surely this should always make a method for ChainRulesCore.rrule:

julia> using ChainRulesCore: @opt_out

julia> ChainRulesCore.@opt_out *(::Rotation, ::Rotation)
ERROR: LoadError: Unexpected opt-out target. Exprected frule or rrule, got: *

julia> ChainRulesCore.@opt_out rrule(::typeof(*), ::Rotation, ::Rotation)
ERROR: LoadError: UndefVarError: ChainRulesCore not defined
in expression starting at REPL[3]:1

julia> using ChainRulesCore

julia> ChainRulesCore.@opt_out rrule(::typeof(*), ::Rotation, ::Rotation)
rrule (generic function with 1 method)

julia> @macroexpand ChainRulesCore.@opt_out rrule(::typeof(*), ::Rotation, ::Rotation)
quote
    ChainRulesCore.no_rrule(::typeof(*), ::Rotation, ::Rotation) = ChainRulesCore.nothing
    rrule(::typeof(*), ::Rotation, ::Rotation) = ChainRulesCore.nothing
end

mcabbott avatar Oct 23 '21 15:10 mcabbott

Yes, it would be good to fix this. This is on me, I knew it wasn't scoping right but wanted to get it in for the 1.0 deadline so we could test it and change it is it's API was wrong.

I probably should have openned an issue about it when the original PR was merged.

oxinabox avatar Oct 24 '21 08:10 oxinabox