Skip to content

gh-132775: Add _PyCode_Returns() #132981

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

Merged
merged 5 commits into from
Apr 29, 2025

Conversation

ericsnowcurrently
Copy link
Member

@ericsnowcurrently ericsnowcurrently commented Apr 25, 2025

The function indicates whether or not the function has a return statement.

This is used by a later change related treating some functions like scripts.

@ericsnowcurrently ericsnowcurrently changed the title Add _PyCode_Returns() gh-132775: Add _PyCode_Returns() Apr 25, 2025
@iritkatriel
Copy link
Member

I think this name is confusing because a function returning None also returns.

Py_ssize_t len = Py_SIZE(co);
for (int i = 0; i < len; i++) {
_Py_CODEUNIT inst = _Py_GetBaseCodeUnit(co, i);
if (inst.op.code == RETURN_VALUE) {
Copy link
Member

Choose a reason for hiding this comment

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

In the past we also had RETURN_CONST and we might have something like that in the future, so I think we should make this more robust. Perhaps add a macro in Include/internal/pycore_opcode_utils.h (say IS_RETURN_OPCODE). Also use this new macro in basicblock_returns in flowgraph.c.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@ericsnowcurrently ericsnowcurrently merged commit 96a7fb9 into python:main Apr 29, 2025
41 checks passed
@ericsnowcurrently ericsnowcurrently deleted the add-pycode-returns branch April 29, 2025 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants