Skip to content

Commit a08a87b

Browse files
authored
Merge pull request #81289 from DougGregor/mutablespan-older-compilers
Fix issue with older compilers not handling MutableSpan code
2 parents 63ee0a4 + f04e916 commit a08a87b

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

stdlib/public/core/Span/MutableRawSpan.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,10 +588,14 @@ extension MutableRawSpan {
588588
@_alwaysEmitIntoClient
589589
@lifetime(&self)
590590
mutating public func extracting(first maxLength: Int) -> Self {
591+
#if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
591592
_precondition(maxLength >= 0, "Can't have a prefix of negative length")
592593
let newCount = min(maxLength, byteCount)
593594
let newSpan = unsafe Self(_unchecked: _pointer, byteCount: newCount)
594595
return unsafe _overrideLifetime(newSpan, mutating: &self)
596+
#else
597+
fatalError("Unsupported compiler")
598+
#endif
595599
}
596600

597601
/// Returns a span over all but the given number of trailing elements.
@@ -611,11 +615,15 @@ extension MutableRawSpan {
611615
@_alwaysEmitIntoClient
612616
@lifetime(&self)
613617
mutating public func extracting(droppingLast k: Int) -> Self {
618+
#if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
614619
_precondition(k >= 0, "Can't drop a negative number of elements")
615620
let droppedCount = min(k, byteCount)
616621
let newCount = byteCount &- droppedCount
617622
let newSpan = unsafe Self(_unchecked: _pointer, byteCount: newCount)
618623
return unsafe _overrideLifetime(newSpan, mutating: &self)
624+
#else
625+
fatalError("Unsupported compiler")
626+
#endif
619627
}
620628

621629
/// Returns a span containing the final elements of the span,
@@ -660,11 +668,15 @@ extension MutableRawSpan {
660668
@_alwaysEmitIntoClient
661669
@lifetime(&self)
662670
mutating public func extracting(droppingFirst k: Int) -> Self {
671+
#if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
663672
_precondition(k >= 0, "Can't drop a negative number of bytes")
664673
let droppedCount = min(k, byteCount)
665674
let newStart = unsafe _pointer?.advanced(by: droppedCount)
666675
let newCount = byteCount &- droppedCount
667676
let newSpan = unsafe Self(_unchecked: newStart, byteCount: newCount)
668677
return unsafe _overrideLifetime(newSpan, mutating: &self)
678+
#else
679+
fatalError("Unsupported compiler")
680+
#endif
669681
}
670682
}

stdlib/public/core/Span/MutableSpan.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,10 +825,14 @@ extension MutableSpan where Element: ~Copyable {
825825
@_alwaysEmitIntoClient
826826
@lifetime(&self)
827827
mutating public func extracting(first maxLength: Int) -> Self {
828+
#if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
828829
_precondition(maxLength >= 0, "Can't have a prefix of negative length")
829830
let newCount = min(maxLength, count)
830831
let newSpan = unsafe Self(_unchecked: _pointer, count: newCount)
831832
return unsafe _overrideLifetime(newSpan, mutating: &self)
833+
#else
834+
fatalError("Unsupported compiler")
835+
#endif
832836
}
833837

834838
/// Returns a span over all but the given number of trailing elements.
@@ -848,11 +852,15 @@ extension MutableSpan where Element: ~Copyable {
848852
@_alwaysEmitIntoClient
849853
@lifetime(&self)
850854
mutating public func extracting(droppingLast k: Int) -> Self {
855+
#if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
851856
_precondition(k >= 0, "Can't drop a negative number of elements")
852857
let droppedCount = min(k, count)
853858
let newCount = count &- droppedCount
854859
let newSpan = unsafe Self(_unchecked: _pointer, count: newCount)
855860
return unsafe _overrideLifetime(newSpan, mutating: &self)
861+
#else
862+
fatalError("Unsupported compiler")
863+
#endif
856864
}
857865

858866
/// Returns a span containing the final elements of the span,
@@ -873,12 +881,16 @@ extension MutableSpan where Element: ~Copyable {
873881
@_alwaysEmitIntoClient
874882
@lifetime(&self)
875883
mutating public func extracting(last maxLength: Int) -> Self {
884+
#if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
876885
_precondition(maxLength >= 0, "Can't have a suffix of negative length")
877886
let newCount = min(maxLength, count)
878887
let offset = (count &- newCount) * MemoryLayout<Element>.stride
879888
let newStart = unsafe _pointer?.advanced(by: offset)
880889
let newSpan = unsafe Self(_unchecked: newStart, count: newCount)
881890
return unsafe _overrideLifetime(newSpan, mutating: &self)
891+
#else
892+
fatalError("Unsupported compiler")
893+
#endif
882894
}
883895

884896
/// Returns a span over all but the given number of initial elements.
@@ -898,12 +910,16 @@ extension MutableSpan where Element: ~Copyable {
898910
@_alwaysEmitIntoClient
899911
@lifetime(&self)
900912
mutating public func extracting(droppingFirst k: Int) -> Self {
913+
#if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
901914
_precondition(k >= 0, "Can't drop a negative number of elements")
902915
let droppedCount = min(k, count)
903916
let offset = droppedCount * MemoryLayout<Element>.stride
904917
let newStart = unsafe _pointer?.advanced(by: offset)
905918
let newCount = count &- droppedCount
906919
let newSpan = unsafe Self(_unchecked: newStart, count: newCount)
907920
return unsafe _overrideLifetime(newSpan, mutating: &self)
921+
#else
922+
fatalError("Unsupported compiler")
923+
#endif
908924
}
909925
}

0 commit comments

Comments
 (0)