-
-
Notifications
You must be signed in to change notification settings - Fork 419
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
Conversation
test/libponyc/recover.cc
Outdated
@@ -738,3 +738,19 @@ TEST_F(RecoverTest, CanWriteTrn_TrnAutoRecovery) | |||
|
|||
TEST_COMPILE(src); | |||
} | |||
TEST_F(RecoverTest, CanAutorecover_Newref) |
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.
there should be a blank line here.
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.
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.
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.
OK, I've moved it.
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 The basic format of the release notes (using markdown) should be:
Thanks. |
Co-authored-by: Sean T Allen <[email protected]>
Co-authored-by: Sean T Allen <[email protected]>
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.
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
src/libponyc/expr/call.c
Outdated
ast_t* wp_type; | ||
if(check_auto_recover_newref(arg)) | ||
{ | ||
wp_type = unisolated(p_type); |
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 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
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.
I believe I've fixed this now.
src/libponyc/expr/call.c
Outdated
|
||
token_id tcap = ast_id(cap_fetch(receiver_type)); | ||
if (tcap == TK_REF || tcap == TK_BOX) | ||
return true; |
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.
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.
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.
Done.
src/libponyc/expr/operator.c
Outdated
if(check_auto_recover_newref(right)) | ||
{ | ||
wl_type = unisolated(fl_type); | ||
} |
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.
Similar comment to above, the r_type
should be upgraded instead, as with recover blocks.
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.
Done as above.
- 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.
I restarted the failing test and it succeeded. |
What test failed and then passed when rerun? |
Multiple libponyc tests failed on |
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? |
Looks good to me. During sync Gordon waiting for @jasoncarr0 to review again. |
Ping @jasoncarr0 will you have time to give this another review? |
@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 |
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.
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.
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
I have merged @jasoncarr0 's changes, thanks! |
@@ -738,3 +738,171 @@ TEST_F(RecoverTest, CanWriteTrn_TrnAutoRecovery) | |||
|
|||
TEST_COMPILE(src); | |||
} | |||
TEST_F(RecoverTest, LetIso_CtorAutoRecovery) |
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.
I have pushed a fix for the incorrect spacing between functions in this diff.
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:
We'd previously get errors on both lines in
Main.create()
; whereas with this PR they are now accepted.Fixes #702