Skip to content

avoid trivial fn map_bound validations - #163638

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
lcnr:map-bound-no-validate
Oct 3, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
lcnr:map-bound-no-validate

Conversation

@lcnr

@lcnr lcnr commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

when compiling zerocopy a lot of time is spent simply checking the bound vars in Clause::kind because it does

        self.0.internee.map_bound(|kind| match kind {
            PredicateKind::Clause(clause) => clause,
            _ => unreachable!(),
        })

let's make performance with debug_assertions a bit better:

zerocopy with -Znext-solver:

16884862 counts
(  1) 12189626 (72.2%, 72.2%): Binder::map_bound called at compiler/rustc_middle/src/ty/predicate.rs:174:25
(  2)  1853971 (11.0%, 83.2%): Binder::map_bound called at compiler/rustc_type_ir/src/binder.rs:89:14
(  3)  1443803 ( 8.6%, 91.7%): Binder::map_bound called at compiler/rustc_type_ir/src/inherent.rs:493:14
(  4)   572570 ( 3.4%, 95.1%): Binder::map_bound called at compiler/rustc_type_ir/src/predicate.rs:234:14
(  5)   272733 ( 1.6%, 96.7%): Binder::map_bound called at compiler/rustc_type_ir/src/inherent.rs:507:14
(  6)   184934 ( 1.1%, 97.8%): Binder::map_bound called at compiler/rustc_middle/src/ty/predicate.rs:523:14
(  7)   183998 ( 1.1%, 98.9%): Binder::map_bound called at compiler/rustc_type_ir/src/predicate.rs:251:14

zerocopy with -Znext-solver=no

13476410 counts
(  1)  9906183 (73.5%, 73.5%): Binder::map_bound called at compiler/rustc_middle/src/ty/predicate.rs:174:25
(  2)  2107825 (15.6%, 89.1%): Binder::map_bound called at compiler/rustc_type_ir/src/binder.rs:89:14
(  3)   376524 ( 2.8%, 91.9%): Binder::map_bound called at compiler/rustc_type_ir/src/inherent.rs:493:14
(  4)   321976 ( 2.4%, 94.3%): Binder::map_bound called at compiler/rustc_type_ir/src/predicate.rs:251:14
(  5)   262305 ( 1.9%, 96.3%): Binder::map_bound called at compiler/rustc_middle/src/ty/predicate.rs:523:14
(  6)    84143 ( 0.6%, 96.9%): Binder::map_bound called at compiler/rustc_infer/src/infer/outlives/verify.rs:49:47
(  7)    83876 ( 0.6%, 97.5%): Binder::map_bound called at compiler/rustc_infer/src/traits/mod.rs:183:24

compiling std:

32803629 counts
(  1) 12234204 (37.3%, 37.3%): Binder::map_bound called at compiler/rustc_type_ir/src/binder.rs:89:14
(  2)  9624749 (29.3%, 66.6%): Binder::map_bound called at compiler/rustc_middle/src/ty/predicate.rs:174:25
(  3)  3805442 (11.6%, 78.2%): Binder::map_bound called at compiler/rustc_type_ir/src/inherent.rs:493:14
(  4)  2542468 ( 7.8%, 86.0%): Binder::map_bound called at compiler/rustc_type_ir/src/predicate.rs:234:14
(  5)  1229480 ( 3.7%, 89.7%): Binder::map_bound called at compiler/rustc_middle/src/ty/predicate.rs:523:14
(  6)  1176716 ( 3.6%, 93.3%): Binder::map_bound called at compiler/rustc_type_ir/src/predicate.rs:251:14
(  7)   385823 ( 1.2%, 94.5%): Binder::map_bound called at compiler/rustc_type_ir/src/inherent.rs:507:14

Could spend more effort to avoid the validation in trivial Binder::fold_with, but that's not worth it I think.

cc https://rust-lang.zulipchat.com/#narrow/channel/364551-t-types.2Ftrait-system-refactor/topic/casual.20chat.20and.20support/near/628479010

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 2, 2026
@rustbot

rustbot commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

r? @oli-obk

rustbot has assigned @oli-obk.
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, types
  • compiler, types expanded to 77 candidates
  • Random selection from 20 candidates

@oli-obk oli-obk left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@rust-bors

rust-bors Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

📌 Commit ee2a5df has been approved by oli-obk

It is now in the queue for this repository.

@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 Oct 2, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 2, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - #163655 (explicitly handle tests that pass with -Znext-solver)
 - #159924 (Send -fno-lto when linker plugin LTO is not requested to avoid having GCC do LTO when using rustc_codegen_gcc)
 - #163572 (Update the minimum external LLVM to 22)
 - #129822 (Docs - type guarantees update)
 - #157973 (Distinguish `repr(C)` ZSTs from others in ABI compatibility rules)
 - #162332 (preserve overflow in builtin Field candidates)
 - #163574 (intrinsics: Rename `abort` to `abort_immediate`)
 - #163638 (avoid trivial `fn map_bound` validations)
 - #163660 (yeet compare-mode-coherence)
