-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SE-0456] Span properties #78561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SE-0456] Span properties #78561
Changes from all commits
13cdfaa
85b53bb
9cdd83b
3863b81
acdfb37
7bbb834
a5e04e0
264747a
d0d5285
d6ab6d0
7188d0b
afb627d
83dc08d
39b4303
063b058
0e1d207
2980878
3d6070d
96e9945
940628a
35b8514
d5cb7dd
31daf5c
7b03593
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ public struct RawSpan: ~Escapable, Copyable, BitwiseCopyable { | |
@usableFromInline | ||
internal let _pointer: UnsafeRawPointer? | ||
|
||
@unsafe | ||
@_alwaysEmitIntoClient | ||
internal func _start() -> UnsafeRawPointer { | ||
unsafe _pointer._unsafelyUnwrappedUnchecked | ||
|
@@ -309,14 +310,17 @@ extension RawSpan { | |
/// - span: An existing `Span<T>`, which will define both this | ||
/// `RawSpan`'s lifetime and the memory it represents. | ||
@_alwaysEmitIntoClient | ||
@lifetime(borrow span) | ||
@lifetime(copy span) | ||
public init<Element: BitwiseCopyable>( | ||
_elements span: borrowing Span<Element> | ||
_elements span: Span<Element> | ||
) { | ||
unsafe self.init( | ||
_unchecked: span._pointer, | ||
byteCount: span.count &* MemoryLayout<Element>.stride | ||
let pointer = span._pointer | ||
let rawSpan = unsafe RawSpan( | ||
_unchecked: pointer, | ||
byteCount: span.count == 1 ? MemoryLayout<Element>.size | ||
: span.count &* MemoryLayout<Element>.stride | ||
Comment on lines
+320
to
+321
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is correct then other APIs may need to be updated:
Alternatively, perhaps There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea here is that safely converting a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The same issue could affect nonempty let one: StaticString = ""
let two: (StaticString, StaticString) = ("", "")
withUnsafePointer(to: one) { start in
let buffer = UnsafeBufferPointer(start: start, count: 1)
return buffer.span.bytes.byteCount //-> either 17 or 24.
}
withUnsafePointer(to: two) { start in
let start = start.pointer(to: \.0)
let buffer = UnsafeBufferPointer(start: start, count: 2)
return buffer.span.bytes.byteCount //-> either 41 or 48.
} Should the padding after the last element always be excluded? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using tuples in this way is incorrect and always has been, because of that padding issue. The buffer in the |
||
) | ||
self = unsafe _overrideLifetime(rawSpan, copying: span) | ||
} | ||
} | ||
|
||
|
@@ -440,7 +444,7 @@ extension RawSpan { | |
public func _extracting( | ||
unchecked bounds: ClosedRange<Int> | ||
) -> Self { | ||
let range = Range( | ||
let range = unsafe Range( | ||
_uncheckedBounds: (bounds.lowerBound, bounds.upperBound + 1) | ||
) | ||
return unsafe _extracting(unchecked: range) | ||
|
@@ -663,7 +667,7 @@ extension RawSpan { | |
guard let spanStart = other._pointer, _count > 0 else { | ||
return unsafe _pointer == other._pointer ? 0..<0 : nil | ||
} | ||
let start = _start() | ||
let start = unsafe _start() | ||
let spanEnd = unsafe spanStart + other._count | ||
if unsafe spanStart < start || (start + _count) < spanEnd { return nil } | ||
let lower = unsafe start.distance(to: spanStart) | ||
|
Uh oh!
There was an error while loading. Please reload this page.