mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Previously, the initializer expressions of lazy vars would only be marked as subsumed when the getter body for the var was synthesized. This didn't work with `-experimental-lazy-typechecking` since accessor synthesis was not guaranteed to happen. Consequently, SILGen would emit the initializer even though it was already subsumed and then assert/crash since the init had also not been checked and contextualized. Now lazy var inits are marked subsumed in the request creating storage. Resolves rdar://118421753
42 lines
2.0 KiB
Swift
42 lines
2.0 KiB
Swift
// RUN: %empty-directory(%t)
|
|
// RUN: %target-swift-frontend -emit-silgen %s -module-name main -experimental-skip-non-inlinable-function-bodies | %FileCheck %s
|
|
// RUN: %target-swift-frontend -emit-silgen %s -module-name main -experimental-skip-non-inlinable-function-bodies-without-types | %FileCheck %s
|
|
// RUN: %target-swift-frontend -emit-silgen %s -module-name main -import-objc-header %S/Inputs/open_enum.h -debug-forbid-typecheck-prefix SKIP_ALL_NO_TYPECHECK -experimental-skip-all-function-bodies | %FileCheck %s --check-prefix=CHECK-SKIP-ALL
|
|
|
|
// CHECK-SKIP-ALL: sil_stage raw
|
|
// CHECK-SKIP-ALL-NOT: sil
|
|
|
|
public protocol P {
|
|
@_borrowed var borrowedVar: Int { get }
|
|
}
|
|
|
|
func generateNumber() -> Int { return 1 }
|
|
|
|
public struct S {
|
|
public var borrowedVar: Int
|
|
|
|
public lazy var lazyVar: Int = generateNumber()
|
|
|
|
// CHECK: sil [transparent] [serialized]{{.*}} @$s4main1SV7lazyVarSivM : $@yield_once @convention(method) (@inout S) -> @yields @inout Int
|
|
// CHECK: end sil function '$s4main1SV7lazyVarSivM'
|
|
|
|
// CHECK: sil [lazy_getter]{{.*}} @$s4main1SV7lazyVarSivg : $@convention(method) (@inout S) -> Int
|
|
// CHECK-NOT: end sil function '$s4main1SV7lazyVarSivg'
|
|
|
|
// CHECK: sil{{.*}} @$s4main1SV7lazyVarSivs : $@convention(method) (Int, @inout S) -> ()
|
|
// CHECK-NOT: end sil function '$s4main1SV7lazyVarSivs'
|
|
|
|
// CHECK: sil [transparent]{{.*}} @$s4main1SV018$__lazy_storage_$_B3Var33_39316373847D37F82BD23977A13DEF23LLSiSgvpfi : $@convention(thin) () -> Optional<Int>
|
|
// CHECK: end sil function '$s4main1SV018$__lazy_storage_$_B3Var33_39316373847D37F82BD23977A13DEF23LLSiSgvpfi'
|
|
|
|
}
|
|
|
|
/// Since `borrowedVar` implements a `@_borrowed` requirement of `P` the synthesized
|
|
/// `_read` accessor has forced static dispatch and is a serialized function
|
|
/// even though it is not `@_transparent`.
|
|
extension S: P {}
|
|
|
|
// CHECK: sil shared [serialized]{{.*}} @$s4main1SV11borrowedVarSivr : $@yield_once @convention(method) (S) -> @yields Int {
|
|
// CHECK: yield
|
|
// CHECK: } // end sil function '$s4main1SV11borrowedVarSivr'
|