Skip to content

Void-returning @differentiable function crashes compiler #62923

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

Closed
hamishknight opened this issue Jan 9, 2023 · 3 comments · Fixed by #63080
Closed

Void-returning @differentiable function crashes compiler #62923

hamishknight opened this issue Jan 9, 2023 · 3 comments · Fixed by #63080
Assignees
Labels
AutoDiff bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself crash Bug: A crash, i.e., an abnormal termination of software SILGen Area → compiler: The SIL generation stage swift 5.8 type checker Area → compiler: Semantic analysis

Comments

@hamishknight
Copy link
Contributor

The following crashes in SILGen:

import _Differentiation

func foo(_ fn: @differentiable(reverse) (Float) -> Void) {}
@hamishknight hamishknight added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. AutoDiff labels Jan 9, 2023
@LucianoPAlmeida LucianoPAlmeida added compiler The Swift compiler itself compiler crash SILGen Area → compiler: The SIL generation stage labels Jan 9, 2023
@asl asl self-assigned this Jan 12, 2023
@asl
Copy link
Contributor

asl commented Jan 18, 2023

So, the reason here is Void (aka empty tuple) type is assumed to be differentiable with tangent space being empty tuple as well.

Looks like we'd need to additionally check and disallow void result type if there are no inouts.

Tagging @rxwei @dan-zheng @BradLarson

@rxwei
Copy link
Contributor

rxwei commented Jan 18, 2023

Yeah that sounds about right. @asl

@asl
Copy link
Contributor

asl commented Jan 18, 2023

@rxwei Thanks for cross-checking! It tried to imagine other corner cases related to Void but failed to find any so far :)

asl added a commit to asl/swift that referenced this issue Jan 18, 2023
Such functions are not differentiable and therefore should be rejected.
Fixes swiftlang#62923
asl added a commit that referenced this issue Jan 18, 2023
…#63080)

Such functions are not differentiable and therefore should be rejected.
Fixes #62923,  fixes #58095
@AnthonyLatsis AnthonyLatsis added type checker Area → compiler: Semantic analysis swift 5.8 crash Bug: A crash, i.e., an abnormal termination of software and removed compiler crash labels Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AutoDiff bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself crash Bug: A crash, i.e., an abnormal termination of software SILGen Area → compiler: The SIL generation stage swift 5.8 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants