Skip to content

Optimisation: avoid emitting verify bounds that always hold#152579

Open
amandasystems wants to merge 2 commits intorust-lang:mainfrom
amandasystems:skip-useless-type-tests
Open

Optimisation: avoid emitting verify bounds that always hold#152579
amandasystems wants to merge 2 commits intorust-lang:mainfrom
amandasystems:skip-useless-type-tests

Conversation

@amandasystems
Copy link
Contributor

@amandasystems amandasystems commented Feb 13, 2026

This PR normalises verify bounds that always hold and uses that logic to cheaply detect that case and never emit them.

This leaves a ton of tripwire assertions around that will activate if these assumptions are violated.

VerifyBound::or() is now also short-circuiting and flattens immediately nested Any bounds. Note that the short-circuiting means information may be lost if both bounds are failing and we want to keep both failing bounds.

r? @lcnr

@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 Feb 13, 2026
… hold

This makes more sense than you'd imagine since empty `All` bounds which
always hold is relatively common.
@amandasystems amandasystems force-pushed the skip-useless-type-tests branch from d55cf4c to 6b612a0 Compare February 13, 2026 16:21
@amandasystems amandasystems changed the title Optimisation: avoid emitting type tests for verify bounds that always hold Optimisation: avoid emitting verify bounds that always hold Feb 16, 2026

// If this bound is always satisfied, a complex bound should never have been
// constructed and we should have gotten [[`VerifyBound::always_satisfied`]]
debug_assert!(
Copy link
Contributor

Choose a reason for hiding this comment

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

redundant assert?

@lcnr
Copy link
Contributor

lcnr commented Feb 26, 2026

@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 Feb 26, 2026
Optimisation: avoid emitting verify bounds that always hold
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 26, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 26, 2026

☀️ Try build successful (CI)
Build commit: 158e3b6 (158e3b6f56887675a169b2ed66abbe28c64ab6a7, parent: bb779a91568ac1ee0b8a9dcb6b69219ef30b18a3)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (158e3b6): comparison URL.

Overall result: ✅ improvements - 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

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.2% [-0.3%, -0.2%] 6
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.2%] 1
All ❌✅ (primary) -0.2% [-0.3%, -0.2%] 6

Max RSS (memory usage)

Results (primary 3.0%)

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

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

Cycles

Results (secondary 2.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)
3.7% [2.3%, 4.5%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.9% [-2.9%, -2.9%] 1
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 480.119s -> 484.722s (0.96%)
Artifact size: 395.65 MiB -> 395.65 MiB (0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 26, 2026
this.append(&mut that);
VerifyBound::AnyBound(this)
}
// FIXME: This can still nest arbitrarily.
Copy link
Contributor

Choose a reason for hiding this comment

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

why FIXME?

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

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants