-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[nfc] document legacy ABI in the implementation of sort #40828
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
@swift-ci please smoke test |
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.
Thank you for adding the documentation!
/// Merges the elements at `runs[i]` and `runs[i - 1]`, using `buffer` as | ||
/// out-of-place storage. | ||
/// | ||
/// The unused return value is legacy ABI. It was originally added as a | ||
/// workaround for a compiler bug (now fixed). See SR-14750 (rdar://45044610). |
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.
Perhaps, for the user who stumbles upon the documentation of this (public, underscored) method and other similar ones, one might consider stating explicitly that the return value is an arbitrary value. I can imagine that "unused" could be confusing since it's up to the caller whether it's unused or not (and "legacy ABI" may not mean much to many folks in terms of clarifying this)--in this case, we're merely trying to say that the value is of no use.
I wonder if it'd be most fitting to write this information explicitly in a - Returns:
section; it isn't essential, I think, to understand what the function is doing.
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.
Huh -- perhaps we should also change this method to be @inlinable internal
. It doesn't seem like a good idea to expose internal implementation details as public entry points.
(BTW, I'm not sure why we ended up using an Array
here for runs
-- it'd be too painful to change it now, but I hope it gets stack allocated...)
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.
Making them internal now is a good idea. I think that when they were added internal was still ill-advised for the standard library, though now it is fine. We can also further document the expectations with tests.
@swift-ci please smoke test |
@swift-ci apple silicon benchmark |
Performance (arm64): -O
Code size: -O
Performance (arm64): -Osize
Code size: -Osize
Performance (arm64): -Onone
Code size: -swiftlibs
How to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the Noise: Sometimes the performance results (not code size!) contain false Hardware Overview
|
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 should still be inlinable, I think; I believe @lorentey indicated the same above too.
stdlib/public/core/Sort.swift
Outdated
/// - Precondition: `runs.count > 1` and `i > 0` | ||
/// - Precondition: `buffer` must have at least | ||
/// `min(runs[i].count, runs[i - 1].count)` uninitialized elements. | ||
@discardableResult | ||
@inlinable | ||
public mutating func _mergeRuns( | ||
@usableFromInline |
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.
@usableFromInline | |
@inlinable |
stdlib/public/core/Sort.swift
Outdated
/// - Precondition: `buffer` must have at least | ||
/// `min(runs[i].count, runs[i - 1].count)` uninitialized elements. | ||
/// - Precondition: The ranges in `runs` must be consecutive, such that for | ||
/// any i, `runs[i].upperBound == runs[i + 1].lowerBound`. | ||
@discardableResult | ||
@inlinable | ||
public mutating func _mergeTopRuns( | ||
@usableFromInline |
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.
@usableFromInline | |
@inlinable |
stdlib/public/core/Sort.swift
Outdated
/// - Precondition: `buffer` must have at least | ||
/// `min(runs[i].count, runs[i - 1].count)` uninitialized elements. | ||
/// - Precondition: The ranges in `runs` must be consecutive, such that for | ||
/// any i, `runs[i].upperBound == runs[i + 1].lowerBound`. | ||
@discardableResult | ||
@inlinable | ||
public mutating func _finalizeRuns( | ||
@usableFromInline |
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.
@usableFromInline | |
@inlinable |
There is a bad error message when putting both attributes: |
The meaning that the message is trying to convey is that |
42f09af
to
66b0eda
Compare
66b0eda
to
b9eed4f
Compare
@swift-ci please test |
@swift-ci apple silicon benchmark |
Performance (arm64): -OCode size: -OPerformance (arm64): -Osize
Code size: -OsizePerformance (arm64): -Onone
Code size: -swiftlibsHow to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the Noise: Sometimes the performance results (not code size!) contain false Hardware Overview
|
buffer -> Bool in | ||
_ = buffer.initialize(from: 0..<10) | ||
return withUnsafeTemporaryAllocation(of: Int.self, capacity: 10) { | ||
_merge( |
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.
(Huh, TIL we have -Xfrontend -disable-access-control
in the %target-run-stdlib-swift
macro.)
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.
LGTM. We could document what the returned values are, but now that these are internal, it seems not very important to do so.
I think the tests are documentation in this case. Thanks! |
This adds documentation of legacy ABI in the implementation of
sort()
. A return value was originally added as a workaround for a compiler bug, and the workaround became ABI. The bug has long been fixed, and the workaround was recently removed (#40081), while leaving the ABI untouched.No SR.