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

Tracking Issue for associated const equality #92827

Open
8 tasks
JulianKnodt opened this issue Jan 12, 2022 · 12 comments
Open
8 tasks

Tracking Issue for associated const equality #92827

JulianKnodt opened this issue Jan 12, 2022 · 12 comments
Assignees
Labels
A-associated-items Area: Associated items (types, constants & functions) A-const-generics Area: const generics (parameters and arguments) B-experimental Blocker: In-tree experiment; RFC pending or unneeded. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. F-associated_const_equality `#![feature(associated_const_equality)]` S-tracking-impl-incomplete Status: The implementation is incomplete. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@JulianKnodt
Copy link
Contributor

JulianKnodt commented Jan 12, 2022

This is a tracking issue for the experimental feature associated const equality brought up in #702561 (RFC pending).
The feature gate for the issue is #![feature(associated_const_equality)].

About experimental features

An experimental feature is one that has not yet had an RFC. The idea is to allow implementation work to proceed to better inform an upcoming RFC. Experimental features cannot be stabilized without first having an RFC. The existence of an experimental feature does not indicate lang team consensus that the feature is desirable, only that there is a problem that is worthy of being solved and that the idea has enough merit to consider exploring. See the lang team process page for more details.

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.

Steps

Unresolved Questions

None so far.

Implementation history

Footnotes

  1. Original proposal with support but no official RFC, but implementation delayed.

  2. Initial effort to implement which includes parsing and use of term throughout the codebase, but still lacking a complete implementation.

  3. More thorough implementation which works for basic cases. This allowed for consts to actually be bound, more than just parsing them.

@JulianKnodt JulianKnodt added the C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. label Jan 12, 2022
bors added a commit to rust-lang-ci/rust that referenced this issue Feb 1, 2022
Continue work on associated const equality

This actually implements some more complex logic for assigning associated consts to values.
Inside of projection candidates, it now defers to a separate function for either consts or
types. To reduce amount of code, projections are now generic over T, where T is either a Type or
a Const. I can add some comments back later, but this was the fastest way to implement it.

It also now finds the correct type of consts in type_of.

---

The current main TODO is finding the const of the def id for the LeafDef.

Right now it works if the function isn't called, but once you use the trait impl with the bound it fails inside projection.
I was hoping to get some help in getting the `&'tcx ty::Const<'tcx>`, in addition to a bunch of other `todo!()`s which I think may not be hit.

r? `@oli-obk`

Updates rust-lang#92827
@pushkine
Copy link

pushkine commented Feb 8, 2022

Hello!
Is there a corresponding RFC, or any context whatsoever concerning those changes ?
This is the first occurrence of language syntax change that is not backed by RFC and community feedback
@Centril @oli-obk

@oli-obk
Copy link
Contributor

oli-obk commented Feb 8, 2022

Well, we have #70256 which indeed has basically no discussion of the feature. It just seemed like an oversight to have associated types + associated type bounds, but only associated consts without any bounds for them.

@JulianKnodt
Copy link
Contributor Author

I probably should've tagged the original issue in this at the start (it was in the original PR if I remember correctly) but I'm bad at leaving a thorough paper trail. I'll add a reference to the original issue in the issue itself, and if there's more work that needs to be done please let know

@oli-obk
Copy link
Contributor

oli-obk commented Feb 8, 2022

You did everything correctly. I found the issue because you did link it in the first sentence in this issue 😄

We should probably do a lang team MCP for it along with some medium sized doc explaining what is going on and why. I'll open a hackmd and then we can collab on it

github-actions bot pushed a commit to rust-lang/glacier that referenced this issue Feb 12, 2022
=== stdout ===
=== stderr ===
error: comparison operators cannot be chained
 --> /home/runner/work/glacier/glacier/ices/93835.rs:2:8
  |
