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

Auto-recover constructor expressions #4124

Merged
merged 12 commits into from
Jul 5, 2022
Merged

Conversation

chalcolith
Copy link
Member

@chalcolith chalcolith commented May 24, 2022

This PR adds checks when assigning a constructor expression or passing one as a parameter to see if it can be auto-recovered, and if so, does not output a subtyping error. E.g. for the following code:

actor Main
  new create(env: Env) =>
    Bar.take_foo(Foo(88))
    let bar: Foo iso = Foo(88)

class Foo
  new create(v: U8) =>
    None

primitive Bar
  fun take_foo(foo: Foo iso) =>
    None

We'd previously get errors on both lines in Main.create(); whereas with this PR they are now accepted.

Fixes #702

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label May 24, 2022
@@ -738,3 +738,19 @@ TEST_F(RecoverTest, CanWriteTrn_TrnAutoRecovery)

TEST_COMPILE(src);
}
TEST_F(RecoverTest, CanAutorecover_Newref)
Copy link
Member

Choose a reason for hiding this comment

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

there should be a blank line here.

Copy link
Member

Choose a reason for hiding this comment

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

I think we said that we would add all tests that we can to runner tests in which case this should be a runner test as we are only checking that it compiles.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I've moved it.

@SeanTAllen SeanTAllen added the changelog - added Automatically add "Added" CHANGELOG entry on merge label May 24, 2022
@ponylang-main
Copy link
Contributor

Hi @kulibali,

The changelog - added label was added to this pull request; all PRs with a changelog label need to have release notes included as part of the PR. If you haven't added release notes already, please do.

Release notes are added by creating a uniquely named file in the .release-notes directory. We suggest you call the file 4124.md to match the number of this pull request.

The basic format of the release notes (using markdown) should be:

## Title

End user description of changes, why it's important,
problems it solves etc.

If a breaking change, make sure to include 1 or more
examples what code would look like prior to this change
and how to update it to work after this change.

Thanks.

.release-notes/4124.md Outdated Show resolved Hide resolved
.release-notes/4124.md Outdated Show resolved Hide resolved
chalcolith and others added 2 commits May 24, 2022 11:13
Co-authored-by: Sean T Allen <sean@seantallen.com>
Co-authored-by: Sean T Allen <sean@seantallen.com>
Copy link
Contributor

@jasoncarr0 jasoncarr0 left a comment

Choose a reason for hiding this comment

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

Pretty good overall. There's some fixes needed for how the upgrading is done.

Otherwise more tests would be good (as I think was mentioned in sync). Some suggestions:

  • Annotate variable as iso, ref constructor with 0 arguments,
  • Same with 1 or more arguments
  • Annotated variable as val
  • Same as above with parameters
  • Verify that inference hasn't been broken by this, with code like the below:
let x = String
let y: String ref = x

ast_t* wp_type;
if(check_auto_recover_newref(arg))
{
wp_type = unisolated(p_type);
Copy link
Contributor

@jasoncarr0 jasoncarr0 May 24, 2022

Choose a reason for hiding this comment

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

This isn't quite the right behavior, although it might be on the right track. You should be upgrading the argument/constructor capability instead trying to downgrade the parameter.

That way for instance, a String val argument can be fulfilled by auto-recovery of String (which is a ref constructor). It would also be a bit clearer what's going on that way. Or for another example, the linked issue used array val

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 believe I've fixed this now.


token_id tcap = ast_id(cap_fetch(receiver_type));
if (tcap == TK_REF || tcap == TK_BOX)
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be nice to instead eagerly return false if the capability doesn't match, that way you don't have to check the arguments if the return capability is already wrong.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

if(check_auto_recover_newref(right))
{
wl_type = unisolated(fl_type);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar comment to above, the r_type should be upgraded instead, as with recover blocks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done as above.

@chalcolith chalcolith added do not merge This PR should not be merged at this time and removed discuss during sync Should be discussed during an upcoming sync labels May 31, 2022
- Change the rhs type instead of the lhs type when auto-recovering constructor calls
- Bail out of the auto-recover check early if we don't need to auto-recover.
- Add tests that make sure we still error out when passing non-sendable args to the constructor call we're trying to auto-recover.
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Jun 10, 2022
@chalcolith chalcolith added do not merge This PR should not be merged at this time and removed do not merge This PR should not be merged at this time labels Jun 10, 2022
@chalcolith
Copy link
Member Author

I restarted the failing test and it succeeded.

@SeanTAllen
Copy link
Member

What test failed and then passed when rerun?

@chalcolith chalcolith removed the do not merge This PR should not be merged at this time label Jun 11, 2022
@chalcolith
Copy link
Member Author

Multiple libponyc tests failed on arm64 Apple Darwin. When I re-ran it they succeeded.

@SeanTAllen
Copy link
Member

That's concerning. If it happens again let's record the failures in an issue. Actually, can you go through the CI history on cirrus and get the failures and open an issue?

@SeanTAllen
Copy link
Member

@kulibali i've added issue #4138 for tracking failures in arm64 apple darwin tests. Please add the information about your failures to it.

@jemc jemc removed the discuss during sync Should be discussed during an upcoming sync label Jun 14, 2022
@jemc
Copy link
Member

jemc commented Jun 14, 2022

Looks good to me. During sync Gordon waiting for @jasoncarr0 to review again.

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Jun 14, 2022
@SeanTAllen SeanTAllen removed the discuss during sync Should be discussed during an upcoming sync label Jun 14, 2022
@chalcolith
Copy link
Member Author

Ping @jasoncarr0 will you have time to give this another review?

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Jul 3, 2022
@jasoncarr0
Copy link
Contributor

@kulibali Yup, I've been looking at it just now, should get something in before tomorrow but I'm expecting a small number of changes

Copy link
Contributor

@jasoncarr0 jasoncarr0 left a comment

Choose a reason for hiding this comment

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

I have a few suggestions for additions, I've put them in a PR as it's hard to make for suggestions with all of it.

#4155

The only code change is a small cap function update that's necessary for val recovery to handle arguments correctly. We can talk about it in sync to clear anything up.

I.e. what I'm requesting (and providing):

  • More tests
  • Proper support for recovery to val

src/libponyc/expr/call.c Outdated Show resolved Hide resolved
@chalcolith
Copy link
Member Author

I have merged @jasoncarr0 's changes, thanks!

@chalcolith chalcolith merged commit 7b01704 into main Jul 5, 2022
@chalcolith chalcolith deleted the issue_702_ctor_autorecover branch July 5, 2022 18:38
@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label Jul 5, 2022
github-actions bot pushed a commit that referenced this pull request Jul 5, 2022
github-actions bot pushed a commit that referenced this pull request Jul 5, 2022
@@ -738,3 +738,171 @@ TEST_F(RecoverTest, CanWriteTrn_TrnAutoRecovery)

TEST_COMPILE(src);
}
TEST_F(RecoverTest, LetIso_CtorAutoRecovery)
Copy link
Member

Choose a reason for hiding this comment

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

I have pushed a fix for the incorrect spacing between functions in this diff.

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Dec 28, 2022
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 discuss during sync Should be discussed during an upcoming sync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auto-recover constructor expressions when assigning to an explicit type.
6 participants