mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
To make it possible to change the implementation of _stdlib_isOSVersionAtLeast(), remove the @inlinable attribute from it. Since it is currently inlinable and calls the helper function _swift_stdlib_operatingSystemVersion(), we’ll have to keep the helper around as ABI. This change causes a minor pessimization where the LLVM optimizer can no longer reason that, for example, a successful check for 10.12 availability means that a later check for 10.11 will always succeed. I don't expect this pessimization to be a problem, but if needed we could write a custom SIL optimizer pass to claw back the performance. <rdar://problem/59447474>
62 lines
2.3 KiB
Swift
62 lines
2.3 KiB
Swift
// RUN: %target-swift-frontend -primary-file %s -emit-ir | %FileCheck %s
|
|
// RUN: %target-swift-frontend -primary-file %s -O -emit-ir | %FileCheck %s --check-prefix=OPT
|
|
|
|
// REQUIRES: objc_interop
|
|
|
|
import Foundation
|
|
|
|
// We mustn't hoist the alloc_stack for measurement out of the availability
|
|
// guard.
|
|
|
|
// CHECK-LABEL: define{{.*}} @{{.*}}dontHoist
|
|
// CHECK-NOT: s10Foundation11MeasurementVySo17NSUnitTemperature
|
|
// CHECK: call swiftcc i1 @"$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF"(
|
|
// CHECK: s10Foundation11MeasurementVySo17NSUnitTemperature
|
|
|
|
// OPT-LABEL: define{{.*}} @{{.*}}dontHoist
|
|
// OPT-NOT: S10Foundation11MeasurementVySo17NSUnitTemperature
|
|
// OPT: call {{.*}} @"$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF"(
|
|
// OPT: s10Foundation11MeasurementVySo17NSUnitTemperature
|
|
|
|
public func dontHoist() {
|
|
if #available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
|
|
let measurement = Measurement<UnitTemperature>(value: Double(42), unit: .celsius)
|
|
print("\(measurement)")
|
|
} else {
|
|
print("Not measurement")
|
|
}
|
|
}
|
|
|
|
|
|
// Now that _isOSVersionAtLeast is no longer inlinable, we do still
|
|
// mark it as _effects(readnone).
|
|
// This means that unlike in the past the optimizer can now only coalesce
|
|
// availability checks with the same availability. It does not determine,
|
|
// for example, that a check for iOS 10 is sufficient to guarantee that a check
|
|
// for iOS 9 will also succeed.
|
|
|
|
// With optimizations on, multiple #availability checks should generate only
|
|
// a single call into _isOSVersionAtLeast.
|
|
|
|
// CHECK-LABEL: define{{.*}} @{{.*}}multipleAvailabilityChecks
|
|
// CHECK: call swiftcc i1 @"$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF"(
|
|
// CHECK: call swiftcc i1 @"$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF"(
|
|
// CHECK: call swiftcc i1 @"$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF"(
|
|
// CHECK: ret void
|
|
|
|
// OPT-LABEL: define{{.*}} @{{.*}}multipleAvailabilityChecks
|
|
// OPT: call {{.*}} @"$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF"
|
|
// OPT-NOT: call {{.*}} @"$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF"
|
|
// OPT: ret void
|
|
public func multipleAvailabilityChecks() {
|
|
if #available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
|
|
print("test one")
|
|
}
|
|
if #available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
|
|
print("test two")
|
|
}
|
|
if #available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
|
|
print("test three")
|
|
}
|
|
}
|