mirror of
https://github.com/apple/swift.git
synced 2026-09-30 10:17:34 +02:00
This is a version of -emit-silgen that emits the earliest "complete" OSSA SIL right after SILGen. It does ownership verification prior to emission. This is handy for people just wanting to ensure programs can make it through SILGen correctly and emit valid Raw SIL, without running any extra SIL passes or triggering any of the diagnostics in the mandatory SIL pipeline. Combining it with `-sil-verify-all` gives you extra assurance that the SIL coming out of SILGen is right even prior to the clean-up. Asserts builds will do that automatically.
33 lines
658 B
Swift
33 lines
658 B
Swift
// RUN: %target-swift-emit-silgen-ossa %s
|
|
|
|
// Capture list with weak capture vs noescape closure
|
|
func transform<T>(fn: () -> T) -> T {
|
|
return fn()
|
|
}
|
|
|
|
// Make sure weak and unowned are captured by box, even from a noescape closure.
|
|
|
|
class Bar {
|
|
var x: Int = 27
|
|
|
|
func test() {
|
|
transform { [weak self] in
|
|
return self!.x
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// Capture list vs autoclosure.
|
|
|
|
func block(_ f: () -> Void) -> Int { return 42 }
|
|
func oneOf(_ a: Int?, _ b: @autoclosure () -> Int) -> Int { return 0 }
|
|
class Foo {
|
|
private var value: Int?
|
|
func refresh() {
|
|
_ = oneOf(self.value, block({
|
|
[unowned self] in _ = self
|
|
}))
|
|
}
|
|
}
|