Repository navigation
Conversation
…iff#334) Since 1.18.8 the methods generated by `@grad_from_chainrules` name their self-argument `func`. Macro hygiene does not rename the self-argument of a callable-object method, so a rule with an argument that is also named `func`, such as ImplicitAD's `_provide_rule(func, x, ...)`, failed with "function argument name not unique". The self-argument now has a name from `gensym`. Fixes JuliaDiff#334 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
Thanks, but I'll close this in favour of #335. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #334.
Since 1.18.8 (#328) the methods generated by
@grad_from_chainrulesname their self-argumentfunc:Macro hygiene does not rename the self-argument of a callable-object method, so a rule with an argument also named
funcproduced a signature with two arguments calledfuncand failed withsyntax: function argument name not unique: "func". This breaks the precompilation of ImplicitAD.jl, which declaresReverseDiff.@grad_from_chainrules _provide_rule(func, x::ReverseDiff.TrackedArray, p, mode, jacobian, jvp, vjp).Change:
@grad_from_chainrulesbinds the self-argument to a name fromgensym(:func)and uses it in both generated methods, so no argument name can collide with it. Only the callable method needs it (hygiene does rename thefuncargument oftrack), but one name for both keeps them consistent.@gradis not changed: itstrack(func::..., ...)method is an ordinary method, whose argument hygiene renames, and an argument namedfuncis already covered by its tests (f15inMacrosTests.jl). On 1.18.8 we tried 13 argument names (f,func,args,kwargs,tp,output_value,back,output,closure,cls_args,instruction,input,self) with both macros. Onlyfuncwith@grad_from_chainrulesfailed.Test: a testset "argument named func" next to "argument names" in
test/ChainRulesTests.jl, with a rulef_func(func, x). On master the file fails to load with the error above; with the change it passes.Tests run: the full test suite with this change passes: 12792 passed, 9 broken (the existing
@test_brokeninderivatives/ArrayFunctionTests.jl), 0 failed, on Julia 1.12.5, Linux x86_64 (Pkg.test(test_args=["--jobs=4"])).This PR does not conflict with #332 (
git merge-treeis clean).