Skip to content
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

[AutoDiff][SILGen] Do not incorrectly rotate direct inout parameters #58437

Closed
wants to merge 1 commit into from

Conversation

philipturner
Copy link
Contributor

@philipturner philipturner commented Apr 27, 2022

When there is a mutating function nested inside an encapsulating function and both are differentiated, the compiler can swizzle around components of the gradient. This first manifested in a subtle runtime crash, but caused a compiler crash when it jumbled around gradient components with different Swift types.

The fix the bug, this PR avoids rotating direct parameters if the first one is "indirect mutating". I do not know whether we should use the same tactic with indirect parameters or when a direct parameter in a position besides index 0 is "indirect mutating".

The original reproducer for SR-15793 has been added to a validation test. The regression test is a new reproducer - which crashes the compiler - that I created while finding the solution to this bug.

Fixes #58070, formerly known as SR-15793.

* Update SILGenPoly.cpp

* Create sr15793-rotation-of-direct-inout-parameters.swift

* Add validation test for SR-15793

* Change comment to say `Double` instead of `Float`
@BradLarson
Copy link
Collaborator

@swift-ci Please test.

@philipturner
Copy link
Contributor Author

This feels like a hacky workaround. I'm not sure whether we have truly identified the source of the problem. Has the scenario causing the bug been thought of before?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SR-15793] [AutoDiff] Incorrect behavior with derivatives
2 participants