File: concurrency.swift

package info (click to toggle)
swiftlang 6.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,532 kB
  • sloc: cpp: 9,901,743; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (96 lines) | stat: -rw-r--r-- 3,807 bytes parent folder | download | duplicates (2)
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
// RUN: %empty-directory(%t)
// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -enable-experimental-concurrency -DLIBRARY -module-name Library
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -enable-experimental-concurrency

// REQUIRES: concurrency

#if LIBRARY
@available(SwiftStdlib 5.5, *)
public func fn() async {
  fatalError()
}

@available(SwiftStdlib 5.5, *)
public func reasyncFn(_: () async -> ()) reasync {
  fatalError()
}

@available(SwiftStdlib 5.5, *)
public func takesSendable(
  _ block: @Sendable @escaping () async throws -> Void
) { }

@available(SwiftStdlib 5.5, *)
public func takesMainActor(
  _ block: @MainActor @escaping () -> Void
) { }

@MainActor(unsafe)
public protocol UnsafeMainProtocol {
  func requirement()
}

public struct InferredUnsafeMainActor: UnsafeMainProtocol {
  public func requirement() {}
  @preconcurrency public func explicitPreconcurrency() {}
}

@preconcurrency @MainActor
public protocol PreconcurrencyMainProtocol {
  func requirement()
}

public struct InferredPreconcurrencyMainActor: PreconcurrencyMainProtocol {
  public func requirement() {}
  @preconcurrency public func explicitPreconcurrency() {}
}

// rdar://122965951
public struct UncheckedSendable: @unchecked Sendable {}
extension UnsafePointer : @retroactive @unchecked Sendable {}

// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency -I %t

#else
import Library

@available(SwiftStdlib 5.5, *)
func callFn() async {
  await fn()
}
#endif

// RUN: %FileCheck --check-prefix=CHECK --check-prefix=CHECK-TYPECHECKED %s < %t/Library.swiftinterface
// CHECK: // swift-module-flags:{{.*}} -enable-experimental-concurrency
// CHECK: public func fn() async
// CHECK: public func reasyncFn(_: () async -> ()) reasync
// CHECK: public func takesSendable(_ block: {{@escaping @Sendable|@Sendable @escaping}} () async throws ->
// CHECK: public func takesMainActor(_ block: {{@escaping @_Concurrency.MainActor|@MainActor @escaping}} () ->

// CHECK:      @_Concurrency.MainActor @preconcurrency public protocol UnsafeMainProtocol {
// CHECK-NEXT:   @_Concurrency.MainActor @preconcurrency func requirement()
// CHECK-NEXT: }

// CHECK:      @_Concurrency.MainActor @preconcurrency public struct InferredUnsafeMainActor :
// CHECK-NEXT:   @_Concurrency.MainActor @preconcurrency public func requirement()
// CHECK-NEXT:   @preconcurrency @_Concurrency.MainActor public func explicitPreconcurrency()
// CHECK-NEXT: }

// CHECK:      @preconcurrency @_Concurrency.MainActor public protocol PreconcurrencyMainProtocol {
// CHECK-NEXT:   @_Concurrency.MainActor @preconcurrency func requirement()
// CHECK-NEXT: }

// CHECK:      @_Concurrency.MainActor @preconcurrency public struct InferredPreconcurrencyMainActor :
// CHECK-NEXT:   @_Concurrency.MainActor @preconcurrency public func requirement()
// CHECK-NEXT:   @preconcurrency @_Concurrency.MainActor public func explicitPreconcurrency()
// CHECK-NEXT: }

// CHECK-TYPECHECKED: public struct UncheckedSendable : @unchecked Swift.Sendable
// CHECK-ASWRITTEN: public struct UncheckedSendable : @unchecked Sendable

// CHECK-TYPECHECKED: extension Swift.UnsafePointer : @unchecked @retroactive Swift.Sendable
// CHECK-ASWRITTEN: extension UnsafePointer : @retroactive @unchecked Sendable

// RUN: %target-swift-emit-module-interface(%t/LibraryPreserveTypesAsWritten.swiftinterface) %s -enable-experimental-concurrency -DLIBRARY -module-name LibraryPreserveTypesAsWritten -module-interface-preserve-types-as-written
// RUN: %target-swift-typecheck-module-from-interface(%t/LibraryPreserveTypesAsWritten.swiftinterface) -enable-experimental-concurrency
// RUN: %FileCheck --check-prefix=CHECK --check-prefix=CHECK-ASWRITTEN %s < %t/LibraryPreserveTypesAsWritten.swiftinterface