JuliaDiff / JuliaDiff/ChainRulesCore.jl

`@opt_out` scope problem

Open
#499 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug rule definition helper
Dominant language
Julia
Stars
267
Forks
66
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two @opt_out calls and inspecting the @macroexpand output shown in the issue. Trace how the macro resolves frule and rrule targets, then verify that an unimported target produces a method for ChainRulesCore.rrule without the unexpected-target or undefined-name behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.