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

const generics support #393

Merged
merged 4 commits into from
May 19, 2020
Merged

const generics support #393

merged 4 commits into from
May 19, 2020

Conversation

basil-cow
Copy link
Contributor

No description provided.

@basil-cow basil-cow marked this pull request as ready for review April 14, 2020 16:27
@basil-cow
Copy link
Contributor Author

@nikomatsakis I guess this is ready for review, I can't really think of something to make it nicer. As for the parser, I want #394 to land before I add proper name resolution to lowering.

@basil-cow basil-cow changed the title [WIP] const generics support const generics support Apr 16, 2020
Copy link
Member

@detrumi detrumi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments, but skipped most of chalk-solve in my review since I don't understand half of it 😅

chalk-ir/src/lib.rs Outdated Show resolved Hide resolved
chalk-ir/src/fold.rs Outdated Show resolved Hide resolved
chalk-ir/src/fold.rs Outdated Show resolved Hide resolved
chalk-ir/src/fold/subst.rs Outdated Show resolved Hide resolved
chalk-ir/src/interner.rs Outdated Show resolved Hide resolved
chalk-ir/src/lib.rs Outdated Show resolved Hide resolved
chalk-ir/src/visit.rs Outdated Show resolved Hide resolved
chalk-solve/src/infer/instantiate.rs Outdated Show resolved Hide resolved
chalk-ir/src/fold.rs Outdated Show resolved Hide resolved
chalk-ir/src/fold.rs Outdated Show resolved Hide resolved
chalk-ir/src/interner.rs Outdated Show resolved Hide resolved
chalk-ir/src/lib.rs Outdated Show resolved Hide resolved
chalk-solve/src/infer.rs Show resolved Hide resolved
chalk-solve/src/infer/unify.rs Outdated Show resolved Hide resolved
chalk-solve/src/solve/slg.rs Show resolved Hide resolved
tests/test/projection.rs Show resolved Hide resolved
Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left misc nits but this all looked basically correct to me

chalk-ir/src/fold.rs Outdated Show resolved Hide resolved
chalk-ir/src/lib.rs Outdated Show resolved Hide resolved
chalk-ir/src/zip.rs Outdated Show resolved Hide resolved
chalk-ir/src/zip.rs Outdated Show resolved Hide resolved
chalk-ir/src/visit.rs Outdated Show resolved Hide resolved
chalk-solve/src/infer/unify.rs Outdated Show resolved Hide resolved
chalk-ir/src/debug.rs Show resolved Hide resolved
chalk-solve/src/infer.rs Show resolved Hide resolved
chalk-solve/src/infer.rs Show resolved Hide resolved
@basil-cow basil-cow force-pushed the const branch 4 times, most recently from 3244583 to 03d5e1d Compare April 28, 2020 19:08
Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're still waiting on

work list extracted

Anything else? I haven't done a look, so some of those may be fixed, I mostly wanted to change it so that, in the list of PRs, this one was listed as "changes requested".

@basil-cow
Copy link
Contributor Author

We have two things we haven't decided on what to do with:
a) this
b) ConcreteConst vs ConstValue

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Apr 29, 2020

Work list:

@basil-cow
Copy link
Contributor Author

So, I implemented const types by adding Ty to ParameterKinds::Const and to ConstData, moving the old contents into ConstValue. This design has some drawbacks: mainly, it has a lot of duplication.

a) ParameterData aka ParameterKind<Ty, Lifetime, Const> which has type of constant both in ParameterKinds::Const and in Const.
b) all bound vars, inference vars and placeholder vars store their types in both vars themselves and in binders and universes and inference tables.

b) is not really "fixable" I think;
in a) ParameterData should really be ParameterKind::<Ty, Lifetime, ConstValue> from the type standpoint, but that requires(?) to intern ConstValue and that is too many internings imo.

If you have ideas on how to design this better, I would like to hear them.

@jackh726 @detrumi I would appreciate if you took a second look at the pr if you have time

@basil-cow
Copy link
Contributor Author

