Skip to content

Prefer -1 for None#155473

Merged
rust-bors[bot] merged 2 commits intorust-lang:mainfrom
scottmcm:tweak_niche_assignment
Apr 26, 2026
Merged

Prefer -1 for None#155473
rust-bors[bot] merged 2 commits intorust-lang:mainfrom
scottmcm:tweak_niche_assignment

Conversation

@scottmcm
Copy link
Copy Markdown
Member

@scottmcm scottmcm commented Apr 18, 2026

View all comments

Currently we pick "weird" numbers like 1114112 for None::<char>. While that's not wrong, it's kinda unnatural -- a human wouldn't make that choice.

This PR instead picks -1 for thinge like None::<char> -- like clang's WEOF -- and None::<bool> and such.

Any enums with more than one niched value (so not Result nor Option) remain as they were before. Also we continue to use 0 when that's possible -- -1 is only preferred when zero isn't possible.


Inspired when someone in discord posted an example like this https://rust.godbolt.org/z/W94s9qdYW and I thought it was odd that we're currently picking -9223372036854775808 to be the value to store to mark an Option<Vec<_>> as None. (Especially since that needs an 8-byte immediate on x64, and writing -1 is only a 4-byte immediate.)

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 18, 2026
Comment on lines 2091 to 2092
// zero is unavailable because wrapping occurs
move_end(v)
Copy link
Copy Markdown
Member Author

@scottmcm scottmcm Apr 18, 2026

Choose a reason for hiding this comment

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

Note that this arm just kinda gave up before; it never even considered whether putting it next to start might be better.

View changes since the review

@scottmcm
Copy link
Copy Markdown
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Apr 18, 2026
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 18, 2026
@rust-log-analyzer

This comment has been minimized.

@scottmcm scottmcm force-pushed the tweak_niche_assignment branch from 302d83d to a146c66 Compare April 18, 2026 06:26
@scottmcm
Copy link
Copy Markdown
Member Author

It helps to remember to git add all the changes 🤦

@rust-bors

This comment was marked as outdated.

@rust-log-analyzer

This comment has been minimized.

@scottmcm scottmcm force-pushed the tweak_niche_assignment branch from a146c66 to 09df883 Compare April 18, 2026 07:26
@scottmcm
Copy link
Copy Markdown
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Apr 18, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 18, 2026

☀️ Try build successful (CI)
Build commit: ed76e05 (ed76e056cbb36453c64da4dd8ffccac4e093f819, parent: 2f201bccb3a7fb5a85b0fcfcc0a020a946d6d58a)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (ed76e05): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +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.3% [0.3%, 0.3%] 1
Regressions ❌
(secondary)
0.5% [0.0%, 1.5%] 9
Improvements ✅
(primary)
-0.3% [-2.9%, -0.2%] 86
Improvements ✅
(secondary)
-0.3% [-1.8%, -0.0%] 62
All ❌✅ (primary) -0.3% [-2.9%, 0.3%] 87

Max RSS (memory usage)

Results (secondary 1.1%)

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)
6.5% [6.5%, 6.5%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.4% [-4.4%, -4.4%] 1
All ❌✅ (primary) - - 0

Cycles

Results (primary -2.9%, secondary -4.2%)

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)
1.8% [1.8%, 1.8%] 1
Improvements ✅
(primary)
-2.9% [-3.0%, -2.9%] 2
Improvements ✅
(secondary)
-6.2% [-7.6%, -3.4%] 3
All ❌✅ (primary) -2.9% [-3.0%, -2.9%] 2

Binary size

Results (primary -0.2%, secondary -0.4%)

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)
0.3% [0.0%, 0.6%] 2
Improvements ✅
(primary)
-0.2% [-0.6%, -0.1%] 5
Improvements ✅
(secondary)
-0.9% [-2.1%, -0.3%] 3
All ❌✅ (primary) -0.2% [-0.6%, -0.1%] 5

Bootstrap: 491.618s -> 493.312s (0.34%)
Artifact size: 394.25 MiB -> 396.31 MiB (0.52%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Apr 18, 2026
@scottmcm
Copy link
Copy Markdown
Member Author

scottmcm commented Apr 18, 2026

Wow, those results are way better than I expected 😅

Seems pretty clearly a net win to me.
@rustbot label: +perf-regression-triaged

@scottmcm scottmcm marked this pull request as ready for review April 18, 2026 16:25
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 18, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Apr 18, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 18, 2026

r? @chenyukang

rustbot has assigned @chenyukang.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 72 candidates
  • Random selection from 18 candidates

@JonathanBrouwer
Copy link
Copy Markdown
Contributor

Is that spurious?
@bors try jobs=x86_64-mingw-1

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Apr 26, 2026
Prefer `-1` for `None`


try-job: x86_64-mingw-1
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 26, 2026

☀️ Try build successful (CI)
Build commit: 031ee25 (031ee2518da74818f784615d980c960239a1711f, parent: 68ffae46b581747074413e4242ab0c6ecc4db4a9)

@JonathanBrouwer
Copy link
Copy Markdown
Contributor

@bors retry

@rust-bors rust-bors Bot 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 Apr 26, 2026
@JonathanBrouwer
Copy link
Copy Markdown
Contributor

@bors p=6
Scheduling this before the next rollup

@rust-bors

This comment has been minimized.

@rust-bors rust-bors Bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 26, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 26, 2026

☀️ Test successful - CI
Approved by: chenyukang,mati865
Duration: 3h 24m 15s
Pushing d4f7856 to main...

@rust-bors rust-bors Bot merged commit d4f7856 into rust-lang:main Apr 26, 2026
13 checks passed
@rustbot rustbot added this to the 1.97.0 milestone Apr 26, 2026
@github-actions
Copy link
Copy Markdown
Contributor

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 c7fe5e9 (parent) -> d4f7856 (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 d4f78565699b229227c9e9ca8164efa3d5d7213e --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-x86_64-apple: 2h 29m -> 1h 42m (-31.2%)
  2. x86_64-gnu: 1h 49m -> 2h 18m (+27.1%)
  3. x86_64-gnu-llvm-21: 1h 14m -> 54m 30s (-27.0%)
  4. dist-x86_64-illumos: 1h 24m -> 1h 46m (+26.9%)
  5. x86_64-gnu-llvm-21-3: 1h 27m -> 1h 49m (+24.9%)
  6. dist-arm-linux-musl: 1h 20m -> 1h 38m (+22.6%)
  7. x86_64-gnu-llvm-22-2: 1h 31m -> 1h 12m (-21.5%)
  8. dist-apple-various: 1h 50m -> 1h 33m (-15.1%)
  9. dist-powerpc-linux: 1h 26m -> 1h 13m (-14.4%)
  10. i686-msvc-1: 3h 3m -> 2h 38m (-13.7%)
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
Copy Markdown
Collaborator

Finished benchmarking commit (d4f7856): 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.7% [0.2%, 1.9%] 5
Improvements ✅
(primary)
-0.3% [-2.7%, -0.1%] 67
Improvements ✅
(secondary)
-0.3% [-0.8%, -0.1%] 52
All ❌✅ (primary) -0.3% [-2.7%, -0.1%] 67

Max RSS (memory usage)

Results (secondary -1.9%)

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)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.9% [-1.9%, -1.9%] 1
All ❌✅ (primary) - - 0

Cycles

Results (primary -2.5%)

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)
- - 0
Improvements ✅
(primary)
-2.5% [-2.5%, -2.5%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.5% [-2.5%, -2.5%] 1

Binary size

Results (primary -0.2%, secondary -0.1%)

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)
0.0% [0.0%, 0.0%] 3
Improvements ✅
(primary)
-0.2% [-0.6%, -0.0%] 25
Improvements ✅
(secondary)
-0.1% [-0.3%, -0.0%] 6
All ❌✅ (primary) -0.2% [-0.6%, -0.0%] 25

Bootstrap: 488.641s -> 488.853s (0.04%)
Artifact size: 393.90 MiB -> 393.54 MiB (-0.09%)

rust-bors Bot pushed a commit that referenced this pull request Apr 27, 2026
Only exclude the #155473 change for 1-byte bool-likes


try-job: x86_64-gnu-llvm-22-1
try-job: x86_64-gnu-llvm-21-1
rust-bors Bot pushed a commit that referenced this pull request Apr 28, 2026
Only exclude the #155473 change for 1-byte bool-likes

That's the thing we handle differently in codegen (see `to_immediate_scalar`) so if the other ones are fine, that helps narrow it down further.

cc #155473
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 28, 2026
…=mati865

Only exclude the rust-lang#155473 change for 1-byte bool-likes

That's the thing we handle differently in codegen (see `to_immediate_scalar`) so if the other ones are fine, that helps narrow it down further.

cc rust-lang#155473
rust-bors Bot pushed a commit that referenced this pull request Apr 28, 2026
…uwer

Rollup of 14 pull requests

