-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Conversation
Some changes occurred in 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 |
There was a problem hiding this 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
compiler/rustc_middle/src/ty/mod.rs
Outdated
} | ||
} | ||
|
||
pub fn as_clause_unchecked(self) -> Clause<'tcx> { | ||
debug_assert!(matches!(self.kind().skip_binder(), PredicateKind::Clause(_))); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 😸
☔ The latest upstream changes (presumably #112351) made this pull request unmergeable. Please resolve the merge conflicts. |
3f05556
to
2395086
Compare
2395086
to
dcee3ab
Compare
@bors r=lcnr |
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)
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
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)
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
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
toty::Clause
(predicates_of
/item_bounds
/ParamEnv::caller_bounds
).Clause
toClauseKind
, so it's parallel withPredicateKind
.Clause
type which is parallel toPredicate
.Clause::kind(self) -> Binder<'tcx, ClauseKind<'tcx>>
which is parallel toPredicate::kind
😸The new
Clause
type essentially acts as a newtype wrapper aroundPredicate
that asserts that it is specifically aPredicateKind::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
https://github.com/rust-lang/rust/pull/112714#issuecomment-1595653910 ↩