From 505d55c4d124ab307f61e55c85cb035516e4800e Mon Sep 17 00:00:00 2001 From: Valeriy Van Date: Mon, 9 Jun 2025 11:54:44 +0300 Subject: [PATCH 1/7] Add type parameter to make code match doc comment --- stdlib/public/core/Span/MutableRawSpan.swift | 8 ++++---- stdlib/public/core/Span/RawSpan.swift | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/stdlib/public/core/Span/MutableRawSpan.swift b/stdlib/public/core/Span/MutableRawSpan.swift index 47c4aa7d43308..764d1827c1a58 100644 --- a/stdlib/public/core/Span/MutableRawSpan.swift +++ b/stdlib/public/core/Span/MutableRawSpan.swift @@ -238,7 +238,7 @@ extension MutableRawSpan { @unsafe @_alwaysEmitIntoClient public func unsafeLoad( - fromByteOffset offset: Int = 0, as: T.Type + fromByteOffset offset: Int = 0, as type: T.Type ) -> T { _precondition( UInt(bitPattern: offset) <= UInt(bitPattern: _count) && @@ -269,7 +269,7 @@ extension MutableRawSpan { @unsafe @_alwaysEmitIntoClient public func unsafeLoad( - fromUncheckedByteOffset offset: Int, as: T.Type + fromUncheckedByteOffset offset: Int, as type: T.Type ) -> T { unsafe _start().load(fromByteOffset: offset, as: T.self) } @@ -293,7 +293,7 @@ extension MutableRawSpan { @unsafe @_alwaysEmitIntoClient public func unsafeLoadUnaligned( - fromByteOffset offset: Int = 0, as: T.Type + fromByteOffset offset: Int = 0, as type: T.Type ) -> T { _precondition( UInt(bitPattern: offset) <= UInt(bitPattern: _count) && @@ -323,7 +323,7 @@ extension MutableRawSpan { @unsafe @_alwaysEmitIntoClient public func unsafeLoadUnaligned( - fromUncheckedByteOffset offset: Int, as: T.Type + fromUncheckedByteOffset offset: Int, as type: T.Type ) -> T { unsafe _start().loadUnaligned(fromByteOffset: offset, as: T.self) } diff --git a/stdlib/public/core/Span/RawSpan.swift b/stdlib/public/core/Span/RawSpan.swift index c2e33896aef90..30308665d155d 100644 --- a/stdlib/public/core/Span/RawSpan.swift +++ b/stdlib/public/core/Span/RawSpan.swift @@ -561,7 +561,7 @@ extension RawSpan { @unsafe @_alwaysEmitIntoClient public func unsafeLoad( - fromByteOffset offset: Int = 0, as: T.Type + fromByteOffset offset: Int = 0, as type: T.Type ) -> T { _precondition( UInt(bitPattern: offset) <= UInt(bitPattern: _count) && @@ -592,7 +592,7 @@ extension RawSpan { @unsafe @_alwaysEmitIntoClient public func unsafeLoad( - fromUncheckedByteOffset offset: Int, as: T.Type + fromUncheckedByteOffset offset: Int, as type: T.Type ) -> T { unsafe _start().load(fromByteOffset: offset, as: T.self) } @@ -616,7 +616,7 @@ extension RawSpan { @unsafe @_alwaysEmitIntoClient public func unsafeLoadUnaligned( - fromByteOffset offset: Int = 0, as: T.Type + fromByteOffset offset: Int = 0, as type: T.Type ) -> T { _precondition( UInt(bitPattern: offset) <= UInt(bitPattern: _count) && @@ -648,7 +648,7 @@ extension RawSpan { @unsafe @_alwaysEmitIntoClient public func unsafeLoadUnaligned( - fromUncheckedByteOffset offset: Int, as: T.Type + fromUncheckedByteOffset offset: Int, as type: T.Type ) -> T { unsafe _start().loadUnaligned(fromByteOffset: offset, as: T.self) } From 4129383ba772dbb5e823d524455a70c4ecd1e84c Mon Sep 17 00:00:00 2001 From: Valeriy Van Date: Mon, 9 Jun 2025 11:56:06 +0300 Subject: [PATCH 2/7] Rename parameter count => byteCount to make signature match doc comment and match other methods --- stdlib/public/core/Span/RawSpan.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/public/core/Span/RawSpan.swift b/stdlib/public/core/Span/RawSpan.swift index 30308665d155d..846f89fdc0f8c 100644 --- a/stdlib/public/core/Span/RawSpan.swift +++ b/stdlib/public/core/Span/RawSpan.swift @@ -301,11 +301,11 @@ extension RawSpan { @lifetime(borrow pointer) public init( _unsafeStart pointer: UnsafePointer, - count: Int + byteCount: Int ) { - _precondition(count >= 0, "Count must not be negative") + _precondition(byteCount >= 0, "Count must not be negative") unsafe self.init( - _unchecked: pointer, byteCount: count * MemoryLayout.stride + _unchecked: pointer, byteCount: byteCount * MemoryLayout.stride ) } From 43ead66f42db906a073f8ee776ef5097fb21339e Mon Sep 17 00:00:00 2001 From: Valeriy Van Date: Mon, 9 Jun 2025 11:56:45 +0300 Subject: [PATCH 3/7] Fix doc comment --- stdlib/public/core/Span/RawSpan.swift | 10 +++++----- stdlib/public/core/Span/Span.swift | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/stdlib/public/core/Span/RawSpan.swift b/stdlib/public/core/Span/RawSpan.swift index 846f89fdc0f8c..ba5c676a5cf95 100644 --- a/stdlib/public/core/Span/RawSpan.swift +++ b/stdlib/public/core/Span/RawSpan.swift @@ -664,14 +664,14 @@ extension RawSpan { unsafe (self._pointer == other._pointer) && (self._count == other._count) } - /// Returns the offsets where the memory of `span` is located within + /// Returns the offsets where the memory of `other` is located within /// the memory represented by `self` /// - /// Note: `span` must be a subrange of `self` + /// Note: `other` must be a subrange of `self` /// - /// Parameters: - /// - span: a subrange of `self` - /// Returns: A range of offsets within `self` + /// - Parameters: + /// - other: a subrange of `self` + /// - Returns: A range of offsets within `self` @_alwaysEmitIntoClient public func byteOffsets(of other: borrowing Self) -> Range? { if other._count > _count { return nil } diff --git a/stdlib/public/core/Span/Span.swift b/stdlib/public/core/Span/Span.swift index 004180a3a5fde..2332df0e2d18f 100644 --- a/stdlib/public/core/Span/Span.swift +++ b/stdlib/public/core/Span/Span.swift @@ -714,12 +714,12 @@ extension Span where Element: ~Copyable { unsafe (self._pointer == other._pointer) && (self._count == other._count) } - /// Returns the indices within `self` where the memory represented by `span` - /// is located, or `nil` if `span` is not located within `self`. + /// Returns the indices within `self` where the memory represented by `other` + /// is located, or `nil` if `other` is not located within `self`. /// - /// Parameters: - /// - span: a span that may be a subrange of `self` - /// Returns: A range of indices within `self`, or `nil` + /// - Parameters: + /// - other: a span that may be a subrange of `self` + /// - Returns: A range of indices within `self`, or `nil` @_alwaysEmitIntoClient public func indices(of other: borrowing Self) -> Range? { if other._count > _count { return nil } From 1c0306871c92b8cd9edb4df5cae07c0d4cc0a537 Mon Sep 17 00:00:00 2001 From: Valeriy Van Date: Mon, 9 Jun 2025 17:59:13 +0300 Subject: [PATCH 4/7] Revert "Rename parameter count => byteCount to make signature match doc comment and match other methods" This reverts commit 4129383ba772dbb5e823d524455a70c4ecd1e84c. --- stdlib/public/core/Span/RawSpan.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/public/core/Span/RawSpan.swift b/stdlib/public/core/Span/RawSpan.swift index ba5c676a5cf95..02e322cf45eff 100644 --- a/stdlib/public/core/Span/RawSpan.swift +++ b/stdlib/public/core/Span/RawSpan.swift @@ -301,11 +301,11 @@ extension RawSpan { @lifetime(borrow pointer) public init( _unsafeStart pointer: UnsafePointer, - byteCount: Int + count: Int ) { - _precondition(byteCount >= 0, "Count must not be negative") + _precondition(count >= 0, "Count must not be negative") unsafe self.init( - _unchecked: pointer, byteCount: byteCount * MemoryLayout.stride + _unchecked: pointer, byteCount: count * MemoryLayout.stride ) } From 83d3d4b3cbb60b3a40a302e6152575dad06ecf19 Mon Sep 17 00:00:00 2001 From: Valeriy Van Date: Mon, 9 Jun 2025 18:01:36 +0300 Subject: [PATCH 5/7] Fix doc comment --- stdlib/public/core/Span/RawSpan.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/public/core/Span/RawSpan.swift b/stdlib/public/core/Span/RawSpan.swift index 02e322cf45eff..bb1fecd9d81d2 100644 --- a/stdlib/public/core/Span/RawSpan.swift +++ b/stdlib/public/core/Span/RawSpan.swift @@ -288,14 +288,14 @@ extension RawSpan { /// Unsafely create a `RawSpan` over initialized memory. /// - /// The region of memory representing `byteCount` bytes starting at `pointer` + /// The region of memory representing `count` bytes starting at `pointer` /// must remain valid, initialized and immutable /// throughout the lifetime of the newly-created `RawSpan`. /// Failure to maintain this invariant results in undefined behaviour. /// /// - Parameters: /// - pointer: a pointer to the first initialized byte. - /// - byteCount: the number of initialized bytes in the span. + /// - count: the number of initialized bytes in the span. @unsafe @_alwaysEmitIntoClient @lifetime(borrow pointer) From e49050a42a707f5a196613ea767837a1f552aa84 Mon Sep 17 00:00:00 2001 From: Valeriy Van Date: Mon, 9 Jun 2025 20:14:25 +0300 Subject: [PATCH 6/7] Update stdlib/public/core/Span/RawSpan.swift Co-authored-by: Guillaume Lessard --- stdlib/public/core/Span/RawSpan.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/public/core/Span/RawSpan.swift b/stdlib/public/core/Span/RawSpan.swift index bb1fecd9d81d2..ad0eb970f4a7a 100644 --- a/stdlib/public/core/Span/RawSpan.swift +++ b/stdlib/public/core/Span/RawSpan.swift @@ -288,7 +288,7 @@ extension RawSpan { /// Unsafely create a `RawSpan` over initialized memory. /// - /// The region of memory representing `count` bytes starting at `pointer` + /// The region of memory representing `count` elements starting at `pointer` /// must remain valid, initialized and immutable /// throughout the lifetime of the newly-created `RawSpan`. /// Failure to maintain this invariant results in undefined behaviour. From b1082d400f73588167739546a77b41bf060c11f6 Mon Sep 17 00:00:00 2001 From: Valeriy Van Date: Mon, 9 Jun 2025 20:14:46 +0300 Subject: [PATCH 7/7] Update stdlib/public/core/Span/RawSpan.swift Co-authored-by: Guillaume Lessard --- stdlib/public/core/Span/RawSpan.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/public/core/Span/RawSpan.swift b/stdlib/public/core/Span/RawSpan.swift index ad0eb970f4a7a..18dc397f7d6e1 100644 --- a/stdlib/public/core/Span/RawSpan.swift +++ b/stdlib/public/core/Span/RawSpan.swift @@ -295,7 +295,7 @@ extension RawSpan { /// /// - Parameters: /// - pointer: a pointer to the first initialized byte. - /// - count: the number of initialized bytes in the span. + /// - count: the number of initialized elements in the span. @unsafe @_alwaysEmitIntoClient @lifetime(borrow pointer)