Skip to content

Commit 6c882eb

Browse files
Merge of #705: Add optimize(size) to some particularly large functions
* Check `as-if-std` only on nightly * Add `optimize(size)` to some particularly large functions It saves a few kb in hello world binaries when built as part of libstd. The comments are formatted like they are so that if this feature is stabilized they can be identified and used unconditionally.
2 parents e09b86e + 2b48d7c commit 6c882eb

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

.github/workflows/main.yml

+3
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,11 @@ jobs:
137137

138138
# Test that including as a submodule will still work, both with and without
139139
# the `backtrace` feature enabled.
140+
# Building as if part of std requires nightly features to be available
140141
- run: cargo build --manifest-path crates/as-if-std/Cargo.toml
142+
if: matrix.rust == 'nightly'
141143
- run: cargo build --manifest-path crates/as-if-std/Cargo.toml --no-default-features
144+
if: matrix.rust == 'nightly'
142145

143146
windows_arm64:
144147
name: Windows AArch64

ci/run.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
set -ex
44

55
cargo test --target $TARGET
6-
cargo build --target $TARGET --manifest-path crates/as-if-std/Cargo.toml
6+
if rustc --version | grep nightly; then
7+
cargo build --target $TARGET --manifest-path crates/as-if-std/Cargo.toml
8+
fi

crates/as-if-std/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// submodule into the standard library. We try to set this crate up similarly
33
// to the standard library itself to minimize the likelihood of issues when
44
// updating the `backtrace` crate.
5-
5+
#![feature(optimize_attribute)]
66
#![no_std]
77

88
extern crate alloc;

src/symbolize/gimli.rs

+4
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ struct Context<'a> {
115115
}
116116

117117
impl<'data> Context<'data> {
118+
// #[feature(optimize_attr)] is enabled when we're built inside libstd
119+
#[cfg_attr(backtrace_in_libstd, optimize(size))]
118120
fn new(
119121
stash: &'data Stash,
120122
object: Object<'data>,
@@ -356,6 +358,8 @@ impl Cache {
356358
}
357359

358360
// unsafe because this is required to be externally synchronized
361+
// #[feature(optimize_attr)] is enabled when we're built inside libstd
362+
#[cfg_attr(backtrace_in_libstd, optimize(size))]
359363
unsafe fn with_global(f: impl FnOnce(&mut Self)) {
360364
// A very small, very simple LRU cache for debug info mappings.
361365
//

0 commit comments

Comments
 (0)