Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

`@grad` fails for qualified function names (`gensym(::Expr)`)

Open Beginner friendly
#318 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
86/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
julia
Domain
tooling

Research direction

Start in src/macros.jl at the closure = gensym(f) line identified in the issue, then read the surrounding @grad macro logic. Check the existing @grad tests and add a regression case for a qualified function name such as M.f. Done means the rule expands successfully for qualified names while existing unqualified-name behavior still passes.

Written by the indexing model from the issue text.

Description

@grad fails at macro expansion time if the function name is qualified, e.g. M.f or Base.:*:

using ReverseDiff

module M
    f(x) = sum(abs2, x)
end

M.f(x::ReverseDiff.TrackedArray) = ReverseDiff.track(M.f, x)
ReverseDiff.@grad function M.f(x)
    xv = ReverseDiff.value(x)
    return M.f(xv), Δ -> (2 .* Δ .* xv,)
end
ERROR: LoadError: MethodError: no method matching gensym(::Expr)
Stacktrace:
 [1] var"@grad"(__source__::LineNumberNode, __module__::Module, expr::Any)

Expected: this defines the rule, like it does for an unqualified name. Qualified names are the normal way to add a rule for a function you don't own, e.g. a Base or LinearAlgebra function for your own array type. @grad_from_chainrules LinearAlgebra.dot(...) already handles them.

Cause: closure = gensym(f) assumes f is a Symbol. A plain gensym(:grad) (or gensym()) would be enough. This is the same line as #135 (callable structs), but a fix for that issue alone won't necessarily cover this case.

ReverseDiff master (b796032, v1.18.4), Julia 1.13.1.

Dominant language
Julia
Stars
396
Forks
61
Avg merge
23h 18m
Merged PRs (30d)
16

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

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.

More from JuliaDiff/ReverseDiff.jl

All issues in JuliaDiff/ReverseDiff.jl

Similar issues

More Julia issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.