Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions stdlib/public/core/Span/MutableSpan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ extension MutableSpan where Element: ~Copyable {
extension MutableSpan where Element: ~Copyable {

@_alwaysEmitIntoClient
@_semantics("fixed_storage.get_count")
public var count: Int { _assumeNonNegative(_count) }

@_alwaysEmitIntoClient
Expand Down Expand Up @@ -279,7 +280,13 @@ extension MutableSpan where Element: BitwiseCopyable {
@available(SwiftCompatibilitySpan 5.0, *)
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
extension MutableSpan where Element: ~Copyable {

// SILOptimizer looks for fixed_storage.check_index semantics for bounds check optimizations.
@_semantics("fixed_storage.check_index")
@inline(__always)
@_alwaysEmitIntoClient
internal func _checkIndex(_ position: Index) {
_precondition(indices.contains(position), "index out of bounds")
}
/// Accesses the element at the specified position in the `MutableSpan`.
///
/// - Parameter position: The offset of the element to access. `position`
Expand All @@ -289,12 +296,12 @@ extension MutableSpan where Element: ~Copyable {
@_alwaysEmitIntoClient
public subscript(_ position: Index) -> Element {
unsafeAddress {
_precondition(indices.contains(position), "index out of bounds")
_checkIndex(position)
return unsafe UnsafePointer(_unsafeAddressOfElement(unchecked: position))
}
@lifetime(self: copy self)
unsafeMutableAddress {
_precondition(indices.contains(position), "index out of bounds")
_checkIndex(position)
return unsafe _unsafeAddressOfElement(unchecked: position)
}
}
Expand Down
13 changes: 11 additions & 2 deletions stdlib/public/core/Span/OutputSpan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ extension OutputSpan where Element: ~Copyable {
extension OutputSpan where Element: ~Copyable {
/// The number of initialized elements in this span.
@_alwaysEmitIntoClient
@_semantics("fixed_storage.get_count")
public var count: Int { _count }

/// The number of additional elements that can be added to this span.
Expand Down Expand Up @@ -193,6 +194,14 @@ extension OutputSpan where Element: ~Copyable {
unsafe Range(_uncheckedBounds: (0, _count))
}

// SILOptimizer looks for fixed_storage.check_index semantics for bounds check optimizations.
@_semantics("fixed_storage.check_index")
@inline(__always)
@_alwaysEmitIntoClient
internal func _checkIndex(_ index: Index) {
_precondition(indices.contains(index), "Index out of bounds")
}

/// Accesses the element at the specified position.
///
/// - Parameter index: A valid index into this span.
Expand All @@ -201,12 +210,12 @@ extension OutputSpan where Element: ~Copyable {
@_alwaysEmitIntoClient
public subscript(_ index: Index) -> Element {
unsafeAddress {
_precondition(indices.contains(index), "index out of bounds")
_checkIndex(index)
return unsafe UnsafePointer(_unsafeAddressOfElement(unchecked: index))
}
@lifetime(self: copy self)
unsafeMutableAddress {
_precondition(indices.contains(index), "index out of bounds")
_checkIndex(index)
return unsafe _unsafeAddressOfElement(unchecked: index)
}
}
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/core/Span/Span.swift
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ extension Span where Element: ~Copyable {
@available(SwiftCompatibilitySpan 5.0, *)
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
extension Span where Element: ~Copyable {
// SILOptimizer looks for fixed_storage.check_index semantics for bounds check optimizations.
@_semantics("fixed_storage.check_index")
@inline(__always)
@_alwaysEmitIntoClient
Expand Down
Loading