[swift-evolution] Proposed amendment to SE-0138: Normalize UnsafeRawBufferPointer Slices

Andrew Trick atrick at apple.com
Mon Mar 20 21:21:21 CDT 2017


This proposal amends SE-0138: Normalize UnsafeRawBufferPointer Slices
to fix a design bug: https://github.com/apple/swift-evolution/pull/651

The issue was discussed on swift-evolution in Nov/Dec:
See [swift-evolution] [Pitch] Normalize Slice Types for Unsafe Buffers
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20161128/029108.html

The implementation of this fix is in PR #8222:
https://github.com/apple/swift/pull/8222

Fix: Change Unsafe[Mutable]RawBufferPointer's SubSequence type

Original: Unsafe[Mutable]RawBufferPointer.SubSequence = Unsafe[Mutable]RawBufferPointer

Fixed: Unsafe[Mutable]RawBufferPointer.SubSequence = [Mutable]RandomAccessSlice<Unsafe[Mutable]RawBufferPointer>

This is a source breaking bug fix that only applies to
post-3.0.1. It's extremely unlikely that any Swift 3 code would rely
on the SubSequence type beyond the simple use case of passing a
raw buffer subrange to an another raw buffer argument:

`takesRawBuffer(buffer[i..<j])`

A diagnostic message now instructs users to convert the slice to a
buffer using a `rebasing` initializer:

`takesRawBuffer(UnsafeRawBufferPointer(rebasing: buffer[i..<j]))`

To support this, the following `rebasing` initializers are added:

extension UnsafeRawBufferPointer {
  public init(rebasing slice: RandomAccessSlice<UnsafeRawBufferPointer>)
  public init(
    rebasing slice: MutableRandomAccessSlice<UnsafeMutableRawBufferPointer>
  )
}

extension UnsafeMutableRawBufferPointer {
  public init(
    rebasing slice: MutableRandomAccessSlice<UnsafeMutableRawBufferPointer>
  )
}

The source compatibility test builds are unnaffected by this change.

-Andy


More information about the swift-evolution mailing list