Skip to content

Conversation

@malbarbo
Copy link
Contributor

This generates a panic free code, with is helpful for smaller binary sizes.

@rustbot

This comment was marked as resolved.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 30, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 30, 2025

r? @jhpratt

rustbot has assigned @jhpratt.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@asquared31415
Copy link
Contributor

I'm kind of shocked that this wouldn't get elided? Using the result of a search should be easily known to be in bounds of the same array.

@malbarbo
Copy link
Contributor Author

malbarbo commented Dec 30, 2025

@asquared31415 the following project suggests that it is indeed the case

Cargo.toml

[package]
name = "a"
version = "0.1.0"
edition = "2024"

[lib]
crate-type = ["cdylib"]

[dependencies]
wasi = "0.11"

[profile.release]
codegen-units = 1

src/lib.rs

#![no_std]
#![no_main]

use core::slice;
use core::str;
use wasi;

#[unsafe(no_mangle)]
pub extern "C" fn _str_lowercase(ptr: *const u8, len: usize, mut dest: *mut u8) -> usize {
    unsafe {
        let s = str::from_utf8_unchecked(slice::from_raw_parts(ptr, len));
        let mut len = 0;
        for ch in s.chars().flat_map(char::to_lowercase) {
            let bytes: &mut [u8; 4] = &mut *(dest as *mut [u8; 4]);
            let s = ch.encode_utf8(bytes);
            len += s.len();
            dest = dest.add(s.len());
        }
        len
    }
}

Compiling with cargo build --target wasm32-unknown-unknown --release and checking the generate code with wasm-tools print target/wasm32-unknown-unknown/release/a.wasm | rustfilt | less we can see that core::panicking::panic_bounds_check is being called from core::unicode::unicode_data::conversions::to_lower.

Adding lto = true to Cargo.toml does not eliminate the panic_bounds_check call.

@jhpratt
Copy link
Member

jhpratt commented Dec 31, 2025

@bors2 try @rust-timer queue

@rust-timer

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Dec 31, 2025
Avoid index check in char::to_lowercase and char::to_uppercase
@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 31, 2025
@rust-bors
Copy link
Contributor

rust-bors bot commented Dec 31, 2025

☀️ Try build successful (CI)
Build commit: 6a7e2e6 (6a7e2e665305d3c86350578d30e9857fb7920a35, parent: 94f8f4083ef82743d44ccb842c2bb65978efec28)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6a7e2e6): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 482.208s -> 480.343s (-0.39%)
Artifact size: 390.84 MiB -> 390.82 MiB (-0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 31, 2025
@jhpratt
Copy link
Member

jhpratt commented Dec 31, 2025

Not particularly surprising, as most cases likely optimize the check already. Given that there is a demo where it doesn't, I'm fine with this change.

@bors r+

@bors
Copy link
Collaborator

bors commented Dec 31, 2025

📌 Commit 262426d has been approved by jhpratt

It is now in the queue for this repository.

@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 Dec 31, 2025
@bors
Copy link
Collaborator

bors commented Jan 1, 2026

⌛ Testing commit 262426d with merge 4c62aa4...

@bors
Copy link
Collaborator

bors commented Jan 1, 2026

☀️ Test successful - checks-actions
Approved by: jhpratt
Pushing 4c62aa4 to main...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 1, 2026
@bors bors merged commit 4c62aa4 into rust-lang:main Jan 1, 2026
13 checks passed
@rustbot rustbot added this to the 1.94.0 milestone Jan 1, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 1, 2026

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 4862272 (parent) -> 4c62aa4 (this PR)

Test differences

Show 2 test diffs

2 doctest diffs were found. These are ignored, as they are noisy.

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 4c62aa446803c8f31eafdc0c0119209ff129b3e0 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-apple-various: 3528.1s -> 5438.9s (+54.2%)
  2. aarch64-apple: 7938.4s -> 9711.0s (+22.3%)
  3. x86_64-gnu-tools: 3211.9s -> 3679.0s (+14.5%)
  4. pr-check-1: 1699.4s -> 1938.6s (+14.1%)
  5. x86_64-gnu-llvm-20: 4189.2s -> 4776.0s (+14.0%)
  6. i686-gnu-1: 7508.5s -> 8536.7s (+13.7%)
  7. x86_64-gnu-llvm-20-1: 3876.3s -> 4393.8s (+13.3%)
  8. x86_64-rust-for-linux: 2685.4s -> 3008.8s (+12.0%)
  9. i686-gnu-2: 5358.8s -> 5992.3s (+11.8%)
  10. i686-gnu-nopt-1: 7366.3s -> 8194.3s (+11.2%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (4c62aa4): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.2%] 3
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary -2.7%, secondary 2.7%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.7% [2.3%, 3.2%] 2
Improvements ✅
(primary)
-2.7% [-3.5%, -2.1%] 4
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.7% [-3.5%, -2.1%] 4

Cycles

Results (primary -7.1%, secondary -12.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.4% [3.4%, 3.4%] 1
Improvements ✅
(primary)
-7.1% [-12.8%, -2.2%] 15
Improvements ✅
(secondary)
-13.2% [-23.0%, -2.1%] 13
All ❌✅ (primary) -7.1% [-12.8%, -2.2%] 15

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 477.392s -> 476.46s (-0.20%)
Artifact size: 390.85 MiB -> 390.83 MiB (-0.00%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants