Skip to content

Commit e477fca

Browse files
authored
[AutoDiff] [Sema] Fix a 'EuclideanDifferentiable' derived conformances crasher. (#26900)
Resolves [TF-783](https://bugs.swift.org/browse/TF-783).
1 parent f34c92f commit e477fca

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lib/Sema/DerivedConformanceDifferentiable.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,13 +404,14 @@ static ValueDecl *deriveEuclideanDifferentiable_differentiableVectorView(
404404
eucDiffProto->lookupDirect(C.Id_differentiableVectorView).front();
405405

406406
SmallVector<VarDecl *, 8> diffProperties;
407-
getStoredPropertiesForDifferentiation(nominal, nominal->getDeclContext(),
408-
diffProperties);
407+
getStoredPropertiesForDifferentiation(nominal, parentDC, diffProperties);
409408

410409
// Create a reference to the memberwise initializer: `TangentVector.init`.
411410
auto *memberwiseInitDecl =
412411
context->tangentDecl->getEffectiveMemberwiseInitializer();
413412
assert(memberwiseInitDecl && "Memberwise initializer must exist");
413+
assert(diffProperties.size() ==
414+
memberwiseInitDecl->getParameters()->size());
414415
// `TangentVector`
415416
auto *tangentTypeExpr =
416417
TypeExpr::createImplicit(context->tangentContextualType, C);
@@ -425,9 +426,9 @@ static ValueDecl *deriveEuclideanDifferentiable_differentiableVectorView(
425426
// Create a call:
426427
// TangentVector.init(
427428
// <property_name_1...>:
428-
// self.differentiableVectorView.<property_name_1>,
429+
// self.<property_name_1>.differentiableVectorView,
429430
// <property_name_2...>:
430-
// self.differentiableVectorView.<property_name_2>,
431+
// self.<property_name_2>.differentiableVectorView,
431432
// ...
432433
// )
433434
SmallVector<Identifier, 8> argLabels;

test/Sema/class_differentiable.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,8 @@ extension VectorSpacesEqualSelf : Equatable, AdditiveArithmetic {
139139
*/
140140

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

0 commit comments

Comments
 (0)