File: attrs.swift

package info (click to toggle)
swiftlang 6.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,856,264 kB
  • sloc: cpp: 9,995,718; ansic: 2,234,019; asm: 1,092,167; python: 313,940; objc: 82,726; f90: 80,126; lisp: 38,373; pascal: 25,580; sh: 20,378; ml: 5,058; perl: 4,751; makefile: 4,725; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (114 lines) | stat: -rw-r--r-- 4,709 bytes parent folder | download
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
// RUN: %target-swift-emit-module-interface(%t.swiftinterface) %s -module-name attrs \
// RUN:  -emit-private-module-interface-path %t.private.swiftinterface

// 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

// 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 {{.*}} $ABIAttributeSE0479
// 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 {{.*}} $ABIAttributeSE0479
// 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 {{.*}} $ABIAttributeSE0479
  // 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 {{.*}} $ABIAttributeSE0479
// 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 {{.*}} $ABIAttributeSE0479
// 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 {{.*}} && $ABIAttributeSE0479
// 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

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) {}
}