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

Support const generics #8655

Open
3 of 6 tasks
flodiebold opened this issue Apr 25, 2021 · 7 comments
Open
3 of 6 tasks

Support const generics #8655

flodiebold opened this issue Apr 25, 2021 · 7 comments
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug C-feature Category: feature request E-hard E-has-instructions Issue has some instructions and pointers to code to get started S-actionable Someone could pick this issue up and work on it right now

Comments

@flodiebold
Copy link
Member

flodiebold commented Apr 25, 2021

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
@flodiebold flodiebold added A-ty type system / type inference / traits / method resolution E-hard S-actionable Someone could pick this issue up and work on it right now E-has-instructions Issue has some instructions and pointers to code to get started labels Apr 25, 2021
@matklad
Copy link
Member

matklad commented Aug 9, 2021

cc rust-lang/compiler-team#453

@matklad
Copy link
Member

matklad commented Aug 9, 2021

I also wonder, what would it take us to “just use miri”, just like we “just use chalk” today (to clarify, I personally know very little at all about how all this is supposed to work)?

@flodiebold
Copy link
Member Author

Miri seemed very entangled with compiler internals when I checked; having the shared type library might be a first step towards that though.

@flodiebold
Copy link
Member Author

Regarding the MCP, in the end we just use Chalk's representation, so 🤷‍♂️

@bjorn3
Copy link
Member

bjorn3 commented Aug 9, 2021

Miri can't be used without TyCtxt. Disentangling it is probably going to be pretty hard. It needs everything from the full type system to the type layout calculation to MIR lowering.

@eggyal
Copy link

eggyal commented Oct 21, 2021

I presume the long-term vision is that, as more and more of rustc is "librarified", RA will increasingly be able to depend on those libraries and (eventually) use them to lower all the way to MIR (whence Miri could be used for const eval etc, or indeed that MIR could be interpreted/lowered to machine code e.g. for #8420)?

Assuming that is the vision, is there somewhere that the broad brush strokes for getting there have been sketched out (perhaps a tracking-issue or similar)? Maybe by breaking the goal into more manageable stages, contributions toward reaching it can be coordinated?

@flodiebold
Copy link
Member Author

The next step right now is the shared type library and Chalk integration in rustc. That would unblock extracting more parts of rustc. There is no overarching long-term plan right now.

bors bot added a commit that referenced this issue Dec 23, 2021
10933: show values of constants in hover r=flodiebold a=HKalbasi

Fix #8497
cc #8655


Co-authored-by: hkalbasi <hamidrezakalbasi@protonmail.com>
bors bot added a commit that referenced this issue Dec 23, 2021
10933: show values of constants in hover r=lnicola a=HKalbasi

Fix #8497
cc #8655


Co-authored-by: hkalbasi <hamidrezakalbasi@protonmail.com>
bors bot added a commit that referenced this issue Jan 4, 2022
11112: Evaluate constants in array repeat expression r=HKalbasi a=HKalbasi

cc #8655 

Co-authored-by: hkalbasi <hamidrezakalbasi@protonmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug C-feature Category: feature request E-hard E-has-instructions Issue has some instructions and pointers to code to get started S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

No branches or pull requests

4 participants