-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathattrs.swift
266 lines (214 loc) · 8.21 KB
/
attrs.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend-dump-parse \
// RUN: -enable-experimental-feature ABIAttribute \
// RUN: -enable-experimental-feature ExecutionAttribute \
// RUN: -enable-experimental-feature Extern \
// RUN: -enable-experimental-feature LifetimeDependence \
// RUN: -enable-experimental-feature RawLayout \
// RUN: -enable-experimental-feature SymbolLinkageMarkers \
// RUN: -enable-experimental-concurrency \
// RUN: -enable-experimental-move-only \
// RUN: -enable-experimental-feature ParserASTGen \
// RUN: | %sanitize-address > %t/astgen.ast
// RUN: %target-swift-frontend-dump-parse \
// RUN: -enable-experimental-feature ABIAttribute \
// RUN: -enable-experimental-feature ExecutionAttribute \
// RUN: -enable-experimental-feature Extern \
// RUN: -enable-experimental-feature LifetimeDependence \
// RUN: -enable-experimental-feature RawLayout \
// RUN: -enable-experimental-feature SymbolLinkageMarkers \
// RUN: -enable-experimental-concurrency \
// RUN: -enable-experimental-move-only \
// RUN: | %sanitize-address > %t/cpp-parser.ast
// RUN: %diff -u %t/astgen.ast %t/cpp-parser.ast
// RUN: %target-typecheck-verify-swift \
// RUN: -module-abi-name ASTGen \
// RUN: -enable-experimental-feature ParserASTGen \
// RUN: -enable-experimental-feature ABIAttribute \
// RUN: -enable-experimental-feature ExecutionAttribute \
// RUN: -enable-experimental-feature Extern \
// RUN: -enable-experimental-feature LifetimeDependence \
// RUN: -enable-experimental-feature RawLayout \
// RUN: -enable-experimental-feature SymbolLinkageMarkers \
// RUN: -enable-experimental-concurrency \
// RUN: -enable-experimental-move-only
// REQUIRES: concurrency
// REQUIRES: executable_test
// REQUIRES: swift_swift_parser
// REQUIRES: swift_feature_ParserASTGen
// REQUIRES: swift_feature_ABIAttribute
// REQUIRES: swift_feature_ExecutionAttribute
// REQUIRES: swift_feature_Extern
// REQUIRES: swift_feature_LifetimeDependence
// REQUIRES: swift_feature_RawLayout
// REQUIRES: swift_feature_SymbolLinkageMarkers
// rdar://116686158
// UNSUPPORTED: asan
struct S1 {
static func staticMethod() {}
}
func testStatic() {
// static.
S1.staticMethod()
S1().staticMethod() // expected-error {{static member 'staticMethod' cannot be used on instance of type 'S1'}}
}
struct S2 {
private func privateMethod() {} // expected-note {{'privateMethod()' declared here}}
fileprivate func fileprivateMethod() {}
internal func internalMethod() {}
public func publicMethod() {}
}
func testAccessControl(value: S2) {
// access control.
value.privateMethod() // expected-error {{'privateMethod' is inaccessible due to 'private' protection level}}
value.fileprivateMethod()
value.internalMethod()
value.publicMethod()
}
struct S3 {
mutating func mutatingMethod() {}
func normalMethod() {}
}
func testMutating(value: S3) {
value.mutatingMethod() // expected-error {{cannot use mutating member on immutable value}}
value.normalMethod()
}
@frozen // expected-error {{'@frozen' attribute cannot be applied to this declaration}}
class C1 {}
@_alignment(7) // expected-error {{alignment value must be a power of two}}
struct S4 {}
@implementation extension ObjCClass1 {} // expected-error {{cannot find type 'ObjCClass1' in scope}}
@implementation(Category) extension ObjCClass1 {} // expected-error {{cannot find type 'ObjCClass1' in scope}}
@abi(func fn_abi()) // expected-error {{cannot give global function 'fn' the ABI of a global function with a different number of low-level parameters}}
func fn(_: Int) {}
@_alignment(8) struct AnyAlignment {}
@_allowFeatureSuppression(IsolatedAny) public func testFeatureSuppression(fn: @isolated(any) @Sendable () -> ()) {}
@_disallowFeatureSuppression(NoncopyableGenerics) public struct LoudlyNC<T: ~Copyable> {}
@_cdecl("c_function_name") func foo(x: Int) {}
struct StaticProperties {
dynamic var property: Int { return 1 }
}
extension StaticProperties {
@_dynamicReplacement(for: property)
var replacement_property: Int { return 2 }
}
@_documentation(visibility: internal) public protocol ProtocolShouldntAppear {}
@_documentation(metadata: cool_stuff) public class CoolClass {}
@_documentation(metadata: "this is a longer string") public class LongerMetadataClass {}
class EffectsTestClass {
}
struct EffectsTestStruct {
var c: EffectsTestClass
@_effects(releasenone) @_effects(readonly) // ok
init(releasenone_readonly c: EffectsTestClass) { self.c = c }
}
public final class CustomEffectsTestClass {
@usableFromInline
var i = 27
public init() { }
}
@_effects(notEscaping x.**)
public func noInlineWithEffects(_ x: CustomEffectsTestClass) -> Int {
return x.i
}
class ExclusivityAttrClass {
@exclusivity(unchecked) var instanceVar1: Int = 27
@exclusivity(checked) var instanceVar2: Int = 27
}
@_extern(wasm, module: "m1", name: "f1") func externWasmFn(x: Int) -> Int
@_extern(c, "valid") func externCValidFn()
@_extern(c) func externCFn()
struct SectionStruct {
@_section("__TEXT,__mysection") @_used func foo() {}
}
protocol ImplementsProto {
func f0() -> Int
}
struct ImplementsStruct: ImplementsProto {
@_implements(ImplementsProto, f0()) func foo() -> Int { 1 }
}
@inline(never) func neverInline() {}
@inline(__always) func alwaysInline() {}
@_nonSendable struct NonSendableWins: Sendable { }
@_nonSendable(_assumed) struct NonSendableLoses: Sendable { }
@_optimize(speed) func OspeedFunc() {}
@_private(sourceFile: "none") func foo() {} // expected-error {{@_private may only be used on 'import' declarations}} {{1-31=}}
struct ProjectedValueStruct {
@_projectedValueProperty($dummy)
let property: Never
}
@_semantics("foobar") func foobar() {}
@_silgen_name("silgen_func") func silGenFn() -> Int
@_specialize(where X: _TrivialStride(16), Y: _Trivial(32, 4), Z: _Class)
func testSpecialize<X, Y, Z>(x: X, y: Y, z: Z) {}
@_spi(SPIName) public func spiFn() {}
struct StorageRestrctionTest {
var x: Int
var y: String
var _x: Int {
@storageRestrictions(initializes: x, accesses: y)
init(initialValue) {}
get { x }
set { }
}
}
@_unavailableFromAsync struct UnavailFromAsyncStruct { } // expected-error {{'@_unavailableFromAsync' attribute cannot be applied to this declaration}}
@_unavailableFromAsync(message: "foo bar") func UnavailFromAsyncFn() {}
@execution(concurrent) func testGlobal() async { // Ok
}
do {
@execution(caller) func testLocal() async {} // Ok
struct Test {
@execution(concurrent) func testMember() async {} // Ok
}
}
typealias testConvention = @convention(c) (Int) -> Int
typealias testExecution = @execution(concurrent) () async -> Void
typealias testIsolated = @isolated(any) () -> Void
protocol OpProto {}
struct OpStruct: OpProto {}
struct OpTest {
func opResult() -> some OpProto { OpStruct() }
typealias Result = @_opaqueReturnTypeOf("$s6ASTGen6OpTestV8opResultQryF", 0) __
}
struct E {}
struct NE : ~Escapable {}
@lifetime(copy ne) func derive(_ ne: NE) -> NE { ne }
@lifetime(borrow ne1, copy ne2) func derive(_ ne1: NE, _ ne2: NE) -> NE {
if (Int.random(in: 1..<100) < 50) { return ne1 }
return ne2
}
@lifetime(borrow borrow) func testNameConflict(_ borrow: E) -> NE { NE() }
@lifetime(result: copy source) func testTarget(_ result: inout NE, _ source: consuming NE) { result = source }
actor MyActor {
nonisolated let constFlag: Bool = false
nonisolated(unsafe) var mutableFlag: Bool = false
}
func testNonIsolated(actor: MyActor) {
_ = actor.constFlag
_ = actor.mutableFlag
}
struct ReferenceOwnershipModifierTest<X: AnyObject> {
weak var weakValue: X?
unowned var unownedValue: X
unowned(safe) var unownedSafeValue: X
unowned(unsafe) var unmanagedValue: X
}
@_rawLayout(like: T) struct RawStorage<T>: ~Copyable {}
@_rawLayout(like: T, movesAsLike) struct RawStorage2<T>: ~Copyable {}
@_rawLayout(likeArrayOf: T, count: 4) struct RawSmallArray<T>: ~Copyable {}
@_rawLayout(size: 4, alignment: 4) struct Lock: ~Copyable {}
struct LayoutOuter {
struct Nested<T> {
var value: T
}
}
@_rawLayout(like: LayoutOuter.Nested<Int>) struct TypeExprTest: ~Copyable {}
@reasync protocol ReasyncProtocol {}
@rethrows protocol RethrowingProtocol {
func source() throws
}
@_typeEraser(AnyEraser) protocol EraserProto {}
struct AnyEraser: EraserProto {
init<T: EraserProto>(erasing: T) {}
}