Files
swift-mirror/test/SILOptimizer/Inputs/cross-module/default-module.swift
T
Erik Eckstein 4b1fea06b5 CrossModuleOptimization: two improvements for default CMO
* Allow serialization of larger generic functions. So far we only serialized very small generic functions. However, it's important for performance to serialize more generic functions.
* Allow serialization of functions which call another function which is already marked as serializable. This can e.g. happen for default argument functions.

https://github.com/swiftlang/swift/issues/88441
rdar://174659028
2026-04-30 07:10:51 +02:00

99 lines
1.8 KiB
Swift

import Submodule
import PrivateCModule
public func incrementByThree(_ x: Int) -> Int {
return incrementByOne(x) + 2
}
package func pkgFunc(_ x: Int) -> Int {
return subPkgFunc(x) + 2
}
public func incrementByThreeWithCall(_ x: Int) -> Int {
return incrementByOneNoCMO(x) + 2
}
package func pkgFuncNoCMO(_ x: Int) -> Int {
return subPkgFuncNoCMO(x) + 2
}
public func submoduleKlassMember() -> Int {
let k = SubmoduleKlass()
return k.i
}
package func pkgSubmoduleKlassMember() -> Int {
let k = PkgSubmoduleKlass()
return k.i
}
public final class ModuleKlass {
public var i: Int
public init() {
i = 27
}
}
public func moduleKlassMember() -> Int {
let k = ModuleKlass()
return k.i
}
package final class PkgModuleKlass {
package var i: Int
package init() {
i = 27
}
}
package func pkgModuleKlassMember() -> Int {
let k = PkgModuleKlass()
return k.i
}
public struct ModuleStruct {
public static var publicFunctionPointer: (Int) -> (Int) = incrementByThree
public static var privateFunctionPointer: (Int) -> (Int) = { $0 }
}
package struct PkgModuleStruct {
package static var funcPointer: (Int) -> (Int) = pkgFunc
package static var closurePointer: (Int) -> (Int) = { $0 }
}
public func callPrivateCFunc() -> Int {
return Int(privateCFunc())
}
public func usePrivateCVar() -> Int {
return Int(privateCVar);
}
public struct S {
@usableFromInline
final class C {
@usableFromInline var p: UnsafeMutableRawPointer
init(p: UnsafeMutableRawPointer) { self.p = p }
}
@usableFromInline var c: C
public let b: Bool
public init(p: UnsafeMutableRawPointer, b: Bool) {
self.c = C(p: p)
self.b = b
}
public func load<T>(t: T.Type, i: Int) -> T {
if b {
return c.p.advanced(by: i).loadUnaligned(as: T.self)
}
return c.p.advanced(by: i).load(as: T.self)
}
}