- Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathfeatures.swift
191 lines (161 loc) · 6.23 KB
/
features.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// RUN: %empty-directory(%t)
// RUN: %target-swift-emit-module-interface(%t/FeatureTest.swiftinterface) %s -module-name FeatureTest -disable-availability-checking
// RUN: %target-swift-typecheck-module-from-interface(%t/FeatureTest.swiftinterface) -module-name FeatureTest -disable-availability-checking
// RUN: %FileCheck %s < %t/FeatureTest.swiftinterface
// REQUIRES: concurrency
// Ensure that when we emit a Swift interface that makes use of new features,
// the uses of those features are guarded by appropriate #if's that allow older
// compilers to skip over the uses of newer features.
// CHECK: #if compiler(>=5.3) && $SpecializeAttributeWithAvailability
// CHECK: @_specialize(exported: true, kind: full, availability: macOS, introduced: 12; where T == Swift.Int)
// CHECK: public func specializeWithAvailability<T>(_ t: T)
// CHECK: #else
// CHECK: public func specializeWithAvailability<T>(_ t: T)
// CHECK: #endif
@_specialize(exported:true, availability: macOS 12,*;where T == Int)
publicfunc specializeWithAvailability<T>(_ t:T){
}
// CHECK: #if compiler(>=5.3) && $Actors
// CHECK-NEXT: public actor MyActor
// CHECK: @_semantics("defaultActor") nonisolated final public var unownedExecutor: _Concurrency.UnownedSerialExecutor {
// CHECK-NEXT: get
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: #endif
publicactorMyActor{
}
// CHECK: #if compiler(>=5.3) && $Actors
// CHECK-NEXT: extension FeatureTest.MyActor
publicextensionMyActor{
// CHECK-NOT: $Actors
// CHECK: testFunc
func testFunc()async{}
// CHECK: }
// CHECK-NEXT: #endif
}
// CHECK: #if compiler(>=5.3) && $AsyncAwait
// CHECK-NEXT: globalAsync
// CHECK-NEXT: #endif
publicfunc globalAsync()async{}
// CHECK: @_marker public protocol MP {
// CHECK-NEXT: }
@_markerpublicprotocolMP{}
// CHECK: @_marker public protocol MP2 : FeatureTest.MP {
// CHECK-NEXT: }
@_markerpublicprotocolMP2:MP{}
// CHECK-NOT: #if compiler(>=5.3) && $MarkerProtocol
// CHECK: public protocol MP3 : AnyObject, FeatureTest.MP {
// CHECK-NEXT: }
publicprotocolMP3:AnyObject,MP{}
// CHECK: extension FeatureTest.MP2 {
// CHECK-NEXT: func inMP2
extensionMP2{
publicfunc inMP2(){}
}
// CHECK: class OldSchool : FeatureTest.MP {
publicclassOldSchool:MP{
// CHECK: #if compiler(>=5.3) && $AsyncAwait
// CHECK-NEXT: takeClass()
// CHECK-NEXT: #endif
publicfunc takeClass()async{}
}
// CHECK: class OldSchool2 : FeatureTest.MP {
publicclassOldSchool2:MP{
// CHECK: #if compiler(>=5.3) && $AsyncAwait
// CHECK-NEXT: takeClass()
// CHECK-NEXT: #endif
publicfunc takeClass()async{}
}
// CHECK: #if compiler(>=5.3) && $RethrowsProtocol
// CHECK-NEXT: @rethrows public protocol RP
@rethrowspublicprotocolRP{
func f()throws->Bool
}
// CHECK: public struct UsesRP {
publicstructUsesRP{
// CHECK: #if compiler(>=5.3) && $RethrowsProtocol
// CHECK-NEXT: public var value: (any FeatureTest.RP)? {
// CHECK-NOT: #if compiler(>=5.3) && $RethrowsProtocol
// CHECK: get
publicvarvalue:RP?{
nil
}
}
// CHECK: #if compiler(>=5.3) && $RethrowsProtocol
// CHECK-NEXT: public struct IsRP
publicstructIsRP:RP{
// CHECK-NEXT: public func f()
publicfunc f()->Bool{}
// CHECK-NOT: $RethrowsProtocol
// CHECK-NEXT: public var isF:
// CHECK-NEXT: get
publicvarisF:Bool{
f()
}
}
// CHECK: #if compiler(>=5.3) && $RethrowsProtocol
// CHECK-NEXT: public func acceptsRP
publicfunc acceptsRP<T:RP>(_:T){}
// CHECK-NOT: #if compiler(>=5.3) && $MarkerProtocol
// CHECK: extension Swift.Array : FeatureTest.MP where Element : FeatureTest.MP {
extensionArray:FeatureTest.MPwhere Element :FeatureTest.MP{}
// CHECK: }
// CHECK-NOT: #if compiler(>=5.3) && $MarkerProtocol
// CHECK: extension FeatureTest.OldSchool : Swift.UnsafeSendable {
extensionOldSchool:UnsafeSendable{}
// CHECK-NEXT: }
// CHECK: #if compiler(>=5.3) && $AsyncAwait
// CHECK-NEXT: func runSomethingSomewhere
// CHECK-NEXT: #endif
publicfunc runSomethingSomewhere(body:()async->Void){}
// CHECK: #if compiler(>=5.3) && $Sendable
// CHECK-NEXT: func runSomethingConcurrently(body: @Sendable () ->
// CHECK-NEXT: #endif
publicfunc runSomethingConcurrently(body:@Sendable()->Void){}
// CHECK: #if compiler(>=5.3) && $Actors
// CHECK-NEXT: func stage
// CHECK-NEXT: #endif
publicfunc stage(with actor:MyActor){}
// CHECK: #if compiler(>=5.3) && $AsyncAwait && $Sendable && $InheritActorContext
// CHECK-NEXT: func asyncIsh
// CHECK-NEXT: #endif
publicfunc asyncIsh(@_inheritActorContext operation:@Sendable@escaping()async->Void){}
// CHECK: #if compiler(>=5.3) && $AsyncAwait
// CHECK-NEXT: #if $UnsafeInheritExecutor
// CHECK-NEXT: @_unsafeInheritExecutor public func unsafeInheritExecutor() async
// CHECK-NEXT: #else
// CHECK-NEXT: public func unsafeInheritExecutor() async
// CHECK-NEXT: #endif
// CHECK-NEXT: #endif
@_unsafeInheritExecutor
publicfunc unsafeInheritExecutor()async{}
// CHECK: #if compiler(>=5.3) && $AsyncAwait
// CHECK-NEXT: #if $UnsafeInheritExecutor
// CHECK-NEXT: @_specialize{{.*}}
// CHECK-NEXT: @_unsafeInheritExecutor public func multipleSuppressible<T>(value: T) async
// CHECK-NEXT: #elseif $SpecializeAttributeWithAvailability
// CHECK-NEXT: @_specialize{{.*}}
// CHECK-NEXT: public func multipleSuppressible<T>(value: T) async
// CHECK-NEXT: #else
// CHECK-NEXT: public func multipleSuppressible<T>(value: T) async
// CHECK-NEXT: #endif
// CHECK-NEXT: #endif
@_unsafeInheritExecutor
@_specialize(exported:true, availability: SwiftStdlib 5.1,*;where T == Int)
publicfunc multipleSuppressible<T>(value:T)async{}
// CHECK: #if compiler(>=5.3) && $UnavailableFromAsync
// CHECK-NEXT: @_unavailableFromAsync(message: "Test") public func unavailableFromAsyncFunc()
// CHECK-NEXT: #else
// CHECK-NEXT: public func unavailableFromAsyncFunc()
// CHECK-NEXT: #endif
@_unavailableFromAsync(message:"Test")
publicfunc unavailableFromAsyncFunc(){}
// CHECK: #if compiler(>=5.3) && $NoAsyncAvailability
// CHECK-NEXT: @available(*, noasync, message: "Test")
// CHECK-NEXT: public func noAsyncFunc()
// CHECK-NEXT: #else
// CHECK-NEXT: public func noAsyncFunc()
// CHECK-NEXT: #endif
@available(*, noasync, message:"Test")
publicfunc noAsyncFunc(){}
// CHECK-NOT: extension FeatureTest.MyActor : Swift.Sendable