1 | fn e() {
  |        - while parsing this struct
2 |     p:a<p:p<e=6>>
  |        ^        ^
  |
  = help: use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments
  = help: or use `(...)` if you meant to specify fn arguments

error[E0425]: cannot find value `p` in this scope
 --> /home/runner/work/glacier/glacier/ices/93835.rs:2:5
  |
2 |     p:a<p:p<e=6>>
  |     ^ not found in this scope
  |
help: you might have meant to write a `struct` literal
  |
1 ~ fn e() { SomeStruct {
2 |     p:a<p:p<e=6>>
3 ~ }}
  |
help: maybe you meant to write a path separator here
  |
2 |     p::a<p:p<e=6>>
  |      ~~
help: maybe you meant to write an assignment here
  |
2 |     let p:a<p:p<e=6>>
  |     ~~~~~

error[E0658]: associated const equality is incomplete
 --> /home/runner/work/glacier/glacier/ices/93835.rs:2:13
  |
2 |     p:a<p:p<e=6>>
  |             ^^^
  |
  = note: see issue #92827 <rust-lang/rust#92827> for more information
  = help: add `#![feature(associated_const_equality)]` to the crate attributes to enable

error[E0658]: associated type bounds are unstable
 --> /home/runner/work/glacier/glacier/ices/93835.rs:2:9
  |
2 |     p:a<p:p<e=6>>
  |         ^^^^^^^^
  |
  = note: see issue #52662 <rust-lang/rust#52662> for more information
  = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable

error[E0601]: `main` function not found in crate `93835`
 --> /home/runner/work/glacier/glacier/ices/93835.rs:1:1
  |
1 | / fn e() {
2 | |     p:a<p:p<e=6>>
3 | | }
  | |_^ consider adding a `main` function to `/home/runner/work/glacier/glacier/ices/93835.rs`

error: aborting due to 5 previous errors

Some errors have detailed explanations: E0425, E0601, E0658.
For more information about an error, try `rustc --explain E0425`.
==============
@dtolnay dtolnay added A-associated-items Area: Associated items (types, constants & functions) T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Mar 14, 2022
github-actions bot pushed a commit to rust-lang/glacier that referenced this issue Jul 31, 2022
=== stdout ===
=== stderr ===
error[E0658]: associated const equality is incomplete
 --> /home/runner/work/glacier/glacier/ices/99828.rs:1:43
  |
1 | fn get_iter(vec: &[i32]) -> impl Iterator<Item = {}> + '_ {
  |                                           ^^^^^^^^^
  |
  = note: see issue #92827 <rust-lang/rust#92827> for more information
  = help: add `#![feature(associated_const_equality)]` to the crate attributes to enable

error: expected associated type bound, found constant
 --> /home/runner/work/glacier/glacier/ices/99828.rs:1:43
  |
1 | fn get_iter(vec: &[i32]) -> impl Iterator<Item = {}> + '_ {
  |                                           ^^^^^^^^^
  |
note: associated type defined here

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0658`.
==============
@joshtriplett joshtriplett added the S-tracking-needs-summary Status: It's hard to tell what's been done and what hasn't! Someone should do some investigation. label Aug 10, 2022
@joshtriplett
Copy link
Member

What's the current state of this? How much is implemented, and how functional is it?

@JulianKnodt
Copy link
Contributor Author

@joshtriplett I've started work on it, and the syntax/parsing is in place, but the implementation currently does not work. I started working on Chalk, but that has stalled since I wasn't really able to know whether it was necessary for implementing it in rustc. I've also gotten a bit sidetracked working on other things.

@urben1680
Copy link

urben1680 commented Aug 12, 2022

Is it planned to recognize Associated Constant Equality as disjoint cases?

trait Foo{
    const DECIDER: bool;
}
trait Bar{ /*stuff*/ }
impl<T: Foo<DECIDER = true>> Bar for T{ /*stuff*/ }
impl<T: Foo<DECIDER = false>> Bar for T{ /*stuff*/ }

@fmease

This comment was marked as resolved.

@rustbot rustbot added the F-associated_const_equality `#![feature(associated_const_equality)]` label Sep 27, 2022
@JulianKnodt
Copy link
Contributor Author

@urben1680 I believe this would be the main point of this, but I have not got around to actually implementing it

rawler added a commit to rawler/dasp that referenced this issue Nov 15, 2022
Replace the hard-coded macro implementing `Frame` for `[impl Sample;0-32]`,
with a generic impl based on const-generics.

I discovered the need for this, when trying to simplify some macro-
-implementations in the `ebur128` crate with const-generics.

We cannot remove the need for `NumChannels`, since (see reference 1)
"Associated Const Equality" is not yet stable. We can however adapt the
`NumChannels` strategy from `N1..N32` to a `NChannels<N>`-generic type.

Some opportunities like removing `unsafe` from `zip_map`, remain out of
reach due to pending stabilization of the standard library.

1: rust-lang/rust#92827
rawler added a commit to rawler/dasp that referenced this issue Nov 17, 2022
Replace the hard-coded macro implementing `Frame` for `[impl Sample;0-32]`,
with a generic impl based on const-generics.

I discovered the need for this, when trying to simplify some macro-
-implementations in the `ebur128` crate with const-generics.

We cannot remove the need for `NumChannels`, since (see reference 1)
"Associated Const Equality" is not yet stable. We can however adapt the
`NumChannels` strategy from `N1..N32` to a `NChannels<N>`-generic type.

Some opportunities like removing `unsafe` from `zip_map`, remain out of
reach due to pending stabilization of the standard library.

1: rust-lang/rust#92827
Antikyth added a commit to XdotRS/xrb that referenced this issue Jan 23, 2023
cc rust-lang/rust#92827 - would be nice to be able to ensure a generic event is absolutely 32 bytes in ConstantX11Size::X11_SIZE, it could be very easy to wreak havoc by accidentally having an incorrectly sized event in SendEvent.
@djdisodo

This comment was marked as off-topic.

@ifsheldon
Copy link

Another use case would be checking tensor shapes. I hit this issue when compiling my code that constrains the shapes of input tensors to have the same dimensionality and/or rank.

For example, dumb code like the below

pub trait TensorShape1D {
    const SHAPE: usize;  // i.e. length
}

pub fn add<const L: usize, LEFT_TENSOR: TensorShape1D<SHAPE=L>, RIGHT_TENSOR: TensorShape1D<SHAPE=L>>(left: LEFT_TENSOR, right: RIGHT_TENSOR) {
    todo!()
}

Any two structs that implement TensorShape1D and have the same SHAPE can be the input of this function.

Right now, I have to use typenum crate and associated type to do the same checking, but it would be great to not have to type-dance like typenum. I think when this is implemented, typenum can be greatly simplified.

@rust-lang rust-lang locked as off-topic and limited conversation to collaborators Mar 21, 2023
@oli-obk
Copy link
Contributor

oli-obk commented Mar 21, 2023

Tracking issues have a tendency to become unmanageable. Please open a dedicated new issue and label it with F-associated_const_equality `#![feature(associated_const_equality)]` for absolutely any topics you want to discuss or have questions about. See rust-lang/compiler-team#739 for details and discussions on this prospective policy.

@fmease fmease added S-tracking-impl-incomplete Status: The implementation is incomplete. B-experimental Blocker: In-tree experiment; RFC pending or unneeded. and removed S-tracking-needs-summary Status: It's hard to tell what's been done and what hasn't! Someone should do some investigation. labels Mar 13, 2024
@rust-lang rust-lang unlocked this conversation Apr 15, 2024
@fmease fmease changed the title Tracking Issue for Associated Const Equality Tracking Issue for associated const equality May 29, 2024
@fmease fmease self-assigned this Sep 13, 2024
apoelstra added a commit to apoelstra/rust-bech32 that referenced this issue Sep 23, 2024
The existing code panics if you try to decode a too-large checksum and
it fails, which is definitely wrong. Fix this so that FieldVec::from_iter
does not panic, allowing the "invalid residue" error to be constructed.

There is also a panic when trying to correct too-large checksums. This
is arguably permissible, since it's something that's detectable at
compile time (though what would be even better is if this language would
support telling the compiler to do this; see
rust-lang/rust#92827
for more info). But remove it anyway.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-const-generics Area: const generics (parameters and arguments) B-experimental Blocker: In-tree experiment; RFC pending or unneeded. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. F-associated_const_equality `#![feature(associated_const_equality)]` S-tracking-impl-incomplete Status: The implementation is incomplete. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests