swift
afe9307c - [AutoDiff] Change `@differentiable` syntax to use parameter names. (#22000)

Commit
6 years ago
[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`.
Author
Committer
Parents
Loading