rust-bors Bot pushed a commit that referenced this pull request Oct 3, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - #163655 (explicitly handle tests that pass with -Znext-solver)
 - #159924 (Send -fno-lto when linker plugin LTO is not requested to avoid having GCC do LTO when using rustc_codegen_gcc)
 - #163572 (Update the minimum external LLVM to 22)
 - #129822 (Docs - type guarantees update)
 - #157973 (Distinguish `repr(C)` ZSTs from others in ABI compatibility rules)
 - #162332 (preserve overflow in builtin Field candidates)
 - #163574 (intrinsics: Rename `abort` to `abort_immediate`)
 - #163638 (avoid trivial `fn map_bound` validations)
 - #163660 (yeet compare-mode-coherence)
@rust-bors
rust-bors Bot merged commit 242c2f4 into rust-lang:main Oct 3, 2026
14 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Oct 3, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 3, 2026
Rollup merge of #163638 - lcnr:map-bound-no-validate, r=oli-obk

avoid trivial `fn map_bound` validations

when compiling `zerocopy` a lot of time is spent simply checking the bound vars in `Clause::kind` because it does
```rust
        self.0.internee.map_bound(|kind| match kind {
            PredicateKind::Clause(clause) => clause,
            _ => unreachable!(),
        })
```
let's make performance with `debug_assertions` a bit better:

`zerocopy` with `-Znext-solver`:
```
16884862 counts
(  1) 12189626 (72.2%, 72.2%): Binder::map_bound called at compiler/rustc_middle/src/ty/predicate.rs:174:25
(  2)  1853971 (11.0%, 83.2%): Binder::map_bound called at compiler/rustc_type_ir/src/binder.rs:89:14
(  3)  1443803 ( 8.6%, 91.7%): Binder::map_bound called at compiler/rustc_type_ir/src/inherent.rs:493:14
(  4)   572570 ( 3.4%, 95.1%): Binder::map_bound called at compiler/rustc_type_ir/src/predicate.rs:234:14
(  5)   272733 ( 1.6%, 96.7%): Binder::map_bound called at compiler/rustc_type_ir/src/inherent.rs:507:14
(  6)   184934 ( 1.1%, 97.8%): Binder::map_bound called at compiler/rustc_middle/src/ty/predicate.rs:523:14
(  7)   183998 ( 1.1%, 98.9%): Binder::map_bound called at compiler/rustc_type_ir/src/predicate.rs:251:14
```
`zerocopy` with `-Znext-solver=no`
```
13476410 counts
(  1)  9906183 (73.5%, 73.5%): Binder::map_bound called at compiler/rustc_middle/src/ty/predicate.rs:174:25
(  2)  2107825 (15.6%, 89.1%): Binder::map_bound called at compiler/rustc_type_ir/src/binder.rs:89:14
(  3)   376524 ( 2.8%, 91.9%): Binder::map_bound called at compiler/rustc_type_ir/src/inherent.rs:493:14
(  4)   321976 ( 2.4%, 94.3%): Binder::map_bound called at compiler/rustc_type_ir/src/predicate.rs:251:14
(  5)   262305 ( 1.9%, 96.3%): Binder::map_bound called at compiler/rustc_middle/src/ty/predicate.rs:523:14
(  6)    84143 ( 0.6%, 96.9%): Binder::map_bound called at compiler/rustc_infer/src/infer/outlives/verify.rs:49:47
(  7)    83876 ( 0.6%, 97.5%): Binder::map_bound called at compiler/rustc_infer/src/traits/mod.rs:183:24
```
compiling `std`:
```
32803629 counts
(  1) 12234204 (37.3%, 37.3%): Binder::map_bound called at compiler/rustc_type_ir/src/binder.rs:89:14
(  2)  9624749 (29.3%, 66.6%): Binder::map_bound called at compiler/rustc_middle/src/ty/predicate.rs:174:25
(  3)  3805442 (11.6%, 78.2%): Binder::map_bound called at compiler/rustc_type_ir/src/inherent.rs:493:14
(  4)  2542468 ( 7.8%, 86.0%): Binder::map_bound called at compiler/rustc_type_ir/src/predicate.rs:234:14
(  5)  1229480 ( 3.7%, 89.7%): Binder::map_bound called at compiler/rustc_middle/src/ty/predicate.rs:523:14
(  6)  1176716 ( 3.6%, 93.3%): Binder::map_bound called at compiler/rustc_type_ir/src/predicate.rs:251:14
(  7)   385823 ( 1.2%, 94.5%): Binder::map_bound called at compiler/rustc_type_ir/src/inherent.rs:507:14
```
Could spend more effort to avoid the validation in trivial `Binder::fold_with`, but that's not worth it I think.

