-
Notifications
You must be signed in to change notification settings - Fork 182
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
Add closures #519
Add closures #519
Conversation
Okay I just applied my changes in a new commit against master, since that was easier. @nikomatsakis I would appreciate a review. The biggest "missing" part of this PR is tests. Not sure the best was to test closures currently. |
The heck. I'm just gonna restart CI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks basically right. I left a few nits. I guess that for testing we'd have to have a way to declare closure types in the source, similar to our fn foo
declarations. Not 100% sure what the obvious syntax for that is, maybe we should just do closure foo(...);
declarations that are otherwise very much like fn
declarations.
There was occasional talk of merging fns and closures in rustc, but I don't know of any concrete plans to do that. I guess that until we do so we can leave things as they are in chalk, though it does seem like you can imagine merging them and having a notion of some way to
(a) get the upvar type for a "callable" thing (for fn-def, returns ()
, for closures returns the tuple)
(b) get the fn-kind for a "callable" thing (for fn-def, returns Fn
, for closures returned whatever is inferred)
(c) get the signature for the callable thing
Certainly would fit in with our general trend in chalk of trying to group together things that are "really quite similar", but I kind of think I'd rather land your PR as is (modulo changes I suggested) and then re-approach this later.
So, testing closures with no upvars is fairly easy (like you said, a We could do something like
where the |
I was imagining
where the self part captures fn/fn-mut/fn-once. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 so far
This should be ready to review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks awesome! I left some comments, I'm a bit confused about the handling of generic type parameters.
Ok @nikomatsakis I addressed your comments. I wasn't handling the generic types correctly. I also just moved from the single |
Btw there might be a bug in here somewhere. Trying to update rustc to use this causes the closure tests to fail. So don't merge yet even if it looks good. Debugging... |
False alarm :) this is good for review |
c.c. #368
This works but isn't rebased.