1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
// RUN: %empty-directory(%t)
//
// RUN: %target-clang -fobjc-arc %S/Inputs/ObjCClasses/ObjCClasses.m -c -o %t/ObjCClasses.o
// RUN: %target-swift-frontend -I %S/Inputs/CTypes -prespecialize-generic-metadata -enable-experimental-feature LayoutStringValueWitnesses -enable-experimental-feature LayoutStringValueWitnessesInstantiation -enable-layout-string-value-witnesses -enable-layout-string-value-witnesses-instantiation -enable-type-layout -enable-autolinking-runtime-compatibility-bytecode-layouts -parse-stdlib -emit-module -emit-module-path=%t/layout_string_witnesses_types.swiftmodule %S/Inputs/layout_string_witnesses_types.swift
// RUN: %target-build-swift-dylib(%t/%target-library-name(layout_string_witnesses_types)) -I %S/Inputs/CTypes -Xfrontend -enable-experimental-feature -Xfrontend LayoutStringValueWitnesses -Xfrontend -enable-experimental-feature -Xfrontend LayoutStringValueWitnessesInstantiation -Xfrontend -enable-layout-string-value-witnesses -Xfrontend -enable-layout-string-value-witnesses-instantiation -Xfrontend -enable-type-layout -Xfrontend -parse-stdlib -parse-as-library %S/Inputs/layout_string_witnesses_types.swift
// RUN: %target-codesign %t/%target-library-name(layout_string_witnesses_types)
// RUN: %target-build-swift -g -Xfrontend -enable-experimental-feature -Xfrontend LayoutStringValueWitnesses -Xfrontend -enable-experimental-feature -Xfrontend LayoutStringValueWitnessesInstantiation -Xfrontend -enable-layout-string-value-witnesses -Xfrontend -enable-layout-string-value-witnesses-instantiation -Xfrontend -enable-type-layout -parse-stdlib -module-name layout_string_witnesses_dynamic -llayout_string_witnesses_types -L%t -I %S/Inputs/ObjCClasses/ %t/ObjCClasses.o -I %t -o %t/main %s %target-rpath(%t)
// RUN: %target-codesign %t/main
// RUN: %target-run %t/main %t/%target-library-name(layout_string_witnesses_types) | %FileCheck %s --check-prefix=CHECK
// REQUIRES: executable_test
// REQUIRES: objc_interop
// Requires runtime functions added in Swift 5.9.
// UNSUPPORTED: use_os_stdlib
import Swift
import layout_string_witnesses_types
import ObjCClasses
import Foundation
func testNestedResilientObjc() {
let ptr = allocateInternalGenericPtr(of: NestedWrapper<ObjCPrintOnDealloc>.self)
do {
let x = NestedWrapper<ObjCPrintOnDealloc>(x: .init(x: ObjCPrintOnDealloc()), y: .init(x: ObjCPrintOnDealloc()))
testGenericInit(ptr, to: x)
}
do {
let y = NestedWrapper<ObjCPrintOnDealloc>(x: .init(x: ObjCPrintOnDealloc()), y: .init(x: ObjCPrintOnDealloc()))
// CHECK: Before deinit
print("Before deinit")
// CHECK-NEXT: ObjCPrintOnDealloc deinitialized!
// CHECK-NEXT: ObjCPrintOnDealloc deinitialized!
testGenericAssign(ptr, from: y)
}
// CHECK-NEXT: Before deinit
print("Before deinit")
// CHECK-NEXT: ObjCPrintOnDealloc deinitialized!
// CHECK-NEXT: ObjCPrintOnDealloc deinitialized!
testGenericDestroy(ptr, of: NestedWrapper<ObjCPrintOnDealloc>.self)
ptr.deallocate()
}
testNestedResilientObjc()
protocol P {}
extension ObjCPrintOnDealloc: P {}
enum MultiPayloadObjCExistential {
case x(AnyObject)
case y(P & ObjCPrintOnDealloc)
}
struct MultiPayloadObjCExistentialWrapper {
let x: MultiPayloadObjCExistential
let y: Int = 0
}
func testMultiPayloadObjCExistentialWrapper() {
let ptr = allocateInternalGenericPtr(of: MultiPayloadObjCExistentialWrapper.self)
do {
let x = MultiPayloadObjCExistentialWrapper(x: .y(ObjCPrintOnDealloc()))
testGenericInit(ptr, to: x)
}
do {
let y = MultiPayloadObjCExistentialWrapper(x: .y(ObjCPrintOnDealloc()))
// CHECK: Before deinit
print("Before deinit")
// CHECK-NEXT: ObjCPrintOnDealloc deinitialized!
testGenericAssign(ptr, from: y)
}
// CHECK-NEXT: Before deinit
print("Before deinit")
// CHECK-NEXT: ObjCPrintOnDealloc deinitialized!
testGenericDestroy(ptr, of: MultiPayloadObjCExistentialWrapper.self)
ptr.deallocate()
}
testMultiPayloadObjCExistentialWrapper()
|