Uh oh!
There was an error while loading. Please reload this page.
Rework init and cleanup - #84115
Conversation
rust-highfive
commented
Apr 12, 2021
(rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
Mark-Simulacrum
commented
Apr 12, 2021
Would it be possible to avoid changing the behavior of when initialization is done (on Windows), making this a pure refactoring PR, and split that work out into a separate PR? The changes to initialization time for the Windows code are not obviously correct to me, as I think we don't make any guarantees that the init() function is run before std code is executed - e.g., if calling into a Rust library from C - is that right? Do we have some linker trickery to ensure it runs in that case? cc @m-ou-se as well; it'd be good to get some more eyes on this in the long run; I think we should get some eyes on PRs of this subtlety :) |
CDirkx
commented
Apr 12, 2021
Of course. I excluded the last two commits containing the changes to initialization, so this is now purely a refactoring. |
bors
commented
Apr 15, 2021
☔ The latest upstream changes (presumably #84206) made this pull request unmergeable. Please resolve the merge conflicts. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
What's the use of the Once static here? Don't we already know for sure this is called exactly once?
There was a problem hiding this comment.
sys_common::rt::cleanup needs to be safe to call multiple times: it could be called in process::exit, then panic, which is caught by lang_start_internal, and then be called again. For symmetry I then made sys_common::rt::init also not unsafe to call, which is why I added the Once, to not have to rely on that it can only be called once remaining true in the future. I could remove it however.
There was a problem hiding this comment.
Yes, exit() could also be called from multiple threads concurrently, so cleanup definitely needs this. But for init I'd remove it if it's not necessary, to not confuse the reader about what is going on.
Uh oh!
There was an error while loading. Please reload this page.
CDirkx
commented
Apr 18, 2021
I confirmed this is correct, |
CDirkx
commented
Apr 18, 2021
I'm not sure what is going on with the runtime on rust/library/std/src/sys/hermit/mod.rs Lines 109 to 128 in dc99219 It could be that I could change it to: // initialize environment
os::init_environment(env as*const*consti8); sys_common::rt::init(argc asisize, argv);let result = main(argc asisize, argv); sys_common::rt::cleanup();
abi::exit(result);and move |
@CDirkx So, you can read that call to *Unrelated to the Rust |
CDirkx
commented
Apr 21, 2021
Ah that's where my confusion came from, then I'll leave it as is. |
m-ou-se
commented
Apr 21, 2021
@bors r+ rollup=iffy Not rolling this one up, since it touches a lot of platform-specific code, so there's a higher chance of CI failures. |
bors
commented
Apr 21, 2021
📌 Commit 83608021cca5419d8dc1424c5c42bbd94b6cad8f has been approved by |
bors
commented
Apr 21, 2021
🌲 The tree is currently closed for pull requests below priority 1000. This pull request will be tested once the tree is reopened. |
bors
commented
Apr 22, 2021
☔ The latest upstream changes (presumably #84411) made this pull request unmergeable. Please resolve the merge conflicts. |
CDirkx
commented
Apr 22, 2021
Rebased and resolved merge conflicts |
m-ou-se
commented
Apr 22, 2021
@bors r+ |
bors
commented
Apr 22, 2021
📌 Commit 9f153eeb34684924aa7880fac6f0e4926a471f20 has been approved by |
bors
commented
Apr 22, 2021
⌛ Testing commit 9f153eeb34684924aa7880fac6f0e4926a471f20 with merge 7289a3db6602624f3e3bc554f0668a599c5699b3... |
This comment has been minimized.
This comment has been minimized.
bors
commented
Apr 22, 2021
💔 Test failed - checks-actions |
CDirkx
commented
Apr 22, 2021
Added the extra required |
m-ou-se
commented
Apr 24, 2021
@bors r+ |
bors
commented
Apr 24, 2021
📌 Commit 7171fec has been approved by |
bors
commented
Apr 25, 2021
bors
commented
Apr 25, 2021
☀️ Test successful - checks-actions |
This PR reworks the code in
stdthat runs before and aftermainand centralizes this code respectively in the functionsinitandcleanupin bothsys_commonandsys. This makes is easy to see what code is executed during initialization and cleanup on each platform just by looking at e.g.sys::windows::init.Full list of changes:
rtinsys_commonto containinitandcleanupand the runtime macros.at_exitand the mechanism to register exit handlers has been completely removed. In practice this was only used for closing sockets on windows and flushing stdout, which have been moved tocleanup.On windowsallocandnetinitialization is now done ininit, this saves a runtime check in every allocation and network use.