diff --git a/lib/IRGen/Linking.cpp b/lib/IRGen/Linking.cpp index 0baac699309eb..e9323b7285576 100644 --- a/lib/IRGen/Linking.cpp +++ b/lib/IRGen/Linking.cpp @@ -1757,5 +1757,12 @@ bool LinkEntity::hasNonUniqueDefinition() const { return true; } + // Always treat witness tables as having non-unique definitions. + if (getKind() == Kind::ProtocolWitnessTable) { + if (auto context = getDeclContextForEmission()) + if (context->getParentModule()->getASTContext().LangOpts.hasFeature(Feature::Embedded)) + return true; + } + return false; } diff --git a/test/embedded/linkage/diamond.swift b/test/embedded/linkage/diamond.swift index b3a0031a82b90..753d035799a62 100644 --- a/test/embedded/linkage/diamond.swift +++ b/test/embedded/linkage/diamond.swift @@ -86,6 +86,25 @@ public func getPointOffsets() -> [Int] { enumerateByteOffsets(Point.self) } +public class PointClass { + public var x, y: Int + + public init(x: Int, y: Int) { + self.x = x + self.y = y + } +} + +public protocol Reflectable: AnyObject { + func reflect() +} + +extension PointClass: Reflectable { + public func reflect() { + swap(&x, &y) + } +} + //--- ClientA.swift import Root @@ -99,6 +118,10 @@ public func getPointAndColorOffsets() -> [Int] { getPointOffsets() + enumerateByteOffsets(Color.self) } +public func getReflectableA() -> any AnyObject & Reflectable { + return PointClass(x: 5, y: 5) +} + //--- ClientB.swift import Root @@ -112,6 +135,10 @@ public func getExtraPoint3DOffsets() -> [Int] { return Array(point3DOffsets[pointOffsets.count...]) } +public func getReflectableB() -> any AnyObject & Reflectable { + return PointClass(x: 5, y: 5) +} + //--- Application.swift import ClientA import ClientB @@ -124,6 +151,7 @@ struct Main { print(pointAndColorOffsets.count) print(extraColor3DOffsets.count) + let reflected = [getReflectableA(), getReflectableB()] // CHECK: DONE print("DONE") } diff --git a/test/embedded/linkage/leaf_application.swift b/test/embedded/linkage/leaf_application.swift index 9087abc5ceb4b..165de44b21ea3 100644 --- a/test/embedded/linkage/leaf_application.swift +++ b/test/embedded/linkage/leaf_application.swift @@ -21,6 +21,8 @@ //--- Library.swift +// LIBRARY-IR: @"$e7Library10PointClassCN" = weak_odr {{.*}}global + // Never referenced. // LIBRARY-IR-NOT: @"$es23_swiftEmptyArrayStorageSi_S3itvp" = weak_odr {{(protected |dllexport )?}}global @@ -54,6 +56,34 @@ public func unnecessary() -> Int64 { 5 } @_neverEmitIntoClient public func unusedYetThere() -> Int64 { 5 } +public class PointClass { + public var x, y: Int + + public init(x: Int, y: Int) { + self.x = x + self.y = y + } +} + +public protocol Reflectable: AnyObject { + func reflect() +} + +// LIBRARY-IR: define linkonce_odr hidden swiftcc void @"$es4swapyyxz_xztlFSi_Tg5" +// LIBRARY-IR: define linkonce_odr hidden swiftcc void @"$e7Library10PointClassCAA11ReflectableA2aDP7reflectyyFTW" + +extension PointClass: Reflectable { + public func reflect() { + swap(&x, &y) + } +} + +// LIBRARY-IR: define {{.*}} @"$e7Library18createsExistentialAA11Reflectable_pyF"() +@_neverEmitIntoClient +public func createsExistential() -> any Reflectable { + return PointClass(x: 5, y: 5) +} + // LIBRARY-IR-NOT: define swiftcc // LIBRARY-IR-NOT: define hidden swiftcc