Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/IRGen/Linking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
28 changes: 28 additions & 0 deletions test/embedded/linkage/diamond.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -124,6 +151,7 @@ struct Main {
print(pointAndColorOffsets.count)
print(extraColor3DOffsets.count)

let reflected = [getReflectableA(), getReflectableB()]
// CHECK: DONE
print("DONE")
}
Expand Down
30 changes: 30 additions & 0 deletions test/embedded/linkage/leaf_application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down