Skip to content

Commit cc7a41f

Browse files
committed
[stdilb] introduce Copyable protocol
This replaces the old, unavailable `_Copyable`. rdar://110420673
1 parent f1142d5 commit cc7a41f

13 files changed

+43
-52
lines changed

include/swift/AST/KnownProtocols.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ PROTOCOL(AsyncIteratorProtocol)
126126

127127
PROTOCOL(FloatingPoint)
128128

129-
PROTOCOL_(Copyable)
129+
PROTOCOL(Copyable)
130130

131131
EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByArrayLiteral, "Array", false)
132132
EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByBooleanLiteral, "BooleanLiteralType", true)

stdlib/public/core/Misc.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,7 @@ public func _unsafePerformance<T>(_ c: () -> T) -> T {
164164
/// constraints on generics in your programs. It is currently
165165
/// only used internally by the compiler.
166166
@available(*, unavailable)
167-
@_marker public protocol _Copyable {}
167+
@_marker public protocol _Copyable {} // FIXME: rdar://115793371 (delete _Copyable from stdlib)
168+
169+
170+
@_marker public protocol Copyable {}

test/Concurrency/async_overload_filtering.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func filter_async(_: String) -> Void {}
1818
var a: String? = nil
1919

2020
// CHECK: attempting disjunction choice $T0 bound to decl async_overload_filtering.(file).filter_async(fn2:)
21-
// CHECK-NEXT: added constraint: {{.*}} conforms to _Copyable
21+
// CHECK-NEXT: added constraint: {{.*}} conforms to Copyable
2222
// CHECK-NEXT: overload set choice binding $T0 := {{.*}}
2323
// CHECK-NEXT: (considering: ({{.*}}) -> {{.*}} applicable fn {{.*}}
2424
// CHECK: increasing 'sync-in-asynchronous' score by 1

test/Constraints/copyable_requirement.swift

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func checkBasicBoxes() {
108108
_ = rb.get()
109109
_ = rb.val
110110

111-
let vb2: ValBox<MO> = .init(MO()) // expected-error {{type 'MO' does not conform to protocol '_Copyable'}}
111+
let vb2: ValBox<MO> = .init(MO()) // expected-error {{type 'MO' does not conform to protocol 'Copyable'}}
112112
}
113113

114114
func checkExistential() {
@@ -126,15 +126,15 @@ func checkExistential() {
126126
}
127127

128128
func checkMethodCalls() {
129-
let tg: NotStoredGenerically<MO> = NotStoredGenerically() // expected-error {{type 'MO' does not conform to protocol '_Copyable'}}
129+
let tg: NotStoredGenerically<MO> = NotStoredGenerically() // expected-error {{type 'MO' does not conform to protocol 'Copyable'}}
130130
tg.take(MO())
131131
tg.give()
132132

133133
let _ = Maybe.just(MO()) // expected-error {{noncopyable type 'MO' cannot be substituted for copyable generic parameter 'T' in 'Maybe'}}
134134

135-
let _: Maybe<MO> = .none // expected-error {{type 'MO' does not conform to protocol '_Copyable'}}
136-
let _ = Maybe<MO>.just(MO()) // expected-error {{type 'MO' does not conform to protocol '_Copyable'}}
137-
let _: Maybe<MO> = .just(MO()) // expected-error {{type 'MO' does not conform to protocol '_Copyable'}}
135+
let _: Maybe<MO> = .none // expected-error {{type 'MO' does not conform to protocol 'Copyable'}}
136+
let _ = Maybe<MO>.just(MO()) // expected-error {{type 'MO' does not conform to protocol 'Copyable'}}
137+
let _: Maybe<MO> = .just(MO()) // expected-error {{type 'MO' does not conform to protocol 'Copyable'}}
138138

139139
takeMaybe(.just(MO())) // expected-error {{noncopyable type 'MO' cannot be substituted for copyable generic parameter 'T' in 'takeMaybe'}}
140140
takeMaybe(true ? .none : .just(MO()))
@@ -144,7 +144,7 @@ func checkMethodCalls() {
144144
func checkCasting(_ b: any Box, _ mo: borrowing MO, _ a: Any) {
145145
// casting dynamically is allowed, but should always fail since you can't
146146
// construct such a type.
147-
let box = b as! ValBox<MO> // expected-error {{type 'MO' does not conform to protocol '_Copyable'}}
147+
let box = b as! ValBox<MO> // expected-error {{type 'MO' does not conform to protocol 'Copyable'}}
148148
let dup = box
149149

150150
let _: MO = dup.get()
@@ -157,8 +157,7 @@ func checkCasting(_ b: any Box, _ mo: borrowing MO, _ a: Any) {
157157

158158
let _: Sendable = (MO(), MO()) // expected-error {{noncopyable type '(MO, MO)' cannot be erased to copyable existential type 'any Sendable'}}
159159
let _: Sendable = MO() // expected-error {{noncopyable type 'MO' cannot be erased to copyable existential type 'any Sendable'}}
160-
let _: _Copyable = mo // expected-error {{'_Copyable' is unavailable}}
161-
// expected-error@-1 {{noncopyable type 'MO' cannot be erased to copyable existential type 'any _Copyable'}}
160+
let _: Copyable = mo // expected-error {{noncopyable type 'MO' cannot be erased to copyable existential type 'any Copyable'}}
162161
let _: AnyObject = MO() // expected-error {{noncopyable type 'MO' cannot be erased to copyable existential type 'AnyObject'}}
163162
let _: Any = mo // expected-error {{noncopyable type 'MO' cannot be erased to copyable existential type 'Any'}}
164163

@@ -262,19 +261,19 @@ protocol HasType<Ty> {
262261
}
263262

264263
class SomeGuy: HasType { // expected-error {{type 'SomeGuy' does not conform to protocol 'HasType'}}
265-
typealias Ty = MO // expected-note {{possibly intended match 'SomeGuy.Ty' (aka 'MO') does not conform to '_Copyable'}}
264+
typealias Ty = MO // expected-note {{possibly intended match 'SomeGuy.Ty' (aka 'MO') does not conform to 'Copyable'}}
266265
}
267266

268267
struct AnotherGuy: HasType { // expected-error {{type 'AnotherGuy' does not conform to protocol 'HasType'}}
269-
@_moveOnly struct Ty {} // expected-note {{possibly intended match 'AnotherGuy.Ty' does not conform to '_Copyable'}}
268+
@_moveOnly struct Ty {} // expected-note {{possibly intended match 'AnotherGuy.Ty' does not conform to 'Copyable'}}
270269
}
271270

272271
protocol Gives: HasType {
273272
func give() -> Ty
274273
}
275274

276275
struct GenerousGuy: Gives { // expected-error {{type 'GenerousGuy' does not conform to protocol 'HasType'}}
277-
typealias Ty = MO // expected-note {{possibly intended match 'GenerousGuy.Ty' (aka 'MO') does not conform to '_Copyable'}}
276+
typealias Ty = MO // expected-note {{possibly intended match 'GenerousGuy.Ty' (aka 'MO') does not conform to 'Copyable'}}
278277
func give() -> Ty {}
279278
}
280279

test/Constraints/moveonly_constraints.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ func checkCasting(_ b: any Box, _ mo: borrowing MO, _ a: Any) {
160160

161161
let _: Sendable = (MO(), MO()) // expected-error {{noncopyable type '(MO, MO)' cannot be erased to copyable existential type 'any Sendable'}}
162162
let _: Sendable = MO() // expected-error {{noncopyable type 'MO' cannot be erased to copyable existential type 'any Sendable'}}
163-
let _: _Copyable = mo // expected-error {{'_Copyable' is unavailable}}
164-
// expected-error@-1 {{noncopyable type 'MO' cannot be erased to copyable existential type 'any _Copyable'}}
163+
let _: Copyable = mo // expected-error {{noncopyable type 'MO' cannot be erased to copyable existential type 'any Copyable'}}
165164
let _: AnyObject = MO() // expected-error {{noncopyable type 'MO' cannot be erased to copyable existential type 'AnyObject'}}
166165
let _: Any = mo // expected-error {{noncopyable type 'MO' cannot be erased to copyable existential type 'Any'}}
167166

@@ -260,19 +259,19 @@ protocol HasType<Ty> {
260259
}
261260

262261
class SomeGuy: HasType { // expected-error {{type 'SomeGuy' does not conform to protocol 'HasType'}}
263-
typealias Ty = MO // expected-note {{possibly intended match 'SomeGuy.Ty' (aka 'MO') does not conform to '_Copyable'}}
262+
typealias Ty = MO // expected-note {{possibly intended match 'SomeGuy.Ty' (aka 'MO') does not conform to 'Copyable'}}
264263
}
265264

266265
struct AnotherGuy: HasType { // expected-error {{type 'AnotherGuy' does not conform to protocol 'HasType'}}
267-
@_moveOnly struct Ty {} // expected-note {{possibly intended match 'AnotherGuy.Ty' does not conform to '_Copyable'}}
266+
@_moveOnly struct Ty {} // expected-note {{possibly intended match 'AnotherGuy.Ty' does not conform to 'Copyable'}}
268267
}
269268

270269
protocol Gives: HasType {
271270
func give() -> Ty
272271
}
273272

274273
struct GenerousGuy: Gives { // expected-error {{type 'GenerousGuy' does not conform to protocol 'HasType'}}
275-
typealias Ty = MO // expected-note {{possibly intended match 'GenerousGuy.Ty' (aka 'MO') does not conform to '_Copyable'}}
274+
typealias Ty = MO // expected-note {{possibly intended match 'GenerousGuy.Ty' (aka 'MO') does not conform to 'Copyable'}}
276275
func give() -> Ty {}
277276
}
278277

test/ModuleInterface/copyable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22

3-
// This test checks that conformances to _Copyable do not appear in swiftinterface files
3+
// This test checks that conformances to Copyable do not appear in swiftinterface files
44

55
// Generate the parseable interface of the current file via the merge-modules step
66
// RUN: %target-build-swift -emit-module -o %t/Test.swiftmodule -emit-module-interface-path %t/TestMerge.swiftinterface -module-name Test %s -enable-library-evolution -swift-version 5

test/Parse/without_copyable.swift renamed to test/Parse/inverses_legacy.swift

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,18 @@ struct U: // expected-error {{noncopyable struct 'U' cannot conform to 'Sando'}}
2121

2222
class C: // expected-error {{type 'C' does not conform to protocol 'Sando'}}
2323
~Copyable, // expected-error {{cannot suppress conformances here}}
24-
// expected-error@-1 {{cannot find type 'Copyable' in scope}}
2524
~Sando // expected-error {{cannot suppress conformances here}}
2625
{}
2726

2827
protocol Rope<Element>: ~Copyable { // expected-error {{cannot suppress conformances here}}
29-
// expected-error@-1 {{cannot find type 'Copyable' in scope}}
3028

3129
associatedtype Element: ~Copyable // expected-error {{cannot suppress conformances here}}
32-
// expected-error@-1 {{cannot find type 'Copyable' in scope}}
3330
}
3431

3532
extension S: ~Copyable {} // expected-error {{cannot suppress conformances here}}
36-
// expected-error@-1 {{cannot find type 'Copyable' in scope}}
33+
// expected-error@-1 {{noncopyable struct 'S' cannot conform to 'Copyable'}}
3734

3835
func takeNoncopyableGeneric<T: ~Copyable>(_ t: T) {} // expected-error {{cannot suppress conformances here}}
39-
// expected-error@-1 {{cannot find type 'Copyable' in scope}}
4036

4137
@_moveOnly struct ExtraNonCopyable: // expected-error {{duplicate attribute}}{{1-12=}}
4238
~Copyable // expected-note {{attribute already specified here}}
@@ -48,6 +44,7 @@ struct HasADeinit: ~Copyable { deinit {} }
4844

4945
public struct MoveOnlyS1<T> : ~Copyable { deinit {} }
5046
public struct MoveOnlyS2<T: Equatable> : ~Copyable { deinit {} }
47+
public struct MoveOnlyS3<T: ~Copyable> : ~Copyable { deinit {} } // expected-error {{cannot suppress conformances here}}
5148

5249
public enum MoveOnlyE1<T> : ~Copyable {
5350
case holding(s: MoveOnlyS1<T>)
@@ -60,22 +57,17 @@ public enum MoveOnlyE2<T: Equatable> : ~Copyable {
6057
}
6158

6259
func more() {
63-
let foo: any ~Copyable = 19 // expected-error@:16 {{cannot suppress conformances here}}
64-
// expected-error@-1 {{cannot find type 'Copyable' in scope}}
60+
let _: any ~Copyable = 19 // expected-error@:14 {{cannot suppress conformances here}}
6561

66-
let foo: any ~Equatable = 19 // expected-error@:16 {{cannot suppress conformances here}}
62+
let _: any ~Equatable = 19 // expected-error@:14 {{cannot suppress conformances here}}
6763
}
6864

6965
func blah<T>(_ t: T) where T: ~Copyable, // expected-error@:31 {{cannot suppress conformances here}}
70-
// expected-error@-1 {{cannot find type 'Copyable' in scope}}
7166

7267
T: ~Hashable {} // expected-error@:31 {{cannot suppress conformances here}}
7368

7469
func foo<T: ~Copyable>(x: T) {} // expected-error {{cannot suppress conformances here}}
75-
// expected-error@-1 {{cannot find type 'Copyable' in scope}}
7670

7771
struct Buurap<T: ~Copyable> {} // expected-error {{cannot suppress conformances here}}
78-
// expected-error@-1 {{cannot find type 'Copyable' in scope}}
7972

8073
protocol Foo where Self: ~Copyable {} // expected-error {{cannot suppress conformances here}}
81-
// expected-error@-1 {{cannot find type 'Copyable' in scope}}

test/SILGen/unmanaged_ownership.swift

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

22
// RUN: %target-swift-emit-silgen -parse-stdlib -module-name Swift %s | %FileCheck %s
33

4-
@_marker protocol _Copyable {}
4+
@_marker protocol Copyable {}
55

66
class C {}
77

test/SILOptimizer/nonescaping_partial_apply_gauntlet.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// RUN: %target-swift-frontend -emit-sil -parse-stdlib -module-name Swift %s
66
// RUN: %target-swift-frontend -emit-sil -O -parse-stdlib -module-name Swift %s
77

8-
@_marker protocol _Copyable {}
8+
@_marker protocol Copyable {}
99
precedencegroup CastingPrecedence {}
1010
precedencegroup AssignmentPrecedence {}
1111

test/SILOptimizer/opaque_values_Onone_stdlib.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ precedencegroup AssignmentPrecedence { assignment: true }
1010
precedencegroup CastingPrecedence {}
1111

1212
public protocol _ObjectiveCBridgeable {}
13-
@_marker public protocol _Copyable {}
13+
@_marker public protocol Copyable {}
1414

1515
public protocol _ExpressibleByBuiltinBooleanLiteral {
1616
init(_builtinBooleanLiteral value: Builtin.Int1)

0 commit comments

Comments
 (0)