Irit Katriel
67a05de17c
gh-121272: move async for/with validation from compiler to symtable ( #121361 )
2024-07-04 14:47:21 +01:00
Irit Katriel
93156880ef
gh-121272: set ste_coroutine during symtable construction ( #121297 )
...
compiler no longer modifies the symtable after this.
2024-07-03 10:18:34 +01:00
Irit Katriel
1ac273224a
gh-121272: move __future__ import validation from compiler to symtable ( #121273 )
2024-07-02 16:22:08 +00:00
Victor Stinner
12af8ec864
gh-121040: Use __attribute__((fallthrough)) ( #121044 )
...
Fix warnings when using -Wimplicit-fallthrough compiler flag.
Annotate explicitly "fall through" switch cases with a new
_Py_FALLTHROUGH macro which uses __attribute__((fallthrough)) if
available. Replace "fall through" comments with _Py_FALLTHROUGH.
Add _Py__has_attribute() macro. No longer define __has_attribute()
macro if it's not defined. Move also _Py__has_builtin() at the top
of pyport.h.
Co-Authored-By: Nikita Sobolev <mail@sobolevn.me>
2024-06-27 09:58:44 +00:00
Steve Dower
e731554337
Fixes loop variables to be the same types as their limit (GH-120958)
2024-06-24 17:11:47 +01:00
Petr Viktorin
6f1d448bc1
gh-113993: 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.
* For free-threaded builds, intern `_Py_LATIN1_CHR` singletons at startup.
* Beef up the tests. Cover internal details (marked with `@cpython_only`).
* Add lots of assertions
Co-Authored-By: Eric Snow <ericsnowcurrently@gmail.com>
2024-06-21 17:19:31 +02:00
Irit Katriel
55596ae044
gh-98442: fix locations of with statement's cleanup instructions ( #120763 )
...
gh-98442: fix location of with statement's cleanup instructions
2024-06-20 09:32:06 +01:00
Irit Katriel
eaaf6995a8
gh-120733: rename internal compiler functions according to naming convention ( #120734 )
2024-06-19 14:19:59 +01:00
Jelle Zijlstra
d8f27cb114
gh-120722: Set position on RETURN_VALUE in lambda ( #120724 )
2024-06-19 05:56:36 -07:00
Mark Shannon
9cefcc0ee7
GH-120507: Lower the `BEFORE_WITH` and `BEFORE_ASYNC_WITH` instructions. ( #120640 )
...
* Remove BEFORE_WITH and BEFORE_ASYNC_WITH instructions.
* Add LOAD_SPECIAL instruction
* Reimplement `with` and `async with` statements using LOAD_SPECIAL
2024-06-18 12:17:46 +01:00
Irit Katriel
97b69db167
gh-93691: fix too broad source locations of for statement iterators ( #120330 )
2024-06-12 12:53:19 +01:00
Jelle Zijlstra
9b8611eeea
gh-119180: PEP 649 compiler changes ( #119361 )
2024-06-11 13:06:49 +00:00
Irit Katriel
eca3f7762c
gh-93691: fix too broad source locations of with-statement instructions ( #120125 )
2024-06-07 14:06:24 +01:00
Irit Katriel
13a5fdc72f
gh-119744: move a few functions from compile.c to flowgraph.c ( #119745 )
2024-05-30 21:55:06 +01:00
Irit Katriel
c1e9647107
gh-119689: generate stack effect metadata for pseudo instructions ( #119691 )
2024-05-29 09:47:56 +00:00
Irit Katriel
ae9140f32a
gh-119676: remove several pseudo instructions which are use only in codegen ( #119677 )
2024-05-28 19:05:38 +00:00
Jelle Zijlstra
a9a74da4a0
gh-119311: Fix name mangling with PEP 695 generic classes ( #119464 )
...
Fixes #119311 . Fixes #119395 .
2024-05-27 19:50:38 -07:00
Jelle Zijlstra
98e855fcc1
gh-119180: Add LOAD_COMMON_CONSTANT opcode ( #119321 )
...
The PEP 649 implementation will require a way to load NotImplementedError
from the bytecode. @markshannon suggested implementing this by converting
LOAD_ASSERTION_ERROR into a more general mechanism for loading constants.
This PR adds this new opcode. I will work on the rest of the implementation
of the PEP separately.
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2024-05-22 00:46:39 +00:00
Serhiy Storchaka
153b3f7530
gh-118465: Add __firstlineno__ attribute to class (GH-118475)
...
It is set by compiler with the line number of the first line of
the class definition.
2024-05-06 12:02:37 +03:00
Carl Meyer
c8deb1e4b4
gh-118513: Fix sibling comprehensions with a name bound in one and global in the other ( #118526 )
...
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
2024-05-03 14:05:19 +00:00
Jelle Zijlstra
ca269e58c2
gh-116126: Implement PEP 696 ( #116129 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
2024-05-03 06:17:32 -07:00
Crowthebird
7c97dc8c95
gh-118216: Don't consider dotted `__future__` imports ( #118267 )
2024-05-02 06:32:20 -07:00
Irit Katriel
c1bf4874c1
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.
2024-05-01 13:01:16 +02:00
Irit Katriel
0aa0fc3d3c
gh-117901: Add option for compiler's codegen to save nested instruction sequences for introspection ( #118007 )
2024-04-24 09:46:17 +00:00
Irit Katriel
c179c0e6cb
gh-117680: make _PyInstructionSequence a PyObject and use it in tests ( #117629 )
2024-04-17 16:42:04 +01:00
Irit Katriel
04697bcfaf
gh-117494: extract the Instruction Sequence data structure into a separate file ( #117496 )
2024-04-04 15:47:26 +00:00
Irit Katriel
1d5479b236
gh-117411: move PyFutureFeatures to pycore_symtable.h and make it private ( #117412 )
2024-04-02 10:34:49 +00:00
Irit Katriel
262fb911ab
gh-117288: Allocate fewer label IDs in _PyCfg_ToInstructionSequence ( #117290 )
2024-03-27 17:38:19 +00:00
Irit Katriel
79be75735c
gh-115775: Compiler adds __static_attributes__ field to classes ( #115913 )
2024-03-26 15:18:17 +00:00
Bogdan Romanyuk
a8e93d3dca
gh-115756: make PyCode_GetFirstFree an unstable API (GH-115781)
2024-03-19 09:20:38 +00:00
Serhiy Storchaka
acd6f41ecf
gh-111789: Use PyDict_GetItemRef() in Python/compile.c (GH-112083)
...
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-02-23 12:35:27 +01:00
Irit Katriel
3a9e67a9fd
gh-115376: fix segfault in _testinternalcapi.compiler_codegen on bad input ( #115379 )
2024-02-15 14:32:21 +00:00
Irit Katriel
732faf17a6
gh-115347: avoid emitting redundant NOP for the docstring with -OO ( #115494 )
2024-02-15 14:20:19 +00:00
Sam Gross
ef3ceab09d
gh-112066: Use `PyDict_SetDefaultRef` in place of `PyDict_SetDefault`. ( #112211 )
...
This changes a number of internal usages of `PyDict_SetDefault` to use `PyDict_SetDefaultRef`.
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2024-02-07 13:43:18 -05:00
Erlend E. Aasland
8612230c1c
gh-114569: Use PyMem_* APIs for non-PyObjects in compiler ( #114587 )
2024-01-30 00:04:34 +01:00
Mark Shannon
981d172f7f
GH-112354: `END_FOR` instruction to only pop one value. (GH-114247)
...
* Compiler emits END_FOR; POP_TOP instead of END_FOR. To support tier 2 side exits in loops.
2024-01-24 15:10:17 +00:00
Irit Katriel
d36a365118
gh-107901: synthetic jumps which are not at end of loop no longer check the eval breaker ( #113721 )
2024-01-06 14:20:08 +00:00
Mark Shannon
e96f26083b
GH-111485: Generate instruction and uop metadata (GH-113287)
2023-12-20 14:27:25 +00:00
Irit Katriel
fb202af447
gh-99606: Make code generated for an empty f-string identical to that of a normal empty string ( #112407 )
2023-11-26 17:13:57 +00:00
Irit Katriel
36aab34fab
gh-107149: make new opcode util functions private rather than public and unstable ( #112042 )
2023-11-14 00:31:02 +00:00
Irit Katriel
d49aba5a7a
gh-111354: Simplify _PyGen_yf by moving some of its work to the compiler and frame state ( #111648 )
2023-11-03 10:01:36 +00:00
Irit Katriel
52cc4af6ae
gh-111354: simplify detection of RESUME after YIELD_VALUE at except-depth 1 ( #111459 )
2023-11-02 10:18:43 +00:00
Serhiy Storchaka
970e719a7a
gh-108082: Use PyErr_FormatUnraisable() (GH-111580)
...
Replace most of calls of _PyErr_WriteUnraisableMsg() and some
calls of PyErr_WriteUnraisable(NULL) with PyErr_FormatUnraisable().
Co-authored-by: Victor Stinner <vstinner@python.org>
2023-11-02 09:16:34 +00:00
Irit Katriel
a0c414c35d
gh-111354: define names for RESUME oparg values ( #111365 )
2023-10-26 16:30:18 +01:00
Irit Katriel
4a54074a0f
gh-105658: fix excess trace events for except block ending with a conditional block ( #109384 )
2023-09-14 17:06:08 +01:00
Brandt Bucher
22e65eecaa
GH-105848: Replace KW_NAMES + CALL with LOAD_CONST + CALL_KW (GH-109300)
2023-09-13 10:25:45 -07:00
Carl Meyer
ceeb4173ae
gh-109195: fix source location for super load before LOAD_SUPER_ATTR ( #109289 )
2023-09-11 17:35:49 -06:00
Victor Stinner
676593859e
gh-106320: Remove private _PyErr_WriteUnraisableMsg() ( #108863 )
...
Move the private _PyErr_WriteUnraisableMsg() functions to the
internal C API (pycore_pyerrors.h).
Move write_unraisable_exc() from _testcapi to _testinternalcapi.
2023-09-05 01:54:55 +02:00
Carl Meyer
d52c4482a8
gh-108654: restore comprehension locals before handling exception ( #108659 )
...
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
2023-08-30 17:50:50 -06:00
Irit Katriel
72119d16a5
gh-105481: remove regen-opcode. Generated _PyOpcode_Caches in regen-cases. ( #108367 )
2023-08-23 18:39:00 +01:00
Victor Stinner
f5559f38d9
gh-108308: Replace PyDict_GetItem() with PyDict_GetItemRef() ( #108309 )
...
Replace PyDict_GetItem() calls with PyDict_GetItemRef()
or PyDict_GetItemWithError() to handle errors.
* Replace PyLong_AS_LONG() with _PyLong_AsInt()
and check for errors.
* Check for PyDict_Contains() error.
* pycore_init_builtins() checks for _PyType_Lookup() failure.
2023-08-23 17:40:26 +02:00
Irit Katriel
2dfbd4f36d
gh-108113: Make it possible to optimize an AST ( #108282 )
2023-08-23 09:01:17 +01:00
Nikita Sobolev
bdd8ddfda1
gh-105724: Add location information to `assert` errors (GH-105935)
2023-08-16 11:35:38 +01:00
Irit Katriel
bafedfbebd
gh-106149: move CFG and basicblock definitions into flowgraph.c, use them as opaque types in compile.c ( #107639 )
2023-08-10 13:03:47 +01:00
Brandt Bucher
a9caf9cf90
GH-105848: Simplify the arrangement of CALL's stack (GH-107788)
2023-08-09 18:19:39 +00:00
Irit Katriel
507d8bc39a
gh-106149: fix comment on stackdepth of generators ( #107321 )
2023-07-26 22:31:47 +00:00
Irit Katriel
b0202a4e5d
gh-106149: Simplify stack depth calculation. Replace asserts by exceptions. ( #107255 )
2023-07-26 13:32:47 +01:00
Victor Stinner
2e0744955f
gh-107211: Rename PySymtable_Lookup() to _PySymtable_Lookup() ( #107212 )
...
Rename the internal PySymtable_Lookup() function to
_PySymtable_Lookup() and no longer export it.
2023-07-25 00:54:09 +00:00
Victor Stinner
5e4af2a3e9
gh-106320: Move private _PySet API to the internal API ( #107041 )
...
* Add pycore_setobject.h header file.
* Move the following API to the internal C API:
* _PySet_Dummy
* _PySet_NextEntry()
* _PySet_Update()
2023-07-22 17:04:34 +02:00
Kirill Podoprigora
85ed1d2442
gh-106916: Add missing error check _PyCompile_CleanDoc ( #106921 )
...
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-07-21 13:56:58 +09:00
Irit Katriel
40f3f11a77
gh-105481: Generate the opcode lists in dis from data extracted from bytecodes.c ( #106758 )
2023-07-18 19:42:44 +01:00
Inada Naoki
ece3b9d12a
gh-106843: fix memleak in _PyCompile_CleanDoc ( #106846 )
2023-07-18 03:44:16 +00:00
Inada Naoki
2566b74b26
gh-81283: compiler: remove indent from docstring ( #106411 )
...
Co-authored-by: Éric <merwok@netwok.org>
2023-07-15 19:33:32 +09:00
Irit Katriel
6a70edf24c
gh-105481: expose opcode metadata via the _opcode module ( #106688 )
2023-07-14 18:41:52 +01:00
Irit Katriel
2ca008e2b7
gh-105481: move Python/opcode_metadata.h to Include/internal/pycore_opcode_metadata.h ( #106673 )
2023-07-12 11:30:25 +01:00
Victor Stinner
8571b271e7
gh-106320: Remove private _PyInterpreterState functions ( #106325 )
...
Remove private _PyThreadState and _PyInterpreterState C API
functions: move them to the internal C API (pycore_pystate.h and
pycore_interp.h). Don't export most of these functions anymore, but
still export functions used by tests.
Remove _PyThreadState_Prealloc() and _PyThreadState_Init() from the C
API, but keep it in the stable API.
2023-07-02 01:39:38 +00:00
Brandt Bucher
7b2d94d875
GH-106008: Make implicit boolean conversions explicit (GH-106003)
2023-06-29 13:49:54 -07:00
hms
8bff940ad6
gh-105775: Convert LOAD_CLOSURE to a pseudo-op ( #106059 )
...
This enables super-instruction formation,
removal of checks for uninitialized variables,
and frees up an instruction.
2023-06-29 09:34:00 -07:00
Irit Katriel
5290881009
gh-106149: move jump target resolution from optimizer to assembler ( #106150 )
2023-06-27 20:24:58 +01:00
Mark Shannon
04492cbc9a
GH-91095: Specialize calls to normal Python classes. (GH-99331)
2023-06-22 09:48:19 +01:00
Crowthebird
28187a9c4f
gh-105908: fix `barry_as_FLUFL` future import ( #105909 )
2023-06-19 22:50:57 +01:00
Irit Katriel
14d01262da
gh-105481: remove HAS_ARG, HAS_CONST, IS_JUMP_OPCODE, IS_PSEUDO_OPCODE and replace by their new versions ( #105865 )
2023-06-17 17:00:16 +01:00
Irit Katriel
d1b0297d3e
gh-105481: add HAS_JUMP flag to opcode metadata ( #105791 )
2023-06-14 23:14:22 +00:00
Mark Shannon
1d857da7f0
GH-77273: Better bytecodes for f-strings (GH-6132)
2023-06-14 16:15:08 +01:00
Irit Katriel
be2779c0cb
gh-105481: add flags to each instr in the opcode metadata table, to replace opcode.hasarg/hasname/hasconst ( #105482 )
2023-06-13 21:42:03 +01:00
Mark Shannon
09ffa69e2e
GH-105678: Split MAKE_FUNCTION into MAKE_FUNCTION and SET_FUNCTION_ATTRIBUTE (GH-105680)
2023-06-13 09:51:05 +01:00
Irit Katriel
58f5227d7c
gh-105481: add pseudo-instructions to the bytecodes DSL ( #105506 )
2023-06-11 22:31:59 +01:00
Erlend E. Aasland
6c832ddcf2
gh-105375: Improve error handling in compiler_enter_scope() ( #105494 )
2023-06-09 18:55:53 +02:00
Dong-hee Na
058b960535
gh-103906: Remove immortal refcounting in compile/marshal.c (gh-103922)
2023-06-05 22:38:36 +09:00
Jelle Zijlstra
69d1245685
gh-105164: Detect annotations inside match blocks ( #105177 )
2023-06-05 06:07:17 -07:00
Irit Katriel
94a1eea511
gh-103277: remove unused macros ( #105247 )
2023-06-03 05:12:07 -06:00
Jelle Zijlstra
44bb03f856
gh-105214: Use named constants for MAKE_FUNCTION oparg ( #105215 )
2023-06-02 14:10:45 +00:00
Irit Katriel
76b9c0cfaa
remove unused #includes of pycore_pymem.h ( #105166 )
2023-06-01 12:12:53 +01:00
Irit Katriel
f990bb8b2d
gh-105148: make _PyASTOptimizeState internal to ast_opt.c ( #105149 )
2023-05-31 20:21:46 +01:00
Jelle Zijlstra
a5f244d627
gh-104656: Rename typeparams AST node to type_params ( #104657 )
2023-05-21 21:25:09 -07:00
Jelle Zijlstra
cd9748409a
gh-104686: Fix tracing for decorated classes ( #104708 )
2023-05-21 16:20:19 -07:00
Carl Meyer
70c7796477
gh-104619: never leak comprehension locals to outer locals() ( #104637 )
2023-05-18 18:50:24 -07:00
Carl Meyer
86e6f16ccb
gh-104602: ensure all cellvars are known up front ( #104603 )
...
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-05-19 00:07:35 +00:00
Carl Meyer
0589c6a4d3
gh-104615: don't make unsafe swaps in apply_static_swaps ( #104620 )
2023-05-18 21:22:03 +00:00
Jelle Zijlstra
662aede68b
gh-104374: Remove access to class scopes for inlined comprehensions ( #104528 )
...
Co-authored-by: Carl Meyer <carl@oddbird.net>
2023-05-18 05:22:17 +00:00
Carl Meyer
f40890b124
gh-103865: add monitoring support to LOAD_SUPER_ATTR ( #103866 )
2023-05-16 10:29:00 -06:00
Jelle Zijlstra
24d8b88420
gh-103763: Implement PEP 695 ( #103764 )
...
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>
2023-05-15 20:36:23 -07:00
Irit Katriel
8a3702f0c7
gh-104482: Fix error handling bugs in ast.c ( #104483 )
2023-05-15 21:53:55 +01:00
Carl Meyer
ac66cc17f2
gh-104377: fix cell in comprehension that is free in outer scope ( #104394 )
2023-05-11 16:48:21 -07:00
Carl Meyer
c3b595e73e
gh-97933: (PEP 709) inline list/dict/set comprehensions ( #101441 )
...
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2023-05-09 11:02:14 -06:00
Irit Katriel
ca95edf177
gh-104240: return code unit metadata from codegen ( #104300 )
2023-05-09 14:33:40 +01:00
Irit Katriel
2c2dc61e8d
gh-104240: make _PyCompile_CodeGen support different compilation modes ( #104241 )
2023-05-07 18:47:28 +01:00
Irit Katriel
80b714835d
gh-87092: Expose assembler to unit tests ( #103988 )
2023-05-01 22:29:30 +01:00
Irit Katriel
fbf3596c3e
gh-87092: change assembler to use instruction sequence instead of CFG ( #103933 )
2023-04-29 12:06:04 +01:00
Carl Meyer
0dc8b50d33
gh-87729: add LOAD_SUPER_ATTR instruction for faster super() ( #103497 )
...
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.
2023-04-24 22:22:14 +00:00