-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SE-0322] Temporary uninitialized buffers #37666
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
Build failed |
f978060
to
d5614aa
Compare
@swift-ci please smoke test |
withUnsafeUninitializedMutableBufferPointer()
Please add some test cases under |
Yep, it's on my to-do list. :) |
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'll submit these for now, but I have a few others to come.
2c71162
to
1ed6ed5
Compare
1ed6ed5
to
6874698
Compare
@swift-ci please smoke test |
It's useful for high-level optimizations of the stack for us to keep stack allocations balanced with deallocation operations. Even if the deallocation doesn't concretely do anything at runtime, knowing when the lifetime of the stack slot ends means that LLVM can potentially reuse the stack memory for something else, reclaim dynamically-allocated stack memory (which we do in some cases with unspecialized generics), and make better choices when splitting coroutines and allocating context for async/read/modify allocations. So it'd be good to have a |
Makes sense @jckarter. This is something I'd add as a builtin and call inside the Swift implementation ( |
a41dabb
to
f41945b
Compare
@swift-ci please test linux |
b0b23fa
to
03310bd
Compare
@swift-ci please test |
Build failed |
Build failed |
c953299
to
dc01f7b
Compare
@swift-ci please test |
Build failed |
Build failures are in unrelated tests. |
e017f08
to
6b8f6b2
Compare
@swift-ci please smoke test |
6b8f6b2
to
a343c77
Compare
@swift-ci please smoke test |
@swift-ci please smoke test windows |
a343c77
to
3b678cf
Compare
@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.
Looks good from the stdlib side! 👍
I have one question about linkage below, to ensure we won't have back deployment issues.
@swift-ci please smoke test windows |
3b678cf
to
6894781
Compare
@swift-ci please smoke test |
Adds two new IRGen-level builtins (one for allocating, the other for deallocating), a stdlib shim function for enhanced stack-promotion heuristics, and the proposed public stdlib functions.
6894781
to
f1bf7ba
Compare
@swift-ci please smoke test |
@swift-ci please smoke test windows |
func isStackAllocated(_ pointer: UnsafeRawPointer) -> Bool? { | ||
var stackBegin: UInt = 0 | ||
var stackEnd: UInt = 0 | ||
if _swift_stdlib_getCurrentStackBounds(&stackBegin, &stackEnd) { |
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.
@lorentey Does this test require availability? This _swift_stdlib_getCurrentStackBounds
function doesn't exist in older OSes.
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.
Ah, good catch! Yep, this should have an availability check and return nil if the fn isn't available.
Furthermore, I think we will need to add the weak_import attribute to this function, like swift_stdlib_isStackAllocationSafe
. (Or add availability information to its declaration in the shims module.)
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 don't think it's necessary—these are testing new API that's only available with the new stdlib (although it can be emitted to older targets.) The tests won't even compile if the new symbols aren't available, let alone link.
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.
The case we're worried about is back deployment testing where the test is compiled with the latest stdlib but executed with a previous release. In that scenario, strongly linking to (and unconditionally calling) the new runtime entry point will trigger a failure.
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.
Ah, I see. This PR is closed now but we can open another one for a fix.
These changes add the ability to temporarily allocate buffers preferentially on the stack.
Pitch thread: https://forums.swift.org/t/pitch-temporary-uninitialized-buffers/48954
Evolution PR: swiftlang/swift-evolution#1379
Evolution thread: https://forums.swift.org/t/se-0322-temporary-uninitialized-buffers/51848
Resolves rdar://76198203.