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-17611. Move unwinding of stack for "pseudo exceptions" from interpreter to compiler. #5006

Merged
merged 85 commits into from
Feb 22, 2018
Merged
Show file tree
Hide file tree
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 Jul 23, 2017
b160900
Cleanup
pitrou Jul 23, 2017
9833631
Improve stack size calculation for SETUP_{EXCEPT,FINALLY}
pitrou Jul 23, 2017
9116fb8
Update frozen importlib
pitrou Jul 23, 2017
5b3796e
Remove useless code
pitrou Jul 23, 2017
77caab0
Don't predict FOR_ITER as it breaks tracing without computed gotos
pitrou Jul 23, 2017
9fffb61
Remove dead code and fix tracing tests
pitrou Jul 23, 2017
5fe5e1b
Fix test_dis
pitrou Jul 23, 2017
a93f2e2
Add JUMP_FINALLY to avoid finally block duplication
pitrou Jul 24, 2017
b007b1c
Remove finally block duplication
pitrou Jul 24, 2017
0bcf8a7
More precise computation of code object stack size
pitrou Jul 24, 2017
eecf02f
JUMP_FINALLY pushes 6 values to be consistent with the effect of an e…
pitrou Jul 24, 2017
64225ce
Exact stack size computation by popping stale exception state in RERAISE
pitrou Jul 24, 2017
04e055e
Remove the now pointless POP_MANY
pitrou Jul 24, 2017
a3e1b80
Add comment for RERAISE
pitrou Jul 24, 2017
a049635
Remove JUMP_FINALLY
pitrou Jul 24, 2017
0741d02
Remove last block duplication
pitrou Jul 24, 2017
5493616
Get rid of END_ITER
pitrou Jul 24, 2017
5c68acf
Fix comments in frameobject.c
pitrou Jul 24, 2017
2d41c17
Add stack size tests
pitrou Jul 29, 2017
afc2235
Fix test_dis.
serhiy-storchaka Aug 24, 2017
00a6681
Simplify handling of 'for' loops in frame_setlineno() and fix it for …
serhiy-storchaka Aug 24, 2017
f8cc274
Do not duplicate the finally block.
serhiy-storchaka Dec 3, 2017
160ce37
Refactor the frame unwinding code.
serhiy-storchaka Dec 4, 2017
b3b3250
Refactoring and optimizations in the compiler.
serhiy-storchaka Dec 5, 2017
e3f5099
Fix frame_setlineno().
serhiy-storchaka Dec 23, 2017
d8dd38d
Rename PUSH_NO_EXCEPT to BEGIN_FINALLY.
serhiy-storchaka Dec 23, 2017
f1d0bc9
Restore SETUP_WITH and SETUP_ASYNC_WITH.
serhiy-storchaka Dec 24, 2017
84c6400
Fix stack depth calculation.
serhiy-storchaka Dec 24, 2017
35bd61b
Remove SETUP_EXCEPT.
serhiy-storchaka Dec 24, 2017
191f2da
Fix rebase error.
serhiy-storchaka Dec 24, 2017
f1a478d
Change codes of new instructions.
serhiy-storchaka Dec 24, 2017
f44d8cd
Update the magic number.
serhiy-storchaka Dec 24, 2017
93ca80e
Remove debug print.
serhiy-storchaka Dec 24, 2017
c8b9129
Polishing.
serhiy-storchaka Dec 24, 2017
e7d03f3
Document changes.
serhiy-storchaka Dec 24, 2017
9273f10
Make CALL_FINALLY a jump instruction, but exclude it from stack depth…
serhiy-storchaka Dec 25, 2017
4ffb02f
Merge branch 'master' into unwind_stack
serhiy-storchaka Dec 26, 2017
b0ea014
Fix jump tests: jumping into a while block is possible now.
serhiy-storchaka Dec 26, 2017
bef9131
Polishing.
serhiy-storchaka Dec 28, 2017
7fc9111
Fix unrolling the finally block.
serhiy-storchaka Dec 28, 2017
800df5c
Optimize 'return' with constant value.
serhiy-storchaka Dec 28, 2017
cb806c5
Do not eliminate END_FINALLY in peepholer.
serhiy-storchaka Dec 29, 2017
c0623d6
Minimize changes in PyCompile_OpcodeStackEffect().
serhiy-storchaka Dec 29, 2017
69d6900
Document POP_FINALLY and add tests for 'break' and 'return' in 'final…
serhiy-storchaka Dec 29, 2017
c879d2e
Polishing.
serhiy-storchaka Dec 29, 2017
894a1f7
Minimize changes in WITH_CLEANUP_START and WITH_CLEANUP_START.
serhiy-storchaka Dec 29, 2017
dc6eae4
Address review comments.
serhiy-storchaka Dec 30, 2017
88a9050
Disable FOR_ITER jump optimization.
serhiy-storchaka Jan 1, 2018
ed175f3
Reorder tests.
serhiy-storchaka Jan 1, 2018
4485924
Merge branch 'master' into unwind_stack
serhiy-storchaka Jan 1, 2018
b49d46e
Merge branch 'master' into unwind_stack
serhiy-storchaka Jan 1, 2018
4ca9831
Clarify the use case of POP_FINALLY.
serhiy-storchaka Jan 1, 2018
e34670a
bpo-24340: Fix estimation of the code stack size.
serhiy-storchaka Jan 1, 2018
42b50d1
Add new tests for stack effect (ported from #5076).
serhiy-storchaka Jan 1, 2018
3d04b53
Add comments.
serhiy-storchaka Jan 1, 2018
4b1697d
Simplify the algorithm, add comments and asserts.
serhiy-storchaka Jan 3, 2018
dc25d14
Merge branch 'master' into stack-size
serhiy-storchaka Jan 3, 2018
8a327cb
Merge branch 'master' into unwind_stack
serhiy-storchaka Jan 3, 2018
4afb870
Merge branch 'stack-size' into unwind_stack
serhiy-storchaka Jan 3, 2018
4d81d0d
Fix stack effect computation.
serhiy-storchaka Jan 3, 2018
edde33a
Update comments and docs in responce to the review.
serhiy-storchaka Jan 3, 2018
44c7d39
Add more tests.
serhiy-storchaka Jan 3, 2018
8dcb17f
Merge branch 'stack-size' into unwind_stack_new
serhiy-storchaka Jan 3, 2018
0317c9d
Add more comments.
serhiy-storchaka Jan 3, 2018
7a33146
Define all stack effects in a single place.
serhiy-storchaka Jan 4, 2018
68e35bb
Make stack_effect() static.
serhiy-storchaka Jan 5, 2018
6056bc7
Add braces for PEP 7.
serhiy-storchaka Jan 7, 2018
44e1e1e
Merge branch 'master' into stack-size
serhiy-storchaka Jan 7, 2018
04647d6
Merge branch 'master' into unwind_stack
serhiy-storchaka Jan 7, 2018
6d5c333
Merge branch 'stack-size' into unwind_stack
serhiy-storchaka Jan 7, 2018
660a117
Add braces for PEP 7.
serhiy-storchaka Jan 7, 2018
a03d212
Merge branch 'master' into unwind_stack
serhiy-storchaka Jan 9, 2018
ff0448f
Merge branch 'master' into unwind_stack
serhiy-storchaka Jan 9, 2018
bd39e0a
Simplify WITH_CLEANUP_START. It is never called after CALL_FINALLY.
serhiy-storchaka Jan 9, 2018
156b455
Merge branch 'master' into unwind_stack
serhiy-storchaka Jan 11, 2018
cd56a99
Merge branch 'master' into unwind_stack
serhiy-storchaka Jan 16, 2018
0816c92
Merge branch 'master' into unwind_stack
serhiy-storchaka Feb 1, 2018
c161251
Merge branch 'master' into unwind_stack
serhiy-storchaka Feb 1, 2018
af9ddf0
Update the magic number.
serhiy-storchaka Feb 4, 2018
c566673
Merge branch 'master' into unwind_stack
serhiy-storchaka Feb 4, 2018
9aee1f0
Merge branch 'master' into unwind_stack
serhiy-storchaka Feb 4, 2018
24667a4
Merge branch 'master' into unwind_stack
serhiy-storchaka Feb 9, 2018
47c5067
Merge branch 'master' into unwind_stack
serhiy-storchaka Feb 22, 2018
4a63042
Merge branch 'master' into unwind_stack
serhiy-storchaka Feb 22, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update comments and docs in responce to the review.
  • Loading branch information
serhiy-storchaka committed Jan 3, 2018
commit edde33aabfba9cb198fa72d5901b74e6514c746d
9 changes: 5 additions & 4 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -681,17 +681,18 @@ iterations of the loop.
used to restore the exception state. An exception handler block is
removed from the block stack.

It is similar to :opcode:`END_FINALLY`, but neither change the bytecode
counter nor raises an exception. Used for implementing :keyword:`break`
It is similar to :opcode:`END_FINALLY`, but doesn't change the bytecode
counter nor raise an exception. Used for implementing :keyword:`break`
and :keyword:`return` in the :keyword:`finally` block.

.. versionadded:: 3.7


.. opcode:: BEGIN_FINALLY

Pushes ``NULL`` onto the stack for using it in :opcode:`END_FINALLY`.
Starts the :keyword:`finally` block.
Pushes ``NULL`` onto the stack for using it in :opcode:`END_FINALLY`,
:opcode:`POP_FINALLY`, :opcode:`WITH_CLEANUP_START` and
:opcode:`WITH_CLEANUP_FINISH`. Starts the :keyword:`finally` block.

.. versionadded:: 3.7

Expand Down
15 changes: 14 additions & 1 deletion Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -1899,6 +1899,16 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
}

