-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff] Revamp derivative type calculation using llvm::Expected
.
#31727
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] Revamp derivative type calculation using llvm::Expected
.
#31727
Conversation
// Try to get the `TangentVector` type witness, in case the conformance has | ||
// not been fully checked. | ||
Type tanType = conf.getTypeWitnessByName(type, ctx.Id_TangentVector); | ||
if (tanType.isNull() || tanType->hasError()) | ||
return ProtocolConformanceRef(); |
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.
@CodaFi: the removal of this code should address your concerns from https://github.com/apple/swift/pull/30936/files#r406541238:
This mix of semantic and syntactico-semantic checks doesn't feel right. Is the idea that you're trying to check for a conformance to this protocol, or to a well-formed conformance of this protocol?
We directly use TypeChecker::conformsToProtocol
now, which is syntactic. Semantic checks (requesting TangentVector
type witnesses) are performed and diagnosed on-demand.
@swift-ci Please test |
Create `DerivativeFunctionTypeError` representing all potential derivative function type calculation errors. Make `AnyFunctionType::getAutoDiffDerivativeFunctionLinearMapType` return `llvm::Expected<AnyFunctionType *>`. This is much safer and caller-friendly than performing assertions. Delete hacks in `@differentiable` and `@derivative` attribute type-checking for verifying that `Differentiable.TangentVector` type witnesses are valid: this is no longer necessary. Robust fix for TF-521: invalid `Differentiable` conformances during `@derivative` attribute type-checking. Resolves SR-12793: bad interaction between `@differentiable` and `@derivative` attribute type-checking and `Differentiable` derived conformances.
cb2a709
to
3bdfd50
Compare
@swift-ci Please test |
Build failed |
Merging now to unblock progress, I'm happy to address any feedback later! |
Create
DerivativeFunctionTypeError
representing all potential derivativefunction type calculation errors.
Make
AnyFunctionType::getAutoDiffDerivativeFunctionLinearMapType
returnllvm::Expected<AnyFunctionType *>
. This is much safer and caller-friendlythan performing assertions.
Delete hacks in
@differentiable
and@derivative
attribute type-checkingfor verifying that
Differentiable.TangentVector
type witnesses are valid:this is no longer necessary.
Robust fix for TF-521: invalid
Differentiable
conformances during@derivative
attribute type-checking.Resolves SR-12793: bad interaction between
@differentiable
and@derivative
attribute type-checking and
Differentiable
derived conformances.Todos
AnyFunctionType::getAutoDiffDerivativeFunctionType
andAnyFunctionType::getAutoDiffDerivativeFunctionLinearMapType
to cache results.Example
Before (the bad interaction):
After: no error.