Skip to content
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: 7 additions & 2 deletions lib/Sema/DerivedConformanceDifferentiable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,9 @@ deriveDifferentiable_AssociatedStruct(DerivedConformance &derived,
}

// Add a typealias declaration with the given name and underlying target
// struct type to the source struct.
auto addAssociatedTypeAliasDecl = [&](Identifier name, StructDecl *source,
// struct type to the source nominal type.
auto addAssociatedTypeAliasDecl = [&](Identifier name,
NominalTypeDecl *source,
StructDecl *target) {
auto lookup = source->lookupDirect(name);
assert(lookup.size() < 2 &&
Expand Down Expand Up @@ -845,6 +846,10 @@ deriveDifferentiable_AssociatedStruct(DerivedConformance &derived,
allDiffableVarsStruct, allDiffableVarsStruct);
addAssociatedTypeAliasDecl(C.Id_CotangentVector,
allDiffableVarsStruct, allDiffableVarsStruct);
addAssociatedTypeAliasDecl(C.Id_TangentVector,
nominal, allDiffableVarsStruct);
addAssociatedTypeAliasDecl(C.Id_CotangentVector,
nominal, allDiffableVarsStruct);
TC.validateDecl(allDiffableVarsStruct);
return parentDC->mapTypeIntoContext(
allDiffableVarsStruct->getDeclaredInterfaceType());
Expand Down
4 changes: 2 additions & 2 deletions test/AutoDiff/derived_differentiable_properties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public struct Foo : Differentiable {
// CHECK-AST: @_fieldwiseProductSpace typealias AllDifferentiableVariables = Foo.AllDifferentiableVariables
// CHECK-AST: @_fieldwiseProductSpace typealias TangentVector = Foo.AllDifferentiableVariables
// CHECK-AST: @_fieldwiseProductSpace typealias CotangentVector = Foo.AllDifferentiableVariables
// CHECK-AST: typealias TangentVector = Foo.AllDifferentiableVariables
// CHECK-AST: typealias CotangentVector = Foo.AllDifferentiableVariables
// CHECK-AST: @_fieldwiseProductSpace typealias TangentVector = Foo.AllDifferentiableVariables
// CHECK-AST: @_fieldwiseProductSpace typealias CotangentVector = Foo.AllDifferentiableVariables

// CHECK-SILGEN-LABEL: // Foo.a.getter
// CHECK-SILGEN: sil [transparent] [serialized] [differentiable source 0 wrt 0] @$s33derived_differentiable_properties3FooV1aSfvg : $@convention(method) (Foo) -> Float
Expand Down