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

improve exception handling notes around lasti #100467

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

P403n1x87
Copy link
Contributor

@P403n1x87 P403n1x87 commented Dec 23, 2022

This change improves the description of the new exception table, focusing on describing the meaning of the lasti flag, and when one should expect it to be set.

@P403n1x87
Copy link
Contributor Author

P403n1x87 commented Dec 23, 2022

@gvanrossum @markshannon following this discussion, I am proposing some improvements to the exception handling notes.

@merwok merwok changed the title chore: improve exception handling notes around lasti improve exception handling notes around lasti Dec 23, 2022
Objects/exception_handling_notes.txt Outdated Show resolved Hide resolved
This change improves the description of the new exception table,
focusing on describing the meaning of the lasti flag, and when one
should expect it to be set.
@P403n1x87 P403n1x87 force-pushed the chore/exception-table-lasti branch from 317b5bc to 2834cb9 Compare Dec 23, 2022
@P403n1x87 P403n1x87 requested a review from merwok Dec 23, 2022
Currently, the only opcode that requires the lasti flag to be set is RERAISE.
That is, if the jump described by an exception table points to an offset where
a RERAISE (with a non-zero oparg) occurs, the lasti is expected to be on the
stack, and therefore the lasti flag of the exception table entry must be set.
The last example gives an illustration of this. The first table entry describes
a jump where no RERAISE is executed. The second entry describes a jump where a
RERAISE with oparg 1 is executed. This means that the RERAISE will consume the
TOS and assume it is the lasti that was pushed when the exception occurred, as
instructed by the lasti flag.
Copy link
Member

@gvanrossum gvanrossum Dec 23, 2022

Choose a reason for hiding this comment

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

While it's true that the lasti pushed on the stack is intended to be consumed by RESUME, this description lacks clarity on the Python constructs that generate RERAISE. It would be good to show some examples (maybe an exhaustive list) of constructs that do or don't use RERAISE. E.g.

try:
    xxx
except Exception:
    yyy

does not use RERAISE, but if we replace the last two lines with

finally:
    zzz

then we do. IIUC the other construct that uses RERAISE is the with statement, which after __exit__ returns may use RERAISE.

Maybe @iritkatriel or @markshannon can help review this.

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.

None yet

6 participants