-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff] Prevent crash when using @differentiable without importing _Differentiation #67162
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
@BradLarson could you invoke the CI bot for me? |
@swift-ci please test |
// **NOTE** - This test can likely be removed when/if the differentiation module is | ||
// available by default in the Swift stdlib. | ||
public func req() {} | ||
} |
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.
Should we end with a newline here like most other tests?
} | |
} | |
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.
Sure.
// **NOTE** - This test can likely be removed when/if the differentiation module is | ||
// available by default in the Swift stdlib. |
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.
The likelihood of this may be 0 though, as domain-specific stdlibs tend to be standalone modules, like Distributed. Not sure it's worth mentioning.
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.
Good to know. I'll remove the comment.
lib/Sema/TypeCheckAttr.cpp
Outdated
@@ -5789,7 +5789,8 @@ IndexSubset *DifferentiableAttributeTypeCheckRequest::evaluate( | |||
void AttributeChecker::visitDifferentiableAttr(DifferentiableAttr *attr) { | |||
// Call `getParameterIndices` to trigger | |||
// `DifferentiableAttributeTypeCheckRequest`. | |||
(void)attr->getParameterIndices(); | |||
if (attr->getParameterIndices() == nullptr) | |||
attr->setInvalid(); |
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.
Instead, should DifferentiableAttributeTypeCheckRequest
be responsible for setting the attr as invalid? The request is already doing so in some places when it calls typecheckDifferentiableAttrforDecl
.
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.
Sure. I'll make the change.
The above referenced issue was causing a compiler crash when writing differentiable protocols and corresponding implementers, without importing the `_Differentiation` module. Changes in this CR fix the issue by marking any `@differentiable` attributes as invalid, if the `_Differentiation` module has not been imported. This ignores the `@differentiable` attributes when the protocol witnesses are being verified. Witness verification was previously leading to an error (due to missing `@differentiable` attribute on the protocol requirement implementer), and the corresponding diagnostic emission code was then leading to a crash, because it was expecting the `_Differentiation` module to be present.
@swift-ci please test |
The above referenced issue was causing a compiler crash when writing differentiable protocols and corresponding implementers, without importing the
_Differentiation
module.Changes in this CR fix the issue by marking any
@differentiable
attributes as invalid, if the_Differentiation
module has not been imported. This ignores the@differentiable
attributes when the protocol witnesses are being verified. Witness verification was previously leading to an error (due to missing@differentiable
attribute on the protocol requirement implementer), and the corresponding diagnostic emission code was then leading to a crash, because it was expecting the_Differentiation
module to be present.Fixes #59100