-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff] Emit a diagnostic for non-differentiable active values #67697
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
For some values we cannot compute types for differentiation (for example, tangent vector type), so it is better to diagnose them earlier. Otherwise we hit assertions when generating code for such invalid values. The LIT test is a reduced reproducer from the issue swiftlang#66996. Before the patch the compiler crashed while trying to get a tangent vector type for the following value (partial_apply): %54 = function_ref @$s4null1o2ffSdAA1FV_tFSdyKXEfu0_ : $@convention(thin) @Substituted <τ_0_0> (@inout_aliasable Double) -> (@out τ_0_0, @error any Error) for <Double> %55 = partial_apply [callee_guaranteed] %54(%2) : $@convention(thin) @Substituted <τ_0_0> (@inout_aliasable Double) -> (@out τ_0_0, @error any Error) for <Double> Now we emit a diagnostic instead. The patch resolves issues swiftlang#66996 and swiftlang#63331.
Tagging @BradLarson |
@swift-ci please test |
@@ -1804,6 +1804,11 @@ bool PullbackCloner::Implementation::run() { | |||
DominanceOrder domOrder(original.getEntryBlock(), domInfo); | |||
// Keep track of visited values. | |||
SmallPtrSet<SILValue, 8> visited; | |||
// Also check for differentiable for all active values |
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.
Not sure I understand this comment. The two lines of code below are just obtaining the protocol and the module and don't seem related to the 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.
Right, this comment is more suitable next to the actual check below.
@swift-ci please test |
There is quite a lot of LIT test with tuples being incorrectly (?) diagnosed as non-differentiable. I will check them and update the patch. |
@asavonic Because some components are non-differentiable? |
…ocol Types like `tuple` do not conform to the differentiable protocol, but they are handled in the compiler as special cases. getTangentSpace should work for all these types, and discard truly non-differentiable types.
@swift-ci please test |
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.
Sorry for the delayed review
For some values we cannot compute types for differentiation (for example, tangent vector type), so it is better to diagnose them earlier. Otherwise we hit assertions when generating code for such invalid values.
The LIT test is a reduced reproducer from the issue #66996. Before the patch the compiler crashed while trying to get a tangent vector type for the following value (partial_apply):
Now we emit a diagnostic instead.
The patch resolves issues #66996 and #63331.