cc https://rust-lang.zulipchat.com/#narrow/channel/364551-t-types.2Ftrait-system-refactor/topic/casual.20chat.20and.20support/near/628479010
github-actions Bot pushed a commit to rust-lang/stdarch that referenced this pull request Oct 5, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#163655 (explicitly handle tests that pass with -Znext-solver)
 - rust-lang/rust#159924 (Send -fno-lto when linker plugin LTO is not requested to avoid having GCC do LTO when using rustc_codegen_gcc)
 - rust-lang/rust#163572 (Update the minimum external LLVM to 22)
 - rust-lang/rust#129822 (Docs - type guarantees update)
 - rust-lang/rust#157973 (Distinguish `repr(C)` ZSTs from others in ABI compatibility rules)
 - rust-lang/rust#162332 (preserve overflow in builtin Field candidates)
 - rust-lang/rust#163574 (intrinsics: Rename `abort` to `abort_immediate`)
 - rust-lang/rust#163638 (avoid trivial `fn map_bound` validations)
 - rust-lang/rust#163660 (yeet compare-mode-coherence)
github-actions Bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Oct 5, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#163655 (explicitly handle tests that pass with -Znext-solver)
 - rust-lang/rust#159924 (Send -fno-lto when linker plugin LTO is not requested to avoid having GCC do LTO when using rustc_codegen_gcc)
 - rust-lang/rust#163572 (Update the minimum external LLVM to 22)
 - rust-lang/rust#129822 (Docs - type guarantees update)
 - rust-lang/rust#157973 (Distinguish `repr(C)` ZSTs from others in ABI compatibility rules)
 - rust-lang/rust#162332 (preserve overflow in builtin Field candidates)
 - rust-lang/rust#163574 (intrinsics: Rename `abort` to `abort_immediate`)
 - rust-lang/rust#163638 (avoid trivial `fn map_bound` validations)
 - rust-lang/rust#163660 (yeet compare-mode-coherence)
programskillforverification pushed a commit to programskillforverification/miri that referenced this pull request Oct 5, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#163655 (explicitly handle tests that pass with -Znext-solver)
 - rust-lang/rust#159924 (Send -fno-lto when linker plugin LTO is not requested to avoid having GCC do LTO when using rustc_codegen_gcc)
 - rust-lang/rust#163572 (Update the minimum external LLVM to 22)
 - rust-lang/rust#129822 (Docs - type guarantees update)
 - rust-lang/rust#157973 (Distinguish `repr(C)` ZSTs from others in ABI compatibility rules)
 - rust-lang/rust#162332 (preserve overflow in builtin Field candidates)
 - rust-lang/rust#163574 (intrinsics: Rename `abort` to `abort_immediate`)
 - rust-lang/rust#163638 (avoid trivial `fn map_bound` validations)
 - rust-lang/rust#163660 (yeet compare-mode-coherence)
AzureXuanVerse pushed a commit to AzureXuanVerse/rustfmt that referenced this pull request Oct 7, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#163655 (explicitly handle tests that pass with -Znext-solver)
 - rust-lang/rust#159924 (Send -fno-lto when linker plugin LTO is not requested to avoid having GCC do LTO when using rustc_codegen_gcc)
 - rust-lang/rust#163572 (Update the minimum external LLVM to 22)
 - rust-lang/rust#129822 (Docs - type guarantees update)
 - rust-lang/rust#157973 (Distinguish `repr(C)` ZSTs from others in ABI compatibility rules)
 - rust-lang/rust#162332 (preserve overflow in builtin Field candidates)
 - rust-lang/rust#163574 (intrinsics: Rename `abort` to `abort_immediate`)
 - rust-lang/rust#163638 (avoid trivial `fn map_bound` validations)
 - rust-lang/rust#163660 (yeet compare-mode-coherence)
bjorn3 pushed a commit to rust-lang/rustc_codegen_cranelift that referenced this pull request Oct 8, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#163655 (explicitly handle tests that pass with -Znext-solver)
 - rust-lang/rust#159924 (Send -fno-lto when linker plugin LTO is not requested to avoid having GCC do LTO when using rustc_codegen_gcc)
 - rust-lang/rust#163572 (Update the minimum external LLVM to 22)
 - rust-lang/rust#129822 (Docs - type guarantees update)
 - rust-lang/rust#157973 (Distinguish `repr(C)` ZSTs from others in ABI compatibility rules)
 - rust-lang/rust#162332 (preserve overflow in builtin Field candidates)
 - rust-lang/rust#163574 (intrinsics: Rename `abort` to `abort_immediate`)
 - rust-lang/rust#163638 (avoid trivial `fn map_bound` validations)
 - rust-lang/rust#163660 (yeet compare-mode-coherence)
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. 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.

3 participants