Implement MVP for opaque generic const arguments#150823
Implement MVP for opaque generic const arguments#150823camelid wants to merge 1 commit intorust-lang:mainfrom
Conversation
|
TODO:
|
This comment has been minimized.
This comment has been minimized.
|
When we avoid normalizing type consts to opaque anon consts we need to make sure that the normalization is ambiguous in coherence instead of #![feature(min_generic_const_args, opaque_generic_const_args)]
#[type_const]
const FOO<const N: usize>: usize = const { N + 1 };
#[type_const]
const BAR<const N: usize>: usize = const { N + 1 };
trait Trait {}
impl Trait for [(); FOO::<1>] {}
impl Trait for [(); BAR::<1>] {}ie we don't want this code to pass due to the two opaque anon consts being unequal. |
|
Ooh good point 👍 |
This comment has been minimized.
This comment has been minimized.
|
HIR ty lowering was modified cc @fmease |
This comment has been minimized.
This comment has been minimized.
|
also need to add the coherence test :3 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
compiler/rustc_next_trait_solver/src/solve/normalizes_to/free_alias.rs
Outdated
Show resolved
Hide resolved
compiler/rustc_next_trait_solver/src/solve/normalizes_to/anon_const.rs
Outdated
Show resolved
Hide resolved
|
@rustbot author |
This comment has been minimized.
This comment has been minimized.
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
5676879 to
5f63932
Compare
|
@rustbot ready |
This comment has been minimized.
This comment has been minimized.
This is meant to be the interim successor to generic const expressions. Essentially, const item RHS's will be allowed to do arbitrary const operations using generics. The limitation is that these const items will be treated opaquely, like ADTs in nominal typing, such that uses of them will only be equal if the same const item is referenced. In other words, two const items with the exact same RHS will not be considered equal. I also added some logic to check feature gates that depend on others being enabled (like oGCA depending on mGCA). = Coherence = During coherence, OGCA consts should be normalized ambiguously because they are opaque but eventually resolved to a real value. We don't want two OGCAs that have the same value to be treated as distinct for coherence purposes. (Just like opaque types.) This actually doesn't work yet because there are pre-existing fundamental issues with equate relations involving consts that need to be normalized. The problem is that we normalize only one layer of the const item and don't actually process the resulting anon const. Normally the created inference variable should be handled, which in this case would cause us to hit the anon const, but that's not happening. Specifically, `visit_const` on `Generalizer` should be updated to be similar to `visit_ty`.
|
(blessed and removed the fluent file for you, see the diff here: https://triagebot.infra.rust-lang.org/gh-changes-since/rust-lang/rust/150823/c7f5f3e0d5defe632d44743cbaed56272e2b67f0..5f63932e140feac21c5764ea3c72a5211407a44f) |
|
@bors r+ |
This is meant to be the interim successor to generic const expressions.
Essentially, const item RHS's will be allowed to do arbitrary const
operations using generics. The limitation is that these const items will
be treated opaquely, like ADTs in nominal typing, such that uses of them
will only be equal if the same const item is referenced. In other words,
two const items with the exact same RHS will not be considered equal.
I also added some logic to check feature gates that depend on others
being enabled (like oGCA depending on mGCA).
Coherence
During coherence, OGCA consts should be normalized ambiguously because
they are opaque but eventually resolved to a real value. We don't want
two OGCAs that have the same value to be treated as distinct for
coherence purposes. (Just like opaque types.)
This actually doesn't work yet because there are pre-existing
fundamental issues with equate relations involving consts that need to
be normalized. The problem is that we normalize only one layer of the
const item and don't actually process the resulting anon const. Normally
the created inference variable should be handled, which in this case
would cause us to hit the anon const, but that's not happening.
Specifically,
visit_constonGeneralizershould be updated to besimilar to
visit_ty.r? @BoxyUwU