Skip to content

Commit af30ae3

Browse files
committed
Remove the last parts of the Boolean protocol, finishing up:
SE-0109: Remove the Boolean protocol. We still love you George, even if we forgot your e.
1 parent ce7751c commit af30ae3

24 files changed

+91
-180
lines changed

stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb

+13-7
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,6 @@ public func expectRandomAccessCollectionAssociatedTypes<X : RandomAccessCollecti
448448
X.Indices.Index == X.Index,
449449
X.Indices.SubSequence == X.Indices {}
450450

451-
public func expectIsBooleanType<X : Boolean>(_ x: inout X) -> X { return x }
452-
453451
public struct AssertionResult : CustomStringConvertible {
454452
init(isPass: Bool) {
455453
self._isPass = isPass
@@ -487,21 +485,29 @@ public func expectUnreachableCatch(_ error: Error, ${TRACE}) {
487485
"error should not be thrown: \"\(error)\"", trace: ${trace})
488486
}
489487

490-
%for BoolType in ['Bool', 'AssertionResult']:
491-
492-
public func expectTrue(_ actual: ${BoolType}, ${TRACE}) {
488+
public func expectTrue(_ actual: AssertionResult, ${TRACE}) {
493489
if !actual.boolValue {
494490
expectationFailure("expected: true", trace: ${trace})
495491
}
496492
}
497493

498-
public func expectFalse(_ actual: ${BoolType}, ${TRACE}) {
494+
public func expectFalse(_ actual: AssertionResult, ${TRACE}) {
499495
if actual.boolValue {
500496
expectationFailure("expected: false", trace: ${trace})
501497
}
502498
}
503499

504-
%end
500+
public func expectTrue(_ actual: Bool, ${TRACE}) {
501+
if !actual {
502+
expectationFailure("expected: true", trace: ${trace})
503+
}
504+
}
505+
506+
public func expectFalse(_ actual: Bool, ${TRACE}) {
507+
if actual {
508+
expectationFailure("expected: false", trace: ${trace})
509+
}
510+
}
505511

506512
public func expectEmpty<T>(_ value: T?, ${TRACE}) {
507513
if value != nil {

stdlib/public/SDK/CoreMedia/CMTimeRange.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ extension CMTimeRange {
5252
return CMTimeRangeGetIntersection(self, otherRange)
5353
}
5454
public func containsTime(_ time: CMTime) -> Bool {
55-
return CMTimeRangeContainsTime(self, time).boolValue
55+
return CMTimeRangeContainsTime(self, time)
5656
}
5757
public func containsTimeRange(_ range: CMTimeRange) -> Bool {
58-
return CMTimeRangeContainsTimeRange(self, range).boolValue
58+
return CMTimeRangeContainsTimeRange(self, range)
5959
}
6060
}
6161

@@ -76,10 +76,10 @@ extension CMTimeRange : Equatable {}
7676

7777
// CMTimeRangeEqual
7878
public func == (range1: CMTimeRange, range2: CMTimeRange) -> Bool {
79-
return CMTimeRangeEqual(range1, range2).boolValue
79+
return CMTimeRangeEqual(range1, range2)
8080
}
8181

8282
public func != (range1: CMTimeRange, range2: CMTimeRange) -> Bool {
83-
return !CMTimeRangeEqual(range1, range2).boolValue
83+
return !CMTimeRangeEqual(range1, range2)
8484
}
8585

stdlib/public/SDK/XCTest/XCTest.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,19 @@ public func XCTAssertNotNil(_ expression: @autoclosure () throws -> Any?, _ mess
171171
}
172172
}
173173

174-
public func XCTAssert(_ expression: @autoclosure () throws -> Boolean, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) -> Void {
174+
public func XCTAssert(_ expression: @autoclosure () throws -> Bool, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) -> Void {
175175
// XCTAssert is just a cover for XCTAssertTrue.
176176
XCTAssertTrue(expression, message, file: file, line: line)
177177
}
178178

179-
public func XCTAssertTrue(_ expression: @autoclosure () throws -> Boolean, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) -> Void {
179+
public func XCTAssertTrue(_ expression: @autoclosure () throws -> Bool, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) -> Void {
180180
let assertionType = _XCTAssertionType.`true`
181181

182182
// evaluate the expression exactly once
183183
var expressionValueOptional: Bool?
184184

185185
let result = _XCTRunThrowableBlock {
186-
expressionValueOptional = try expression().boolValue
186+
expressionValueOptional = try expression()
187187
}
188188

189189
switch result {
@@ -207,14 +207,14 @@ public func XCTAssertTrue(_ expression: @autoclosure () throws -> Boolean, _ mes
207207
}
208208
}
209209

210-
public func XCTAssertFalse(_ expression: @autoclosure () throws -> Boolean, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) -> Void {
210+
public func XCTAssertFalse(_ expression: @autoclosure () throws -> Bool, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) -> Void {
211211
let assertionType = _XCTAssertionType.`false`
212212

213213
// evaluate the expression exactly once
214214
var expressionValueOptional: Bool?
215215

216216
let result = _XCTRunThrowableBlock {
217-
expressionValueOptional = try expression().boolValue
217+
expressionValueOptional = try expression()
218218
}
219219

220220
switch result {

stdlib/public/core/Bool.swift

+7-13
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
/// A value type whose instances are either `true` or `false`.
1616
///
17-
/// `Bool` is the default type for Boolean values in Swift. Create instances of
17+
/// `Bool` represents Boolean values in Swift. Create instances of
1818
/// `Bool` by using one of the Boolean literals `true` and `false` or by
1919
/// assigning the result of a Boolean method or operation to a variable or
2020
/// constant.
@@ -69,6 +69,10 @@ public struct Bool {
6969
@_versioned
7070
@_transparent
7171
internal init(_ v: Builtin.Int1) { self._value = v }
72+
73+
public init(_ value: Bool) {
74+
self = value
75+
}
7276
}
7377

7478
extension Bool : _ExpressibleByBuiltinBooleanLiteral, ExpressibleByBooleanLiteral {
@@ -101,22 +105,12 @@ extension Bool : _ExpressibleByBuiltinBooleanLiteral, ExpressibleByBooleanLitera
101105
}
102106
}
103107

104-
extension Bool : Boolean {
108+
extension Bool {
109+
// This is a magic entry point known to the compiler.
105110
@_transparent
106111
public func _getBuiltinLogicValue() -> Builtin.Int1 {
107112
return _value
108113
}
109-
110-
/// This value expressed as a `Bool` instance; its value is identical to that
111-
/// of the current instance.
112-
@_transparent public var boolValue: Bool { return self }
113-
114-
/// Creates an instance representing the given logical value.
115-
///
116-
/// - Parameter value: The logical value for the new instance.
117-
public init<T : Boolean>(_ value: T) {
118-
self = value.boolValue
119-
}
120114
}
121115

122116
extension Bool : CustomStringConvertible {

stdlib/public/core/Builtin.swift

+6-7
Original file line numberDiff line numberDiff line change
@@ -264,23 +264,22 @@ public func _getUnsafePointerToStoredProperties(_ x: AnyObject)
264264
@_versioned
265265
@_transparent
266266
@_semantics("branchhint")
267-
internal func _branchHint<C : Boolean>(_ actual: C, expected: Bool)
268-
-> Bool {
269-
return Bool(Builtin.int_expect_Int1(actual.boolValue._value, expected._value))
267+
internal func _branchHint(_ actual: Bool, expected: Bool) -> Bool {
268+
return Bool(Builtin.int_expect_Int1(actual._value, expected._value))
270269
}
271270

272271
/// Optimizer hint that `x` is expected to be `true`.
273272
@_transparent
274273
@_semantics("fastpath")
275-
public func _fastPath<C: Boolean>(_ x: C) -> Bool {
276-
return _branchHint(x.boolValue, expected: true)
274+
public func _fastPath(_ x: Bool) -> Bool {
275+
return _branchHint(x, expected: true)
277276
}
278277

279278
/// Optimizer hint that `x` is expected to be `false`.
280279
@_transparent
281280
@_semantics("slowpath")
282-
public func _slowPath<C : Boolean>(_ x: C) -> Bool {
283-
return _branchHint(x.boolValue, expected: false)
281+
public func _slowPath(_ x: Bool) -> Bool {
282+
return _branchHint(x, expected: false)
284283
}
285284

286285
/// Optimizer hint that the code where this function is called is on the fast

stdlib/public/core/CompilerProtocols.swift

+2-42
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,6 @@
1212
// Intrinsic protocols shared with the compiler
1313
//===----------------------------------------------------------------------===//
1414

15-
/// A type that represents a Boolean value.
16-
///
17-
/// Types that conform to the `Boolean` protocol can be used as the condition
18-
/// in control statements, such as `if` and `while`, and in other contexts
19-
/// that require a logical value, such as the `where` clause of a `case`
20-
/// statement.
21-
///
22-
/// Swift uses only simple Boolean values in conditional contexts to help avoid
23-
/// accidental programming errors and to help maintain the clarity of each
24-
/// control statement. Unlike other programming languages, integers or strings
25-
/// cannot be used where a Boolean value is expected.
26-
///
27-
/// For example, the following code sample will not compile, because it
28-
/// attempts to use the integer `i` in a logical context:
29-
///
30-
/// var i = 5
31-
/// while i {
32-
/// print(i)
33-
/// i -= 1
34-
/// }
35-
///
36-
/// The correct approach in Swift is to compare the `i` value with zero in the
37-
/// `while` statement.
38-
///
39-
/// while i != 0 {
40-
/// print(i)
41-
/// i -= 1
42-
/// }
43-
///
44-
/// Conforming to the Boolean Protocol
45-
/// ==================================
46-
///
47-
/// To add `Boolean` conformance to your custom type, implement a `boolValue`
48-
/// property that represents your type as an instance of `Bool`, the default
49-
/// concrete type for the `Boolean` protocol.
50-
public protocol Boolean {
51-
/// This value expressed as a `Bool` instance.
52-
var boolValue: Bool { get }
53-
}
54-
5515
/// A type that can be converted to and from an associated raw value.
5616
///
5717
/// With a `RawRepresentable` type, you can switch back and forth between a
@@ -701,8 +661,8 @@ public protocol _ExpressibleByFileReferenceLiteral {
701661
public protocol _DestructorSafeContainer {
702662
}
703663

704-
@available(*, unavailable, renamed: "Boolean")
705-
public typealias BooleanType = Boolean
664+
@available(*, unavailable, renamed: "Bool")
665+
public typealias BooleanType = Bool
706666

707667
// Deprecated by SE-0115.
708668

stdlib/public/core/GroupInfo.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
"UnavailableStringAPIs.swift"
2626
],
2727
"Bool": [
28-
"Bool.swift",
29-
"Boolean.swift"
28+
"Bool.swift"
3029
],
3130
"Collection": [
3231
"Collection.swift",

test/1_stdlib/Renames.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func _CollectionOfOne<T>(i: IteratorOverOne<T>) {
9494
}
9595

9696
func _CompilerProtocols() {
97-
func fn(_: BooleanType) {} // expected-error {{'BooleanType' has been renamed to 'Boolean'}} {{14-25=Boolean}} {{none}}
97+
func fn(_: BooleanType) {} // expected-error {{'BooleanType' has been renamed to 'Bool'}} {{14-25=Bool}} {{none}}
9898
}
9999

100100
func _EmptyCollection<T>(i: EmptyIterator<T>) {

test/1_stdlib/Runtime.swift.gyb

+13-5
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,29 @@ Runtime.test("_canBeClass") {
6666

6767
//===----------------------------------------------------------------------===//
6868

69+
protocol MyBoolean {
70+
var boolValue : Bool { get }
71+
}
72+
73+
extension Bool : MyBoolean {
74+
var boolValue : Bool { return self }
75+
}
76+
6977
// The protocol should be defined in the standard library, otherwise the cast
7078
// does not work.
71-
typealias P1 = Boolean
79+
typealias P1 = MyBoolean
7280
typealias P2 = CustomStringConvertible
7381
protocol Q1 {}
7482

7583
// A small struct that can be stored inline in an opaque buffer.
76-
struct StructConformsToP1 : Boolean, Q1 {
84+
struct StructConformsToP1 : MyBoolean, Q1 {
7785
var boolValue: Bool {
7886
return true
7987
}
8088
}
8189

8290
// A small struct that can be stored inline in an opaque buffer.
83-
struct Struct2ConformsToP1<T : Boolean> : Boolean, Q1 {
91+
struct Struct2ConformsToP1<T : MyBoolean> : MyBoolean, Q1 {
8492
init(_ value: T) {
8593
self.value = value
8694
}
@@ -135,13 +143,13 @@ struct Struct4ConformsToP2<T : CustomStringConvertible> : CustomStringConvertibl
135143

136144
struct StructDoesNotConformToP1 : Q1 {}
137145

138-
class ClassConformsToP1 : Boolean, Q1 {
146+
class ClassConformsToP1 : MyBoolean, Q1 {
139147
var boolValue: Bool {
140148
return true
141149
}
142150
}
143151

144-
class Class2ConformsToP1<T : Boolean> : Boolean, Q1 {
152+
class Class2ConformsToP1<T : MyBoolean> : MyBoolean, Q1 {
145153
init(_ value: T) {
146154
self.value = [value]
147155
}

test/Constraints/members.swift

-4
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@ func goo() {
146146

147147
func id<T>(_ t: T) -> T { return t }
148148

149-
func doGetLogicValue<T : Boolean>(_ t: T) {
150-
t.boolValue // expected-warning {{expression of type 'Bool' is unused}}
151-
}
152-
153149
protocol P {
154150
init()
155151
func bar(_ x: Int)

test/DebugInfo/autoclosure.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %target-swift-frontend %s -emit-ir -g -o - | FileCheck %s
22

3-
// CHECK: define{{.*}}@_TFF11autoclosure7call_meFVs5Int64T_u_KT_Ps7Boolean_
3+
// CHECK: define{{.*}}@_TF11autoclosure7call_meFVs5Int64T_
44
// CHECK-NOT: ret void
55
// CHECK: call void @llvm.dbg.declare{{.*}}, !dbg
66
// CHECK-NOT: ret void
@@ -17,14 +17,14 @@ infix operator &&&&& {
1717
precedence 120
1818
}
1919

20-
func &&&&&(lhs: Boolean, rhs: @autoclosure () -> Boolean) -> Bool {
21-
return lhs.boolValue ? rhs().boolValue : false
20+
func &&&&&(lhs: Bool, rhs: @autoclosure () -> Bool) -> Bool {
21+
return lhs ? rhs() : false
2222
}
2323

2424
func call_me(_ input: Int64) -> Void {
2525
// rdar://problem/14627460
2626
// An autoclosure should have a line number in the debug info and a scope line of 0.
27-
// CHECK-DAG: !DISubprogram({{.*}}linkageName: "_TFF11autoclosure7call_meFVs5Int64T_u_KT_Ps7Boolean_",{{.*}} line: [[@LINE+3]],{{.*}} isLocal: false, isDefinition: true
27+
// CHECK-DAG: !DISubprogram({{.*}}linkageName: "_TFF11autoclosure7call_meFVs5Int64T_u_KT_Sb",{{.*}} line: [[@LINE+3]],{{.*}} isLocal: false, isDefinition: true
2828
// But not in the line table.
2929
// CHECK-DAG: ![[DBG]] = !DILocation(line: [[@LINE+1]],
3030
if input != 0 &&&&& ( get_truth (input * 2 + 1) > 0 ) {

test/DebugInfo/local-vars.swift.gyb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
public class C {
1616
let member : Int
1717
init(_ i : Int) { member = i }
18-
func isZero() -> Boolean { return member == 0 }
18+
func isZero() -> Bool { return member == 0 }
1919
}
2020

2121
public struct S {

test/IDE/complete_literal.swift

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
true.#^LITERAL3^#
3131
}
3232
// LITERAL3: Begin completions
33-
// LITERAL3-DAG: Decl[InstanceVar]/CurrNominal: boolValue[#Bool#]; name=boolValue{{$}}
3433
// LITERAL3-DAG: Decl[InstanceVar]/CurrNominal: description[#String#]; name=description{{$}}
3534
// LITERAL3-DAG: Decl[InstanceVar]/CurrNominal: hashValue[#Int#]; name=hashValue{{$}}
3635

test/Inputs/clang-importer-sdk/swift-modules-without-ns/ObjectiveC.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// The iOS/arm64 target uses _Bool for Objective-C's BOOL. We include
44
// x86_64 here as well because the iOS simulator also uses _Bool.
55
#if ((os(iOS) || os(tvOS)) && (arch(arm64) || arch(x86_64))) || os(watchOS)
6-
public struct ObjCBool : Boolean {
6+
public struct ObjCBool {
77
private var value : Bool
88

99
public init(_ value: Bool) {
@@ -18,7 +18,7 @@ public struct ObjCBool : Boolean {
1818

1919
#else
2020

21-
public struct ObjCBool : Boolean {
21+
public struct ObjCBool {
2222
private var value : UInt8
2323

2424
public init(_ value: Bool) {
@@ -68,7 +68,7 @@ internal func _convertBoolToObjCBool(_ x: Bool) -> ObjCBool {
6868
}
6969

7070
internal func _convertObjCBoolToBool(_ x: ObjCBool) -> Bool {
71-
return Bool(x)
71+
return x.boolValue
7272
}
7373

7474
public func ~=(x: NSObject, y: NSObject) -> Bool {

0 commit comments

Comments
 (0)