-
Notifications
You must be signed in to change notification settings - Fork 10.5k
SE-0333: Expand usability of withMemoryRebound
#39529
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
Conversation
483dcf6
to
712918c
Compare
f072d4b
to
23fa269
Compare
7753049
to
cc85b89
Compare
- updated documentation and adjust implementations
cc85b89
to
b850838
Compare
withMemoryRebound
withMemoryRebound
withMemoryRebound
withMemoryRebound
b850838
to
133222d
Compare
@swift-ci please test |
withMemoryRebound
withMemoryRebound
@swift-ci please test |
16cca8c
to
5c29236
Compare
/// - Returns: The return value, if any, of the `body` closure parameter. | ||
@inlinable // unsafe-performance | ||
@_alwaysEmitIntoClient | ||
% if Mutable: | ||
@_silgen_name("$_swift_UnsafeMutableBufferPointer_se0333_withMemoryRebound") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These getting-out-of-the-way silgen names are a new thing in the stdlib, as far as I can tell.
Is this naming scheme reasonable? Too fussy?
This is likely to be the precedent for other similar actions in the future, so agreement is desirable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that these names are fine; I like that they explicitly point to the proposal for reference.
% else: | ||
@_silgen_name("$sSR17withMemoryRebound2to_qd_0_qd__m_qd_0_SRyqd__GKXEtKr0_lF") | ||
% end | ||
public func _legacy_withMemoryRebound<T, Result>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, the public name for a symbol that being pushed out of the way is a new thing.
Is this naming scheme reasonable? This is likely to be the precedent for other similar actions in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I might explicitly put _legacy_se0333_withMemoryRebound
or similar here, but I also don't really want to bikeshed these, because users should never need to worry about them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea.
Note that the additions to |
% else: | ||
@_silgen_name("$sSR17withMemoryRebound2to_qd_0_qd__m_qd_0_SRyqd__GKXEtKr0_lF") | ||
% end | ||
public func _legacy_withMemoryRebound<T, Result>( | ||
to type: T.Type, _ body: (${Self}<T>) throws -> Result | ||
) rethrows -> Result { | ||
if let base = _position { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This preserves the old implementation verbatim, but we could also forward to the new implementation. Forwarding to the new implementation would be better from a testability standpoint, but less rigourously correct from a compatibility standpoint. However, we are lifting a restriction so the new implementation should be compatible (e.g. it passes the old test). Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I agree we should forward it! The code looks clearly compatible for well-written code.
There is a minor chance of a binary compatibility issue if someone is calling this with mismatching strides; they might rely on the resulting buffer pointer having the same count as the original. But the original debug precondition seems like a big enough obstacle to prevent that for actually occurring in practice.
@swift-ci please test |
Build failed |
Build failed |
3ed0741
to
78a2558
Compare
@swift-ci please smoke test |
78a2558
to
72f4e65
Compare
@swift-ci please smoke test |
The output of I believe the ABI checker test is in error when it says that
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me!
Having nothing else to complain about, I picked a few ridiculously tiny nits; take them or ignore them as you like. 😉
% else: | ||
@_silgen_name("$sSR17withMemoryRebound2to_qd_0_qd__m_qd_0_SRyqd__GKXEtKr0_lF") | ||
% end | ||
public func _legacy_withMemoryRebound<T, Result>( | ||
to type: T.Type, _ body: (${Self}<T>) throws -> Result | ||
) rethrows -> Result { | ||
if let base = _position { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I agree we should forward it! The code looks clearly compatible for well-written code.
There is a minor chance of a binary compatibility issue if someone is calling this with mismatching strides; they might rely on the resulting buffer pointer having the same count as the original. But the original debug precondition seems like a big enough obstacle to prevent that for actually occurring in practice.
return try body(.init(start: nil, count: 0)) | ||
} | ||
_debugPrecondition( | ||
Int(bitPattern: s) & (MemoryLayout<T>.alignment-1) == 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Low prio note) We should probably introduce a utility predicate for this. (s._isAligned(to: T.self)
, or something like that?)
@swift-ci please smoke test |
The test "api-digester/stability-stdlib-abi-with-asserts.test" says:
This is an error on the part of the test. |
@swift-ci please smoke test |
2a2bb17
to
b2aaaeb
Compare
@swift-ci please smoke test |
@swift-ci please test macOS platform |
Implementation of SE-0333, "Expand usability of
withMemoryRebound
. See proposal here.Addresses bugs SR-11082, SR-11087, rdar://88087816