Repository navigation
autodiff: don't ICE on parameter patterns or name clashes - #166684
Open
puranikyashaswin wants to merge 2 commits into
Open
puranikyashaswin wants to merge 2 commits into
puranikyashaswin wants to merge 2 commits into
Conversation
Collaborator
|
Some changes occurred in compiler/rustc_builtin_macros/src/autodiff.rs cc @ZuseZ4 |
Collaborator
|
rustbot has assigned @dingxiangfei2009. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Member
|
r? ZuseZ4 |
This comment has been minimized.
This comment has been minimized.
puranikyashaswin
force-pushed
the
autodiff-150328-150330
branch
from
November 28, 2026 02:59
2168466 to
b98627c
Compare
This branch has not been deployed
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 #150328
Fixes #150330
Parameters that aren't plain names, like
_,(a, b)or&x, no longer ICE. The generated function only passes its arguments on to the intrinsic, so it now binds each parameter to its name, or to a fresh name when there is none. The original function keeps its patterns. The exact snippet in #150328 already stops at the name check from #166196, so the tests use valid names.This changes code that compiled before. For
mut xandref xthe generated function now bindsxby value. Before,ref xpassed a&f64where the declaration saysf64and Enzyme stopped with "Cannot cast", andmut xgave anunused_mutwarning on the user's code. If you would rather have a plain error for patterns, I can make the first commit smaller.The second commit fixes the call in the generated function. It used plain paths for the generated function and the original one, so a parameter with the same name was picked up in their place, and codegen hit
bug!("invalid args"). The path now gets the mark thatmacro_rules!puts on tokens from its body. Local lookup keeps the mark, so no parameter matches it. Item lookup drops it, so the function is still found.Two functions in
param-patterns.rstake a tuple by value, so they are in thecheckrevision only. Enzyme fails on a tuple passed by value even with a plain name (Canonicalization failed), also without this PR.I ran
tests/ui/autodiff,tests/codegen-llvm/autodiffand the autodiff tests intests/prettyon a build with Enzyme, andtests/crashesand tidy on a build without it.