Files
swift-mirror/test/SILGen/optional_to_bool.swift
Erik Eckstein 2de425665c PerformanceInliner: prevent inlining of lazy property getters
Lazy property getters are usually non tivial functions (otherwise the user would not implement it as lazy property).
Inlining such getters would most likely not benefit other optimizations because the top-level switch_enum cannot be constant folded in most cases.
Also, not inlining lazy property getters enables optimizing them in CSE.
2020-03-13 09:49:56 +01:00

26 lines
860 B
Swift

// RUN: %target-swift-emit-silgen %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-runtime
public protocol P {}
extension Int: P {}
public class A {}
public class B: A {
// CHECK-LABEL: sil [lazy_getter] [noinline] [ossa] @$s16optional_to_bool1BC1x{{[_0-9a-zA-Z]*}}vg
// CHECK: switch_enum {{%.*}} : $Optional<Int>
public lazy var x: Int = 0
// CHECK-LABEL: sil [lazy_getter] [noinline] [ossa] @$s16optional_to_bool1BC1y{{[_0-9a-zA-Z]*}}vg
// CHECK: switch_enum_addr {{%.*}} : $*Optional<P>
public lazy var y: P = 0
}
// Collection casting is not implemented in non-ObjC runtime
#if _runtime(_ObjC)
// CHECK-objc-LABEL: sil [ossa] @$s16optional_to_bool3foo{{[_0-9a-zA-Z]*}}F
public func foo(x: inout [A]) -> Bool {
// CHECK-objc: select_enum {{%.*}} : $Optional<Array<B>>
return x is [B]
}
#endif