- Notifications
You must be signed in to change notification settings - Fork 10.6k
[AutoDiff] Initial support for differentiation of throwing functions #82653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| Tagging @JaapWijnen @kovdan01 |
| @swift-ci please test |
| @swift-ci please test |
| Windows fails in unrelated @swift-ci please test windows platform |
| @swift-ci please test |
| @swift-ci please test |
kovdan01 left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks! Functionally this is totally OK, but please consider addressing minor suggestions I've left in comments before merging this. Feel free to ignore though.
| @swift-ci please test |
| @swift-ci please test Windows platform |
| @swift-ci please test Windows platform |
This adds initial support for differentiation of functions that may produce
Errorresult. Essentially we wrap the pullback intoOptionaland emit a diamond-shape control flow pattern depending on whether the pullback value is available or not. VJP emission was modified to accommodate for this. In addition to this, some additional tricks are required astry_applyresult is not available in the instruction parent block, it is available in normal successor basic block.As a result we can now:
try_applyresult (that would be produced fromdo ... try .. catchconstructions)try_applywhen error result is unreachable (usuallytry!and similar source code constructs)@derivative(of:)attribute, so we can register custom derivatives for functions producing error resultOptional.??operator (note that support here is not yet complete as we cannot differentiate through autoclosures, sox ?? yworks only ifyis not active, e.g. a constant value).Some fixes here and there