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

Internal Compiler Error: Unhandled exception #2312

Closed
davidbrochart opened this issue Sep 4, 2023 · 9 comments
Closed

Internal Compiler Error: Unhandled exception #2312

davidbrochart opened this issue Sep 4, 2023 · 9 comments

Comments

@davidbrochart
Copy link

It seems asyncio is not supported yet? I get the following error while importing it:

semantic error: Could not find the module 'asyncio'. If an import path is available, please use the `-I` option to specify it

As a workaround, I wanted to try this simple coroutine runner:

async def main():
    print("done")

def run_async_fn(async_fn, *args, **kwargs):
    coro = async_fn(*args, **kwargs)
    try:
        coro.send(None)
    except StopIteration as exc:
        return exc.value
    else:
        raise RuntimeError("Cannot run async function")

run_async_fn(main)

But I get:

Internal Compiler Error: Unhandled exception
@certik
Copy link
Contributor

certik commented Sep 4, 2023

Yes, we don't support asyncio natively yet. The second example should give a nice error, so that's a bug. Thanks for reporting it!

@davidbrochart
Copy link
Author

Actually I get a better error message with lpython from conda-forge (the above was with lpython compiled locally):

Internal Compiler Error: Unhandled exception
Traceback (most recent call last):
LCompilersException: visit_AsyncFunctionDef() not implemented

So I guess this issue should be closed?

@certik
Copy link
Contributor

certik commented Sep 5, 2023

Leave it open. This error message is a general developer error message that we have not implemented visit_AsyncFunctionDef in the AST->ASR visitor.

However the error message should actually be the user error message where we underline the code that is not supported and explain why, possibly linking to a github issue.

@ujjwaltwitx
Copy link
Contributor

Hello everyone, I want to work on this issue but I have no idea on how to approach this. Can someone just guide me a bit in the right direction.

@certik
Copy link
Contributor

certik commented Nov 30, 2023

@ujjwaltwitx you have to override the function visit_AsyncFunctionDef in AST to ASR, and raise a nice error message to the user. You can watch https://www.youtube.com/watch?v=yuYsyM08bss to get an idea how the internals work.

@ujjwaltwitx
Copy link
Contributor

Sorry for replying this late. I was busy doing some other work. I will watch the video and if I face any difficulties, I will definitely get back to the community for help.

@ujjwaltwitx
Copy link
Contributor

ujjwaltwitx commented Dec 11, 2023

I have implemented visit_AsyncFunctionDef in SymbolTableVisitor class. Here's the definition of the function

void visit_AsyncFunctionDef(const AST::AsyncFunctionDef_t &x){
        try
        {
            // to be implemented
        }
        catch(const std::exception& e)
        {
            std::cerr << e.what() << '\n';
        }        
    }

Am I required to add something more to this function. I have also add the visit_AsyncFunctionDef in BodyVisitor class. Here's the definition of the same

void visit_AsyncFunctionDef(const AST::AsyncFunctionDef_t &x) {
        try
        {
            // BodyVisitor for visit_AsyncFunctionDef to be implemented
        }
        catch(const std::exception& e)
        {
            std::cerr << e.what() << '\n';
        }
    }

Any feedback will be much appreciated.

@syheliel
Copy link
Contributor

This problem has been fixed in #2442 . should we close this issue?

@certik
Copy link
Contributor

certik commented Feb 16, 2024

Here is what I get on the above code now:

$ lpython a.py 
semantic error: The `async` keyword is currently not supported
 --> a.py:1:1 - 2:17
  |
1 |    async def main():
  |    ^^^^^^^^^^^^^^^^^...
...
  |
2 |        print("done")
  | ...^^^^^^^^^^^^^^^^^ 


Note: Please report unclear or confusing messages as bugs at
https://github.com/lcompilers/lpython/issues.

So I think this issue is now fixed.

@certik certik closed this as completed Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants