Skip to content

autodiff: don't ICE on parameter patterns or name clashes - #166684

Open
puranikyashaswin wants to merge 2 commits into
rust-lang:mainfrom
puranikyashaswin:autodiff-150328-150330
Open

puranikyashaswin wants to merge 2 commits into
rust-lang:mainfrom
puranikyashaswin:autodiff-150328-150330

Conversation

@puranikyashaswin

Copy link
Copy Markdown
Contributor

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 x and ref x the generated function now binds x by value. Before, ref x passed a &f64 where the declaration says f64 and Enzyme stopped with "Cannot cast", and mut x gave an unused_mut warning 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 that macro_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.rs take a tuple by value, so they are in the check revision 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/autodiff and the autodiff tests in tests/pretty on a build with Enzyme, and tests/crashes and tidy on a build without it.

@rustbot

rustbot commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_builtin_macros/src/autodiff.rs

cc @ZuseZ4

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 28, 2026
@rustbot

rustbot commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

r? @dingxiangfei2009

rustbot has assigned @dingxiangfei2009.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 79 candidates
  • Random selection from 19 candidates

@ZuseZ4

ZuseZ4 commented Nov 28, 2026

Copy link
Copy Markdown
Member

r? ZuseZ4

@rustbot rustbot assigned ZuseZ4 and unassigned dingxiangfei2009 Nov 28, 2026
@rust-log-analyzer

This comment has been minimized.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE: autodiff: invalid args ICE: autodiff: not an ident?

5 participants