You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[AutoDiff] Change @differentiable syntax to use parameter names. (#22000)
* [AutoDiff] Change `@differentiable` syntax to use parameter names.
Use parameter names instead of parameter indices in `@differentiable` attribute `wrt` list.
The old syntax used parameter indices with a prefix dot, e.g. `wrt: (.0, .1)`.
The new syntax is more readable and understandable when good parameter names are chosen.
New syntax:
```
@differentiable(wrt: (self, input))
func applied(to input: Float) -> Output { ... }
```
The internal, lowered representation of parameter indices is unchanged. This patch affects
only AST attribute parsing/print.
Update `wrt` clause usages in stdlib and tests.
Todos:
- Support parameter name `self` in `wrt` clause, probably via escape backticks: ``self``.
- Low priority: add fixits/specific diagnostics for old parameter index style.
* Address comments from @rxwei.
- Don't allocate auxiliary vector.
- Update parameter index related diagnostics.
* Support single `wrt` parameter without parentheses.
Single `wrt` parameters don't require parenthesis.
The following are now valid:
```
@differentiable(wrt: x)
@differentiable(wrt: self)
```
Multiple parameters still require parentheses: `@differentiable(wrt: x, y)`.
* Rewrite stdlib usages of `@differentiable`, update libSyntax support.
Rewrite stdlib usages of `@differentiable` with one differentiation parameter:
`wrt: (self)` -> `wrt: self`.
Note: printing still always prints parentheses around the differentiation
parameter list.
* Fix `test/Syntax/round_trip_parse_gen.swift`.
0 commit comments