Skip to content
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

std: Improve codegen size of accessing TLS #55518

Merged
merged 2 commits into from
Nov 6, 2018

Conversation

alexcrichton
Copy link
Member

Some code in the TLS implementation in libstd stores Some(val) into an
&mut Option<T> (effectively) and then pulls out &T, but it currently
uses .unwrap() which can codegen into a panic even though it can never
panic. With sufficient optimizations enabled (like LTO) the compiler can
see through this but this commit helps it along in normal mode
(--release with Cargo by default) to avoid codegen'ing the panic path.

This ends up improving the optimized codegen on wasm by ensuring that a
call to panic pulling in more file size doesn't stick around.

@rust-highfive
Copy link
Collaborator

r? @bluss

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 30, 2018
@alexcrichton
Copy link
Member Author

r? @sfackler

@rust-highfive rust-highfive assigned sfackler and unassigned bluss Oct 30, 2018
@sfackler
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Oct 30, 2018

📌 Commit 62eec9ee4c523ead0f46f1a5e6e85460ef02bc1a has been approved by sfackler

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 30, 2018
(*ptr).as_ref().unwrap()
match *ptr {
Some(ref x) => x,
None => intrinsics::unreachable(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this really deserves a comment indicating why it was done -- could you add one? That way we can avoid confusion or cleanup removing this without knowing what to check

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also don't we have unreachable_unchecked so that we do not have to call an intrinsic directly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!

@alexcrichton
Copy link
Member Author

@bors: r=sfackler

@bors
Copy link
Contributor

bors commented Oct 31, 2018

📌 Commit 36990de9f160739bc56925d4e7036e13476300be has been approved by sfackler

@alexcrichton
Copy link
Member Author

@bors: r=sfackler

@bors
Copy link
Contributor

bors commented Oct 31, 2018

📌 Commit f64efa5ea3607047aba695154767030da5abf3d4 has been approved by sfackler

@rust-highfive

This comment has been minimized.

@alexcrichton
Copy link
Member Author

@bors: r=sfackler

@bors
Copy link
Contributor

bors commented Oct 31, 2018

📌 Commit c24c2c95f47f05eec17f3c4afbd981addb795fbf has been approved by sfackler

@kennytm
Copy link
Member

kennytm commented Nov 1, 2018

@bors r-

Failed in #55579 (comment)

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 1, 2018
No need for this to actually show up in optimized non-LTO executables!
Some code in the TLS implementation in libstd stores `Some(val)` into an
`&mut Option<T>` (effectively) and then pulls out `&T`, but it currently
uses `.unwrap()` which can codegen into a panic even though it can never
panic. With sufficient optimizations enabled (like LTO) the compiler can
see through this but this commit helps it along in normal mode
(`--release` with Cargo by default) to avoid codegen'ing the panic path.

This ends up improving the optimized codegen on wasm by ensuring that a
call to panic pulling in more file size doesn't stick around.
@bors
Copy link
Contributor

bors commented Nov 4, 2018

💔 Test failed - status-appveyor

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 4, 2018
@alexcrichton
Copy link
Member Author

@bors: retry

Seems spurious ...

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 5, 2018
@bors
Copy link
Contributor

bors commented Nov 5, 2018

⌛ Testing commit 0c3d08e with merge 8e950fb...

bors added a commit that referenced this pull request Nov 5, 2018
std: Improve codegen size of accessing TLS

Some code in the TLS implementation in libstd stores `Some(val)` into an
`&mut Option<T>` (effectively) and then pulls out `&T`, but it currently
uses `.unwrap()` which can codegen into a panic even though it can never
panic. With sufficient optimizations enabled (like LTO) the compiler can
see through this but this commit helps it along in normal mode
(`--release` with Cargo by default) to avoid codegen'ing the panic path.

This ends up improving the optimized codegen on wasm by ensuring that a
call to panic pulling in more file size doesn't stick around.
@bors
Copy link
Contributor

bors commented Nov 5, 2018

💔 Test failed - status-travis

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 5, 2018
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-distcheck of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[02:27:37] warning: spurious network error (2 tries remaining): curl error: Could not resolve host: github.com
[02:27:37] ; class=Net (12)
[02:27:57] warning: spurious network error (1 tries remaining): curl error: Could not resolve host: github.com
[02:27:57] ; class=Net (12)
[02:28:18] error: failed to load source for a dependency on `rand`
[02:28:18] Caused by:
[02:28:18]   Unable to update registry `https://github.com/rust-lang/crates.io-index`
[02:28:18] 
[02:28:18] Caused by:
[02:28:18] Caused by:
[02:28:18]   failed to fetch `https://github.com/rust-lang/crates.io-index`
[02:28:18] 
[02:28:18] Caused by:
[02:28:18]   curl error: Could not resolve host: github.com
[02:28:18] ; class=Net (12)
[02:28:18] 
[02:28:18] 
[02:28:18] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "generate-lockfile" "--manifest-path" "/checkout/obj/build/tmp/distcheck-src/rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml"
[02:28:18] 
[02:28:18] 
[02:28:18] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test distcheck
[02:28:18] Build completed unsuccessfully in 2:25:39
---
travis_time:end:077f9314:start=1541400965139249602,finish=1541400965147256143,duration=8006541
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:0d540134
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:start:crashlog
obj/cores/core.5222.!checkout!obj!build!tmp!distcheck!build!x86_64-unknown-linux-gnu!stage2!bin!rustc
[New LWP 5261]
[New LWP 5260]
[New LWP 5222]
warning: Could not load shared library symbols for 8 libraries, e.g. /lib/x86_64-linux-gnu/libc.so.6.
Use the "info sharedlibrary" command to see the complete listing.
Do you need "set solib-search-path" or "set sysroot"?
Core was generated by `/checkout/obj/build/tmp/distcheck/build/x86_64-unknown-linux-gnu/stage2/bin/rus'.
Program terminated with signal SIGABRT, Aborted.
#0  0x00007fc6341ce428 in ?? ()
#0  0x00007fc6341ce428 in ?? ()
#1  0x00007fc6341d002a in ?? ()
#2  0x0000000000000020 in ?? ()
#3  0x0000000000000000 in ?? ()
travis_time:end:0d540134:start=1541400965155673864,finish=1541400966883935842,duration=1728261978
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:02407ceb
travis_time:start:02407ceb
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:187109f4
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@kennytm
Copy link
Member

kennytm commented Nov 5, 2018

@bors retry travis-ci/travis-ci#9696

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 5, 2018
@bors
Copy link
Contributor

bors commented Nov 5, 2018

⌛ Testing commit 0c3d08e with merge d6cb28f...

bors added a commit that referenced this pull request Nov 5, 2018
std: Improve codegen size of accessing TLS

Some code in the TLS implementation in libstd stores `Some(val)` into an
`&mut Option<T>` (effectively) and then pulls out `&T`, but it currently
uses `.unwrap()` which can codegen into a panic even though it can never
panic. With sufficient optimizations enabled (like LTO) the compiler can
see through this but this commit helps it along in normal mode
(`--release` with Cargo by default) to avoid codegen'ing the panic path.

This ends up improving the optimized codegen on wasm by ensuring that a
call to panic pulling in more file size doesn't stick around.
@bors
Copy link
Contributor

bors commented Nov 5, 2018

💔 Test failed - status-appveyor

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 5, 2018
@alexcrichton
Copy link
Member Author

@bors: retry

3 hr timeout

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 5, 2018
@bors
Copy link
Contributor

bors commented Nov 6, 2018

⌛ Testing commit 0c3d08e with merge 24e66c2...

bors added a commit that referenced this pull request Nov 6, 2018
std: Improve codegen size of accessing TLS

Some code in the TLS implementation in libstd stores `Some(val)` into an
`&mut Option<T>` (effectively) and then pulls out `&T`, but it currently
uses `.unwrap()` which can codegen into a panic even though it can never
panic. With sufficient optimizations enabled (like LTO) the compiler can
see through this but this commit helps it along in normal mode
(`--release` with Cargo by default) to avoid codegen'ing the panic path.

This ends up improving the optimized codegen on wasm by ensuring that a
call to panic pulling in more file size doesn't stick around.
@bors
Copy link
Contributor

bors commented Nov 6, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: sfackler
Pushing 24e66c2 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants