Open
Description
There's a bunch of stuff we need to implement to support const generics at least enough to get method resolution right in simple cases:
- lower const parameters and array sizes as bodies (Lower const parameters #7434)
- represent const parameters in the type checker: this (like supporting lifetime parameters) will mean fixing a bunch of places in
hir_ty
that currently assume only type parameters exist. A good place to start is probably theGenerics
helper inhir_ty
'sutil.rs
- use Chalk's unification logic instead of ours that doesn't take consts into account (I'm working on this)
- represent consts in types, at least simple numbers:
- this means changing
InternedConcreteConst
in ourInterner
from()
to an enum that can represent these numbers - then we need to implement the
const_eq
method onInterner
- this means changing
- evaluate const bodies: there should be a query that takes a const body and tries to evaluate it, returning a
Result<Binders<Const>, ConstEvalError>
that can be either a concrete const, aBoundVar
referring to a const param, or an error if the expression is too complicated. We'll want to handle errors differently depending on the situation (while inferring bodies, we could replace them by const variables, for example). We should stick to only evaluating simple integer literals for now. We'll need to call this query during type lowering.- this would basically also get us most of the way to Feature: show values of constants #8497
- this should also fix Incorrect resolution of Nalgebra 0.26's fixed-size Vector/Matrix constructors #8654 since our method resolution will then take the const values into account
- to represent more complicated const generics like
{ N + 1 }
(whereN
is a const param), we need support in Chalk for unevaluated consts that doesn't exist yet
- expand the const evaluation logic: we shouldn't put too much work into this, but a good subset might be integer literals, consts and maybe the standard binary operations