mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
stdlib: adopt @warn_unused_result
rdar://20957486 Swift SVN r31048
This commit is contained in:
@@ -1089,7 +1089,7 @@ self.test("\(testNamePrefix).dropFirst/semantics/dropFirst()==dropFirst(1)") {
|
||||
self.test("\(testNamePrefix).dropFirst/semantics/negative") {
|
||||
let s = makeWrappedSequence([1010, 2020, 3030].map(OpaqueValue.init))
|
||||
expectCrashLater()
|
||||
s.dropFirst(-1)
|
||||
_ = s.dropFirst(-1)
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
@@ -1126,7 +1126,7 @@ self.test("\(testNamePrefix).dropLast/semantics/equivalence") {
|
||||
self.test("\(testNamePrefix).dropLast/semantics/negative") {
|
||||
let s = makeWrappedSequence([1010, 2020, 3030].map(OpaqueValue.init))
|
||||
expectCrashLater()
|
||||
s.dropLast(-1)
|
||||
_ = s.dropLast(-1)
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@@ -44,6 +44,7 @@ public func find<
|
||||
}
|
||||
|
||||
/// Returns the lesser of `x` and `y`.
|
||||
@warn_unused_result
|
||||
public func min<T : Comparable>(x: T, _ y: T) -> T {
|
||||
var r = x
|
||||
if y < x {
|
||||
@@ -53,6 +54,7 @@ public func min<T : Comparable>(x: T, _ y: T) -> T {
|
||||
}
|
||||
|
||||
/// Returns the least argument passed.
|
||||
@warn_unused_result
|
||||
public func min<T : Comparable>(x: T, _ y: T, _ z: T, _ rest: T...) -> T {
|
||||
var r = x
|
||||
if y < x {
|
||||
@@ -70,6 +72,7 @@ public func min<T : Comparable>(x: T, _ y: T, _ z: T, _ rest: T...) -> T {
|
||||
}
|
||||
|
||||
/// Returns the greater of `x` and `y`.
|
||||
@warn_unused_result
|
||||
public func max<T : Comparable>(x: T, _ y: T) -> T {
|
||||
var r = y
|
||||
if y < x {
|
||||
@@ -79,6 +82,7 @@ public func max<T : Comparable>(x: T, _ y: T) -> T {
|
||||
}
|
||||
|
||||
/// Returns the greatest argument passed.
|
||||
@warn_unused_result
|
||||
public func max<T : Comparable>(x: T, _ y: T, _ z: T, _ rest: T...) -> T {
|
||||
var r = y
|
||||
if y < x {
|
||||
|
||||
@@ -37,6 +37,7 @@ public struct _ArrayBuffer<Element> : _ArrayBufferType {
|
||||
///
|
||||
/// - Requires: The elements actually have dynamic type `U`, and `U`
|
||||
/// is a class or `@objc` existential.
|
||||
@warn_unused_result
|
||||
func castToBufferOf<U>(_: U.Type) -> _ArrayBuffer<U> {
|
||||
_sanityCheck(_isClassOrObjCExistential(Element.self))
|
||||
_sanityCheck(_isClassOrObjCExistential(U.self))
|
||||
@@ -51,6 +52,7 @@ public struct _ArrayBuffer<Element> : _ArrayBufferType {
|
||||
/// deffering checking each element's `U`-ness until it is accessed.
|
||||
///
|
||||
/// - Requires: `U` is a class or `@objc` existential derived from `Element`.
|
||||
@warn_unused_result
|
||||
func downcastToBufferWithDeferredTypeCheckOf<U>(
|
||||
_: U.Type
|
||||
) -> _ArrayBuffer<U> {
|
||||
@@ -96,6 +98,7 @@ extension _ArrayBuffer {
|
||||
}
|
||||
|
||||
/// Returns `true` iff this buffer's storage is uniquely-referenced.
|
||||
@warn_unused_result
|
||||
mutating func isUniquelyReferenced() -> Bool {
|
||||
if !_isClassOrObjCExistential(Element.self) {
|
||||
return _storage.isUniquelyReferenced_native_noSpareBits()
|
||||
@@ -105,6 +108,7 @@ extension _ArrayBuffer {
|
||||
|
||||
/// Returns `true` iff this buffer's storage is either
|
||||
/// uniquely-referenced or pinned.
|
||||
@warn_unused_result
|
||||
mutating func isUniquelyReferencedOrPinned() -> Bool {
|
||||
if !_isClassOrObjCExistential(Element.self) {
|
||||
return _storage.isUniquelyReferencedOrPinned_native_noSpareBits()
|
||||
@@ -116,6 +120,7 @@ extension _ArrayBuffer {
|
||||
///
|
||||
/// - Precondition: `_isBridgedToObjectiveC(Element.self)`.
|
||||
/// O(1) if the element type is bridged verbatim, O(N) otherwise.
|
||||
@warn_unused_result
|
||||
public func _asCocoaArray() -> _NSArrayCoreType {
|
||||
_sanityCheck(
|
||||
_isBridgedToObjectiveC(Element.self),
|
||||
@@ -128,6 +133,7 @@ extension _ArrayBuffer {
|
||||
/// `_ContiguousArrayBuffer` that can be grown in-place to allow the self
|
||||
/// buffer store minimumCapacity elements, returns that buffer.
|
||||
/// Otherwise, returns `nil`.
|
||||
@warn_unused_result
|
||||
public mutating func requestUniqueMutableBackingBuffer(minimumCapacity: Int)
|
||||
-> NativeBuffer?
|
||||
{
|
||||
@@ -140,10 +146,12 @@ extension _ArrayBuffer {
|
||||
return nil
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public mutating func isMutableAndUniquelyReferenced() -> Bool {
|
||||
return isUniquelyReferenced()
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public mutating func isMutableAndUniquelyReferencedOrPinned() -> Bool {
|
||||
return isUniquelyReferencedOrPinned()
|
||||
}
|
||||
@@ -151,6 +159,7 @@ extension _ArrayBuffer {
|
||||
/// If this buffer is backed by a `_ContiguousArrayBuffer`
|
||||
/// containing the same number of elements as `self`, return it.
|
||||
/// Otherwise, return `nil`.
|
||||
@warn_unused_result
|
||||
public func requestNativeBuffer() -> NativeBuffer? {
|
||||
if !_isClassOrObjCExistential(Element.self) {
|
||||
return _native
|
||||
@@ -290,6 +299,7 @@ extension _ArrayBuffer {
|
||||
|
||||
/// Return whether the given `index` is valid for subscripting, i.e. `0
|
||||
/// ≤ index < count`
|
||||
@warn_unused_result
|
||||
internal func _isValidSubscript(index : Int,
|
||||
hoistedIsNativeBuffer: Bool) -> Bool {
|
||||
if _fastPath(hoistedIsNativeBuffer) {
|
||||
@@ -325,6 +335,7 @@ extension _ArrayBuffer {
|
||||
|
||||
/// Returns whether the given `index` is valid for subscripting, i.e. `0
|
||||
/// ≤ index < count`.
|
||||
@warn_unused_result
|
||||
internal func _isValidSubscript(index : Int,
|
||||
hoistedIsNativeNoTypeCheckBuffer : Bool)
|
||||
-> Bool {
|
||||
@@ -351,6 +362,7 @@ extension _ArrayBuffer {
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
@warn_unused_result
|
||||
func getElement(i: Int, hoistedIsNativeNoTypeCheckBuffer: Bool) -> Element {
|
||||
if _fastPath(hoistedIsNativeNoTypeCheckBuffer) {
|
||||
return _nativeNoTypeCheck[i]
|
||||
@@ -359,6 +371,7 @@ extension _ArrayBuffer {
|
||||
}
|
||||
|
||||
@inline(never)
|
||||
@warn_unused_result
|
||||
func _getElementSlowPath(i: Int) -> AnyObject {
|
||||
_sanityCheck(_isClassOrObjCExistential(Element.self), "Only single reference elements can be indexed here.")
|
||||
let element: AnyObject
|
||||
|
||||
@@ -43,6 +43,7 @@ public protocol _ArrayBufferType : MutableCollectionType {
|
||||
/// - Note: This function must remain mutating; otherwise the buffer
|
||||
/// may acquire spurious extra references, which will cause
|
||||
/// unnecessary reallocation.
|
||||
@warn_unused_result
|
||||
mutating func requestUniqueMutableBackingBuffer(minimumCapacity: Int)
|
||||
-> _ContiguousArrayBuffer<Element>?
|
||||
|
||||
@@ -52,11 +53,13 @@ public protocol _ArrayBufferType : MutableCollectionType {
|
||||
/// - Note: This function must remain mutating; otherwise the buffer
|
||||
/// may acquire spurious extra references, which will cause
|
||||
/// unnecessary reallocation.
|
||||
@warn_unused_result
|
||||
mutating func isMutableAndUniquelyReferenced() -> Bool
|
||||
|
||||
/// If this buffer is backed by a `_ContiguousArrayBuffer`
|
||||
/// containing the same number of elements as `self`, return it.
|
||||
/// Otherwise, return `nil`.
|
||||
@warn_unused_result
|
||||
func requestNativeBuffer() -> _ContiguousArrayBuffer<Element>?
|
||||
|
||||
/// Replace the given `subRange` with the first `newCount` elements of
|
||||
|
||||
@@ -73,6 +73,7 @@ protocol _ArrayType
|
||||
|
||||
//===--- algorithms -----------------------------------------------------===//
|
||||
|
||||
@warn_unused_result
|
||||
func join<
|
||||
S : SequenceType where S.Generator.Element == Self
|
||||
>(elements: S) -> Self
|
||||
|
||||
@@ -281,6 +281,7 @@ public struct ${Self}<Element>
|
||||
|
||||
//===--- private --------------------------------------------------------===//
|
||||
|
||||
@warn_unused_result
|
||||
@_semantics("array.props.isNative")
|
||||
public // @testable
|
||||
func _getArrayPropertyIsNative() -> Bool {
|
||||
@@ -289,22 +290,26 @@ public struct ${Self}<Element>
|
||||
|
||||
/// Returns true if the array is native and does not need a deferred type
|
||||
/// check.
|
||||
@warn_unused_result
|
||||
@_semantics("array.props.isNativeNoTypeCheck")
|
||||
public // @testable
|
||||
func _getArrayPropertyIsNativeNoTypeCheck() -> Bool {
|
||||
return _buffer.arrayPropertyIsNativeNoTypeCheck
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
@_semantics("array.get_count")
|
||||
internal func _getCount() -> Int {
|
||||
return _buffer.count
|
||||
}
|
||||
@warn_unused_result
|
||||
@_semantics("array.get_capacity")
|
||||
internal func _getCapacity() -> Int {
|
||||
return _buffer.capacity
|
||||
}
|
||||
|
||||
/// - Requires: The array has a native buffer.
|
||||
@warn_unused_result
|
||||
@_semantics("array.owner")
|
||||
internal func _getOwner() -> Builtin.NativeObject {
|
||||
return Builtin.castToNativeObject(_buffer.nativeOwner)
|
||||
@@ -367,6 +372,7 @@ public struct ${Self}<Element>
|
||||
_precondition(index >= startIndex, "Negative ${Self} index is out of range")
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
@_semantics("array.get_element")
|
||||
@inline(__always)
|
||||
public // @testable
|
||||
@@ -376,6 +382,7 @@ public struct ${Self}<Element>
|
||||
hoistedIsNativeNoTypeCheckBuffer : hoistedIsNativeNoTypeCheckBuffer)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
@_semantics("array.get_element_address")
|
||||
internal func _getElementAddress(index: Int) -> UnsafeMutablePointer<Element> {
|
||||
return _buffer._unconditionalMutableSubscriptBaseAddress + index
|
||||
@@ -418,6 +425,7 @@ extension ${Self} : ArrayLiteralConvertible {
|
||||
}
|
||||
|
||||
// Referenced by the compiler to allocate array literals.
|
||||
@warn_unused_result
|
||||
@_semantics("array.uninitialized")
|
||||
public func _allocateUninitialized${Self}<Element>(count: Builtin.Word)
|
||||
-> (${Self}<Element>, Builtin.RawPointer) {
|
||||
@@ -428,6 +436,7 @@ public func _allocateUninitialized${Self}<Element>(count: Builtin.Word)
|
||||
%if Self == 'Array':
|
||||
// Referenced by the compiler to deallocate array literals on the
|
||||
// error path.
|
||||
@warn_unused_result
|
||||
@_semantics("array.dealloc_uninitialized")
|
||||
public func _deallocateUninitialized${Self}<Element>(
|
||||
var array: ${Self}<Element>
|
||||
@@ -476,6 +485,7 @@ extension ${Self} : _ArrayType {
|
||||
|
||||
/// Entry point for `Array` literal construction; builds and returns
|
||||
/// a ${Self} of `count` uninitialized elements.
|
||||
@warn_unused_result
|
||||
internal static func _allocateUninitialized(
|
||||
count: Int
|
||||
) -> (${Self}, UnsafeMutablePointer<Element>) {
|
||||
@@ -663,6 +673,7 @@ extension ${Self} : _ArrayType {
|
||||
/// and concatenate the elements of the resulting sequence. For
|
||||
/// example, `[-1, -2].join([[1, 2, 3], [4, 5, 6], [7, 8, 9]])`
|
||||
/// yields `[1, 2, 3, -1, -2, 4, 5, 6, -1, -2, 7, 8, 9]`.
|
||||
@warn_unused_result
|
||||
public func join<
|
||||
S : SequenceType where S.Generator.Element == ${Self}<Element>
|
||||
>(elements: S) -> ${Self}<Element> {
|
||||
@@ -680,6 +691,7 @@ extension ${Self} : _ArrayType {
|
||||
fatalError("unavailable function can't be called")
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func _copyToNativeArrayBuffer() -> _ContiguousArrayBuffer<Element> {
|
||||
return _extractOrCopyToNativeArrayBuffer(self._buffer)
|
||||
}
|
||||
@@ -687,12 +699,14 @@ extension ${Self} : _ArrayType {
|
||||
|
||||
extension ${Self} : _Reflectable {
|
||||
/// Returns a mirror that reflects `self`.
|
||||
@warn_unused_result
|
||||
public func _getMirror() -> _MirrorType {
|
||||
return _ArrayTypeMirror(self)
|
||||
}
|
||||
}
|
||||
|
||||
extension ${Self} : CustomStringConvertible, CustomDebugStringConvertible {
|
||||
@warn_unused_result
|
||||
internal func _makeDescription(isDebug isDebug: Bool) -> String {
|
||||
var result = "["
|
||||
var first = true
|
||||
@@ -725,6 +739,7 @@ extension ${Self} : CustomStringConvertible, CustomDebugStringConvertible {
|
||||
|
||||
extension ${Self} {
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
internal func _cPointerArgs() -> (AnyObject?, Builtin.RawPointer) {
|
||||
let p = _baseAddressIfContiguous
|
||||
if _fastPath(p != nil || isEmpty) {
|
||||
@@ -837,15 +852,14 @@ internal func _arrayOutOfPlaceReplace<
|
||||
/// A _debugPrecondition check that `i` has exactly reached the end of
|
||||
/// `s`. This test is never used to ensure memory safety; that is
|
||||
/// always guaranteed by measuring `s` once and re-using that value.
|
||||
internal func _expectEnd<C : CollectionType>(
|
||||
i: C.Index, _ s: C
|
||||
) {
|
||||
internal func _expectEnd<C : CollectionType>(i: C.Index, _ s: C) {
|
||||
_debugPrecondition(
|
||||
i == s.endIndex,
|
||||
"invalid CollectionType: count differed in successive traversals"
|
||||
)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func _growArrayCapacity(capacity: Int) -> Int {
|
||||
return capacity * 2
|
||||
}
|
||||
@@ -1109,6 +1123,7 @@ internal func _arrayAppendSequence<
|
||||
// ArraySlice<Int> and Array<Int>.
|
||||
|
||||
/// Returns true if these arrays contain the same elements.
|
||||
@warn_unused_result
|
||||
public func == <Element : Equatable>(
|
||||
lhs: ${Self}<Element>, rhs: ${Self}<Element>
|
||||
) -> Bool {
|
||||
@@ -1138,6 +1153,7 @@ public func == <Element : Equatable>(
|
||||
}
|
||||
|
||||
/// Returns true if the arrays do not contain the same elements.
|
||||
@warn_unused_result
|
||||
public func != <Element : Equatable>(
|
||||
lhs: ${Self}<Element>, rhs: ${Self}<Element>
|
||||
) -> Bool {
|
||||
@@ -1151,6 +1167,7 @@ public func != <Element : Equatable>(
|
||||
///
|
||||
/// - Requires: `Base` is a base class or base `@objc` protocol (such
|
||||
/// as `AnyObject`) of `Derived`.
|
||||
@warn_unused_result
|
||||
public func _arrayUpCast<Derived, Base>(a: Array<Derived>) -> Array<Base> {
|
||||
// FIXME: Dynamic casting is currently not possible without the objc runtime:
|
||||
// rdar://problem/18801510
|
||||
@@ -1165,6 +1182,7 @@ extension Array {
|
||||
/// Return `nil` otherwise.
|
||||
// Note: this function exists here so that Foundation doesn't have
|
||||
// to know Array's implementation details.
|
||||
@warn_unused_result
|
||||
public static func _bridgeFromObjectiveCAdoptingNativeStorage(
|
||||
source: AnyObject
|
||||
) -> Array? {
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
// UnsafeMutablePointer
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _isDebugAssertConfiguration() -> Bool {
|
||||
// The values for the assert_configuration call are:
|
||||
@@ -28,6 +29,7 @@ func _isDebugAssertConfiguration() -> Bool {
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
internal func _isReleaseAssertConfiguration() -> Bool {
|
||||
// The values for the assert_configuration call are:
|
||||
// 0: Debug
|
||||
@@ -37,6 +39,7 @@ internal func _isReleaseAssertConfiguration() -> Bool {
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _isFastAssertConfiguration() -> Bool {
|
||||
// The values for the assert_configuration call are:
|
||||
@@ -47,6 +50,7 @@ func _isFastAssertConfiguration() -> Bool {
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _isStdlibInternalChecksEnabled() -> Bool {
|
||||
#if INTERNAL_CHECKS_ENABLED
|
||||
|
||||
@@ -17,6 +17,7 @@ import SwiftShims
|
||||
///
|
||||
/// This is a magic entrypoint known to the compiler. It is called in
|
||||
/// generated code for API availability checking.
|
||||
@warn_unused_result
|
||||
@_semantics("availability.osversion")
|
||||
public func _stdlib_isOSVersionAtLeast(
|
||||
major: Builtin.Word,
|
||||
@@ -44,6 +45,7 @@ public func _stdlib_isOSVersionAtLeast(
|
||||
|
||||
extension _SwiftNSOperatingSystemVersion : Comparable { }
|
||||
|
||||
@warn_unused_result
|
||||
public func == (
|
||||
left: _SwiftNSOperatingSystemVersion,
|
||||
right: _SwiftNSOperatingSystemVersion
|
||||
@@ -54,6 +56,7 @@ public func == (
|
||||
}
|
||||
|
||||
/// Lexicographic comparison of version components.
|
||||
@warn_unused_result
|
||||
public func < (
|
||||
_lhs: _SwiftNSOperatingSystemVersion,
|
||||
_rhs: _SwiftNSOperatingSystemVersion
|
||||
@@ -85,6 +88,7 @@ public func < (
|
||||
return false
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func >= (
|
||||
_lhs: _SwiftNSOperatingSystemVersion,
|
||||
_rhs: _SwiftNSOperatingSystemVersion
|
||||
|
||||
@@ -83,10 +83,12 @@ internal struct _BitMirror : _MirrorType {
|
||||
var disposition: _MirrorDisposition { return .Enum }
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func == (lhs: Bit, rhs: Bit) -> Bool {
|
||||
return lhs.rawValue == rhs.rawValue
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func < (lhs: Bit, rhs: Bit) -> Bool {
|
||||
return lhs.rawValue < rhs.rawValue
|
||||
}
|
||||
|
||||
@@ -41,7 +41,9 @@ extension Bool : _BuiltinBooleanLiteralConvertible, BooleanLiteralConvertible {
|
||||
}
|
||||
|
||||
extension Bool : BooleanType {
|
||||
@transparent public func _getBuiltinLogicValue() -> Builtin.Int1 {
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func _getBuiltinLogicValue() -> Builtin.Int1 {
|
||||
return value
|
||||
}
|
||||
|
||||
@@ -87,11 +89,13 @@ extension Bool : Equatable, Hashable {
|
||||
|
||||
// Unary logical complement.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public prefix func !(a: Bool) -> Bool {
|
||||
return Bool(Builtin.xor_Int1(a.value, true.value))
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func ==(lhs: Bool, rhs: Bool) -> Bool {
|
||||
return Bool(Builtin.cmp_eq_Int1(lhs.value, rhs.value))
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// Return the result of inverting `a`'s logic value.
|
||||
@warn_unused_result
|
||||
public prefix func !<T : BooleanType>(a: T) -> Bool {
|
||||
return !a.boolValue
|
||||
}
|
||||
@@ -20,6 +21,7 @@ public prefix func !<T : BooleanType>(a: T) -> Bool {
|
||||
/// If `lhs` is `false`, return it. Otherwise, evaluate `rhs` and
|
||||
/// return its `boolValue`.
|
||||
@inline(__always)
|
||||
@warn_unused_result
|
||||
public func && <T : BooleanType, U : BooleanType>(
|
||||
lhs: T, @autoclosure rhs: () throws -> U
|
||||
) rethrows -> Bool {
|
||||
@@ -29,6 +31,7 @@ public func && <T : BooleanType, U : BooleanType>(
|
||||
/// If `lhs` is `true`, return it. Otherwise, evaluate `rhs` and
|
||||
/// return its `boolValue`.
|
||||
@inline(__always)
|
||||
@warn_unused_result
|
||||
public func || <T : BooleanType, U : BooleanType>(
|
||||
lhs: T, @autoclosure rhs: () throws -> U
|
||||
) rethrows -> Bool {
|
||||
@@ -39,6 +42,7 @@ public func || <T : BooleanType, U : BooleanType>(
|
||||
// rdar://problem/19418937, so here are some @transparent overloads
|
||||
// for Bool. We've done the same for ObjCBool
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func && <T : BooleanType>(
|
||||
lhs: T, @autoclosure rhs: () throws -> Bool
|
||||
) rethrows -> Bool {
|
||||
@@ -46,6 +50,7 @@ public func && <T : BooleanType>(
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func || <T : BooleanType>(
|
||||
lhs: T, @autoclosure rhs: () throws -> Bool
|
||||
) rethrows -> Bool {
|
||||
|
||||
@@ -25,6 +25,7 @@ public protocol _ObjectiveCBridgeable {
|
||||
/// successfully to `Self`; for example, an `NSArray` will only
|
||||
/// convert successfully to `[String]` if it contains only
|
||||
/// `NSString`s.
|
||||
@warn_unused_result
|
||||
static func _isBridgedToObjectiveC() -> Bool
|
||||
|
||||
// _getObjectiveCType is a workaround: right now protocol witness
|
||||
@@ -32,9 +33,11 @@ public protocol _ObjectiveCBridgeable {
|
||||
// '_ObjectiveCType.self' from them.
|
||||
|
||||
/// Must return `_ObjectiveCType.self`.
|
||||
@warn_unused_result
|
||||
static func _getObjectiveCType() -> Any.Type
|
||||
|
||||
/// Convert `self` to Objective-C.
|
||||
@warn_unused_result
|
||||
func _bridgeToObjectiveC() -> _ObjectiveCType
|
||||
|
||||
/// Bridge from an Objective-C object of the bridged class type to a
|
||||
@@ -47,6 +50,7 @@ public protocol _ObjectiveCBridgeable {
|
||||
///
|
||||
/// - parameter result The location where the result is written. The optional
|
||||
/// will always contain a value.
|
||||
@warn_unused_result
|
||||
static func _forceBridgeFromObjectiveC(
|
||||
source: _ObjectiveCType,
|
||||
inout result: Self?
|
||||
@@ -66,6 +70,7 @@ public protocol _ObjectiveCBridgeable {
|
||||
/// information is provided for the convenience of the runtime's dynamic_cast
|
||||
/// implementation, so that it need not look into the optional representation
|
||||
/// to determine success.
|
||||
@warn_unused_result
|
||||
static func _conditionallyBridgeFromObjectiveC(
|
||||
source: _ObjectiveCType,
|
||||
inout result: Self?
|
||||
@@ -137,6 +142,7 @@ public struct _BridgeableMetatype: _ObjectiveCBridgeable {
|
||||
/// + otherwise, returns the result of `x._bridgeToObjectiveC()`;
|
||||
///
|
||||
/// - otherwise, the result is empty.
|
||||
@warn_unused_result
|
||||
public func _bridgeToObjectiveC<T>(x: T) -> AnyObject? {
|
||||
if _fastPath(_isClassOrObjCExistential(T.self)) {
|
||||
return unsafeBitCast(x, AnyObject.self)
|
||||
@@ -144,6 +150,7 @@ public func _bridgeToObjectiveC<T>(x: T) -> AnyObject? {
|
||||
return _bridgeNonVerbatimToObjectiveC(x)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func _bridgeToObjectiveCUnconditional<T>(x: T) -> AnyObject {
|
||||
let optResult: AnyObject? = _bridgeToObjectiveC(x)
|
||||
_precondition(optResult != nil,
|
||||
@@ -153,6 +160,7 @@ public func _bridgeToObjectiveCUnconditional<T>(x: T) -> AnyObject {
|
||||
|
||||
/// Same as `_bridgeToObjectiveCUnconditional`, but autoreleases the
|
||||
/// return value if `T` is bridged non-verbatim.
|
||||
@warn_unused_result
|
||||
func _bridgeToObjectiveCUnconditionalAutorelease<T>(x: T) -> AnyObject
|
||||
{
|
||||
if _fastPath(_isClassOrObjCExistential(T.self)) {
|
||||
@@ -167,6 +175,7 @@ func _bridgeToObjectiveCUnconditionalAutorelease<T>(x: T) -> AnyObject
|
||||
return bridged
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
@asmname("swift_bridgeNonVerbatimToObjectiveC")
|
||||
func _bridgeNonVerbatimToObjectiveC<T>(x: T) -> AnyObject?
|
||||
|
||||
@@ -181,6 +190,7 @@ func _bridgeNonVerbatimToObjectiveC<T>(x: T) -> AnyObject?
|
||||
/// or a subclass of it, trap;
|
||||
/// + otherwise, returns the result of `T._forceBridgeFromObjectiveC(x)`;
|
||||
/// - otherwise, trap.
|
||||
@warn_unused_result
|
||||
public func _forceBridgeFromObjectiveC<T>(x: AnyObject, _: T.Type) -> T {
|
||||
if _fastPath(_isClassOrObjCExistential(T.self)) {
|
||||
return x as! T
|
||||
@@ -193,6 +203,7 @@ public func _forceBridgeFromObjectiveC<T>(x: AnyObject, _: T.Type) -> T {
|
||||
|
||||
/// Convert `x` from its Objective-C representation to its Swift
|
||||
/// representation.
|
||||
@warn_unused_result
|
||||
@asmname("_forceBridgeFromObjectiveC_bridgeable")
|
||||
public func _forceBridgeFromObjectiveC_bridgeable<T:_ObjectiveCBridgeable>(x: T._ObjectiveCType, _: T.Type) -> T {
|
||||
var result: T?
|
||||
@@ -214,6 +225,7 @@ public func _forceBridgeFromObjectiveC_bridgeable<T:_ObjectiveCBridgeable>(x: T.
|
||||
/// + otherwise, returns the result of
|
||||
/// `T._conditionallyBridgeFromObjectiveC(x)`;
|
||||
/// - otherwise, the result is empty.
|
||||
@warn_unused_result
|
||||
public func _conditionallyBridgeFromObjectiveC<T>(
|
||||
x: AnyObject,
|
||||
_: T.Type
|
||||
@@ -229,6 +241,7 @@ public func _conditionallyBridgeFromObjectiveC<T>(
|
||||
|
||||
/// Attempt to convert `x` from its Objective-C representation to its Swift
|
||||
/// representation.
|
||||
@warn_unused_result
|
||||
@asmname("_conditionallyBridgeFromObjectiveC_bridgeable")
|
||||
public func _conditionallyBridgeFromObjectiveC_bridgeable<T:_ObjectiveCBridgeable>(
|
||||
x: T._ObjectiveCType,
|
||||
@@ -239,7 +252,7 @@ public func _conditionallyBridgeFromObjectiveC_bridgeable<T:_ObjectiveCBridgeabl
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@warn_unused_result
|
||||
@asmname("swift_bridgeNonVerbatimFromObjectiveC")
|
||||
func _bridgeNonVerbatimFromObjectiveC<T>(
|
||||
x: AnyObject,
|
||||
@@ -254,6 +267,7 @@ func _bridgeNonVerbatimFromObjectiveC<T>(
|
||||
/// unchanged otherwise.
|
||||
///
|
||||
/// - Returns: `true` to indicate success, `false` to indicate failure.
|
||||
@warn_unused_result
|
||||
@asmname("swift_bridgeNonVerbatimFromObjectiveCConditional")
|
||||
func _bridgeNonVerbatimFromObjectiveCConditional<T>(
|
||||
x: AnyObject,
|
||||
@@ -267,6 +281,7 @@ func _bridgeNonVerbatimFromObjectiveCConditional<T>(
|
||||
/// - If `T` is a class type, returns `true`;
|
||||
/// - otherwise, if `T` conforms to `_ObjectiveCBridgeable`, returns
|
||||
/// `T._isBridgedToObjectiveC()`.
|
||||
@warn_unused_result
|
||||
public func _isBridgedToObjectiveC<T>(_: T.Type) -> Bool {
|
||||
if _fastPath(_isClassOrObjCExistential(T.self)) {
|
||||
return true
|
||||
@@ -274,6 +289,7 @@ public func _isBridgedToObjectiveC<T>(_: T.Type) -> Bool {
|
||||
return _isBridgedNonVerbatimToObjectiveC(T.self)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
@asmname("swift_isBridgedNonVerbatimToObjectiveC")
|
||||
func _isBridgedNonVerbatimToObjectiveC<T>(_: T.Type) -> Bool
|
||||
|
||||
@@ -281,11 +297,13 @@ func _isBridgedNonVerbatimToObjectiveC<T>(_: T.Type) -> Bool
|
||||
/// `_ObjectiveCBridgeable`, and can have its bits reinterpreted as an
|
||||
/// `AnyObject`. When this function returns true, the storage of an
|
||||
/// `Array<T>` can be `unsafeBitCast` as an array of `AnyObject`.
|
||||
@warn_unused_result
|
||||
public func _isBridgedVerbatimToObjectiveC<T>(_: T.Type) -> Bool {
|
||||
return _isClassOrObjCExistential(T.self)
|
||||
}
|
||||
|
||||
/// Retrieve the Objective-C type to which the given type is bridged.
|
||||
@warn_unused_result
|
||||
public func _getBridgedObjectiveCType<T>(_: T.Type) -> Any.Type? {
|
||||
if _fastPath(_isClassOrObjCExistential(T.self)) {
|
||||
return T.self
|
||||
@@ -293,6 +311,7 @@ public func _getBridgedObjectiveCType<T>(_: T.Type) -> Any.Type? {
|
||||
return _getBridgedNonVerbatimObjectiveCType(T.self)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
@asmname("swift_getBridgedNonVerbatimObjectiveCType")
|
||||
func _getBridgedNonVerbatimObjectiveCType<T>(_: T.Type) -> Any.Type?
|
||||
|
||||
@@ -425,6 +444,7 @@ extension AutoreleasingUnsafeMutablePointer : CustomDebugStringConvertible {
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func == <Memory> (
|
||||
lhs: AutoreleasingUnsafeMutablePointer<Memory>,
|
||||
rhs: AutoreleasingUnsafeMutablePointer<Memory>
|
||||
|
||||
@@ -67,12 +67,14 @@ struct _BridgeStorage<
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
mutating func isUniquelyReferencedNative() -> Bool {
|
||||
return _isUnique(&rawValue)
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
mutating func isUniquelyReferencedOrPinnedNative() -> Bool {
|
||||
return _isUniqueOrPinned(&rawValue)
|
||||
@@ -87,6 +89,7 @@ struct _BridgeStorage<
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func isNativeWithClearedSpareBits(bits: Int) -> Bool {
|
||||
return (_bitPattern(rawValue) &
|
||||
@@ -119,6 +122,7 @@ struct _BridgeStorage<
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
mutating func isUniquelyReferenced_native_noSpareBits() -> Bool {
|
||||
_sanityCheck(isNative)
|
||||
@@ -126,6 +130,7 @@ struct _BridgeStorage<
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
mutating func isUniquelyReferencedOrPinned_native_noSpareBits() -> Bool {
|
||||
_sanityCheck(isNative)
|
||||
|
||||
@@ -28,6 +28,7 @@ internal var _nilRawPointer: Builtin.RawPointer {
|
||||
/// In particular, `sizeof(X.self)`, when `X` is a class type, is the
|
||||
/// same regardless of how many stored properties `X` has.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func sizeof<T>(_:T.Type) -> Int {
|
||||
return Int(Builtin.sizeof(T.self))
|
||||
}
|
||||
@@ -38,18 +39,21 @@ public func sizeof<T>(_:T.Type) -> Int {
|
||||
/// In particular, `sizeof(a)`, when `a` is a class instance, is the
|
||||
/// same regardless of how many stored properties `a` has.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func sizeofValue<T>(_:T) -> Int {
|
||||
return sizeof(T.self)
|
||||
}
|
||||
|
||||
/// Returns the minimum memory alignment of `T`.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func alignof<T>(_:T.Type) -> Int {
|
||||
return Int(Builtin.alignof(T.self))
|
||||
}
|
||||
|
||||
/// Returns the minimum memory alignment of `T`.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func alignofValue<T>(_:T) -> Int {
|
||||
return alignof(T.self)
|
||||
}
|
||||
@@ -57,6 +61,7 @@ public func alignofValue<T>(_:T) -> Int {
|
||||
/// Returns the least possible interval between distinct instances of
|
||||
/// `T` in memory. The result is always positive.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func strideof<T>(_:T.Type) -> Int {
|
||||
return Int(Builtin.strideof_nonzero(T.self))
|
||||
}
|
||||
@@ -64,10 +69,12 @@ public func strideof<T>(_:T.Type) -> Int {
|
||||
/// Returns the least possible interval between distinct instances of
|
||||
/// `T` in memory. The result is always positive.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func strideofValue<T>(_:T) -> Int {
|
||||
return strideof(T.self)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
func _roundUpToAlignment(offset: Int, _ alignment: Int) -> Int {
|
||||
_sanityCheck(offset >= 0)
|
||||
_sanityCheck(alignment > 0)
|
||||
@@ -82,6 +89,7 @@ func _roundUpToAlignment(offset: Int, _ alignment: Int) -> Int {
|
||||
|
||||
/// Returns a tri-state of 0 = no, 1 = yes, 2 = maybe.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _canBeClass<T>(_: T.Type) -> Int8 {
|
||||
return Int8(Builtin.canBeClass(T.self))
|
||||
@@ -94,6 +102,7 @@ func _canBeClass<T>(_: T.Type) -> Int8 {
|
||||
/// anything.
|
||||
///
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func unsafeBitCast<T, U>(var x: T, _: U.Type) -> U {
|
||||
_precondition(sizeof(T.self) == sizeof(U.self),
|
||||
"can't unsafeBitCast between types of different sizes")
|
||||
@@ -104,38 +113,45 @@ public func unsafeBitCast<T, U>(var x: T, _: U.Type) -> U {
|
||||
|
||||
/// `unsafeBitCast` something to `AnyObject`.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func _reinterpretCastToAnyObject<T>(x: T) -> AnyObject {
|
||||
return unsafeBitCast(x, AnyObject.self)
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
func ==(lhs: Builtin.NativeObject, rhs: Builtin.NativeObject) -> Bool {
|
||||
return unsafeBitCast(lhs, Int.self) == unsafeBitCast(rhs, Int.self)
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
func !=(lhs: Builtin.NativeObject, rhs: Builtin.NativeObject) -> Bool {
|
||||
return !(lhs == rhs)
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
func ==(lhs: Builtin.RawPointer, rhs: Builtin.RawPointer) -> Bool {
|
||||
return unsafeBitCast(lhs, Int.self) == unsafeBitCast(rhs, Int.self)
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
func !=(lhs: Builtin.RawPointer, rhs: Builtin.RawPointer) -> Bool {
|
||||
return !(lhs == rhs)
|
||||
}
|
||||
|
||||
/// Return `true` iff `t0` is identical to `t1`; i.e. if they are both
|
||||
/// `nil` or they both represent the same type.
|
||||
@warn_unused_result
|
||||
public func == (t0: Any.Type?, t1: Any.Type?) -> Bool {
|
||||
return unsafeBitCast(t0, Int.self) == unsafeBitCast(t1, Int.self)
|
||||
}
|
||||
|
||||
/// Return `false` iff `t0` is identical to `t1`; i.e. if they are both
|
||||
/// `nil` or they both represent the same type.
|
||||
@warn_unused_result
|
||||
public func != (t0: Any.Type?, t1: Any.Type?) -> Bool {
|
||||
return !(t0 == t1)
|
||||
}
|
||||
@@ -160,12 +176,14 @@ func _conditionallyUnreachable() {
|
||||
Builtin.conditionallyUnreachable()
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
@asmname("swift_isClassOrObjCExistential")
|
||||
func _swift_isClassOrObjCExistential<T>(x: T.Type) -> Bool
|
||||
|
||||
/// Returns `true` iff `T` is a class type or an `@objc` existential such as
|
||||
/// `AnyObject`.
|
||||
@inline(__always)
|
||||
@warn_unused_result
|
||||
internal func _isClassOrObjCExistential<T>(x: T.Type) -> Bool {
|
||||
let tmp = _canBeClass(x)
|
||||
|
||||
@@ -185,6 +203,7 @@ internal func _isClassOrObjCExistential<T>(x: T.Type) -> Bool {
|
||||
/// not much you can do with this other than use it to identify the
|
||||
/// object.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func unsafeAddressOf(object: AnyObject) -> UnsafePointer<Void> {
|
||||
return UnsafePointer(Builtin.bridgeToRawPointer(object))
|
||||
}
|
||||
@@ -200,6 +219,7 @@ public func unsafeAddressOf(object: AnyObject) -> UnsafePointer<Void> {
|
||||
/// `unsafeBitCast` because it's more restrictive, and because
|
||||
/// checking is still performed in debug builds.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func unsafeDowncast<T : AnyObject>(x: AnyObject) -> T {
|
||||
_debugPrecondition(x is T, "invalid unsafeDowncast")
|
||||
return Builtin.bridgeFromRawPointer(Builtin.bridgeToRawPointer(x))
|
||||
@@ -216,6 +236,7 @@ public func unsafeDowncast<T : AnyObject>(x: AnyObject) -> T {
|
||||
/// than an `unsafeBitCast` because it's more restrictive, and
|
||||
/// because checking is still performed in debug builds.
|
||||
@inline(__always)
|
||||
@warn_unused_result
|
||||
public func unsafeUnwrap<T>(nonEmpty: T?) -> T {
|
||||
if let x = nonEmpty {
|
||||
return x
|
||||
@@ -228,6 +249,7 @@ public func unsafeUnwrap<T>(nonEmpty: T?) -> T {
|
||||
/// This version is for internal stdlib use; it avoids any checking
|
||||
/// overhead for users, even in Debug builds.
|
||||
@inline(__always)
|
||||
@warn_unused_result
|
||||
public // SPI(SwiftExperimental)
|
||||
func _unsafeUnwrap<T>(nonEmpty: T?) -> T {
|
||||
if let x = nonEmpty {
|
||||
@@ -237,6 +259,7 @@ func _unsafeUnwrap<T>(nonEmpty: T?) -> T {
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
@warn_unused_result
|
||||
public func _getUnsafePointerToStoredProperties(x: AnyObject)
|
||||
-> UnsafeMutablePointer<UInt8> {
|
||||
let storedPropertyOffset = _roundUpToAlignment(
|
||||
@@ -253,20 +276,27 @@ public func _getUnsafePointerToStoredProperties(x: AnyObject)
|
||||
// semantics of these function calls. This won't be necessary with
|
||||
// mandatory generic inlining.
|
||||
|
||||
@transparent @_semantics("branchhint") internal
|
||||
func _branchHint<C: BooleanType>(actual: C, _ expected: Bool) -> Bool {
|
||||
@transparent
|
||||
@_semantics("branchhint")
|
||||
@warn_unused_result
|
||||
internal func _branchHint<C : BooleanType>(actual: C, _ expected: Bool)
|
||||
-> Bool {
|
||||
return Bool(Builtin.int_expect_Int1(actual.boolValue.value, expected.value))
|
||||
}
|
||||
|
||||
/// Optimizer hint that `x` is expected to be `true`.
|
||||
@transparent @_semantics("fastpath") public
|
||||
func _fastPath<C: BooleanType>(x: C) -> Bool {
|
||||
@transparent
|
||||
@_semantics("fastpath")
|
||||
@warn_unused_result
|
||||
public func _fastPath<C: BooleanType>(x: C) -> Bool {
|
||||
return _branchHint(x.boolValue, true)
|
||||
}
|
||||
|
||||
/// Optimizer hint that `x` is expected to be `false`.
|
||||
@transparent @_semantics("slowpath") public
|
||||
func _slowPath<C: BooleanType>(x: C) -> Bool {
|
||||
@transparent
|
||||
@_semantics("slowpath")
|
||||
@warn_unused_result
|
||||
public func _slowPath<C : BooleanType>(x: C) -> Bool {
|
||||
return _branchHint(x.boolValue, false)
|
||||
}
|
||||
|
||||
@@ -275,6 +305,7 @@ func _slowPath<C: BooleanType>(x: C) -> Bool {
|
||||
/// Returns `true` iff the class indicated by `theClass` uses native
|
||||
/// Swift reference-counting.
|
||||
@inline(__always)
|
||||
@warn_unused_result
|
||||
internal func _usesNativeSwiftReferenceCounting(theClass: AnyClass) -> Bool {
|
||||
#if _runtime(_ObjC)
|
||||
return _swift_usesNativeSwiftReferenceCounting_class(
|
||||
@@ -285,11 +316,13 @@ internal func _usesNativeSwiftReferenceCounting(theClass: AnyClass) -> Bool {
|
||||
#endif
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
@asmname("_swift_class_getInstancePositiveExtentSize_native")
|
||||
func _swift_class_getInstancePositiveExtentSize_native(theClass: AnyClass) -> UInt
|
||||
|
||||
/// - Returns: `class_getInstanceSize(theClass)`.
|
||||
@inline(__always)
|
||||
@warn_unused_result
|
||||
internal func _class_getInstancePositiveExtentSize(theClass: AnyClass) -> Int {
|
||||
#if _runtime(_ObjC)
|
||||
return Int(_swift_class_getInstancePositiveExtentSize(
|
||||
@@ -299,6 +332,7 @@ internal func _class_getInstancePositiveExtentSize(theClass: AnyClass) -> Int {
|
||||
#endif
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
@asmname("_swift_isClass")
|
||||
public func _swift_isClass(x: Any) -> Bool
|
||||
|
||||
@@ -347,17 +381,20 @@ internal var _objCTaggedPointerBits: UInt {
|
||||
|
||||
/// Extract the raw bits of `x`.
|
||||
@inline(__always)
|
||||
@warn_unused_result
|
||||
internal func _bitPattern(x: Builtin.BridgeObject) -> UInt {
|
||||
return UInt(Builtin.castBitPatternFromBridgeObject(x))
|
||||
}
|
||||
|
||||
/// Extract the raw spare bits of `x`.
|
||||
@inline(__always)
|
||||
@warn_unused_result
|
||||
internal func _nonPointerBits(x: Builtin.BridgeObject) -> UInt {
|
||||
return _bitPattern(x) & _objectPointerSpareBits
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
@warn_unused_result
|
||||
internal func _isObjCTaggedPointer(x: AnyObject) -> Bool {
|
||||
return (Builtin.reinterpretCast(x) & _objCTaggedPointerBits) != 0
|
||||
}
|
||||
@@ -371,6 +408,7 @@ internal func _isObjCTaggedPointer(x: AnyObject) -> Bool {
|
||||
/// - Requires: `bits & _objectPointerIsObjCBit == 0`,
|
||||
/// `bits & _objectPointerSpareBits == bits`.
|
||||
@inline(__always)
|
||||
@warn_unused_result
|
||||
internal func _makeNativeBridgeObject(
|
||||
nativeObject: AnyObject, _ bits: UInt
|
||||
) -> Builtin.BridgeObject {
|
||||
@@ -383,6 +421,7 @@ internal func _makeNativeBridgeObject(
|
||||
|
||||
/// Create a `BridgeObject` around the given `objCObject`.
|
||||
@inline(__always)
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _makeObjCBridgeObject(
|
||||
objCObject: AnyObject
|
||||
@@ -402,6 +441,7 @@ func _makeObjCBridgeObject(
|
||||
/// `object` is either a native object, or `bits ==
|
||||
/// _objectPointerIsObjCBit`.
|
||||
@inline(__always)
|
||||
@warn_unused_result
|
||||
internal func _makeBridgeObject(
|
||||
object: AnyObject, _ bits: UInt
|
||||
) -> Builtin.BridgeObject {
|
||||
@@ -427,6 +467,7 @@ internal func _makeBridgeObject(
|
||||
/// Return the superclass of `t`, if any. The result is nil if `t` is
|
||||
/// a root class or class protocol.
|
||||
@inline(__always)
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _getSuperclass(t: AnyClass) -> AnyClass? {
|
||||
return unsafeBitCast(
|
||||
@@ -437,6 +478,7 @@ func _getSuperclass(t: AnyClass) -> AnyClass? {
|
||||
/// Return the superclass of `t`, if any. The result is nil if `t` is
|
||||
/// not a class, is a root class, or is a class protocol.
|
||||
@inline(__always)
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _getSuperclass(t: Any.Type) -> AnyClass? {
|
||||
return (t as? AnyClass).flatMap { _getSuperclass($0) }
|
||||
@@ -463,12 +505,14 @@ func _getSuperclass(t: Any.Type) -> AnyClass? {
|
||||
|
||||
/// Return true if `object` is uniquely referenced.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
internal func _isUnique<T>(inout object: T) -> Bool {
|
||||
return Bool(Builtin.isUnique(&object))
|
||||
}
|
||||
|
||||
/// Return true if `object` is uniquely referenced or pinned.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
internal func _isUniqueOrPinned<T>(inout object: T) -> Bool {
|
||||
return Bool(Builtin.isUniqueOrPinned(&object))
|
||||
}
|
||||
@@ -476,6 +520,7 @@ internal func _isUniqueOrPinned<T>(inout object: T) -> Bool {
|
||||
/// Return true if `object` is uniquely referenced.
|
||||
/// This provides sanity checks on top of the Builtin.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _isUnique_native<T>(inout object: T) -> Bool {
|
||||
// This could be a bridge object, single payload enum, or plain old
|
||||
@@ -492,6 +537,7 @@ func _isUnique_native<T>(inout object: T) -> Bool {
|
||||
/// Return true if `object` is uniquely referenced or pinned.
|
||||
/// This provides sanity checks on top of the Builtin.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _isUniqueOrPinned_native<T>(inout object: T) -> Bool {
|
||||
// This could be a bridge object, single payload enum, or plain old
|
||||
|
||||
@@ -63,6 +63,7 @@ def TypedUnaryIntrinsicFunctions():
|
||||
// Note these have a corresponding LLVM intrinsic
|
||||
% for T, CT, bits, ufunc in TypedUnaryIntrinsicFunctions():
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func _${ufunc}(x: ${T}) -> ${T} {
|
||||
return ${T}(_bits: Builtin.int_${ufunc}_FPIEEE${bits}(x.value))
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ extension String {
|
||||
///
|
||||
/// Returns `nil` if the `CString` is `NULL` or if it contains ill-formed
|
||||
/// UTF-8 code unit sequences.
|
||||
@warn_unused_result
|
||||
public static func fromCString(cs: UnsafePointer<CChar>) -> String? {
|
||||
if cs._isNull {
|
||||
return .None
|
||||
@@ -35,6 +36,7 @@ extension String {
|
||||
/// Returns `nil` if the `CString` is `NULL`. If `CString` contains
|
||||
/// ill-formed UTF-8 code unit sequences, replaces them with replacement
|
||||
/// characters (U+FFFD).
|
||||
@warn_unused_result
|
||||
public static func fromCStringRepairingIllFormedUTF8(
|
||||
cs: UnsafePointer<CChar>)
|
||||
-> (String?, hadError: Bool) {
|
||||
@@ -51,6 +53,7 @@ extension String {
|
||||
/// From a non-`nil` `UnsafePointer` to a null-terminated string
|
||||
/// with possibly-transient lifetime, create a nul-terminated array of 'C' char.
|
||||
/// Returns `nil` if passed a null pointer.
|
||||
@warn_unused_result
|
||||
public func _persistCString(s: UnsafePointer<CChar>) -> [CChar]? {
|
||||
if s == nil {
|
||||
return .None
|
||||
|
||||
@@ -149,6 +149,7 @@ extension COpaquePointer : CustomDebugStringConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func ==(lhs: COpaquePointer, rhs: COpaquePointer) -> Bool {
|
||||
return Bool(Builtin.cmp_eq_RawPointer(lhs._rawValue, rhs._rawValue))
|
||||
}
|
||||
|
||||
@@ -117,6 +117,7 @@ public struct Character :
|
||||
|
||||
/// Returns the index of the lowest byte that is 0xFF, or 8 if
|
||||
/// there is none.
|
||||
@warn_unused_result
|
||||
static func _smallSize(value: UInt64) -> Int {
|
||||
var mask: UInt64 = 0xFF
|
||||
for var i = 0; i < 8; ++i {
|
||||
@@ -128,10 +129,12 @@ public struct Character :
|
||||
return 8
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
static func _smallValue(value: Builtin.Int63) -> UInt64 {
|
||||
return UInt64(Builtin.zext_Int63_Int64(value)) | (1<<63)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal static func _makeSmallUTF8Generator(var u8: UInt64)
|
||||
-> AnyGenerator<UTF8.CodeUnit> {
|
||||
return anyGenerator {
|
||||
@@ -293,6 +296,7 @@ internal var _minASCIICharReprBuiltin: Builtin.Int63 {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func ==(lhs: Character, rhs: Character) -> Bool {
|
||||
switch (lhs._representation, rhs._representation) {
|
||||
case let (.Small(lbits), .Small(rbits)) where
|
||||
@@ -306,6 +310,7 @@ public func ==(lhs: Character, rhs: Character) -> Bool {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func <(lhs: Character, rhs: Character) -> Bool {
|
||||
switch (lhs._representation, rhs._representation) {
|
||||
case let (.Small(lbits), .Small(rbits)) where
|
||||
|
||||
@@ -162,16 +162,19 @@ public protocol CollectionType : Indexable, SequenceType {
|
||||
/// Returns `self[startIndex..<end]`
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@warn_unused_result
|
||||
func prefixUpTo(end: Index) -> SubSequence
|
||||
|
||||
/// Returns `self[start..<endIndex]`
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@warn_unused_result
|
||||
func suffixFrom(start: Index) -> SubSequence
|
||||
|
||||
/// Returns `prefixUpTo(position.successor())`
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@warn_unused_result
|
||||
func prefixThrough(position: Index) -> SubSequence
|
||||
|
||||
/// Returns `true` iff `self` is empty.
|
||||
@@ -190,6 +193,7 @@ public protocol CollectionType : Indexable, SequenceType {
|
||||
/// `nil` otherwise.
|
||||
///
|
||||
/// - Complexity: O(N).
|
||||
@warn_unused_result
|
||||
func _customIndexOfEquatableElement(element: Generator.Element) -> Index??
|
||||
|
||||
/// Returns the first element of `self`, or `nil` if `self` is empty.
|
||||
@@ -218,6 +222,7 @@ extension CollectionType where SubSequence == Self {
|
||||
/// return `nil`.
|
||||
///
|
||||
/// - Complexity: O(`self.count`)
|
||||
@warn_unused_result
|
||||
public mutating func popFirst() -> Generator.Element? {
|
||||
guard !isEmpty else { return nil }
|
||||
let element = first!
|
||||
@@ -229,6 +234,7 @@ extension CollectionType where SubSequence == Self {
|
||||
/// return `nil`.
|
||||
///
|
||||
/// - Complexity: O(`self.count`)
|
||||
@warn_unused_result
|
||||
public mutating func popLast() -> Generator.Element? {
|
||||
guard !isEmpty else { return nil }
|
||||
let lastElementIndex = startIndex.advancedBy(numericCast(count) - 1)
|
||||
@@ -280,6 +286,7 @@ extension CollectionType {
|
||||
/// `Optional(Optional(index))` if an element was found.
|
||||
///
|
||||
/// - Complexity: O(N).
|
||||
@warn_unused_result
|
||||
public // dispatching
|
||||
func _customIndexOfEquatableElement(_: Generator.Element) -> Index?? {
|
||||
return nil
|
||||
@@ -334,6 +341,7 @@ extension CollectionType {
|
||||
///
|
||||
/// - Requires: `n >= 0`
|
||||
/// - Complexity: O(`n`)
|
||||
@warn_unused_result
|
||||
public func dropFirst(n: Int) -> SubSequence {
|
||||
_precondition(n >= 0, "Can't drop a negative number of elements from a collection")
|
||||
let start = startIndex.advancedBy(numericCast(n), limit: endIndex)
|
||||
@@ -344,6 +352,7 @@ extension CollectionType {
|
||||
///
|
||||
/// - Requires: `n >= 0`
|
||||
/// - Complexity: O(`self.count`)
|
||||
@warn_unused_result
|
||||
public func dropLast(n: Int) -> SubSequence {
|
||||
_precondition(n >= 0, "Can't drop a negative number of elements from a collection")
|
||||
let amount = max(0, numericCast(count) - n)
|
||||
@@ -359,6 +368,7 @@ extension CollectionType {
|
||||
///
|
||||
/// - Requires: `maxLength >= 0`
|
||||
/// - Complexity: O(`maxLength`)
|
||||
@warn_unused_result
|
||||
public func prefix(maxLength: Int) -> SubSequence {
|
||||
_precondition(maxLength >= 0, "Can't take a prefix of negative length from a collection")
|
||||
let end = startIndex.advancedBy(numericCast(maxLength), limit: endIndex)
|
||||
@@ -373,6 +383,7 @@ extension CollectionType {
|
||||
///
|
||||
/// - Requires: `maxLength >= 0`
|
||||
/// - Complexity: O(`self.count`)
|
||||
@warn_unused_result
|
||||
public func suffix(maxLength: Int) -> SubSequence {
|
||||
_precondition(maxLength >= 0, "Can't take a suffix of negative length from a collection")
|
||||
let amount = max(0, numericCast(count) - maxLength)
|
||||
@@ -383,6 +394,7 @@ extension CollectionType {
|
||||
/// Returns `self[startIndex..<end]`
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@warn_unused_result
|
||||
public func prefixUpTo(end: Index) -> SubSequence {
|
||||
return self[startIndex..<end]
|
||||
}
|
||||
@@ -390,6 +402,7 @@ extension CollectionType {
|
||||
/// Returns `self[start..<endIndex]`
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@warn_unused_result
|
||||
public func suffixFrom(start: Index) -> SubSequence {
|
||||
return self[start..<endIndex]
|
||||
}
|
||||
@@ -397,6 +410,7 @@ extension CollectionType {
|
||||
/// Returns `prefixUpTo(position.successor())`
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@warn_unused_result
|
||||
public func prefixThrough(position: Index) -> SubSequence {
|
||||
return prefixUpTo(position.successor())
|
||||
}
|
||||
@@ -416,6 +430,7 @@ extension CollectionType {
|
||||
/// The default value is `false`.
|
||||
///
|
||||
/// - Requires: `maxSplit >= 0`
|
||||
@warn_unused_result
|
||||
public func split(
|
||||
maxSplit: Int = Int.max,
|
||||
allowEmptySlices: Bool = false,
|
||||
@@ -470,6 +485,7 @@ extension CollectionType where Generator.Element : Equatable {
|
||||
/// The default value is `false`.
|
||||
///
|
||||
/// - Requires: `maxSplit >= 0`
|
||||
@warn_unused_result
|
||||
public func split(
|
||||
separator: Generator.Element,
|
||||
maxSplit: Int = Int.max,
|
||||
@@ -485,6 +501,7 @@ extension CollectionType where Index : BidirectionalIndexType {
|
||||
///
|
||||
/// - Requires: `n >= 0`
|
||||
/// - Complexity: O(`n`)
|
||||
@warn_unused_result
|
||||
public func dropLast(n: Int) -> SubSequence {
|
||||
_precondition(n >= 0, "Can't drop a negative number of elements from a collection")
|
||||
let end = endIndex.advancedBy(numericCast(-n), limit: startIndex)
|
||||
@@ -499,6 +516,7 @@ extension CollectionType where Index : BidirectionalIndexType {
|
||||
///
|
||||
/// - Requires: `maxLength >= 0`
|
||||
/// - Complexity: O(`maxLength`)
|
||||
@warn_unused_result
|
||||
public func suffix(maxLength: Int) -> SubSequence {
|
||||
_precondition(maxLength >= 0, "Can't take a suffix of negative length from a collection")
|
||||
let start = endIndex.advancedBy(numericCast(-maxLength), limit: startIndex)
|
||||
|
||||
@@ -37,6 +37,7 @@ extension CollectionType where ${GElement} : Equatable {
|
||||
/// `value` is not found.
|
||||
///
|
||||
/// - Complexity: O(`self.count`).
|
||||
@warn_unused_result
|
||||
public func indexOf(element: ${GElement}) -> Index? {
|
||||
if let result = _customIndexOfEquatableElement(element) {
|
||||
return result
|
||||
@@ -56,6 +57,7 @@ extension CollectionType {
|
||||
/// corresponding value, or `nil` if such value is not found.
|
||||
///
|
||||
/// - Complexity: O(`self.count`).
|
||||
@warn_unused_result
|
||||
public func indexOf(
|
||||
@noescape predicate: (${GElement}) throws -> Bool
|
||||
) rethrows -> Index? {
|
||||
|
||||
@@ -47,6 +47,7 @@ public protocol RawRepresentable {
|
||||
}
|
||||
|
||||
/// Returns `true` iff `lhs.rawValue == rhs.rawValue`.
|
||||
@warn_unused_result
|
||||
public func == <
|
||||
T : RawRepresentable where T.RawValue : Equatable
|
||||
>(lhs: T, rhs: T) -> Bool {
|
||||
@@ -54,6 +55,7 @@ public func == <
|
||||
}
|
||||
|
||||
/// Returns `true` iff `lhs.rawValue != rhs.rawValue`.
|
||||
@warn_unused_result
|
||||
public func != <
|
||||
T : RawRepresentable where T.RawValue : Equatable
|
||||
>(lhs: T, rhs: T) -> Bool {
|
||||
@@ -63,6 +65,7 @@ public func != <
|
||||
// This overload is needed for ambiguity resolution against the
|
||||
// implementation of != for T : Equatable
|
||||
/// Returns `true` iff `lhs.rawValue != rhs.rawValue`.
|
||||
@warn_unused_result
|
||||
public func != <
|
||||
T : Equatable where T : RawRepresentable, T.RawValue : Equatable
|
||||
>(lhs: T, rhs: T) -> Bool {
|
||||
|
||||
@@ -34,10 +34,12 @@ internal final class _EmptyArrayStorage
|
||||
return try body(UnsafeBufferPointer(start: nil, count: 0))
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
override func _getNonVerbatimBridgedCount(dummy: Void) -> Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
override func _getNonVerbatimBridgedHeapBuffer(
|
||||
dummy: Void
|
||||
) -> _HeapBuffer<Int, AnyObject> {
|
||||
@@ -46,6 +48,7 @@ internal final class _EmptyArrayStorage
|
||||
}
|
||||
#endif
|
||||
|
||||
@warn_unused_result
|
||||
override func canStoreElementsOfDynamicType(_: Any.Type) -> Bool {
|
||||
return false
|
||||
}
|
||||
@@ -120,6 +123,7 @@ final class _ContiguousArrayStorage<Element> : _ContiguousArrayStorage1 {
|
||||
/// Returns the number of elements in the array.
|
||||
///
|
||||
/// - Precondition: `Element` is bridged non-verbatim.
|
||||
@warn_unused_result
|
||||
override internal func _getNonVerbatimBridgedCount(dummy: Void) -> Int {
|
||||
_sanityCheck(
|
||||
!_isBridgedVerbatimToObjectiveC(Element.self),
|
||||
@@ -130,6 +134,7 @@ final class _ContiguousArrayStorage<Element> : _ContiguousArrayStorage1 {
|
||||
/// Bridge array elements and return a new buffer that owns them.
|
||||
///
|
||||
/// - Precondition: `Element` is bridged non-verbatim.
|
||||
@warn_unused_result
|
||||
override internal func _getNonVerbatimBridgedHeapBuffer(dummy: Void) ->
|
||||
_HeapBuffer<Int, AnyObject> {
|
||||
_sanityCheck(
|
||||
@@ -152,6 +157,7 @@ final class _ContiguousArrayStorage<Element> : _ContiguousArrayStorage1 {
|
||||
/// `Element`. We can't store anything else without violating type
|
||||
/// safety; for example, the destructor has static knowledge that
|
||||
/// all of the elements can be destroyed as `Element`.
|
||||
@warn_unused_result
|
||||
override func canStoreElementsOfDynamicType(
|
||||
proposedElementType: Any.Type
|
||||
) -> Bool {
|
||||
@@ -183,8 +189,7 @@ public struct _ContiguousArrayBuffer<Element> : _ArrayBufferType {
|
||||
/// Make a buffer with uninitialized elements. After using this
|
||||
/// method, you must either initialize the count elements at the
|
||||
/// result's .firstElementAddress or set the result's .count to zero.
|
||||
public init(count: Int, minimumCapacity: Int)
|
||||
{
|
||||
public init(count: Int, minimumCapacity: Int) {
|
||||
let realMinimumCapacity = max(count, minimumCapacity)
|
||||
if realMinimumCapacity == 0 {
|
||||
self = _ContiguousArrayBuffer<Element>()
|
||||
@@ -262,6 +267,7 @@ public struct _ContiguousArrayBuffer<Element> : _ArrayBufferType {
|
||||
self = buffer
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public mutating func requestUniqueMutableBackingBuffer(minimumCapacity: Int)
|
||||
-> _ContiguousArrayBuffer<Element>?
|
||||
{
|
||||
@@ -271,10 +277,12 @@ public struct _ContiguousArrayBuffer<Element> : _ArrayBufferType {
|
||||
return nil
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public mutating func isMutableAndUniquelyReferenced() -> Bool {
|
||||
return isUniquelyReferenced()
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public mutating func isMutableAndUniquelyReferencedOrPinned() -> Bool {
|
||||
return isUniquelyReferencedOrPinned()
|
||||
}
|
||||
@@ -282,10 +290,12 @@ public struct _ContiguousArrayBuffer<Element> : _ArrayBufferType {
|
||||
/// If this buffer is backed by a `_ContiguousArrayBuffer`
|
||||
/// containing the same number of elements as `self`, return it.
|
||||
/// Otherwise, return `nil`.
|
||||
@warn_unused_result
|
||||
public func requestNativeBuffer() -> _ContiguousArrayBuffer<Element>? {
|
||||
return self
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
func getElement(i: Int, hoistedIsNativeNoTypeCheckBuffer: Bool) -> Element {
|
||||
_sanityCheck(
|
||||
_isValidSubscript(i,
|
||||
@@ -332,6 +342,7 @@ public struct _ContiguousArrayBuffer<Element> : _ArrayBufferType {
|
||||
|
||||
/// Returns whether the given `index` is valid for subscripting, i.e. `0
|
||||
/// ≤ index < count`.
|
||||
@warn_unused_result
|
||||
func _isValidSubscript(index : Int, hoistedIsNativeBuffer : Bool) -> Bool {
|
||||
/// Instead of returning 0 for no storage, we explicitly check
|
||||
/// for the existance of storage.
|
||||
@@ -348,6 +359,7 @@ public struct _ContiguousArrayBuffer<Element> : _ArrayBufferType {
|
||||
/// `_isValidSubscript(_:hoistedIsNativeBuffer:)` form, but is necessary
|
||||
/// for interface parity with `ArrayBuffer`.
|
||||
@inline(__always)
|
||||
@warn_unused_result
|
||||
func _isValidSubscript(index : Int, hoistedIsNativeNoTypeCheckBuffer : Bool)
|
||||
-> Bool {
|
||||
return _isValidSubscript(index,
|
||||
@@ -377,8 +389,7 @@ public struct _ContiguousArrayBuffer<Element> : _ArrayBufferType {
|
||||
|
||||
/// Returns a `_SliceBuffer` containing the given `subRange` of values
|
||||
/// from this buffer.
|
||||
public subscript(subRange: Range<Int>) -> _SliceBuffer<Element>
|
||||
{
|
||||
public subscript(subRange: Range<Int>) -> _SliceBuffer<Element> {
|
||||
return _SliceBuffer(
|
||||
owner: __bufferPointer.buffer,
|
||||
subscriptBaseAddress: subscriptBaseAddress,
|
||||
@@ -391,6 +402,7 @@ public struct _ContiguousArrayBuffer<Element> : _ArrayBufferType {
|
||||
/// - Note: This does not mean the buffer is mutable. Other factors
|
||||
/// may need to be considered, such as whether the buffer could be
|
||||
/// some immutable Cocoa container.
|
||||
@warn_unused_result
|
||||
public mutating func isUniquelyReferenced() -> Bool {
|
||||
return __bufferPointer.holdsUniqueReference()
|
||||
}
|
||||
@@ -398,6 +410,7 @@ public struct _ContiguousArrayBuffer<Element> : _ArrayBufferType {
|
||||
/// Return true iff this buffer's storage is either
|
||||
/// uniquely-referenced or pinned. NOTE: this does not mean
|
||||
/// the buffer is mutable; see the comment on isUniquelyReferenced.
|
||||
@warn_unused_result
|
||||
public mutating func isUniquelyReferencedOrPinned() -> Bool {
|
||||
return __bufferPointer.holdsUniqueOrPinnedReference()
|
||||
}
|
||||
@@ -408,6 +421,7 @@ public struct _ContiguousArrayBuffer<Element> : _ArrayBufferType {
|
||||
/// - Precondition: `Element` is bridged to Objective-C.
|
||||
///
|
||||
/// - Complexity: O(1).
|
||||
@warn_unused_result
|
||||
public func _asCocoaArray() -> _NSArrayCoreType {
|
||||
_sanityCheck(
|
||||
_isBridgedToObjectiveC(Element.self),
|
||||
@@ -449,6 +463,7 @@ public struct _ContiguousArrayBuffer<Element> : _ArrayBufferType {
|
||||
/// - Requires: `U` is a class or `@objc` existential.
|
||||
///
|
||||
/// - Complexity: O(N).
|
||||
@warn_unused_result
|
||||
func storesOnlyElementsOfType<U>(
|
||||
_: U.Type
|
||||
) -> Bool {
|
||||
@@ -523,6 +538,7 @@ extension SequenceType {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func _copySequenceToNativeArrayBuffer<
|
||||
S : SequenceType
|
||||
>(source: S) -> _ContiguousArrayBuffer<S.Generator.Element> {
|
||||
@@ -569,6 +585,7 @@ extension _ContiguousArrayBuffer {
|
||||
/// ARC loops, the extra retain, release overhead can not be eliminated which
|
||||
/// makes assigning ranges very slow. Once this has been implemented, this code
|
||||
/// should be changed to use _UnsafePartiallyInitializedContiguousArrayBuffer.
|
||||
@warn_unused_result
|
||||
internal func _copyCollectionToNativeArrayBuffer<
|
||||
C : CollectionType
|
||||
>(source: C) -> _ContiguousArrayBuffer<C.Generator.Element>
|
||||
@@ -599,9 +616,9 @@ internal func _copyCollectionToNativeArrayBuffer<
|
||||
/// element-by-element. The type is unsafe because it cannot be deinitialized
|
||||
/// until the buffer has been finalized by a call to `finish`.
|
||||
internal struct _UnsafePartiallyInitializedContiguousArrayBuffer<Element> {
|
||||
/*private*/ var result: _ContiguousArrayBuffer<Element>
|
||||
/*private*/ var p: UnsafeMutablePointer<Element>
|
||||
/*private*/ var remainingCapacity: Int
|
||||
internal var result: _ContiguousArrayBuffer<Element>
|
||||
internal var p: UnsafeMutablePointer<Element>
|
||||
internal var remainingCapacity: Int
|
||||
|
||||
/// Initialize the buffer with an initial size of `initialCapacity`
|
||||
/// elements.
|
||||
@@ -653,6 +670,7 @@ internal struct _UnsafePartiallyInitializedContiguousArrayBuffer<Element> {
|
||||
/// Returns the fully-initialized buffer. `self` is reset to contain an
|
||||
/// empty buffer and cannot be used afterward.
|
||||
@inline(__always) // For performance reasons.
|
||||
@warn_unused_result
|
||||
mutating func finish() -> _ContiguousArrayBuffer<Element> {
|
||||
// Adjust the initialized count of the buffer.
|
||||
result.count = result.capacity - remainingCapacity
|
||||
@@ -667,6 +685,7 @@ internal struct _UnsafePartiallyInitializedContiguousArrayBuffer<Element> {
|
||||
/// Returns the fully-initialized buffer. `self` is reset to contain an
|
||||
/// empty buffer and cannot be used afterward.
|
||||
@inline(__always) // For performance reasons.
|
||||
@warn_unused_result
|
||||
mutating func finishWithOriginalCount() -> _ContiguousArrayBuffer<Element> {
|
||||
_sanityCheck(remainingCapacity == result.capacity - result.count,
|
||||
"_UnsafePartiallyInitializedContiguousArrayBuffer has incorrect count")
|
||||
|
||||
@@ -26,12 +26,14 @@ extension ErrorType {
|
||||
#if _runtime(_ObjC)
|
||||
// Helper functions for the C++ runtime to have easy access to domain and
|
||||
// code as Objective-C values.
|
||||
@warn_unused_result
|
||||
@asmname("swift_stdlib_getErrorDomainNSString")
|
||||
public func _stdlib_getErrorDomainNSString<T : ErrorType>(x: UnsafePointer<T>)
|
||||
-> AnyObject {
|
||||
return x.memory._domain._bridgeToObjectiveCImpl()
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
@asmname("swift_stdlib_getErrorCode")
|
||||
public func _stdlib_getErrorCode<T : ErrorType>(x: UnsafePointer<T>) -> Int {
|
||||
return x.memory._code
|
||||
@@ -39,6 +41,7 @@ public func _stdlib_getErrorCode<T : ErrorType>(x: UnsafePointer<T>) -> Int {
|
||||
|
||||
// Known function for the compiler to use to coerce `ErrorType` instances to
|
||||
// `NSError`.
|
||||
@warn_unused_result
|
||||
@asmname("swift_bridgeErrorTypeToNSError")
|
||||
public func _bridgeErrorTypeToNSError(e: ErrorType) -> AnyObject
|
||||
#endif
|
||||
|
||||
@@ -98,6 +98,7 @@ internal class _FunctionGenerator<Element> : AnyGenerator<Element> {
|
||||
/// var x = 7
|
||||
/// let g = anyGenerator { x < 15 ? x++ : nil }
|
||||
/// let a = Array(g) // [ 7, 8, 9, 10, 11, 12, 13, 14 ]
|
||||
@warn_unused_result
|
||||
public func anyGenerator<Element>(body: ()->Element?) -> AnyGenerator<Element> {
|
||||
return _FunctionGenerator(body)
|
||||
}
|
||||
@@ -261,13 +262,26 @@ extension Any${Kind} {
|
||||
|
||||
internal protocol _ForwardIndexBoxType : class {
|
||||
var typeID: ObjectIdentifier {get}
|
||||
|
||||
@warn_unused_result
|
||||
func successor() -> _ForwardIndexBoxType
|
||||
|
||||
func _successorInPlace()
|
||||
|
||||
@warn_unused_result
|
||||
func equals(other: _ForwardIndexBoxType) -> Bool
|
||||
|
||||
@warn_unused_result
|
||||
func _unbox<T : ForwardIndexType>() -> T?
|
||||
|
||||
@warn_unused_result
|
||||
func _distanceTo(other: _ForwardIndexBoxType) -> AnyForwardIndex.Distance
|
||||
|
||||
// FIXME: Can't return Self from _advancedBy pending <rdar://20181253>
|
||||
@warn_unused_result
|
||||
func _advancedBy(distance: AnyForwardIndex.Distance) -> _ForwardIndexBoxType
|
||||
|
||||
@warn_unused_result
|
||||
func _advancedBy(
|
||||
distance: AnyForwardIndex.Distance,
|
||||
_ limit: _ForwardIndexBoxType
|
||||
@@ -466,6 +480,7 @@ public struct ${Self} : ${Traversal}IndexType {
|
||||
///
|
||||
/// - Requires: The types of indices wrapped by `lhs` and `rhs` are
|
||||
/// identical.
|
||||
@warn_unused_result
|
||||
public func == (lhs: ${Self}, rhs: ${Self}) -> Bool {
|
||||
precondition(lhs._typeID == rhs._typeID, "base index types differ.")
|
||||
return lhs._box.equals(rhs._box)
|
||||
@@ -502,6 +517,7 @@ public protocol AnyCollectionType : CollectionType {
|
||||
}
|
||||
|
||||
/// Return true iff `lhs` and `rhs` store the same underlying collection.
|
||||
@warn_unused_result
|
||||
public func === <
|
||||
L: AnyCollectionType, R: AnyCollectionType
|
||||
>(lhs: L, rhs: R) -> Bool {
|
||||
@@ -509,6 +525,7 @@ public func === <
|
||||
}
|
||||
|
||||
/// Returns false iff `lhs` and `rhs` store the same underlying collection.
|
||||
@warn_unused_result
|
||||
public func !== <
|
||||
L: AnyCollectionType, R: AnyCollectionType
|
||||
>(lhs: L, rhs: R) -> Bool {
|
||||
|
||||
@@ -138,7 +138,8 @@ public struct LazyFilterIndex<
|
||||
}
|
||||
|
||||
/// Returns `true` iff `lhs` is identical to `rhs`.
|
||||
public func == <Base: CollectionType>(
|
||||
@warn_unused_result
|
||||
public func == <Base : CollectionType>(
|
||||
lhs: LazyFilterIndex<Base>,
|
||||
rhs: LazyFilterIndex<Base>
|
||||
) -> Bool {
|
||||
|
||||
@@ -68,6 +68,7 @@ public protocol IntegerType : _IntegerType, RandomAccessIndexType {
|
||||
public protocol _SignedIntegerType : _IntegerType, SignedNumberType {
|
||||
/// Represent this number using Swift's widest native signed integer
|
||||
/// type.
|
||||
@warn_unused_result
|
||||
func toIntMax() -> IntMax
|
||||
|
||||
/// Convert from Swift's widest signed integer type, trapping on
|
||||
@@ -101,6 +102,7 @@ public protocol UnsignedIntegerType : _DisallowMixedSignArithmetic, IntegerType
|
||||
|
||||
/// Represent this number using Swift's widest native unsigned
|
||||
/// integer type.
|
||||
@warn_unused_result
|
||||
func toUIntMax() -> UIntMax
|
||||
|
||||
/// Convert from Swift's widest unsigned integer type, trapping on
|
||||
@@ -116,6 +118,7 @@ public protocol UnsignedIntegerType : _DisallowMixedSignArithmetic, IntegerType
|
||||
///
|
||||
/// func f(x: Int32) {}
|
||||
/// func g(x: Int64) { f(numericCast(x)) }
|
||||
@warn_unused_result
|
||||
public func numericCast<
|
||||
T : _SignedIntegerType, U : _SignedIntegerType
|
||||
>(x: T) -> U {
|
||||
@@ -130,6 +133,7 @@ public func numericCast<
|
||||
///
|
||||
/// func f(x: UInt32) {}
|
||||
/// func g(x: UInt64) { f(numericCast(x)) }
|
||||
@warn_unused_result
|
||||
public func numericCast<
|
||||
T : UnsignedIntegerType, U : UnsignedIntegerType
|
||||
>(x: T) -> U {
|
||||
@@ -144,6 +148,7 @@ public func numericCast<
|
||||
///
|
||||
/// func f(x: UInt32) {}
|
||||
/// func g(x: Int64) { f(numericCast(x)) }
|
||||
@warn_unused_result
|
||||
public func numericCast<
|
||||
T : _SignedIntegerType, U : UnsignedIntegerType
|
||||
>(x: T) -> U {
|
||||
@@ -158,6 +163,7 @@ public func numericCast<
|
||||
///
|
||||
/// func f(x: Int32) {}
|
||||
/// func g(x: UInt64) { f(numericCast(x)) }
|
||||
@warn_unused_result
|
||||
public func numericCast<
|
||||
T : UnsignedIntegerType, U : _SignedIntegerType
|
||||
>(x: T) -> U {
|
||||
@@ -628,6 +634,7 @@ public postfix func -- (inout x: ${Self}) -> ${Self} {
|
||||
/// Returns the argument and specifies that the value is not negative.
|
||||
/// It has only an effect if the argument is a load or call.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func _assumeNonNegative(x: ${Self}) -> ${Self} {
|
||||
_sanityCheck(x >= 0)
|
||||
return ${Self}(Builtin.assumeNonNegative_${BuiltinName}(x.value))
|
||||
|
||||
@@ -90,6 +90,7 @@ public struct FlattenSequence<
|
||||
|
||||
extension SequenceType where Generator.Element : SequenceType {
|
||||
/// A concatenation of the elements of `self`.
|
||||
@warn_unused_result
|
||||
public func flatten() -> FlattenSequence<Self> {
|
||||
return FlattenSequence(self)
|
||||
}
|
||||
@@ -99,6 +100,7 @@ extension LazySequenceType
|
||||
where Elements.Generator.Element == Generator.Element,
|
||||
Generator.Element : SequenceType {
|
||||
/// A concatenation of the elements of `self`.
|
||||
@warn_unused_result
|
||||
public func flatten() -> LazySequence<
|
||||
FlattenSequence<Elements>
|
||||
> {
|
||||
@@ -195,6 +197,7 @@ public struct ${Index}<
|
||||
internal let _innerCollection: BaseElements.Generator.Element?
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func == <BaseElements> (
|
||||
lhs: ${Index}<BaseElements>,
|
||||
rhs: ${Index}<BaseElements>
|
||||
@@ -285,6 +288,7 @@ public struct ${Collection}<
|
||||
|
||||
extension CollectionType where ${constraints % {'Base': ''}} {
|
||||
/// A concatenation of the elements of `self`.
|
||||
@warn_unused_result
|
||||
public func flatten() -> ${Collection}<Self> {
|
||||
return ${Collection}(self)
|
||||
}
|
||||
@@ -295,6 +299,7 @@ extension LazyCollectionType
|
||||
${constraints % {'Base': 'Elements.'}},
|
||||
Generator.Element == Elements.Generator.Element {
|
||||
/// A concatenation of the elements of `self`.
|
||||
@warn_unused_result
|
||||
public func flatten() -> LazyCollection<${Collection}<Elements>> {
|
||||
return ${Collection}(elements).lazy
|
||||
}
|
||||
|
||||
@@ -216,14 +216,17 @@ extension ${Self} : FloatingPointType {
|
||||
return _BitsType(Builtin.bitcast_FPIEEE${bits}_Int${bits}(value))
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
func __getSignBit() -> Int {
|
||||
return Int(_toBitPattern() >> ${bits - 1}) & 1
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
func __getBiasedExponent() -> _BitsType {
|
||||
return (_toBitPattern() >> ${getSignificantBitCount(bits)}) & ${getInfinityExponent(bits)}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
func __getSignificand() -> _BitsType {
|
||||
let mask: _BitsType = (1 << ${getSignificantBitCount(bits)}) - 1
|
||||
return _toBitPattern() & mask
|
||||
@@ -417,31 +420,37 @@ extension ${Self} : FloatLiteralConvertible {
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func ==(lhs: ${Self}, rhs: ${Self}) -> Bool {
|
||||
return Bool(Builtin.fcmp_oeq_FPIEEE${bits}(lhs.value, rhs.value))
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func != (lhs: ${Self}, rhs: ${Self}) -> Bool {
|
||||
return Bool(Builtin.fcmp_une_FPIEEE${bits}(lhs.value, rhs.value))
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func <(lhs: ${Self}, rhs: ${Self}) -> Bool {
|
||||
return Bool(Builtin.fcmp_olt_FPIEEE${bits}(lhs.value, rhs.value))
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func > (lhs: ${Self}, rhs: ${Self}) -> Bool {
|
||||
return Bool(Builtin.fcmp_ogt_FPIEEE${bits}(lhs.value, rhs.value))
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func <= (lhs: ${Self}, rhs: ${Self}) -> Bool {
|
||||
return Bool(Builtin.fcmp_ole_FPIEEE${bits}(lhs.value, rhs.value))
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func >= (lhs: ${Self}, rhs: ${Self}) -> Bool {
|
||||
return Bool(Builtin.fcmp_oge_FPIEEE${bits}(lhs.value, rhs.value))
|
||||
}
|
||||
@@ -490,17 +499,20 @@ extension ${Self} : Hashable {
|
||||
extension ${Self} : AbsoluteValuable {
|
||||
/// Returns the absolute value of `x`.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public static func abs(x: ${Self}) -> ${Self} {
|
||||
return ${Self}(_bits: Builtin.int_fabs_FPIEEE${bits}(x.value))
|
||||
}
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public prefix func +(x: ${Self}) -> ${Self} {
|
||||
return x
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public prefix func -(x: ${Self}) -> ${Self} {
|
||||
return ${Self}(_bits: Builtin.fneg_FPIEEE${bits}(x.value))
|
||||
}
|
||||
@@ -588,6 +600,7 @@ extension ${Self} : Strideable {
|
||||
|
||||
% for op, name in ('+','fadd'), ('-','fsub'),('*','fmul'), ('/','fdiv'):
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func ${op} (lhs: ${Self}, rhs: ${Self}) -> ${Self} {
|
||||
return ${Self}(_bits: Builtin.${name}_FPIEEE${bits}(lhs.value, rhs.value))
|
||||
}
|
||||
@@ -598,8 +611,9 @@ public func ${op} (lhs: ${Self}, rhs: ${Self}) -> ${Self} {
|
||||
// 1) This is consistent with '%' in C#, D, Java, and JavaScript
|
||||
// 2) C99 requires this behavior for fmod*()
|
||||
// 3) C++11 requires this behavior for std::fmod*()
|
||||
@asmname("_swift_fmod${cFuncSuffix(bits)}") public
|
||||
func % (lhs: ${Self}, rhs: ${Self}) -> ${Self}
|
||||
@warn_unused_result
|
||||
@asmname("_swift_fmod${cFuncSuffix(bits)}")
|
||||
public func % (lhs: ${Self}, rhs: ${Self}) -> ${Self}
|
||||
|
||||
// See Bool.swift for && and ||
|
||||
// In C, 120 is &&
|
||||
|
||||
@@ -58,7 +58,11 @@ func ==(lhs: FloatingPointClassification, rhs: FloatingPointClassification) -> B
|
||||
/// A set of common requirements for Swift's floating point types.
|
||||
public protocol FloatingPointType : Strideable {
|
||||
typealias _BitsType
|
||||
|
||||
@warn_unused_result
|
||||
static func _fromBitPattern(bits: _BitsType) -> Self
|
||||
|
||||
@warn_unused_result
|
||||
func _toBitPattern() -> _BitsType
|
||||
|
||||
% for src_ty in all_integer_types(word_bits):
|
||||
|
||||
@@ -30,6 +30,7 @@ cFuncSuffix2 = {32: 'f', 64: 'd', 80: 'ld'}
|
||||
|
||||
/// Return true iff isspace(u) would return nonzero when the current
|
||||
/// locale is the C locale.
|
||||
@warn_unused_result
|
||||
internal func _isspace_clocale(u: UTF16.CodeUnit) -> Bool {
|
||||
return "\t\n\u{b}\u{c}\r ".utf16.contains(u)
|
||||
}
|
||||
|
||||
@@ -206,16 +206,26 @@ internal protocol _HashStorageType {
|
||||
typealias SequenceElement
|
||||
var startIndex: Index { get }
|
||||
var endIndex: Index { get }
|
||||
|
||||
@warn_unused_result
|
||||
func indexForKey(key: Key) -> Index?
|
||||
|
||||
@warn_unused_result
|
||||
func assertingGet(i: Index) -> SequenceElement
|
||||
|
||||
@warn_unused_result
|
||||
func assertingGet(key: Key) -> Value
|
||||
|
||||
@warn_unused_result
|
||||
func maybeGet(key: Key) -> Value?
|
||||
|
||||
mutating func updateValue(value: Value, forKey: Key) -> Value?
|
||||
mutating func removeAtIndex(index: Index) -> SequenceElement
|
||||
mutating func removeValueForKey(key: Key) -> Value?
|
||||
mutating func removeAll(keepCapacity keepCapacity: Bool)
|
||||
var count: Int { get }
|
||||
|
||||
@warn_unused_result
|
||||
static func fromArray(elements: [SequenceElement]) -> Self
|
||||
}
|
||||
|
||||
@@ -363,12 +373,14 @@ public struct Set<Element : Hashable> :
|
||||
}
|
||||
|
||||
/// Returns `true` if the set contains a member.
|
||||
@warn_unused_result
|
||||
public func contains(member: Element) -> Bool {
|
||||
return _variantStorage.maybeGet(member) != nil
|
||||
}
|
||||
|
||||
/// Returns the `Index` of a given member, or `nil` if the member is not
|
||||
/// present in the set.
|
||||
@warn_unused_result
|
||||
public func indexOf(member: Element) -> Index? {
|
||||
return _variantStorage.indexForKey(member)
|
||||
}
|
||||
@@ -472,6 +484,7 @@ public struct Set<Element : Hashable> :
|
||||
}
|
||||
|
||||
/// Returns true if the set is a subset of a finite sequence as a `Set`.
|
||||
@warn_unused_result
|
||||
public func isSubsetOf<
|
||||
S : SequenceType where S.Generator.Element == Element
|
||||
>(sequence: S) -> Bool {
|
||||
@@ -482,6 +495,7 @@ public struct Set<Element : Hashable> :
|
||||
|
||||
/// Returns true if the set is a subset of a finite sequence as a `Set`
|
||||
/// but not equal.
|
||||
@warn_unused_result
|
||||
public func isStrictSubsetOf<
|
||||
S : SequenceType where S.Generator.Element == Element
|
||||
>(sequence: S) -> Bool {
|
||||
@@ -491,6 +505,7 @@ public struct Set<Element : Hashable> :
|
||||
}
|
||||
|
||||
/// Returns true if the set is a superset of a finite sequence as a `Set`.
|
||||
@warn_unused_result
|
||||
public func isSupersetOf<
|
||||
S : SequenceType where S.Generator.Element == Element
|
||||
>(sequence: S) -> Bool {
|
||||
@@ -500,6 +515,7 @@ public struct Set<Element : Hashable> :
|
||||
|
||||
/// Returns true if the set is a superset of a finite sequence as a `Set`
|
||||
/// but not equal.
|
||||
@warn_unused_result
|
||||
public func isStrictSupersetOf<
|
||||
S : SequenceType where S.Generator.Element == Element
|
||||
>(sequence: S) -> Bool {
|
||||
@@ -508,6 +524,7 @@ public struct Set<Element : Hashable> :
|
||||
}
|
||||
|
||||
/// Returns true if no members in the set are in a finite sequence as a `Set`.
|
||||
@warn_unused_result
|
||||
public func isDisjointWith<
|
||||
S : SequenceType where S.Generator.Element == Element
|
||||
>(sequence: S) -> Bool {
|
||||
@@ -521,6 +538,7 @@ public struct Set<Element : Hashable> :
|
||||
}
|
||||
|
||||
/// Return a new `Set` with items in both this set and a finite sequence.
|
||||
@warn_unused_result
|
||||
public func union<
|
||||
S : SequenceType where S.Generator.Element == Element
|
||||
>(sequence: S) -> Set<Element> {
|
||||
@@ -540,6 +558,7 @@ public struct Set<Element : Hashable> :
|
||||
|
||||
/// Return a new set with elements in this set that do not occur
|
||||
/// in a finite sequence.
|
||||
@warn_unused_result
|
||||
public func subtract<
|
||||
S : SequenceType where S.Generator.Element == Element
|
||||
>(sequence: S) -> Set<Element> {
|
||||
@@ -558,6 +577,7 @@ public struct Set<Element : Hashable> :
|
||||
}
|
||||
|
||||
/// Return a new set with elements common to this set and a finite sequence.
|
||||
@warn_unused_result
|
||||
public func intersect<
|
||||
S : SequenceType where S.Generator.Element == Element
|
||||
>(sequence: S) -> Set<Element> {
|
||||
@@ -593,6 +613,7 @@ public struct Set<Element : Hashable> :
|
||||
|
||||
/// Return a new set with elements that are either in the set or a finite
|
||||
/// sequence but do not occur in both.
|
||||
@warn_unused_result
|
||||
public func exclusiveOr<
|
||||
S : SequenceType where S.Generator.Element == Element
|
||||
>(sequence: S) -> Set<Element> {
|
||||
@@ -630,10 +651,12 @@ public struct Set<Element : Hashable> :
|
||||
// `SequenceType` conformance
|
||||
//
|
||||
|
||||
@warn_unused_result
|
||||
public func _customContainsEquatableElement(member: Element) -> Bool? {
|
||||
return contains(member)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func _customIndexOfEquatableElement(member: Element) -> Index?? {
|
||||
return Optional(indexOf(member))
|
||||
}
|
||||
@@ -658,6 +681,7 @@ public struct Set<Element : Hashable> :
|
||||
/// a set and some sequence (which may itself be a `Set`).
|
||||
///
|
||||
/// (isSubset: lhs ⊂ rhs, isEqual: lhs ⊂ rhs and |lhs| = |rhs|)
|
||||
@warn_unused_result
|
||||
internal func _compareSets<Element>(lhs: Set<Element>, _ rhs: Set<Element>)
|
||||
-> (isSubset: Bool, isEqual: Bool) {
|
||||
for member in lhs {
|
||||
@@ -668,6 +692,7 @@ internal func _compareSets<Element>(lhs: Set<Element>, _ rhs: Set<Element>)
|
||||
return (true, lhs.count == rhs.count)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func == <Element : Hashable>(lhs: Set<Element>, rhs: Set<Element>) -> Bool {
|
||||
switch (lhs._variantStorage, rhs._variantStorage) {
|
||||
case (.Native(let lhsNativeOwner), .Native(let rhsNativeOwner)):
|
||||
@@ -734,7 +759,8 @@ public func == <Element : Hashable>(lhs: Set<Element>, rhs: Set<Element>) -> Boo
|
||||
}
|
||||
}
|
||||
|
||||
extension Set: CustomStringConvertible, CustomDebugStringConvertible {
|
||||
extension Set : CustomStringConvertible, CustomDebugStringConvertible {
|
||||
@warn_unused_result
|
||||
private func makeDescription(isDebug isDebug: Bool) -> String {
|
||||
var result = isDebug ? "Set([" : "["
|
||||
var first = true
|
||||
@@ -784,6 +810,7 @@ internal func _stdlib_NSSet_allObjects(nss: _NSSetType) ->
|
||||
///
|
||||
/// - Requires: `BaseValue` is a base class or base `@objc`
|
||||
/// protocol (such as `AnyObject`) of `DerivedValue`.
|
||||
@warn_unused_result
|
||||
public func _setUpCast<DerivedValue, BaseValue>(source: Set<DerivedValue>)
|
||||
-> Set<BaseValue> {
|
||||
_sanityCheck(_isClassOrObjCExistential(BaseValue.self))
|
||||
@@ -802,6 +829,7 @@ public func _setUpCast<DerivedValue, BaseValue>(source: Set<DerivedValue>)
|
||||
///
|
||||
/// - Precondition: `SwiftValue` is bridged to Objective-C
|
||||
/// and requires non-trivial bridging.
|
||||
@warn_unused_result
|
||||
public func _setBridgeToObjectiveC<SwiftValue, ObjCValue>(
|
||||
source: Set<SwiftValue>
|
||||
) -> Set<ObjCValue> {
|
||||
@@ -834,6 +862,7 @@ public func _setBridgeToObjectiveC<SwiftValue, ObjCValue>(
|
||||
///
|
||||
/// - Precondition: `DerivedValue` is a subtype of `BaseValue` and both
|
||||
/// are reference types.
|
||||
@warn_unused_result
|
||||
public func _setDownCast<BaseValue, DerivedValue>(source: Set<BaseValue>)
|
||||
-> Set<DerivedValue> {
|
||||
|
||||
@@ -860,6 +889,7 @@ public func _setDownCast<BaseValue, DerivedValue>(source: Set<BaseValue>)
|
||||
///
|
||||
/// - Precondition: `DerivedValue` is a subtype of `BaseValue` and both
|
||||
/// are reference types.
|
||||
@warn_unused_result
|
||||
public func _setDownCastConditional<BaseValue, DerivedValue>(
|
||||
source: Set<BaseValue>
|
||||
) -> Set<DerivedValue>? {
|
||||
@@ -881,6 +911,7 @@ public func _setDownCastConditional<BaseValue, DerivedValue>(
|
||||
///
|
||||
/// - Precondition: At least one of `SwiftValue` is a bridged value
|
||||
/// type, and the corresponding `ObjCValue` is a reference type.
|
||||
@warn_unused_result
|
||||
public func _setBridgeFromObjectiveC<ObjCValue, SwiftValue>(
|
||||
source: Set<ObjCValue>
|
||||
) -> Set<SwiftValue> {
|
||||
@@ -896,6 +927,7 @@ public func _setBridgeFromObjectiveC<ObjCValue, SwiftValue>(
|
||||
///
|
||||
/// - Precondition: At least one of `SwiftValue` is a bridged value
|
||||
/// type, and the corresponding `ObjCValue` is a reference type.
|
||||
@warn_unused_result
|
||||
public func _setBridgeFromObjectiveCConditional<
|
||||
ObjCValue, SwiftValue
|
||||
>(
|
||||
@@ -1038,6 +1070,7 @@ public struct Dictionary<Key : Hashable, Value> :
|
||||
|
||||
/// Returns the `Index` for the given key, or `nil` if the key is not
|
||||
/// present in the dictionary.
|
||||
@warn_unused_result
|
||||
public func indexForKey(key: Key) -> Index? {
|
||||
// Complexity: amortized O(1) for native storage, O(N) when wrapping an
|
||||
// NSDictionary.
|
||||
@@ -1184,6 +1217,7 @@ public struct Dictionary<Key : Hashable, Value> :
|
||||
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func == <Key : Equatable, Value : Equatable>(
|
||||
lhs: [Key : Value],
|
||||
rhs: [Key : Value]
|
||||
@@ -1259,6 +1293,7 @@ public func == <Key : Equatable, Value : Equatable>(
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func != <Key : Equatable, Value : Equatable>(
|
||||
lhs: [Key : Value],
|
||||
rhs: [Key : Value]
|
||||
@@ -1267,6 +1302,7 @@ public func != <Key : Equatable, Value : Equatable>(
|
||||
}
|
||||
|
||||
extension Dictionary : CustomStringConvertible, CustomDebugStringConvertible {
|
||||
@warn_unused_result
|
||||
internal func _makeDescription(isDebug isDebug: Bool) -> String {
|
||||
if count == 0 {
|
||||
return "[:]"
|
||||
@@ -1310,6 +1346,7 @@ extension Dictionary : CustomStringConvertible, CustomDebugStringConvertible {
|
||||
#if _runtime(_ObjC)
|
||||
/// Equivalent to `NSDictionary.allKeys`, but does not leave objects on the
|
||||
/// autorelease pool.
|
||||
@warn_unused_result
|
||||
internal func _stdlib_NSDictionary_allKeys(nsd: _NSDictionaryType)
|
||||
-> _HeapBuffer<Int, AnyObject> {
|
||||
let count = nsd.count
|
||||
@@ -1329,6 +1366,7 @@ internal func _stdlib_NSDictionary_allKeys(nsd: _NSDictionaryType)
|
||||
/// - Requires: `BaseKey` and `BaseValue` are base classes or base `@objc`
|
||||
/// protocols (such as `AnyObject`) of `DerivedKey` and `DerivedValue`,
|
||||
/// respectively.
|
||||
@warn_unused_result
|
||||
public func _dictionaryUpCast<DerivedKey, DerivedValue, BaseKey, BaseValue>(
|
||||
source: Dictionary<DerivedKey, DerivedValue>
|
||||
) -> Dictionary<BaseKey, BaseValue> {
|
||||
@@ -1353,6 +1391,7 @@ public func _dictionaryUpCast<DerivedKey, DerivedValue, BaseKey, BaseValue>(
|
||||
///
|
||||
/// - Precondition: `SwiftKey` and `SwiftValue` are bridged to Objective-C,
|
||||
/// and at least one of them requires non-trivial bridging.
|
||||
@warn_unused_result
|
||||
public func _dictionaryBridgeToObjectiveC<
|
||||
SwiftKey, SwiftValue, ObjCKey, ObjCValue
|
||||
>(
|
||||
@@ -1407,6 +1446,7 @@ public func _dictionaryBridgeToObjectiveC<
|
||||
///
|
||||
/// - Precondition: `DerivedKey` is a subtype of `BaseKey`, `DerivedValue` is
|
||||
/// a subtype of `BaseValue`, and all of these types are reference types.
|
||||
@warn_unused_result
|
||||
public func _dictionaryDownCast<BaseKey, BaseValue, DerivedKey, DerivedValue>(
|
||||
source: Dictionary<BaseKey, BaseValue>
|
||||
) -> Dictionary<DerivedKey, DerivedValue> {
|
||||
@@ -1446,6 +1486,7 @@ public func _dictionaryDownCast<BaseKey, BaseValue, DerivedKey, DerivedValue>(
|
||||
///
|
||||
/// - Precondition: `DerivedKey` is a subtype of `BaseKey`, `DerivedValue` is
|
||||
/// a subtype of `BaseValue`, and all of these types are reference types.
|
||||
@warn_unused_result
|
||||
public func _dictionaryDownCastConditional<
|
||||
BaseKey, BaseValue, DerivedKey, DerivedValue
|
||||
>(
|
||||
@@ -1476,6 +1517,7 @@ public func _dictionaryDownCastConditional<
|
||||
///
|
||||
/// - Precondition: At least one of `SwiftKey` or `SwiftValue` is a bridged value
|
||||
/// type, and the corresponding `ObjCKey` or `ObjCValue` is a reference type.
|
||||
@warn_unused_result
|
||||
public func _dictionaryBridgeFromObjectiveC<
|
||||
ObjCKey, ObjCValue, SwiftKey, SwiftValue
|
||||
>(
|
||||
@@ -1494,6 +1536,7 @@ public func _dictionaryBridgeFromObjectiveC<
|
||||
///
|
||||
/// - Precondition: At least one of `SwiftKey` or `SwiftValue` is a bridged value
|
||||
/// type, and the corresponding `ObjCKey` or `ObjCValue` is a reference type.
|
||||
@warn_unused_result
|
||||
public func _dictionaryBridgeFromObjectiveCConditional<
|
||||
ObjCKey, ObjCValue, SwiftKey, SwiftValue
|
||||
>(
|
||||
@@ -1613,6 +1656,7 @@ final internal class _Native${Self}StorageImpl<${TypeParameters}> {
|
||||
buffer.baseAddress.destroy(body.capacity)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
final func __getInstanceSizeAndAlignMask() -> (Int, Int) {
|
||||
let buffer = ${Self}HeapBuffer(
|
||||
unsafeBitCast(self, HeapBufferStorage.self))
|
||||
@@ -1737,15 +1781,18 @@ struct _Native${Self}Storage<${TypeParametersDecl}> :
|
||||
return capacity &- 1
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func _bucket(k: Key) -> Int {
|
||||
return _squeezeHashValue(k.hashValue, 0..<capacity)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func _next(bucket: Int) -> Int {
|
||||
// Bucket is within 0 and capacity. Therefore adding 1 does not overflow.
|
||||
return (bucket &+ 1) & _bucketMask
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func _prev(bucket: Int) -> Int {
|
||||
// Bucket is not negative. Therefore subtracting 1 does not overflow.
|
||||
return (bucket &- 1) & _bucketMask
|
||||
@@ -1755,6 +1802,7 @@ struct _Native${Self}Storage<${TypeParametersDecl}> :
|
||||
///
|
||||
/// If the key is not present, returns the position where it could be
|
||||
/// inserted.
|
||||
@warn_unused_result
|
||||
internal func _find(k: Key, _ startBucket: Int) -> (pos: Index, found: Bool) {
|
||||
var bucket = startBucket
|
||||
|
||||
@@ -1770,6 +1818,7 @@ struct _Native${Self}Storage<${TypeParametersDecl}> :
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
internal static func getMinCapacity(
|
||||
requestedCount: Int, _ maxLoadFactorInverse: Double) -> Int {
|
||||
// `requestedCount + 1` below ensures that we don't fill in the last hole
|
||||
@@ -1831,6 +1880,7 @@ struct _Native${Self}Storage<${TypeParametersDecl}> :
|
||||
return Index(nativeStorage: self, offset: capacity)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func indexForKey(key: Key) -> Index? {
|
||||
if count == 0 {
|
||||
// Fast path that avoids computing the hash of the key.
|
||||
@@ -1840,6 +1890,7 @@ struct _Native${Self}Storage<${TypeParametersDecl}> :
|
||||
return found ? i : .None
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func assertingGet(i: Index) -> SequenceElement {
|
||||
let e = self[i.offset]
|
||||
_precondition(
|
||||
@@ -1857,12 +1908,14 @@ struct _Native${Self}Storage<${TypeParametersDecl}> :
|
||||
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func assertingGet(key: Key) -> Value {
|
||||
let e = self[_find(key, _bucket(key)).pos.offset]
|
||||
_precondition(e != nil, "key not found")
|
||||
return e!.value
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func maybeGet(key: Key) -> Value? {
|
||||
if count == 0 {
|
||||
// Fast path that avoids computing the hash of the key.
|
||||
@@ -1896,6 +1949,7 @@ struct _Native${Self}Storage<${TypeParametersDecl}> :
|
||||
"don't call mutating methods on _Native${Self}Storage")
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal static func fromArray(elements: [SequenceElement])
|
||||
-> _Native${Self}Storage<${TypeParameters}> {
|
||||
|
||||
@@ -1987,6 +2041,7 @@ internal struct _BridgedNative${Self}Storage {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func assertingGet(i: Int) -> SequenceElement {
|
||||
let e = self[i]
|
||||
_precondition(
|
||||
@@ -2029,6 +2084,7 @@ final internal class _Native${Self}StorageKeyNSEnumerator<
|
||||
//
|
||||
|
||||
@objc
|
||||
@warn_unused_result
|
||||
internal func nextObject() -> AnyObject? {
|
||||
if nextIndex == endIndex {
|
||||
return nil
|
||||
@@ -2129,16 +2185,19 @@ final internal class _Native${Self}StorageOwner<${TypeParametersDecl}>
|
||||
}
|
||||
|
||||
@objc
|
||||
@warn_unused_result
|
||||
internal func member(object: AnyObject) -> AnyObject? {
|
||||
return bridgingObjectForKey(object)
|
||||
}
|
||||
|
||||
@objc
|
||||
@warn_unused_result
|
||||
internal func objectEnumerator() -> _NSEnumeratorType {
|
||||
return bridgingKeyEnumerator(())
|
||||
}
|
||||
|
||||
@objc
|
||||
@warn_unused_result
|
||||
internal func copyWithZone(zone: _SwiftNSZone) -> AnyObject {
|
||||
// Instances of this class should be visible outside of standard library as
|
||||
// having `NSSet` type, which is immutable.
|
||||
@@ -2226,6 +2285,7 @@ final internal class _Native${Self}StorageOwner<${TypeParametersDecl}>
|
||||
return BridgedNativeStorage(buffer: _HeapBuffer(_heapBufferBridged!))
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func _createBridgedNativeStorage(capacity: Int) ->
|
||||
BridgedNativeStorage {
|
||||
let body = _${Self}Body(capacity: capacity)
|
||||
@@ -2269,6 +2329,7 @@ final internal class _Native${Self}StorageOwner<${TypeParametersDecl}>
|
||||
// Foundation subclasses (NS${Self}, NSEnumerator), don't access any
|
||||
// storage directly, use these functions.
|
||||
//
|
||||
@warn_unused_result
|
||||
internal func _getBridgedKey(i: _Native${Self}Index<${TypeParameters}>) ->
|
||||
AnyObject {
|
||||
if _fastPath(_isClassOrObjCExistential(Key.self)) {
|
||||
@@ -2288,6 +2349,7 @@ final internal class _Native${Self}StorageOwner<${TypeParametersDecl}>
|
||||
|
||||
%if Self == 'Set':
|
||||
|
||||
@warn_unused_result
|
||||
internal func _getBridgedValue(i: _Native${Self}Index<${TypeParameters}>) ->
|
||||
AnyObject {
|
||||
if _fastPath(_isClassOrObjCExistential(Value.self)) {
|
||||
@@ -2299,6 +2361,7 @@ final internal class _Native${Self}StorageOwner<${TypeParametersDecl}>
|
||||
|
||||
%elif Self == 'Dictionary':
|
||||
|
||||
@warn_unused_result
|
||||
internal func _getBridgedValue(i: _Native${Self}Index<${TypeParameters}>)
|
||||
-> AnyObject {
|
||||
if _fastPath(_isClassOrObjCExistential(Value.self)) {
|
||||
@@ -2368,6 +2431,7 @@ final internal class _Native${Self}StorageOwner<${TypeParametersDecl}>
|
||||
return nativeStorage.count
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func bridgingObjectForKey(aKey: AnyObject)
|
||||
-> AnyObject? {
|
||||
let nativeKey = _forceBridgeFromObjectiveC(aKey, Key.self)
|
||||
@@ -2379,6 +2443,7 @@ final internal class _Native${Self}StorageOwner<${TypeParametersDecl}>
|
||||
return nil
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func bridgingKeyEnumerator() -> _NSEnumeratorType {
|
||||
return _Native${Self}StorageKeyNSEnumerator<${TypeParameters}>(self)
|
||||
}
|
||||
@@ -2436,6 +2501,7 @@ internal struct _Cocoa${Self}Storage : _HashStorageType {
|
||||
return Index(cocoa${Self}, endIndex: ())
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func indexForKey(key: Key) -> Index? {
|
||||
// Fast path that does not involve creating an array of all keys. In case
|
||||
// the key is present, this lookup is a penalty for the slow path, but the
|
||||
@@ -2462,6 +2528,7 @@ internal struct _Cocoa${Self}Storage : _HashStorageType {
|
||||
return Index(cocoa${Self}, allKeys, keyIndex)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func assertingGet(i: Index) -> SequenceElement {
|
||||
|
||||
%if Self == 'Set':
|
||||
@@ -2476,6 +2543,7 @@ internal struct _Cocoa${Self}Storage : _HashStorageType {
|
||||
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func assertingGet(key: Key) -> Value {
|
||||
|
||||
%if Self == 'Set':
|
||||
@@ -2489,6 +2557,7 @@ internal struct _Cocoa${Self}Storage : _HashStorageType {
|
||||
%end
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func maybeGet(key: Key) -> Value? {
|
||||
|
||||
%if Self == 'Set':
|
||||
@@ -2519,6 +2588,7 @@ internal struct _Cocoa${Self}Storage : _HashStorageType {
|
||||
return cocoa${Self}.count
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal static func fromArray(elements: [SequenceElement])
|
||||
-> _Cocoa${Self}Storage {
|
||||
|
||||
@@ -2552,6 +2622,7 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorageType {
|
||||
return _canBeClass(Key.self) == 0 && _canBeClass(Value.self) == 0
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal mutating func isUniquelyReferenced() -> Bool {
|
||||
if _fastPath(guaranteedNative) {
|
||||
return _isUnique_native(&self)
|
||||
@@ -2710,6 +2781,7 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorageType {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func indexForKey(key: Key) -> Index? {
|
||||
switch self {
|
||||
case .Native:
|
||||
@@ -2730,6 +2802,7 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorageType {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func assertingGet(i: Index) -> SequenceElement {
|
||||
switch self {
|
||||
case .Native:
|
||||
@@ -2753,6 +2826,7 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorageType {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func assertingGet(key: Key) -> Value {
|
||||
switch self {
|
||||
case .Native:
|
||||
@@ -2769,6 +2843,7 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorageType {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func maybeGet(key: Key) -> Value? {
|
||||
switch self {
|
||||
case .Native:
|
||||
@@ -3072,6 +3147,7 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorageType {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal static func fromArray(elements: [SequenceElement])
|
||||
-> _Variant${Self}Storage<${TypeParameters}> {
|
||||
|
||||
@@ -3096,6 +3172,7 @@ internal struct _Native${Self}Index<${TypeParametersDecl}> :
|
||||
/// Returns the next consecutive value after `self`.
|
||||
///
|
||||
/// - Requires: The next value is representable.
|
||||
@warn_unused_result
|
||||
internal func successor() -> NativeIndex {
|
||||
var i = offset + 1
|
||||
// FIXME: Can't write the simple code pending
|
||||
@@ -3177,6 +3254,7 @@ internal struct _Cocoa${Self}Index : ForwardIndexType, Comparable {
|
||||
/// Returns the next consecutive value after `self`.
|
||||
///
|
||||
/// - Requires: The next value is representable.
|
||||
@warn_unused_result
|
||||
internal func successor() -> _Cocoa${Self}Index {
|
||||
_precondition(
|
||||
currentKeyIndex < allKeys.value, "can not increment endIndex")
|
||||
@@ -3184,6 +3262,7 @@ internal struct _Cocoa${Self}Index : ForwardIndexType, Comparable {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func ==(lhs: _Cocoa${Self}Index, rhs: _Cocoa${Self}Index) -> Bool {
|
||||
_precondition(lhs.cocoa${Self} === rhs.cocoa${Self},
|
||||
"can not compare indexes pointing to different ${Self}s")
|
||||
@@ -3193,6 +3272,7 @@ internal func ==(lhs: _Cocoa${Self}Index, rhs: _Cocoa${Self}Index) -> Bool {
|
||||
return lhs.currentKeyIndex == rhs.currentKeyIndex
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func <(lhs: _Cocoa${Self}Index, rhs: _Cocoa${Self}Index) -> Bool {
|
||||
_precondition(lhs.cocoa${Self} === rhs.cocoa${Self},
|
||||
"can not compare indexes pointing to different ${Self}s")
|
||||
@@ -3314,6 +3394,7 @@ public struct ${Self}Index<${TypeParametersDecl}> :
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func == <${TypeParametersDecl}> (
|
||||
lhs: ${Self}Index<${TypeParameters}>,
|
||||
rhs: ${Self}Index<${TypeParameters}>
|
||||
@@ -3336,6 +3417,7 @@ public func == <${TypeParametersDecl}> (
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func < <${TypeParametersDecl}> (
|
||||
lhs: ${Self}Index<${TypeParameters}>,
|
||||
rhs: ${Self}Index<${TypeParameters}>
|
||||
@@ -3566,18 +3648,21 @@ internal struct ${Self}MirrorPosition<${TypeParametersDecl}> {
|
||||
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func == <${TypeParametersDecl}> (
|
||||
lhs: ${Self}MirrorPosition<${TypeParameters}>, rhs : Int
|
||||
) -> Bool {
|
||||
return lhs._intPos == rhs
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func > <${TypeParametersDecl}> (
|
||||
lhs: ${Self}MirrorPosition<${TypeParameters}>, rhs : Int
|
||||
) -> Bool {
|
||||
return lhs._intPos > rhs
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func < <${TypeParametersDecl}> (
|
||||
lhs: ${Self}MirrorPosition<${TypeParameters}>, rhs : Int
|
||||
) -> Bool {
|
||||
@@ -3644,6 +3729,7 @@ internal class ${Self}Mirror<${TypeParametersDecl}> : _MirrorType {
|
||||
|
||||
extension ${Self} : _Reflectable {
|
||||
/// Returns a mirror that reflects `self`.
|
||||
@warn_unused_result
|
||||
public func _getMirror() -> _MirrorType {
|
||||
return ${Self}Mirror(self)
|
||||
}
|
||||
@@ -3684,6 +3770,7 @@ public struct _${Self}Builder<${TypeParametersDecl}> {
|
||||
_actualCount++
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public mutating func take() -> ${Self}<${TypeParameters}> {
|
||||
_precondition(_actualCount >= 0,
|
||||
"can not take the result twice")
|
||||
@@ -3714,6 +3801,7 @@ extension ${Self} {
|
||||
|
||||
#if _runtime(_ObjC)
|
||||
extension ${Self} {
|
||||
@warn_unused_result
|
||||
public func _bridgeToObjectiveCImpl() -> _NS${Self}CoreType {
|
||||
switch _variantStorage {
|
||||
case _Variant${Self}Storage.Native(let nativeOwner):
|
||||
@@ -3731,6 +3819,7 @@ extension ${Self} {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public static func _bridgeFromObjectiveCAdoptingNativeStorage(
|
||||
s: AnyObject
|
||||
) -> ${Self}<${TypeParameters}>? {
|
||||
|
||||
@@ -40,6 +40,7 @@ struct _HashingDetail {
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
static func getExecutionSeed() -> UInt64 {
|
||||
// FIXME: This needs to be a per-execution seed. This is just a placeholder
|
||||
// implementation.
|
||||
@@ -48,6 +49,7 @@ struct _HashingDetail {
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
static func hash16Bytes(low: UInt64, _ high: UInt64) -> UInt64 {
|
||||
// Murmur-inspired hashing.
|
||||
let mul: UInt64 = 0x9ddfea08eb382d69
|
||||
@@ -70,6 +72,7 @@ struct _HashingDetail {
|
||||
//
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _mixUInt32(value: UInt32) -> UInt32 {
|
||||
// Zero-extend to 64 bits, hash, select 32 bits from the hash.
|
||||
@@ -83,12 +86,14 @@ func _mixUInt32(value: UInt32) -> UInt32 {
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _mixInt32(value: Int32) -> Int32 {
|
||||
return Int32(bitPattern: _mixUInt32(UInt32(bitPattern: value)))
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _mixUInt64(value: UInt64) -> UInt64 {
|
||||
// Similar to hash_4to8_bytes but using a seed instead of length.
|
||||
@@ -99,12 +104,14 @@ func _mixUInt64(value: UInt64) -> UInt64 {
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _mixInt64(value: Int64) -> Int64 {
|
||||
return Int64(bitPattern: _mixUInt64(UInt64(bitPattern: value)))
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _mixUInt(value: UInt) -> UInt {
|
||||
#if arch(i386) || arch(arm)
|
||||
@@ -115,6 +122,7 @@ func _mixUInt(value: UInt) -> UInt {
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _mixInt(value: Int) -> Int {
|
||||
#if arch(i386) || arch(arm)
|
||||
@@ -141,6 +149,7 @@ func _mixInt(value: Int) -> Int {
|
||||
/// hash value does not change anything fundamentally: collisions are still
|
||||
/// possible, and it does not prevent malicious users from constructing data
|
||||
/// sets that will exhibit pathological collisions.
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _squeezeHashValue(hashValue: Int, _ resultRange: Range<Int>) -> Int {
|
||||
// Length of a Range<Int> does not fit into an Int, but fits into an UInt.
|
||||
@@ -163,6 +172,7 @@ func _squeezeHashValue(hashValue: Int, _ resultRange: Range<Int>) -> Int {
|
||||
UInt(bitPattern: resultRange.startIndex) &+ unsignedResult)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _squeezeHashValue(hashValue: Int, _ resultRange: Range<UInt>) -> UInt {
|
||||
let mixedHashValue = UInt(bitPattern: _mixInt(hashValue))
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
import SwiftShims
|
||||
typealias _HeapObject = SwiftShims.HeapObject
|
||||
|
||||
@warn_unused_result
|
||||
@asmname("swift_bufferAllocate")
|
||||
func _swift_bufferAllocate(
|
||||
bufferType: AnyClass, _ size: Int, _ alignMask: Int) -> AnyObject
|
||||
@@ -46,6 +47,8 @@ class _HeapBufferStorage<Value,Element> : NonObjectiveCBase {
|
||||
deinit {
|
||||
Buffer(self)._value.destroy()
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
final func __getInstanceSizeAndAlignMask() -> (Int,Int) {
|
||||
return Buffer(self)._allocatedSizeAndAlignMask()
|
||||
}
|
||||
@@ -66,15 +69,18 @@ struct _HeapBuffer<Value, Element> : Equatable {
|
||||
return _storage.map { Builtin.castFromNativeObject($0) }
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
static func _valueOffset() -> Int {
|
||||
return _roundUpToAlignment(sizeof(_HeapObject.self), alignof(Value.self))
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
static func _elementOffset() -> Int {
|
||||
return _roundUpToAlignment(_valueOffset() + sizeof(Value.self),
|
||||
alignof(Element.self))
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
static func _requiredAlignMask() -> Int {
|
||||
// We can't use max here because it can allocate an array.
|
||||
let heapAlign = alignof(_HeapObject.self) &- 1
|
||||
@@ -100,19 +106,23 @@ struct _HeapBuffer<Value, Element> : Equatable {
|
||||
return UnsafeMutablePointer(_HeapBuffer._elementOffset() + _address)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
func _allocatedSize() -> Int {
|
||||
return swift_malloc_size(_address)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
func _allocatedAlignMask() -> Int {
|
||||
return _HeapBuffer._requiredAlignMask()
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
func _allocatedSizeAndAlignMask() -> (Int, Int) {
|
||||
return (_allocatedSize(), _allocatedAlignMask())
|
||||
}
|
||||
|
||||
/// Return the actual number of `Elements` we can possibly store.
|
||||
@warn_unused_result
|
||||
func _capacity() -> Int {
|
||||
return (_allocatedSize() - _HeapBuffer._elementOffset())
|
||||
/ strideof(Element.self)
|
||||
@@ -194,15 +204,18 @@ struct _HeapBuffer<Value, Element> : Equatable {
|
||||
return _storage!
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
static func fromNativeObject(x: Builtin.NativeObject) -> _HeapBuffer {
|
||||
return _HeapBuffer(nativeStorage: x)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
mutating func isUniquelyReferenced() -> Bool {
|
||||
return _isUnique(&_storage)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
mutating func isUniquelyReferencedOrPinned() -> Bool {
|
||||
return _isUniqueOrPinned(&_storage)
|
||||
@@ -210,6 +223,7 @@ struct _HeapBuffer<Value, Element> : Equatable {
|
||||
}
|
||||
|
||||
// HeapBuffers are equal when they reference the same buffer
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func == <Value, Element> (
|
||||
lhs: _HeapBuffer<Value, Element>,
|
||||
|
||||
@@ -92,6 +92,7 @@ extension ImplicitlyUnwrappedOptional : CustomStringConvertible {
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // COMPILER_INTRINSIC
|
||||
func _getImplicitlyUnwrappedOptionalValue<T>(v: T!) -> T {
|
||||
switch v {
|
||||
@@ -104,12 +105,14 @@ func _getImplicitlyUnwrappedOptionalValue<T>(v: T!) -> T {
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // COMPILER_INTRINSIC
|
||||
func _injectValueIntoImplicitlyUnwrappedOptional<T>(v: T) -> T! {
|
||||
return .Some(v)
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // COMPILER_INTRINSIC
|
||||
func _injectNothingIntoImplicitlyUnwrappedOptional<T>() -> T! {
|
||||
return .None
|
||||
|
||||
@@ -47,6 +47,7 @@ public protocol _Incrementable : Equatable {
|
||||
/// `Self` values.
|
||||
///
|
||||
/// - Requires: `self` has a well-defined successor.
|
||||
@warn_unused_result
|
||||
func successor() -> Self
|
||||
|
||||
mutating func _successorInPlace()
|
||||
@@ -158,6 +159,7 @@ public protocol ForwardIndexType : _Incrementable {
|
||||
/// - Complexity:
|
||||
/// - O(1) if conforming to `RandomAccessIndexType`
|
||||
/// - O(`abs(n)`) otherwise
|
||||
@warn_unused_result
|
||||
func advancedBy(n: Distance) -> Self
|
||||
|
||||
/// Return the result of advancing `self` by `n` positions, or until it
|
||||
@@ -175,6 +177,7 @@ public protocol ForwardIndexType : _Incrementable {
|
||||
/// - Complexity:
|
||||
/// - O(1) if conforming to `RandomAccessIndexType`
|
||||
/// - O(`abs(n)`) otherwise
|
||||
@warn_unused_result
|
||||
func advancedBy(n: Distance, limit: Self) -> Self
|
||||
|
||||
/// Measure the distance between `self` and `end`.
|
||||
@@ -187,6 +190,7 @@ public protocol ForwardIndexType : _Incrementable {
|
||||
/// - Complexity:
|
||||
/// - O(1) if conforming to `RandomAccessIndexType`
|
||||
/// - O(`n`) otherwise, where `n` is the function's result.
|
||||
@warn_unused_result
|
||||
func distanceTo(end: Self) -> Distance
|
||||
}
|
||||
|
||||
@@ -205,6 +209,7 @@ extension ForwardIndexType {
|
||||
|
||||
/// Do not use this method directly; call advancedBy(n) instead.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
internal func _advanceForward(n: Distance) -> Self {
|
||||
_precondition(n >= 0,
|
||||
"Only BidirectionalIndexType can be advanced by a negative amount")
|
||||
@@ -217,6 +222,7 @@ extension ForwardIndexType {
|
||||
|
||||
/// Do not use this method directly; call advancedBy(n, limit) instead.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
internal func _advanceForward(n: Distance, _ limit: Self) -> Self {
|
||||
_precondition(n >= 0,
|
||||
"Only BidirectionalIndexType can be advanced by a negative amount")
|
||||
@@ -227,14 +233,17 @@ extension ForwardIndexType {
|
||||
return p
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func advancedBy(n: Distance) -> Self {
|
||||
return self._advanceForward(n)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func advancedBy(n: Distance, limit: Self) -> Self {
|
||||
return self._advanceForward(n, limit)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func distanceTo(end: Self) -> Distance {
|
||||
var p = self
|
||||
var count: Distance = 0
|
||||
@@ -261,6 +270,7 @@ public protocol BidirectionalIndexType : ForwardIndexType {
|
||||
/// self`.
|
||||
///
|
||||
/// - Requires: `self` has a well-defined predecessor.
|
||||
@warn_unused_result
|
||||
func predecessor() -> Self
|
||||
|
||||
mutating func _predecessorInPlace()
|
||||
@@ -272,6 +282,7 @@ extension BidirectionalIndexType {
|
||||
self = self.predecessor()
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func advancedBy(n: Distance) -> Self {
|
||||
if n >= 0 {
|
||||
return _advanceForward(n)
|
||||
@@ -283,6 +294,7 @@ extension BidirectionalIndexType {
|
||||
return p
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func advancedBy(n: Distance, limit: Self) -> Self {
|
||||
if n >= 0 {
|
||||
return _advanceForward(n, limit)
|
||||
@@ -323,10 +335,12 @@ public protocol _RandomAccessAmbiguity {
|
||||
}
|
||||
|
||||
extension _RandomAccessAmbiguity {
|
||||
@warn_unused_result
|
||||
public func advancedBy(n: Distance) -> Self {
|
||||
fatalError("advancedBy(n) not implememented")
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func advancedBy(n: Distance, limit: Self) -> Self {
|
||||
fatalError("advancedBy(n, limit:) not implememented")
|
||||
}
|
||||
@@ -336,8 +350,14 @@ extension _RandomAccessAmbiguity {
|
||||
/// and can measure the distance to any reachable value, in O(1).
|
||||
public protocol RandomAccessIndexType : BidirectionalIndexType, Strideable,
|
||||
_RandomAccessAmbiguity {
|
||||
|
||||
@warn_unused_result
|
||||
func distanceTo(other: Self) -> Distance
|
||||
|
||||
@warn_unused_result
|
||||
func advancedBy(n: Distance) -> Self
|
||||
|
||||
@warn_unused_result
|
||||
func advancedBy(n: Distance, limit: Self) -> Self
|
||||
}
|
||||
|
||||
@@ -372,6 +392,7 @@ extension RandomAccessIndexType {
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func advancedBy(n: Distance, limit: Self) -> Self {
|
||||
let d = self.distanceTo(limit)
|
||||
if d == 0 || (d > 0 ? d <= n : d >= n) {
|
||||
|
||||
@@ -21,6 +21,7 @@ import SwiftShims
|
||||
///
|
||||
/// Standard input is interpreted as `UTF-8`. Invalid bytes
|
||||
/// will be replaced by Unicode [replacement characters](http://en.wikipedia.org/wiki/Specials_(Unicode_block)#Replacement_character).
|
||||
@warn_unused_result
|
||||
public func readLine(stripNewline stripNewline: Bool = true) -> String? {
|
||||
var linePtr: UnsafeMutablePointer<CChar> = nil
|
||||
var readBytes = swift_stdlib_readLine_stdin(&linePtr)
|
||||
|
||||
@@ -41,11 +41,13 @@ public protocol IntegerArithmeticType : _IntegerArithmeticType, Comparable {
|
||||
% for name,op,Action,result in integerBinaryOps:
|
||||
/// ${Action} `lhs` and `rhs`, returning ${result} and trapping in case of
|
||||
/// arithmetic overflow (except in -Ounchecked builds).
|
||||
@warn_unused_result
|
||||
func ${op} (lhs: Self, rhs: Self) -> Self
|
||||
% end
|
||||
|
||||
/// Explicitly convert to `IntMax`, trapping on overflow (except in
|
||||
/// -Ounchecked builds).
|
||||
@warn_unused_result
|
||||
func toIntMax() -> IntMax
|
||||
}
|
||||
|
||||
@@ -53,6 +55,7 @@ public protocol IntegerArithmeticType : _IntegerArithmeticType, Comparable {
|
||||
/// ${Action} `lhs` and `rhs`, returning ${result} and trapping in case of
|
||||
/// arithmetic overflow (except in -Ounchecked builds).
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func ${op} <T : _IntegerArithmeticType>(lhs: T, rhs: T) -> T {
|
||||
return _overflowChecked(T.${name}WithOverflow(lhs, rhs))
|
||||
}
|
||||
@@ -60,6 +63,7 @@ public func ${op} <T : _IntegerArithmeticType>(lhs: T, rhs: T) -> T {
|
||||
% if (op != '/') and (op != '%'):
|
||||
/// ${name} `lhs` and `rhs`, silently discarding any overflow.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func &${op} <T : _IntegerArithmeticType>(lhs: T, rhs: T) -> T {
|
||||
return T.${name}WithOverflow(lhs, rhs).0
|
||||
}
|
||||
@@ -89,9 +93,11 @@ public func ${op}= <T : _IntegerArithmeticType>(inout lhs: T, rhs: T) {
|
||||
/// - `-(-x) == x`
|
||||
public protocol SignedNumberType : Comparable, IntegerLiteralConvertible {
|
||||
/// Return the result of negating `x`.
|
||||
@warn_unused_result
|
||||
prefix func - (x: Self) -> Self
|
||||
|
||||
/// Return the difference between `lhs` and `rhs`.
|
||||
@warn_unused_result
|
||||
func - (lhs: Self, rhs: Self) -> Self
|
||||
|
||||
// Do not use this operator directly; call abs(x) instead
|
||||
@@ -128,6 +134,7 @@ public func ~> <T : SignedNumberType>(x:T,_:(_Abs, ())) -> T {
|
||||
/// A type that supports an "absolute value" function.
|
||||
public protocol AbsoluteValuable : SignedNumberType {
|
||||
/// Returns the absolute value of `x`.
|
||||
@warn_unused_result
|
||||
static func abs(x: Self) -> Self
|
||||
}
|
||||
|
||||
|
||||
@@ -16,10 +16,12 @@ public protocol IntervalType {
|
||||
typealias Bound : Comparable
|
||||
|
||||
/// Returns `true` iff the interval contains `value`.
|
||||
@warn_unused_result
|
||||
func contains(value: Bound) -> Bool
|
||||
|
||||
/// Return `rhs` clamped to `self`. The bounds of the result, even
|
||||
/// if it is empty, are always within the bounds of `self`.
|
||||
@warn_unused_result
|
||||
func clamp(intervalToClamp: Self) -> Self
|
||||
|
||||
/// `true` iff `self` is empty.
|
||||
@@ -102,6 +104,7 @@ public struct ${Self}<Bound : Comparable>
|
||||
}
|
||||
|
||||
/// Returns `true` iff the `Interval` contains `x`.
|
||||
@warn_unused_result
|
||||
public func contains(x: Bound) -> Bool {
|
||||
return x >= start && x ${upperBoundCompare} end
|
||||
}
|
||||
@@ -110,6 +113,7 @@ public struct ${Self}<Bound : Comparable>
|
||||
///
|
||||
/// The bounds of the result, even if it is empty, are always limited to the bounds of
|
||||
/// `self`.
|
||||
@warn_unused_result
|
||||
public func clamp(intervalToClamp: ${Self}) -> ${Self} {
|
||||
|
||||
return ${Self}(
|
||||
@@ -134,6 +138,7 @@ public struct ${Self}<Bound : Comparable>
|
||||
}
|
||||
|
||||
/// Two `${Self}`s are equal if their `start` and `end` are equal.
|
||||
@warn_unused_result
|
||||
public func == <Bound : Comparable> (
|
||||
lhs: ${Self}<Bound>, rhs: ${Self}<Bound>
|
||||
) -> Bool {
|
||||
@@ -158,6 +163,7 @@ extension ClosedInterval {
|
||||
|
||||
extension IntervalType {
|
||||
/// Returns `true` if `lhs` and `rhs` have a non-empty intersection.
|
||||
@warn_unused_result
|
||||
public func overlaps<
|
||||
I: IntervalType where I.Bound == Bound
|
||||
>(other: I) -> Bool {
|
||||
@@ -173,6 +179,7 @@ public func overlaps<
|
||||
}
|
||||
|
||||
/// Returns a half-open interval from `start` to `end`.
|
||||
@warn_unused_result
|
||||
public func ..< <Bound : Comparable>(
|
||||
start: Bound, end: Bound
|
||||
) -> HalfOpenInterval<Bound> {
|
||||
@@ -180,6 +187,7 @@ public func ..< <Bound : Comparable>(
|
||||
}
|
||||
|
||||
/// Returns a closed interval from `start` through `end`.
|
||||
@warn_unused_result
|
||||
public func ... <Bound : Comparable>(
|
||||
start: Bound, end: Bound
|
||||
) -> ClosedInterval<Bound> {
|
||||
@@ -187,6 +195,7 @@ public func ... <Bound : Comparable>(
|
||||
}
|
||||
|
||||
/// Returns `true` iff `pattern` contains `value`.
|
||||
@warn_unused_result
|
||||
public func ~= <I: IntervalType>(pattern: I, value: I.Bound) -> Bool {
|
||||
return pattern.contains(value)
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
/// output:
|
||||
///
|
||||
/// print(join(" ", [ "here", "be", "dragons" ]))
|
||||
@warn_unused_result
|
||||
public func join<
|
||||
C : RangeReplaceableCollectionType, S : SequenceType
|
||||
where S.Generator.Element == C
|
||||
|
||||
@@ -141,10 +141,12 @@ public struct Mirror {
|
||||
case Struct, Class, Enum, Tuple, Optional, Collection, Dictionary, Set
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
static func _noSuperclassMirror() -> Mirror? { return nil }
|
||||
|
||||
/// Return the legacy mirror representing the part of `subject`
|
||||
/// corresponding to the superclass of `staticSubclass`.
|
||||
@warn_unused_result
|
||||
internal static func _legacyMirror(
|
||||
subject: AnyObject, asClass targetSuperclass: AnyClass) -> _MirrorType? {
|
||||
|
||||
@@ -164,6 +166,7 @@ public struct Mirror {
|
||||
return nil
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal static func _superclassGenerator<T: Any>(
|
||||
subject: T, _ ancestorRepresentation: AncestorRepresentation
|
||||
) -> ()->Mirror? {
|
||||
@@ -330,6 +333,7 @@ public struct Mirror {
|
||||
/// Suggests a display style for the reflected subject.
|
||||
public let displayStyle: DisplayStyle?
|
||||
|
||||
@warn_unused_result
|
||||
public func superclassMirror() -> Mirror? {
|
||||
return _makeSuperclassMirror()
|
||||
}
|
||||
@@ -349,6 +353,7 @@ public protocol CustomReflectable {
|
||||
///
|
||||
/// - Note: If `Self` has value semantics, the `Mirror` should be
|
||||
/// unaffected by subsequent mutations of `self`.
|
||||
@warn_unused_result
|
||||
func customMirror() -> Mirror
|
||||
}
|
||||
|
||||
@@ -372,6 +377,7 @@ extension String : MirrorPathType {}
|
||||
extension Mirror {
|
||||
internal struct _Dummy : CustomReflectable {
|
||||
var mirror: Mirror
|
||||
@warn_unused_result
|
||||
func customMirror() -> Mirror { return mirror }
|
||||
}
|
||||
|
||||
@@ -407,6 +413,7 @@ extension Mirror {
|
||||
/// this function is suitable for exploring the structure of a
|
||||
/// `Mirror` in a REPL or playground, but don't expect it to be
|
||||
/// efficient.
|
||||
@warn_unused_result
|
||||
public func descendant(
|
||||
first: MirrorPathType, _ rest: MirrorPathType...
|
||||
) -> Any? {
|
||||
@@ -452,6 +459,7 @@ extension Mirror.DisplayStyle {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func _isClassSuperMirror(t: Any.Type) -> Bool {
|
||||
#if _runtime(_ObjC)
|
||||
return t == _ClassSuperMirror.self || t == _ObjCSuperMirror.self
|
||||
@@ -461,6 +469,7 @@ internal func _isClassSuperMirror(t: Any.Type) -> Bool {
|
||||
}
|
||||
|
||||
extension _MirrorType {
|
||||
@warn_unused_result
|
||||
internal func _superMirror() -> _MirrorType? {
|
||||
if self.count > 0 {
|
||||
let childMirror = self[0].1
|
||||
@@ -692,6 +701,7 @@ public protocol CustomPlaygroundQuickLookable {
|
||||
///
|
||||
/// - Note: If `Self` has value semantics, the `Mirror` should be
|
||||
/// unaffected by subsequent mutations of `self`.
|
||||
@warn_unused_result
|
||||
func customPlaygroundQuickLook() -> PlaygroundQuickLook
|
||||
}
|
||||
|
||||
@@ -806,6 +816,7 @@ extension Mirror : CustomStringConvertible {
|
||||
}
|
||||
|
||||
extension Mirror : CustomReflectable {
|
||||
@warn_unused_result
|
||||
public func customMirror() -> Mirror {
|
||||
return Mirror(self, children: [:])
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
// FIXME: Once we have an FFI interface, make these have proper function bodies
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _countLeadingZeros(value: Int64) -> Int64 {
|
||||
return Int64(Builtin.int_ctlz_Int64(value.value, false.value))
|
||||
@@ -22,6 +23,7 @@ func _countLeadingZeros(value: Int64) -> Int64 {
|
||||
|
||||
/// Returns if `x` is a power of 2.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _isPowerOf2(x: UInt) -> Bool {
|
||||
if x == 0 {
|
||||
@@ -34,6 +36,7 @@ func _isPowerOf2(x: UInt) -> Bool {
|
||||
|
||||
/// Returns if `x` is a power of 2.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _isPowerOf2(x: Int) -> Bool {
|
||||
if x <= 0 {
|
||||
@@ -45,7 +48,8 @@ func _isPowerOf2(x: Int) -> Bool {
|
||||
}
|
||||
|
||||
#if _runtime(_ObjC)
|
||||
@transparent public func _autorelease(x: AnyObject) {
|
||||
@transparent
|
||||
public func _autorelease(x: AnyObject) {
|
||||
Builtin.retain(x)
|
||||
Builtin.autorelease(x)
|
||||
}
|
||||
@@ -76,7 +80,9 @@ public func _stdlib_getDemangledMetatypeNameImpl(type: Any.Type, qualified: Bool
|
||||
public func _stdlib_getDemangledUnqualifiedMetatypeNameImpl(type: Any.Type, _ result: UnsafeMutablePointer<String>)
|
||||
|
||||
/// Returns the demangled qualified name of a metatype.
|
||||
public func _typeName(type: Any.Type, qualified: Bool = true) -> String {
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _typeName(type: Any.Type, qualified: Bool = true) -> String {
|
||||
let stringPtr = UnsafeMutablePointer<String>.alloc(1)
|
||||
_stdlib_getDemangledMetatypeNameImpl(type, qualified: qualified, stringPtr)
|
||||
let result = stringPtr.move()
|
||||
@@ -85,7 +91,9 @@ public func _typeName(type: Any.Type, qualified: Bool = true) -> String {
|
||||
}
|
||||
|
||||
/// Returns the human-readable type name for the given value.
|
||||
public func _stdlib_getDemangledTypeName<T>(value: T) -> String {
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _stdlib_getDemangledTypeName<T>(value: T) -> String {
|
||||
// FIXME: this code should be using _withUninitializedString, but it leaks
|
||||
// when called from here.
|
||||
// <rdar://problem/17892969> Closures in generic context leak their captures?
|
||||
@@ -96,13 +104,16 @@ public func _stdlib_getDemangledTypeName<T>(value: T) -> String {
|
||||
return stringResult
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
@asmname("swift_stdlib_demangleName")
|
||||
func _stdlib_demangleNameImpl(
|
||||
mangledName: UnsafePointer<UInt8>,
|
||||
_ mangledNameLength: UInt,
|
||||
_ demangledName: UnsafeMutablePointer<String>)
|
||||
|
||||
public func _stdlib_demangleName(mangledName: String) -> String {
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _stdlib_demangleName(mangledName: String) -> String {
|
||||
let mangledNameUTF8 = Array(mangledName.utf8)
|
||||
return mangledNameUTF8.withUnsafeBufferPointer {
|
||||
(mangledNameUTF8) in
|
||||
@@ -127,6 +138,7 @@ public func _stdlib_demangleName(mangledName: String) -> String {
|
||||
/// floorLog2(9) == floorLog2(15) == 3
|
||||
///
|
||||
/// TODO: Implement version working on Int instead of Int64.
|
||||
@warn_unused_result
|
||||
@transparent
|
||||
public // @testable
|
||||
func _floorLog2(x: Int64) -> Int {
|
||||
|
||||
@@ -57,6 +57,7 @@ public protocol OptionSetType : SetAlgebraType, RawRepresentable {
|
||||
extension OptionSetType {
|
||||
/// Returns the set of elements contained in `self`, in `other`, or in
|
||||
/// both `self` and `other`.
|
||||
@warn_unused_result
|
||||
public func union(other: Self) -> Self {
|
||||
var r: Self = Self(rawValue: self.rawValue)
|
||||
r.unionInPlace(other)
|
||||
@@ -64,6 +65,7 @@ extension OptionSetType {
|
||||
}
|
||||
|
||||
/// Returns the set of elements contained in both `self` and `other`.
|
||||
@warn_unused_result
|
||||
public func intersect(other: Self) -> Self {
|
||||
var r = Self(rawValue: self.rawValue)
|
||||
r.intersectInPlace(other)
|
||||
@@ -72,6 +74,7 @@ extension OptionSetType {
|
||||
|
||||
/// Returns the set of elements contained in `self` or in `other`,
|
||||
/// but not in both `self` and `other`.
|
||||
@warn_unused_result
|
||||
public func exclusiveOr(other: Self) -> Self {
|
||||
var r = Self(rawValue: self.rawValue)
|
||||
r.exclusiveOrInPlace(other)
|
||||
@@ -89,6 +92,7 @@ extension OptionSetType where Element == Self {
|
||||
/// Returns `true` if `self` contains `member`.
|
||||
///
|
||||
/// - Equivalent to `self.intersect([member]) == [member]`
|
||||
@warn_unused_result
|
||||
public func contains(member: Self) -> Bool {
|
||||
return self.isSupersetOf(member)
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ public enum Optional<T> : _Reflectable, NilLiteralConvertible {
|
||||
}
|
||||
|
||||
/// Returns a mirror that reflects `self`.
|
||||
@warn_unused_result
|
||||
public func _getMirror() -> _MirrorType {
|
||||
return _OptionalMirror(self)
|
||||
}
|
||||
@@ -132,6 +133,7 @@ func _injectNothingIntoOptional<T>() -> T? {
|
||||
}
|
||||
|
||||
// Comparisons
|
||||
@warn_unused_result
|
||||
public func == <T : Equatable> (lhs: T?, rhs: T?) -> Bool {
|
||||
switch (lhs,rhs) {
|
||||
case let (l?, r?):
|
||||
@@ -143,6 +145,7 @@ public func == <T : Equatable> (lhs: T?, rhs: T?) -> Bool {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func != <T : Equatable> (lhs: T?, rhs: T?) -> Bool {
|
||||
return !(lhs == rhs)
|
||||
}
|
||||
@@ -156,6 +159,7 @@ public struct _OptionalNilComparisonType : NilLiteralConvertible {
|
||||
}
|
||||
}
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func ~= <T>(lhs: _OptionalNilComparisonType, rhs: T?) -> Bool {
|
||||
switch rhs {
|
||||
case .Some(_):
|
||||
@@ -167,6 +171,7 @@ public func ~= <T>(lhs: _OptionalNilComparisonType, rhs: T?) -> Bool {
|
||||
|
||||
// Enable equality comparisons against the nil literal, even if the
|
||||
// element type isn't equatable
|
||||
@warn_unused_result
|
||||
public func == <T>(lhs: T?, rhs: _OptionalNilComparisonType) -> Bool {
|
||||
switch lhs {
|
||||
case .Some(_):
|
||||
@@ -176,6 +181,7 @@ public func == <T>(lhs: T?, rhs: _OptionalNilComparisonType) -> Bool {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func != <T>(lhs: T?, rhs: _OptionalNilComparisonType) -> Bool {
|
||||
switch lhs {
|
||||
case .Some(_):
|
||||
@@ -185,6 +191,7 @@ public func != <T>(lhs: T?, rhs: _OptionalNilComparisonType) -> Bool {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func == <T>(lhs: _OptionalNilComparisonType, rhs: T?) -> Bool {
|
||||
switch rhs {
|
||||
case .Some(_):
|
||||
@@ -194,6 +201,7 @@ public func == <T>(lhs: _OptionalNilComparisonType, rhs: T?) -> Bool {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func != <T>(lhs: _OptionalNilComparisonType, rhs: T?) -> Bool {
|
||||
switch rhs {
|
||||
case .Some(_):
|
||||
@@ -238,6 +246,7 @@ internal struct _OptionalMirror<T> : _MirrorType {
|
||||
}
|
||||
|
||||
|
||||
@warn_unused_result
|
||||
public func < <T : Comparable> (lhs: T?, rhs: T?) -> Bool {
|
||||
switch (lhs,rhs) {
|
||||
case let (l?, r?):
|
||||
@@ -249,6 +258,7 @@ public func < <T : Comparable> (lhs: T?, rhs: T?) -> Bool {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func > <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
|
||||
switch (lhs,rhs) {
|
||||
case let (l?, r?):
|
||||
@@ -258,6 +268,7 @@ public func > <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func <= <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
|
||||
switch (lhs,rhs) {
|
||||
case let (l?, r?):
|
||||
@@ -267,6 +278,7 @@ public func <= <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func >= <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
|
||||
switch (lhs,rhs) {
|
||||
case let (l?, r?):
|
||||
@@ -277,6 +289,7 @@ public func >= <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func ?? <T> (optional: T?, @autoclosure defaultValue: () throws -> T)
|
||||
rethrows -> T {
|
||||
switch optional {
|
||||
@@ -288,6 +301,7 @@ public func ?? <T> (optional: T?, @autoclosure defaultValue: () throws -> T)
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func ?? <T> (optional: T?, @autoclosure defaultValue: () throws -> T?)
|
||||
rethrows -> T? {
|
||||
switch optional {
|
||||
|
||||
@@ -23,6 +23,7 @@ public protocol _PointerType {
|
||||
|
||||
/// Derive a pointer argument from a convertible pointer type.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // COMPILER_INTRINSIC
|
||||
func _convertPointerToPointerArgument<
|
||||
FromPointer: _PointerType,
|
||||
@@ -33,6 +34,7 @@ func _convertPointerToPointerArgument<
|
||||
|
||||
/// Derive a pointer argument from the address of an inout parameter.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // COMPILER_INTRINSIC
|
||||
func _convertInOutToPointerArgument<
|
||||
ToPointer: _PointerType
|
||||
@@ -42,6 +44,7 @@ func _convertInOutToPointerArgument<
|
||||
|
||||
/// Derive a pointer argument from an inout array parameter.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // COMPILER_INTRINSIC
|
||||
func _convertMutableArrayToPointerArgument<
|
||||
FromElement,
|
||||
@@ -59,6 +62,7 @@ func _convertMutableArrayToPointerArgument<
|
||||
|
||||
/// Derive a pointer argument from a value array parameter.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // COMPILER_INTRINSIC
|
||||
func _convertConstArrayToPointerArgument<
|
||||
FromElement,
|
||||
@@ -70,6 +74,7 @@ func _convertConstArrayToPointerArgument<
|
||||
|
||||
/// Derive a UTF-8 pointer argument from a value string parameter.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // COMPILER_INTRINSIC
|
||||
func _convertConstStringToUTF8PointerArgument<
|
||||
ToPointer: _PointerType
|
||||
|
||||
@@ -142,6 +142,7 @@ public protocol AnyObject : class {}
|
||||
/// - SeeAlso: `AnyObject`
|
||||
public typealias AnyClass = AnyObject.Type
|
||||
|
||||
@warn_unused_result
|
||||
public func === (lhs: AnyObject?, rhs: AnyObject?) -> Bool {
|
||||
switch (lhs, rhs) {
|
||||
case let (l?, r?):
|
||||
@@ -156,6 +157,7 @@ public func === (lhs: AnyObject?, rhs: AnyObject?) -> Bool {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func !== (lhs: AnyObject?, rhs: AnyObject?) -> Bool {
|
||||
return !(lhs === rhs)
|
||||
}
|
||||
@@ -190,9 +192,11 @@ public protocol Equatable {
|
||||
///
|
||||
/// **Inequality is the inverse of equality**, i.e. `!(x == y)` iff
|
||||
/// `x != y`.
|
||||
@warn_unused_result
|
||||
func == (lhs: Self, rhs: Self) -> Bool
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func != <T : Equatable>(lhs: T, rhs: T) -> Bool {
|
||||
return !(lhs == rhs)
|
||||
}
|
||||
@@ -201,12 +205,17 @@ public func != <T : Equatable>(lhs: T, rhs: T) -> Bool {
|
||||
// Comparable
|
||||
//
|
||||
|
||||
@warn_unused_result
|
||||
public func > <T : Comparable>(lhs: T, rhs: T) -> Bool {
|
||||
return rhs < lhs
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func <= <T : Comparable>(lhs: T, rhs: T) -> Bool {
|
||||
return !(rhs < lhs)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func >= <T : Comparable>(lhs: T, rhs: T) -> Bool {
|
||||
return !(lhs < rhs)
|
||||
}
|
||||
@@ -232,10 +241,17 @@ public func >= <T : Comparable>(lhs: T, rhs: T) -> Bool {
|
||||
public protocol Comparable : Equatable {
|
||||
/// A [strict total order](http://en.wikipedia.org/wiki/Total_order#Strict_total_order)
|
||||
/// over instances of `Self`.
|
||||
func <(lhs: Self, rhs: Self) -> Bool
|
||||
func <=(lhs: Self, rhs: Self) -> Bool
|
||||
func >=(lhs: Self, rhs: Self) -> Bool
|
||||
func >(lhs: Self, rhs: Self) -> Bool
|
||||
@warn_unused_result
|
||||
func < (lhs: Self, rhs: Self) -> Bool
|
||||
|
||||
@warn_unused_result
|
||||
func <= (lhs: Self, rhs: Self) -> Bool
|
||||
|
||||
@warn_unused_result
|
||||
func >= (lhs: Self, rhs: Self) -> Bool
|
||||
|
||||
@warn_unused_result
|
||||
func > (lhs: Self, rhs: Self) -> Bool
|
||||
}
|
||||
|
||||
/// A set type with O(1) standard bitwise operators.
|
||||
@@ -253,22 +269,26 @@ public protocol BitwiseOperationsType {
|
||||
/// Returns the intersection of bits set in `lhs` and `rhs`.
|
||||
///
|
||||
/// - Complexity: O(1).
|
||||
@warn_unused_result
|
||||
func & (lhs: Self, rhs: Self) -> Self
|
||||
|
||||
/// Returns the union of bits set in `lhs` and `rhs`.
|
||||
///
|
||||
/// - Complexity: O(1).
|
||||
func |(lhs: Self, rhs: Self) -> Self
|
||||
@warn_unused_result
|
||||
func | (lhs: Self, rhs: Self) -> Self
|
||||
|
||||
/// Returns the bits that are set in exactly one of `lhs` and `rhs`.
|
||||
///
|
||||
/// - Complexity: O(1).
|
||||
func ^(lhs: Self, rhs: Self) -> Self
|
||||
@warn_unused_result
|
||||
func ^ (lhs: Self, rhs: Self) -> Self
|
||||
|
||||
/// Returns `x ^ ~Self.allZeros`.
|
||||
///
|
||||
/// - Complexity: O(1).
|
||||
prefix func ~(x: Self) -> Self
|
||||
@warn_unused_result
|
||||
prefix func ~ (x: Self) -> Self
|
||||
|
||||
/// The empty bitset.
|
||||
///
|
||||
@@ -278,14 +298,17 @@ public protocol BitwiseOperationsType {
|
||||
static var allZeros: Self { get }
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func |= <T : BitwiseOperationsType>(inout lhs: T, rhs: T) {
|
||||
lhs = lhs | rhs
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func &= <T : BitwiseOperationsType>(inout lhs: T, rhs: T) {
|
||||
lhs = lhs & rhs
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func ^= <T : BitwiseOperationsType>(inout lhs: T, rhs: T) {
|
||||
lhs = lhs ^ rhs
|
||||
}
|
||||
@@ -313,6 +336,7 @@ public typealias SinkType = _SinkType
|
||||
|
||||
// Equatable types can be matched in patterns by value equality.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func ~= <T : Equatable> (a: T, b: T) -> Bool {
|
||||
return a == b
|
||||
}
|
||||
|
||||
@@ -147,7 +147,8 @@ public struct Range<
|
||||
}
|
||||
}
|
||||
|
||||
public func ==<Element>(lhs: Range<Element>, rhs: Range<Element>) -> Bool {
|
||||
@warn_unused_result
|
||||
public func == <Element>(lhs: Range<Element>, rhs: Range<Element>) -> Bool {
|
||||
return lhs.startIndex == rhs.startIndex &&
|
||||
lhs.endIndex == rhs.endIndex
|
||||
}
|
||||
@@ -155,6 +156,7 @@ public func ==<Element>(lhs: Range<Element>, rhs: Range<Element>) -> Bool {
|
||||
/// Forms a half-open range that contains `minimum`, but not
|
||||
/// `maximum`.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func ..< <Pos : ForwardIndexType> (minimum: Pos, maximum: Pos)
|
||||
-> Range<Pos> {
|
||||
return Range(start: minimum, end: maximum)
|
||||
@@ -162,6 +164,7 @@ public func ..< <Pos : ForwardIndexType> (minimum: Pos, maximum: Pos)
|
||||
|
||||
/// Forms a closed range that contains both `minimum` and `maximum`.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func ... <Pos : ForwardIndexType> (
|
||||
minimum: Pos, maximum: Pos
|
||||
) -> Range<Pos> {
|
||||
@@ -174,6 +177,7 @@ public func ... <Pos : ForwardIndexType> (
|
||||
///
|
||||
/// - Requires: `start <= end`.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func ..< <Pos : ForwardIndexType where Pos : Comparable> (
|
||||
start: Pos, end: Pos
|
||||
) -> Range<Pos> {
|
||||
@@ -184,6 +188,7 @@ public func ..< <Pos : ForwardIndexType where Pos : Comparable> (
|
||||
/// Forms a closed range that contains both `start` and `end`.
|
||||
/// - Requires: `start <= end`.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func ... <Pos : ForwardIndexType where Pos : Comparable> (
|
||||
start: Pos, end: Pos
|
||||
) -> Range<Pos> {
|
||||
@@ -192,6 +197,7 @@ public func ... <Pos : ForwardIndexType where Pos : Comparable> (
|
||||
return Range(start: start, end: end.successor())
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func ~= <I : ForwardIndexType where I : Comparable> (
|
||||
pattern: Range<I>, value: I
|
||||
) -> Bool {
|
||||
|
||||
@@ -124,6 +124,7 @@ public protocol RangeReplaceableCollectionType : CollectionType {
|
||||
/// - Complexity: O(`self.count`).
|
||||
mutating func removeAtIndex(i: Index) -> Generator.Element
|
||||
|
||||
@warn_unused_result
|
||||
mutating func _customRemoveLast() -> Generator.Element?
|
||||
|
||||
/// Remove the element at `startIndex` and return it.
|
||||
@@ -226,6 +227,7 @@ extension RangeReplaceableCollectionType {
|
||||
}
|
||||
|
||||
extension RangeReplaceableCollectionType {
|
||||
@warn_unused_result
|
||||
public mutating func _customRemoveLast() -> Generator.Element? {
|
||||
return nil
|
||||
}
|
||||
@@ -348,6 +350,7 @@ public func removeLast<
|
||||
fatalError("unavailable function can't be called")
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func +<
|
||||
C : RangeReplaceableCollectionType,
|
||||
S : SequenceType
|
||||
@@ -358,6 +361,7 @@ public func +<
|
||||
return lhs
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func +<
|
||||
C : RangeReplaceableCollectionType,
|
||||
S : SequenceType
|
||||
@@ -370,6 +374,7 @@ public func +<
|
||||
return result
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func +<
|
||||
C : RangeReplaceableCollectionType,
|
||||
S : CollectionType
|
||||
@@ -381,6 +386,7 @@ public func +<
|
||||
return lhs
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func +<
|
||||
RRC1 : RangeReplaceableCollectionType,
|
||||
RRC2 : RangeReplaceableCollectionType
|
||||
|
||||
@@ -18,6 +18,7 @@ public protocol _Reflectable {
|
||||
// corresponding change to Reflection.cpp.
|
||||
|
||||
/// Returns a mirror that reflects `self`.
|
||||
@warn_unused_result
|
||||
func _getMirror() -> _MirrorType
|
||||
}
|
||||
|
||||
@@ -59,10 +60,12 @@ public struct ObjectIdentifier : Hashable, Comparable {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func <(lhs: ObjectIdentifier, rhs: ObjectIdentifier) -> Bool {
|
||||
return lhs.uintValue < rhs.uintValue
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func ==(x: ObjectIdentifier, y: ObjectIdentifier) -> Bool {
|
||||
return Bool(Builtin.cmp_eq_RawPointer(x.value, y.value))
|
||||
}
|
||||
@@ -126,6 +129,7 @@ public protocol _MirrorType {
|
||||
/// An entry point that can be called from C++ code to get the summary string
|
||||
/// for an arbitrary object. The memory pointed to by "out" is initialized with
|
||||
/// the summary string.
|
||||
@warn_unused_result
|
||||
@asmname("swift_getSummary")
|
||||
public // COMPILER_INTRINSIC
|
||||
func _getSummary<T>(out: UnsafeMutablePointer<String>, x: T) {
|
||||
@@ -136,6 +140,7 @@ func _getSummary<T>(out: UnsafeMutablePointer<String>, x: T) {
|
||||
/// `_Reflectable`, invoke its `_getMirror()` method; otherwise, fall back
|
||||
/// to an implementation in the runtime that structurally reflects values
|
||||
/// of any type.
|
||||
@warn_unused_result
|
||||
@asmname("swift_reflectAny")
|
||||
public func _reflect<T>(x: T) -> _MirrorType
|
||||
|
||||
@@ -143,6 +148,7 @@ public func _reflect<T>(x: T) -> _MirrorType
|
||||
/// guaranteed by holding a strong reference to a heap object.
|
||||
/// This lets containers with heap storage vend mirrors for their elements
|
||||
/// without unnecessary copying of the underlying value.
|
||||
@warn_unused_result
|
||||
@asmname("swift_unsafeReflectAny")
|
||||
internal func _unsafeReflect<T>(
|
||||
owner: Builtin.NativeObject,
|
||||
@@ -376,14 +382,20 @@ struct _EnumMirror : _MirrorType {
|
||||
var disposition: _MirrorDisposition { return .Enum }
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
@asmname("swift_ClassMirror_count")
|
||||
func _getClassCount(_: _MagicMirrorData) -> Int
|
||||
|
||||
@warn_unused_result
|
||||
@asmname("swift_ClassMirror_subscript")
|
||||
func _getClassChild(_: Int, _: _MagicMirrorData) -> (String, _MirrorType)
|
||||
|
||||
#if _runtime(_ObjC)
|
||||
@asmname("swift_ClassMirror_quickLookObject")public
|
||||
func _getClassPlaygroundQuickLook(data: _MagicMirrorData) -> PlaygroundQuickLook?
|
||||
@warn_unused_result
|
||||
@asmname("swift_ClassMirror_quickLookObject")
|
||||
public func _getClassPlaygroundQuickLook(
|
||||
data: _MagicMirrorData
|
||||
) -> PlaygroundQuickLook?
|
||||
#endif
|
||||
|
||||
struct _ClassMirror : _MirrorType {
|
||||
|
||||
@@ -66,6 +66,7 @@ public struct ReverseIndex<Base: BidirectionalIndexType>
|
||||
public typealias I = Base
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func == <Base> (
|
||||
lhs: ReverseIndex<Base>, rhs: ReverseIndex<Base>
|
||||
) -> Bool {
|
||||
@@ -207,6 +208,7 @@ extension CollectionType where Index : BidirectionalIndexType {
|
||||
/// Return the elements of `self` in reverse order.
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@warn_unused_result
|
||||
public func reverse() -> ReverseCollection<Self> {
|
||||
return ReverseCollection(self)
|
||||
}
|
||||
@@ -216,6 +218,7 @@ extension CollectionType where Index : RandomAccessIndexType {
|
||||
/// Return the elements of `self` in reverse order.
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@warn_unused_result
|
||||
public func reverse() -> ReverseRandomAccessCollection<Self> {
|
||||
return ReverseRandomAccessCollection(self)
|
||||
}
|
||||
@@ -226,6 +229,7 @@ where Index : BidirectionalIndexType, Elements.Index : BidirectionalIndexType {
|
||||
/// Return the elements of `self` in reverse order.
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@warn_unused_result
|
||||
public func reverse() -> LazyCollection<
|
||||
ReverseCollection<Elements>
|
||||
> {
|
||||
@@ -238,6 +242,7 @@ where Index : RandomAccessIndexType, Elements.Index : RandomAccessIndexType {
|
||||
/// Return the elements of `self` in reverse order.
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@warn_unused_result
|
||||
public func reverse() -> LazyCollection<
|
||||
ReverseRandomAccessCollection<Elements>
|
||||
> {
|
||||
|
||||
@@ -20,6 +20,7 @@ import SwiftShims
|
||||
// Atomics
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@warn_unused_result
|
||||
@asmname("swift_stdlib_atomicCompareExchangeStrongPtr")
|
||||
func _stdlib_atomicCompareExchangeStrongPtrImpl(
|
||||
object target: UnsafeMutablePointer<COpaquePointer>,
|
||||
@@ -54,6 +55,7 @@ func _stdlib_atomicCompareExchangeStrongPtrImpl(
|
||||
/// compare-and-exchange instruction will operate on the writeback buffer, and
|
||||
/// you will get a *race* while doing writeback into shared memory.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _stdlib_atomicCompareExchangeStrongPtr<T>(
|
||||
object target: UnsafeMutablePointer<UnsafeMutablePointer<T>>,
|
||||
@@ -66,6 +68,7 @@ func _stdlib_atomicCompareExchangeStrongPtr<T>(
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _stdlib_atomicInitializeARCRef(
|
||||
object target: UnsafeMutablePointer<AnyObject?>,
|
||||
@@ -86,12 +89,14 @@ func _stdlib_atomicInitializeARCRef(
|
||||
|
||||
% for bits in [ 32, 64 ]:
|
||||
|
||||
@warn_unused_result
|
||||
@asmname("swift_stdlib_atomicCompareExchangeStrongUInt${bits}")
|
||||
func _stdlib_atomicCompareExchangeStrongUInt${bits}(
|
||||
object target: UnsafeMutablePointer<UInt${bits}>,
|
||||
expected: UnsafeMutablePointer<UInt${bits}>,
|
||||
desired: UInt${bits}) -> Bool
|
||||
|
||||
@warn_unused_result
|
||||
func _stdlib_atomicCompareExchangeStrongInt${bits}(
|
||||
object target: UnsafeMutablePointer<Int${bits}>,
|
||||
expected: UnsafeMutablePointer<Int${bits}>,
|
||||
@@ -115,10 +120,12 @@ func _swift_stdlib_atomicStoreInt${bits}(
|
||||
desired: UInt${bits}(bitPattern: desired))
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
@asmname("swift_stdlib_atomicLoadUInt${bits}")
|
||||
func _swift_stdlib_atomicLoadUInt${bits}(
|
||||
object target: UnsafeMutablePointer<UInt${bits}>) -> UInt${bits}
|
||||
|
||||
@warn_unused_result
|
||||
func _swift_stdlib_atomicLoadInt${bits}(
|
||||
object target: UnsafeMutablePointer<Int${bits}>) -> Int${bits} {
|
||||
return Int${bits}(bitPattern:
|
||||
@@ -128,12 +135,14 @@ func _swift_stdlib_atomicLoadInt${bits}(
|
||||
|
||||
% for operation in [ 'Add', 'And', 'Or', 'Xor' ]:
|
||||
// Warning: no overflow checking.
|
||||
@warn_unused_result
|
||||
@asmname("swift_stdlib_atomicFetch${operation}UInt${bits}")
|
||||
func _swift_stdlib_atomicFetch${operation}UInt${bits}(
|
||||
object target: UnsafeMutablePointer<UInt${bits}>,
|
||||
operand: UInt${bits}) -> UInt${bits}
|
||||
|
||||
// Warning: no overflow checking.
|
||||
@warn_unused_result
|
||||
func _swift_stdlib_atomicFetch${operation}Int${bits}(
|
||||
object target: UnsafeMutablePointer<Int${bits}>,
|
||||
operand: Int${bits}) -> Int${bits} {
|
||||
@@ -146,6 +155,7 @@ func _swift_stdlib_atomicFetch${operation}Int${bits}(
|
||||
|
||||
% end
|
||||
|
||||
@warn_unused_result
|
||||
func _stdlib_atomicCompareExchangeStrongInt(
|
||||
object target: UnsafeMutablePointer<Int>,
|
||||
expected: UnsafeMutablePointer<Int>,
|
||||
@@ -178,6 +188,7 @@ func _swift_stdlib_atomicStoreInt(
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func _swift_stdlib_atomicLoadInt(
|
||||
object target: UnsafeMutablePointer<Int>) -> Int {
|
||||
#if arch(i386) || arch(arm)
|
||||
@@ -191,12 +202,14 @@ public func _swift_stdlib_atomicLoadInt(
|
||||
#endif
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
@asmname("swift_stdlib_atomicLoadPtr")
|
||||
func _swift_stdlib_atomicLoadPtrImpl(
|
||||
object target: UnsafeMutablePointer<COpaquePointer>
|
||||
) -> COpaquePointer
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _stdlib_atomicLoadARCRef(
|
||||
object target: UnsafeMutablePointer<AnyObject?>
|
||||
@@ -211,6 +224,7 @@ func _stdlib_atomicLoadARCRef(
|
||||
|
||||
% for operation in [ 'Add', 'And', 'Or', 'Xor' ]:
|
||||
// Warning: no overflow checking.
|
||||
@warn_unused_result
|
||||
public func _swift_stdlib_atomicFetch${operation}Int(
|
||||
object target: UnsafeMutablePointer<Int>,
|
||||
operand: Int) -> Int {
|
||||
@@ -243,22 +257,26 @@ public final class _stdlib_AtomicInt {
|
||||
return _swift_stdlib_atomicStoreInt(object: _valuePtr, desired: desired)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func load() -> Int {
|
||||
return _swift_stdlib_atomicLoadInt(object: _valuePtr)
|
||||
}
|
||||
|
||||
% for operation_name, operation in [ ('Add', '+'), ('And', '&'), ('Or', '|'), ('Xor', '^') ]:
|
||||
@warn_unused_result
|
||||
public func fetchAnd${operation_name}(operand: Int) -> Int {
|
||||
return _swift_stdlib_atomicFetch${operation_name}Int(
|
||||
object: _valuePtr,
|
||||
operand: operand)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func ${operation_name.lower()}AndFetch(operand: Int) -> Int {
|
||||
return fetchAnd${operation_name}(operand) ${operation} operand
|
||||
}
|
||||
% end
|
||||
|
||||
@warn_unused_result
|
||||
public func compareExchange(
|
||||
inout expected expected: Int, desired: Int
|
||||
) -> Bool {
|
||||
@@ -303,12 +321,14 @@ struct _Buffer72 {
|
||||
#if arch(i386) || arch(x86_64)
|
||||
% end
|
||||
|
||||
@warn_unused_result
|
||||
@asmname("swift_float${bits}ToString")
|
||||
func _float${bits}ToStringImpl(
|
||||
buffer: UnsafeMutablePointer<UTF8.CodeUnit>,
|
||||
_ bufferLength: UInt, _ value: Float${bits}
|
||||
) -> UInt
|
||||
|
||||
@warn_unused_result
|
||||
func _float${bits}ToString(value: Float${bits}) -> String {
|
||||
_sanityCheck(sizeof(_Buffer32.self) == 32)
|
||||
_sanityCheck(sizeof(_Buffer72.self) == 72)
|
||||
@@ -331,6 +351,7 @@ func _float${bits}ToString(value: Float${bits}) -> String {
|
||||
|
||||
% end
|
||||
|
||||
@warn_unused_result
|
||||
@asmname("swift_int64ToString")
|
||||
func _int64ToStringImpl(
|
||||
buffer: UnsafeMutablePointer<UTF8.CodeUnit>,
|
||||
@@ -338,6 +359,7 @@ func _int64ToStringImpl(
|
||||
_ radix: Int64, _ uppercase: Bool
|
||||
) -> UInt
|
||||
|
||||
@warn_unused_result
|
||||
func _int64ToString(
|
||||
value: Int64, radix: Int64 = 10, uppercase: Bool = false
|
||||
) -> String {
|
||||
@@ -368,12 +390,14 @@ func _int64ToString(
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
@asmname("swift_uint64ToString")
|
||||
func _uint64ToStringImpl(
|
||||
buffer: UnsafeMutablePointer<UTF8.CodeUnit>,
|
||||
_ bufferLength: UInt, _ value: UInt64, _ radix: Int64, _ uppercase: Bool
|
||||
) -> UInt
|
||||
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _uint64ToString(
|
||||
value: UInt64, radix: Int64 = 10, uppercase: Bool = false
|
||||
@@ -405,6 +429,7 @@ func _uint64ToString(
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
func _rawPointerToString(value: Builtin.RawPointer) -> String {
|
||||
var result = _uint64ToString(
|
||||
UInt64(unsafeBitCast(value, UInt.self)), radix: 16, uppercase: false)
|
||||
|
||||
@@ -34,6 +34,7 @@ public protocol GeneratorType {
|
||||
/// has returned `nil`. Specific implementations of this protocol
|
||||
/// are encouraged to respond to violations of this requirement by
|
||||
/// calling `preconditionFailure("...")`.
|
||||
@warn_unused_result
|
||||
mutating func next() -> Element?
|
||||
}
|
||||
|
||||
@@ -76,24 +77,28 @@ public protocol SequenceType {
|
||||
/// Return a *generator* over the elements of this *sequence*.
|
||||
///
|
||||
/// - Complexity: O(1).
|
||||
@warn_unused_result
|
||||
func generate() -> Generator
|
||||
|
||||
/// Return a value less than or equal to the number of elements in
|
||||
/// `self`, **nondestructively**.
|
||||
///
|
||||
/// - Complexity: O(N).
|
||||
@warn_unused_result
|
||||
func underestimateCount() -> Int
|
||||
|
||||
/// Return an `Array` containing the results of mapping `transform`
|
||||
/// over `self`.
|
||||
///
|
||||
/// - Complexity: O(N).
|
||||
@warn_unused_result
|
||||
func map<T>(
|
||||
@noescape transform: (Generator.Element) throws -> T
|
||||
) rethrows -> [T]
|
||||
|
||||
/// Return an `Array` containing the elements of `self`,
|
||||
/// in order, that satisfy the predicate `includeElement`.
|
||||
@warn_unused_result
|
||||
func filter(
|
||||
@noescape includeElement: (Generator.Element) throws -> Bool
|
||||
) rethrows -> [Generator.Element]
|
||||
@@ -124,6 +129,7 @@ public protocol SequenceType {
|
||||
///
|
||||
/// - Requires: `n >= 0`
|
||||
/// - Complexity: O(`n`)
|
||||
@warn_unused_result
|
||||
func dropFirst(n: Int) -> SubSequence
|
||||
|
||||
/// Returns a subsequence containing all but the last `n` elements.
|
||||
@@ -131,6 +137,7 @@ public protocol SequenceType {
|
||||
/// - Requires: `self` is a finite sequence.
|
||||
/// - Requires: `n >= 0`
|
||||
/// - Complexity: O(`self.count`)
|
||||
@warn_unused_result
|
||||
func dropLast(n: Int) -> SubSequence
|
||||
|
||||
/// Returns a subsequence, up to `maxLength` in length, containing the
|
||||
@@ -140,6 +147,7 @@ public protocol SequenceType {
|
||||
/// the elements of `self`.
|
||||
///
|
||||
/// - Requires: `maxLength >= 0`
|
||||
@warn_unused_result
|
||||
func prefix(maxLength: Int) -> SubSequence
|
||||
|
||||
/// Returns a slice, up to `maxLength` in length, containing the
|
||||
@@ -150,6 +158,7 @@ public protocol SequenceType {
|
||||
///
|
||||
/// - Requires: `self` is a finite sequence.
|
||||
/// - Requires: `maxLength >= 0`
|
||||
@warn_unused_result
|
||||
func suffix(maxLength: Int) -> SubSequence
|
||||
|
||||
/// Returns the maximal `SubSequence`s of `self`, in order, that
|
||||
@@ -167,10 +176,12 @@ public protocol SequenceType {
|
||||
/// The default value is `false`.
|
||||
///
|
||||
/// - Requires: `maxSplit >= 0`
|
||||
@warn_unused_result
|
||||
func split(maxSplit: Int, allowEmptySlices: Bool,
|
||||
@noescape isSeparator: (Generator.Element) throws -> Bool
|
||||
) rethrows -> [SubSequence]
|
||||
|
||||
@warn_unused_result
|
||||
func _customContainsEquatableElement(
|
||||
element: Generator.Element
|
||||
) -> Bool?
|
||||
@@ -345,6 +356,7 @@ extension SequenceType {
|
||||
///
|
||||
/// - Requires: `n >= 0`
|
||||
/// - Complexity: O(`n`)
|
||||
@warn_unused_result
|
||||
public func dropFirst(n: Int) -> AnySequence<Generator.Element> {
|
||||
_precondition(n >= 0, "Can't drop a negative number of elements from a sequence")
|
||||
if n == 0 { return AnySequence(self) }
|
||||
@@ -371,6 +383,7 @@ extension SequenceType {
|
||||
/// - Requires: `self` is a finite collection.
|
||||
/// - Requires: `n >= 0`
|
||||
/// - Complexity: O(`self.count`)
|
||||
@warn_unused_result
|
||||
public func dropLast(n: Int) -> AnySequence<Generator.Element> {
|
||||
_precondition(n >= 0, "Can't drop a negative number of elements from a sequence")
|
||||
if n == 0 { return AnySequence(self) }
|
||||
@@ -396,6 +409,7 @@ extension SequenceType {
|
||||
return AnySequence(result)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func prefix(maxLength: Int) -> AnySequence<Generator.Element> {
|
||||
_precondition(maxLength >= 0, "Can't take a prefix of negative length from a sequence")
|
||||
if maxLength == 0 {
|
||||
@@ -415,6 +429,7 @@ extension SequenceType {
|
||||
return AnySequence(_PrefixSequence(generate(), maxLength: maxLength))
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func suffix(maxLength: Int) -> AnySequence<Generator.Element> {
|
||||
_precondition(maxLength >= 0, "Can't take a suffix of negative length from a sequence")
|
||||
if maxLength == 0 { return AnySequence([]) }
|
||||
@@ -459,6 +474,7 @@ extension SequenceType {
|
||||
/// The default value is `false`.
|
||||
///
|
||||
/// - Requires: `maxSplit >= 0`
|
||||
@warn_unused_result
|
||||
public func split(
|
||||
maxSplit: Int = Int.max,
|
||||
allowEmptySlices: Bool = false,
|
||||
@@ -497,6 +513,7 @@ extension SequenceType {
|
||||
/// `self`, **nondestructively**.
|
||||
///
|
||||
/// - Complexity: O(N).
|
||||
@warn_unused_result
|
||||
public func underestimateCount() -> Int {
|
||||
return 0
|
||||
}
|
||||
@@ -505,6 +522,7 @@ extension SequenceType {
|
||||
return nil
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func _customContainsEquatableElement(
|
||||
element: Generator.Element
|
||||
) -> Bool? {
|
||||
@@ -558,6 +576,7 @@ extension SequenceType where Generator.Element : Equatable {
|
||||
/// The default value is `false`.
|
||||
///
|
||||
/// - Requires: `maxSplit >= 0`
|
||||
@warn_unused_result
|
||||
public func split(
|
||||
separator: Generator.Element,
|
||||
maxSplit: Int = Int.max,
|
||||
@@ -573,6 +592,7 @@ extension SequenceType {
|
||||
///
|
||||
/// - Requires: `n >= 0`
|
||||
/// - Complexity: O(`n`)
|
||||
@warn_unused_result
|
||||
public func dropFirst() -> SubSequence { return dropFirst(1) }
|
||||
|
||||
/// Returns a subsequence containing all but the last element.
|
||||
@@ -580,6 +600,7 @@ extension SequenceType {
|
||||
/// - Requires: `self` is a finite sequence.
|
||||
/// - Requires: `n >= 0`
|
||||
/// - Complexity: O(`self.count`)
|
||||
@warn_unused_result
|
||||
public func dropLast() -> SubSequence { return dropLast(1) }
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ extension SequenceType {
|
||||
/// 2: 'i'
|
||||
/// 3: 'f'
|
||||
/// 4: 't'
|
||||
@warn_unused_result
|
||||
public func enumerate() -> EnumerateSequence<Self> {
|
||||
return EnumerateSequence(self)
|
||||
}
|
||||
@@ -67,6 +68,7 @@ extension SequenceType ${"" if preds else "where Generator.Element : Comparable"
|
||||
/// - Complexity: O(`elements.count`).
|
||||
///
|
||||
/// ${orderingRequirement}
|
||||
@warn_unused_result
|
||||
public func minElement(
|
||||
% if preds:
|
||||
@noescape isOrderedBefore: (${GElement}, ${GElement}) throws -> Bool
|
||||
@@ -88,6 +90,7 @@ extension SequenceType ${"" if preds else "where Generator.Element : Comparable"
|
||||
///
|
||||
/// - Complexity: O(`elements.count`).
|
||||
/// ${orderingRequirement}
|
||||
@warn_unused_result
|
||||
public func maxElement(
|
||||
% if preds:
|
||||
@noescape isOrderedBefore: (${GElement}, ${GElement}) throws -> Bool
|
||||
@@ -136,6 +139,7 @@ else:
|
||||
rethrows_ = ""
|
||||
}%
|
||||
${comment}
|
||||
@warn_unused_result
|
||||
public func startsWith<
|
||||
OtherSequence : SequenceType where OtherSequence.${GElement} == ${GElement}
|
||||
>(
|
||||
@@ -188,6 +192,7 @@ else:
|
||||
}%
|
||||
|
||||
${comment}
|
||||
@warn_unused_result
|
||||
public func elementsEqual<
|
||||
OtherSequence : SequenceType where OtherSequence.${GElement} == ${GElement}
|
||||
>(
|
||||
@@ -254,6 +259,7 @@ else:
|
||||
}%
|
||||
|
||||
${comment}
|
||||
@warn_unused_result
|
||||
public func lexicographicalCompare<
|
||||
OtherSequence : SequenceType where OtherSequence.${GElement} == ${GElement}
|
||||
>(
|
||||
@@ -290,7 +296,8 @@ else:
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
extension SequenceType where Generator.Element : Equatable {
|
||||
/// Return `true` iff `x` is in `self`.
|
||||
/// Return `true` iff `element` is in `self`.
|
||||
@warn_unused_result
|
||||
public func contains(element: ${GElement}) -> Bool {
|
||||
if let result = _customContainsEquatableElement(element) {
|
||||
return result
|
||||
@@ -307,6 +314,7 @@ extension SequenceType where Generator.Element : Equatable {
|
||||
|
||||
extension SequenceType {
|
||||
/// Return `true` iff an element in `self` satisfies `predicate`.
|
||||
@warn_unused_result
|
||||
public func contains(
|
||||
@noescape predicate: (${GElement}) throws -> Bool
|
||||
) rethrows -> Bool {
|
||||
@@ -329,6 +337,7 @@ extension SequenceType {
|
||||
/// `self`, in turn, i.e. return
|
||||
/// `combine(combine(...combine(combine(initial, self[0]),
|
||||
/// self[1]),...self[count-2]), self[count-1])`.
|
||||
@warn_unused_result
|
||||
public func reduce<T>(
|
||||
initial: T, @noescape combine: (T, ${GElement}) throws -> T
|
||||
) rethrows -> T {
|
||||
@@ -349,6 +358,7 @@ extension SequenceType {
|
||||
/// order.
|
||||
///
|
||||
/// Complexity: O(N), where N is the length of `self`.
|
||||
@warn_unused_result
|
||||
public func reverse() -> [${GElement}] {
|
||||
// FIXME(performance): optimize to 1 pass? But Array(self) can be
|
||||
// optimized to a memcpy() sometimes. Those cases are usually collections,
|
||||
|
||||
@@ -58,17 +58,21 @@ public protocol SetAlgebraType : Equatable, ArrayLiteralConvertible {
|
||||
/// Returns `true` if `self` contains `member`.
|
||||
///
|
||||
/// - Equivalent to `self.intersect([member]) == [member]`
|
||||
@warn_unused_result
|
||||
func contains(member: Element) -> Bool
|
||||
|
||||
/// Returns the set of elements contained in `self`, in `other`, or in
|
||||
/// both `self` and `other`.
|
||||
@warn_unused_result
|
||||
func union(other: Self) -> Self
|
||||
|
||||
/// Returns the set of elements contained in both `self` and `other`.
|
||||
@warn_unused_result
|
||||
func intersect(other: Self) -> Self
|
||||
|
||||
/// Returns the set of elements contained in `self` or in `other`,
|
||||
/// but not in both `self` and `other`.
|
||||
@warn_unused_result
|
||||
func exclusiveOr(other: Self) -> Self
|
||||
|
||||
/// If `member` is not already contained in `self`, inserts it.
|
||||
@@ -105,13 +109,21 @@ public protocol SetAlgebraType : Equatable, ArrayLiteralConvertible {
|
||||
|
||||
//===--- Requirements with default implementations ----------------------===//
|
||||
/// Return true iff `self.intersect(other).isEmpty`.
|
||||
@warn_unused_result
|
||||
func subtract(other: Self) -> Self
|
||||
|
||||
/// Return true iff every element of `self` is contained in `other`.
|
||||
@warn_unused_result
|
||||
func isSubsetOf(other: Self) -> Bool
|
||||
|
||||
/// Return true iff `self.intersect(other).isEmpty`.
|
||||
@warn_unused_result
|
||||
func isDisjointWith(other: Self) -> Bool
|
||||
|
||||
/// Return true iff every element of `other` is contained in `self`.
|
||||
@warn_unused_result
|
||||
func isSupersetOf(other: Self) -> Bool
|
||||
|
||||
/// Return true iff `self.contains(e)` is `false` for all `e`.
|
||||
var isEmpty: Bool { get }
|
||||
|
||||
@@ -126,6 +138,7 @@ public protocol SetAlgebraType : Equatable, ArrayLiteralConvertible {
|
||||
/// Returns `true` iff `a` subsumes `b`.
|
||||
///
|
||||
/// - Equivalent to `([a] as Self).isSupersetOf([b])`
|
||||
@warn_unused_result
|
||||
static func element(a: Element, subsumes b: Element) -> Bool
|
||||
|
||||
/// Returns `true` iff `a` is disjoint with `b`.
|
||||
@@ -133,6 +146,7 @@ public protocol SetAlgebraType : Equatable, ArrayLiteralConvertible {
|
||||
/// Two elements are disjoint when neither one subsumes the other.
|
||||
///
|
||||
/// - SeeAlso: `Self.element(_, subsumes:_)`
|
||||
@warn_unused_result
|
||||
static func element(a: Element, isDisjointWith b: Element) -> Bool
|
||||
|
||||
}
|
||||
@@ -169,21 +183,25 @@ extension SetAlgebraType {
|
||||
}
|
||||
|
||||
/// Returns true iff every element of `self` is contained in `other`.
|
||||
@warn_unused_result
|
||||
public func isSubsetOf(other: Self) -> Bool {
|
||||
return self.intersect(other) == self
|
||||
}
|
||||
|
||||
/// Returns true iff every element of `other` is contained in `self`.
|
||||
@warn_unused_result
|
||||
public func isSupersetOf(other: Self) -> Bool {
|
||||
return other.isSubsetOf(self)
|
||||
}
|
||||
|
||||
/// Returns true iff `self.intersect(other).isEmpty`.
|
||||
@warn_unused_result
|
||||
public func isDisjointWith(other: Self) -> Bool {
|
||||
return self.intersect(other).isEmpty
|
||||
}
|
||||
|
||||
/// Returns true iff `self.intersect(other).isEmpty`.
|
||||
@warn_unused_result
|
||||
public func subtract(other: Self) -> Self {
|
||||
return self.intersect(self.exclusiveOr(other))
|
||||
}
|
||||
@@ -195,12 +213,14 @@ extension SetAlgebraType {
|
||||
|
||||
/// Returns true iff every element of `other` is contained in `self`
|
||||
/// and `self` contains an element that is not contained in `other`.
|
||||
@warn_unused_result
|
||||
public func isStrictSupersetOf(other: Self) -> Bool {
|
||||
return self.isSupersetOf(other) && self != other
|
||||
}
|
||||
|
||||
/// Return true iff every element of `self` is contained in `other`
|
||||
/// and `other` contains an element that is not contained in `self`.
|
||||
@warn_unused_result
|
||||
public func isStrictSubsetOf(other: Self) -> Bool {
|
||||
return other.isStrictSupersetOf(self)
|
||||
}
|
||||
@@ -208,6 +228,7 @@ extension SetAlgebraType {
|
||||
/// Returns `true` iff `a` subsumes `b`.
|
||||
///
|
||||
/// - Equivalent to `([a] as Self).isSupersetOf([b])`
|
||||
@warn_unused_result
|
||||
public static func element(a: Element, subsumes b: Element) -> Bool {
|
||||
return ([a] as Self).isSupersetOf([b])
|
||||
}
|
||||
@@ -217,6 +238,7 @@ extension SetAlgebraType {
|
||||
/// Two elements are disjoint when neither one subsumes the other.
|
||||
///
|
||||
/// - SeeAlso: `Self.element(_, subsumes:_)`
|
||||
@warn_unused_result
|
||||
public static func element(a: Element, isDisjointWith b: Element) -> Bool {
|
||||
return ([a] as Self).isDisjointWith([b])
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#if _runtime(_ObjC)
|
||||
import SwiftShims
|
||||
|
||||
@warn_unused_result
|
||||
internal func _makeSwiftNSFastEnumerationState()
|
||||
-> _SwiftNSFastEnumerationState {
|
||||
return _SwiftNSFastEnumerationState(
|
||||
|
||||
@@ -129,8 +129,8 @@ struct _SliceBuffer<Element> : _ArrayBufferType {
|
||||
|
||||
//===--- Non-essential bits ---------------------------------------------===//
|
||||
|
||||
public
|
||||
mutating func requestUniqueMutableBackingBuffer(minimumCapacity: Int)
|
||||
@warn_unused_result
|
||||
public mutating func requestUniqueMutableBackingBuffer(minimumCapacity: Int)
|
||||
-> NativeBuffer?
|
||||
{
|
||||
_invariantCheck()
|
||||
@@ -159,21 +159,21 @@ struct _SliceBuffer<Element> : _ArrayBufferType {
|
||||
return nil
|
||||
}
|
||||
|
||||
public
|
||||
mutating func isMutableAndUniquelyReferenced() -> Bool {
|
||||
@warn_unused_result
|
||||
public mutating func isMutableAndUniquelyReferenced() -> Bool {
|
||||
return _hasNativeBuffer && isUniquelyReferenced()
|
||||
}
|
||||
|
||||
public
|
||||
mutating func isMutableAndUniquelyReferencedOrPinned() -> Bool {
|
||||
@warn_unused_result
|
||||
public mutating func isMutableAndUniquelyReferencedOrPinned() -> Bool {
|
||||
return _hasNativeBuffer && isUniquelyReferencedOrPinned()
|
||||
}
|
||||
|
||||
/// If this buffer is backed by a `_ContiguousArrayBuffer`
|
||||
/// containing the same number of elements as `self`, return it.
|
||||
/// Otherwise, return `nil`.
|
||||
public
|
||||
func requestNativeBuffer() -> _ContiguousArrayBuffer<Element>? {
|
||||
@warn_unused_result
|
||||
public func requestNativeBuffer() -> _ContiguousArrayBuffer<Element>? {
|
||||
_invariantCheck()
|
||||
if _fastPath(_hasNativeBuffer && nativeBuffer.count == count) {
|
||||
return nativeBuffer
|
||||
@@ -220,6 +220,7 @@ struct _SliceBuffer<Element> : _ArrayBufferType {
|
||||
|
||||
/// Return whether the given `index` is valid for subscripting, i.e.
|
||||
/// `startIndex ≤ index < endIndex`
|
||||
@warn_unused_result
|
||||
internal func _isValidSubscript(
|
||||
index : Int, hoistedIsNativeBuffer: Bool
|
||||
) -> Bool {
|
||||
@@ -240,14 +241,17 @@ struct _SliceBuffer<Element> : _ArrayBufferType {
|
||||
return count
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
mutating func isUniquelyReferenced() -> Bool {
|
||||
return isUniquelyReferencedNonObjC(&owner)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
mutating func isUniquelyReferencedOrPinned() -> Bool {
|
||||
return isUniquelyReferencedOrPinnedNonObjC(&owner)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
func getElement(i: Int, hoistedIsNativeNoTypeCheckBuffer: Bool) -> Element {
|
||||
_sanityCheck(i >= startIndex, "negative slice index is out of range")
|
||||
_sanityCheck(i < endIndex, "slice index out of range")
|
||||
|
||||
@@ -25,6 +25,7 @@ public protocol _Strideable {
|
||||
///
|
||||
/// - SeeAlso: `RandomAccessIndexType`'s `distanceTo`, which provides a
|
||||
/// stronger semantic guarantee.
|
||||
@warn_unused_result
|
||||
func distanceTo(other: Self) -> Stride
|
||||
|
||||
/// Returns a `Self` `x` such that `self.distanceTo(x)` approximates
|
||||
@@ -34,6 +35,7 @@ public protocol _Strideable {
|
||||
///
|
||||
/// - SeeAlso: `RandomAccessIndexType`'s `advancedBy`, which
|
||||
/// provides a stronger semantic guarantee.
|
||||
@warn_unused_result
|
||||
func advancedBy(n: Stride) -> Self
|
||||
}
|
||||
|
||||
@@ -61,6 +63,7 @@ public protocol Strideable : Comparable, _Strideable {
|
||||
///
|
||||
/// - SeeAlso: `RandomAccessIndexType`'s `distanceTo`, which provides a
|
||||
/// stronger semantic guarantee.
|
||||
@warn_unused_result
|
||||
func distanceTo(other: Self) -> Stride
|
||||
|
||||
/// Returns a `Self` `x` such that `self.distanceTo(x)` approximates
|
||||
@@ -70,21 +73,26 @@ public protocol Strideable : Comparable, _Strideable {
|
||||
///
|
||||
/// - SeeAlso: `RandomAccessIndexType`'s `advancedBy`, which
|
||||
/// provides a stronger semantic guarantee.
|
||||
@warn_unused_result
|
||||
func advancedBy(n: Stride) -> Self
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func + <T : Strideable> (lhs: T, rhs: T.Stride) -> T {
|
||||
return lhs.advancedBy(rhs)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func + <T : Strideable> (lhs: T.Stride, rhs: T) -> T {
|
||||
return rhs.advancedBy(lhs)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func - <T : Strideable> (lhs: T, rhs: T.Stride) -> T {
|
||||
return lhs.advancedBy(-rhs)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func - <T : Strideable> (lhs: T, rhs: T) -> T.Stride {
|
||||
return rhs.distanceTo(lhs)
|
||||
}
|
||||
@@ -193,6 +201,7 @@ extension Strideable {
|
||||
/// Return the sequence of values (`self`, `self + stride`, `self +
|
||||
/// stride + stride`, ... *last*) where *last* is the last value in
|
||||
/// the progression that is less than `end`.
|
||||
@warn_unused_result
|
||||
public func stride(to end: Self, by stride: Stride) -> StrideTo<Self> {
|
||||
return StrideTo(start: self, end: end, stride: stride)
|
||||
}
|
||||
@@ -267,6 +276,7 @@ extension Strideable {
|
||||
/// the progression less than or equal to `end`.
|
||||
///
|
||||
/// - Note: There is no guarantee that `end` is an element of the sequence.
|
||||
@warn_unused_result
|
||||
public func stride(
|
||||
through end: Self, by stride: Stride
|
||||
) -> StrideThrough<Self> {
|
||||
|
||||
@@ -120,6 +120,7 @@ public struct String {
|
||||
}
|
||||
|
||||
extension String {
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
static func _fromWellFormedCodeUnitSequence<
|
||||
Encoding: UnicodeCodecType, Input: CollectionType
|
||||
@@ -130,6 +131,7 @@ extension String {
|
||||
return String._fromCodeUnitSequence(encoding, input: input)!
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
static func _fromCodeUnitSequence<
|
||||
Encoding: UnicodeCodecType, Input: CollectionType
|
||||
@@ -147,6 +149,7 @@ extension String {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
static func _fromCodeUnitSequenceWithRepair<
|
||||
Encoding: UnicodeCodecType, Input: CollectionType
|
||||
@@ -180,8 +183,7 @@ extension String : UnicodeScalarLiteralConvertible {
|
||||
extension String : _BuiltinExtendedGraphemeClusterLiteralConvertible {
|
||||
@effects(readonly)
|
||||
@_semantics("string.makeUTF8")
|
||||
public
|
||||
init(
|
||||
public init(
|
||||
_builtinExtendedGraphemeClusterLiteral start: Builtin.RawPointer,
|
||||
byteSize: Builtin.Word,
|
||||
isASCII: Builtin.Int1) {
|
||||
@@ -203,8 +205,7 @@ extension String : ExtendedGraphemeClusterLiteralConvertible {
|
||||
extension String : _BuiltinUTF16StringLiteralConvertible {
|
||||
@effects(readonly)
|
||||
@_semantics("string.makeUTF16")
|
||||
public
|
||||
init(
|
||||
public init(
|
||||
_builtinUTF16StringLiteral start: Builtin.RawPointer,
|
||||
numberOfCodeUnits: Builtin.Word
|
||||
) {
|
||||
@@ -221,8 +222,7 @@ extension String : _BuiltinUTF16StringLiteralConvertible {
|
||||
extension String : _BuiltinStringLiteralConvertible {
|
||||
@effects(readonly)
|
||||
@_semantics("string.makeUTF8")
|
||||
public
|
||||
init(
|
||||
public init(
|
||||
_builtinStringLiteral start: Builtin.RawPointer,
|
||||
byteSize: Builtin.Word,
|
||||
isASCII: Builtin.Int1) {
|
||||
@@ -267,6 +267,7 @@ extension String : CustomDebugStringConvertible {
|
||||
extension String {
|
||||
/// Return the number of code units occupied by this string
|
||||
/// in the given encoding.
|
||||
@warn_unused_result
|
||||
func _encodedLength<
|
||||
Encoding: UnicodeCodecType
|
||||
>(encoding: Encoding.Type) -> Int {
|
||||
@@ -315,6 +316,7 @@ public func _stdlib_compareNSStringDeterministicUnicodeCollation(
|
||||
extension String : Equatable {
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func ==(lhs: String, rhs: String) -> Bool {
|
||||
if lhs._core.isASCII && rhs._core.isASCII {
|
||||
if lhs._core.count != rhs._core.count {
|
||||
@@ -335,12 +337,15 @@ extension String {
|
||||
/// This is consistent with Foundation, but incorrect as defined by Unicode.
|
||||
/// Unicode weights some ASCII punctuation in a different order than ASCII
|
||||
/// value. Such as:
|
||||
///
|
||||
/// 0022 ; [*02FF.0020.0002] # QUOTATION MARK
|
||||
/// 0023 ; [*038B.0020.0002] # NUMBER SIGN
|
||||
/// 0025 ; [*038C.0020.0002] # PERCENT SIGN
|
||||
/// 0026 ; [*0389.0020.0002] # AMPERSAND
|
||||
/// 0027 ; [*02F8.0020.0002] # APOSTROPHE
|
||||
/// - Precondition: Both self and rhs are ASCII strings.
|
||||
///
|
||||
/// - Precondition: Both `self` and `rhs` are ASCII strings.
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _compareASCII(rhs: String) -> Int {
|
||||
var compare = Int(memcmp(
|
||||
@@ -356,7 +361,9 @@ extension String {
|
||||
#endif
|
||||
|
||||
/// Compares two strings with the Unicode Collation Algorithm.
|
||||
@inline(never) @_semantics("stdlib_binary_only") // Hide the CF/ICU dependency
|
||||
@warn_unused_result
|
||||
@inline(never)
|
||||
@_semantics("stdlib_binary_only") // Hide the CF/ICU dependency
|
||||
public // @testable
|
||||
func _compareDeterministicUnicodeCollation(rhs: String) -> Int {
|
||||
// Note: this operation should be consistent with equality comparison of
|
||||
@@ -393,6 +400,7 @@ extension String {
|
||||
#endif
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _compareString(rhs: String) -> Int {
|
||||
#if _runtime(_ObjC)
|
||||
@@ -406,6 +414,7 @@ extension String {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func <(lhs: String, rhs: String) -> Bool {
|
||||
return lhs._compareString(rhs) < 0
|
||||
}
|
||||
@@ -436,9 +445,11 @@ extension String {
|
||||
}
|
||||
|
||||
#if _runtime(_ObjC)
|
||||
@warn_unused_result
|
||||
@asmname("swift_stdlib_NSStringNFDHashValue")
|
||||
func _stdlib_NSStringNFDHashValue(str: AnyObject) -> Int
|
||||
|
||||
@warn_unused_result
|
||||
@asmname("swift_stdlib_NSStringASCIIHashValue")
|
||||
func _stdlib_NSStringASCIIHashValue(str: AnyObject) -> Int
|
||||
#endif
|
||||
@@ -485,9 +496,10 @@ extension String : Hashable {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
@effects(readonly)
|
||||
@_semantics("string.concat")
|
||||
public func +(var lhs: String, rhs: String) -> String {
|
||||
public func + (var lhs: String, rhs: String) -> String {
|
||||
if (lhs.isEmpty) {
|
||||
return rhs
|
||||
}
|
||||
@@ -543,10 +555,12 @@ extension String {
|
||||
public subscript(i: Index) -> Character { return characters[i] }
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func == (lhs: String.Index, rhs: String.Index) -> Bool {
|
||||
return lhs._base == rhs._base
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func < (lhs: String.Index, rhs: String.Index) -> Bool {
|
||||
return lhs._base < rhs._base
|
||||
}
|
||||
@@ -596,6 +610,7 @@ extension String {
|
||||
/// then concatenate the result. For example:
|
||||
///
|
||||
/// "-|-".join(["foo", "bar", "baz"]) // "foo-|-bar-|-baz"
|
||||
@warn_unused_result
|
||||
public func join<
|
||||
S : SequenceType where S.Generator.Element == String
|
||||
>(elements: S) -> String {
|
||||
@@ -694,12 +709,15 @@ extension String {
|
||||
}
|
||||
}
|
||||
#if _runtime(_ObjC)
|
||||
@warn_unused_result
|
||||
@asmname("swift_stdlib_NSStringLowercaseString")
|
||||
func _stdlib_NSStringLowercaseString(str: AnyObject) -> _CocoaStringType
|
||||
|
||||
@warn_unused_result
|
||||
@asmname("swift_stdlib_NSStringUppercaseString")
|
||||
func _stdlib_NSStringUppercaseString(str: AnyObject) -> _CocoaStringType
|
||||
#else
|
||||
@warn_unused_result
|
||||
internal func _nativeUnicodeLowercaseString(str: String) -> String {
|
||||
var buffer = _StringBuffer(
|
||||
capacity: str._core.count, initialSize: str._core.count, elementWidth: 2)
|
||||
@@ -722,6 +740,7 @@ internal func _nativeUnicodeLowercaseString(str: String) -> String {
|
||||
return String(_storage: buffer)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
internal func _nativeUnicodeUppercaseString(str: String) -> String {
|
||||
var buffer = _StringBuffer(
|
||||
capacity: str._core.count, initialSize: str._core.count, elementWidth: 2)
|
||||
@@ -894,6 +913,7 @@ extension String.Index {
|
||||
/// to `self`.
|
||||
///
|
||||
/// - Requires: `self` is an element of `String(utf8).indices`.
|
||||
@warn_unused_result
|
||||
public func samePositionIn(
|
||||
utf8: String.UTF8View
|
||||
) -> String.UTF8View.Index {
|
||||
@@ -904,6 +924,7 @@ extension String.Index {
|
||||
/// to `self`.
|
||||
///
|
||||
/// - Requires: `self` is an element of `String(utf16).indices`.
|
||||
@warn_unused_result
|
||||
public func samePositionIn(
|
||||
utf16: String.UTF16View
|
||||
) -> String.UTF16View.Index {
|
||||
@@ -914,6 +935,7 @@ extension String.Index {
|
||||
/// to `self`.
|
||||
///
|
||||
/// - Requires: `self` is an element of `String(unicodeScalars).indices`.
|
||||
@warn_unused_result
|
||||
public func samePositionIn(
|
||||
unicodeScalars: String.UnicodeScalarView
|
||||
) -> String.UnicodeScalarView.Index {
|
||||
|
||||
@@ -82,6 +82,7 @@ public struct _StringBuffer {
|
||||
= ((_storage._capacity() - capacityBump) << 1) + elementShift
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
static func fromCodeUnits<
|
||||
Encoding : UnicodeCodecType, Input : CollectionType // SequenceType?
|
||||
where Input.Generator.Element == Encoding.CodeUnit
|
||||
@@ -169,6 +170,7 @@ public struct _StringBuffer {
|
||||
// reserveCapacity on String and subsequently use that capacity, in
|
||||
// two separate phases. Operations with one-phase growth should use
|
||||
// "grow()," below.
|
||||
@warn_unused_result
|
||||
func hasCapacity(
|
||||
cap: Int, forSubRange r: Range<UnsafePointer<RawByte>>
|
||||
) -> Bool {
|
||||
|
||||
@@ -125,6 +125,7 @@ extension String.CharacterView : CollectionType {
|
||||
|
||||
/// Returns the length of the first extended grapheme cluster in UTF-16
|
||||
/// code units.
|
||||
@warn_unused_result
|
||||
internal static func _measureExtendedGraphemeClusterForward(
|
||||
var start: UnicodeScalarView.Index
|
||||
) -> Int {
|
||||
@@ -163,6 +164,7 @@ extension String.CharacterView : CollectionType {
|
||||
|
||||
/// Returns the length of the previous extended grapheme cluster in UTF-16
|
||||
/// code units.
|
||||
@warn_unused_result
|
||||
internal static func _measureExtendedGraphemeClusterBackward(
|
||||
end: UnicodeScalarView.Index
|
||||
) -> Int {
|
||||
@@ -327,6 +329,7 @@ extension String.CharacterView {
|
||||
/// then concatenate the result. For example:
|
||||
///
|
||||
/// "-|-".join(["foo", "bar", "baz"]) // "foo-|-bar-|-baz"
|
||||
@warn_unused_result
|
||||
public func join<
|
||||
S : SequenceType where S.Generator.Element == String.CharacterView
|
||||
>(elements: S) -> String.CharacterView {
|
||||
|
||||
@@ -95,6 +95,7 @@ public struct _StringCore {
|
||||
/// storage. Caveats: The string must have contiguous storage; the
|
||||
/// element may be 1 or 2 bytes wide, depending on elementWidth; the
|
||||
/// result may be null if the string is empty.
|
||||
@warn_unused_result
|
||||
func _pointerToNth(n: Int) -> COpaquePointer {
|
||||
_sanityCheck(hasContiguousStorage && n >= 0 && n <= count)
|
||||
return COpaquePointer(
|
||||
@@ -288,6 +289,7 @@ public struct _StringCore {
|
||||
}
|
||||
|
||||
/// Get the Nth UTF-16 Code Unit stored.
|
||||
@warn_unused_result
|
||||
func _nthContiguous(position: Int) -> UTF16.CodeUnit {
|
||||
let p = UnsafeMutablePointer<UInt8>(_pointerToNth(position)._rawValue)
|
||||
// Always dereference two bytes, but when elements are 8 bits we
|
||||
@@ -366,6 +368,7 @@ public struct _StringCore {
|
||||
/// - Note: If unsuccessful because of insufficient space in an
|
||||
/// existing buffer, the suggested new capacity will at least double
|
||||
/// the existing buffer's storage.
|
||||
@warn_unused_result
|
||||
mutating func _claimCapacity(
|
||||
newSize: Int, minElementWidth: Int) -> (Int, COpaquePointer) {
|
||||
if _fastPath((nativeBuffer != nil) && elementWidth >= minElementWidth) {
|
||||
@@ -399,6 +402,7 @@ public struct _StringCore {
|
||||
/// Effectively appends garbage to the String until it has newSize
|
||||
/// UTF-16 code units. Returns a pointer to the garbage code units;
|
||||
/// you must immediately copy valid data into that storage.
|
||||
@warn_unused_result
|
||||
mutating func _growBuffer(
|
||||
newSize: Int, minElementWidth: Int
|
||||
) -> COpaquePointer {
|
||||
@@ -536,6 +540,7 @@ public struct _StringCore {
|
||||
/// represented as pure ASCII.
|
||||
///
|
||||
/// - Complexity: O(N) in the worst case.
|
||||
@warn_unused_result
|
||||
func representableAsASCII() -> Bool {
|
||||
if _slowPath(!hasContiguousStorage) {
|
||||
return false
|
||||
|
||||
@@ -36,6 +36,7 @@ extension String {
|
||||
return _split("\n")
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func _split(separator: UnicodeScalar) -> [String] {
|
||||
let scalarSlices = unicodeScalars.split { $0 == separator }
|
||||
return scalarSlices.map { String($0) }
|
||||
@@ -52,14 +53,20 @@ extension String {
|
||||
self = String(count: 1, repeatedValue: _c)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
func _isAll(@noescape predicate: (UnicodeScalar) -> Bool) -> Bool {
|
||||
for c in unicodeScalars { if !predicate(c) { return false } }
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
func _isAlpha() -> Bool { return _isAll({ $0._isAlpha() }) }
|
||||
|
||||
@warn_unused_result
|
||||
func _isDigit() -> Bool { return _isAll({ $0._isDigit() }) }
|
||||
|
||||
@warn_unused_result
|
||||
func _isSpace() -> Bool { return _isAll({ $0._isSpace() }) }
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ extension String {
|
||||
return Index(_offset: _length)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
func _toInternalIndex(i: Int) -> Int {
|
||||
return _core.startIndex + _offset + i
|
||||
}
|
||||
@@ -122,6 +123,7 @@ extension String {
|
||||
}
|
||||
|
||||
/// Returns a mirror that reflects `self`.
|
||||
@warn_unused_result
|
||||
public func _getMirror() -> _MirrorType {
|
||||
return _UTF16ViewMirror(self)
|
||||
}
|
||||
@@ -174,14 +176,18 @@ extension String {
|
||||
extension String.UTF16View.Index : BidirectionalIndexType {
|
||||
public typealias Distance = Int
|
||||
|
||||
@warn_unused_result
|
||||
public func successor() -> String.UTF16View.Index {
|
||||
return String.UTF16View.Index(_offset: _offset.successor())
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func predecessor() -> String.UTF16View.Index {
|
||||
return String.UTF16View.Index(_offset: _offset.predecessor())
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func == (
|
||||
lhs: String.UTF16View.Index, rhs: String.UTF16View.Index
|
||||
) -> Bool {
|
||||
@@ -190,6 +196,7 @@ public func == (
|
||||
|
||||
extension String.UTF16View.Index : Comparable, Equatable {}
|
||||
|
||||
@warn_unused_result
|
||||
public func < (
|
||||
lhs: String.UTF16View.Index, rhs: String.UTF16View.Index
|
||||
) -> Bool {
|
||||
@@ -201,15 +208,18 @@ public func < (
|
||||
|
||||
/// Do not use this operator directly; call distance(start, end) instead.
|
||||
extension String.UTF16View.Index {
|
||||
@warn_unused_result
|
||||
public func distanceTo(end: String.UTF16View.Index)
|
||||
-> String.UTF16View.Index.Distance {
|
||||
return self._offset.distanceTo(end._offset)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func advancedBy(n: Distance) -> String.UTF16View.Index {
|
||||
return String.UTF16View.Index(_offset: self._offset.advancedBy(n))
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func advancedBy(n: Distance, limit: String.UTF16View.Index)
|
||||
-> String.UTF16View.Index {
|
||||
return String.UTF16View.Index(
|
||||
@@ -265,6 +275,7 @@ extension String.UTF16View.Index {
|
||||
///
|
||||
/// - Requires: `self` is an element of
|
||||
/// `String(utf8)!.utf16.indices`.
|
||||
@warn_unused_result
|
||||
public func samePositionIn(
|
||||
utf8: String.UTF8View
|
||||
) -> String.UTF8View.Index? {
|
||||
@@ -276,6 +287,7 @@ extension String.UTF16View.Index {
|
||||
///
|
||||
/// - Requires: `self` is an element of
|
||||
/// `String(unicodeScalars).utf16.indices`.
|
||||
@warn_unused_result
|
||||
public func samePositionIn(
|
||||
unicodeScalars: String.UnicodeScalarView
|
||||
) -> String.UnicodeScalarIndex? {
|
||||
@@ -286,6 +298,7 @@ extension String.UTF16View.Index {
|
||||
/// to `self`, or if no such position exists, `nil`.
|
||||
///
|
||||
/// - Requires: `self` is an element of `characters.utf16.indices`.
|
||||
@warn_unused_result
|
||||
public func samePositionIn(
|
||||
characters: String
|
||||
) -> String.Index? {
|
||||
|
||||
@@ -27,6 +27,7 @@ extension _StringCore {
|
||||
/// and the second element contains the encoded UTF-8 starting in its
|
||||
/// low byte. Any unused high bytes in the result will be set to
|
||||
/// 0xFF.
|
||||
@warn_unused_result
|
||||
func _encodeSomeUTF8(i: Int) -> (Int, UTF8Chunk) {
|
||||
_sanityCheck(i <= count)
|
||||
|
||||
@@ -56,6 +57,7 @@ extension _StringCore {
|
||||
|
||||
/// Helper for `_encodeSomeUTF8`, above. Handles the case where the
|
||||
/// storage is contiguous UTF-16.
|
||||
@warn_unused_result
|
||||
func _encodeSomeContiguousUTF16AsUTF8(i: Int) -> (Int, UTF8Chunk) {
|
||||
_sanityCheck(elementWidth == 2)
|
||||
_sanityCheck(!_baseAddress._isNull)
|
||||
@@ -67,6 +69,7 @@ extension _StringCore {
|
||||
#if _runtime(_ObjC)
|
||||
/// Helper for `_encodeSomeUTF8`, above. Handles the case where the
|
||||
/// storage is non-contiguous UTF-16.
|
||||
@warn_unused_result
|
||||
func _encodeSomeNonContiguousUTF16AsUTF8(i: Int) -> (Int, UTF8Chunk) {
|
||||
_sanityCheck(elementWidth == 2)
|
||||
_sanityCheck(_baseAddress._isNull)
|
||||
@@ -122,6 +125,7 @@ extension String {
|
||||
/// Returns the next consecutive value after `self`.
|
||||
///
|
||||
/// - Requires: The next value is representable.
|
||||
@warn_unused_result
|
||||
public func successor() -> Index {
|
||||
let currentUnit = UTF8.CodeUnit(truncatingBitPattern: _buffer)
|
||||
let hiNibble = currentUnit >> 4
|
||||
@@ -227,6 +231,7 @@ extension String {
|
||||
}
|
||||
|
||||
/// Returns a mirror that reflects `self`.
|
||||
@warn_unused_result
|
||||
public func _getMirror() -> _MirrorType {
|
||||
return _UTF8ViewMirror(self)
|
||||
}
|
||||
@@ -280,8 +285,11 @@ extension String {
|
||||
public typealias UTF8Index = UTF8View.Index
|
||||
}
|
||||
|
||||
public
|
||||
func == (lhs: String.UTF8View.Index, rhs: String.UTF8View.Index) -> Bool {
|
||||
@warn_unused_result
|
||||
public func == (
|
||||
lhs: String.UTF8View.Index,
|
||||
rhs: String.UTF8View.Index
|
||||
) -> Bool {
|
||||
// If the underlying UTF16 index differs, they're unequal
|
||||
if lhs._coreIndex != rhs._coreIndex {
|
||||
return false
|
||||
@@ -373,6 +381,7 @@ extension String.UTF8View.Index {
|
||||
/// to `self`, or if no such position exists, `nil`.
|
||||
///
|
||||
/// - Requires: `self` is an element of `String(utf16)!.utf8.indices`.
|
||||
@warn_unused_result
|
||||
public func samePositionIn(
|
||||
utf16: String.UTF16View
|
||||
) -> String.UTF16View.Index? {
|
||||
@@ -384,6 +393,7 @@ extension String.UTF8View.Index {
|
||||
///
|
||||
/// - Requires: `self` is an element of
|
||||
/// `String(unicodeScalars).utf8.indices`.
|
||||
@warn_unused_result
|
||||
public func samePositionIn(
|
||||
unicodeScalars: String.UnicodeScalarView
|
||||
) -> String.UnicodeScalarIndex? {
|
||||
@@ -394,6 +404,7 @@ extension String.UTF8View.Index {
|
||||
/// to `self`, or if no such position exists, `nil`.
|
||||
///
|
||||
/// - Requires: `self` is an element of `characters.utf8.indices`.
|
||||
@warn_unused_result
|
||||
public func samePositionIn(
|
||||
characters: String
|
||||
) -> String.Index? {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@warn_unused_result
|
||||
public func ==(
|
||||
lhs: String.UnicodeScalarView.Index,
|
||||
rhs: String.UnicodeScalarView.Index
|
||||
@@ -17,6 +18,7 @@ public func ==(
|
||||
return lhs._position == rhs._position
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func <(
|
||||
lhs: String.UnicodeScalarView.Index,
|
||||
rhs: String.UnicodeScalarView.Index
|
||||
@@ -58,6 +60,7 @@ extension String {
|
||||
/// Returns the next consecutive value after `self`.
|
||||
///
|
||||
/// - Requires: The next value is representable.
|
||||
@warn_unused_result
|
||||
public func successor() -> Index {
|
||||
var scratch = _ScratchGenerator(_core, _position)
|
||||
var decoder = UTF16()
|
||||
@@ -68,6 +71,7 @@ extension String {
|
||||
/// Returns the previous consecutive value before `self`.
|
||||
///
|
||||
/// - Requires: The previous value is representable.
|
||||
@warn_unused_result
|
||||
public func predecessor() -> Index {
|
||||
var i = _position
|
||||
let codeUnit = _core[--i]
|
||||
@@ -201,11 +205,13 @@ extension String {
|
||||
/// this *sequence*.
|
||||
///
|
||||
/// - Complexity: O(1).
|
||||
@warn_unused_result
|
||||
public func generate() -> Generator {
|
||||
return Generator(_core)
|
||||
}
|
||||
|
||||
/// Returns a mirror that reflects `self`.
|
||||
@warn_unused_result
|
||||
public func _getMirror() -> _MirrorType {
|
||||
return _UnicodeScalarViewMirror(self)
|
||||
}
|
||||
@@ -357,6 +363,7 @@ extension String.UnicodeScalarIndex {
|
||||
/// to `self`.
|
||||
///
|
||||
/// - Requires: `self` is an element of `String(utf8)!.indices`.
|
||||
@warn_unused_result
|
||||
public func samePositionIn(utf8: String.UTF8View) -> String.UTF8View.Index {
|
||||
return String.UTF8View.Index(self, within: utf8)
|
||||
}
|
||||
@@ -365,6 +372,7 @@ extension String.UnicodeScalarIndex {
|
||||
/// to `self`.
|
||||
///
|
||||
/// - Requires: `self` is an element of `String(utf16)!.indices`.
|
||||
@warn_unused_result
|
||||
public func samePositionIn(
|
||||
utf16: String.UTF16View
|
||||
) -> String.UTF16View.Index {
|
||||
@@ -375,6 +383,7 @@ extension String.UnicodeScalarIndex {
|
||||
/// to `self`, or if no such position exists, `nil`.
|
||||
///
|
||||
/// - Requires: `self` is an element of `characters.unicodeScalars.indices`.
|
||||
@warn_unused_result
|
||||
public func samePositionIn(characters: String) -> String.Index? {
|
||||
return String.Index(self, within: characters)
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ public enum UnicodeDecodingResult {
|
||||
|
||||
/// Return true if `self` indicates no more unicode scalars are
|
||||
/// available.
|
||||
public
|
||||
func isEmptyInput() -> Bool {
|
||||
@warn_unused_result
|
||||
public func isEmptyInput() -> Bool {
|
||||
switch self {
|
||||
case .EmptyInput:
|
||||
return true
|
||||
@@ -81,6 +81,7 @@ public struct UTF8 : UnicodeCodecType {
|
||||
/// Returns the number of expected trailing bytes for a given first byte: 0,
|
||||
/// 1, 2 or 3. If the first byte can not start a valid UTF-8 code unit
|
||||
/// sequence, returns 4.
|
||||
@warn_unused_result
|
||||
public static func _numTrailingBytes(cu0: CodeUnit) -> UInt8 {
|
||||
if _fastPath(cu0 & 0x80 == 0) {
|
||||
// 0x00 -- 0x7f: 1-byte sequences.
|
||||
@@ -142,6 +143,7 @@ public struct UTF8 : UnicodeCodecType {
|
||||
|
||||
/// Return `true` if the LSB bytes in `buffer` are well-formed UTF-8 code
|
||||
/// unit sequence.
|
||||
@warn_unused_result
|
||||
static func _isValidUTF8Impl(buffer: UInt32, length: UInt8) -> Bool {
|
||||
switch length {
|
||||
case 4:
|
||||
@@ -192,6 +194,7 @@ public struct UTF8 : UnicodeCodecType {
|
||||
|
||||
/// Return `true` if the LSB bytes in `buffer` are well-formed UTF-8 code
|
||||
/// unit sequence.
|
||||
@warn_unused_result
|
||||
static func _isValidUTF8(buffer: UInt32, validBytes: UInt8) -> Bool {
|
||||
_sanityCheck(validBytes & 0b0000_1111 != 0,
|
||||
"input buffer should not be empty")
|
||||
@@ -221,6 +224,7 @@ public struct UTF8 : UnicodeCodecType {
|
||||
|
||||
/// Given an ill-formed sequence, find the length of its maximal subpart.
|
||||
@inline(never)
|
||||
@warn_unused_result
|
||||
static func _findMaximalSubpartOfIllFormedUTF8Sequence(
|
||||
var buffer: UInt32, var validBytes: UInt8) -> UInt8 {
|
||||
// This function is '@inline(never)' because it is used only in the error
|
||||
@@ -472,6 +476,7 @@ public struct UTF8 : UnicodeCodecType {
|
||||
|
||||
/// Return `true` if `byte` is a continuation byte of the form
|
||||
/// `0b10xxxxxx`.
|
||||
@warn_unused_result
|
||||
public static func isContinuation(byte: CodeUnit) -> Bool {
|
||||
return byte & 0b11_00__0000 == 0b10_00__0000
|
||||
}
|
||||
@@ -712,6 +717,7 @@ public func transcode<
|
||||
///
|
||||
/// Returns the index of the first unhandled code unit and the UTF-8 data
|
||||
/// that was encoded.
|
||||
@warn_unused_result
|
||||
internal func _transcodeSomeUTF16AsUTF8<
|
||||
Input : CollectionType
|
||||
where Input.Generator.Element == UInt16>(
|
||||
@@ -805,7 +811,10 @@ internal func _transcodeSomeUTF16AsUTF8<
|
||||
/// representation.
|
||||
public // @testable
|
||||
protocol _StringElementType {
|
||||
@warn_unused_result
|
||||
static func _toUTF16CodeUnit(_: Self) -> UTF16.CodeUnit
|
||||
|
||||
@warn_unused_result
|
||||
static func _fromUTF16CodeUnit(utf16: UTF16.CodeUnit) -> Self
|
||||
}
|
||||
|
||||
@@ -839,6 +848,7 @@ extension UTF8.CodeUnit : _StringElementType {
|
||||
|
||||
extension UTF16 {
|
||||
/// Return the number of code units required to encode `x`.
|
||||
@warn_unused_result
|
||||
public static func width(x: UnicodeScalar) -> Int {
|
||||
return x.value <= 0xFFFF ? 1 : 2
|
||||
}
|
||||
@@ -847,6 +857,7 @@ extension UTF16 {
|
||||
/// `x`.
|
||||
///
|
||||
/// - Requires: `width(x) == 2`.
|
||||
@warn_unused_result
|
||||
public static func leadSurrogate(x: UnicodeScalar) -> UTF16.CodeUnit {
|
||||
_precondition(width(x) == 2)
|
||||
return UTF16.CodeUnit((x.value - 0x1_0000) >> (10 as UInt32)) + 0xD800
|
||||
@@ -856,6 +867,7 @@ extension UTF16 {
|
||||
/// `x`.
|
||||
///
|
||||
/// - Requires: `width(x) == 2`.
|
||||
@warn_unused_result
|
||||
public static func trailSurrogate(x: UnicodeScalar) -> UTF16.CodeUnit {
|
||||
_precondition(width(x) == 2)
|
||||
return UTF16.CodeUnit(
|
||||
@@ -863,10 +875,12 @@ extension UTF16 {
|
||||
) + 0xDC00
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public static func isLeadSurrogate(x: CodeUnit) -> Bool {
|
||||
return 0xD800...0xDBFF ~= x
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public static func isTrailSurrogate(x: CodeUnit) -> Bool {
|
||||
return 0xDC00...0xDFFF ~= x
|
||||
}
|
||||
@@ -897,6 +911,7 @@ extension UTF16 {
|
||||
/// If `repairIllFormedSequences` is `true`, the function always succeeds.
|
||||
/// If it is `false`, `nil` is returned if an ill-formed code unit sequence is
|
||||
/// found in `input`.
|
||||
@warn_unused_result
|
||||
public static func measure<
|
||||
Encoding : UnicodeCodecType, Input : GeneratorType
|
||||
where Encoding.CodeUnit == Input.Element
|
||||
|
||||
@@ -90,6 +90,7 @@ public struct UnicodeScalar :
|
||||
///
|
||||
/// - parameter forceASCII: If `true`, forces most values into a numeric
|
||||
/// representation.
|
||||
@warn_unused_result
|
||||
public func escape(asASCII forceASCII: Bool) -> String {
|
||||
func lowNibbleAsHex(v: UInt32) -> String {
|
||||
let nibble = v & 15
|
||||
@@ -151,21 +152,25 @@ public struct UnicodeScalar :
|
||||
|
||||
/// Returns true if this is an ASCII character (code point 0 to 127
|
||||
/// inclusive).
|
||||
@warn_unused_result
|
||||
public func isASCII() -> Bool {
|
||||
return value <= 127
|
||||
}
|
||||
|
||||
// FIXME: Locales make this interesting
|
||||
@warn_unused_result
|
||||
func _isAlpha() -> Bool {
|
||||
return (self >= "A" && self <= "Z") || (self >= "a" && self <= "z")
|
||||
}
|
||||
|
||||
// FIXME: Is there an similar term of art in Unicode?
|
||||
@warn_unused_result
|
||||
public func _isASCIIDigit() -> Bool {
|
||||
return self >= "0" && self <= "9"
|
||||
}
|
||||
|
||||
// FIXME: Unicode makes this interesting
|
||||
@warn_unused_result
|
||||
func _isDigit() -> Bool {
|
||||
return _isASCIIDigit()
|
||||
}
|
||||
@@ -191,6 +196,7 @@ public struct UnicodeScalar :
|
||||
}
|
||||
|
||||
// FIXME: Unicode makes this interesting.
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func _isSpace() -> Bool {
|
||||
// FIXME: The constraint-based type checker goes painfully exponential
|
||||
@@ -202,6 +208,7 @@ public struct UnicodeScalar :
|
||||
}
|
||||
|
||||
// FIXME: Unicode makes this interesting.
|
||||
@warn_unused_result
|
||||
func _isPrintableASCII() -> Bool {
|
||||
return (self >= UnicodeScalar(0o040) && self <= UnicodeScalar(0o176))
|
||||
}
|
||||
@@ -270,10 +277,12 @@ extension UInt64 {
|
||||
extension UnicodeScalar : Comparable, Equatable {
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func ==(lhs: UnicodeScalar, rhs: UnicodeScalar) -> Bool {
|
||||
return lhs.value == rhs.value
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func <(lhs: UnicodeScalar, rhs: UnicodeScalar) -> Bool {
|
||||
return lhs.value < rhs.value
|
||||
}
|
||||
@@ -315,6 +324,7 @@ extension UnicodeScalar.UTF16View : CollectionType {
|
||||
}
|
||||
|
||||
/// Return c as a UTF8.CodeUnit. Meant to be used as _ascii8("x").
|
||||
@warn_unused_result
|
||||
public // SPI(SwiftExperimental)
|
||||
func _ascii8(c: UnicodeScalar) -> UTF8.CodeUnit {
|
||||
_sanityCheck(c.value >= 0 && c.value <= 0x7F, "not ASCII")
|
||||
@@ -322,6 +332,7 @@ func _ascii8(c: UnicodeScalar) -> UTF8.CodeUnit {
|
||||
}
|
||||
|
||||
/// Return c as a UTF16.CodeUnit. Meant to be used as _ascii16("x").
|
||||
@warn_unused_result
|
||||
public // SPI(SwiftExperimental)
|
||||
func _ascii16(c: UnicodeScalar) -> UTF16.CodeUnit {
|
||||
_sanityCheck(c.value >= 0 && c.value <= 0x7F, "not ASCII")
|
||||
|
||||
@@ -176,31 +176,37 @@ struct _UnicodeGraphemeClusterBreakPropertyTrie {
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
func _getBMPFirstLevelIndex(cp: UInt32) -> Int {
|
||||
return Int(cp >> ${BMPFirstLevelIndexBits})
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
func _getBMPDataOffset(cp: UInt32) -> Int {
|
||||
return Int(cp & ((1 << ${BMPDataOffsetBits}) - 1))
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
func _getSuppFirstLevelIndex(cp: UInt32) -> Int {
|
||||
return Int(cp >> (${SuppSecondLevelIndexBits} + ${SuppDataOffsetBits}))
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
func _getSuppSecondLevelIndex(cp: UInt32) -> Int {
|
||||
return Int((cp >> ${SuppDataOffsetBits}) &
|
||||
((1 << ${SuppSecondLevelIndexBits}) - 1))
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
func _getSuppDataOffset(cp: UInt32) -> Int {
|
||||
return Int(cp & ((1 << ${SuppDataOffsetBits}) - 1))
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
func getPropertyRawValue(
|
||||
codePoint: UInt32
|
||||
) -> _GraphemeClusterBreakPropertyRawValue {
|
||||
@@ -229,6 +235,7 @@ struct _UnicodeGraphemeClusterBreakPropertyTrie {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public // @testable
|
||||
func getPropertyValue(
|
||||
codePoint: UInt32
|
||||
@@ -247,6 +254,7 @@ internal struct _UnicodeExtendedGraphemeClusterSegmenter {
|
||||
|
||||
/// Returns `true` if there is always a grapheme cluster break after a code
|
||||
/// point with a given `Grapheme_Cluster_Break` property value.
|
||||
@warn_unused_result
|
||||
func isBoundaryAfter(gcb: _GraphemeClusterBreakPropertyRawValue) -> Bool {
|
||||
let ruleRow = _noBoundaryRulesMatrix[Int(gcb.rawValue)]
|
||||
return ruleRow == 0
|
||||
@@ -254,6 +262,7 @@ internal struct _UnicodeExtendedGraphemeClusterSegmenter {
|
||||
|
||||
/// Returns `true` if there is a grapheme cluster break between code points
|
||||
/// with given `Grapheme_Cluster_Break` property values.
|
||||
@warn_unused_result
|
||||
func isBoundary(
|
||||
gcb1: _GraphemeClusterBreakPropertyRawValue,
|
||||
_ gcb2: _GraphemeClusterBreakPropertyRawValue
|
||||
|
||||
@@ -30,6 +30,7 @@ public struct Unmanaged<Instance : AnyObject> {
|
||||
///
|
||||
/// let str: CFString = Unmanaged.fromOpaque(ptr).takeUnretainedValue()
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public static func fromOpaque(value: COpaquePointer) -> Unmanaged {
|
||||
// Null pointer check is a debug check, because it guards only against one
|
||||
// specific bad pointer value.
|
||||
@@ -47,6 +48,7 @@ public struct Unmanaged<Instance : AnyObject> {
|
||||
///
|
||||
/// let str: CFString = Unmanaged.fromOpaque(ptr).takeUnretainedValue()
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func toOpaque() -> COpaquePointer {
|
||||
return unsafeBitCast(_value, COpaquePointer.self)
|
||||
}
|
||||
@@ -58,6 +60,7 @@ public struct Unmanaged<Instance : AnyObject> {
|
||||
/// does not know the ownership rules for, but you know that the
|
||||
/// API expects you to pass the object at +1.
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public static func passRetained(value: Instance) -> Unmanaged {
|
||||
return Unmanaged(_private: value).retain()
|
||||
}
|
||||
@@ -72,6 +75,7 @@ public struct Unmanaged<Instance : AnyObject> {
|
||||
/// CFArraySetValueAtIndex(.passUnretained(array), i,
|
||||
/// .passUnretained(object))
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public static func passUnretained(value: Instance) -> Unmanaged {
|
||||
return Unmanaged(_private: value)
|
||||
}
|
||||
@@ -81,6 +85,7 @@ public struct Unmanaged<Instance : AnyObject> {
|
||||
///
|
||||
/// This is useful when a function returns an unmanaged reference
|
||||
/// and you know that you're not responsible for releasing the result.
|
||||
@warn_unused_result
|
||||
public func takeUnretainedValue() -> Instance {
|
||||
return _value
|
||||
}
|
||||
@@ -90,6 +95,7 @@ public struct Unmanaged<Instance : AnyObject> {
|
||||
///
|
||||
/// This is useful when a function returns an unmanaged reference
|
||||
/// and you know that you're responsible for releasing the result.
|
||||
@warn_unused_result
|
||||
public func takeRetainedValue() -> Instance {
|
||||
let result = _value
|
||||
release()
|
||||
|
||||
@@ -108,6 +108,7 @@ public struct ${Self}<Memory>
|
||||
/// Allocate memory for `num` objects of type `Memory`.
|
||||
///
|
||||
/// - Postcondition: The memory is allocated, but not initialized.
|
||||
@warn_unused_result
|
||||
public static func alloc(num: Int) -> ${Self} {
|
||||
let size = strideof(Memory.self) * num
|
||||
return ${Self}(
|
||||
@@ -177,6 +178,7 @@ ${comment}
|
||||
///
|
||||
/// - Postcondition: The value has been destroyed and the memory must
|
||||
/// be initialized before being used again.
|
||||
@warn_unused_result
|
||||
public func move() -> Memory {
|
||||
return Builtin.take(_rawValue)
|
||||
}
|
||||
@@ -446,6 +448,7 @@ ${MirrorDecl} {
|
||||
${MirrorConformance}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func == <Memory>(
|
||||
lhs: ${Self}<Memory>, rhs: ${Self}<Memory>
|
||||
) -> Bool {
|
||||
@@ -453,28 +456,33 @@ public func == <Memory>(
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func < <Memory>(lhs: ${Self}<Memory>, rhs: ${Self}<Memory>) -> Bool {
|
||||
return Bool(Builtin.cmp_ult_RawPointer(lhs._rawValue, rhs._rawValue))
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func + <Memory>(lhs: ${Self}<Memory>, rhs: Int) -> ${Self}<Memory> {
|
||||
return ${Self}(Builtin.gep_Word(
|
||||
lhs._rawValue, (rhs &* strideof(Memory.self))._builtinWordValue))
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func + <Memory>(lhs: Int,
|
||||
rhs: ${Self}<Memory>) -> ${Self}<Memory> {
|
||||
return rhs + lhs
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func - <Memory>(lhs: ${Self}<Memory>, rhs: Int) -> ${Self}<Memory> {
|
||||
return lhs + -rhs
|
||||
}
|
||||
|
||||
@transparent
|
||||
@warn_unused_result
|
||||
public func - <Memory>(lhs: ${Self}<Memory>, rhs: ${Self}<Memory>) -> Int {
|
||||
return
|
||||
Int(Builtin.sub_Word(Builtin.ptrtoint_Word(lhs._rawValue),
|
||||
|
||||
@@ -89,6 +89,7 @@ public func withVaList<R>(builder: VaListBuilder,
|
||||
/// `withVaList`, but occasionally (i.e. in a `class` initializer) you
|
||||
/// may find that the language rules don't allow you to use
|
||||
/// `withVaList` as intended.
|
||||
@warn_unused_result
|
||||
public func getVaList(args: [CVarArgType]) -> CVaListPointer {
|
||||
let builder = VaListBuilder()
|
||||
for a in args {
|
||||
@@ -100,6 +101,7 @@ public func getVaList(args: [CVarArgType]) -> CVaListPointer {
|
||||
return builder.va_list()
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func _encodeBitsAsWords<T : CVarArgType>(x: T) -> [Int] {
|
||||
let result = [Int](
|
||||
count: (sizeof(T.self) + sizeof(Int.self) - 1) / sizeof(Int.self),
|
||||
@@ -300,6 +302,7 @@ final public class VaListBuilder {
|
||||
appendWords(arg._cVarArgEncoding)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
func va_list() -> CVaListPointer {
|
||||
return CVaListPointer(_fromUnsafeMutablePointer: storage)
|
||||
}
|
||||
@@ -331,11 +334,13 @@ final public class VaListBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
func rawSizeAndAlignment(wordCount: Int) -> (Builtin.Word, Builtin.Word) {
|
||||
return ((wordCount * strideof(Int.self))._builtinWordValue,
|
||||
requiredAlignmentInBytes._builtinWordValue)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
func allocStorage(wordCount wordCount: Int) -> UnsafeMutablePointer<Int> {
|
||||
let (rawSize, rawAlignment) = rawSizeAndAlignment(wordCount)
|
||||
let rawStorage = Builtin.allocRaw(rawSize, rawAlignment)
|
||||
@@ -404,6 +409,7 @@ final public class VaListBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
func va_list() -> CVaListPointer {
|
||||
header.reg_save_area = storage._baseAddressIfContiguous
|
||||
header.overflow_arg_area
|
||||
|
||||
@@ -20,7 +20,7 @@ func find<R : GeneratorType where R.Element : Eq>
|
||||
if x == value {
|
||||
break
|
||||
}
|
||||
result.next()
|
||||
_ = result.next()
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -31,7 +31,7 @@ func findIf<R : GeneratorType>(range: R, predicate: (R.Element) -> Bool) -> R {
|
||||
if predicate(x) {
|
||||
break
|
||||
}
|
||||
result.next()
|
||||
_ = result.next()
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -101,8 +101,8 @@ func mismatch<R1 : GeneratorType, R2 : GeneratorType where R1.Element : Eq,
|
||||
let e1 = range1.next(), e2 = range2.next()
|
||||
|
||||
if (e1 == nil) || (e2 == nil) || e1! != e2! { break }
|
||||
prev1.next()
|
||||
prev2.next()
|
||||
_ = prev1.next()
|
||||
_ = prev2.next()
|
||||
}
|
||||
|
||||
return (prev1, prev2)
|
||||
@@ -117,8 +117,8 @@ func mismatchIf<R1 : GeneratorType, R2 : GeneratorType>
|
||||
let e1 = range1.next(), e2 = range2.next()
|
||||
|
||||
if (e1 == nil) || (e2 == nil) || !predicate(e1!, e2!) { break }
|
||||
prev1.next()
|
||||
prev2.next()
|
||||
_ = prev1.next()
|
||||
_ = prev2.next()
|
||||
}
|
||||
|
||||
return (prev1, prev2)
|
||||
|
||||
@@ -199,18 +199,18 @@ extension Something {
|
||||
// rdar://problem/18120419
|
||||
func TTGenWrap<T, G: GeneratorType where G.Element == (T,T)>(var gen: G)
|
||||
{
|
||||
gen.next()
|
||||
_ = gen.next()
|
||||
}
|
||||
|
||||
func IntIntGenWrap<G: GeneratorType where G.Element == (Int,Int)>(var gen: G)
|
||||
{
|
||||
gen.next()
|
||||
_ = gen.next()
|
||||
}
|
||||
|
||||
func GGWrap<G1: GeneratorType, G2: GeneratorType where G1.Element == G2.Element>(var g1: G1, var _ g2: G2)
|
||||
{
|
||||
g1.next()
|
||||
g2.next()
|
||||
_ = g1.next()
|
||||
_ = g2.next()
|
||||
}
|
||||
|
||||
func testSameTypeTuple(a: Array<(Int,Int)>, s: ArraySlice<(Int,Int)>) {
|
||||
|
||||
@@ -370,7 +370,7 @@ func testPreDecOverflow() {
|
||||
|
||||
func testAssumeNonNegative() {
|
||||
let input = -3
|
||||
_assumeNonNegative(input); // expected-error {{assumed non-negative value '-3' is negative}}
|
||||
_ = _assumeNonNegative(input) // expected-error {{assumed non-negative value '-3' is negative}}
|
||||
}
|
||||
|
||||
protocol Num { func Double() -> Self }
|
||||
|
||||
@@ -700,7 +700,7 @@ SequenceTypeTests.test("reverse/WhereIndexIsRandomAccess,RandomAccessReverseView
|
||||
|
||||
SequenceTypeTests.test("filter/SequenceType/Dispatch") {
|
||||
let tester = SequenceLog.dispatchTester([OpaqueValue(1)])
|
||||
tester.filter { _ in false }
|
||||
_ = tester.filter { _ in false }
|
||||
expectCustomizable(tester, tester.log.filter)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user