Skip to content

Tests: Upstream a few availability related tests for visionOS #78918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions test/attr/attr_availability_vision.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// RUN: %swift -typecheck -verify -parse-stdlib -target arm64-apple-xros2.0 %s

@available(visionOS, introduced: 1.0, deprecated: 1.5, obsoleted: 2.0,
message: "you don't want to do that anyway")
public func doSomething() { }
// expected-note @-1{{'doSomething()' was obsoleted in visionOS 2.0}}

doSomething() // expected-error{{'doSomething()' is unavailable in visionOS: you don't want to do that anyway}}

// Preservation of major.minor.micro
@available(visionOS, introduced: 1.0, deprecated: 1.5, obsoleted: 1.5.3)
func doSomethingElse() { }
// expected-note @-1{{'doSomethingElse()' was obsoleted in visionOS 1.5.3}}

doSomethingElse() // expected-error{{'doSomethingElse()' is unavailable in visionOS}}

// Preservation of minor-only version
@available(visionOS, introduced: 1.0, deprecated: 1.5, obsoleted: 2)
func doSomethingReallyOld() { }
// expected-note @-1{{'doSomethingReallyOld()' was obsoleted in visionOS 2}}

doSomethingReallyOld() // expected-error{{'doSomethingReallyOld()' is unavailable in visionOS}}

// Test deprecations in 2.0 and later

@available(visionOS, introduced: 1.1, deprecated: 2.0,
message: "Use another function")
func deprecatedFunctionWithMessage() { }

deprecatedFunctionWithMessage() // expected-warning{{'deprecatedFunctionWithMessage()' was deprecated in visionOS 2.0: Use another function}}


@available(visionOS, introduced: 1.0, deprecated: 2.0)
func deprecatedFunctionWithoutMessage() { }

deprecatedFunctionWithoutMessage() // expected-warning{{'deprecatedFunctionWithoutMessage()' was deprecated in visionOS 2.0}}

@available(visionOS, introduced: 1.0, deprecated: 2.0,
message: "Use BetterClass instead")
class DeprecatedClass { }

func functionWithDeprecatedParameter(p: DeprecatedClass) { } // expected-warning{{'DeprecatedClass' was deprecated in visionOS 2.0: Use BetterClass instead}}

@available(visionOS, introduced: 2.0, deprecated: 4.0,
message: "Use BetterClass instead")
class DeprecatedClassIn3_0 { }

// Elements deprecated later than the minimum deployment target (which is 2.0, in this case) should not generate warnings
func functionWithDeprecatedLaterParameter(p: DeprecatedClassIn3_0) { }

// Treat visionOS as an alias for iOS in availability queries

@available(visionOS, introduced: 2.2)
func functionIntroducedOnvisionOS2_2() { }

if #available(iOS 17.3, *) {
functionIntroducedOnvisionOS2_2() // expected-error{{'functionIntroducedOnvisionOS2_2()' is only available in visionOS 2.2 or newer}}
// expected-note @-1{{add 'if #available' version check}}
}

if #available(visionOS 1.5, *) {
functionIntroducedOnvisionOS2_2() // expected-error{{'functionIntroducedOnvisionOS2_2()' is only available in visionOS 2.2 or newer}}
// expected-note @-1{{add 'if #available' version check}}
}

if #available(visionOS 2.2, *) {
functionIntroducedOnvisionOS2_2()
}

@available(visionOS 1.50.4, *)
public func foo() { }
116 changes: 116 additions & 0 deletions test/attr/attr_backDeployed_availability_visionos.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// RUN: %target-typecheck-verify-swift -parse-as-library

// REQUIRES: OS=xros

@backDeployed(before: visionOS 2) // Ok, introduced availability is inferred to be visionOS epoch
public func topLevelFunc() {}

public struct TopLevelStruct {
@backDeployed(before: visionOS 2) // Ok, introduced availability is inferred to be visionOS epoch
public func methodInStruct() {}
}

extension TopLevelStruct {
@backDeployed(before: visionOS 2) // Ok, introduced availability is inferred to be visionOS epoch
public func methodInExtension() {}
}

@available(visionOS 1.1, *)
@backDeployed(before: visionOS 2) // Ok, introduced availability is earlier than visionOS 2
public func availableBeforeBackDeployment() {}

