rust-lang / chalk

An implementation and definition of the Rust trait system using a PROLOG-like logic solver
https://rust-lang.github.io/chalk/book/
Other
1.84k stars 182 forks source link

Add ProjectionTerm #745

Closed JulianKnodt closed 1 year ago

JulianKnodt commented 2 years ago

This starts adding terms into chalk so that associated consts can be equated.

compiler-errors commented 2 years ago

howdy @JulianKnodt, what's the status of this?

JulianKnodt commented 2 years ago

@compiler-errors Started on it, been caught up with some other deadlines so have not had a chance to progress, will get to it eventualllyyyy but I'm unsure when I'll be able to.

bors commented 2 years ago

:umbrella: The latest upstream changes (presumably #753) made this pull request unmergeable. Please resolve the merge conflicts.

HKalbasi commented 2 years ago

Is this PR in the right direction? I think chalk should not get its hand dirty with const evaluation, since const eval needs handling and interpreting whole rust syntax, and doing that in chalk is against modularization. I imagine that the user of chalk should provide const eval infrastructure, and evaluate const generics so chalk has them in the concrete shape.

In this way, chalk doesn't need to normalize associated constants (it can't normalize completely without full const eval), it just needs to provide a function that computes an ImplId + substitution from a <Type as Trait>, so that the caller can find associated constants and evaluate them (and other associated items for other reasons).

JulianKnodt commented 2 years ago

@HKalbasi It's been a minute since I started this, and it's a good reminder for me to go back and actually implement this (I'm starting to finally get more time on my hands), but the context for this is that it would make sense to support const equality in the context of trait bounds (see here). While I don't know whether Chalk needs to support evaluating them, my understanding from a few months ago that chalk needs to support consts in a new position which it previously did not.

If any of this is wrong, please let me know, I haven't thought about this in a minute and should get back to it.

HKalbasi commented 2 years ago

I thought it is going to add a NormalizeConst (which is essentially const eval) similar to NormalizeFn in #726 and handles associated constants in <Type as Trait>::ASSOC_CONST position, but it is about associated constants in Trait<ASSOC_CONST=?> position, so my comment above is irrelevant. Sorry for noise.

JulianKnodt commented 2 years ago

@compiler-errors Do you know who I can ask about Chalk? I'm starting to run into things I am unsure about, and am unsure where to look. Specifically, is there any existing infrastructure for consts inside of chalk?

jackh726 commented 2 years ago

Generally I or @nikomatsakis should have the most knowledge of Chalk things. Easiest to ask in Zulip.

There is very little infrastructure for consts in Chalk. I think most/all of it is in chalk-ir, for variable kinds and such.

bors commented 2 years ago

:umbrella: The latest upstream changes (presumably #767) made this pull request unmergeable. Please resolve the merge conflicts.