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

[Feature] Implement error recovery for the Kipper compiler #198

Closed
5 tasks done
Tracked by #261 ...
Luna-Klatzer opened this issue Jun 18, 2022 · 1 comment · Fixed by #261
Closed
5 tasks done
Tracked by #261 ...

[Feature] Implement error recovery for the Kipper compiler #198

Luna-Klatzer opened this issue Jun 18, 2022 · 1 comment · Fixed by #261
Assignees
Labels
feature New feature or enhancement high priority High priority issue, discussion or pull request

Comments

@Luna-Klatzer
Copy link
Member

Luna-Klatzer commented Jun 18, 2022

Is there an existing proposal for this?

  • I have searched the existing issues

This feature does not exist in the latest version

  • I am using the latest version

Proposal

Implement error recovery for the Kipper compiler, which allows it to attempt recovery from an error and continue the semantic analysis if possible. This will make it be able to throw multiple compile errors and provide more insight into the errors of a program.

Example

  • Code:
    var x: typ = 5 + "str";
  • Errors:
    [ERROR]: Traceback:
      File 'anonymous-script', line 1, col 7:
        var x: typ = 5 + "5";
               ^^^ 
    TypeError: Unknown type 'typ'.
    [ERROR]: Traceback:
      File 'anonymous-script', line 1, col 13:
        var x: typ = 5 + "5";
                     ^^^^^^^ 
    InvalidArithmeticOperationError: Invalid arithmetic operation between types 'num' and 'str'.

Exact behaviour / changes you want

  • Add compile config field recover, which is per default true.
  • Add new CLI flags -r/--recover and --no-recover.
  • Implement the recover algorithm, which follows the following procedure (Lexing and Parsing does not apply to these rules):
    • Run semantic analysis for an AST node.
    • If the semantic analysis fails due to an error, try to determine whether the semantic data is present:
      • If not, then recovering for this AST node and its primary parent (statement or definition) is impossible, and as such, the whole statement/definition is discarded and the analysis should continue with the next statement or definition.
      • If it is present, then recover from this error and continue the analysis for the statement/definition.
    • Afterwards, the error should be added to a list of errors and then thrown using a single error at the end of the semantic analysis. (KipperCompileResult should contain an errors field, which provides a list of all errors).
    • Continue with the next expression, statement or definition.

Note

The recover algorithm can result in semantic data being missing. For example, if a variable can not be created/registered due to an error, recovering from that error will mean that any reference to it afterwards will cause more errors as the compiler does not know about the variable. This is bad behaviour, as it results in errors that are wrong and provide invalid insight into what went wrong. Such behaviour should therefore be avoided at all costs and the semantic analysis should be structured as robust as possible to make sure semantic data that is valid is registered, and as such "invalid errors" are avoided.

@Luna-Klatzer Luna-Klatzer added the feature New feature or enhancement label Jun 18, 2022
@Luna-Klatzer Luna-Klatzer self-assigned this Jun 18, 2022
@Luna-Klatzer Luna-Klatzer added this to the Stable Kipper Release milestone Jun 18, 2022
@Luna-Klatzer Luna-Klatzer added the high priority High priority issue, discussion or pull request label Jun 18, 2022
@Luna-Klatzer Luna-Klatzer pinned this issue Jun 26, 2022
@Luna-Klatzer Luna-Klatzer moved this from Todo to In Progress in Kipper Language Development Jul 28, 2022
@Luna-Klatzer
Copy link
Member Author

Luna-Klatzer commented Jul 29, 2022

Basic error recovery implementation implemented with 79f94a4. Development and tests will continue on the branch, and then later be merged into dev for the next release v0.10.0.

@Luna-Klatzer Luna-Klatzer linked a pull request Jul 29, 2022 that will close this issue
2 tasks
@Luna-Klatzer Luna-Klatzer mentioned this issue Aug 2, 2022
3 tasks
Repository owner moved this from In Progress to Done in Kipper Language Development Aug 2, 2022
@Luna-Klatzer Luna-Klatzer unpinned this issue Aug 2, 2022
@Luna-Klatzer Luna-Klatzer added this to the v0.10.0 milestone Jan 28, 2023
@Luna-Klatzer Luna-Klatzer mentioned this issue Feb 19, 2023
34 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or enhancement high priority High priority issue, discussion or pull request
Projects
Development

Successfully merging a pull request may close this issue.

1 participant