Skip to content

Add a check for impossible predicates to trivial_const - #156934

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
saethlin:impossible-bounds-check
Jun 12, 2026
Merged

Add a check for impossible predicates to trivial_const#156934
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
saethlin:impossible-bounds-check

Conversation

@saethlin

@saethlin saethlin commented May 25, 2026

Copy link
Copy Markdown
Member

View all comments

The problem here is that trivial consts bypass the MIR pass which replaces bodies with unreachable when there are false global bounds. see #147721 (comment).

This fixes the problem, but it is a bit hacky. But maybe all the handling of false global bounds is hacky?

@rustbot

rustbot commented May 25, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@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 May 25, 2026
@rustbot

rustbot commented May 25, 2026

Copy link
Copy Markdown
Collaborator

BoxyUwU is currently at their maximum review capacity.
They may take a while to respond.

@cjgillot

Copy link
Copy Markdown
Contributor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 30, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request May 30, 2026
Add a check for impossible predicates to trivial_const
@rust-bors

rust-bors Bot commented May 31, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 131aad2 (131aad2325ddc63f4d13d56c4362a59aafa966ba, parent: f8a08b688cbe60acc386ed1fbd1b7cbaaf5576b1)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (131aad2): comparison URL.

Overall result: ❌ regressions - 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.4% [0.2%, 0.5%] 11
Regressions ❌
(secondary)
0.4% [0.0%, 0.7%] 13
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.2% [-2.2%, -2.2%] 1
All ❌✅ (primary) 0.4% [0.2%, 0.5%] 11

Max RSS (memory usage)

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

Cycles

Results (primary 2.0%, secondary 2.9%)

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

mean range count
Regressions ❌
(primary)
2.0% [2.0%, 2.0%] 1
Regressions ❌
(secondary)
3.8% [2.4%, 5.0%] 7
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.0% [-3.0%, -3.0%] 1
All ❌✅ (primary) 2.0% [2.0%, 2.0%] 1

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 511.354s -> 510.996s (-0.07%)
Artifact size: 400.80 MiB -> 400.70 MiB (-0.03%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels May 31, 2026
@saethlin

Copy link
Copy Markdown
Member Author

IMO the perf overhead is fine, all that the "regression" means is that the trival_const optimization is now a touch less of an improvement, see this perf run from the initial implementation: #148040 (comment)

@BoxyUwU

BoxyUwU commented Jun 7, 2026

Copy link
Copy Markdown
Member

false global bounds continue to make me unhappy 😆 in the long term we hopefully can cleanup this special case but for now it seems reasonable enough to me.

note that impossible_bounds uses the new solver internally even on stable. this seems reasonable enough to me and probably doesn't warrant wider sign off? cc @rust-lang/initiative-trait-system-refactor

can you add something to the PR description which links to #147721 specifically helix's comment about trivial consts bypassing the existing jank around false global bounds on const items

@saethlin

saethlin commented Jun 7, 2026

Copy link
Copy Markdown
Member Author

Updated. Feel free to just modify the PR description yourself, I don't really understand type system implementation context here I just identified where to insert the right hack to make a test case pass.

BoxyUwU
BoxyUwU approved these changes Jun 8, 2026
return None;
}

