Skip to content

Commit 7f05516

Browse files
authored
Merge pull request #60075 from tshortli/weak-link-associated-conformance-descriptor-5.7
[5.7] IRGen: Weakly link associated conformance descriptors when either the protocol or the associated requirement is weak
2 parents 7c9a716 + bd90133 commit 7f05516

File tree

2 files changed

+64
-3
lines changed

2 files changed

+64
-3
lines changed

lib/IRGen/Linking.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,9 +1158,12 @@ bool LinkEntity::isWeakImported(ModuleDecl *module) const {
11581158

11591159
case Kind::AssociatedConformanceDescriptor:
11601160
case Kind::DefaultAssociatedConformanceAccessor: {
1161-
// Associated conformance descriptors use the protocol as
1162-
// their declaration, but are weak linked if the associated
1163-
// type stored in extra storage area is weak linked.
1161+
// Associated conformance descriptors use the protocol as their declaration
1162+
// and are weak linked if either the protocol or the associated type stored
1163+
// in extra storage area is weak linked.
1164+
if (cast<ProtocolDecl>(getDecl())->isWeakImported(module))
1165+
return true;
1166+
11641167
auto assocConformance = getAssociatedConformance();
11651168
auto *depMemTy = assocConformance.first->castTo<DependentMemberType>();
11661169
return depMemTy->getAssocType()->isWeakImported(module);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/Library.swiftmodule -parse-as-library %t/Library.swift -enable-library-evolution
5+
// RUN: %target-swift-frontend -primary-file %t/Client.swift -I %t -emit-ir | %FileCheck %s
6+
7+
// REQUIRES: OS=macosx
8+
9+
//--- Library.swift
10+
11+
public protocol P { }
12+
public protocol Q: P { }
13+
14+
public protocol StrongProtoWithAssoc {
15+
associatedtype Assoc: P
16+
}
17+
18+
public protocol StrongProtoWithWeakLinkedAssoc {
19+
@_weakLinked associatedtype Assoc: P
20+
}
21+
22+
@available(macOS 10.50, *)
23+
public protocol WeakProtoWithAssoc {
24+
associatedtype Assoc: P
25+
}
26+
27+
@available(macOS 10.50, *)
28+
public protocol WeakProtoWithStrongInheritedAssoc: StrongProtoWithAssoc where Self.Assoc: Q { }
29+
30+
31+
//--- Client.swift
32+
33+
import Library
34+
35+
struct ConformsToP: P { }
36+
struct ConformsToQ: Q { }
37+
38+
// CHECK: @"$s7Library20StrongProtoWithAssocP0E0AC_AA1PTn" = external global %swift.protocol_requirement, align 4
39+
struct ConformsToStrongProtoWithAssoc: StrongProtoWithAssoc {
40+
typealias Assoc = ConformsToP
41+
}
42+
43+
// CHECK: @"$s7Library30StrongProtoWithWeakLinkedAssocP0G0AC_AA1PTn" = extern_weak global %swift.protocol_requirement, align 4
44+
struct ConformsToStrongProtoWithWeakLinkedAssoc: StrongProtoWithWeakLinkedAssoc {
45+
typealias Assoc = ConformsToP
46+
}
47+
48+
// CHECK: @"$s7Library18WeakProtoWithAssocP0E0AC_AA1PTn" = extern_weak global %swift.protocol_requirement, align 4
49+
@available(macOS 10.50, *)
50+
struct ConformsToWeakProtoWithAssoc: WeakProtoWithAssoc {
51+
typealias Assoc = ConformsToP
52+
}
53+
54+
// CHECK: @"$s7Library33WeakProtoWithStrongInheritedAssocP0G0AA0ecdG0P_AA1QTn" = extern_weak global %swift.protocol_requirement, align 4
55+
@available(macOS 10.50, *)
56+
struct ConformsToWeakProtoWithStrongInheritedAssoc: WeakProtoWithStrongInheritedAssoc {
57+
typealias Assoc = ConformsToQ
58+
}

0 commit comments

Comments
 (0)