-
-
Notifications
You must be signed in to change notification settings - Fork 415
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
Prevent compiler crashes on certain consume
expressions
#3650
Conversation
While this does fix #3567 , this fix looks more like a hack. The generate_multidot_name function seems to have too rigid a view of its input. |
Hi @kapilash, The changelog - fixed 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. |
@kapilash shall I add a "do not merge" label to this? Also, are you aware of "draft PRs"? I'm asking as you added WIP to the YouTube title, I assume to indicate that this shouldn't be merged or that it wasn't ready for review. |
@SeanTAllen Thanks for asking. I am sorry, I am not aware of a draft PR. I will look it up and send one if that's the way to go about such changes. I know I picked a "good first issue" and the implementation of the fix does look like one. So may be the fix is indeed right? But then, I am worried that I am introducing fragility into the system by fixing the symptoms and not the underlying cause. But I could be totally wrong. So I was wondering if I should send out another commit into the same PR and let the reviewers pick the right solution? |
It looks like I am doing syntactic checks in the type checker layer. That seems wrong ?. Perhaps we should fix things like this, #3647 and #3463 in the syntax layer? Alternatively, refactor generate_multidot_name and/or its callers to ensure that the invariants in the function are satisfied. |
Yes, I think that's probably the right choice. When the feature was added to allow consuming a field, that line in the syntax checker wasn't made to be restrictive enough - it allows any Also the error message was not updated when the feature was added to allow consuming a field - it still says that you can only consume a single identifier, but this is no longer true. It should probably say "a local identifier or a field". |
c1d1b0d
to
fea88c7
Compare
consume
expressions
* `consume (consume variable).field` must result in a similar compillation error as `consume (consume variable)`. * `consume f().field` must result in similar compilation error as `consume f()` * `(consume f).b` must be allowed and `f` should be moved. Fixes ponylang#3463, ponylang#3567 (and ponylang#3453)
17a7a6c
to
567df59
Compare
@@ -139,14 +139,16 @@ static const char* generate_multi_dot_name(ast_t* ast, ast_t** def_found) { | |||
|
|||
default: | |||
{ | |||
if (def == NULL) | |||
return stringtab(""); |
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.
@jemc , this is one change needed in generate_multi_dot_name
.
I believe this
-
will do no harm to working pony code: The new code was added in a place where it is throwing an assert. So no working code will get affected.
-
is in sync with the rest of the method: if the parent ast node has null
data
, we are supposed to return empty string. That is possible when we have expressions wrapped in braces.
src/libponyc/pass/syntax.c
Outdated
|
||
case TK_DOT: { | ||
AST_GET_CHILDREN(term, left, right); | ||
if (ast_id(left) != TK_CALL && ast_id(left) != TK_SEQ) |
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.
Here I went a bit too defensive and raising errors for known errors.
Mainly because, by allowing other illegal constructs, we get more detailed/friendlier errors down the line where we do lot more tree traversal anyway.
Do you suggest we go a bit more aggressive here? It could mean we will have to do go up and down the ast a bit more.
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.
Thanks! Just a few small formatting fixes:
Co-authored-by: Joe Eli McIlvain <joe.eli.mac@gmail.com>
Co-authored-by: Joe Eli McIlvain <joe.eli.mac@gmail.com>
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.
A few small notes, requests on the release notes.
.release-notes/3650.md
Outdated
``` | ||
must be equivalent to |
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.
``` | |
must be equivalent to |
must be equivalent to
.release-notes/3650.md
Outdated
@@ -0,0 +1,17 @@ | |||
## Graceful error handling on `consume` expressions | |||
|
|||
The fix ensures |
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.
The fix ensures | |
The fix ensures: | |
.release-notes/3650.md
Outdated
@@ -0,0 +1,17 @@ | |||
## Graceful error handling on `consume` expressions |
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 what is missing from these release notes is an that previously some of these things might have been compiler errors etc before. The fix ensures some things, but what does that mean for the end-user?
Something along the lines of "previously any of X would result in Y that has now been fixed" is an important part of the release notes messaging.
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.
Rephrased. Can you please check if this sounds better? also I removed one of the points. I notice that 0.38.0 already covered it. (That particular fix was only refactored this time around).
Co-authored-by: Sean T Allen <sean@seantallen.com>
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.
Excellent release note update. Thanks!
consume (consume variable).field
must result in similar compilation error asconsume (consume variable)
.consume f().field
must result in similar compilation error asconsume f()
(consume c).field
must not result in a crash.Fixes #3463, #3567 (and #3453)