import Submodule @_implementationOnly import PrivateSubmodule @_implementationOnly import PrivateCModule private enum PE { case A case B(T) } public struct Container { private final class Base { } @inline(never) public func testclass(_ t: T) -> T { var arr = Array() arr.append(Base()) print(arr) dontBlockSerialization(arr) return t } @inline(never) @_semantics("optimize.sil.specialize.generic.never") public func testclass_gen(_ t: T) -> T { var arr = Array() arr.append(Base()) print(arr) return t } @inline(never) public func testenum(_ t: T) -> T { var arr = Array>() arr.append(.B(t)) print(arr) return t } @inline(never) @_semantics("optimize.sil.specialize.generic.never") public func testenum_gen(_ t: T) -> T { var arr = Array>() arr.append(.B(t)) print(arr) return t } public init() { } } private class PrivateBase { var t: T func foo() -> Int { return 27 } init(_ t: T) { self.t = t } } private class PrivateDerived : PrivateBase { override func foo() -> Int { return 28 } } @inline(never) private func getClass(_ t : T) -> PrivateBase { return PrivateDerived(t) } @inline(never) public func createClass(_ t: T) -> Int { return getClass(t).foo() } @inline(never) @_semantics("optimize.sil.specialize.generic.never") public func createClass_gen(_ t: T) -> Int { return getClass(t).foo() } private struct PrivateError: Error { } public func returnPrivateError(_ v: V) -> Error { return PrivateError() } struct InternalError: Error { } public func returnInternalError(_ v: V) -> Error { return InternalError() } private protocol PrivateProtocol { func foo() -> Int } open class OpenClass { public init() { } @inline(never) fileprivate func bar(_ t: T) { print(t) } } extension OpenClass { @inline(never) public func testit() -> Bool { return self is PrivateProtocol } } @inline(never) public func checkIfClassConforms(_ t: T) { let x = OpenClass() print(x.testit()) } @inline(never) @_semantics("optimize.sil.specialize.generic.never") public func checkIfClassConforms_gen(_ t: T) { let x = OpenClass() print(x.testit()) } @inline(never) public func callClassMethod(_ t: T) { let k = OpenClass() k.bar(t) } extension Int : PrivateProtocol { func foo() -> Int { return self } } @inline(never) @_semantics("optimize.no.crossmodule") private func printFooExistential(_ p: PrivateProtocol) { print(p.foo()) } @inline(never) private func printFooGeneric(_ p: T) { print(p.foo()) } @inline(never) public func callFoo(_ t: T) { printFooExistential(123) printFooGeneric(1234) } @inline(never) @_semantics("optimize.sil.specialize.generic.never") public func callFoo_gen(_ t: T) { printFooExistential(123) printFooGeneric(1234) } fileprivate protocol PrivateProto { func foo() } public class FooClass: PrivateProto { func foo() { print(321) } } final class Internalclass { public var publicint: Int = 27 } final public class Outercl { var ic: Internalclass = Internalclass() } @inline(never) public func classWithPublicProperty(_ t: T) -> Int { return createInternal().ic.publicint } @inline(never) func createInternal() -> Outercl { return Outercl() } @inline(never) @_semantics("optimize.sil.specialize.generic.never") fileprivate func callProtocolFoo(_ t: T) { t.foo() } @inline(never) @_semantics("optimize.sil.specialize.generic.never") public func callFooViaConformance(_ t: T) { let c = FooClass() callProtocolFoo(c) } @inline(never) public func callGenericSubmoduleFunc(_ t: T) { genericSubmoduleFunc(t) } @inline(never) @_semantics("optimize.sil.specialize.generic.never") public func callGenericSubmoduleFunc_gen(_ t: T) { genericSubmoduleFunc(t) } @inline(never) public func genericClosure(_ t: T) -> T { let c : () -> T = { return t } return c() } @inline(never) @_semantics("optimize.sil.specialize.generic.never") public func genericClosure_gen(_ t: T) -> T { let c : () -> T = { return t } return c() } struct Abc { var x: Int { return 27 } var y: Int { return 28 } } class Myclass { var x: Int { return 27 } var y: Int { return 28 } } class Derived : Myclass { override var x: Int { return 29 } override var y: Int { return 30 } } @inline(never) func getStructKeypath(_ t: T) -> KeyPath { return \Abc.x } @inline(never) public func useStructKeypath(_ t: T) -> Int { let abc = Abc() return abc[keyPath: getStructKeypath(t)] } @inline(never) func getClassKeypath(_ t: T) -> KeyPath { return \Myclass.x } @inline(never) public func useClassKeypath(_ t: T) -> Int { let c = Derived() return c[keyPath: getClassKeypath(t)] } @inline(never) func unrelated(_ u: U) { print(u) } @inline(never) public func callUnrelated(_ t: T) -> T { unrelated(43) return t } public func callImplementationOnlyType(_ t: T) -> T { let p = PrivateStr(i: 27) print(p.test()) return t } public func callImplementationOnlyFunc(_ t: T) -> Int { return privateFunc() } public func callCImplementationOnly(_ t: T) -> Int { return Int(privateCFunc()) } public let globalLet = 529387 private var privateVar = Int.random(in: 0..<100) public func getRandom() -> Int { return privateVar } public struct StructWithClosure { public static let c = { (x: Int) -> Int in return x } } public func getEmptySet() -> Set { return Set() } public protocol Visitable { func visit() } @available(SwiftStdlib 6.0, *) public struct S { var storage: (repeat each T) public func visit() { _ = (repeat (each storage).visit()) } } public struct StructWithInternal { var internalVar: Int } public func getKP() -> KeyPath { return \StructWithInternal.internalVar }