Skip to content

Commit fa87b3b

Browse files
committed
[stdlib] remove bulk-update from MutableRawSpan per SE-0485
1 parent 923a6e5 commit fa87b3b

File tree

2 files changed

+0
-206
lines changed

2 files changed

+0
-206
lines changed

stdlib/public/core/Span/MutableRawSpan.swift

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -360,108 +360,6 @@ extension MutableRawSpan {
360360
}
361361
}
362362

363-
// FIXME: The functions in this extension crash the SIL optimizer when built inside
364-
// the stub. But these declarations don't generate a public symbol anyway.
365-
#if !SPAN_COMPATIBILITY_STUB
366-
367-
//MARK: copyMemory
368-
@available(SwiftCompatibilitySpan 5.0, *)
369-
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
370-
extension MutableRawSpan {
371-
372-
@_alwaysEmitIntoClient
373-
@lifetime(self: copy self)
374-
public mutating func update<S: Sequence>(
375-
from source: S
376-
) -> (unwritten: S.Iterator, byteOffset: Int) where S.Element: BitwiseCopyable {
377-
var iterator = source.makeIterator()
378-
let offset = update(from: &iterator)
379-
return (iterator, offset)
380-
}
381-
382-
@_alwaysEmitIntoClient
383-
@lifetime(self: copy self)
384-
public mutating func update<Element: BitwiseCopyable>(
385-
from elements: inout some IteratorProtocol<Element>
386-
) -> Int {
387-
var offset = 0
388-
while offset + MemoryLayout<Element>.stride <= _count {
389-
guard let element = elements.next() else { break }
390-
unsafe storeBytes(
391-
of: element, toUncheckedByteOffset: offset, as: Element.self
392-
)
393-
offset &+= MemoryLayout<Element>.stride
394-
}
395-
return offset
396-
}
397-
398-
@_alwaysEmitIntoClient
399-
@lifetime(self: copy self)
400-
public mutating func update<C: Collection>(
401-
fromContentsOf source: C
402-
) -> Int where C.Element: BitwiseCopyable {
403-
let newOffset = source.withContiguousStorageIfAvailable {
404-
self.update(fromContentsOf: unsafe RawSpan(_unsafeElements: $0))
405-
}
406-
if let newOffset { return newOffset }
407-
408-
var elements = source.makeIterator()
409-
let lastOffset = update(from: &elements)
410-
_precondition(
411-
elements.next() == nil,
412-
"destination span cannot contain every element from source."
413-
)
414-
return lastOffset
415-
}
416-
417-
@_alwaysEmitIntoClient
418-
@lifetime(self: copy self)
419-
public mutating func update<Element: BitwiseCopyable>(
420-
fromContentsOf source: Span<Element>
421-
) -> Int {
422-
// update(from: source.bytes)
423-
unsafe source.withUnsafeBytes {
424-
unsafe update(fromContentsOf: $0)
425-
}
426-
}
427-
428-
@_alwaysEmitIntoClient
429-
@lifetime(self: copy self)
430-
public mutating func update<Element: BitwiseCopyable>(
431-
fromContentsOf source: borrowing MutableSpan<Element>
432-
) -> Int {
433-
// update(from: source.span.bytes)
434-
unsafe source.withUnsafeBytes {
435-
unsafe update(fromContentsOf: $0)
436-
}
437-
}
438-
439-
@_alwaysEmitIntoClient
440-
@lifetime(self: copy self)
441-
public mutating func update(
442-
fromContentsOf source: RawSpan
443-
) -> Int {
444-
_precondition(
445-
source.byteCount <= self.byteCount,
446-
"destination span cannot contain every byte from source."
447-
)
448-
if source.byteCount == 0 { return 0 }
449-
unsafe source.withUnsafeBytes {
450-
unsafe _start().copyMemory(from: $0.baseAddress!, byteCount: $0.count)
451-
}
452-
return source.byteCount
453-
}
454-
455-
@_alwaysEmitIntoClient
456-
@lifetime(self: copy self)
457-
public mutating func update(
458-
fromContentsOf source: borrowing MutableRawSpan
459-
) -> Int {
460-
update(fromContentsOf: source.bytes)
461-
}
462-
}
463-
#endif
464-
465363
// MARK: sub-spans
466364
@available(SwiftCompatibilitySpan 5.0, *)
467365
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)

test/stdlib/Span/MutableRawSpanTests.swift

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -281,110 +281,6 @@ suite.test("storeBytes(of:as:)")
281281
expectEqual(a[0].bigEndian & 0xffff, 0xffff)
282282
}
283283

