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

Cut down on number formating code size #58272

Merged
merged 7 commits into from
Feb 14, 2019

Conversation

fitzgen
Copy link
Member

@fitzgen fitzgen commented Feb 7, 2019

Instead of inlining the same logic into every number formatting implementation,
pull it out into a function that each of the number formatting impls call into.
The generic `F` in `with_padding` was causing a bunch of stuff to get inlined
that otherwise needn't be, blowing up code size.
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 7, 2019
@fitzgen
Copy link
Member Author

fitzgen commented Feb 7, 2019

This got the new test case's code size down from 22871 to 20609: a savings of 2262 bytes (about 10%).

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 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.
travis_time:end:03603c51:start=1549557147641131588,finish=1549557294147151753,duration=146506020165
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-6.0
---

[00:04:07] travis_fold:start:tidy
travis_time:start:tidy
tidy check
[00:04:07] tidy error: binary checked into source: /checkout/src/test/run-make/wasm-stringify-ints-small/foo.rs
[00:04:07] tidy error: /checkout/src/libcore/fmt/num.rs:265: line longer than 100 chars
[00:04:09] some tidy checks failed
[00:04:09] 
[00:04:09] 
[00:04:09] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor" "--quiet"
[00:04:09] 
[00:04:09] 
[00:04:09] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:04:09] Build completed unsuccessfully in 0:00:47
[00:04:09] Build completed unsuccessfully in 0:00:47
[00:04:09] Makefile:68: recipe for target 'tidy' failed
[00:04:09] make: *** [tidy] Error 1
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:2ec421a0
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Thu Feb  7 16:39:12 UTC 2019
---
travis_time:end:364154c7:start=1549557553634501702,finish=1549557553639193304,duration=4691602
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:057482e5
$ 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:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:352ef240
travis_time:start:352ef240
$ 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:2fa96ad0
$ 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)

src/libcore/fmt/mod.rs Outdated Show resolved Hide resolved
src/test/run-make/wasm-stringify-ints-small/foo.rs Outdated Show resolved Hide resolved
@Mark-Simulacrum
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Feb 8, 2019

📌 Commit f00f0e6 has been approved by Mark-Simulacrum

@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 Feb 8, 2019
Centril added a commit to Centril/rust that referenced this pull request Feb 13, 2019
…k-Simulacrum

Cut down on number formating code size

r? @alexcrichton
Centril added a commit to Centril/rust that referenced this pull request Feb 13, 2019
…k-Simulacrum

Cut down on number formating code size

r? @alexcrichton
Centril added a commit to Centril/rust that referenced this pull request Feb 13, 2019
…k-Simulacrum

Cut down on number formating code size

r? @alexcrichton
bors added a commit that referenced this pull request Feb 13, 2019
Rollup of 10 pull requests

Successful merges:

 - #58110 (libpanic_unwind => 2018)
 - #58167 (HirId-ify hir::BodyId)
 - #58202 (Ignore future deprecations in #[deprecated])
 - #58272 (Cut down on number formating code size)
 - #58276 (Improve the error messages for missing stability attributes)
 - #58354 (Fix ICE and invalid filenames in MIR printing code)
 - #58381 (Only suggest imports if not imported.)
 - #58386 (Fix #54242)
 - #58400 (Fix rustc_driver swallowing errors when compilation is stopped)
 - #58420 (target/uefi: clarify documentation)

Failed merges:

r? @ghost
@fitzgen fitzgen mentioned this pull request Feb 14, 2019
@bors bors merged commit f00f0e6 into rust-lang:master Feb 14, 2019
@fitzgen fitzgen deleted the num-format-code-size branch February 14, 2019 03:20
@therealprof
Copy link
Contributor

Ooh. I'm really curious to see whether this has any noticeable impact on embedded.

@therealprof
Copy link
Contributor

Very nice! I'm seeing a reduction of up to 800B in .text size (or -28% in that specific example) on ARMv6m.

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.

6 participants