Skip to content

Commit bfe2edc

Browse files
committed
rename _Copyable to Copyable and make it available
1 parent 8451e7f commit bfe2edc

14 files changed

+48
-37
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,8 @@ ERROR(unexpected_class_constraint,none,
18241824
"'class' constraint can only appear on protocol declarations", ())
18251825
NOTE(suggest_anyobject,none,
18261826
"did you mean to write an 'AnyObject' constraint?", ())
1827+
ERROR(suppress_illegal_here,none,
1828+
"cannot suppress conformances here", ())
18271829
ERROR(expected_generics_type_restriction,none,
18281830
"expected a class type or protocol-constrained type restricting %0",
18291831
(Identifier))

include/swift/AST/KnownProtocols.def

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

123123
PROTOCOL(FloatingPoint)
124124

125-
PROTOCOL_(Copyable)
125+
PROTOCOL(Copyable)
126126

127127
EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByArrayLiteral, "Array", false)
128128
EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByBooleanLiteral, "BooleanLiteralType", true)

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4623,7 +4623,7 @@ swift::checkTypeWitness(Type type, AssociatedTypeDecl *assocType,
46234623
if (type->isPureMoveOnly()) {
46244624
// describe the failure reason as it not conforming to Copyable
46254625
auto *copyable = ctx.getProtocol(KnownProtocolKind::Copyable);
4626-
assert(copyable && "missing _Copyable protocol!");
4626+
assert(copyable && "missing Copyable protocol!");
46274627
return CheckTypeWitnessResult(copyable->getDeclaredInterfaceType());
46284628
}
46294629

stdlib/public/core/CompilerProtocols.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,3 +972,19 @@ public protocol _ExpressibleByFileReferenceLiteral {
972972
/// then Array would no longer be a _DestructorSafeContainer.
973973
public protocol _DestructorSafeContainer {
974974
}
975+
976+
/// This marker protocol describes the category of types that support implicit
977+
/// copying. By default, all types in Swift implicitly support copying and thus
978+
/// conformance to `Copyable` is implicitly synthesized. To suppress the
979+
/// implicit conformance synthesis, write `~Copyable` on the type declaration:
980+
///
981+
/// struct FileDescriptor: ~Copyable { /* ... */ }
982+
///
983+
/// The reading of this type declaration is "FileDescriptor suppresses implicit
984+
/// Copyable conformance".
985+
@_marker public protocol Copyable {}
986+
987+
/// For older compilers interacting with newer stdlibs, define the unavailable
988+
/// `_Copyable` marker protocol that they expect to find.
989+
@available(*, unavailable)
990+
typealias _Copyable = Copyable

stdlib/public/core/Misc.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,3 @@ public func _getTypeByMangledNameInContext(
154154
public func _unsafePerformance<T>(_ c: () -> T) -> T {
155155
return c()
156156
}
157-
158-
/// This marker protocol represents types that support copying.
159-
/// This type is not yet available for use to express explicit
160-
/// constraints on generics in your programs. It is currently
161-
/// only used internally by the compiler.
162-
@available(*, unavailable)
163-
@_marker public protocol _Copyable {}

test/Concurrency/async_overload_filtering.swift

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

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

test/Constraints/moveonly_constraints.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ func testBasic(_ mo: borrowing MO) {
8888
genericVarArg(5)
8989
genericVarArg(mo) // expected-error {{move-only type 'MO' cannot be used with generics yet}}
9090

91-
takeGeneric( (mo, 5) ) // expected-error {{global function 'takeGeneric' requires that 'MO' conform to '_Copyable'}}
92-
takeGenericSendable((mo, mo)) // expected-error 2{{global function 'takeGenericSendable' requires that 'MO' conform to '_Copyable'}}
91+
takeGeneric( (mo, 5) ) // expected-error {{global function 'takeGeneric' requires that 'MO' conform to 'Copyable'}}
92+
takeGenericSendable((mo, mo)) // expected-error 2{{global function 'takeGenericSendable' requires that 'MO' conform to 'Copyable'}}
9393

9494
let singleton : (MO) = (mo)
9595
takeGeneric(singleton) // expected-error {{move-only type 'MO' cannot be used with generics yet}}
@@ -150,7 +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}}
153+
let _: Copyable = mo // expected-error {{'Copyable' is unavailable}}
154154
// expected-error@-1 {{move-only type 'MO' cannot be used with generics yet}}
155155
let _: AnyObject = MO() // expected-error {{move-only type 'MO' cannot be used with generics yet}}
156156
let _: Any = mo // expected-error {{move-only type 'MO' cannot be used with generics yet}}
@@ -251,18 +251,18 @@ protocol HasType<Ty> {
251251
}
252252

253253
class SomeGuy: HasType { // expected-error {{type 'SomeGuy' does not conform to protocol 'HasType'}}
254-
typealias Ty = MO // expected-note {{possibly intended match 'SomeGuy.Ty' (aka 'MO') does not conform to '_Copyable'}}
254+
typealias Ty = MO // expected-note {{possibly intended match 'SomeGuy.Ty' (aka 'MO') does not conform to 'Copyable'}}
255255
}
256256

257257
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'}}
258+
@_moveOnly struct Ty {} // expected-note {{possibly intended match 'AnotherGuy.Ty' does not conform to 'Copyable'}}
259259
}
260260

261261
protocol Gives: HasType {
262262
func give() -> Ty
263263
}
264264

265265
struct GenerousGuy: Gives { // expected-error {{type 'GenerousGuy' does not conform to protocol 'HasType'}}
266-
typealias Ty = MO // expected-note {{possibly intended match 'GenerousGuy.Ty' (aka 'MO') does not conform to '_Copyable'}}
266+
typealias Ty = MO // expected-note {{possibly intended match 'GenerousGuy.Ty' (aka 'MO') does not conform to 'Copyable'}}
267267
func give() -> Ty {}
268268
}

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: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
// RUN: %target-typecheck-verify-swift
22

3-
protocol P: _Copyable {} // expected-error {{'_Copyable' is unavailable}}
3+
protocol P: Copyable {} // expected-error {{'Copyable' is unavailable}}
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 // expected-error {{'Copyable' is unavailable}}
7+
typealias WhatIfIQualify = Swift.Copyable // expected-error {{'Copyable' is unavailable}}
88

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

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

1515

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}}
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}}
2020

21-
enum RockNRoll<T: _Copyable> { // expected-error {{'_Copyable' is unavailable}}
22-
case isNoisePollution(_Copyable) // expected-error {{'_Copyable' is unavailable}}
21+
enum RockNRoll<T: Copyable> { // expected-error {{'Copyable' is unavailable}}
22+
case isNoisePollution(Copyable) // expected-error {{'Copyable' is unavailable}}
2323
case isMusic(T)
2424
}
2525

2626
enum namespace {
27-
typealias _Copyable = Int
27+
typealias Copyable = Int
2828

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

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) {}
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)