Skip to content

Commit 2f08561

Browse files
authored
Merge pull request #18968 from DougGregor/no-assoc-type-override-witnesses
[ABI] Don't emit overriding associated type declarations into witness tables.
2 parents ecd25a7 + 51aa4b2 commit 2f08561

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

include/swift/SIL/SILWitnessVisitor.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ template <class T> class SILWitnessVisitor : public ASTVisitor<T> {
6161
SmallVector<AssociatedTypeDecl *, 2> associatedTypes;
6262
for (Decl *member : protocol->getMembers()) {
6363
if (auto associatedType = dyn_cast<AssociatedTypeDecl>(member)) {
64-
associatedTypes.push_back(associatedType);
64+
// If this is a new associated type (which does not override an
65+
// existing associated type), add it.
66+
if (associatedType->getOverriddenDecls().empty())
67+
associatedTypes.push_back(associatedType);
6568
}
6669
}
6770

@@ -70,7 +73,6 @@ template <class T> class SILWitnessVisitor : public ASTVisitor<T> {
7073
TypeDecl::compare);
7174

7275
for (auto *associatedType : associatedTypes) {
73-
// TODO: only add associated types when they're new?
7476
asDerived().addAssociatedType(AssociatedType(associatedType));
7577
}
7678
};

test/IRGen/generic_structs.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ struct GenericLayoutWithAssocType<T: ParentHasAssociatedType> {
262262
// CHECK: [[T4:%.*]] = call swiftcc %swift.metadata_response [[T3]](i64 0, %swift.type* %T, i8** [[T1]])
263263
// CHECK: %T.Assoc = extractvalue %swift.metadata_response [[T4]], 0
264264

265-
// CHECK: [[T0:%.*]] = getelementptr inbounds i8*, i8** %T.ParentHasAssociatedType, i32 3
265+
// CHECK: [[T0:%.*]] = getelementptr inbounds i8*, i8** %T.ParentHasAssociatedType, i32 2
266266
// CHECK: [[T1:%.*]] = load i8*, i8** [[T0]],
267267
// CHECK: [[T2:%.*]] = bitcast i8* [[T1]] to i8** (%swift.type*, %swift.type*, i8**)*
268268
// CHECK: %T.Assoc.HasAssociatedType = call swiftcc i8** [[T2]](%swift.type* %T.Assoc, %swift.type* %T, i8** %T.ParentHasAssociatedType)

test/SILGen/witnesses_refinement.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,44 @@ extension Int: Saturable {
1313
// CHECK-NOT: sil_witness_table Int: Equatable module witnesses_refinement {
1414
// CHECK-NOT: sil_witness_table Int: Comparable module witnesses_refinement {
1515
// CHECK: sil_witness_table hidden Int: Saturable module witnesses_refinement {
16+
17+
protocol P { }
18+
19+
protocol P0 {
20+
associatedtype A
21+
}
22+
23+
protocol P1 {
24+
associatedtype A
25+
}
26+
27+
protocol P2: P0 {
28+
associatedtype A
29+
}
30+
31+
protocol P3: P2, P1 {
32+
associatedtype A: P
33+
}
34+
35+
struct ConformsToP: P { }
36+
37+
// CHECK-LABEL: sil_witness_table hidden ConformsToP3: P3
38+
// CHECK: base_protocol P1
39+
// CHECK-NEXT: base_protocol P2
40+
// CHECK-NEXT: associated_type_protocol (A: P)
41+
// CHECK-NEXT: }
42+
struct ConformsToP3: P3 {
43+
typealias A = ConformsToP
44+
}
45+
46+
// CHECK-LABEL: sil_witness_table hidden ConformsToP3: P2
47+
// CHECK: base_protocol P0
48+
// CHECK-NEXT: }
49+
50+
// CHECK-LABEL: sil_witness_table hidden ConformsToP3: P1
51+
// CHECK: associated_type A: ConformsToP
52+
// CHECK-NEXT: }
53+
54+
// CHECK-LABEL: sil_witness_table hidden ConformsToP3: P0
55+
// CHECK: associated_type A: ConformsToP
56+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)