284-
suite.test("update(from: some Sequence<some BitwiseCopyable>)")
285-
.skip(.custom(
286-
{ if #available(SwiftStdlib 6.2, *) { false } else { true } },
287-
reason: "Requires Swift 6.2's standard library"
288-
))
289-
.code {
290-
guard #available(SwiftStdlib 6.2, *) else { return }
291-
292-
let capacity = 8
293-
var a = Array(repeating: Int.max, count: capacity)
294-
expectEqual(a.allSatisfy({ $0 == .max }), true)
295-
a.withUnsafeMutableBufferPointer {
296-
let empty = UnsafeMutableBufferPointer<Int>(start: nil, count: 0)
297-
var span = MutableRawSpan(_unsafeElements: empty)
298-
var (iterator, updated) = span.update(from: 0..<0)
299-
expectNil(iterator.next())
300-
expectEqual(updated, 0)
301-
302-
span = MutableRawSpan(_unsafeElements: $0)
303-
(iterator, updated) = span.update(from: 0..<0)
304-
expectNil(iterator.next())
305-
expectEqual(updated, 0)
306-
307-
(iterator, updated) = span.update(from: 0..<10000)
308-
expectNotNil(iterator.next())
309-
expectEqual(updated, capacity*MemoryLayout<Int>.stride)
310-
}
311-
expectEqual(a.elementsEqual(0..<capacity), true)
312-
}
313-
314-
suite.test("update(from: some Collection<some BitwiseCopyable>)")
315-
.skip(.custom(
316-
{ if #available(SwiftStdlib 6.2, *) { false } else { true } },
317-
reason: "Requires Swift 6.2's standard library"
318-
))
319-
.code {
320-
guard #available(SwiftStdlib 6.2, *) else { return }
321-
322-
let capacity = 8
323-
var a = Array(repeating: Int.max, count: capacity)
324-
let e = Array(EmptyCollection<UInt>())
325-
expectEqual(a.allSatisfy({ $0 == .max }), true)
326-
a.withUnsafeMutableBytes {
327-
let emptyPrefix = $0.prefix(0)
328-
var span = MutableRawSpan(_unsafeBytes: emptyPrefix)
329-
var updated = span.update(fromContentsOf: e)
330-
expectEqual(updated, 0)
331-
332-
333-
updated = span.update(fromContentsOf: AnyCollection(e))
334-
expectEqual(updated, 0)
335-
336-
span = MutableRawSpan(_unsafeBytes: $0)
337-
updated = span.update(fromContentsOf: 0..<capacity)
338-
expectEqual(updated, capacity*MemoryLayout<Int>.stride)
339-
}
340-
expectEqual(a.elementsEqual(0..<capacity), true)
341-
}
342-
343-
suite.test("update(fromContentsOf:) (contiguous memory)")
344-
.skip(.custom(
345-
{ if #available(SwiftStdlib 6.2, *) { false } else { true } },
346-
reason: "Requires Swift 6.2's standard library"
347-
))
348-
.code {
349-
guard #available(SwiftStdlib 6.2, *) else { return }
350-
351-
let capacity = 8
352-
var a = Array(repeating: Int.max, count: capacity)
353-
expectEqual(a.allSatisfy({ $0 == .max }), true)
354-
a.withUnsafeMutableBytes {
355-
var span = MutableRawSpan(_unsafeBytes: $0)
356-
let array = Array(0..<capacity)
357-
var updated = span.update(fromContentsOf: array.prefix(0))
358-
expectEqual(updated, 0)
359-
360-
updated = span.update(fromContentsOf: array)
361-
expectEqual(updated, capacity*MemoryLayout<Int>.stride)
362-
}
363-
expectEqual(a.elementsEqual(0..<capacity), true)
364-
365-
a.withUnsafeMutableBytes {
366-
var span = MutableRawSpan(_unsafeBytes: $0)
367-
var array = Array(repeating: Int.min, count: capacity)
368-
array.withUnsafeMutableBytes {
369-
let source = MutableRawSpan(_unsafeBytes: $0)
370-
let updated = span.update(fromContentsOf: source)
371-
expectEqual(updated, capacity*MemoryLayout<Int>.stride)
372-
}
373-
}
374-
expectEqual(a.allSatisfy({ $0 == Int.min }), true)
375-
376-
a.withUnsafeMutableBytes {
377-
var span = MutableRawSpan(_unsafeBytes: $0)
378-
let array = Array(0..<capacity)
379-
array.withUnsafeBufferPointer {
380-
let source = Span(_unsafeElements: $0)
381-
let updated = span.update(fromContentsOf: source)
382-
expectEqual(updated, capacity*MemoryLayout<Int>.stride)
383-
}
384-
}
385-
expectEqual(a.elementsEqual(0..<capacity), true)
386-
}
387-
388284
suite.test("_mutatingExtracting()")
389285
.skip(.custom(
390286
{ if #available(SwiftStdlib 6.2, *) { false } else { true } },

0 commit comments

Comments
 (0)