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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
|
// RUN: %target-swift-emit-sil -sil-verify-all -verify %s
class CopyableKlass {}
protocol P {}
extension CopyableKlass : P {}
public struct NonTrivialStruct : ~Copyable {
var k = CopyableKlass()
}
public struct AddressOnlyMoveOnlyContainingProtocol : ~Copyable {
var copyable: any P = CopyableKlass()
var moveOnly = NonTrivialStruct()
func nonMutatingFunc() {}
mutating func mutatingFunc() {}
}
// MARK: Getter Only
public struct LoadableSubscriptGetOnlyTester : ~Copyable {
subscript(_ i: Int) -> AddressOnlyMoveOnlyContainingProtocol {
get {
fatalError()
}
}
}
public func testSubscriptGetOnly_BaseLoadable_ResultAddressOnly_Var() {
var m = LoadableSubscriptGetOnlyTester()
m = LoadableSubscriptGetOnlyTester()
m[0].nonMutatingFunc()
}
public func testSubscriptGetOnly_BaseLoadable_ResultAddressOnly_Let() {
let m = LoadableSubscriptGetOnlyTester()
m[0].nonMutatingFunc()
}
public func testSubscriptGetOnly_BaseLoadable_ResultAddressOnly_InOut(m: inout LoadableSubscriptGetOnlyTester) {
m[0].nonMutatingFunc()
}
var globalLoadableSubscriptGetOnlyTester = LoadableSubscriptGetOnlyTester()
public func testSubscriptGetOnly_BaseLoadable_ResultAddressOnly_Global() {
globalLoadableSubscriptGetOnlyTester[0].nonMutatingFunc()
}
// Make sure that we get the same behavior when we access through another noncopyable struct.
public struct LoadableSubscriptGetOnlyTesterNonCopyableStructParent : ~Copyable {
var tester = LoadableSubscriptGetOnlyTester()
var computedTester: LoadableSubscriptGetOnlyTester { fatalError() }
}
public func testSubscriptGetOnlyThroughNonCopyableParentStruct_BaseLoadable_ResultAddressOnly_Var() {
var m = LoadableSubscriptGetOnlyTesterNonCopyableStructParent()
m = LoadableSubscriptGetOnlyTesterNonCopyableStructParent()
m.tester[0].nonMutatingFunc()
m.computedTester[0].nonMutatingFunc()
}
public func testSubscriptGetOnlyThroughNonCopyableParentStruct_BaseLoadable_ResultAddressOnly_Let() {
let m = LoadableSubscriptGetOnlyTesterNonCopyableStructParent()
m.tester[0].nonMutatingFunc()
}
public func testSubscriptGetOnlyThroughNonCopyableParentStruct_BaseLoadable_ResultAddressOnly_InOut(m: inout LoadableSubscriptGetOnlyTesterNonCopyableStructParent) {
m.tester[0].nonMutatingFunc()
}
var globalLoadableSubscriptGetOnlyTesterNonCopyableStructParent = LoadableSubscriptGetOnlyTesterNonCopyableStructParent()
public func testSubscriptGetOnlyThroughNonCopyableParentStruct_BaseLoadable_ResultAddressOnly_Global() {
globalLoadableSubscriptGetOnlyTesterNonCopyableStructParent.tester[0].nonMutatingFunc()
}
public class LoadableSubscriptGetOnlyTesterClassParent {
var tester = LoadableSubscriptGetOnlyTester()
var computedTester: LoadableSubscriptGetOnlyTester { fatalError() }
var testerParent = LoadableSubscriptGetOnlyTesterNonCopyableStructParent()
}
public func testSubscriptGetOnlyThroughParentClass_BaseLoadable_ResultAddressOnly_Var() {
var m = LoadableSubscriptGetOnlyTesterClassParent()
m = LoadableSubscriptGetOnlyTesterClassParent()
m.tester[0].nonMutatingFunc()
m.testerParent.tester[0].nonMutatingFunc()
m.computedTester[0].nonMutatingFunc()
}
// MARK: Getter + Setter.
// This is different since adding a setter changes how we codegen.
public struct LoadableSubscriptGetSetTester : ~Copyable {
subscript(_ i: Int) -> AddressOnlyMoveOnlyContainingProtocol {
get {
fatalError()
}
set {
fatalError()
}
}
}
public func testSubscriptGetSet_BaseLoadable_ResultAddressOnly_Var() {
var m = LoadableSubscriptGetSetTester()
m = LoadableSubscriptGetSetTester()
m[0].nonMutatingFunc()
m[0] = AddressOnlyMoveOnlyContainingProtocol()
m[0].mutatingFunc()
}
public func testSubscriptGetSet_BaseLoadable_ResultAddressOnly_Let() {
let m = LoadableSubscriptGetSetTester()
m[0].nonMutatingFunc()
}
public func testSubscriptGetSet_BaseLoadable_ResultAddressOnly_InOut(m: inout LoadableSubscriptGetSetTester) {
m[0].nonMutatingFunc()
m[0] = AddressOnlyMoveOnlyContainingProtocol()
m[0].mutatingFunc()
}
var globalLoadableSubscriptGetSetTester = LoadableSubscriptGetSetTester()
public func testSubscriptGetSet_BaseLoadable_ResultAddressOnly_Global() {
globalLoadableSubscriptGetSetTester[0].nonMutatingFunc()
globalLoadableSubscriptGetSetTester[0] = AddressOnlyMoveOnlyContainingProtocol()
globalLoadableSubscriptGetSetTester[0].mutatingFunc()
}
// Make sure that we get the same behavior when we access through another noncopyable struct.
public struct LoadableSubscriptGetSetTesterNonCopyableStructParent : ~Copyable {
var tester = LoadableSubscriptGetSetTester()
var computedTester: LoadableSubscriptGetSetTester { fatalError() }
}
public func testSubscriptGetSetThroughNonCopyableParentStruct_BaseLoadable_ResultAddressOnly_Var() {
var m = LoadableSubscriptGetSetTesterNonCopyableStructParent()
m = LoadableSubscriptGetSetTesterNonCopyableStructParent()
m.tester[0].nonMutatingFunc()
m.tester[0].mutatingFunc()
m.computedTester[0].nonMutatingFunc()
}
public func testSubscriptGetSetThroughNonCopyableParentStruct_BaseLoadable_ResultAddressOnly_Let() {
let m = LoadableSubscriptGetSetTesterNonCopyableStructParent()
m.tester[0].nonMutatingFunc()
}
public func testSubscriptGetSetThroughNonCopyableParentStruct_BaseLoadable_ResultAddressOnly_InOut(m: inout LoadableSubscriptGetSetTesterNonCopyableStructParent) {
m.tester[0].nonMutatingFunc()
m.tester[0].mutatingFunc()
}
var globalLoadableSubscriptGetSetTesterNonCopyableStructParent = LoadableSubscriptGetSetTesterNonCopyableStructParent()
public func testSubscriptGetSetThroughNonCopyableParentStruct_BaseLoadable_ResultAddressOnly_Global() {
globalLoadableSubscriptGetSetTesterNonCopyableStructParent.tester[0].nonMutatingFunc()
globalLoadableSubscriptGetSetTesterNonCopyableStructParent.tester[0].mutatingFunc()
}
public class LoadableSubscriptGetSetTesterClassParent {
var tester = LoadableSubscriptGetSetTester()
var computedTester: LoadableSubscriptGetSetTester { fatalError() }
var computedTester2: LoadableSubscriptGetSetTester {
get { fatalError() }
set { fatalError() }
}
var testerParent = LoadableSubscriptGetSetTesterNonCopyableStructParent()
}
public func testSubscriptGetSetThroughParentClass_BaseLoadable_ResultAddressOnly_Var() {
var m = LoadableSubscriptGetSetTesterClassParent()
m = LoadableSubscriptGetSetTesterClassParent()
m.tester[0].nonMutatingFunc()
m.tester[0].mutatingFunc()
m.testerParent.tester[0].nonMutatingFunc()
m.testerParent.tester[0].mutatingFunc()
m.computedTester[0].nonMutatingFunc()
m.computedTester2[0].nonMutatingFunc()
m.computedTester2[0].mutatingFunc()
}
// MARK: _read and _modify
public struct LoadableSubscriptReadModifyTester : ~Copyable {
subscript(_ i: Int) -> AddressOnlyMoveOnlyContainingProtocol {
_read {
fatalError()
}
_modify {
fatalError()
}
}
}
public func testSubscriptReadModify_BaseLoadable_ResultAddressOnly_Var() {
var m = LoadableSubscriptReadModifyTester()
m = LoadableSubscriptReadModifyTester()
m[0].nonMutatingFunc()
m[0] = AddressOnlyMoveOnlyContainingProtocol()
m[0].mutatingFunc()
}
public func testSubscriptReadModify_BaseLoadable_ResultAddressOnly_Let() {
let m = LoadableSubscriptReadModifyTester()
m[0].nonMutatingFunc()
}
public func testSubscriptReadModify_BaseLoadable_ResultAddressOnly_InOut(m: inout LoadableSubscriptReadModifyTester) {
m[0].nonMutatingFunc()
m[0] = AddressOnlyMoveOnlyContainingProtocol()
m[0].mutatingFunc()
}
var globalLoadableSubscriptReadModifyTester = LoadableSubscriptReadModifyTester()
public func testSubscriptReadModify_BaseLoadable_ResultAddressOnly_Global() {
globalLoadableSubscriptReadModifyTester[0].nonMutatingFunc()
globalLoadableSubscriptReadModifyTester[0] = AddressOnlyMoveOnlyContainingProtocol()
globalLoadableSubscriptReadModifyTester[0].mutatingFunc()
}
// Make sure that we get the same behavior when we access through another noncopyable struct.
public struct LoadableSubscriptReadModifyTesterNonCopyableStructParent : ~Copyable {
var tester = LoadableSubscriptReadModifyTester()
var computedTester: LoadableSubscriptReadModifyTester { fatalError() }
}
public func testSubscriptReadModifyThroughNonCopyableParentStruct_BaseLoadable_ResultAddressOnly_Var() {
var m = LoadableSubscriptReadModifyTesterNonCopyableStructParent()
m = LoadableSubscriptReadModifyTesterNonCopyableStructParent()
m.tester[0].nonMutatingFunc()
m.tester[0].mutatingFunc()
m.computedTester[0].nonMutatingFunc()
}
public func testSubscriptReadModifyThroughNonCopyableParentStruct_BaseLoadable_ResultAddressOnly_Let() {
let m = LoadableSubscriptReadModifyTesterNonCopyableStructParent()
m.tester[0].nonMutatingFunc()
}
public func testSubscriptReadModifyThroughNonCopyableParentStruct_BaseLoadable_ResultAddressOnly_InOut(m: inout LoadableSubscriptReadModifyTesterNonCopyableStructParent) {
m.tester[0].nonMutatingFunc()
m.tester[0].mutatingFunc()
}
var globalLoadableSubscriptReadModifyTesterNonCopyableStructParent = LoadableSubscriptReadModifyTesterNonCopyableStructParent()
public func testSubscriptReadModifyThroughNonCopyableParentStruct_BaseLoadable_ResultAddressOnly_Global() {
globalLoadableSubscriptReadModifyTesterNonCopyableStructParent.tester[0].nonMutatingFunc()
globalLoadableSubscriptReadModifyTesterNonCopyableStructParent.tester[0].mutatingFunc()
}
public class LoadableSubscriptReadModifyTesterClassParent {
var tester = LoadableSubscriptReadModifyTester()
var computedTester: LoadableSubscriptReadModifyTester { fatalError() }
var computedTester2: LoadableSubscriptReadModifyTester {
get { fatalError() }
set { fatalError() }
}
var testerParent = LoadableSubscriptReadModifyTesterNonCopyableStructParent()
}
public func testSubscriptReadModifyThroughParentClass_BaseLoadable_ResultAddressOnly_Var() {
var m = LoadableSubscriptReadModifyTesterClassParent()
m = LoadableSubscriptReadModifyTesterClassParent()
m.tester[0].nonMutatingFunc()
m.tester[0].mutatingFunc()
m.testerParent.tester[0].nonMutatingFunc()
m.testerParent.tester[0].mutatingFunc()
m.computedTester[0].nonMutatingFunc()
m.computedTester2[0].nonMutatingFunc()
m.computedTester2[0].mutatingFunc()
}
// MARK: get and _modify
public struct LoadableSubscriptGetModifyTester : ~Copyable {
subscript(_ i: Int) -> AddressOnlyMoveOnlyContainingProtocol {
get {
fatalError()
}
_modify {
fatalError()
}
}
}
public func testSubscriptGetModify_BaseLoadable_ResultAddressOnly_Var() {
var m = LoadableSubscriptGetModifyTester()
m = LoadableSubscriptGetModifyTester()
m[0].nonMutatingFunc()
m[0] = AddressOnlyMoveOnlyContainingProtocol()
m[0].mutatingFunc()
}
public func testSubscriptGetModify_BaseLoadable_ResultAddressOnly_Let() {
let m = LoadableSubscriptGetModifyTester()
m[0].nonMutatingFunc()
}
public func testSubscriptGetModify_BaseLoadable_ResultAddressOnly_InOut(m: inout LoadableSubscriptGetModifyTester) {
m[0].nonMutatingFunc()
m[0] = AddressOnlyMoveOnlyContainingProtocol()
m[0].mutatingFunc()
}
var globalLoadableSubscriptGetModifyTester = LoadableSubscriptGetModifyTester()
public func testSubscriptGetModify_BaseLoadable_ResultAddressOnly_Global() {
globalLoadableSubscriptGetModifyTester[0].nonMutatingFunc()
globalLoadableSubscriptGetModifyTester[0] = AddressOnlyMoveOnlyContainingProtocol()
globalLoadableSubscriptGetModifyTester[0].mutatingFunc()
}
// Make sure that we get the same behavior when we access through another noncopyable struct.
public struct LoadableSubscriptGetModifyTesterNonCopyableStructParent : ~Copyable {
var tester = LoadableSubscriptGetModifyTester()
var computedTester: LoadableSubscriptGetModifyTester { fatalError() }
}
public func testSubscriptGetModifyThroughNonCopyableParentStruct_BaseLoadable_ResultAddressOnly_Var() {
var m = LoadableSubscriptGetModifyTesterNonCopyableStructParent()
m = LoadableSubscriptGetModifyTesterNonCopyableStructParent()
m.tester[0].nonMutatingFunc()
m.tester[0].mutatingFunc()
m.computedTester[0].nonMutatingFunc()
}
public func testSubscriptGetModifyThroughNonCopyableParentStruct_BaseLoadable_ResultAddressOnly_Let() {
let m = LoadableSubscriptGetModifyTesterNonCopyableStructParent()
m.tester[0].nonMutatingFunc()
}
var globalLoadableSubscriptGetModifyTesterNonCopyableStructParent = LoadableSubscriptGetModifyTesterNonCopyableStructParent()
public func testSubscriptGetModifyThroughNonCopyableParentStruct_BaseLoadable_ResultAddressOnly_Global() {
globalLoadableSubscriptGetModifyTesterNonCopyableStructParent.tester[0].nonMutatingFunc()
globalLoadableSubscriptGetModifyTesterNonCopyableStructParent.tester[0].mutatingFunc()
}
public class LoadableSubscriptGetModifyTesterClassParent {
var tester = LoadableSubscriptGetModifyTester()
var computedTester: LoadableSubscriptGetModifyTester { fatalError() }
var computedTester2: LoadableSubscriptGetModifyTester {
get { fatalError() }
set { fatalError() }
}
var testerParent = LoadableSubscriptGetModifyTesterNonCopyableStructParent()
}
public func testSubscriptGetModifyThroughParentClass_BaseLoadable_ResultAddressOnly_Var() {
var m = LoadableSubscriptGetModifyTesterClassParent()
m = LoadableSubscriptGetModifyTesterClassParent()
m.tester[0].nonMutatingFunc()
m.tester[0].mutatingFunc()
m.testerParent.tester[0].nonMutatingFunc()
m.testerParent.tester[0].mutatingFunc()
m.computedTester[0].nonMutatingFunc()
m.computedTester2[0].nonMutatingFunc()
m.computedTester2[0].mutatingFunc()
}
|