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

Inference of lambda type and array element type from an antecedent (RFC 45). #2168

Merged
merged 16 commits into from
Sep 13, 2017

Conversation

jemc
Copy link
Member

@jemc jemc commented Aug 15, 2017

Resolves #2094.

@jemc jemc added the do not merge This PR should not be merged at this time label Aug 15, 2017
@jemc jemc self-assigned this Aug 15, 2017
@jemc
Copy link
Member Author

jemc commented Aug 15, 2017

This one is in the final stages of cleanup work before preparing to merge.

I've tried to imagine and test for all the cases of this, but invariably I will have missed some cases. We can clean up the cases I missed later, as they come up.

@jemc jemc force-pushed the feature/lambda-inference branch 2 times, most recently from 0d65065 to 9a2145c Compare August 16, 2017 02:26
@jemc jemc removed the do not merge This PR should not be merged at this time label Aug 16, 2017
@jemc jemc force-pushed the feature/lambda-inference branch from 9a2145c to 460d5e4 Compare August 16, 2017 02:28
@jemc jemc changed the title Feature: Lambda and array inference Inference of lambda type and array element type from an antecedent (RFC 0045). Aug 16, 2017
@jemc jemc changed the title Inference of lambda type and array element type from an antecedent (RFC 0045). Inference of lambda type and array element type from an antecedent (RFC 45). Aug 16, 2017
@jemc jemc added the changelog - added Automatically add "Added" CHANGELOG entry on merge label Aug 16, 2017
@jemc
Copy link
Member Author

jemc commented Aug 16, 2017

Hm, nevermind - I've come across a case that I didn't handle already, so I'm going to take a look to see if it can be handled.

@jemc jemc added the do not merge This PR should not be merged at this time label Aug 16, 2017
@@ -27,6 +272,13 @@ bool expr_array(pass_opt_t* opt, ast_t** astp)
told_type = true;
}

if(!told_type && (ast_childcount(elements) == 0))
Copy link
Member

Choose a reason for hiding this comment

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

This can use the size local instead of the duplicate call to ast_childcount.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call. Fixed in 943c1ba.

#include "../type/lookup.h"
#include "ponyassert.h"

static ast_t* build_array_type(ast_t* scope, ast_t* elem_type, token_id cap)
Copy link
Member

Choose a reason for hiding this comment

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

Is there a particular reason to use this new function instead of type_builtin_args?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't know about that function.

In 943c1ba I refactored build_array_type to use type_builtin_args as part of its implementation.

{
for(ast_t* c = ast_child(ast); c != NULL; c = ast_sibling(c))
find_possible_element_types(opt, c, list);
}
Copy link
Member

Choose a reason for hiding this comment

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

I'd feel more comfortable with a break or return here, to avoid problems in future refactorings.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call. Fixed in 943c1ba.

@jemc jemc removed the do not merge This PR should not be merged at this time label Aug 27, 2017
@jemc
Copy link
Member Author

jemc commented Aug 27, 2017

I found and fixed some more edge cases.

I also addressed @Praetonus' review comments.

This is ready for a final review.

@SeanTAllen
Copy link
Member

@jemc looks like this needs a rebase?

@jemc
Copy link
Member Author

jemc commented Aug 27, 2017

@SeanTAllen - I'm not sure what you mean. As long as we merge with the squash-and-merge feature of GitHub, it will only show as one commit.

In other news, I'm applying the "DO NOT MERGE" label on this again because it's hitting an issue in the changelog tool compilation.

@jemc jemc added the do not merge This PR should not be merged at this time label Aug 27, 2017
@SeanTAllen
Copy link
Member

@jemc i was referring to the "This branch cannot be rebased due to conflicts"

@Praetonus
Copy link
Member

The Linux LLVM 3.9 builds (both debug and release) are hitting an assertion failure in the type inference code when building pony-stable.

@jemc jemc removed the do not merge This PR should not be merged at this time label Sep 8, 2017
@jemc
Copy link
Member Author

jemc commented Sep 8, 2017

Removing the "DO NOT MERGE" label - if this passes CI, it's good to merge.

@Theodus
Copy link
Contributor

Theodus commented Sep 8, 2017

@jemc Travis is showing the following error on all builds:

Error:
/home/travis/build/ponylang/ponyc/packages/cli/command_parser.pony:162:19: can't reuse name 'v'
            | let v: _Value => v
                  ^
    Info:
    /home/travis/build/ponylang/ponyc/packages/cli/command_parser.pony:160:11: previous use of 'v'
              let v: _Value =
              ^

@jemc
Copy link
Member Author

jemc commented Sep 10, 2017

This now passed all Travis builds except the last build for OSX, which had a Travis-caused error. I restarted that one build, so here's hoping it finally passes this time.

@jemc
Copy link
Member Author

jemc commented Sep 10, 2017

🎉

@SeanTAllen
Copy link
Member

@jemc can you write up release notes for this so i can include with the release?

@jemc
Copy link
Member Author

jemc commented Sep 13, 2017

@SeanTAllen - here's a shot at some helpful release notes:


This release includes significant improvements to type inference for array literals and lambda expressions when the type of the expression has an unambiguous antecedent (such as the "left side" of an assignment, the parameter signature of a method call, or the return type of a method body), including the following improvements:

  • Empty array literals are now valid syntax: let a: Array[U8] = []
  • Non-homogenous concrete elements in an array literal can be treated as a trait or interface instead of as a union: let a: Array[Stringable] = [true; None; "string"]
  • Array literals can have an implied capability recovery to iso or val: let a: Array[String] val = ["foo"; "bar"; "baz"]
  • Lambda expressions can have implied parameter and return types: let fn: {(U64, U64): U64} = {(x, y) => x + y }
  • Unused lambda parameters can use the "don't care" symbol (_) instead of a parameter name and type: let fn: {(U64, U64): U64} = {(_, y) => y * 2 }
  • The receiver and object capability of lambda expressions can be inferred from context, instead of being inferred from the statefulness of the lamba.

For more information, see RFC #45.

@SeanTAllen
Copy link
Member

@jemc is this a breaking change? would we be doing 0.19.1 or 0.20.0?

@jemc
Copy link
Member Author

jemc commented Sep 13, 2017

@SeanTAllen - it's not a breaking change. If this breaks some working code, that would be a bug to be fixed.

That said, I think we've been bumping the second number for both breaking changes and new features, here in the pre-1.0.0 days. That is, I think we use the third number for representing bug fixes. I could be wrong though.

@SeanTAllen
Copy link
Member

@jemc i havent been bumping for new features at this point, only breaking changes.

@SeanTAllen SeanTAllen merged commit 2bca9dc into master Sep 13, 2017
ponylang-main added a commit that referenced this pull request Sep 13, 2017
@SeanTAllen SeanTAllen deleted the feature/lambda-inference branch September 13, 2017 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog - added Automatically add "Added" CHANGELOG entry on merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants