Skip to content

Commit 0854b93

Browse files
committed
Tests: Upstream a few availability related tests for visionOS.
Resolves rdar://124158932.
1 parent 3472312 commit 0854b93

File tree

3 files changed

+270
-0
lines changed

3 files changed

+270
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// RUN: %swift -typecheck -verify -parse-stdlib -target arm64-apple-xros2.0 %s
2+
3+
@available(visionOS, introduced: 1.0, deprecated: 1.5, obsoleted: 2.0,
4+
message: "you don't want to do that anyway")
5+
public func doSomething() { }
6+
// expected-note @-1{{'doSomething()' was obsoleted in visionOS 2.0}}
7+
8+
doSomething() // expected-error{{'doSomething()' is unavailable in visionOS: you don't want to do that anyway}}
9+
10+
// Preservation of major.minor.micro
11+
@available(visionOS, introduced: 1.0, deprecated: 1.5, obsoleted: 1.5.3)
12+
func doSomethingElse() { }
13+
// expected-note @-1{{'doSomethingElse()' was obsoleted in visionOS 1.5.3}}
14+
15+
doSomethingElse() // expected-error{{'doSomethingElse()' is unavailable in visionOS}}
16+
17+
// Preservation of minor-only version
18+
@available(visionOS, introduced: 1.0, deprecated: 1.5, obsoleted: 2)
19+
func doSomethingReallyOld() { }
20+
// expected-note @-1{{'doSomethingReallyOld()' was obsoleted in visionOS 2}}
21+
22+
doSomethingReallyOld() // expected-error{{'doSomethingReallyOld()' is unavailable in visionOS}}
23+
24+
// Test deprecations in 2.0 and later
25+
26+
@available(visionOS, introduced: 1.1, deprecated: 2.0,
27+
message: "Use another function")
28+
func deprecatedFunctionWithMessage() { }
29+
30+
deprecatedFunctionWithMessage() // expected-warning{{'deprecatedFunctionWithMessage()' was deprecated in visionOS 2.0: Use another function}}
31+
32+
33+
@available(visionOS, introduced: 1.0, deprecated: 2.0)
34+
func deprecatedFunctionWithoutMessage() { }
35+
36+
deprecatedFunctionWithoutMessage() // expected-warning{{'deprecatedFunctionWithoutMessage()' was deprecated in visionOS 2.0}}
37+
38+
@available(visionOS, introduced: 1.0, deprecated: 2.0,
39+
message: "Use BetterClass instead")
40+
class DeprecatedClass { }
41+
42+
func functionWithDeprecatedParameter(p: DeprecatedClass) { } // expected-warning{{'DeprecatedClass' was deprecated in visionOS 2.0: Use BetterClass instead}}
43+
44+
@available(visionOS, introduced: 2.0, deprecated: 4.0,
45+
message: "Use BetterClass instead")
46+
class DeprecatedClassIn3_0 { }
47+
48+
// Elements deprecated later than the minimum deployment target (which is 2.0, in this case) should not generate warnings
49+
func functionWithDeprecatedLaterParameter(p: DeprecatedClassIn3_0) { }
50+
51+
// Treat visionOS as an alias for iOS in availability queries
52+
53+
@available(visionOS, introduced: 2.2)
54+
func functionIntroducedOnvisionOS2_2() { }
55+
56+
if #available(iOS 17.3, *) {
57+
functionIntroducedOnvisionOS2_2() // expected-error{{'functionIntroducedOnvisionOS2_2()' is only available in visionOS 2.2 or newer}}
58+
// expected-note @-1{{add 'if #available' version check}}
59+
}
60+
61+
if #available(visionOS 1.5, *) {
62+
functionIntroducedOnvisionOS2_2() // expected-error{{'functionIntroducedOnvisionOS2_2()' is only available in visionOS 2.2 or newer}}
63+
// expected-note @-1{{add 'if #available' version check}}
64+
}
65+
66+
if #available(visionOS 2.2, *) {
67+
functionIntroducedOnvisionOS2_2()
68+
}
69+
70+
@available(visionOS 1.50.4, *)
71+
public func foo() { }
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// RUN: %target-typecheck-verify-swift -parse-as-library
2+
3+
// REQUIRES: OS=xros
4+
5+
@backDeployed(before: visionOS 2) // Ok, introduced availability is inferred to be visionOS epoch
6+
public func topLevelFunc() {}
7+
8+
public struct TopLevelStruct {
9+
@backDeployed(before: visionOS 2) // Ok, introduced availability is inferred to be visionOS epoch
10+
public func methodInStruct() {}
11+
}
12+
13+
extension TopLevelStruct {
14+
@backDeployed(before: visionOS 2) // Ok, introduced availability is inferred to be visionOS epoch
15+
public func methodInExtension() {}
16+
}
17+
18+
@available(visionOS 1.1, *)
19+
@backDeployed(before: visionOS 2) // Ok, introduced availability is earlier than visionOS 2
20+
public func availableBeforeBackDeployment() {}
21+
22+
@available(iOS 17, *)
23+
@backDeployed(before: iOS 17.4) // Ok, introduced availability is earlier than visionOS 1.1
24+
public func availableOniOSBeforeBackDeploymentOniOS() {}
25+
26+
@available(iOS 15, *)
27+
@backDeployed(before: iOS 16) // Ok, both iOS availability and back deployment are earlier than the visionOS epoch
28+
public func availableOnEarlyiOSBeforeBackDeploymentOnEarlyiOS() {}
29+
30+
@available(iOS 13, *)
31+
@backDeployed(before: visionOS 2) // Ok, re-mapped introduced availability is earlier than visionOS 2
32+
public func availableOniOSBeforeBackDeployment() {}
33+
34+
@available(iOS 17.4, visionOS 1, *)
35+
@backDeployed(before: visionOS 1.1) // Ok, introduced availability is earlier than visionOS 1.1
36+
public func availableBeforeBackDeploymentOnVisionOSNotOniOS() {}
37+
38+
@available(visionOS 2, *) // expected-note {{'availableSameVersionAsBackDeployment()' was introduced in visionOS 2}}
39+
@backDeployed(before: visionOS 2) // expected-error {{'@backDeployed' has no effect because 'availableSameVersionAsBackDeployment()' is not available before visionOS 2}}
40+
public func availableSameVersionAsBackDeployment() {}
41+
42+
@available(iOS 17.4, *) // expected-note {{'availableSameRemappedVersionAsBackDeployment()' was introduced in visionOS 1.1}}
43+
@backDeployed(before: visionOS 1.1) // expected-error {{'@backDeployed' has no effect because 'availableSameRemappedVersionAsBackDeployment()' is not available before visionOS 1.1}}
44+
public func availableSameRemappedVersionAsBackDeployment() {}
45+
46+
@available(iOS 17, visionOS 2, *) // expected-note {{'availableSameVersionAsBackDeploymentAndAlsoAvailableEarlierOniOS()' was introduced in visionOS 2}}
47+
@backDeployed(before: visionOS 2) // expected-error {{'@backDeployed' has no effect because 'availableSameVersionAsBackDeploymentAndAlsoAvailableEarlierOniOS()' is not available before visionOS 2}}
48+
public func availableSameVersionAsBackDeploymentAndAlsoAvailableEarlierOniOS() {}
49+
50+
@available(visionOS 2.1, *) // expected-note {{'availableAfterBackDeployment()' was introduced in visionOS 2.1}}
51+
@backDeployed(before: visionOS 2) // expected-error {{'@backDeployed' has no effect because 'availableAfterBackDeployment()' is not available before visionOS 2}}
52+
public func availableAfterBackDeployment() {}
53+
54+
@available(iOS 99, *) // expected-note {{'availableOniOSAfterBackDeploymentOniOS()' was introduced in visionOS 99}}
55+
@backDeployed(before: iOS 17.4) // expected-error {{'@backDeployed' has no effect because 'availableOniOSAfterBackDeploymentOniOS()' is not available before visionOS 1.1}}
56+
public func availableOniOSAfterBackDeploymentOniOS() {}
57+
58+
@available(visionOS 2, *) // expected-note {{'memberFuncBackDeploymentSame()' was introduced in visionOS 2}}
59+
public struct AvailableVisionOSStruct {
60+
@backDeployed(before: visionOS 2.1)
61+
public func memberFunc() {}
62+
63+
@backDeployed(before: visionOS 2) // expected-error {{'@backDeployed' has no effect because 'memberFuncBackDeploymentSame()' is not available before visionOS 2}}
64+
public func memberFuncBackDeploymentSame() {}
65+
}
66+
67+
@available(iOS 17.4, *) // expected-note {{'memberFuncBackDeploymentSame()' was introduced in visionOS 1.1}}
68+
public struct AvailableiOSStruct {
69+
@backDeployed(before: visionOS 2)
70+
public func memberFunc() {}
71+
72+
@backDeployed(before: visionOS 1.1) // expected-error {{'@backDeployed' has no effect because 'memberFuncBackDeploymentSame()' is not available before visionOS 1.1}}
73+
public func memberFuncBackDeploymentSame() {}
74+
}
75+
76+
@available(*, unavailable) // expected-note {{'alwaysUnavailableFunc()' has been explicitly marked unavailable here}}
77+
@backDeployed(before: visionOS 2) // expected-error {{'@backDeployed' has no effect because 'alwaysUnavailableFunc()' is unavailable on visionOS}}
78+
public func alwaysUnavailableFunc() {}
79+
80+
@available(visionOS, unavailable) // expected-note {{'unavailableOnVisionOSFunc()' has been explicitly marked unavailable here}}
81+
@backDeployed(before: visionOS 2) // expected-error {{'@backDeployed' has no effect because 'unavailableOnVisionOSFunc()' is unavailable on visionOS}}
82+
public func unavailableOnVisionOSFunc() {}
83+
84+
@available(visionOSApplicationExtension, unavailable)
85+
@backDeployed(before: visionOS 2)
86+
public func unavailableForVisionOSExtensionsFunc() {}
87+
88+
@available(iOS, unavailable) // expected-note {{'unavailableOniOSFunc()' has been explicitly marked unavailable here}}
89+
@backDeployed(before: visionOS 2) // expected-error {{'@backDeployed' has no effect because 'unavailableOniOSFunc()' is unavailable on visionOS}}
90+
public func unavailableOniOSFunc() {}
91+
92+
@available(iOSApplicationExtension, unavailable)
93+
@backDeployed(before: visionOS 2)
94+
public func unavailableForiOSExtensionsFunc() {}
95+
96+
@available(visionOS, unavailable)
97+
@backDeployed(before: iOS 17.4)
98+
public func unavailableOnVisionOSBackDeployedOniOSFunc() {}
99+
100+
@available(visionOS, unavailable) // expected-note {{'memberFunc()' has been explicitly marked unavailable here}}
101+
public struct UnavailableVisionOSStruct {
102+
@backDeployed(before: visionOS 2) // expected-error {{'@backDeployed' has no effect because 'memberFunc()' is unavailable on visionOS}}
103+
public func memberFunc() {}
104+
}
105+
106+
@available(iOS, unavailable) // expected-note {{'memberFunc()' has been explicitly marked unavailable here}}
107+
public struct UnavailableiOSStruct {
108+
@backDeployed(before: visionOS 2) // expected-error {{'@backDeployed' has no effect because 'memberFunc()' is unavailable on visionOS}}
109+
public func memberFunc() {}
110+
}
111+
112+
@available(visionOS, unavailable) // expected-note {{'methodInUnavailableExtension()' has been explicitly marked unavailable here}}
113+
extension TopLevelStruct {
114+
@backDeployed(before: visionOS 2) // expected-error {{'@backDeployed' has no effect because 'methodInUnavailableExtension()' is unavailable on visionOS}}
115+
public func methodInUnavailableExtension() {}
116+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// RUN: %target-swift-emit-sil -parse-as-library -module-name back_deploy %s -target %target-cpu-apple-xros1.0 -verify
2+
// RUN: %target-swift-emit-silgen -parse-as-library -module-name back_deploy %s -target %target-cpu-apple-xros1.0 | %FileCheck %s
3+
4+
// REQUIRES: OS=xros
5+
6+
// -- Fallback definition of trivialFunc()
7+
// CHECK-LABEL: sil non_abi [serialized] [ossa] @$s11back_deploy11trivialFuncyyFTwB : $@convention(thin) () -> ()
8+
// CHECK: bb0:
9+
// CHECK: [[RESULT:%.*]] = tuple ()
10+
// CHECK: return [[RESULT]] : $()
11+
12+
// -- Back deployment thunk for trivialFunc()
13+
// CHECK-LABEL: sil non_abi [serialized] [thunk] [ossa] @$s11back_deploy11trivialFuncyyFTwb : $@convention(thin) () -> ()
14+
// CHECK: bb0:
15+
// CHECK: [[MAJOR:%.*]] = integer_literal $Builtin.Word, 2
16+
// CHECK: [[MINOR:%.*]] = integer_literal $Builtin.Word, 0
17+
// CHECK: [[PATCH:%.*]] = integer_literal $Builtin.Word, 0
18+
// CHECK: [[OSVFN:%.*]] = function_ref @$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF : $@convention(thin) (Builtin.Word, Builtin.Word, Builtin.Word) -> Builtin.Int1
19+
// CHECK: [[AVAIL:%.*]] = apply [[OSVFN]]([[MAJOR]], [[MINOR]], [[PATCH]]) : $@convention(thin) (Builtin.Word, Builtin.Word, Builtin.Word) -> Builtin.Int1
20+
// CHECK: cond_br [[AVAIL]], [[AVAIL_BB:bb[0-9]+]], [[UNAVAIL_BB:bb[0-9]+]]
21+
//
22+
// CHECK: [[UNAVAIL_BB]]:
23+
// CHECK: [[FALLBACKFN:%.*]] = function_ref @$s11back_deploy11trivialFuncyyFTwB : $@convention(thin) () -> ()
24+
// CHECK: {{%.*}} = apply [[FALLBACKFN]]() : $@convention(thin) () -> ()
25+
// CHECK: br [[RETURN_BB:bb[0-9]+]]
26+
//
27+
// CHECK: [[AVAIL_BB]]:
28+
// CHECK: [[ORIGFN:%.*]] = function_ref @$s11back_deploy11trivialFuncyyF : $@convention(thin) () -> ()
29+
// CHECK: {{%.*}} = apply [[ORIGFN]]() : $@convention(thin) () -> ()
30+
// CHECK: br [[RETURN_BB]]
31+
//
32+
// CHECK: [[RETURN_BB]]
33+
// CHECK: [[RESULT:%.*]] = tuple ()
34+
// CHECK: return [[RESULT]] : $()
35+
36+
// -- Original definition of trivialFunc()
37+
// CHECK-LABEL: sil [available 2] [ossa] @$s11back_deploy11trivialFuncyyF : $@convention(thin) () -> ()
38+
@backDeployed(before: visionOS 2)
39+
public func trivialFunc() {}
40+
41+
// -- Fallback definition of trivialFunc_iOS()
42+
// CHECK-LABEL: sil non_abi [serialized] [ossa] @$s11back_deploy15trivialFunc_iOSyyFTwB : $@convention(thin) () -> ()
43+
// CHECK: bb0:
44+
// CHECK: [[RESULT:%.*]] = tuple ()
45+
// CHECK: return [[RESULT]] : $()
46+
47+
// -- Back deployment thunk for trivialFunc_iOS()
48+
// CHECK-LABEL: sil non_abi [serialized] [thunk] [ossa] @$s11back_deploy15trivialFunc_iOSyyFTwb : $@convention(thin) () -> ()
49+
// CHECK: bb0:
50+
// CHECK: [[MAJOR:%.*]] = integer_literal $Builtin.Word, 1
51+
// CHECK: [[MINOR:%.*]] = integer_literal $Builtin.Word, 1
52+
// CHECK: [[PATCH:%.*]] = integer_literal $Builtin.Word, 0
53+
// CHECK: [[OSVFN:%.*]] = function_ref @$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF : $@convention(thin) (Builtin.Word, Builtin.Word, Builtin.Word) -> Builtin.Int1
54+
// CHECK: [[AVAIL:%.*]] = apply [[OSVFN]]([[MAJOR]], [[MINOR]], [[PATCH]]) : $@convention(thin) (Builtin.Word, Builtin.Word, Builtin.Word) -> Builtin.Int1
55+
// CHECK: cond_br [[AVAIL]], [[AVAIL_BB:bb[0-9]+]], [[UNAVAIL_BB:bb[0-9]+]]
56+
//
57+
// CHECK: [[UNAVAIL_BB]]:
58+
// CHECK: [[FALLBACKFN:%.*]] = function_ref @$s11back_deploy15trivialFunc_iOSyyFTwB : $@convention(thin) () -> ()
59+
// CHECK: {{%.*}} = apply [[FALLBACKFN]]() : $@convention(thin) () -> ()
60+
// CHECK: br [[RETURN_BB:bb[0-9]+]]
61+
//
62+
// CHECK: [[AVAIL_BB]]:
63+
// CHECK: [[ORIGFN:%.*]] = function_ref @$s11back_deploy15trivialFunc_iOSyyF : $@convention(thin) () -> ()
64+
// CHECK: {{%.*}} = apply [[ORIGFN]]() : $@convention(thin) () -> ()
65+
// CHECK: br [[RETURN_BB]]
66+
//
67+
// CHECK: [[RETURN_BB]]
68+
// CHECK: [[RESULT:%.*]] = tuple ()
69+
// CHECK: return [[RESULT]] : $()
70+
71+
// -- Original definition of trivialFunc_iOS()
72+
// CHECK-LABEL: sil [available 1.1] [ossa] @$s11back_deploy15trivialFunc_iOSyyF : $@convention(thin) () -> ()
73+
@backDeployed(before: iOS 17.4)
74+
public func trivialFunc_iOS() {}
75+
76+
// CHECK-LABEL: sil hidden [ossa] @$s11back_deploy6calleryyF : $@convention(thin) () -> ()
77+
func caller() {
78+
// -- Verify the thunk is called
79+
// CHECK: {{%.*}} = function_ref @$s11back_deploy11trivialFuncyyFTwb : $@convention(thin) () -> ()
80+
trivialFunc()
81+
// CHECK: {{%.*}} = function_ref @$s11back_deploy15trivialFunc_iOSyyFTwb : $@convention(thin) () -> ()
82+
trivialFunc_iOS()
83+
}

0 commit comments

Comments
 (0)