forked from swiftlang/swift
- Notifications
You must be signed in to change notification settings - Fork 0
/
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 }{{$}}
@_transparentpublicfunc glass()->Int{return0}
// CHECK: @_effects(readnone) public func illiterate(){{$}}
@_effects(readnone)publicfunc illiterate(){}
// CHECK: @_effects(notEscaping arg1.**) public func escapeEffects(arg1: Swift.Int){{$}}
@_effects(notEscaping arg1.**)publicfunc escapeEffects(arg1:Int){}
// CHECK-LABEL: @frozen public struct Point {
@frozenpublicstructPoint{
// CHECK-NEXT: public var x: Swift.Int
publicvarx:Int
// CHECK-NEXT: public var y: Swift.Int
publicvary:Int
} // CHECK-NEXT: {{^}$}}
publicfunc someGenericFunction<T>(_ t:T)->Int{return0}
// 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)
internalfunc __specialize_someGenericFunction<T>(_ t:T)->Int{
fatalError("don't call")
}
@abi(func __abi__abiAttrOnFunction(param: Int))
publicfunc 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)
publicvarabiAttrOnVar: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
publicstructMutatingTest{
// 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())
publicmutatingfunc 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)publicfunc abiSpiFunc(){}
// We should print feature guards outside, but not inside, an @abi attribute.
@abi(func sendingABI()-> sending Any?)
publicfunc 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
publicfunc testExecutionConcurrent()async{}
// CHECK: @concurrent public func testExecutionConcurrent() async
nonisolated(nonsending)
publicfunc testExecutionCaller()async{}
// CHECK: nonisolated(nonsending) public func testExecutionCaller() async
// CHECK-NOT: @extensible
// CHECK: public enum TestExtensible
@extensible
publicenumTestExtensible{
case a
case b
}
publicstructTestPlacementOfAttrsAndSpecifiers{
// CHECK: public func test1<T>(_: sending @autoclosure () -> T)
publicfunc test1<T>(_:sending@autoclosure()->T){}
// CHECK: public func test2<T>(_: borrowing @autoclosure () -> T)
publicfunc test2<T>(_:borrowing@autoclosure()->T){}
// CHECK: public func test3<T>(_: inout () async -> T)
publicfunc test3<T>(_:inout()async->T){}
}