@available(iOS 17, *)
@backDeployed(before: iOS 17.4) // Ok, introduced availability is earlier than visionOS 1.1
public func availableOniOSBeforeBackDeploymentOniOS() {}

@available(iOS 15, *)
@backDeployed(before: iOS 16) // Ok, both iOS availability and back deployment are earlier than the visionOS epoch
public func availableOnEarlyiOSBeforeBackDeploymentOnEarlyiOS() {}

@available(iOS 13, *)
@backDeployed(before: visionOS 2) // Ok, re-mapped introduced availability is earlier than visionOS 2
public func availableOniOSBeforeBackDeployment() {}

@available(iOS 17.4, visionOS 1, *)
@backDeployed(before: visionOS 1.1) // Ok, introduced availability is earlier than visionOS 1.1
public func availableBeforeBackDeploymentOnVisionOSNotOniOS() {}

@available(visionOS 2, *) // expected-note {{'availableSameVersionAsBackDeployment()' was introduced in visionOS 2}}
@backDeployed(before: visionOS 2) // expected-error {{'@backDeployed' has no effect because 'availableSameVersionAsBackDeployment()' is not available before visionOS 2}}
public func availableSameVersionAsBackDeployment() {}

@available(iOS 17.4, *) // expected-note {{'availableSameRemappedVersionAsBackDeployment()' was introduced in visionOS 1.1}}
@backDeployed(before: visionOS 1.1) // expected-error {{'@backDeployed' has no effect because 'availableSameRemappedVersionAsBackDeployment()' is not available before visionOS 1.1}}
public func availableSameRemappedVersionAsBackDeployment() {}

@available(iOS 17, visionOS 2, *) // expected-note {{'availableSameVersionAsBackDeploymentAndAlsoAvailableEarlierOniOS()' was introduced in visionOS 2}}
@backDeployed(before: visionOS 2) // expected-error {{'@backDeployed' has no effect because 'availableSameVersionAsBackDeploymentAndAlsoAvailableEarlierOniOS()' is not available before visionOS 2}}
public func availableSameVersionAsBackDeploymentAndAlsoAvailableEarlierOniOS() {}

@available(visionOS 2.1, *) // expected-note {{'availableAfterBackDeployment()' was introduced in visionOS 2.1}}
@backDeployed(before: visionOS 2) // expected-error {{'@backDeployed' has no effect because 'availableAfterBackDeployment()' is not available before visionOS 2}}
public func availableAfterBackDeployment() {}

@available(iOS 99, *) // expected-note {{'availableOniOSAfterBackDeploymentOniOS()' was introduced in visionOS 99}}
@backDeployed(before: iOS 17.4) // expected-error {{'@backDeployed' has no effect because 'availableOniOSAfterBackDeploymentOniOS()' is not available before visionOS 1.1}}
public func availableOniOSAfterBackDeploymentOniOS() {}

@available(visionOS 2, *) // expected-note {{'memberFuncBackDeploymentSame()' was introduced in visionOS 2}}
public struct AvailableVisionOSStruct {
@backDeployed(before: visionOS 2.1)
public func memberFunc() {}

@backDeployed(before: visionOS 2) // expected-error {{'@backDeployed' has no effect because 'memberFuncBackDeploymentSame()' is not available before visionOS 2}}
public func memberFuncBackDeploymentSame() {}
}

@available(iOS 17.4, *) // expected-note {{'memberFuncBackDeploymentSame()' was introduced in visionOS 1.1}}
public struct AvailableiOSStruct {
@backDeployed(before: visionOS 2)
public func memberFunc() {}

@backDeployed(before: visionOS 1.1) // expected-error {{'@backDeployed' has no effect because 'memberFuncBackDeploymentSame()' is not available before visionOS 1.1}}
public func memberFuncBackDeploymentSame() {}
}

@available(*, unavailable) // expected-note {{'alwaysUnavailableFunc()' has been explicitly marked unavailable here}}
@backDeployed(before: visionOS 2) // expected-error {{'@backDeployed' has no effect because 'alwaysUnavailableFunc()' is unavailable on visionOS}}
public func alwaysUnavailableFunc() {}

