@@ -337,6 +337,7 @@ extension MutableCollection where Self: BidirectionalCollection {
337337/// - Precondition: `buffer` must point to a region of memory at least as large
338338/// as `min(mid - lo, hi - mid)`.
339339/// - Postcondition: `lo..<hi` is sorted according to `areInIncreasingOrder`.
340+ @discardableResult
340341@inlinable
341342internal func _merge< Element> (
342343 low: UnsafeMutablePointer < Element > ,
@@ -439,7 +440,6 @@ internal func _merge<Element>(
439440 }
440441 }
441442
442- // FIXME: Remove this, it works around SR-14750 (rdar://45044610)
443443 return true
444444}
445445
@@ -512,6 +512,7 @@ extension UnsafeMutableBufferPointer {
512512 /// - Precondition: `runs.count > 1` and `i > 0`
513513 /// - Precondition: `buffer` must have at least
514514 /// `min(runs[i].count, runs[i - 1].count)` uninitialized elements.
515+ @discardableResult
515516 @inlinable
516517 public mutating func _mergeRuns(
517518 _ runs: inout [ Range < Index > ] ,
@@ -524,7 +525,7 @@ extension UnsafeMutableBufferPointer {
524525 let middle = runs [ i] . lowerBound
525526 let high = runs [ i] . upperBound
526527
527- let result = try _merge (
528+ try _merge (
528529 low: baseAddress! + low,
529530 mid: baseAddress! + middle,
530531 high: baseAddress! + high,
@@ -534,8 +535,7 @@ extension UnsafeMutableBufferPointer {
534535 runs [ i - 1 ] = low..< high
535536 runs. remove ( at: i)
536537
537- // FIXME: Remove this, it works around SR-14750 (rdar://45044610)
538- return result
538+ return true
539539 }
540540
541541 /// Merges upper elements of `runs` until the required invariants are
@@ -545,6 +545,7 @@ extension UnsafeMutableBufferPointer {
545545 /// `min(runs[i].count, runs[i - 1].count)` uninitialized elements.
546546 /// - Precondition: The ranges in `runs` must be consecutive, such that for
547547 /// any i, `runs[i].upperBound == runs[i + 1].lowerBound`.
548+ @discardableResult
548549 @inlinable
549550 public mutating func _mergeTopRuns(
550551 _ runs: inout [ Range < Index > ] ,
@@ -571,9 +572,6 @@ extension UnsafeMutableBufferPointer {
571572 // If W > X + Y, X > Y + Z, and Y > Z, then the invariants are satisfied
572573 // for the entirety of `runs`.
573574
574- // FIXME: Remove this, it works around SR-14750 (rdar://45044610)
575- var result = true
576-
577575 // The invariant is always in place for a single element.
578576 while runs. count > 1 {
579577 var lastIndex = runs. count - 1
@@ -607,11 +605,11 @@ extension UnsafeMutableBufferPointer {
607605 }
608606
609607 // Merge the runs at `i` and `i - 1`.
610- result = try result && _mergeRuns (
608+ try _mergeRuns (
611609 & runs, at: lastIndex, buffer: buffer, by: areInIncreasingOrder)
612610 }
613611
614- return result
612+ return true
615613 }
616614
617615 /// Merges elements of `runs` until only one run remains.
@@ -620,19 +618,19 @@ extension UnsafeMutableBufferPointer {
620618 /// `min(runs[i].count, runs[i - 1].count)` uninitialized elements.
621619 /// - Precondition: The ranges in `runs` must be consecutive, such that for
622620 /// any i, `runs[i].upperBound == runs[i + 1].lowerBound`.
621+ @discardableResult
623622 @inlinable
624623 public mutating func _finalizeRuns(
625624 _ runs: inout [ Range < Index > ] ,
626625 buffer: UnsafeMutablePointer < Element > ,
627626 by areInIncreasingOrder: ( Element , Element ) throws -> Bool
628627 ) rethrows -> Bool {
629- // FIXME: Remove this, it works around SR-14750 (rdar://45044610)
630- var result = true
631628 while runs. count > 1 {
632- result = try result && _mergeRuns (
629+ try _mergeRuns (
633630 & runs, at: runs. count - 1 , buffer: buffer, by: areInIncreasingOrder)
634631 }
635- return result
632+
633+ return true
636634 }
637635
638636 /// Sorts the elements of this buffer according to `areInIncreasingOrder`,
@@ -651,9 +649,6 @@ extension UnsafeMutableBufferPointer {
651649 return
652650 }
653651
654- // FIXME: Remove this, it works around SR-14750 (rdar://45044610)
655- var result = true
656-
657652 // Use array's allocating initializer to create a temporary buffer---this
658653 // keeps the buffer allocation going through the same tail-allocated path
659654 // as other allocating methods.
@@ -685,17 +680,14 @@ extension UnsafeMutableBufferPointer {
685680 // Append this run and merge down as needed to maintain the `runs`
686681 // invariants.
687682 runs. append ( start..< end)
688- result = try result && _mergeTopRuns (
683+ try _mergeTopRuns (
689684 & runs, buffer: buffer. baseAddress!, by: areInIncreasingOrder)
690685 start = end
691686 }
692687
693- result = try result && _finalizeRuns (
688+ try _finalizeRuns (
694689 & runs, buffer: buffer. baseAddress!, by: areInIncreasingOrder)
695690 _internalInvariant ( runs. count == 1 , " Didn't complete final merge " )
696691 }
697-
698- // FIXME: Remove this, it works around SR-14750 (rdar://45044610)
699- _precondition ( result)
700692 }
701693}
0 commit comments