Skip to content

Commit 0c3df2c

Browse files
authored
Merge pull request #21 from lcnr/uwu-new-book
uwu a list of all the issues
2 parents a33bec1 + 5e401da commit 0c3df2c

13 files changed

+209
-136
lines changed

SUMMARY.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@
1717
- [📅 Roadmap for 2021](./vision/roadmap.md)
1818
- [❓How to vision doc](./vision/how_to_vision_doc.md)
1919
- [🔍 Meetings](./meetings/README.md)
20-
- [📚 Design Documents](./design-docs/README.md)
21-
- [Anon const substs](./design-docs/anon-const-substs.md)
22-
- [Const eval requirements](./design-docs/const-eval-requirements.md)
23-
- [Generic const param types](./design-docs/generic-const-param-types.md)
20+
- [📚 Design](./design/README.md)
21+
- [❗ Constraining generic parameters](./design/constraining-generic-parameters.md)
22+
- [❗⚖️🔄 Generic const parameter types](./design/generic-const-param-types.md)
23+
- [❗🔙 Restrictions on const evaluation](./design/const-eval-requirements.md)
24+
- [❗🔙 ⚖️ Structural equality](./design/structural-equality.md)
25+
- [❗⚖️ Valid const parameter types](./design/valid-const-parameter-types.md)
26+
- [❗ Valtrees](./design/valtrees.md)
27+
- [❔ Exhaustiveness](./design/exhaustiveness.md)
28+
- [❔🔙 Functions as const parameters](./design/functions-as-const-parameters.md)
2429
- [✏️ Draft RFCs](./draft-rfcs/README.md)
2530
s

design-docs/README.md

-3
This file was deleted.

design-docs/anon-const-substs.md

-113
This file was deleted.

design-docs/const-eval-requirements.md

-14
This file was deleted.

