Skip to content

Commit 535b12f

Browse files
authored
Merge pull request #14761 from moiseev/bitwise-ops
[stdlib] Make default implementations of bitwise operators as obsoleted
2 parents aa85e45 + bfddc4a commit 535b12f

File tree

2 files changed

+99
-33
lines changed

2 files changed

+99
-33
lines changed

stdlib/public/core/Policy.swift

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -474,39 +474,44 @@ public protocol _BitwiseOperations {
474474
static var allZeros: Self { get }
475475
}
476476

477-
/// Calculates the union of bits sets in the two arguments and stores the result
478-
/// in the first argument.
479-
///
480-
/// - Parameters:
481-
/// - lhs: A value to update with the union of bits set in the two arguments.
482-
/// - rhs: Another value.
483-
@_inlineable // FIXME(sil-serialize-all)
484-
public func |= <T : _BitwiseOperations>(lhs: inout T, rhs: T) {
485-
lhs = lhs | rhs
486-
}
487-
488-
/// Calculates the intersections of bits sets in the two arguments and stores
489-
/// the result in the first argument.
490-
///
491-
/// - Parameters:
492-
/// - lhs: A value to update with the intersections of bits set in the two
493-
/// arguments.
494-
/// - rhs: Another value.
495-
@_inlineable // FIXME(sil-serialize-all)
496-
public func &= <T : _BitwiseOperations>(lhs: inout T, rhs: T) {
497-
lhs = lhs & rhs
498-
}
499-
500-
/// Calculates the bits that are set in exactly one of the two arguments and
501-
/// stores the result in the first argument.
502-
///
503-
/// - Parameters:
504-
/// - lhs: A value to update with the bits that are set in exactly one of the
505-
/// two arguments.
506-
/// - rhs: Another value.
507-
@_inlineable // FIXME(sil-serialize-all)
508-
public func ^= <T : _BitwiseOperations>(lhs: inout T, rhs: T) {
509-
lhs = lhs ^ rhs
477+
extension _BitwiseOperations {
478+
/// Calculates the union of bits sets in the two arguments and stores the result
479+
/// in the first argument.
480+
///
481+
/// - Parameters:
482+
/// - lhs: A value to update with the union of bits set in the two arguments.
483+
/// - rhs: Another value.
484+
@_inlineable // FIXME(sil-serialize-all)
485+
@available(swift, obsoleted: 4.1)
486+
public static func |= (lhs: inout Self, rhs: Self) {
487+
lhs = lhs | rhs
488+
}
489+
490+
/// Calculates the intersections of bits sets in the two arguments and stores
491+
/// the result in the first argument.
492+
///
493+
/// - Parameters:
494+
/// - lhs: A value to update with the intersections of bits set in the two
495+
/// arguments.
496+
/// - rhs: Another value.
497+
@_inlineable // FIXME(sil-serialize-all)
498+
@available(swift, obsoleted: 4.1)
499+
public static func &= (lhs: inout Self, rhs: Self) {
500+
lhs = lhs & rhs
501+
}
502+
503+
/// Calculates the bits that are set in exactly one of the two arguments and
504+
/// stores the result in the first argument.
505+
///
506+
/// - Parameters:
507+
/// - lhs: A value to update with the bits that are set in exactly one of the
508+
/// two arguments.
509+
/// - rhs: Another value.
510+
@_inlineable // FIXME(sil-serialize-all)
511+
@available(swift, obsoleted: 4.1)
512+
public static func ^= (lhs: inout Self, rhs: Self) {
513+
lhs = lhs ^ rhs
514+
}
510515
}
511516

512517
//===----------------------------------------------------------------------===//
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// RUN: %swift -swift-version 4 -typecheck -verify %s
2+
3+
struct MyInt: FixedWidthInteger { // expected-error {{type 'MyInt' does not conform to protocol 'BinaryInteger'}}
4+
typealias IntegerLiteralType = Int
5+
static let isSigned = false
6+
init(integerLiteral value: Int) { fatalError() }
7+
init(_truncatingBits bits: UInt) { fatalError() }
8+
init<T : BinaryFloatingPoint>(_ source: T) { fatalError() }
9+
init?<T : BinaryFloatingPoint>(exactly source: T) { fatalError() }
10+
init<T : BinaryInteger>(_ source: T) { fatalError() }
11+
init?<T : BinaryInteger>(exactly source: T) { fatalError() }
12+
init<T : BinaryInteger>(truncatingIfNeeded source: T) { fatalError() }
13+
init<T : BinaryInteger>(clamping source: T) { fatalError() }
14+
15+
let words = [UInt]()
16+
let _lowWord: UInt = 0
17+
static var bitWidth: Int { fatalError() }
18+
var trailingZeroBitCount: Int { fatalError() }
19+
20+
static func /=(_ lhs: inout MyInt, _ rhs: MyInt) { fatalError() }
21+
static func /(_ lhs: MyInt, _ rhs: MyInt) -> MyInt { fatalError() }
22+
static func %=(_ lhs: inout MyInt, _ rhs: MyInt) { fatalError() }
23+
static func %(_ lhs: MyInt, _ rhs: MyInt) -> MyInt { fatalError() }
24+
static func +=(_ lhs: inout MyInt, _ rhs: MyInt) { fatalError() }
25+
static func +(_ lhs: MyInt, _ rhs: MyInt) -> MyInt { fatalError() }
26+
static func -=(_ lhs: inout MyInt, _ rhs: MyInt) { fatalError() }
27+
static func -(_ lhs: MyInt, _ rhs: MyInt) -> MyInt { fatalError() }
28+
static func *=(_ lhs: inout MyInt, _ rhs: MyInt) { fatalError() }
29+
static func *(_ lhs: MyInt, _ rhs: MyInt) -> MyInt { fatalError() }
30+
31+
static func ==(_ lhs: MyInt, _ rhs: MyInt) -> Bool { fatalError() }
32+
static func <(_ lhs: MyInt, _ rhs: MyInt) -> Bool { fatalError() }
33+
34+
static prefix func ~ (_ x: MyInt) -> MyInt { fatalError() }
35+
36+
static func >><RHS: BinaryInteger>(_ lhs: MyInt, _ rhs: RHS) -> MyInt { fatalError() }
37+
38+
static func >>=<RHS: BinaryInteger>(_ lhs: inout MyInt, _ rhs: RHS) { fatalError() }
39+
static func <<<RHS: BinaryInteger>(_ lhs: MyInt, _ rhs: RHS) -> MyInt { fatalError() }
40+
static func <<=<RHS: BinaryInteger>(_ lhs: inout MyInt, _ rhs: RHS) { fatalError() }
41+
42+
func quotientAndRemainder(dividingBy rhs: MyInt) -> (quotient: MyInt, remainder: MyInt) { fatalError() }
43+
func signum() -> MyInt { fatalError() }
44+
45+
var hashValue: Int { fatalError() }
46+
var byteSwapped: MyInt { fatalError() }
47+
static var max: MyInt { fatalError() }
48+
static var min: MyInt { fatalError() }
49+
func addingReportingOverflow(_ rhs: MyInt) -> (partialValue: MyInt, overflow: Bool) { fatalError() }
50+
func subtractingReportingOverflow(_ rhs: MyInt) -> (partialValue: MyInt, overflow: Bool) { fatalError() }
51+
func multipliedReportingOverflow(by rhs: MyInt) -> (partialValue: MyInt, overflow: Bool) { fatalError() }
52+
func dividedReportingOverflow(by rhs: MyInt) -> (partialValue: MyInt, overflow: Bool) { fatalError() }
53+
func remainderReportingOverflow(dividingBy rhs: MyInt) -> (partialValue: MyInt, overflow: Bool) { fatalError() }
54+
func multipliedFullWidth(by other: MyInt) -> (high: MyInt, low: Magnitude) { fatalError() }
55+
func dividingFullWidth(_ dividend: (high: MyInt, low: Magnitude)) -> (quotient: MyInt, remainder: MyInt) { fatalError() }
56+
57+
var nonzeroBitCount: Int { fatalError() }
58+
var leadingZeroBitCount: Int { fatalError() }
59+
60+
var magnitude: UInt { fatalError() }
61+
}

0 commit comments

Comments
 (0)