mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
just making them thin. Among other things, this allows us to pass the metatype self value with the swiftself convention, which has various advantages.
36 lines
946 B
Swift
36 lines
946 B
Swift
// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -O -emit-sil -primary-file %s | FileCheck %s
|
|
//
|
|
// This is a .swift test because the SIL parser does not support Self.
|
|
|
|
class C {
|
|
required init() {}
|
|
}
|
|
|
|
class SubC : C {}
|
|
|
|
var g: AnyObject = SubC()
|
|
|
|
@inline(never)
|
|
func gen<R>() -> R {
|
|
return g as! R
|
|
}
|
|
|
|
extension C {
|
|
@inline(__always)
|
|
class func factory(_ z: Int) -> Self {
|
|
return gen()
|
|
}
|
|
}
|
|
|
|
// Do not inline C.factory into main. Doing so would lose the ability
|
|
// to materialize local Self metadata.
|
|
//
|
|
// CHECK-LABEL: sil @main : $@convention(c)
|
|
// CHECK: function_ref static inline_self.C.factory (Swift.Int) -> Self
|
|
// CHECK: [[F:%[0-9]+]] = function_ref @_TZFC11inline_self1C7factory{{.*}} : $@convention(method) (Int, @thick C.Type) -> @owned C
|
|
// CHECK: apply [[F]](%{{.+}}, %{{.+}}) : $@convention(method) (Int, @thick C.Type) -> @owned C
|
|
|
|
// Call the function so it can be inlined.
|
|
var x = C()
|
|
var x2 = C.factory(1)
|