[stdlib] bitwise assignments for NS_OPTIONS

Fixes <rdar://problem/17797711>

This is rather a kluge because of two other problems.  Having these
fixed would allow a cleaner solution:

<rdar://problem/17815538> synthesize an allZeros static var for
BitwiseOperationsType conformance of imported NS_OPTIONS

<rdar://problem/17815767> Adding three overloads to stdlib slows
Fibonacci by 18-19%

Swift SVN r20563
This commit is contained in:
Dave Abrahams
2014-07-25 22:05:08 +00:00
parent 5b3a3bdbaa
commit 71d8e16fbf
3 changed files with 42 additions and 9 deletions

View File

@@ -171,14 +171,15 @@ public protocol RawRepresentable {
// RawOptionSetType without a circularity our type-checker can't yet handle.
public protocol _RawOptionSetType: RawRepresentable {
typealias Raw : BitwiseOperationsType, Equatable
// A non-failable version of RawRepresentable.fromRaw.
class func fromMask(raw: Raw) -> Self
}
// TODO: This is an incomplete implementation of our option sets vision.
public protocol RawOptionSetType : _RawOptionSetType, BooleanType, Equatable,
NilLiteralConvertible {
// A non-failable version of RawRepresentable.fromRaw.
class func fromMask(raw: Raw) -> Self
public protocol RawOptionSetType
: _RawOptionSetType, BooleanType, Equatable,
// BitwiseOperationsType, // FIXME <rdar://problem/17815538>
NilLiteralConvertible {
// FIXME: Disabled pending <rdar://problem/14011860> (Default
// implementations in protocols)
// The Clang importer synthesizes these for imported NS_OPTIONS.
@@ -186,6 +187,20 @@ public protocol RawOptionSetType : _RawOptionSetType, BooleanType, Equatable,
/* class func fromRaw(raw: Raw) -> Self? { return fromMask(raw) } */
}
// FIXME These overloads can go away once <rdar://problem/17815538> is
// handled.
public func |= <T: RawOptionSetType>(inout lhs: T, rhs: T) {
lhs = lhs | rhs
}
public func &= <T: RawOptionSetType>(inout lhs: T, rhs: T) {
lhs = lhs | rhs
}
public func ^= <T: RawOptionSetType>(inout lhs: T, rhs: T) {
lhs = lhs | rhs
}
/// Conforming to this protocol allows a type to be usable with the 'nil'
/// literal.
public protocol NilLiteralConvertible {