[embedded] When using existentials in embedded value witness tables can also have non unique definitions

This commit is contained in:
Arnold Schwaighofer
2025-12-04 07:49:30 -08:00
parent 95d0fd64da
commit 729cc1e08f
2 changed files with 74 additions and 1 deletions

View File

@@ -0,0 +1,72 @@
// RUN: %empty-directory(%t)
// RUN: split-file %S/diamond.swift %t
// Test: Main drives code generation
// 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
// 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
// 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
// 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
// RUN: %target-clang %target-clang-resource-dir-opt %t/Root.o %t/ClientA.o %t/ClientB.o %t/Application.o -o %t/Application
// RUN: %target-run %t/Application | %FileCheck %s
// But use this file's Root.swift
// RUN: %empty-directory(%t)
// RUN: split-file %S/diamond.swift %t
// RUN: split-file %s %t
// Test: Main drives most code generation but Root.swift references PointClass.
// 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
// 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
// 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
// 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
// RUN: %target-clang %target-clang-resource-dir-opt %t/Root.o %t/ClientA.o %t/ClientB.o %t/Application.o -o %t/Application
// RUN: %target-run %t/Application | %FileCheck %s
// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: swift_feature_Embedded
// REQUIRES: swift_feature_EmbeddedExistentials
// REQUIRES: swift_feature_DeferredCodeGen
//--- Root.swift
struct Point {
var x, y: Int
}
public func enumerateByteOffsets<T>(_: T.Type) -> [Int] {
var array: [Int] = []
for i in 0..<MemoryLayout<T>.size {
array.append(i)
}
return array
}
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)
}
}
@used
public func getPointClass() -> PointClass {
return PointClass(x: 1, y: 2)
}
// CHECK: DONE