Skip to content

[Swiftify] Don't use count from Span inside withUnsafeBufferPointer call #81267

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

Merged
merged 3 commits into from
May 4, 2025

Conversation

hnrklssn
Copy link
Contributor

@hnrklssn hnrklssn commented May 3, 2025

Given a call like: ptr.withUnsafeBufferPointer { _ptrPtr in ... } ptr.count and _ptrPtr.count both contain the same value, but when ptr is a MutableSpan we get an error when referring to ptr inside a call to withUnsafeMutableBufferPointer, so we should use _ptrPtr.count instead.

rdar://150551109

Given a call like: `ptr.withUnsafeBufferPointer { _ptrPtr in ... }`
`ptr.count` and `_ptrPtr.count` both contain the same value, but when
`ptr` is a `MutableSpan` we get an error when referring to `ptr` inside
a call to `withUnsafeMutableBufferPointer`, so we should use
`_ptrPtr.count` instead.

rdar://150551109
@hnrklssn hnrklssn requested review from DougGregor and rapidsna May 3, 2025 00:23
@hnrklssn hnrklssn requested a review from Xazax-hun as a code owner May 3, 2025 00:23
@hnrklssn
Copy link
Contributor Author

hnrklssn commented May 3, 2025

@swift-ci please smoke test

This improves the test coverage, most relevantly for MutableSpan, where
some lifetime errors are not emitted unless the function is actually
called.
std::span imports already have _cxxOverrideLifetime for their return
values. __counted_by needs the same, but Cxx may not be available at the
macro site, so we introduce _swiftifyOverrideLifetime in SwiftifyImport.

rdar://150569220
@hnrklssn
Copy link
Contributor Author

hnrklssn commented May 3, 2025

@swift-ci please smoke test

@hnrklssn hnrklssn enabled auto-merge (squash) May 3, 2025 06:39
@hnrklssn
Copy link
Contributor Author

hnrklssn commented May 4, 2025

@swift-ci please smoke test windows

@hnrklssn hnrklssn merged commit bd233ea into swiftlang:main May 4, 2025
3 checks passed
hnrklssn added a commit to hnrklssn/swift that referenced this pull request May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants