Skip to content

Predicate/clause cleanups#157104

Draft
nnethercote wants to merge 8 commits into
rust-lang:mainfrom
nnethercote:predicate-clause-cleanups
Draft

Predicate/clause cleanups#157104
nnethercote wants to merge 8 commits into
rust-lang:mainfrom
nnethercote:predicate-clause-cleanups

Conversation

@nnethercote
Copy link
Copy Markdown
Contributor

Clause is a subset of Predicate, more or less. (Interning makes things slightly more complicated than that.) There are numerous places where the code deals in predicates but really only clauses are possible. This PR eliminates some of them. Details in individual commits.

And insert some blank lines.
`check_predicates` currently does the following.
- Builds `impl2_predicates` by gathering some clauses and converting
  them into predicates.
- Extends `impl2_predicates` with some actual predicates from
  `elaborate`.
- Iterates over `impl1_predicates` (which are actually clauses),
  converting each clause to a predicate in order to look for a match
  with any predicate in `impl2_predicates`.

After this commit it instead does the following.
- Builds `impl2_clauses` by gathering some clauses.
- Extends `impl2_clauses` with only the predicates from `elaborate`
  that are clauses (pre-filtering out non-clause predicates).
- Iterates over `impl1_clauses` (now correctly named), to look for a
  match with any clause in `impl2_clauses`.

I.e. instead of promoting clauses to predicates and doing some
comparisons that can't succeed, we pre-filter any non-clause predicates
before doing the comparisons.
`deduce_closure_signature_from_predicates` currently takes a `Predicate`
iterator. But it ignores any predicates that are not clauses. This
commit changes it to take a `Clause` iterator. The change requires one
call site to pre-filter any non-clause predicates, but also lets another
site avoid uselessly promoting clauses to predicates.
`get_future_output` takes a predicate, but can only succeed if the
predicate is a clause. This commit changes it to take a clause. This
requires changing one call site to pre-filter any non-clause predicates,
but also lets another site avoid uselessly promoting clauses to
predicates.
`Predicate` already implements `Flags`. By adding an impl of `Flags` for
`Clause`, we can call `flags` and `outer_exclusive_binder` directly on
clauses, instead of having to convert them to predicates first.
`caller_bounds` returns a sequence of clauses, but all the call sites
use variables as if it returns predicates. Similarly,
`assemble_candidates_from_predicates` actually takes clauses, not
predicates.

This commit renames things appropriately, replacing name mixups like
`tcx.mk_clauses(&predicates)` with `tcx.mk_clauses(&clauses)`.
`evaluate_predicates` creates some predicate lists from clauses, and
then later converts them back to clauses. This commit avoids this back
and forth. The only tricky part is the addition of an `expect_clause`
call in `evaluate_nested_obligations` to extract a clause from a
predicate that we've already matched as a clause.
Currently they both take arguments that can be upcast into a predicate.
But in practice the arguments at all call sites are things that can be
upcast to a clause. So this commits changes their names and types to
work with clauses, which are more specific.
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels May 29, 2026
@nnethercote
Copy link
Copy Markdown
Contributor Author

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

This comment has been minimized.

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

rust-bors Bot commented May 29, 2026

☀️ Try build successful (CI)
Build commit: ddecfc1 (ddecfc1e61c27ae75eda5bcf833358094661b716, parent: dc375db7d8df0aa450e622c529147c95eee756f5)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (ddecfc1): 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
Regressions ❌
(secondary)
0.1% [0.0%, 0.1%] 3
Improvements ✅
(primary)
-0.5% [-1.0%, -0.2%] 3
Improvements ✅
(secondary)
-0.1% [-0.2%, -0.0%] 4
All ❌✅ (primary) -0.5% [-1.0%, -0.2%] 3

Max RSS (memory usage)

Results (primary -5.2%, secondary -2.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)
- - 0
Improvements ✅
(primary)
-5.2% [-5.2%, -5.2%] 1
Improvements ✅
(secondary)
-2.0% [-2.5%, -1.6%] 2
All ❌✅ (primary) -5.2% [-5.2%, -5.2%] 1

Cycles

Results (primary 2.0%, 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)
2.0% [2.0%, 2.0%] 1
Regressions ❌
(secondary)
5.9% [2.9%, 10.7%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-5.0% [-7.6%, -2.3%] 3
All ❌✅ (primary) 2.0% [2.0%, 2.0%] 1

Binary size

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

Bootstrap: 510.27s -> 513.645s (0.66%)
Artifact size: 400.65 MiB -> 400.61 MiB (-0.01%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc 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