-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathattrs.swift
125 lines (107 loc) · 4.78 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
// RUN: %target-swift-emit-module-interface(%t.swiftinterface) %s -module-name attrs \
// RUN: -emit-private-module-interface-path %t.private.swiftinterface \
// RUN: -enable-experimental-feature ABIAttribute
// RUN: %target-swift-typecheck-module-from-interface(%t.swiftinterface) -module-name attrs
// RUN: %target-swift-typecheck-module-from-interface(%t.private.swiftinterface) -module-name attrs
// RUN: %FileCheck %s --check-prefixes CHECK,PUBLIC-CHECK --input-file %t.swiftinterface
// RUN: %FileCheck %s --check-prefixes CHECK,PRIVATE-CHECK --input-file %t.private.swiftinterface
// REQUIRES: swift_feature_ABIAttribute
// CHECK: @_transparent public func glass() -> Swift.Int { return 0 }{{$}}
@_transparent public func glass() -> Int { return 0 }
// CHECK: @_effects(readnone) public func illiterate(){{$}}
@_effects(readnone) public func illiterate() {}
// CHECK: @_effects(notEscaping arg1.**) public func escapeEffects(arg1: Swift.Int){{$}}
@_effects(notEscaping arg1.**) public func escapeEffects(arg1: Int) {}
// CHECK-LABEL: @frozen public struct Point {
@frozen public struct Point {
// CHECK-NEXT: public var x: Swift.Int
public var x: Int
// CHECK-NEXT: public var y: Swift.Int
public var y: Int
} // CHECK-NEXT: {{^}$}}
public func someGenericFunction<T>(_ t: T) -> Int { return 0 }
// CHECK: @_specialize(exported: true, kind: full, target: someGenericFunction(_:), where T == Swift.Int)
// CHECK: internal func __specialize_someGenericFunction<T>(_ t: T)
@_specialize(exported: true, target: someGenericFunction(_:), where T == Int)
internal func __specialize_someGenericFunction<T>(_ t: T) -> Int {
fatalError("don't call")
}
@abi(func __abi__abiAttrOnFunction(param: Int))
public func abiAttrOnFunction(param: Int) {}
// CHECK: #if {{.*}} $ABIAttribute
// CHECK: @abi(func __abi__abiAttrOnFunction(param: Swift.Int))
// CHECK: public func abiAttrOnFunction(param: Swift.Int)
// CHECK: #else
// CHECK: @_silgen_name("$s5attrs07__abi__B14AttrOnFunction5paramySi_tF")
// CHECK: public func abiAttrOnFunction(param: Swift.Int)
// CHECK: #endif
@abi(let __abi__abiAttrOnVar: Int)
public var abiAttrOnVar: Int = 42
// CHECK: #if {{.*}} $ABIAttribute
// CHECK: @abi(var __abi__abiAttrOnVar: Swift.Int)
// CHECK: public var abiAttrOnVar: Swift.Int
// CHECK: #else
// CHECK: @available(*, unavailable, message: "this compiler cannot match the ABI specified by the @abi attribute")
// CHECK: public var abiAttrOnVar: Swift.Int
// CHECK: #endif
public struct MutatingTest {
// CHECK: #if {{.*}} $ABIAttribute
// CHECK: @abi(mutating func abiMutFunc())
// CHECK: public mutating func abiMutFunc()
// CHECK: #else
// CHECK: @_silgen_name("$s5attrs12MutatingTestV10abiMutFuncyyF")
// CHECK: public mutating func abiMutFunc()
// CHECK: #endif
@abi(mutating func abiMutFunc())
public mutating func abiMutFunc() {}
}
// PUBLIC-CHECK-NOT: #if {{.*}} $ABIAttribute
// PUBLIC-CHECK-NOT: @abi(func abiSpiFunc())
// PUBLIC-CHECK-NOT: public func abiSpiFunc()
// PUBLIC-CHECK-NOT: #else
// PUBLIC-CHECK-NOT: @_silgen_name("$s5attrs10abiSpiFuncyyF")
// PUBLIC-CHECK-NOT: public func abiSpiFunc()
// PUBLIC-CHECK-NOT: #endif
// PRIVATE-CHECK: #if {{.*}} $ABIAttribute
// PRIVATE-CHECK: @abi(func abiSpiFunc())
// PRIVATE-CHECK: public func abiSpiFunc()
// PRIVATE-CHECK: #else
// PRIVATE-CHECK: @_silgen_name("$s5attrs10abiSpiFuncyyF")
// PRIVATE-CHECK: public func abiSpiFunc()
// PRIVATE-CHECK: #endif
@abi(func abiSpiFunc())
@_spi(spiGroup) public func abiSpiFunc() {}
// We should print feature guards outside, but not inside, an @abi attribute.
@abi(func sendingABI() -> sending Any?)
public func sendingABI() -> Any? { nil }
// CHECK: #if {{.*}} && $ABIAttribute
// CHECK: @abi(func sendingABI() -> sending Any?)
// CHECK: public func sendingABI() -> Any?
// CHECK: #elseif {{.*}} && $SendingArgsAndResults
// CHECK: @_silgen_name("$s5attrs10sendingABIypSgyF")
// CHECK: public func sendingABI() -> Any?
// CHECK: #else
// CHECK: @_silgen_name("$s5attrs10sendingABIypSgyF")
// CHECK: public func sendingABI() -> Any?
// CHECK: #endif
@concurrent
public func testExecutionConcurrent() async {}
// CHECK: @concurrent public func testExecutionConcurrent() async
nonisolated(nonsending)
public func testExecutionCaller() async {}
// CHECK: nonisolated(nonsending) public func testExecutionCaller() async
// CHECK-NOT: @extensible
// CHECK: public enum TestExtensible
@extensible
public enum TestExtensible {
case a
case b
}
public struct TestPlacementOfAttrsAndSpecifiers {
// CHECK: public func test1<T>(_: sending @autoclosure () -> T)
public func test1<T>(_: sending @autoclosure () -> T) {}
// CHECK: public func test2<T>(_: borrowing @autoclosure () -> T)
public func test2<T>(_: borrowing @autoclosure () -> T) {}
// CHECK: public func test3<T>(_: inout () async -> T)
public func test3<T>(_: inout () async -> T) {}
}