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

Properly report default argument inference errors #2504

Merged
merged 2 commits into from
Feb 4, 2018

Conversation

mfelsche
Copy link
Contributor

Errors for default arguments could leave the AST in an illegal state,
which was causing assertions when evaluating default args during TK_CALL evaluation in the expr pass.

This PR makes those errors stop compilation immediately, so they are properly reported.

This fixes #2496

I did not handle TK_LITERAL in uifset as it seemed to be more of an unwanted state of the AST in general, if such an AST node reaches this function and thus tried to avoid getting into this branch in the first place.

errors for default arguments could leave the AST in an illegal state
which was causing assertions when evaluating default args during TK_CALL evaluation in the expr pass.

This PR makes those errors stop compilation immediately, so they are properly reported.
@mfelsche mfelsche added the changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge label Jan 17, 2018
@mfelsche mfelsche requested a review from Praetonus January 17, 2018 23:18
Copy link
Member

@Praetonus Praetonus left a comment

Choose a reason for hiding this comment

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

I'd personally prefer this bug to be fixed with the change to uifset. Returning AST_FATAL in a pass can be problematic since it stops error reporting for this compilation, and can require the programmer to do multiple edit-compile cycles if they have lots of errors in their code. As such, we only want to issue AST_FATAL results if an error is absolutely unrecoverable and we can't wait until the end of the current pass to stop AST processing.

Generally speaking, if there is an error in the source code the AST will be in an "unwanted state" anyway, so I don't think it is a problem to guard against such edge cases as long as it is in the same pass.

@mfelsche
Copy link
Contributor Author

Yeah, i totally see your point @Praetonus
If i do it like you suggested, the only downside is that we have the same error reported twice, both for the actual function definition with unresolvable literal default argument and for the call where the default argument is evaluated again.
I found that mildly annoying, but it is true that we should keep the edit compile cycles low.
If you are fine with two identical error messages, i will implement the uifset fix in this PR.

@Praetonus
Copy link
Member

You're right that the error shouldn't be reported twice, and in fact I think you were right from the beginning when saying that the change in uifset isn't right.

The root issue here, for both the crash and the duplicated error message, is that the default argument AST goes through the expr pass twice. This is due to the direct expr_seq call here. So the correct fix would be to replace that call with a call to ast_passes_subtree. That function will check if the AST has already been processed before processing it.

as this does not result in double error messages when evaluating default args for function definitions and function calls
@SeanTAllen
Copy link
Member

TravisCI MacOS builds are WAY behind again. There's a backlog of about 2,800. It's completely nuts. I've cancelled the MacOS builds associated with this. I ran the tests locally for LLVM 3.9.1 which is what we really care about. They passed.

@mfelsche
Copy link
Contributor Author

@Praetonus @SeanTAllen is this mergable from your point of view?

@mfelsche mfelsche merged commit 100f822 into master Feb 4, 2018
@mfelsche mfelsche deleted the default-arg-inference branch February 4, 2018 16:46
ponylang-main added a commit that referenced this pull request Feb 4, 2018
dipinhora pushed a commit to dipinhora/ponyc that referenced this pull request Jun 5, 2018
* Properly report default argument inference errors

errors for default arguments could leave the AST in an illegal state
which was causing assertions when evaluating default args during TK_CALL evaluation in the expr pass.

This PR makes those errors stop compilation immediately, so they are properly reported.

* use ast_passes_subtree instead of expr_seq for default arguments

as this does not result in double error messages when evaluating default args for function definitions and function calls
dipinhora pushed a commit to dipinhora/ponyc that referenced this pull request Jun 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compiler crash on default argument?
3 participants