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

Towards error resilient frontend #5036

Open
1 of 4 tasks
Pranavchiku opened this issue Oct 12, 2024 · 2 comments
Open
1 of 4 tasks

Towards error resilient frontend #5036

Pranavchiku opened this issue Oct 12, 2024 · 2 comments

Comments

@Pranavchiku
Copy link
Member

Pranavchiku commented Oct 12, 2024

Picked from PR: #1098:

This example shows how to recover from errors, it creates an AST:

tests/errors(error2) $ lfortran assignment_01.f90 --show-ast
ERROR 3
ERROR 2
(TranslationUnit 
    [(Module 
        assignment_01 
        (TriviaNode 
            [(EndOfLine)
            (EndOfLine)] 
            []
        ) 
        [] 
        [] 
        [] 
        [(Subroutine 
            f 
            [(a)
            (b)] 
            [] 
            () 
            (TriviaNode 
                [] 
                [(EndOfLine)
                (EndOfLine)]
            ) 
            [] 
            [] 
            [] 
            [(Declaration 
                (AttrType 
                    TypeInteger 
                    [] 
                    () 
                    None
                ) 
                [(AttrIntent 
                    InOut
                )] 
                [(a 
                [] 
                [] 
                () 
                None 
                ())
                (b 
                [] 
                [] 
                () 
                None 
                ())] 
                (TriviaNode 
                    [] 
                    [(EndOfLine)
                    (EndOfLine)]
                )
            )] 
            [(= 
                0 
                b 
                b 
                (TriviaNode 
                    [] 
                    [(EndOfLine)
                    (EndOfLine)]
                )
            )] 
            []
        )]
    )]
)

TODO:

  • Put the syntax error into the diagnostics, but continue (Fault Tolerant Parsing #4774)
  • Add a compiler option that would keep these errors but it would not exit after AST, but to ASR as well, just ignoring/recovering from the error
  • Create InvalidStatement, or InvalidExpr AST nodes, and insert them into the tree with location information and any other info that we might have
  • Benchmark speed for valid code to ensure there is no regression (I don't expect a significant slow down, but let's check)
@Pranavchiku Pranavchiku mentioned this issue Oct 12, 2024
4 tasks
@certik
Copy link
Contributor

certik commented Oct 12, 2024

@Pranavchiku as we discussed:

  • use the SemanticAbort exception, but catch at at the statement level. Keep constructing ASR.

I think we should for now not add error nodes into the AST/ASR, that can be done later if needed, and perhaps it is not needed.

@Pranavchiku
Copy link
Member Author

Yes, I just copied it over so that I can brainstorm and document design ideas here whenever I do.

This was referenced Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants