Skip to content

Commit bd90133

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 d6e5805 commit bd90133

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

11431143
case Kind::AssociatedConformanceDescriptor:
11441144
case Kind::DefaultAssociatedConformanceAccessor: {
1145-
// Associated conformance descriptors use the protocol as
1146-
// their declaration, but are weak linked if the associated
1147-
// type stored in extra storage area is weak linked.
1145+
// Associated conformance descriptors use the protocol as their declaration
1146+
// and are weak linked if either the protocol or the associated type stored
1147+
// in extra storage area is weak linked.
1148+
if (cast<ProtocolDecl>(getDecl())->isWeakImported(module))
1149+
return true;
1150+
11481151
auto assocConformance = getAssociatedConformance();
11491152
auto *depMemTy = assocConformance.first->castTo<DependentMemberType>();
11501153
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)