mirror of
https://github.com/apple/swift.git
synced 2026-06-20 15:42:51 +02:00
ae1e3d0865
The new library, swiftEmbeddedPlatformPOSIX, implements all of the _swift_XYZ functions needed to support Embedded Swift as shims on top of a POSIX system that provides posix_memalign, free, putchar, and so on. This offers an easier way to bridge between the prior ad hoc requirements of Embedded Swift and the newer platform abstraction layer. Part of rdar://164057124
102 lines
2.0 KiB
Swift
102 lines
2.0 KiB
Swift
// RUN: %target-run-simple-swift(-enable-experimental-feature Embedded -parse-as-library -wmo %target-embedded-posix-shim) | %FileCheck %s
|
|
// RUN: %target-run-simple-swift(-enable-experimental-feature Embedded -parse-as-library -wmo -O %target-embedded-posix-shim) | %FileCheck %s
|
|
// RUN: %target-run-simple-swift(-enable-experimental-feature Embedded -parse-as-library -wmo -Osize %target-embedded-posix-shim) | %FileCheck %s
|
|
|
|
// REQUIRES: executable_test
|
|
// REQUIRES: optimized_stdlib
|
|
// REQUIRES: swift_feature_Embedded
|
|
|
|
// Simple case
|
|
|
|
public protocol ProtocolWithDefaultMethod: AnyObject {
|
|
func getInt() -> Int
|
|
}
|
|
|
|
extension ProtocolWithDefaultMethod {
|
|
public func getInt() -> Int {
|
|
return 42
|
|
}
|
|
}
|
|
|
|
public class Class: ProtocolWithDefaultMethod {
|
|
}
|
|
|
|
public class GenClass<T>: ProtocolWithDefaultMethod {
|
|
}
|
|
|
|
func test(existential: any ProtocolWithDefaultMethod) {
|
|
print(existential.getInt())
|
|
}
|
|
|
|
// Test that we specialize for the correct derived class
|
|
|
|
class C {
|
|
class func g() -> Int {
|
|
return 1
|
|
}
|
|
}
|
|
|
|
class D: C {
|
|
override class func g() -> Int {
|
|
return 2
|
|
}
|
|
}
|
|
|
|
protocol P: AnyObject {
|
|
static func g() -> Int
|
|
func test() -> Int
|
|
}
|
|
|
|
extension P {
|
|
func test() -> Int {
|
|
Self.g()
|
|
}
|
|
}
|
|
|
|
extension C: P {}
|
|
|
|
func createDerived() -> P {
|
|
return D()
|
|
}
|
|
|
|
// Test that we don't end up in an infinite recursion loop
|
|
|
|
public protocol RecursiveProto: AnyObject {
|
|
associatedtype T: RecursiveProto
|
|
func getInt() -> Int
|
|
func getT() -> T
|
|
}
|
|
|
|
extension RecursiveProto {
|
|
public func getInt() -> Int {
|
|
return 27
|
|
}
|
|
}
|
|
|
|
public class RecursiveClass: RecursiveProto {
|
|
public typealias T = RecursiveClass
|
|
public func getT() -> RecursiveClass {
|
|
return self
|
|
}
|
|
}
|
|
|
|
func testRecursive(existential: any RecursiveProto) {
|
|
print(existential.getT().getInt())
|
|
}
|
|
|
|
|
|
@main
|
|
struct Main {
|
|
static func main() {
|
|
// CHECK: 42
|
|
test(existential: Class())
|
|
// CHECK: 42
|
|
test(existential: GenClass<Int>())
|
|
// CHECK: 2
|
|
print(createDerived().test())
|
|
// CHECK: 27
|
|
testRecursive(existential: RecursiveClass())
|
|
}
|
|
}
|
|
|