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

Projects
None yet
6 participants
@fitzgen
Copy link
Member

fitzgen commented Feb 7, 2019

r? @alexcrichton

fitzgen added some commits Feb 7, 2019

De-duplicate number formatting implementations for smaller code size
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.
Un-monomorphize and inline formatting with padding
The generic `F` in `with_padding` was causing a bunch of stuff to get inlined
that otherwise needn't be, blowing up code size.
@fitzgen

This comment has been minimized.

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

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Feb 7, 2019

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)

Show resolved Hide resolved src/libcore/fmt/mod.rs Outdated
Show resolved Hide resolved src/test/run-make/wasm-stringify-ints-small/foo.rs Outdated

@fitzgen fitzgen force-pushed the fitzgen:num-format-code-size branch from b4765f7 to 2ec556c Feb 8, 2019

@fitzgen fitzgen force-pushed the fitzgen:num-format-code-size branch from 2ec556c to f00f0e6 Feb 8, 2019

@Mark-Simulacrum

This comment has been minimized.

Copy link
Member

Mark-Simulacrum commented Feb 8, 2019

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Feb 8, 2019

📌 Commit f00f0e6 has been approved by Mark-Simulacrum

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request Feb 10, 2019

Rollup merge of rust-lang#58272 - fitzgen:num-format-code-size, r=Mar…
…k-Simulacrum

Cut down on number formating code size

r? @alexcrichton

bors added a commit that referenced this pull request Feb 10, 2019

Auto merge of #58338 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 17 pull requests

Successful merges:

 - #57259 (Update reference of rlibc crate to compiler-builtins crate)
 - #57740 (Use `to_ne_bytes` for converting IPv4Addr to octets)
 - #58085 (Implement more detailed self profiling)
 - #58103 (Make -Zdump-mir dump shims)
 - #58129 (MaybeUninit: some docs, rename into_inner -> into_initialized, return &mut from set)
 - #58151 (Partially HirId-ify rustc)
 - #58152 (Partially HirIdify mir)
 - #58153 (Partially Hiridify typeck)
 - #58203 (rustdoc: display sugared return types for async functions)
 - #58258 (Reduce the size of `hir::Expr`.)
 - #58262 (Add #[must_use] message to Fn* traits)
 - #58272 (Cut down on number formating code size)
 - #58276 (Improve the error messages for missing stability attributes)
 - #58295 (std::sys::unix::stdio: explain why we do into_raw)
 - #58297 (Cleanup JS a bit)
 - #58300 (librustc_typeck => 2018)
 - #58332 (operand-to-place copies should never be overlapping)

Failed merges:

 - #58167 (HirId-ify hir::BodyId)

r? @ghost

Centril added a commit to Centril/rust that referenced this pull request Feb 13, 2019

Rollup merge of rust-lang#58272 - fitzgen:num-format-code-size, r=Mar…
…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

Rollup merge of rust-lang#58272 - fitzgen:num-format-code-size, r=Mar…
…k-Simulacrum

Cut down on number formating code size

r? @alexcrichton

bors added a commit that referenced this pull request Feb 13, 2019

Auto merge of #58428 - Centril:rollup, r=Centril
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

Centril added a commit to Centril/rust that referenced this pull request Feb 13, 2019

Rollup merge of rust-lang#58272 - fitzgen:num-format-code-size, r=Mar…
…k-Simulacrum

Cut down on number formating code size

r? @alexcrichton

bors added a commit that referenced this pull request Feb 13, 2019

Auto merge of #58432 - Centril:rollup, r=Centril
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

bors added a commit that referenced this pull request Feb 13, 2019

Auto merge of #58432 - Centril:rollup, r=Centril
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 referenced this pull request Feb 14, 2019

Open

2019 roadmap #7

@bors bors merged commit f00f0e6 into rust-lang:master Feb 14, 2019

@fitzgen fitzgen deleted the fitzgen:num-format-code-size branch Feb 14, 2019

@therealprof

This comment has been minimized.

Copy link

therealprof commented Feb 14, 2019

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

@therealprof

This comment has been minimized.

Copy link

therealprof commented Feb 17, 2019

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