@available(visionOS, unavailable) // expected-note {{'unavailableOnVisionOSFunc()' has been explicitly marked unavailable here}}
@backDeployed(before: visionOS 2) // expected-error {{'@backDeployed' has no effect because 'unavailableOnVisionOSFunc()' is unavailable on visionOS}}
public func unavailableOnVisionOSFunc() {}

@available(visionOSApplicationExtension, unavailable)
@backDeployed(before: visionOS 2)
public func unavailableForVisionOSExtensionsFunc() {}

@available(iOS, unavailable) // expected-note {{'unavailableOniOSFunc()' has been explicitly marked unavailable here}}
@backDeployed(before: visionOS 2) // expected-error {{'@backDeployed' has no effect because 'unavailableOniOSFunc()' is unavailable on visionOS}}
public func unavailableOniOSFunc() {}

@available(iOSApplicationExtension, unavailable)
@backDeployed(before: visionOS 2)
public func unavailableForiOSExtensionsFunc() {}

@available(visionOS, unavailable)
@backDeployed(before: iOS 17.4)
public func unavailableOnVisionOSBackDeployedOniOSFunc() {}

@available(visionOS, unavailable) // expected-note {{'memberFunc()' has been explicitly marked unavailable here}}
public struct UnavailableVisionOSStruct {
@backDeployed(before: visionOS 2) // expected-error {{'@backDeployed' has no effect because 'memberFunc()' is unavailable on visionOS}}
public func memberFunc() {}
}

@available(iOS, unavailable) // expected-note {{'memberFunc()' has been explicitly marked unavailable here}}
public struct UnavailableiOSStruct {
@backDeployed(before: visionOS 2) // expected-error {{'@backDeployed' has no effect because 'memberFunc()' is unavailable on visionOS}}
public func memberFunc() {}
}

@available(visionOS, unavailable) // expected-note {{'methodInUnavailableExtension()' has been explicitly marked unavailable here}}
extension TopLevelStruct {
@backDeployed(before: visionOS 2) // expected-error {{'@backDeployed' has no effect because 'methodInUnavailableExtension()' is unavailable on visionOS}}
public func methodInUnavailableExtension() {}
}
83 changes: 83 additions & 0 deletions test/attr/back_deployed_attr_func_visionos.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// RUN: %target-swift-emit-sil -parse-as-library -module-name back_deploy %s -target %target-cpu-apple-xros1.0 -verify
// RUN: %target-swift-emit-silgen -parse-as-library -module-name back_deploy %s -target %target-cpu-apple-xros1.0 | %FileCheck %s

// REQUIRES: OS=xros

// -- Fallback definition of trivialFunc()
// CHECK-LABEL: sil non_abi [serialized] [ossa] @$s11back_deploy11trivialFuncyyFTwB : $@convention(thin) () -> ()
// CHECK: bb0:
// CHECK: [[RESULT:%.*]] = tuple ()
// CHECK: return [[RESULT]] : $()

// -- Back deployment thunk for trivialFunc()
// CHECK-LABEL: sil non_abi [serialized] [thunk] [ossa] @$s11back_deploy11trivialFuncyyFTwb : $@convention(thin) () -> ()
// CHECK: bb0:
// CHECK: [[MAJOR:%.*]] = integer_literal $Builtin.Word, 2
// CHECK: [[MINOR:%.*]] = integer_literal $Builtin.Word, 0
// CHECK: [[PATCH:%.*]] = integer_literal $Builtin.Word, 0
// CHECK: [[OSVFN:%.*]] = function_ref @$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF : $@convention(thin) (Builtin.Word, Builtin.Word, Builtin.Word) -> Builtin.Int1
// CHECK: [[AVAIL:%.*]] = apply [[OSVFN]]([[MAJOR]], [[MINOR]], [[PATCH]]) : $@convention(thin) (Builtin.Word, Builtin.Word, Builtin.Word) -> Builtin.Int1
// CHECK: cond_br [[AVAIL]], [[AVAIL_BB:bb[0-9]+]], [[UNAVAIL_BB:bb[0-9]+]]
//
// CHECK: [[UNAVAIL_BB]]:
// CHECK: [[FALLBACKFN:%.*]] = function_ref @$s11back_deploy11trivialFuncyyFTwB : $@convention(thin) () -> ()
// CHECK: {{%.*}} = apply [[FALLBACKFN]]() : $@convention(thin) () -> ()
// CHECK: br [[RETURN_BB:bb[0-9]+]]
//
// CHECK: [[AVAIL_BB]]:
// CHECK: [[ORIGFN:%.*]] = function_ref @$s11back_deploy11trivialFuncyyF : $@convention(thin) () -> ()
// CHECK: {{%.*}} = apply [[ORIGFN]]() : $@convention(thin) () -> ()
// CHECK: br [[RETURN_BB]]
//
// CHECK: [[RETURN_BB]]
// CHECK: [[RESULT:%.*]] = tuple ()
// CHECK: return [[RESULT]] : $()

