Skip to content

Consolidate Ty variants into a new variant Ty::Apply #988

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

Merged
merged 7 commits into from
Mar 22, 2019

Conversation

flodiebold
Copy link
Member

This gets us a lot closer to Chalk. It also introduces a lot of boilerplate, though, especially when matching :/ A lot of this can probably be refactored to be nicer, though.

Copy link
Member

@matklad matklad left a comment

Choose a reason for hiding this comment

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

Looks nice from the impl point of view!

However, the interface which requires deep matching feels awkward. I also notice that, when we do matching, we almost always have an _ branch anyway...

Perhaps adding a slew of conversions to Ty, like Ty::as_adt, Ty::is_primitive, etc, would make this nicer? This might also be a good place to check invariant like "primitive types have empty subst"

Ty::Adt { def_id, .. } => Ty::Adt { def_id, substs },
Ty::FnDef { def, .. } => Ty::FnDef { def, substs },
Ty::Apply(ApplicationTy { name, .. }) => {
Ty::Apply(ApplicationTy { name, parameters: substs })
Copy link
Member

Choose a reason for hiding this comment

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

should we check that before/after subst lengths are the same?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, and I found a bug when I did it ;)

#[derive(Clone, PartialEq, Eq, Debug)]
pub enum Ty {
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
pub enum TypeName {
Copy link
Member

Choose a reason for hiding this comment

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

Isn't a TypeCtor a better name here? I imagine name would be a pretty overloaded term, so it's better to avoid it. I guess TypeName is what's used in chalk? I wonder if it was intentionally chosen over TypeCtor.

Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed it to TypeCtor now.

@flodiebold
Copy link
Member Author

Perhaps adding a slew of conversions to Ty, like Ty::as_adt, Ty::is_primitive, etc, would make this nicer? This might also be a good place to check invariant like "primitive types have empty subst"

Yeah, that's what I was thinking...

@matklad
Copy link
Member

matklad commented Mar 22, 2019

bors r+

bors bot added a commit that referenced this pull request Mar 22, 2019
988: Consolidate Ty variants into a new variant Ty::Apply r=matklad a=flodiebold

This gets us a lot closer to Chalk. It also introduces a lot of boilerplate, though, especially when matching :/ A lot of this can probably be refactored to be nicer, though.

Co-authored-by: Florian Diebold <[email protected]>
@bors
Copy link
Contributor

bors bot commented Mar 22, 2019

Build succeeded

@bors bors bot merged commit 1ee779d into rust-lang:master Mar 22, 2019
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.

2 participants