Skip to content

Support const generics #8655

Open
Open
@flodiebold

Description

@flodiebold

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 the Generics helper in hir_ty's util.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 our Interner from () to an enum that can represent these numbers
    • then we need to implement the const_eq method on Interner
  • 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, a BoundVar 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.
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tytype system / type inference / traits / method resolutionC-bugCategory: bugC-featureCategory: feature requestE-hardE-has-instructionsIssue has some instructions and pointers to code to get startedS-actionableSomeone could pick this issue up and work on it right now

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions