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

Python frontend fixes for return values and arguments #1834

Merged
merged 4 commits into from
Dec 23, 2024
Merged

Conversation

tbennun
Copy link
Collaborator

@tbennun tbennun commented Dec 22, 2024

  • Properly parse return statements without a return value
  • Fix missing argument detection when no arguments are given

@tbennun tbennun requested a review from phschaad December 22, 2024 22:53
@tbennun
Copy link
Collaborator Author

tbennun commented Dec 22, 2024

@phschaad when reviewing, keep the following code in mind (I couldn't reproduce such a situation, you are more qualified to do so): is there any case where the top-level CFG target is an SDFG, and we still create a terminator (ReturnBlock) state?
I am thinking of a situation where the python frontend may parse an SDFG, visit a Return statement, and then continue to visit other states/blocks. In that case, the "return" state might still be incorrectly connected to subsequent states.

I want to make sure that creating a terminator (like the return statement) is airtight. Thanks!

ast_name = ast.copy_location(ast.Name(id='__return'), node)
self._visit_assign(new_node, ast_name, None, is_return=True)
else: # No return value
pass

if not isinstance(self.cfg_target, SDFG):
Copy link
Collaborator Author

@tbennun tbennun Dec 22, 2024

Choose a reason for hiding this comment

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

@phschaad Comment in PR refers to this code.

@phschaad
Copy link
Collaborator

@tbennun There isn't currently something in the frontend that consciously does it that way, but having a return block followed by other content is still valid and works similar to how it would work in Python - i.e., the program exits and everything following is dead code. On a separate branch I currently have even augmented dead state elimination to take that into account and kill more unreachable states. I have thus augmented the PR slightly to insert such a return block now to make the feature airtight.

@tbennun tbennun added this pull request to the merge queue Dec 23, 2024
Merged via the queue into main with commit dbc7747 Dec 23, 2024
9 checks passed
@tbennun tbennun deleted the return-fix branch December 23, 2024 16:53
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

Successfully merging this pull request may close these issues.

2 participants