TARGET(POP_FINALLY) {
/* If oparg is 0 at the top of the stack are 1 or 6 values:
Either:
- TOP = NULL or an integer
or:
- (TOP, SECOND, THIRD) = exc_info()
- (FOURTH, FITH, SIXTH) = previous exception for EXCEPT_HANDLER

If oparg is 1 the value for 'return' was additionally pushed
at the top of the stack.
*/
PyObject *res = NULL;
Copy link
Member

Choose a reason for hiding this comment

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

I would expect a similar comment as at the to top of END_FINALLY here.

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.

if (oparg) {
res = POP();
Expand Down Expand Up @@ -1950,6 +1960,9 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
}

TARGET(BEGIN_FINALLY) {
/* Push NULL onto the stack for using it in END_FINALLY,
POP_FINALLY, WITH_CLEANUP_START and WITH_CLEANUP_FINISH.
*/
PUSH(NULL);
Copy link
Member

Choose a reason for hiding this comment

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

Explain this is in a comment here?

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.

FAST_DISPATCH();
}
Expand All @@ -1958,7 +1971,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
TARGET(END_FINALLY) {
/* At the top of the stack are 1 or 6 values:
Either:
- NULL or an integer
- TOP = NULL or an integer
or:
- (TOP, SECOND, THIRD) = exc_info()
- (FOURTH, FITH, SIXTH) = previous exception for EXCEPT_HANDLER
Expand Down
4 changes: 3 additions & 1 deletion Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,9 @@ PyCompile_OpcodeStackEffect(int opcode, int oparg)
return 6;
case BEGIN_FINALLY:
/* Actually pushes 1 value, but count 6 for balancing with
* END_FINALLY and POP_FINALLY. */
* END_FINALLY and POP_FINALLY.
* This is the main reason of using this opcode instead of
* "LOAD_CONST None". */
return 6;
case CALL_FINALLY:
return 1;
Expand Down