Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a fully fledged Clause type, rename old Clause to ClauseKind #112772

Merged
merged 3 commits into from
Jun 21, 2023

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Jun 18, 2023

Does two basic things before I put up a more delicate set of PRs (along the lines of #112714, but hopefully much cleaner) that migrate existing usages of ty::Predicate to ty::Clause (predicates_of/item_bounds/ParamEnv::caller_bounds).

  1. Rename Clause to ClauseKind, so it's parallel with PredicateKind.
  2. Add a new Clause type which is parallel to Predicate.
    • This type exposes Clause::kind(self) -> Binder<'tcx, ClauseKind<'tcx>> which is parallel to Predicate::kind 😸

The new Clause type essentially acts as a newtype wrapper around Predicate that asserts that it is specifically a PredicateKind::Clause. Turns out from experimentation1 that this is not negative performance-wise, which is wonderful, since this a much simpler design than something that requires encoding the discriminant into the alignment bits of a predicate kind, or something else like that...

r? @lcnr or @oli-obk

Footnotes

  1. https://github.com/rust-lang/rust/pull/112714#issuecomment-1595653910

@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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Jun 18, 2023
@rustbot
Copy link
Collaborator

rustbot commented Jun 18, 2023

Some changes occurred in const_evaluatable.rs

cc @BoxyUwU

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

r=me after nits

}
}

pub fn as_clause_unchecked(self) -> Clause<'tcx> {
debug_assert!(matches!(self.kind().skip_binder(), PredicateKind::Clause(_)));
Copy link
Contributor

Choose a reason for hiding this comment

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

this assert is perf critical? and assuming that it is, would it not be faster to make this an assert and make using the clause use unreachable_unchecked?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think it's perf critical, just seems redundant since we already assert that it's a Clause in Clause::kind.

Copy link
Member Author

Choose a reason for hiding this comment

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

Anyways I made it an assert, and we can make it unreachable_unchecked on the read path if perf warrants it later.

if let ty::PredicateKind::Clause(ty::Clause::Trait(pred)) = pred.kind().skip_binder()
if let ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) = pred.kind().skip_binder()
Copy link
Contributor

Choose a reason for hiding this comment

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

What's your opinion on reexporting the ClauseKind variants from a clause module and using clause::Trait instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Eh, doesn't really seem worthwhile tbh. Or at least, I think I want to do it as a follow-up 😸

@bors
Copy link
Contributor

bors commented Jun 19, 2023

☔ The latest upstream changes (presumably #112351) made this pull request unmergeable. Please resolve the merge conflicts.

@oli-obk
Copy link
Contributor

oli-obk commented Jun 19, 2023

@bors r=lcnr

@bors
Copy link
Contributor

bors commented Jun 19, 2023

📌 Commit dcee3ab has been approved by lcnr

It is now in the queue for this repository.

@bors bors 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 19, 2023
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Jun 20, 2023
Add a fully fledged `Clause` type, rename old `Clause` to `ClauseKind`

Does two basic things before I put up a more delicate set of PRs (along the lines of rust-lang#112714, but hopefully much cleaner) that migrate existing usages of `ty::Predicate` to `ty::Clause` (`predicates_of`/`item_bounds`/`ParamEnv::caller_bounds`).

1. Rename `Clause` to `ClauseKind`, so it's parallel with `PredicateKind`.
2. Add a new `Clause` type which is parallel to `Predicate`.
    * This type exposes `Clause::kind(self) -> Binder<'tcx, ClauseKind<'tcx>>` which is parallel to `Predicate::kind` 😸

The new `Clause` type essentially acts as a newtype wrapper around `Predicate` that asserts that it is specifically a `PredicateKind::Clause`. Turns out from experimentation[^1] that this is not negative performance-wise, which is wonderful, since this a much simpler design than something that requires encoding the discriminant into the alignment bits of a predicate kind, or something else like that...

r? `@lcnr` or `@oli-obk`

[^1]: rust-lang#112714 (comment)
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 21, 2023
Rollup of 6 pull requests

Successful merges:

 - rust-lang#112632 (Implement PartialOrd for `Vec`s over different allocators)
 - rust-lang#112759 (Make closure_saved_names_of_captured_variables a query. )
 - rust-lang#112772 (Add a fully fledged `Clause` type, rename old `Clause` to `ClauseKind`)
 - rust-lang#112790 (Syntactically accept `become` expressions (explicit tail calls experiment))
 - rust-lang#112830 (More codegen cleanups)
 - rust-lang#112844 (Add retag in MIR transform: `Adt` for `Unique` may contain a reference)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a98c14f into rust-lang:master Jun 21, 2023
@rustbot rustbot added this to the 1.72.0 milestone Jun 21, 2023
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jun 30, 2023
Add a fully fledged `Clause` type, rename old `Clause` to `ClauseKind`

Does two basic things before I put up a more delicate set of PRs (along the lines of rust-lang#112714, but hopefully much cleaner) that migrate existing usages of `ty::Predicate` to `ty::Clause` (`predicates_of`/`item_bounds`/`ParamEnv::caller_bounds`).

1. Rename `Clause` to `ClauseKind`, so it's parallel with `PredicateKind`.
2. Add a new `Clause` type which is parallel to `Predicate`.
    * This type exposes `Clause::kind(self) -> Binder<'tcx, ClauseKind<'tcx>>` which is parallel to `Predicate::kind` 😸

The new `Clause` type essentially acts as a newtype wrapper around `Predicate` that asserts that it is specifically a `PredicateKind::Clause`. Turns out from experimentation[^1] that this is not negative performance-wise, which is wonderful, since this a much simpler design than something that requires encoding the discriminant into the alignment bits of a predicate kind, or something else like that...

r? ``@lcnr`` or ``@oli-obk``

[^1]: rust-lang#112714 (comment)
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jun 30, 2023
Rollup of 6 pull requests

Successful merges:

 - rust-lang#112632 (Implement PartialOrd for `Vec`s over different allocators)
 - rust-lang#112759 (Make closure_saved_names_of_captured_variables a query. )
 - rust-lang#112772 (Add a fully fledged `Clause` type, rename old `Clause` to `ClauseKind`)
 - rust-lang#112790 (Syntactically accept `become` expressions (explicit tail calls experiment))
 - rust-lang#112830 (More codegen cleanups)
 - rust-lang#112844 (Add retag in MIR transform: `Adt` for `Unique` may contain a reference)

r? `@ghost`
`@rustbot` modify labels: rollup
@compiler-errors compiler-errors deleted the clauses-1 branch August 11, 2023 19:56
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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants