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
|
// RUN: %target-swift-frontend -enable-library-evolution -strict-concurrency=complete %s -emit-sil -o /dev/null -verify
// RUN: %target-swift-frontend -enable-library-evolution -strict-concurrency=complete %s -emit-sil -o /dev/null -verify -enable-upcoming-feature RegionBasedIsolation
// REQUIRES: concurrency
// REQUIRES: asserts
class C1 { } // expected-note {{class 'C1' does not conform to the 'Sendable' protocol}}
final class C2: Sendable { }
struct S1 {
var x: Int
var s: String
var c: C2
}
enum E1 { // expected-note {{consider making enum 'E1' conform to the 'Sendable' protocol}}{{9-9=: Sendable}}
case base
indirect case nested(E1)
}
enum E2 {
case s1(S1)
case c2(C2)
}
struct GS1<T> { }
struct GS2<T> { // expected-note {{consider making generic struct 'GS2' conform to the 'Sendable' protocol}}
var storage: T
}
func acceptCV<T: Sendable>(_: T) { }
// Example that was triggering circular dependencies.
struct Signature { }
struct Data { }
struct BlockInfo { }
struct Bitcode { // expected-note {{consider making struct 'Bitcode' conform to the 'Sendable' protocol}}
let signature: Signature
let elements: [BitcodeElement]
let blockInfo: [UInt64: BlockInfo]
}
enum BitcodeElement {
struct Block {
var id: UInt64
var elements: [BitcodeElement]
}
struct Record {
enum Payload {
case none
case array([UInt64])
case char6String(String)
case blob(Data)
}
var id: UInt64
var fields: [UInt64]
var payload: Payload
}
case block(Block)
case record(Record)
}
// Public structs and enums do not get implicit Sendable unless they
// are frozen.
public struct PublicStruct { // expected-note {{consider making struct 'PublicStruct' conform to the 'Sendable' protocol}}
var i: Int
}
public enum PublicEnum { // expected-note {{consider making enum 'PublicEnum' conform to the 'Sendable' protocol}}
case some
}
@frozen public struct FrozenPublicStruct {
var i: Int
}
@frozen public enum FrozenPublicEnum {
case some
}
struct HasFunctions {
var tfp: @convention(thin) () -> Void
var cfp: @convention(c) () -> Void
}
@available(SwiftStdlib 5.1, *)
@globalActor
actor MyGlobalActor {
static let shared = MyGlobalActor()
}
@available(SwiftStdlib 5.1, *)
@MyGlobalActor
class C3 { }
@available(SwiftStdlib 5.1, *)
class C4: C3 { }
// Make Sendable unavailable, but be sure not to diagnose it.
struct S2 {
var c1: C1
}
@available(*, unavailable)
extension S2: Sendable { }
@available(SwiftStdlib 5.1, *)
func testCV(
c1: C1, c2: C2, c3: C3, c4: C4, s1: S1, e1: E1, e2: E2,
gs1: GS1<Int>, gs2: GS2<Int>,
bc: Bitcode, ps: PublicStruct, pe: PublicEnum,
fps: FrozenPublicStruct, fpe: FrozenPublicEnum,
hf: HasFunctions
) {
acceptCV(c1) // expected-warning {{type 'C1' does not conform to the 'Sendable' protocol}}
acceptCV(c2)
acceptCV(c3)
acceptCV(c4)
acceptCV(s1)
acceptCV(e1) // expected-warning {{type 'E1' does not conform to the 'Sendable'}}
acceptCV(e2)
acceptCV(gs1)
acceptCV(gs2) // expected-warning {{type 'GS2<Int>' does not conform to the 'Sendable' protocol}}
// Not available due to recursive conformance dependencies.
acceptCV(bc) // expected-warning {{type 'Bitcode' does not conform to the 'Sendable' protocol}}
// Not available due to "public".
acceptCV(ps) // expected-warning {{type 'PublicStruct' does not conform to the 'Sendable' protocol}}
acceptCV(pe) // expected-warning {{type 'PublicEnum' does not conform to the 'Sendable' protocol}}
// Public is okay when also @frozen.
acceptCV(fps)
acceptCV(fpe)
// Thin and C function types are Sendable.
acceptCV(hf)
}
|