design/README.md

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# 📚 Design
2+
3+
For an explanation of how const generics currently works in the compiler,
4+
also check out the [rustc-dev-guide](https://rustc-dev-guide.rust-lang.org/constants.html).
5+
6+
7+
Const generics has quite a few deep rooted issues and design challenges.
8+
In this document we try to highlight some specific topics which are fairly
9+
pervasive while working on this feature.
10+
11+
### 🔙 Backwards compatability
12+
13+
Rust was not design with const generics in mind, and we've also made
14+
some unfortunate decisions even after work on const generics started.
15+
16+
Future extensions of const generics must not cause substantial breakage
17+
to existing code, or if they do, this breakage has to be contained somehow.
18+
A possible solution to many such changes are editions.
19+
20+
### ⚖️ No perfect solution
21+
22+
There isn't just one *perfect* version of const generics we are working towards.
23+
Instead there are a lot of major and minor tradeoffs between learnability, expressiveness,
24+
implementation complexity and many other factors. As we can't perfectly tell how
25+
const generics will be used in the future, making these decisions can be especially
26+
hard. For any such issues we should try to reach out to the wider community before
27+
coming to a final conclusion.
28+
29+
### 🔄 The query system
30+
31+
Const generics mixes evaluation with typechecking which very quickly reaches the edge
32+
of what is possible with the query system. It might make sense to look at these issues in
33+
unison and consider whether there are some more fundamental changes to the compiler which
34+
provide a better solution to them instead of [adding more hacks](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.WithOptConstParam.html).
35+
36+
### ❔ Optional extensions
37+
38+
There are a lot of things which are nice to have but not strictly necessary or maybe not even
39+
desirable. This means that decisions which prevents them may still be the correct ones,
40+
i.e. these are not strictly a blocking concern.
41+
We should still try to find alternatives before blocking these though.
42+
43+
## Const parameter types ([`adt_const_params`](https://github.com/rust-lang/rust/issues/95174))
44+
45+
On stable, only integers, `bool`, and `char` is allowed as the type of const parameters.
46+
We want to extend this to more types in the future.
47+
```rust
48+
struct NamedType<const NAME: &'static str> { ... }
49+
```
50+
51+
Additionally, we want to support generic const parameter types and must not stabilize anything
52+
which prevents the addition of that in the future.
53+
```rust
54+
struct WithGenericArray<T, const N: usize, const ARRAY: [T; N]> { ... }
55+
```
56+
57+
This feature interacts with the following topics:
58+
59+
- [❗ Constraining generic parameters](./design/constraining-generic-parameters.html)
60+
- [❗🔙 ⚖️ Structural equality](./design/structural-equality.html)
61+
- [❗⚖️ Valid const parameter types](./design/valid-const-parameter-types.html)
62+
- [❗ Valtrees](./design/valtrees.html)
63+
- [❗⚖️🔄 Generic const parameter types](./design/generic-const-param-types.html)
64+
- [❔ Exhaustiveness](./design/exhaustiveness.html)
65+
- [❔🔙 Functions as const parameters](./design/functions-as-const-parameters.html)
66+
67+
## Generic constants in the type system ([`generic_const_exprs`](https://github.com/rust-lang/rust/issues/76560))
68+
69+
- ❗🔙 🔄 Unused substs
70+
- ❗🔄 Self referential where clauses
71+
- ❗🔄 Evaluation without first checking where-clauses
72+
### Unifying generic constants
73+
74+
- [❗🔙 Restrictions on const evaluation](./design/const-eval-requirements.html)
75+
- ❗ Do not leak implementation details
76+
- ❗ Splitting constants during unification
77+
- [❗ Constraining generic parameters](./design/constraining-generic-parameters.html)
78+
- ❔⚖️ Extending unification logic
79+
80+
### Const evaluatable bounds
81+
82+
ALL OF THIS
83+
84+
## Repeat length backcompatability lint ([`const_evaluatable_unchecked`](https://github.com/rust-lang/rust/issues/76200))
85+
86+
close this or wait until it's possible on stable.

design/const-eval-requirements.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# ❗🔙 Restrictions on const evaluation
2+
3+
For generic constants in the type system to be sound, const evaluation must
4+
not be able to differentiate between values considered equal by the type system.
5+
Const evaluation must also be fully deterministic and must not depend on any external state
6+
when used in the type system.
7+
8+
## Floats
9+
10+
Using floats during CTFE is fully determinstic. So using
11+
them inside of the type system is fine. CTFE can however
12+
produce different results than what would happen on real hardware,
13+
but this is not a concern for const generics.
14+
15+
## Dealing with references and allocations
16+
17+
Other sources of non-determinism are allocations. This non-determinism
18+
must however not be observed during const-evaluation (TODO: link to const-eval).
19+
20+
Any references used in a constant are considered equal if their targets are equal, which is also determistic.
21+
This is needed by [valtrees](./design/valtrees.html). The specific design of valtrees also adds some other
22+
additional constraints to const evaluation which are listed on its page.
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# ❗ Constraining generic parameters
2+
3+
Given an impl, the compiler has to be able to decide the generic arguments used by that impl.
4+
Consider the following snippet:
5+
6+
```rust
7+
struct Weird<const N: usize>;
8+
9+
impl<const A: usize, const B: usize> Weird<{ A + B }> {
10+
fn returns_a() -> usize {
11+
A
12+
}
13+
}
14+
```
15+
16+
When calling `Weird::<3>::returns_a()`, there is no way to restrict the generic parameters `A` or `B` so this has to error.
17+
If a generic parameter is used by an injective expression, then we should allow this. The most relevant case here are
18+
constructors:
19+
```rust
20+
struct UsesOption<const N: Option<usize>>;
21+
impl<const N: usize> UsesOption<{ Some(N) }> {}
22+
```
23+
Here it is very clear which `N` we should use given `UsesOption::<{ Some(3) }>`.
24+
25+
## Current status
26+
27+
**Blocked**: Before making any decisions here we should first figure out [structural equality](./design/structural-equality.md)

design/exhaustiveness.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# ❔ Exhaustiveness
2+
3+
Whether we want to be able to unify different partial impls to consider them exhaustive.
4+
5+
```rust
6+
trait ForBool<const B: bool> {}
7+
8+
impl ForBool<true> for u8 {}
9+
impl ForBool<false> for u8 {}
10+
// Does `for<const B: bool> u8: ForBool<B>` hold?
11+
```
12+
13+
## Status
14+
15+
**Idle**: While not blocked, it may make sense to wait until we are able to [constrain generic parameters](./design/constraining-generic-parameters.html).
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# ❔🔙 Functions as const parameters
2+
3+
**[project-const-generics#7](https://github.com/rust-lang/project-const-generics/issues/7)**
4+
5+
It would be nice to allow function pointers as const parameter types.
6+
7+
```rust
8+
fn foo<const N: fn() -> usize>() {}
9+
```
10+
11+
While they do have a sensible definition of structural equality at compile time,
12+
comparing them is not deterministic at runtime. This behavior might be fairly surprising,
13+
so it might be better to not allow this.
14+
15+
## Current status
16+
17+
**Planning/Blocked**: needs `generic_const_exprs` to be closer to stable before it makes sense to start working on this.

design-docs/generic-const-param-types.md renamed to design/generic-const-param-types.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generic const param types
1+
# ❗⚖️🔄 Generic const parameter types
22

33
We want to support the types of const parameters
44
to depend on other generic parameters.
@@ -33,4 +33,8 @@ break stuff.
3333

3434
Potential dangers include partially resolved types and projections.
3535

36-
[WithOptConstParam]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.WithOptConstParam.html
36+
[WithOptConstParam]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.WithOptConstParam.html
37+
38+
## Status
39+
40+
**Blocked**: We should first stabilize `feature(adt_const_params)`.

design/structural-equality.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# ❗🔙 ⚖️ Structural equality
2+
3+
We have to figure out which values and types can be sensibly compared at compile time.
4+
5+
## Status
6+
7+
**In progress**: [lcnr](https://github.com/lcnr/) is working on this.

design/valid-const-parameter-types.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# ❗⚖️ Valid const parameter types
2+
3+
**[project-const-generics#6](https://github.com/rust-lang/project-const-generics/issues/6)**
4+
5+
We have to decide which types may be used as a const parameter and whether there needs to be explicit opt-in.
6+
7+
## Status
8+
9+
**Blocked**: Waiting on [structural equality](./design/structural-equality.html).

design/valtrees.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# ❗ Valtrees
2+
3+
A new representation for `ty::Const`.
4+
5+
## ❗ Figure out how they interact with references wrt padding
6+
7+
**[project-const-generics#20](https://github.com/rust-lang/project-const-generics/issues/20)**
8+
9+
## Status
10+
11+
**In Progress**: [b-naber](https://github.com/rust-lang/project-const-generics/issues/20) is working on this.

0 commit comments

Comments
 (0)