Visitar URL original
bpo-46202: Remove opcode POP_EXCEPT_AND_RERAISE by iritkatriel · Pull Request #30302 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20221223144232/https://github.com/python/cpython/pull/30302
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

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

bedevere-bot commented Dec 30, 2021

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

iritkatriel commented Dec 30, 2021

I think the bot wants this in a new comment:

I have made the requested changes; please review again.

@bedevere-bot
Copy link

bedevere-bot commented Dec 30, 2021

Thanks for making the requested changes!

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

@bedevere-bot bedevere-bot requested a review from brandtbucher Dec 30, 2021
Copy link
Member

@ericsnowcurrently ericsnowcurrently left a comment

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

iritkatriel commented Dec 30, 2021

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

LGTM

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

@iritkatriel
Copy link
Member Author

iritkatriel commented Dec 31, 2021

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 Jan 2, 2022
@iritkatriel
Copy link
Member Author

iritkatriel commented Jan 2, 2022

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

Copy link
Member

@ericsnowcurrently ericsnowcurrently left a comment

LGTM

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

None yet

6 participants