Skip to content

Commit 0df911c

Browse files
committed
IRGen: Weakly link associated conformance descriptors when either the protocol or the associated requirement is weak.
Previously, only the associated requirement was considered when deciding whether to weakly link an associated conformance descriptor. This lead to unexpected strong linkage for some symbols, interfering with back deployment when integrating with some frameworks. Resolves rdar://96974850
1 parent 4e1a1b8 commit 0df911c

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
@@ -1182,9 +1182,12 @@ bool LinkEntity::isWeakImported(ModuleDecl *module) const {
11821182

11831183
case Kind::AssociatedConformanceDescriptor:
11841184
case Kind::DefaultAssociatedConformanceAccessor: {
1185-
// Associated conformance descriptors use the protocol as
1186-
// their declaration, but are weak linked if the associated
1187-
// type stored in extra storage area is weak linked.
1185+
// Associated conformance descriptors use the protocol as their declaration
1186+
// and are weak linked if either the protocol or the associated type stored
1187+
// in extra storage area is weak linked.
1188+
if (cast<ProtocolDecl>(getDecl())->isWeakImported(module))
1189+
return true;
1190+
11881191
auto assocConformance = getAssociatedConformance();
11891192
auto *depMemTy = assocConformance.first->castTo<DependentMemberType>();
11901193
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)