if crate::impossible_predicates::has_impossible_predicates(tcx, def.into()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if crate::impossible_predicates::has_impossible_predicates(tcx, def.into()) {
// If there are impossible predicates then MIR passes will replace the body with
// `unreachable` causing const eval errors when trying to evaluate the body. For
// now we avoid using trivial consts for such bodies so that the behaviour doesn't
// change.
if crate::impossible_predicates::has_impossible_predicates(tcx, def.into()) {

@BoxyUwU BoxyUwU Jun 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

though, writing this out, your logic here just straight up looks at the MIR so I'm surprised there'd wind up being a divergence? are you looking at different MIR than what const eval actually executes? if so why :3

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

are you looking at different MIR than what const eval actually executes? if so why :3

Yes. The entire idea of trivial_const is to bypass the numerous MIR passes and queries that are done on MIR bodies to lower consts, because in the common case all those passes and queries just add compile time.

It would probably make sense for trivial_const to intercept const lowering before MIR is built.

@lcnr

lcnr commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

note that impossible_bounds uses the new solver internally even on stable. this seems reasonable enough to me and probably doesn't warrant wider sign off? cc @rust-lang/initiative-trait-system-refactor

yeah, we already use this when building vtables, so relying on this more sgtm

@saethlin

saethlin commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

@bors squash

@rust-bors

This comment has been minimized.

* Add a check for impossible predicates to trivial_const
* Improve comment on impossible predicates check

Co-authored-by: Boxy <rust@boxyuwu.dev>
@rust-bors

rust-bors Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

🔨 2 commits were squashed into 8dc9f9a.

@rust-bors
rust-bors Bot force-pushed the impossible-bounds-check branch from 1fa0962 to 8dc9f9a Compare June 9, 2026 22:07
@BoxyUwU

BoxyUwU commented Jun 10, 2026

Copy link
Copy Markdown
Member

@bors r+ rollup=never (perf sensitive)

@rust-bors

rust-bors Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 8dc9f9a has been approved by BoxyUwU

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 Jun 10, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 11, 2026
Add a check for impossible predicates to trivial_const



The problem here is that trivial consts bypass the MIR pass which replaces bodies with `unreachable` when there are false global bounds.  see #147721 (comment).

This fixes the problem, but it is a bit hacky. But maybe all the handling of false global bounds is hacky?
@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@bors yield
Stuck again, hasn't printed anything in hours

@rust-bors

rust-bors Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #157739.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 12, 2026
Add a check for impossible predicates to trivial_const



The problem here is that trivial consts bypass the MIR pass which replaces bodies with `unreachable` when there are false global bounds.  see #147721 (comment).

This fixes the problem, but it is a bit hacky. But maybe all the handling of false global bounds is hacky?
@rust-bors rust-bors Bot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 12, 2026
@rust-bors

rust-bors Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

💔 Test for 5f9f26e failed: CI. Failed job:

@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 Jun 12, 2026
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

A job failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
  WIX: /d/a/rust/rust/wix
##[endgroup]
    Updating crates.io index
error: failed to get `simd-adler32` as a dependency of package `miniz_oxide v0.8.8`
    ... which satisfies dependency `miniz_oxide = "^0.8.5"` of package `flate2 v1.1.9`
    ... which satisfies dependency `flate2 = "^1.1.9"` of package `citool v0.1.0 (D:\a\rust\rust\src\ci\citool)`

Caused by:
  failed to load source for dependency `simd-adler32`

Caused by:

@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 Jun 12, 2026
@rust-bors

rust-bors Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

☀️ Test successful - CI
Approved by: BoxyUwU
Duration: 3h 13m 42s
Pushing 3bdd7f8 to main...

@rust-bors
rust-bors Bot merged commit 3bdd7f8 into rust-lang:main Jun 12, 2026
13 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jun 12, 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 a1e52fc (parent) -> 3bdd7f8 (this PR)

Test differences

Show 4 test diffs

Stage 1

  • [ui] tests/ui/traits/trivial-const-with-impossible-bounds.rs: [missing] -> pass (J0)

Stage 2

  • [ui] tests/ui/traits/trivial-const-with-impossible-bounds.rs: [missing] -> pass (J1)

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

Job group index

  • J0: x86_64-gnu-llvm-21-3, x86_64-gnu-llvm-22-3
  • J1: aarch64-apple, aarch64-gnu, aarch64-gnu-llvm-21-1, aarch64-msvc-1, arm-android, armhf-gnu, dist-i586-gnu-i586-i686-musl, i686-gnu-1, i686-gnu-nopt-1, i686-msvc-1, optional-x86_64-gnu-parallel-frontend, test-various, x86_64-gnu, x86_64-gnu-debug, x86_64-gnu-gcc, x86_64-gnu-llvm-21, x86_64-gnu-llvm-21-2, x86_64-gnu-llvm-22-2, x86_64-gnu-nopt, x86_64-gnu-stable, x86_64-mingw-1, x86_64-msvc-1
Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 3bdd7f86fcecc0ea65d79e62e39a70c8a2aabf15 --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. pr-check-2: 40m 49s -> 27m 14s (-33.3%)
  2. dist-apple-various: 1h 29m -> 1h 56m (+30.0%)
  3. i686-msvc-1: 3h 16m -> 2h 19m (-28.6%)
  4. i686-gnu-2: 1h 15m -> 1h 32m (+21.5%)
  5. dist-x86_64-netbsd: 1h 27m -> 1h 8m (-21.3%)
  6. pr-check-1: 27m 28s -> 21m 49s (-20.5%)
  7. arm-android: 1h 21m -> 1h 35m (+17.9%)
  8. aarch64-apple: 3h 25m -> 2h 50m (-17.1%)
  9. x86_64-gnu-nopt: 2h 37m -> 2h 16m (-13.6%)
  10. x86_64-gnu-llvm-21: 1h 12m -> 1h 21m (+13.0%)
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 (3bdd7f8): comparison URL.

Overall result: ❌ regressions - please read:

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

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.4% [0.2%, 0.5%] 10
Regressions ❌
(secondary)
0.4% [0.2%, 0.7%] 10
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.4% [0.2%, 0.5%] 10

Max RSS (memory usage)

Results (secondary -3.3%)

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)
-3.3% [-6.3%, -1.5%] 3
All ❌✅ (primary) - - 0

Cycles

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

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 519.113s -> 519.494s (0.07%)
Artifact size: 400.82 MiB -> 400.81 MiB (-0.00%)

@saethlin
saethlin deleted the impossible-bounds-check branch June 13, 2026 15:53
@panstromek

Copy link
Copy Markdown
Contributor

perf triage:

This regression was justified per-merge in #156934 (comment)

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Jun 15, 2026
Kobzol pushed a commit to Kobzol/rust that referenced this pull request Jun 21, 2026
…BoxyUwU

Add a check for impossible predicates to trivial_const



The problem here is that trivial consts bypass the MIR pass which replaces bodies with `unreachable` when there are false global bounds.  see rust-lang#147721 (comment).

This fixes the problem, but it is a bit hacky. But maybe all the handling of false global bounds is hacky?
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. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. 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