// -- Original definition of trivialFunc()
// CHECK-LABEL: sil [available 2] [ossa] @$s11back_deploy11trivialFuncyyF : $@convention(thin) () -> ()
@backDeployed(before: visionOS 2)
public func trivialFunc() {}

// -- Fallback definition of trivialFunc_iOS()
// CHECK-LABEL: sil non_abi [serialized] [ossa] @$s11back_deploy15trivialFunc_iOSyyFTwB : $@convention(thin) () -> ()
// CHECK: bb0:
// CHECK: [[RESULT:%.*]] = tuple ()
// CHECK: return [[RESULT]] : $()

// -- Back deployment thunk for trivialFunc_iOS()
// CHECK-LABEL: sil non_abi [serialized] [thunk] [ossa] @$s11back_deploy15trivialFunc_iOSyyFTwb : $@convention(thin) () -> ()
// CHECK: bb0:
// CHECK: [[MAJOR:%.*]] = integer_literal $Builtin.Word, 1
// CHECK: [[MINOR:%.*]] = integer_literal $Builtin.Word, 1
// CHECK: [[PATCH:%.*]] = integer_literal $Builtin.Word, 0
// CHECK: [[OSVFN:%.*]] = function_ref @$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF : $@convention(thin) (Builtin.Word, Builtin.Word, Builtin.Word) -> Builtin.Int1
// CHECK: [[AVAIL:%.*]] = apply [[OSVFN]]([[MAJOR]], [[MINOR]], [[PATCH]]) : $@convention(thin) (Builtin.Word, Builtin.Word, Builtin.Word) -> Builtin.Int1
// CHECK: cond_br [[AVAIL]], [[AVAIL_BB:bb[0-9]+]], [[UNAVAIL_BB:bb[0-9]+]]
//
// CHECK: [[UNAVAIL_BB]]:
// CHECK: [[FALLBACKFN:%.*]] = function_ref @$s11back_deploy15trivialFunc_iOSyyFTwB : $@convention(thin) () -> ()
// CHECK: {{%.*}} = apply [[FALLBACKFN]]() : $@convention(thin) () -> ()
// CHECK: br [[RETURN_BB:bb[0-9]+]]
//
// CHECK: [[AVAIL_BB]]:
// CHECK: [[ORIGFN:%.*]] = function_ref @$s11back_deploy15trivialFunc_iOSyyF : $@convention(thin) () -> ()
// CHECK: {{%.*}} = apply [[ORIGFN]]() : $@convention(thin) () -> ()
// CHECK: br [[RETURN_BB]]
//
// CHECK: [[RETURN_BB]]
// CHECK: [[RESULT:%.*]] = tuple ()
// CHECK: return [[RESULT]] : $()

// -- Original definition of trivialFunc_iOS()
// CHECK-LABEL: sil [available 1.1] [ossa] @$s11back_deploy15trivialFunc_iOSyyF : $@convention(thin) () -> ()
@backDeployed(before: iOS 17.4)
public func trivialFunc_iOS() {}

// CHECK-LABEL: sil hidden [ossa] @$s11back_deploy6calleryyF : $@convention(thin) () -> ()
func caller() {
// -- Verify the thunk is called
// CHECK: {{%.*}} = function_ref @$s11back_deploy11trivialFuncyyFTwb : $@convention(thin) () -> ()
trivialFunc()
// CHECK: {{%.*}} = function_ref @$s11back_deploy15trivialFunc_iOSyyFTwb : $@convention(thin) () -> ()
trivialFunc_iOS()
}