Skip to content

Commit 0c23e66

Browse files
committed
[stdilb] introduce Copyable protocol
This replaces the old, unavailable `_Copyable`.
1 parent f1142d5 commit 0c23e66

File tree

12 files changed

+39
-40
lines changed

12 files changed

+39
-40
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/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)

test/Sema/copyable.swift

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

3-
protocol P: _Copyable {} // expected-error {{'_Copyable' is unavailable}}
3+
protocol P: Copyable {}
44
struct S: P {}
55

6-
typealias PleaseLetMeDoIt = _Copyable // expected-error {{'_Copyable' is unavailable}}
7-
typealias WhatIfIQualify = Swift._Copyable // expected-error {{'_Copyable' is unavailable}}
6+
typealias PleaseLetMeDoIt = Copyable
7+
typealias WhatIfIQualify = Swift.Copyable
88

9-
class C: _Copyable {} // expected-error {{'_Copyable' is unavailable}}
9+
class C: Copyable {}
1010

11-
@_moveOnly struct MOStruct: _Copyable {}
12-
// expected-error@-1 {{noncopyable struct 'MOStruct' cannot conform to '_Copyable'}}
13-
// expected-error@-2 {{'_Copyable' is unavailable}}
11+
@_moveOnly struct MOStruct: Copyable {} // expected-error {{noncopyable struct 'MOStruct' cannot conform to 'Copyable'}}
1412

1513

16-
func whatever<T>(_ t: T) where T: _Copyable {} // expected-error {{'_Copyable' is unavailable}}
17-
func vatever<T: _Copyable>(_ t: T) {} // expected-error {{'_Copyable' is unavailable}}
18-
func buttever(_ t: any _Copyable) {} // expected-error {{'_Copyable' is unavailable}}
19-
func zuttever(_ t: some _Copyable) {} // expected-error 2{{'_Copyable' is unavailable}}
14+
func whatever<T>(_ t: T) where T: Copyable {}
15+
func vatever<T: Copyable>(_ t: T) {}
16+
func buttever(_ t: any Copyable) {}
17+
func zuttever(_ t: some Copyable) {}
2018

21-
enum RockNRoll<T: _Copyable> { // expected-error {{'_Copyable' is unavailable}}
22-
case isNoisePollution(_Copyable) // expected-error {{'_Copyable' is unavailable}}
19+
enum RockNRoll<T: Copyable> {
20+
case isNoisePollution(Copyable)
2321
case isMusic(T)
2422
}
2523

2624
enum namespace {
27-
typealias _Copyable = Int
25+
typealias Copyable = Int
2826

29-
func _Copyable() -> _Copyable { return 0 }
27+
func Copyable() -> Copyable { return 0 }
3028
}

test/Sema/copyable_constraint.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// FIXME: Now demonstrate that plain -parse-stdlib, such as in some arbitrary test, doesn't get the Copyable constraint :(
66
// RUN: not %target-swift-frontend -typecheck -verify -parse-stdlib %s
77

8-
@_marker public protocol _Copyable {}
8+
@_marker public protocol Copyable {}
99

1010
func nextTime<T>(_ t: T) {} // expected-note {{generic parameter 'T' has an implicit Copyable requirement}}
1111

test/Sema/moveonly_sendable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ protocol GiveSendable<T> {
131131

132132
// make sure witnessing associatedtypes is still prevented, even though we meet the explicit constraint.
133133
class Bad: GiveSendable { // expected-error {{type 'Bad' does not conform to protocol 'GiveSendable'}}
134-
typealias T = FileDescriptor // expected-note {{possibly intended match 'Bad.T' (aka 'FileDescriptor') does not conform to '_Copyable'}}
134+
typealias T = FileDescriptor // expected-note {{possibly intended match 'Bad.T' (aka 'FileDescriptor') does not conform to 'Copyable'}}
135135
func give() -> FileDescriptor { return FileDescriptor(id: -1) }
136136
}
137137

0 commit comments

Comments
 (0)