One more of my concerns is const type unification: it can push lifetime constraints if types are not equal-equal, which is not a big deal maybe, worst case scenario it's kicking the can down the road. I decided to defer dealing with it until subtyping is implemented

@nikomatsakis
Copy link
Contributor

@Areredify I'm kind of confused -- I would expect to have a type like

pub struct ConstData<I> {
    ty: Ty<I>,
    kind: ConstKind<I>,
}

pub enum ConstKind<I> {
    Variable, Bound, Value, etc
}

and then type Parameter<I> = ParameterKind<Ty<I>, Lifetime<I>, Const<I>>.

Was there something with this approach that didn't work? (Modulo having to find a good name for ConstKind...) I feel like that's the approach you had early on in the PR history.

@basil-cow
Copy link
Contributor Author

basil-cow commented May 2, 2020

@nikomatsakis That's the current setup + ParameterKind is defined as

pub enum ParameterKind<I, T, L, C> {
    Ty(T),
    Lifetime(L),
    Const {
        ty: Ty<I>,
        value: C
    } 
}

Right now, everything works, my concern is more of "maybe is there a way to design this better"

@nikomatsakis
Copy link
Contributor

nikomatsakis commented May 4, 2020

@Areredify I'm not sure what you mean by "current", I guess, but it seems like the setup I laid out is not what you described. In particular, I don't understand why the ParameterKind::Const variant should be "different" than the others, in that it contains both a type and a constant. I think the ty field should live in the "constant", as I described.

EDIT: I guess I didn't make it totally clear, but I expect

pub enum ParameterKind<T, L, C> {
    Ty(T),
    Lifetime(L),
    Const(C),
}

in addition to

pub struct ConstData<I> {
    ty: Ty<I>,
    kind: ConstKind<I>,
}

pub enum ConstKind<I> {
    Variable, Bound, Value, etc
}

type Parameter<I> = ParameterKind<Ty<I>, Lifetime<I>, Const<I>>;

@basil-cow
Copy link
Contributor Author

@nikomatsakis Because we use ParameterKind<T> in a lot of places (ParameterKind<()> in binders, ParameterKind<EnaVariable> in unification) we need it to carry type of the constant with it, that's why my current setup is:

pub enum ParameterKind<I, T, L, C> {
    Ty(T),
    Lifetime(L),
    Const { ty: Ty<I>, value: C },
}

pub struct ConstData<I> {
    ty: Ty<I>,
    kind: ConstKind<I>,
}

pub enum ConstKind<I> {
    Variable, Bound, Value, etc
}

type Parameter<I> = ParameterKind<Ty<I>, Lifetime<I>, Const<I>>;

@nikomatsakis
Copy link
Contributor

nikomatsakis commented May 4, 2020

@Areredify Why do we need ParameterKind<()> to carry the type of the constant along with it? (Similarly ParameterKind<EnaVariable>)

@basil-cow
Copy link
Contributor Author

basil-cow commented May 4, 2020

To instantiate universal binders correctly, for example, it's a strange situation when your constants (in unverse sense) are not typed

@basil-cow basil-cow force-pushed the const branch 2 times, most recently from 84bdaac to 9dee20a Compare May 14, 2020 21:33
@basil-cow
Copy link
Contributor Author

rebased against the GenericArg pr

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gave this a quick read. Thanks for factoring out the other PR -- this PR now reads fairly cleanly, I think. At least based on my current reading, everything seems like a fairly straightforward extension. Did anything surprise you or catch your eye while you were rebasing?

tests/test/constants.rs Show resolved Hide resolved
tests/test/projection.rs Show resolved Hide resolved
chalk-solve/src/solve/slg/aggregate.rs Outdated Show resolved Hide resolved
@basil-cow
Copy link
Contributor Author

basil-cow commented May 18, 2020

@nikomatsakis locked and loaded; I think there is a suspicious place that we probably should save for later: specialization rules for consts say that literals are more specific than anything else, but in this pr I ignore that. Other than that, I can't think of anything

@nikomatsakis nikomatsakis merged commit 499d492 into rust-lang:master May 19, 2020
@AzureMarker AzureMarker mentioned this pull request May 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants