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

bpo-46202: Remove opcode POP_EXCEPT_AND_RERAISE #30302

Merged
merged 10 commits into from
Jan 4, 2022

Conversation

iritkatriel
Copy link
Member

@iritkatriel iritkatriel commented Dec 30, 2021

Following the reduction of exc_info to just one stack item, POP_EXCEPT_AND_RERAISE can be replaced by an equivalent sequence of other opcodes.

One of the except* usages can be simplified further because it doesn't need to restore lasti. (this was moved to another pr).

https://bugs.python.org/issue46202

Copy link
Member

@brandtbucher brandtbucher left a comment

Choose a reason for hiding this comment

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

Nice! Looks good to me, except for one weird bug I stumbled upon while reviewing it.

It's not directly related to these changes, but it still probably deserves to be fixed:

Python/compile.c Outdated Show resolved Hide resolved
@bedevere-bot
Copy link

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@iritkatriel
Copy link
Member Author

I think the bot wants this in a new comment:

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@brandtbucher: please review the changes made to this pull request.

Copy link
Member

@ericsnowcurrently ericsnowcurrently left a comment

Choose a reason for hiding this comment

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

This strictly relates to re-raising an exception, right?

try:
    ...
except Exception:
    ...
    raise  # re-raise

and not raising an exception while handing another:

try:
    ...
except Exception as exc:
    ...
    raise exc
    # or raise Exception
    # or raise exc from exc2

Python/ceval.c Show resolved Hide resolved
Python/compile.c Outdated Show resolved Hide resolved
Python/compile.c Outdated Show resolved Hide resolved
Python/compile.c Show resolved Hide resolved
Python/ceval.c Show resolved Hide resolved
@iritkatriel
Copy link
Member Author

This strictly relates to re-raising an exception, right?

try:
    ...
except Exception:
    ...
    raise  # re-raise

and not raising an exception while handing another:

try:
    ...
except Exception as exc:
    ...
    raise exc
    # or raise Exception
    # or raise exc from exc2

It's for both - it's when you are about the exit a finally block, and you have a previous "handled exception" on the stack (because this finally is from a try-except or a with-statement which is nested in an except clause), and above it you have the lasti and an exception that you need to raise. So you need to pop the TOS and the lasti below it and raise, but first you need to take the THIRD item and use it to restore exc_info.

Copy link
Member

@ericsnowcurrently ericsnowcurrently left a comment

Choose a reason for hiding this comment

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

LGTM

(assuming you address any other review comments, of course)

@iritkatriel
Copy link
Member Author

I think this PR lost focus a bit. I want to split the except* changes into a separate PR and just do a straightforward opcode removal in this one.

@iritkatriel iritkatriel marked this pull request as ready for review January 2, 2022 23:36
@iritkatriel
Copy link
Member Author

I committed the except* changes separately so this PR now just removes POP_EXCEPT_AND_RERAISE.

Copy link
Member

@ericsnowcurrently ericsnowcurrently left a comment

Choose a reason for hiding this comment

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

LGTM

@markshannon markshannon merged commit a94461d into python:main Jan 4, 2022
@iritkatriel iritkatriel deleted the remove-POP_EXCEPT_AND_RERAISE branch January 13, 2022 15:33
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.

6 participants