Skip to content

Commit 055f3e0

Browse files
Merge pull request #85838 from aschwaighofer/embedded_exist_deferred_codegen
[embedded] When using existentials in embedded value witness tables can also have non unique definitions
2 parents 153dd02 + 729cc1e commit 055f3e0

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

lib/IRGen/Linking.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1767,7 +1767,8 @@ bool LinkEntity::hasNonUniqueDefinition() const {
17671767
getKind() == Kind::ReadOnlyGlobalObject)
17681768
return getSILGlobalVariable()->hasNonUniqueDefinition();
17691769

1770-
if (getKind() == Kind::TypeMetadata) {
1770+
if (getKind() == Kind::TypeMetadata ||
1771+
getKind() == Kind::ValueWitnessTable) {
17711772
// For a nominal type, check its declaration.
17721773
CanType type = getType();
17731774
if (auto nominal = type->getAnyNominal()) {
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %S/diamond.swift %t
3+
4+
// Test: Main drives code generation
5+
// RUN: %target-swift-frontend -c -emit-module -o %t/Root.o %t/Root.swift -enable-experimental-feature Embedded -enable-experimental-feature DeferredCodeGen -parse-as-library -enable-experimental-feature EmbeddedExistentials
6+
// RUN: %target-swift-frontend -c -I %t -emit-module -o %t/ClientA.o %t/ClientA.swift -enable-experimental-feature Embedded -enable-experimental-feature DeferredCodeGen -parse-as-library -enable-experimental-feature EmbeddedExistentials
7+
// RUN: %target-swift-frontend -c -I %t -emit-module -o %t/ClientB.o %t/ClientB.swift -enable-experimental-feature Embedded -enable-experimental-feature DeferredCodeGen -parse-as-library -enable-experimental-feature EmbeddedExistentials
8+
// RUN: %target-swift-frontend -c -I %t -emit-module -o %t/Application.o %t/Application.swift -enable-experimental-feature Embedded -enable-experimental-feature DeferredCodeGen -parse-as-library -enable-experimental-feature EmbeddedExistentials
9+
// RUN: %target-clang %target-clang-resource-dir-opt %t/Root.o %t/ClientA.o %t/ClientB.o %t/Application.o -o %t/Application
10+
// RUN: %target-run %t/Application | %FileCheck %s
11+
12+
// But use this file's Root.swift
13+
// RUN: %empty-directory(%t)
14+
// RUN: split-file %S/diamond.swift %t
15+
// RUN: split-file %s %t
16+
17+
// Test: Main drives most code generation but Root.swift references PointClass.
18+
// RUN: %target-swift-frontend -c -emit-module -o %t/Root.o %t/Root.swift -enable-experimental-feature Embedded -enable-experimental-feature DeferredCodeGen -parse-as-library -enable-experimental-feature EmbeddedExistentials
19+
// RUN: %target-swift-frontend -c -I %t -emit-module -o %t/ClientA.o %t/ClientA.swift -enable-experimental-feature Embedded -enable-experimental-feature DeferredCodeGen -parse-as-library -enable-experimental-feature EmbeddedExistentials
20+
// RUN: %target-swift-frontend -c -I %t -emit-module -o %t/ClientB.o %t/ClientB.swift -enable-experimental-feature Embedded -enable-experimental-feature DeferredCodeGen -parse-as-library -enable-experimental-feature EmbeddedExistentials
21+
// RUN: %target-swift-frontend -c -I %t -emit-module -o %t/Application.o %t/Application.swift -enable-experimental-feature Embedded -enable-experimental-feature DeferredCodeGen -parse-as-library -enable-experimental-feature EmbeddedExistentials
22+
// RUN: %target-clang %target-clang-resource-dir-opt %t/Root.o %t/ClientA.o %t/ClientB.o %t/Application.o -o %t/Application
23+
// RUN: %target-run %t/Application | %FileCheck %s
24+
25+
// REQUIRES: swift_in_compiler
26+
// REQUIRES: executable_test
27+
// REQUIRES: swift_feature_Embedded
28+
// REQUIRES: swift_feature_EmbeddedExistentials
29+
// REQUIRES: swift_feature_DeferredCodeGen
30+
31+
//--- Root.swift
32+
struct Point {
33+
var x, y: Int
34+
}
35+
36+
public func enumerateByteOffsets<T>(_: T.Type) -> [Int] {
37+
var array: [Int] = []
38+
for i in 0..<MemoryLayout<T>.size {
39+
array.append(i)
40+
}
41+
return array
42+
}
43+
44+
public func getPointOffsets() -> [Int] {
45+
enumerateByteOffsets(Point.self)
46+
}
47+
48+
public class PointClass {
49+
public var x, y: Int
50+
51+
public init(x: Int, y: Int) {
52+
self.x = x
53+
self.y = y
54+
}
55+
}
56+
57+
public protocol Reflectable: AnyObject {
58+
func reflect()
59+
}
60+
61+
extension PointClass: Reflectable {
62+
public func reflect() {
63+
swap(&x, &y)
64+
}
65+
}
66+
67+
@used
68+
public func getPointClass() -> PointClass {
69+
return PointClass(x: 1, y: 2)
70+
}
71+
72+
// CHECK: DONE

0 commit comments

Comments
 (0)