Skip to content

[AutoDiff] [Sema] Fix a 'EuclideanDifferentiable' derived conformances crasher. #26900

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

Merged
merged 1 commit into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/Sema/DerivedConformanceDifferentiable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,14 @@ static ValueDecl *deriveEuclideanDifferentiable_differentiableVectorView(
eucDiffProto->lookupDirect(C.Id_differentiableVectorView).front();

SmallVector<VarDecl *, 8> diffProperties;
getStoredPropertiesForDifferentiation(nominal, nominal->getDeclContext(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parentDC as the second argument is correct.

For reference, nominal->getDeclContext() returns the parent context of the NominalDecl - passing just nominal would be closer to correct.

diffProperties);
getStoredPropertiesForDifferentiation(nominal, parentDC, diffProperties);

// Create a reference to the memberwise initializer: `TangentVector.init`.
auto *memberwiseInitDecl =
context->tangentDecl->getEffectiveMemberwiseInitializer();
assert(memberwiseInitDecl && "Memberwise initializer must exist");
assert(diffProperties.size() ==
memberwiseInitDecl->getParameters()->size());
// `TangentVector`
auto *tangentTypeExpr =
TypeExpr::createImplicit(context->tangentContextualType, C);
Expand All @@ -425,9 +426,9 @@ static ValueDecl *deriveEuclideanDifferentiable_differentiableVectorView(
// Create a call:
// TangentVector.init(
// <property_name_1...>:
// self.differentiableVectorView.<property_name_1>,
// self.<property_name_1>.differentiableVectorView,
// <property_name_2...>:
// self.differentiableVectorView.<property_name_2>,
// self.<property_name_2>.differentiableVectorView,
// ...
// )
SmallVector<Identifier, 8> argLabels;
Expand Down
5 changes: 2 additions & 3 deletions test/Sema/class_differentiable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@ extension VectorSpacesEqualSelf : Equatable, AdditiveArithmetic {
*/

// Test generic type with vector space types to `Self`.
// FIXME(TF-783): Uncomment `EuclideanDifferentiable` conformance once crasher is fixed.
class GenericVectorSpacesEqualSelf<T> : Differentiable//, EuclideanDifferentiable
where T : Differentiable, T == T.TangentVector
class GenericVectorSpacesEqualSelf<T> : Differentiable, EuclideanDifferentiable
where T : EuclideanDifferentiable, T == T.TangentVector
{
var w: T
var b: T
Expand Down