Dennis Sweeney
39bc70e267
gh-97912: Avoid quadratic behavior when adding LOAD_FAST_CHECK (GH-97952)
...
* The compiler analyzes the usage of the first 64 local variables all at once using bit masks.
* Local variables beyond the first 64 are only partially analyzed, achieving linear time.
2022-10-20 18:27:41 -04:00
Irit Katriel
4ec9ed8fde
gh-98461: Fix source location in comprehensions bytecode (GH-98464)
2022-10-20 16:58:37 +01:00
Irit Katriel
9be05df399
gh-98398: Fix source locations for 'assert' bytecode (GH-98405)
2022-10-19 10:48:50 +01:00
Irit Katriel
c051d55ddb
gh-98390: Fix source locations of boolean sub-expressions (GH-98396)
2022-10-18 17:18:38 +01:00
Irit Katriel
6da1a2e993
gh-93691: Compiler's code-gen passes location around instead of holding it on the global compiler state (GH-98001)
2022-10-17 14:28:51 +01:00
Irit Katriel
c529b45122
gh-87092: bring compiler code closer to a preprocessing-opt-assembler organisation (GH-97644)
2022-10-05 08:52:35 +01:00
Brandt Bucher
dfc73b5724
GH-95921: Fix positions for some chained comparisons (GH-96968)
2022-09-20 12:22:24 -07:00
Irit Katriel
98e785d364
gh-87092: in compiler, move the detection of exception handlers before the CFG optimization stage (GH-96935)
2022-09-20 13:14:07 +01:00
Irit Katriel
6d7a0e0dd7
gh-87092: reduce redundancy and repetition in compiler's optimization stage (GH-96713)
2022-09-13 13:03:41 +01:00
Irit Katriel
0cd992c000
gh-88057: in compile.c, assertion that stackdepth is alway >=0 is missing in one place (GH-96513)
2022-09-07 14:01:57 +01:00
Irit Katriel
4c72517cad
gh-93554: Conditional jump opcodes only jump forward (GH-96318)
2022-09-01 21:36:47 +01:00
Irit Katriel
894cafd9a5
gh-93678: apply remove_redundant_jumps in optimize_cfg (GH-96274)
2022-09-01 11:03:52 +01:00
Irit Katriel
fba3b67af4
gh-87092: use basicblock_last_instr consistently in the compiler (GH-96243)
2022-08-24 16:58:42 +01:00
Irit Katriel
420f39f457
gh-93678: add _testinternalcapi.optimize_cfg() and test utils for compiler optimization unit tests (GH-96007)
2022-08-24 11:02:53 +01:00
Brandt Bucher
5bfb3c372b
GH-90997: Wrap yield from/await in a virtual try/except StopIteration (GH-96010)
2022-08-19 12:33:44 -07:00
Irit Katriel
41757bfabd
gh-95922: compiler's eliminate_empty_basic_blocks ignores the last block of the compilation unit (GH-95924)
2022-08-12 16:35:09 +01:00
Irit Katriel
9533b40cce
gh-87092: compiler's codegen stage uses int jump target labels, and the target pointer is only calculated just before optimization stage (GH-95655)
2022-08-11 17:40:49 +01:00
Irit Katriel
000c3874bf
gh-87092: create a 'jump target label' abstraction so that the compiler's codegen stage does not work directly with basic blocks (GH-95398)
2022-08-04 14:59:32 +01:00
Irit Katriel
75c0c1b993
gh-93678: extract 'struct cfg_builder' from the compiler so that the CFG can be manipulated directly (GH-95107)
2022-07-26 14:36:30 +01:00
Brandt Bucher
900bfc53cb
GH-94036: Fix more attribute location quirks (GH-95028)
2022-07-22 13:13:16 -07:00
Brandt Bucher
e402b26b7f
GH-95113: Don't use EXTENDED_ARG_QUICK in unquickened code (GH-95121)
2022-07-22 11:04:20 -07:00
Brandt Bucher
742d4614e1
GH-91409: Don't overwrite valid locations with NOP locations (GH-95067)
2022-07-20 14:27:31 -07:00
Kumar Aditya
7476154886
GH-94851: fix immortal objects refcounting in compiler (gh-95040)
2022-07-20 18:53:27 +09:00
Irit Katriel
ea11c17742
gh-93678: move normalize_basic_block and extend_block call into optimize_cfg (GH-95002)
2022-07-19 17:48:56 +01:00
Brandt Bucher
264b3ddfd5
GH-94694: Fix column offsets for multi-line method lookups (GH-94697)
2022-07-09 17:22:23 -07:00
Irit Katriel
bde06e1b83
gh-92228: disable the compiler's 'small exit block inlining' optimization for blocks that have a line number (GH-94592)
...
Inlining of code that corresponds to source code lines, can make it hard to distinguish later between code which is only reachable from except handlers, and that which is reachable in normal control flow. This caused problems with the debugger's jump feature.
This PR turns off the inlining optimisation for code which has line numbers. We still inline things like the implicit "return None".
2022-07-06 23:38:36 -07:00
Irit Katriel
324d01944d
gh-94485: Set line number of module's RESUME instruction to 0, as specified by PEP 626 (GH-94552)
...
Co-authored-by: Mark Shannon <mark@hotpy.org>
2022-07-05 14:38:44 +02:00
Irit Katriel
c57aad777a
gh-94216: add pseudo instructions to the dis/opcodes modules (GH-94241)
2022-07-01 15:33:35 +01:00
Mark Shannon
b152bf448b
GH-94329: Don't raise on excessive stack consumption (GH-94421)
2022-06-30 15:27:14 +01:00
Irit Katriel
be82d26570
gh-94332: make it safe to call assemble_free when assemble_init has not been called (GH-94389)
2022-06-30 12:26:29 +01:00
Mark Shannon
c0453a40fa
GH-94163: Add BINARY_SLICE and STORE_SLICE instructions. (GH-94168)
2022-06-27 12:24:23 +01:00
Irit Katriel
889772fb56
GH-93678: refactor compiler so that optimizer does not need the assembler and compiler structs (GH-93842)
2022-06-21 09:22:17 +01:00
Irit Katriel
af15cc534c
GH-93678: reduce boilerplate and code repetition in the compiler (GH-93682)
2022-06-14 13:40:09 +01:00
Ken Jin
b083450f88
GH-93429: Merge `LOAD_METHOD` back into `LOAD_ATTR` (GH-93430)
2022-06-14 11:36:22 +01:00
Mark Shannon
2bf74753c1
GH-93662: Make sure that column offsets are correct in multi-line method calls. (GH-93673)
2022-06-14 11:08:12 +01:00
Irit Katriel
cf730b595e
GH-93621: reorder code in with/async-with exception exit path to reduce the size of the exception table (GH-93622)
2022-06-10 17:53:34 +01:00
Irit Katriel
1713ff09d6
GH-93444: remove redundant fields from basicblock: b_nofallthrough, b_exit, b_return (GH-93445)
2022-06-03 22:43:22 +01:00
Irit Katriel
94b1586ca5
gh-93356: Lay out exception handling code at end of code unit (GH-92769)
2022-06-02 14:13:43 +01:00
Dennis Sweeney
f425f3bb27
gh-93143: Avoid NULL check in LOAD_FAST based on analysis in the compiler (GH-93144)
2022-05-31 16:32:30 -04:00
Irit Katriel
ace6607aa3
gh-93008: refactor compiler functions that add instructions to take only a basicblock* (not the whole compiler) (GH-93009)
2022-05-29 17:13:29 +01:00
Kumar Aditya
cb04a09d2d
GH-93207: Remove HAVE_STDARG_PROTOTYPES configure check for stdarg.h ( #93215 )
2022-05-27 13:30:45 +02:00
Dennis Sweeney
ddc4a782d3
gh-93223: More aggressive Jump-To-Jump elimination (GH-93229)
2022-05-27 11:17:59 +01:00
Dennis Sweeney
a458be3263
gh-93061: Mark as artificial: backwards jump after async for (GH-93062)
2022-05-23 13:58:41 +01:00
Mark Shannon
3fd8610002
GH-89914: Make the oparg of the YIELD_VALUE instruction equal the stack depth. (GH-92960)
2022-05-19 17:49:29 +01:00
Mark Shannon
e48ac9c100
GH-90690: Remove `PRECALL` instruction (GH-92925)
2022-05-19 11:05:26 +01:00
Irit Katriel
8781a041a0
gh-92782: unify the style of CFG traversal algorithms in the compiler (GH-92784)
2022-05-17 13:00:11 +01:00
zikcheng
dc091204f9
gh-92632: Make function starunpack_helper run faster when encounters starred argument. (GH-92655)
2022-05-11 15:09:40 +09:00
Irit Katriel
7c6b7ade8d
gh-92619: Fix bug where the compiler duplicates exit blocks unnecessarily (GH-92620)
2022-05-10 13:36:08 +01:00
Dennis Sweeney
37c6db60f9
gh-91869: Fix tracing of specialized instructions with extended args (GH-91945)
2022-04-27 22:36:34 -06:00
Victor Stinner
64a54e511d
gh-91719: Add pycore_opcode.h internal header file ( #91906 )
...
Move the following API from Include/opcode.h (public C API) to a new
Include/internal/pycore_opcode.h header file (internal C API):
* EXTRA_CASES
* _PyOpcode_Caches
* _PyOpcode_Deopt
* _PyOpcode_Jump
* _PyOpcode_OpName
* _PyOpcode_RelativeJump
2022-04-26 00:14:30 +02:00
Mark Shannon
944fffee89
GH-88116: Use a compact format to represent end line and column offsets. (GH-91666)
...
* Stores all location info in linetable to conform to PEP 626.
* Remove column table from code objects.
* Remove end-line table from code objects.
* Document new location table format
2022-04-21 16:10:37 +01:00
Kumar Aditya
ab0d35d70d
bpo-46712: share more global strings in deepfreeze (gh-32152)
...
(for gh-90868)
2022-04-19 11:41:36 -06:00
Irit Katriel
304f5b63e9
Fix an out of date comment in compile.c (GH-91615)
2022-04-16 20:40:02 +01:00
Irit Katriel
ea2ae02607
gh-91276: Make JUMP_IF_TRUE_OR_POP/JUMP_IF_FALSE_OR_POP relative (GH-32215)
2022-04-15 20:19:24 +01:00
L. A. F. Pereira
5f056acdf2
Fill holes in internal compiler structs ( #91458 )
2022-04-13 15:09:20 -07:00
Irit Katriel
dd207a6ac5
bpo-47120: make POP_JUMP_IF_TRUE/FALSE/NONE/NOT_NONE relative (GH-32400)
2022-04-11 10:40:24 +01:00
Irit Katriel
0aa8d5cbd8
bpo-47120: make JUMP_NO_INTERRUPT relative (GH-32221)
2022-04-05 12:49:08 +01:00
Irit Katriel
32091df41c
bpo-47186: Replace JUMP_IF_NOT_EG_MATCH by CHECK_EG_MATCH + jump (GH-32309)
2022-04-05 12:06:22 +01:00
Irit Katriel
997ba5d126
bpo-47172: Compiler enhancements (GH-32200)
...
* Make virtual opcodes negative.
* Make is_jump detect only actual jumps.
* Use is_block_push for the exception block setup opcodes.
2022-04-01 15:50:15 +01:00
Irit Katriel
04e07c258f
bpo-47186: Replace JUMP_IF_NOT_EXC_MATCH by CHECK_EXC_MATCH + jump (GH-32231)
2022-04-01 13:59:38 +01:00
Irit Katriel
a00518d9ad
bpo-47120: Replace the JUMP_ABSOLUTE opcode by the relative JUMP_BACKWARD (GH-32115)
2022-03-31 14:14:15 +01:00
Matthew Rahtz
e8e737bcf6
bpo-43224: Implement PEP 646 grammar changes (GH-31018)
...
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2022-03-26 09:55:35 -07:00
Brandt Bucher
2bde6827ea
bpo-46841: Quicken code in-place (GH-31888)
...
* Moves the bytecode to the end of the corresponding PyCodeObject, and quickens it in-place.
* Removes the almost-always-unused co_varnames, co_freevars, and co_cellvars member caches
* _PyOpcode_Deopt is a new mapping from all opcodes to their un-quickened forms.
* _PyOpcode_InlineCacheEntries is renamed to _PyOpcode_Caches
* _Py_IncrementCountAndMaybeQuicken is renamed to _PyCode_Warmup
* _Py_Quicken is renamed to _PyCode_Quicken
* _co_quickened is renamed to _co_code_adaptive (and is now a read-only memoryview).
* Do not emit unused nonzero opargs anymore in the compiler.
2022-03-21 11:11:17 +00:00
Mark Shannon
3011a097bd
Use low bit of LOAD_GLOBAL's oparg to indicate whether it should push an additional NULL. (GH-31933)
2022-03-17 16:14:57 +00:00
Brandt Bucher
586b24d3be
bpo-46841: Fix error message hacks in `GET_AWAITABLE` (GH-31664)
2022-03-04 12:41:17 +00:00
Shantanu
81d968b7c3
bpo-46831: Update __build_class__ comment ( #31522 )
...
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2022-03-02 21:32:57 -08:00
Inada Naoki
df9f759755
compiler: Merge except_table and cnotab (GH-31614)
2022-03-01 10:27:20 +09:00
Mark Shannon
4558af5a8f
bpo-46841: Move the cache for `LOAD_GLOBAL` inline. (GH-31575)
2022-02-28 12:56:29 +00:00
Irit Katriel
c579243eb6
bpo-46808: remove NEXT_BLOCK() from compile.c (GH-31448)
2022-02-25 12:17:50 +00:00
Brandt Bucher
0f41aac109
bpo-46841: Use *inline* caching for `BINARY_OP` (GH-31543)
2022-02-25 12:11:34 +00:00
Eric Snow
1f455361ec
bpo-46765: Replace Locally Cached Strings with Statically Initialized Objects (gh-31366)
...
https://bugs.python.org/issue46765
2022-02-22 17:23:51 -07:00
Mark Shannon
59585d6b2e
bpo-46329: Streamline calling sequence a bit. (GH-31465)
...
* Move handling of bound-methods to PRECALL.
* Remove call_shape.postcall_shrink
* Remove call_shape.callable
* Remove call_shape.callable. Change CALL oparg to match PRECALL oparg.
* Move KW_NAMES before PRECALL.
* Update opcode docs in dis.rst
2022-02-21 18:26:47 +00:00
Mark Shannon
cf345e945f
bpo-46329: Change calling sequence (again) (GH-31373)
...
* Change calling sequence: Add PUSH_NULL. Merge PRECALL_FUNCTION and PRECALL_METHOD into PRECALL.
2022-02-18 17:19:08 +00:00
Mark Shannon
3be1a443ca
bpo-46724: Use `JUMP_ABSOLUTE` for all backward jumps. (GH-31326)
...
* Make sure all backward jumps use JUMP_ABSOLUTE.
* Add news.
* Fix up news item.
* Make test use consistent style.
2022-02-15 09:35:16 +00:00
Eric Snow
12360aa159
bpo-46541: Discover the global strings. (gh-31346)
...
Instead of manually enumerating the global strings in generate_global_objects.py, we extrapolate the list from usage of _Py_ID() and _Py_STR() in the source files.
This is partly inspired by gh-31261.
https://bugs.python.org/issue46541
2022-02-14 17:36:51 -07:00
Brandt Bucher
3b799d7448
Remove unnecessary basic block from comprehensions (GH-31263)
2022-02-14 17:48:45 +00:00
Brandt Bucher
78ae4cc6dc
bpo-46528: Attempt SWAPs at compile-time (GH-30970)
2022-02-09 15:15:36 -08:00
Brandt Bucher
46328d8ae6
bpo-46528: Check PyMem_Malloc for NULL (GH-30998)
2022-02-09 11:31:01 -08:00
Eric Snow
81c72044a1
bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized global objects. (gh-30928)
...
We're no longer using _Py_IDENTIFIER() (or _Py_static_string()) in any core CPython code. It is still used in a number of non-builtin stdlib modules.
The replacement is: PyUnicodeObject (not pointer) fields under _PyRuntimeState, statically initialized as part of _PyRuntime. A new _Py_GET_GLOBAL_IDENTIFIER() macro facilitates lookup of the fields (along with _Py_GET_GLOBAL_STRING() for non-identifier strings).
https://bugs.python.org/issue46541#msg411799 explains the rationale for this change.
The core of the change is in:
* (new) Include/internal/pycore_global_strings.h - the declarations for the global strings, along with the macros
* Include/internal/pycore_runtime_init.h - added the static initializers for the global strings
* Include/internal/pycore_global_objects.h - where the struct in pycore_global_strings.h is hooked into _PyRuntimeState
* Tools/scripts/generate_global_objects.py - added generation of the global string declarations and static initializers
I've also added a --check flag to generate_global_objects.py (along with make check-global-objects) to check for unused global strings. That check is added to the PR CI config.
The remainder of this change updates the core code to use _Py_GET_GLOBAL_IDENTIFIER() instead of _Py_IDENTIFIER() and the related _Py*Id functions (likewise for _Py_GET_GLOBAL_STRING() instead of _Py_static_string()). This includes adding a few functions where there wasn't already an alternative to _Py*Id(), replacing the _Py_Identifier * parameter with PyObject *.
The following are not changed (yet):
* stop using _Py_IDENTIFIER() in the stdlib modules
* (maybe) get rid of _Py_IDENTIFIER(), etc. entirely -- this may not be doable as at least one package on PyPI using this (private) API
* (maybe) intern the strings during runtime init
https://bugs.python.org/issue46541
2022-02-08 13:39:07 -07:00
Victor Stinner
7d8b69e1d1
bpo-46670: Remove unused macros in the Python directory (GH-31192)
2022-02-07 16:21:52 +01:00
Brandt Bucher
e0433c1e70
bpo-45773: Remove invalid peephole optimizations (GH-31066)
2022-02-03 10:14:44 +00:00
Brandt Bucher
a0e55a571c
bpo-46528: Simplify BUILD_TUPLE/UNPACK_SEQUENCE folding (GH-31039)
2022-02-01 13:41:32 -08:00
Mark Shannon
89fd7c3452
bpo-46329: Split calls into precall and call instructions. (GH-30855)
...
* Add PRECALL_FUNCTION opcode.
* Move 'call shape' varaibles into struct.
* Replace CALL_NO_KW and CALL_KW with KW_NAMES and CALL instructions.
* Specialize for builtin methods taking using the METH_FASTCALL | METH_KEYWORDS protocol.
* Allow kwnames for specialized calls to builtin types.
* Specialize calls to tuple(arg) and str(arg).
2022-01-28 12:42:30 +00:00
Irit Katriel
3d2ce34716
bpo-46458: emit code for else of a try block immediately after the try body (GH-30751)
2022-01-27 13:40:44 +00:00
Brandt Bucher
8548366864
bpo-46528: Simplify the VM's stack manipulations (GH-30902)
2022-01-26 12:47:45 -08:00
Mark Shannon
0367a36fdc
bpo-43683: Streamline YIELD_VALUE and SEND (GH-30723)
...
* Split YIELD_VALUE into ASYNC_GEN_WRAP; YIELD_VALUE for async generators.
* Split SEND into SEND; YIELD_VALUE.
* Document new opcodes.
2022-01-24 11:08:53 +00:00
Mark Shannon
b04dfbbe4b
bpo-46409: Make generators in bytecode (GH-30633)
...
* Add RETURN_GENERATOR and JUMP_NO_INTERRUPT opcodes.
* Trim frame and generator by word each.
* Minor refactor of frame.c
* Update test.test_sys to account for smaller frames.
* Treat generator functions as normal functions when evaluating and specializing.
2022-01-20 11:46:39 +00:00
zq1997
c118c2455c
bpo-46161: Fix bug in starunpack_helper in compile.c (GH-30235)
2022-01-17 17:45:44 +00:00
Irit Katriel
9c2ebb906d
bpo-46344: Fix trace bug in else of try and try-star blocks (GH-30544)
2022-01-13 12:34:38 +00:00
Mark Shannon
bd04fac7eb
bpo-46331: Do not set line number of instruction storing doc-string. (GH-30518)
2022-01-11 11:28:30 +00:00
Mark Shannon
ec0c392f34
bpo-46314: Remove extra RESUME when compiling a lamdba. (GH-30513)
2022-01-10 12:29:02 +00:00
Irit Katriel
16dfabf75c
bpo-46286: use the new POP_JUMP_IF_NOT_NONE opcode to simplify except* (GH-30439)
...
Automerge-Triggered-By: GH:iritkatriel
2022-01-06 11:43:16 -08:00
Mark Shannon
e028ae99ec
bpo-45923: Handle call events in bytecode (GH-30364)
...
* Add a RESUME instruction to handle "call" events.
2022-01-06 13:09:25 +00:00
penguin_wwy
3db762db72
bpo-46031: add POP_JUMP_IF_NOT_NONE and POP_JUMP_IF_NONE (GH-30019)
2022-01-06 11:38:35 +00:00
Brandt Bucher
31e43cbe5f
bpo-46009: Remove GEN_START (GH-30367)
2022-01-04 11:38:32 -08:00
Irit Katriel
a94461d718
bpo-46202: Remove opcode POP_EXCEPT_AND_RERAISE (GH-30302)
...
* bpo-46202: remove opcode POP_EXCEPT_AND_RERAISE
* do not assume that an exception group is truthy
2022-01-04 10:37:12 +00:00
Irit Katriel
65e7c1f90e
bpo-46219, 46221: simplify except* implementation following exc_info changes. Move helpers to exceptions.c. Do not assume that exception groups are truthy. (GH-30289)
2022-01-02 23:22:42 +00:00
Irit Katriel
396b58345f
bpo-45711: Remove type and traceback from exc_info (GH-30122)
...
* Do not PUSH/POP traceback or type to the stack as part of exc_info
* Remove exc_traceback and exc_type from _PyErr_StackItem
* Add to what's new, because this change breaks things like Cython
2021-12-17 14:46:22 +00:00
Mark Shannon
0b50a4f0cd
bpo-46039: Split yield from in two (GH-30035)
...
* Split YIELD_FROM opcode into SEND and JUMP_ABSOLUTE.
* Remove YIELD_FROM opcode.
2021-12-15 10:30:09 +00:00
Mark Shannon
9f8f45144b
bpo-44525: Split calls into PRECALL and CALL (GH-30011)
...
* Add 3 new opcodes for calls: PRECALL_METHOD, CALL_NO_KW, CALL_KW.
* Update specialization to handle new CALL opcodes.
* Specialize call to method descriptors.
* Remove old CALL opcodes: CALL_FUNCTION, CALL_METHOD, CALL_METHOD_KW, CALL_FUNCTION_KW.
2021-12-14 18:22:44 +00:00