summaryrefslogtreecommitdiff
path: root/Python/compile.c
AgeCommit message (Collapse)AuthorLines
2022-02-08bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized ↵Eric Snow-86/+20
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-07bpo-46670: Remove unused macros in the Python directory (GH-31192)Victor Stinner-13/+0
2022-02-03bpo-45773: Remove invalid peephole optimizations (GH-31066)Brandt Bucher-2/+0
2022-02-01bpo-46528: Simplify BUILD_TUPLE/UNPACK_SEQUENCE folding (GH-31039)Brandt Bucher-14/+7
2022-01-28bpo-46329: Split calls into precall and call instructions. (GH-30855)Mark Shannon-26/+39
* 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-27bpo-46458: emit code for else of a try block immediately after the try body ↵Irit Katriel-6/+7
(GH-30751)
2022-01-26bpo-46528: Simplify the VM's stack manipulations (GH-30902)Brandt Bucher-105/+161
2022-01-24bpo-43683: Streamline YIELD_VALUE and SEND (GH-30723)Mark Shannon-6/+19
* Split YIELD_VALUE into ASYNC_GEN_WRAP; YIELD_VALUE for async generators. * Split SEND into SEND; YIELD_VALUE. * Document new opcodes.
2022-01-20bpo-46409: Make generators in bytecode (GH-30633)Mark Shannon-20/+36
* 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-17bpo-46161: Fix bug in starunpack_helper in compile.c (GH-30235)zq1997-1/+4
2022-01-13bpo-46344: Fix trace bug in else of try and try-star blocks (GH-30544)Irit Katriel-2/+0
2022-01-11bpo-46331: Do not set line number of instruction storing doc-string. (GH-30518)Mark Shannon-0/+1
2022-01-10bpo-46314: Remove extra RESUME when compiling a lamdba. (GH-30513)Mark Shannon-144/+142
2022-01-06bpo-46286: use the new POP_JUMP_IF_NOT_NONE opcode to simplify except* ↵Irit Katriel-6/+2
(GH-30439) Automerge-Triggered-By: GH:iritkatriel
2022-01-06bpo-45923: Handle call events in bytecode (GH-30364)Mark Shannon-27/+43
* Add a RESUME instruction to handle "call" events.
2022-01-06bpo-46031: add POP_JUMP_IF_NOT_NONE and POP_JUMP_IF_NONE (GH-30019)penguin_wwy-0/+27
2022-01-04bpo-46009: Remove GEN_START (GH-30367)Brandt Bucher-17/+4
2022-01-04bpo-46202: Remove opcode POP_EXCEPT_AND_RERAISE (GH-30302)Irit Katriel-11/+26
* bpo-46202: remove opcode POP_EXCEPT_AND_RERAISE * do not assume that an exception group is truthy
2022-01-02bpo-46219, 46221: simplify except* implementation following exc_info ↵Irit Katriel-9/+16
changes. Move helpers to exceptions.c. Do not assume that exception groups are truthy. (GH-30289)
2021-12-17bpo-45711: Remove type and traceback from exc_info (GH-30122)Irit Katriel-92/+64
* 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-15bpo-46039: Split yield from in two (GH-30035)Mark Shannon-16/+39
* Split YIELD_FROM opcode into SEND and JUMP_ABSOLUTE. * Remove YIELD_FROM opcode.
2021-12-14bpo-44525: Split calls into PRECALL and CALL (GH-30011)Mark Shannon-15/+16
* 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-14bpo-45292: [PEP-654] add except* (GH-29581)Irit Katriel-1/+338
2021-12-11bpo-37971: fix the position of decorator application (GH-30027)Carl Friedrich Bolz-Tereick-8/+25
The line numbers of actually calling the decorator functions of functions and classes was wrong (as opposed to loading them, were they have been correct previously too). Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2021-12-05Delete orphaned comment (#29917)Guido van Rossum-5/+0
(The function this described was deleted by PR #23743, the comment was accidentally retained.)
2021-11-23bpo-44525: Copy free variables in bytecode to allow calls to inner functions ↵Mark Shannon-2/+19
to be specialized (GH-29595) * Make internal APIs that take PyFrameConstructor take a PyFunctionObject instead. * Add reference to function to frame, borrow references to builtins and globals. * Add COPY_FREE_VARS instruction to allow specialization of calls to inner functions.
2021-11-19Fix link to exception handling notes (GH-29617)Irit Katriel-1/+1
2021-11-11bpo-45773: Stop "optimizing" certain jump patterns (GH-29505)Brandt Bucher-76/+41
2021-11-10bpo-45636: Merge all numeric operators (GH-29482)Brandt Bucher-106/+59
2021-11-10bpo-45711: remove unnecessary DUP_TOP and POP in exception handling (GH-29495)Irit Katriel-6/+4
2021-10-27bpo-44511: Improve the bytecode for class and mapping patterns (GH-26922)Brandt Bucher-29/+44
* Refactor mapping patterns and speed up class patterns. * Simplify MATCH_KEYS and MATCH_CLASS. * Add COPY opcode.
2021-10-06Fix typos in the Python directory (GH-28767)Christian Clauss-2/+2
2021-10-06Normalize jumps in compiler. All forward jumps to use JUMP_FORWARD. (GH-28755)Mark Shannon-0/+23
2021-10-04bpo-45355: More use of sizeof(_Py_CODEUNIT) (GH-28720)Serhiy Storchaka-1/+1
2021-09-14bpo-45152: Add HAS_CONST macro and get_const_value() function and use… ↵Irit Katriel-7/+39
(#28262)
2021-09-02bpo-45056: Remove trailing unused constants from co_consts (GH-28109)Inada Naoki-0/+33
2021-08-31bpo-45039: Consistently use ADDOP_LOAD_CONST in compiler rather than ↵Irit Katriel-2/+4
ADDOP_O(c, LOAD_CONST,...) (GH-28015)
2021-08-25bpo-45000: Raise SyntaxError when try to delete __debug__ (GH-27947)Dong-hee Na-0/+4
Automerge-Triggered-By: GH:pablogsal
2021-08-09Remove unused variable. (GH-27677)Mark Shannon-3/+0
2021-08-09bpo-44840: Compiler: Move duplication of exit blocks with no line numbers to ↵Mark Shannon-16/+25
after CFG optimization. (GH-27656)
2021-07-25bpo-44600: Fix line numbers for pattern matching cleanup code (GH-27346)Charles Burkland-4/+12
2021-07-15bpo-44626: Merge basic blocks earlier to enable better handling of exit ↵Mark Shannon-16/+48
blocks without line numbers (GH-27138)
2021-07-15bpo-44622: Set line number of END_ASYNC_FOR to match that of iterator. ↵Mark Shannon-1/+3
(GH-27160)
2021-07-14bpo-44589: raise a SyntaxError when mapping patterns have duplicate literal ↵Jack DeVries-4/+41
keys (GH-27131)
2021-07-14bpo-44616: Mark all clean up instructions at end of named exception block as ↵Mark Shannon-3/+2
artificial (GH-27109)
2021-07-13bpo-33346: Allow async comprehensions inside implicit async comprehensions ↵Serhiy Storchaka-6/+8
(GH-6766) Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
2021-07-07bpo-44530: Add co_qualname field to PyCodeObject (GH-26941)Gabriele N. Tornetta-4/+2
2021-07-02bpo-43950: optimize column table assembling with pre-sizing object (GH-26997)Batuhan Taskaya-6/+13
The new resizing system works like this; ``` $ cat t.py a + a + a + b + c + a + a + a + b + c + a + a + a + b + c + a + a + a + b + c [repeated 99 more times] $ ./python t.py RESIZE: prev len = 32, new len = 66 FINAL SIZE: 56 ----------------------------------------------------- RESIZE: prev len = 32, new len = 66 RESIZE: prev len = 66, new len = 134 RESIZE: prev len = 134, new len = 270 RESIZE: prev len = 270, new len = 542 RESIZE: prev len = 542, new len = 1086 RESIZE: prev len = 1086, new len = 2174 RESIZE: prev len = 2174, new len = 4350 RESIZE: prev len = 4350, new len = 8702 FINAL SIZE: 8004 ``` So now we do considerably lower number of `_PyBytes_Resize` calls. Automerge-Triggered-By: GH:isidentical
2021-07-02bpo-43950: Add code.co_positions (PEP 657) (GH-26955)Pablo Galindo-63/+208
This PR is part of PEP 657 and augments the compiler to emit ending line numbers as well as starting and ending columns from the AST into compiled code objects. This allows bytecodes to be correlated to the exact source code ranges that generated them. This information is made available through the following public APIs: * The `co_positions` method on code objects. * The C API function `PyCode_Addr2Location`. Co-authored-by: Batuhan Taskaya <isidentical@gmail.com> Co-authored-by: Ammar Askar <ammar@ammaraskar.com>
2021-06-30bpo-44313: generate LOAD_ATTR/CALL_FUNCTION for top-level imported objects ↵Batuhan Taskaya-0/+23
(GH-26677)