-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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-17611. Move unwinding of stack for "pseudo exceptions" from interpreter to compiler. #5006
Merged
serhiy-storchaka
merged 85 commits into
python:master
from
serhiy-storchaka:unwind_stack
Feb 22, 2018
Merged
Changes from 1 commit
Commits
Show all changes
85 commits
Select commit
Hold shift + click to select a range
2315076
bpo-17611: Move unwinding of stack from interpreter to compiler
pitrou b160900
Cleanup
pitrou 9833631
Improve stack size calculation for SETUP_{EXCEPT,FINALLY}
pitrou 9116fb8
Update frozen importlib
pitrou 5b3796e
Remove useless code
pitrou 77caab0
Don't predict FOR_ITER as it breaks tracing without computed gotos
pitrou 9fffb61
Remove dead code and fix tracing tests
pitrou 5fe5e1b
Fix test_dis
pitrou a93f2e2
Add JUMP_FINALLY to avoid finally block duplication
pitrou b007b1c
Remove finally block duplication
pitrou 0bcf8a7
More precise computation of code object stack size
pitrou eecf02f
JUMP_FINALLY pushes 6 values to be consistent with the effect of an e…
pitrou 64225ce
Exact stack size computation by popping stale exception state in RERAISE
pitrou 04e055e
Remove the now pointless POP_MANY
pitrou a3e1b80
Add comment for RERAISE
pitrou a049635
Remove JUMP_FINALLY
pitrou 0741d02
Remove last block duplication
pitrou 5493616
Get rid of END_ITER
pitrou 5c68acf
Fix comments in frameobject.c
pitrou 2d41c17
Add stack size tests
pitrou afc2235
Fix test_dis.
serhiy-storchaka 00a6681
Simplify handling of 'for' loops in frame_setlineno() and fix it for …
serhiy-storchaka f8cc274
Do not duplicate the finally block.
serhiy-storchaka 160ce37
Refactor the frame unwinding code.
serhiy-storchaka b3b3250
Refactoring and optimizations in the compiler.
serhiy-storchaka e3f5099
Fix frame_setlineno().
serhiy-storchaka d8dd38d
Rename PUSH_NO_EXCEPT to BEGIN_FINALLY.
serhiy-storchaka f1d0bc9
Restore SETUP_WITH and SETUP_ASYNC_WITH.
serhiy-storchaka 84c6400
Fix stack depth calculation.
serhiy-storchaka 35bd61b
Remove SETUP_EXCEPT.
serhiy-storchaka 191f2da
Fix rebase error.
serhiy-storchaka f1a478d
Change codes of new instructions.
serhiy-storchaka f44d8cd
Update the magic number.
serhiy-storchaka 93ca80e
Remove debug print.
serhiy-storchaka c8b9129
Polishing.
serhiy-storchaka e7d03f3
Document changes.
serhiy-storchaka 9273f10
Make CALL_FINALLY a jump instruction, but exclude it from stack depth…
serhiy-storchaka 4ffb02f
Merge branch 'master' into unwind_stack
serhiy-storchaka b0ea014
Fix jump tests: jumping into a while block is possible now.
serhiy-storchaka bef9131
Polishing.
serhiy-storchaka 7fc9111
Fix unrolling the finally block.
serhiy-storchaka 800df5c
Optimize 'return' with constant value.
serhiy-storchaka cb806c5
Do not eliminate END_FINALLY in peepholer.
serhiy-storchaka c0623d6
Minimize changes in PyCompile_OpcodeStackEffect().
serhiy-storchaka 69d6900
Document POP_FINALLY and add tests for 'break' and 'return' in 'final…
serhiy-storchaka c879d2e
Polishing.
serhiy-storchaka 894a1f7
Minimize changes in WITH_CLEANUP_START and WITH_CLEANUP_START.
serhiy-storchaka dc6eae4
Address review comments.
serhiy-storchaka 88a9050
Disable FOR_ITER jump optimization.
serhiy-storchaka ed175f3
Reorder tests.
serhiy-storchaka 4485924
Merge branch 'master' into unwind_stack
serhiy-storchaka b49d46e
Merge branch 'master' into unwind_stack
serhiy-storchaka 4ca9831
Clarify the use case of POP_FINALLY.
serhiy-storchaka e34670a
bpo-24340: Fix estimation of the code stack size.
serhiy-storchaka 42b50d1
Add new tests for stack effect (ported from #5076).
serhiy-storchaka 3d04b53
Add comments.
serhiy-storchaka 4b1697d
Simplify the algorithm, add comments and asserts.
serhiy-storchaka dc25d14
Merge branch 'master' into stack-size
serhiy-storchaka 8a327cb
Merge branch 'master' into unwind_stack
serhiy-storchaka 4afb870
Merge branch 'stack-size' into unwind_stack
serhiy-storchaka 4d81d0d
Fix stack effect computation.
serhiy-storchaka edde33a
Update comments and docs in responce to the review.
serhiy-storchaka 44c7d39
Add more tests.
serhiy-storchaka 8dcb17f
Merge branch 'stack-size' into unwind_stack_new
serhiy-storchaka 0317c9d
Add more comments.
serhiy-storchaka 7a33146
Define all stack effects in a single place.
serhiy-storchaka 68e35bb
Make stack_effect() static.
serhiy-storchaka 6056bc7
Add braces for PEP 7.
serhiy-storchaka 44e1e1e
Merge branch 'master' into stack-size
serhiy-storchaka 04647d6
Merge branch 'master' into unwind_stack
serhiy-storchaka 6d5c333
Merge branch 'stack-size' into unwind_stack
serhiy-storchaka 660a117
Add braces for PEP 7.
serhiy-storchaka a03d212
Merge branch 'master' into unwind_stack
serhiy-storchaka ff0448f
Merge branch 'master' into unwind_stack
serhiy-storchaka bd39e0a
Simplify WITH_CLEANUP_START. It is never called after CALL_FINALLY.
serhiy-storchaka 156b455
Merge branch 'master' into unwind_stack
serhiy-storchaka cd56a99
Merge branch 'master' into unwind_stack
serhiy-storchaka 0816c92
Merge branch 'master' into unwind_stack
serhiy-storchaka c161251
Merge branch 'master' into unwind_stack
serhiy-storchaka af9ddf0
Update the magic number.
serhiy-storchaka c566673
Merge branch 'master' into unwind_stack
serhiy-storchaka 9aee1f0
Merge branch 'master' into unwind_stack
serhiy-storchaka 24667a4
Merge branch 'master' into unwind_stack
serhiy-storchaka 47c5067
Merge branch 'master' into unwind_stack
serhiy-storchaka 4a63042
Merge branch 'master' into unwind_stack
serhiy-storchaka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Document POP_FINALLY and add tests for 'break' and 'return' in 'final…
…ly' clause.
- Loading branch information
commit 69d690032f5777ee9ae59b3f695d0c290e68e9c7
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 7 additions & 4 deletions
11
Misc/NEWS.d/next/Core and Builtins/2017-12-24-19-48-59.bpo-17611.P85kWL.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
Simplified the interpreter loop by moving the logic of unrolling the stack | ||
of blocks into the compiler. The compiler emits now explicit instructions | ||
for adjusting the stack of values and calling the cleaning up code for | ||
"break", "continue" and "return". | ||
:keyword:`break`, :keyword:`continue` and :keyword:`return`. | ||
|
||
Removed opcodes BREAK_LOOP, CONTINUE_LOOP, SETUP_LOOP and SETUP_EXCEPT. | ||
Added new opcodes ROT_FOUR, BEGIN_FINALLY and CALL_FINALLY. Changed the | ||
behavior of END_FINALLY. WITH_CLEANUP_FINISH now includes END_FINALLY. | ||
Removed opcodes :opcode:`BREAK_LOOP`, :opcode:`CONTINUE_LOOP`, | ||
:opcode:`SETUP_LOOP` and :opcode:`SETUP_EXCEPT`. Added new opcodes | ||
:opcode:`ROT_FOUR`, :opcode:`BEGIN_FINALLY` and :opcode:`CALL_FINALLY` and | ||
:opcode:`POP_FINALLY`. Changed the behavior of :opcode:`END_FINALLY`. | ||
:opcode:`WITH_CLEANUP_FINISH` now includes the functionality of | ||
:opcode:`END_FINALLY`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the sake of static bytecode analyzers, perhaps it would be better to have two separate opcodes: one preserving TOS, the other not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this just complicate the code and the documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code wouldn't be much more complicated (you can share the same implementation in the eval loop). OTOH I'm not sure it's necessary.
Other question: why are both POP_FINALLY and END_FINALLY needed? The documentation should be a bit clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
END_FINALLY
re-raises an exception,POP_FINALLY 0
just drops it.END_FINALLY
jumps to the return address,POP_FINALLY 0
ignores it. AndPOP_FINALLY 1
preserves TOS.I don't know what to add to the documentation. Can you provide your changes?
If push 6
None
instead of 1NULL
inBEGIN_FINALLY
, and push an exception block inBEGIN_FINALLY
, and update other instructions accordingly, and add additional hacks to stack effect calculation,POP_FINALLY 0
could be replaced with:and
POP_FINALLY 1
could be replaced with:This was my initial solution for @nascheme's examples. But this would add too much unneeded overhead and complication. The single new opcode has lesser cost.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes... So what I don't understand is why both are needed. In which case do you need to drop an exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'break' and 'return' in 'finally' clause.
'continue' is specially prohibited, but it can be allowed too after merging this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. Can you add some explanation of this in the docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.