Successful merges:

 - #155850 (Only exclude the #155473 change for 1-byte bool-likes)
 - #155923 (Subtree sync for rustc_codegen_cranelift)
 - #151994 (switch to v0 mangling by default on stable)
 - #154325 (Tweak irrefutable let else warning output)
 - #155899 (`dlltool`: Set the working directory to workaround `--temp-prefix` bug)
 - #155273 (Lock stable_crate_ids once in create_crate_num)
 - #155361 (Document that CFI diverges from Rust wrt. ABI-compatibility rules)
 - #155692 (disable naked-dead-code-elimination test if no RET mnemonic is available)
 - #155747 (Update documentation for `wasm32-wali-linux-musl` after integrating n…)
 - #155768 (compiletest: Overhaul the code for running an incremental test revision)
 - #155907 (Handle hkl const closures)
 - #155910 (misc stuff from reading borrowck again :))
 - #155913 (Delete the 12 year old fixme)
 - #155920 (remove review queue triagebot mentions)
rust-bors Bot pushed a commit that referenced this pull request Apr 28, 2026
…uwer

Rollup of 14 pull requests

Successful merges:

 - #155850 (Only exclude the #155473 change for 1-byte bool-likes)
 - #155923 (Subtree sync for rustc_codegen_cranelift)
 - #151994 (switch to v0 mangling by default on stable)
 - #154325 (Tweak irrefutable let else warning output)
 - #155899 (`dlltool`: Set the working directory to workaround `--temp-prefix` bug)
 - #155273 (Lock stable_crate_ids once in create_crate_num)
 - #155361 (Document that CFI diverges from Rust wrt. ABI-compatibility rules)
 - #155692 (disable naked-dead-code-elimination test if no RET mnemonic is available)
 - #155747 (Update documentation for `wasm32-wali-linux-musl` after integrating n…)
 - #155768 (compiletest: Overhaul the code for running an incremental test revision)
 - #155907 (Handle hkl const closures)
 - #155910 (misc stuff from reading borrowck again :))
 - #155913 (Delete the 12 year old fixme)
 - #155920 (remove review queue triagebot mentions)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 28, 2026
…=mati865

Only exclude the rust-lang#155473 change for 1-byte bool-likes

That's the thing we handle differently in codegen (see `to_immediate_scalar`) so if the other ones are fine, that helps narrow it down further.

cc rust-lang#155473
rust-bors Bot pushed a commit that referenced this pull request Apr 28, 2026
…uwer

Rollup of 15 pull requests

Successful merges:

 - #155923 (Subtree sync for rustc_codegen_cranelift)
 - #155930 (Sync from portable simd 2026 04 28)
 - #155850 (Only exclude the #155473 change for 1-byte bool-likes)
 - #151994 (switch to v0 mangling by default on stable)
 - #154325 (Tweak irrefutable let else warning output)
 - #155273 (Lock stable_crate_ids once in create_crate_num)
 - #155361 (Document that CFI diverges from Rust wrt. ABI-compatibility rules)
 - #155692 (disable naked-dead-code-elimination test if no RET mnemonic is available)
 - #155747 (Update documentation for `wasm32-wali-linux-musl` after integrating n…)
 - #155768 (compiletest: Overhaul the code for running an incremental test revision)
 - #155907 (Handle hkl const closures)
 - #155910 (misc stuff from reading borrowck again :))
 - #155913 (Delete the 12 year old fixme)
 - #155920 (remove review queue triagebot mentions)
 - #155936 (Rename `SharedContext::emit_dyn_lint*` into `emit_lint*`)
rust-bors Bot pushed a commit that referenced this pull request Apr 28, 2026
…uwer

Rollup of 15 pull requests

Successful merges:

 - #155923 (Subtree sync for rustc_codegen_cranelift)
 - #155930 (Sync from portable simd 2026 04 28)
 - #155850 (Only exclude the #155473 change for 1-byte bool-likes)
 - #151994 (switch to v0 mangling by default on stable)
 - #154325 (Tweak irrefutable let else warning output)
 - #155273 (Lock stable_crate_ids once in create_crate_num)
 - #155361 (Document that CFI diverges from Rust wrt. ABI-compatibility rules)
 - #155692 (disable naked-dead-code-elimination test if no RET mnemonic is available)
 - #155747 (Update documentation for `wasm32-wali-linux-musl` after integrating n…)
 - #155768 (compiletest: Overhaul the code for running an incremental test revision)
 - #155907 (Handle hkl const closures)
 - #155910 (misc stuff from reading borrowck again :))
 - #155913 (Delete the 12 year old fixme)
 - #155920 (remove review queue triagebot mentions)
 - #155936 (Rename `SharedContext::emit_dyn_lint*` into `emit_lint*`)
rust-timer added a commit that referenced this pull request Apr 28, 2026
Rollup merge of #155850 - scottmcm:tweak_niche_assignment, r=mati865

Only exclude the #155473 change for 1-byte bool-likes

That's the thing we handle differently in codegen (see `to_immediate_scalar`) so if the other ones are fine, that helps narrow it down further.

cc #155473
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants