summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
Commit message (Collapse)AuthorAgeFilesLines
* [3.12] gh-130740: Move some `stdbool.h` includes after `Python.h` (#130738) ↵Bénédikt Tran2025-03-041-2/+2
| | | | | | | | | | | | | | | | (#130757) gh-130740: Move some `stdbool.h` includes after `Python.h` (#130738) Move some `#include <stdbool.h>` after `#include "Python.h"` when `pyconfig.h` is not included first and when we are in a platform-agnostic context. This is to avoid having features defined by `stdbool.h` before those decided by `Python.h` (this caused some build failures when compiling CPython with `zig cc`). (cherry-picked from commit 214562ed4ddc248b007f718ed92ebcc0c3669611) --------- Co-authored-by: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
* [3.12] Fix possible null pointer dereference of freevars in ↵Valery Fedorenko2024-11-061-1/+1
| | | | | | | | | | | | _PyCompile_LookupArg (gh-126238) (#126474) [3.12] gh-126238: Fix possible null pointer dereference of freevars in _PyCompile_LookupArg (GH-126239) * Replace Py_DECREF by Py_XDECREF (cherry picked from commit 8525c9375f25e6ec0c0b5dfcab464703f6e78082) Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
* [3.12] gh-125832: Clarify comment for inlined comprehensions as per P… ↵Donghee Na2024-11-031-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | (gh-126345) * [3.12] gh-125832: Clarify comment for inlined comprehensions as per PEP-709 (gh-126322) * Fix comprehensions comment to inlined by pep 709 * Update spacing Co-authored-by: RUANG (James Roy) <longjinyii@outlook.com> * Add reference to PEP 709 --------- Co-authored-by: Carol Willing <carolcode@willingconsulting.com> Co-authored-by: RUANG (James Roy) <longjinyii@outlook.com> * Add space --------- Co-authored-by: rimchoi <hyerimc858@gmail.com> Co-authored-by: Carol Willing <carolcode@willingconsulting.com> Co-authored-by: RUANG (James Roy) <longjinyii@outlook.com>
* [3.12] gh-113993: Make interned strings mortal (GH-120520, GH-121364, ↵Petr Viktorin2024-09-271-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GH-121903, GH-122303) (#123065) This backports several PRs for gh-113993, making interned strings mortal so they can be garbage-collected when no longer needed. * Allow interned strings to be mortal, and fix related issues (GH-120520) * Add an InternalDocs file describing how interning should work and how to use it. * Add internal functions to *explicitly* request what kind of interning is done: - `_PyUnicode_InternMortal` - `_PyUnicode_InternImmortal` - `_PyUnicode_InternStatic` * Switch uses of `PyUnicode_InternInPlace` to those. * Disallow using `_Py_SetImmortal` on strings directly. You should use `_PyUnicode_InternImmortal` instead: - Strings should be interned before immortalization, otherwise you're possibly interning a immortalizing copy. - `_Py_SetImmortal` doesn't handle the `SSTATE_INTERNED_MORTAL` to `SSTATE_INTERNED_IMMORTAL` update, and those flags can't be changed in backports, as they are now part of public API and version-specific ABI. * Add private `_only_immortal` argument for `sys.getunicodeinternedsize`, used in refleak test machinery. Make sure the statically allocated string singletons are unique. This means these sets are now disjoint: - `_Py_ID` - `_Py_STR` (including the empty string) - one-character latin-1 singletons Now, when you intern a singleton, that exact singleton will be interned. * Add a `_Py_LATIN1_CHR` macro, use it instead of `_Py_ID`/`_Py_STR` for one-character latin-1 singletons everywhere (including Clinic). * Intern `_Py_STR` singletons at startup. * Beef up the tests. Cover internal details (marked with `@cpython_only`). * Add lots of assertions * Don't immortalize in PyUnicode_InternInPlace; keep immortalizing in other API (GH-121364) * Switch PyUnicode_InternInPlace to _PyUnicode_InternMortal, clarify docs * Document immortality in some functions that take `const char *` This is PyUnicode_InternFromString; PyDict_SetItemString, PyObject_SetAttrString; PyObject_DelAttrString; PyUnicode_InternFromString; and the PyModule_Add convenience functions. Always point out a non-immortalizing alternative. * Don't immortalize user-provided attr names in _ctypes * Immortalize names in code objects to avoid crash (GH-121903) * Intern latin-1 one-byte strings at startup (GH-122303) There are some 3.12-specific changes, mainly to allow statically allocated strings in deepfreeze. (In 3.13, deepfreeze switched to the general `_Py_ID`/`_Py_STR`.) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
* [3.12] gh-98442: fix locations of with statement's cleanup instructions ↵Miss Islington (bot)2024-09-151-1/+3
| | | | | | | | | | | (GH-120763) (#120787) gh-98442: fix locations of with statement's cleanup instructions (GH-120763) (cherry picked from commit 55596ae0446e40f47e2a28b8897fe9530c32a19a) gh-98442: fix location of with statement's cleanup instructions Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
* [3.12] gh-93691: fix too broad source locations of with-statement ↵Miss Islington (bot)2024-09-021-3/+2
| | | | | | | | instructions (GH-120125) (#123605) gh-93691: fix too broad source locations of with-statement instructions (GH-120125) (cherry picked from commit eca3f7762c23b22a73a5e0b09520748c88aab4a0) Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
* [3.12] gh-123142: fix too wide source location of GET_ITER/GET_AITER ↵Irit Katriel2024-08-281-8/+7
| | | | | (GH-123420). (#123436) (cherry picked from commit 61bef6245c4a32bf430d684ede8603f423d63284)
* [3.12] gh-123142: Fix too wide source locations in tracebacks of exceptions ↵Irit Katriel2024-08-221-2/+3
| | | | | from broken iterables in comprehensions (GH-123173). (#123210) (cherry picked from commit ec89620e5e147ba028a46dd695ef073a72000b84)
* [3.12] gh-121657: Display correct error message for yield from outsid… ↵Kirill Podoprigora2024-07-151-1/+1
| | | | | | | | (GH-121769) (cherry picked from commit 178e44de8f023be7a5dc400044ab61983b191f24) Co-authored-by: Gregor <36135323+gege-hoho@users.noreply.github.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
* [3.12] gh-120722: Set position on RETURN_VALUE in lambda (GH-120724) (#120739)Jelle Zijlstra2024-06-191-1/+1
| | | (cherry picked from commit d8f27cb1141fd3575de816438ed80a916c0560ed)
* [3.12] gh-93691: fix too broad source locations of for statement iterators ↵Irit Katriel2024-06-131-0/+7
| | | | | | (GH-120330 (#120405) [3.12] gh-93691: fix too broad source locations of for statement iterators (GH-120330). (cherry picked from commit 97b69db167be28a33688db436551a6c3c3ea4662)
* [3.12] gh-120155: Fix optimize_and_assemble_code_unit() error handling (#120231)Victor Stinner2024-06-071-1/+1
| | | | | | | | | | | | | | | | | | gh-120155: Fix optimize_and_assemble_code_unit() error handling Don't use 'g' before it's being initialized: don't use the 'error' label if consts_dict_keys_inorder() failed. Fix the Coverity issue: Error: UNINIT (CWE-457): Python-3.12.2/Python/compile.c:7670:5: skipped_decl: Jumping over declaration of ""g"". Python-3.12.2/Python/compile.c:7714:5: uninit_use_in_call: Using uninitialized value ""g.g_block_list"" when calling ""_PyCfgBuilder_Fini"". Python-3.12.2/Python/compile.c:7714:5: uninit_use_in_call: Using uninitialized value ""g.g_entryblock"" when calling ""_PyCfgBuilder_Fini"". 7712| Py_XDECREF(consts); 7713| instr_sequence_fini(&optimized_instrs); 7714|-> _PyCfgBuilder_Fini(&g); 7715| return co; 7716| }
* [3.12] gh-119311: Fix name mangling with PEP 695 generic classes (#119464) ↵Jelle Zijlstra2024-06-041-6/+6
| | | | | | | | | | (#119644) * [3.12] gh-119311: Fix name mangling with PEP 695 generic classes (#119464) Fixes #119311. Fixes #119395. (cherry picked from commit a9a74da4a0ca0645f049e67b6434a95e30592c32)
* [3.12] gh-118513: Fix sibling comprehensions with a name bound in one and ↵Miss Islington (bot)2024-05-031-39/+42
| | | | | | | | | | global in the other (GH-118526) (#118548) gh-118513: Fix sibling comprehensions with a name bound in one and global in the other (GH-118526) (cherry picked from commit c8deb1e4b495bf97ab00c710dfd63f227e1fb645) Co-authored-by: Carl Meyer <carl@oddbird.net> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
* [3.12] gh-116767: fix crash on 'async with' with many context managers ↵Irit Katriel2024-05-011-2/+16
| | | | | | | | | | | | (GH-118348) (#118477) gh-116767: fix crash on 'async with' with many context managers (GH-118348) Account for `add_stopiteration_handler` pushing a block for `async with`. To allow generator functions that previously almost hit the `CO_MAXBLOCKS` limit by nesting non-async blocks, the limit is increased by 1. This increase allows one more block in non-generator functions. (cherry picked from commit c1bf4874c1e9db2beda1d62c8c241229783c789b)
* [3.12] gh-116034: fix location info on the error of a failed assertion (#116054)Irit Katriel2024-02-291-1/+1
|
* [3.12] gh-105658: fix excess trace events for except block ending with a ↵Irit Katriel2023-09-141-14/+2
| | | | | | | conditional block (#109384) (#109411) gh-105658: fix excess trace events for except block ending with a conditional block (#109384) (cherry picked from commit 4a54074a0f5579d417445ec28427cd0ed5aa01f4)
* [3.12] gh-109195: fix source location for super load before LOAD_SUPER_ATTR ↵Miss Islington (bot)2023-09-121-1/+1
| | | | | | | | (GH-109289) (#109291) gh-109195: fix source location for super load before LOAD_SUPER_ATTR (GH-109289) (cherry picked from commit ceeb4173aee7b835f553a8286feaa48b98c16124) Co-authored-by: Carl Meyer <carl@oddbird.net>
* [3.12] gh-108654: restore comprehension locals before handling exception ↵Miss Islington (bot)2023-08-311-14/+53
| | | | | | | | | (GH-108659) (#108700) gh-108654: restore comprehension locals before handling exception (GH-108659) (cherry picked from commit d52c4482a82f3f98f1a78efa948144a1fe3c52b2) Co-authored-by: Carl Meyer <carl@oddbird.net> Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
* [3.12] gh-105908: fix `barry_as_FLUFL` future import (GH-105909) (#105930)Miss Islington (bot)2023-06-201-6/+10
| | | | | (cherry picked from commit 28187a9c4f95affe50fd37e0db0db177e2b9c2e9) Co-authored-by: Crowthebird <78076854+thatbirdguythatuknownot@users.noreply.github.com>
* [3.12] gh-105375: Improve error handling in compiler_enter_scope() ↵Miss Islington (bot)2023-06-091-1/+5
| | | | | | | (GH-105494) (#105581) (cherry picked from commit 6c832ddcf28187f86100c790afb16a0223d945d0) Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
* [3.12] gh-105164: Detect annotations inside match blocks (GH-105177) (#105313)Miss Islington (bot)2023-06-051-0/+10
| | | | | (cherry picked from commit 69d1245685cf95ddc678633e978a56673da64865) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* gh-104656: Rename typeparams AST node to type_params (#104657)Jelle Zijlstra2023-05-221-36/+36
|
* gh-104686: Fix tracing for decorated classes (#104708)Jelle Zijlstra2023-05-211-0/+4
|
* gh-104619: never leak comprehension locals to outer locals() (#104637)Carl Meyer2023-05-191-21/+19
|
* gh-104602: ensure all cellvars are known up front (#104603)Carl Meyer2023-05-191-1/+1
| | | Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* gh-104615: don't make unsafe swaps in apply_static_swaps (#104620)Carl Meyer2023-05-181-2/+2
|
* gh-104374: Remove access to class scopes for inlined comprehensions (#104528)Jelle Zijlstra2023-05-181-5/+15
| | | Co-authored-by: Carl Meyer <carl@oddbird.net>
* gh-103865: add monitoring support to LOAD_SUPER_ATTR (#103866)Carl Meyer2023-05-161-0/+4
|
* gh-103763: Implement PEP 695 (#103764)Jelle Zijlstra2023-05-161-103/+520
| | | | | | | | | | | | | | This implements PEP 695, Type Parameter Syntax. It adds support for: - Generic functions (def func[T](): ...) - Generic classes (class X[T](): ...) - Type aliases (type X = ...) - New scoping when the new syntax is used within a class body - Compiler and interpreter changes to support the new syntax and scoping rules Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Co-authored-by: Eric Traut <eric@traut.com> Co-authored-by: Larry Hastings <larry@hastings.org> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-104482: Fix error handling bugs in ast.c (#104483)Irit Katriel2023-05-151-0/+1
|
* gh-104377: fix cell in comprehension that is free in outer scope (#104394)Carl Meyer2023-05-111-3/+12
|
* gh-97933: (PEP 709) inline list/dict/set comprehensions (#101441)Carl Meyer2023-05-091-75/+288
| | | | Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
* gh-104240: return code unit metadata from codegen (#104300)Irit Katriel2023-05-091-3/+47
|
* gh-104240: make _PyCompile_CodeGen support different compilation modes (#104241)Irit Katriel2023-05-071-2/+6
|
* gh-87092: Expose assembler to unit tests (#103988)Irit Katriel2023-05-011-33/+88
|
* gh-87092: change assembler to use instruction sequence instead of CFG (#103933)Irit Katriel2023-04-291-13/+27
|
* gh-87729: add LOAD_SUPER_ATTR instruction for faster super() (#103497)Carl Meyer2023-04-241-3/+125
| | | | | This speeds up `super()` (by around 85%, for a simple one-level `super().meth()` microbenchmark) by avoiding allocation of a new single-use `super()` object on each use.
* gh-103492: Clarify SyntaxWarning with literal comparison (#103493)Shantanu2023-04-241-4/+12
|
* gh-101517: fix line number propagation in code generated for except* (#103550)Irit Katriel2023-04-241-12/+20
|
* gh-87092: fix a few cases of incorrect error handling in compiler (#103456)Irit Katriel2023-04-241-9/+23
| | | gh-87092: fix a few cases of incorrect error handling
* GH-103082: Implementation of PEP 669: Low Impact Monitoring for CPython ↵Mark Shannon2023-04-121-2/+1
| | | | | | | | | | (GH-103083) * The majority of the monitoring code is in instrumentation.c * The new instrumentation bytecodes are in bytecodes.c * legacy_tracing.c adapts the new API to the old sys.setrace and sys.setprofile APIs
* gh-87092: fix refleak in peepholer test harness (#103448)Irit Katriel2023-04-111-4/+0
|
* gh-87092: move assembler related code from compile.c to assemble.c (#103277)Irit Katriel2023-04-111-713/+160
|
* gh-87092: move CFG related code from compile.c to flowgraph.c (#103021)Irit Katriel2023-03-311-2391/+76
|
* GH-100982: Break up COMPARE_AND_BRANCH (GH-102801)Brandt Bucher2023-03-231-1/+10
|
* gh-102859: Remove JUMP_IF_FALSE_OR_POP and JUMP_IF_TRUE_OR_POP (#102870)Irit Katriel2023-03-221-115/+77
|
* gh-102860: improve performance of compiler's instr_sequence_to_cfg (#102861)Irit Katriel2023-03-211-6/+44
|
* gh-87092: refactor assemble() to a number of separate functions, which do ↵Irit Katriel2023-03-131-244/+290
| | | | not need the compiler struct (#102562)
* gh-87092: compiler's CFG construction moved to after codegen stage (#102320)Irit Katriel2023-03-071-184/+336
|