Skip to content

Commit d19e323

Browse files
committed
[tests] use ~Copyable instead of @_moveOnly
many of these are mechanical changes
1 parent ad369e0 commit d19e323

File tree

56 files changed

+223
-353
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+223
-353
lines changed

test/Constraints/moveonly_constraints.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// RUN: %target-typecheck-verify-swift
22

33
// a concrete move-only type
4-
@_moveOnly struct MO {
4+
struct MO : ~Copyable {
55
var x: Int?
66
}
77

8-
@_moveOnly struct Container {
8+
struct Container : ~Copyable {
99
var mo: MO = MO()
1010
}
1111

@@ -150,8 +150,7 @@ func checkCasting(_ b: any Box, _ mo: borrowing MO, _ a: Any) {
150150

151151
let _: Sendable = (MO(), MO()) // expected-error {{move-only type '(MO, MO)' cannot be used with generics yet}}
152152
let _: Sendable = MO() // expected-error {{move-only type 'MO' cannot be used with generics yet}}
153-
let _: Copyable = mo // expected-error {{'Copyable' is unavailable}}
154-
// expected-error@-1 {{move-only type 'MO' cannot be used with generics yet}}
153+
let _: Copyable = mo // expected-error {{move-only type 'MO' cannot be used with generics yet}}
155154
let _: AnyObject = MO() // expected-error {{move-only type 'MO' cannot be used with generics yet}}
156155
let _: Any = mo // expected-error {{move-only type 'MO' cannot be used with generics yet}}
157156

@@ -255,7 +254,7 @@ class SomeGuy: HasType { // expected-error {{type 'SomeGuy' does not conform to
255254
}
256255

257256
struct AnotherGuy: HasType { // expected-error {{type 'AnotherGuy' does not conform to protocol 'HasType'}}
258-
@_moveOnly struct Ty {} // expected-note {{possibly intended match 'AnotherGuy.Ty' does not conform to 'Copyable'}}
257+
struct Ty : ~Copyable {} // expected-note {{possibly intended match 'AnotherGuy.Ty' does not conform to 'Copyable'}}
259258
}
260259

261260
protocol Gives: HasType {

test/Constraints/moveonly_tuples.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
// Tuples with noncopyable elements are not yet supported. Make sure we reject
44
// them when code attempts to form such a type explicitly or by inference.
55

6-
@_moveOnly struct Butt {
6+
struct Butt: ~Copyable {
77
var x: Int
88
}
99

10-
@_moveOnly
11-
struct Foo {
10+
struct Foo: ~Copyable {
1211
var t: (Int, Butt) // expected-error{{tuples with noncopyable elements are not supported}}
1312
}
14-
@_moveOnly
15-
struct Bar<T> {
13+
14+
struct Bar<T>: ~Copyable {
1615
var t: (T, Butt) // expected-error{{tuples with noncopyable elements are not supported}}
1716
var u: (Int, (T, Butt)) // expected-error{{tuples with noncopyable elements are not supported}}
1817
}

test/IRGen/moveonly_deinits.swift

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ class Klass {}
2222
// Struct Declarations //
2323
/////////////////////////
2424

25-
@_moveOnly
26-
struct KlassPairWithoutDeinit {
25+
struct KlassPairWithoutDeinit : ~Copyable {
2726
var lhs = Klass()
2827
var rhs = Klass()
2928
}
3029

31-
@_moveOnly
32-
struct KlassPairWithDeinit {
30+
struct KlassPairWithDeinit : ~Copyable {
3331
var lhs = Klass()
3432
var rhs = Klass()
3533

@@ -38,14 +36,12 @@ struct KlassPairWithDeinit {
3836
}
3937
}
4038

41-
@_moveOnly
42-
struct IntPairWithoutDeinit {
39+
struct IntPairWithoutDeinit : ~Copyable {
4340
var k: Int = 5
4441
var k2: Int = 6
4542
}
4643

47-
@_moveOnly
48-
struct IntPairWithDeinit {
44+
struct IntPairWithDeinit : ~Copyable {
4945
var k: Int = 5
5046
var k2: Int = 6
5147

@@ -195,14 +191,12 @@ public func testKlassPairWithDeinit() {
195191
// Enum Declarations //
196192
///////////////////////
197193

198-
@_moveOnly
199-
enum KlassEnumPairWithoutDeinit {
194+
enum KlassEnumPairWithoutDeinit : ~Copyable {
200195
case lhs(Klass)
201196
case rhs(Klass)
202197
}
203198

204-
@_moveOnly
205-
enum KlassEnumPairWithDeinit {
199+
enum KlassEnumPairWithDeinit : ~Copyable {
206200
case lhs(Klass)
207201
case rhs(Klass)
208202

@@ -211,14 +205,12 @@ enum KlassEnumPairWithDeinit {
211205
}
212206
}
213207

214-
@_moveOnly
215-
enum IntEnumPairWithoutDeinit {
208+
enum IntEnumPairWithoutDeinit : ~Copyable {
216209
case lhs(Int)
217210
case rhs(Int)
218211
}
219212

220-
@_moveOnly
221-
enum IntEnumPairWithDeinit {
213+
enum IntEnumPairWithDeinit : ~Copyable {
222214
case lhs(Int)
223215
case rhs(Int)
224216

test/Interpreter/moveonly.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ defer { runAllTests() }
88

99
var Tests = TestSuite("MoveOnlyTests")
1010

11-
@_moveOnly
12-
struct FD {
11+
struct FD : ~Copyable {
1312
var a = LifetimeTracked(0)
1413

1514
deinit {
@@ -48,8 +47,10 @@ Tests.test("global destroyed once") {
4847
expectEqual(0, LifetimeTracked.instances)
4948
}
5049

51-
@_moveOnly
52-
struct FD2 {
50+
// TODO (rdar://107494072): Move-only types with deinits declared inside
51+
// functions sometimes lose their deinit function.
52+
// When that's fixed, FD2 can be moved back inside the test closure below.
53+
struct FD2 : ~Copyable {
5354
var field = 5
5455
static var count = 0
5556
init() { FD2.count += 1 }
@@ -92,8 +93,7 @@ Tests.test("deinit not called in init when assigned") {
9293
}
9394

9495
Tests.test("empty struct") {
95-
@_moveOnly
96-
struct EmptyStruct {
96+
struct EmptyStruct: ~Copyable {
9797
func doSomething() {}
9898
var value: Bool { false }
9999
}

test/Interpreter/moveonly_bufferview.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
// Until we get support for emitting value witnesses for deinits, do not run
88
// this with optimizations.
99

10-
@_moveOnly
11-
public struct BufferView<T> {
10+
public struct BufferView<T> : ~Copyable {
1211
var ptr: UnsafeBufferPointer<T>
1312

1413
var count: Int {

test/Interpreter/moveonly_computed_property_in_class.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %target-run-simple-swift
22
// REQUIRES: executable_test
3-
@_moveOnly
4-
struct FileDescriptor {
3+
4+
struct FileDescriptor: ~Copyable {
55
let desc: Int
66

77
var empty: Bool { return desc == Int.min }

test/Interpreter/moveonly_consuming_param.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
// REQUIRES: executable_test
44

5-
@_moveOnly
6-
struct Butt {
5+
struct Butt : ~Copyable {
76
var value: Int
87
deinit { print("disposing \(value)") }
98

test/Interpreter/moveonly_escaping_capture.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ class C {
1010
deinit { print("C died \(value)") }
1111
}
1212

13-
@_moveOnly
14-
struct Butt {
13+
struct Butt : ~Copyable {
1514
static var myButt: () -> () = {}
1615

1716
init(value: Int) { self._value = C(value: value) }

test/Interpreter/moveonly_escaping_capture_lifetimes.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
// REQUIRES: executable_test
44

5-
@_moveOnly
6-
struct MO {
5+
struct MO : ~Copyable {
76
var x: Int
87
deinit { print("dying \(x)") }
98
}

test/Interpreter/moveonly_escaping_definite_initialization.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
// REQUIRES: executable_test
44

5-
@_moveOnly
6-
struct MO {
5+
struct MO : ~Copyable {
76
var value: Int
87

98
func use() {}

test/Interpreter/moveonly_field_in_class_reflection.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
// a move-only field does not trap from trying to reflect and copy those
66
// move-only fields.
77

8-
@_moveOnly
9-
public struct MO {
8+
public struct MO : ~Copyable {
109
var x: Int8 = 0
1110
var y: Int8 = 0
1211
var z: Int8 = 0

test/Interpreter/moveonly_forget.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ func print_closing_MFD() { print("closing MaybeFileDescriptor") }
99

1010
enum E: Error { case err }
1111

12-
@_moveOnly
13-
struct FileDescriptor {
12+
struct FileDescriptor : ~Copyable {
1413
var fd: Int
1514
static var nextFD: Int = 0
1615

@@ -57,7 +56,7 @@ struct FileDescriptor {
5756
}
5857
}
5958

60-
@_moveOnly enum MaybeFileDescriptor {
59+
enum MaybeFileDescriptor : ~Copyable {
6160
case some(FileDescriptor)
6261
case nothing
6362

test/ModuleInterface/Inputs/moveonly_api.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ public enum Descriptor {
88
public func message() -> String { return "hello world" }
99
}
1010

11-
@_moveOnly
12-
public struct File {
11+
public struct File : ~Copyable {
1312

1413
#if SYNTHESIZE_ACCESSORS
1514
public var fd: Descriptor = .other(1337)

test/ModuleInterface/Inputs/moveonly_simple.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11

22
public class Message { var s: String = "hello" }
33

4-
@_moveOnly
5-
public struct FileDescriptor {
4+
public struct FileDescriptor : ~Copyable {
65
public var x: Int = 0
76
public var msg: Message = Message()
87
}

test/ModuleInterface/moveonly_interface_flag.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
// this test makes sure that decls containing a move-only type are guarded by the $MoveOnly feature flag
77

88
// CHECK: #if compiler(>=5.3) && $MoveOnly
9-
// CHECK-NEXT: @_moveOnly public struct MoveOnlyStruct {
9+
// CHECK-NEXT: public struct MoveOnlyStruct : ~Swift.Copyable {
10+
11+
// CHECK: #if compiler(>=5.3) && $MoveOnly
12+
// CHECK-NEXT: @_moveOnly public struct OldAttr_MoveOnlyStruct {
1013

1114
// CHECK: #if compiler(>=5.3) && $MoveOnly
12-
// CHECK-NEXT: @_moveOnly public enum MoveOnlyEnum {
15+
// CHECK-NEXT: public enum MoveOnlyEnum : ~Swift.Copyable {
1316

1417
// CHECK: #if compiler(>=5.3) && $MoveOnly
1518
// CHECK-NEXT: public func someFn() -> Library.MoveOnlyEnum
@@ -21,11 +24,15 @@
2124
// CHECK: #if compiler(>=5.3) && $MoveOnly
2225
// CHECK-NEXT: extension Library.MoveOnlyStruct {
2326

24-
@_moveOnly public struct MoveOnlyStruct {
27+
public struct MoveOnlyStruct : ~Copyable {
28+
let x = 0
29+
}
30+
31+
@_moveOnly public struct OldAttr_MoveOnlyStruct {
2532
let x = 0
2633
}
2734

28-
@_moveOnly public enum MoveOnlyEnum {
35+
public enum MoveOnlyEnum : ~Copyable {
2936
case depth
3037
}
3138

test/SILGen/forget.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
func invokedDeinit() {}
55

6-
@_moveOnly enum MaybeFile {
6+
enum MaybeFile : ~Copyable {
77
case some(File)
88
case none
99

@@ -29,7 +29,7 @@ func invokedDeinit() {}
2929
// CHECK: destroy_value [[FILE]] : $File
3030
}
3131

32-
@_moveOnly struct File {
32+
struct File : ~Copyable {
3333
let fd: Int
3434
static var nextFD: Int = 0
3535

@@ -59,7 +59,7 @@ func invokedDeinit() {}
5959
}
6060
}
6161

62-
@_moveOnly struct PointerTree {
62+
struct PointerTree : ~Copyable {
6363
let left: Ptr
6464
let file: File
6565
let popularity: Int
@@ -147,7 +147,7 @@ final class Wallet {
147147
var numCards = 0
148148
}
149149

150-
@_moveOnly enum Ticket {
150+
enum Ticket : ~Copyable {
151151
case empty
152152
case within(Wallet)
153153

test/SILGen/moveonly.swift

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,16 @@ public final class CopyableKlass {
88
var fd = FD()
99
}
1010

11-
@_moveOnly
12-
public struct FD {
11+
public struct FD : ~Copyable {
1312
var copyableKlass = CopyableKlass()
1413
}
1514

16-
@_moveOnly
17-
public struct NonTrivialStruct2 {
15+
public struct NonTrivialStruct2 : ~Copyable {
1816
var fd = FD()
1917
var copyableKlass = CopyableKlass()
2018
}
2119

22-
@_moveOnly
23-
public struct NonTrivialStruct {
20+
public struct NonTrivialStruct : ~Copyable {
2421
var fd = FD()
2522
var nonTrivialStruct2 = NonTrivialStruct2()
2623
var copyableKlass = CopyableKlass()
@@ -37,8 +34,7 @@ public struct NonTrivialCopyableStruct {
3734
var nonTrivialCopyableStruct2 = NonTrivialCopyableStruct2()
3835
}
3936

40-
@_moveOnly
41-
public enum NonTrivialEnum {
37+
public enum NonTrivialEnum : ~Copyable {
4238
case first
4339
case second(CopyableKlass)
4440
case third(NonTrivialStruct)
@@ -543,14 +539,12 @@ func assignCopyableKlass(_ x: CopyableKlass) {
543539
///////////////////////
544540

545541
enum EnumSwitchTests {
546-
@_moveOnly
547-
enum E2 {
542+
enum E2 : ~Copyable {
548543
case lhs(CopyableKlass)
549544
case rhs(FD)
550545
}
551546

552-
@_moveOnly
553-
enum E {
547+
enum E : ~Copyable {
554548
case first(NonTrivialStruct2)
555549
case second(NonTrivialStruct)
556550
case third(CopyableKlass)
@@ -786,8 +780,7 @@ func checkMarkMustCheckOnCaptured(x: __owned FD) {
786780
// Empty Struct //
787781
//////////////////
788782

789-
@_moveOnly
790-
struct EmptyStruct {
783+
struct EmptyStruct: ~Copyable {
791784
// Make sure we explicitly initialize empty struct as appropriate despite the
792785
// fact we do not have any fields.
793786
//

0 commit comments

Comments
 (0)