Commit graph

278 commits

Author SHA1 Message Date
Mark Shannon bf4bc36069
GH-109369: Merge all eval-breaker flags and monitoring version into one word. (GH-109846) 2023-10-04 16:09:48 +01:00
Guido van Rossum 7c149a76b2
gh-104909: Split more LOAD_ATTR specializations (GH-110317)
* Split LOAD_ATTR_MODULE

* Split LOAD_ATTR_WITH_HINT

* Split _GUARD_TYPE_VERSION out of the latter

* Split LOAD_ATTR_CLASS

* Split LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES

* Fix indent of DEOPT_IF in macros

* Split LOAD_ATTR_METHOD_LAZY_DICT

* Split LOAD_ATTR_NONDESCRIPTOR_NO_DICT

* Fix omission of _CHECK_ATTR_METHOD_LAZY_DICT
2023-10-04 16:08:02 +01:00
Guido van Rossum 625ecbe92e
gh-109979: Unify _GUARD_TYPE_VERSION{,_STORE} (#110301)
Now the target for `DEOPT_IF()` is auto-filled,
we don't need a separate `_GUARD_TYPE_VERSION_STORE` uop.
2023-10-03 22:37:21 +00:00
Guido van Rossum d67edcf0b3
gh-109979: Auto-generate the target for DEOPT_IF() (#110193)
In Python/bytecodes.c, you now write
```
    DEOPT_IF(condition);
```
The code generator expands this to
```
    DEOPT_IF(condition, opcode);
```
where `opcode` is the name of the unspecialized instruction.
This works inside macro expansions too.

**CAVEAT:** The entire `DEOPT_IF(condition)` statement must be on a single line.
If it isn't, the substitution will fail; an error will be printed by the code generator
and the C compiler will report some errors.
2023-10-03 10:13:50 -07:00
Nikita Sobolev 3814bc1723
gh-110020: Fix unused variable warnings in bytecodes.c (GH-110023) 2023-09-28 15:31:32 +01:00
Guido van Rossum 5bb6f0fcba
gh-104909: Split some more insts into ops (#109943)
These are the most popular specializations of `LOAD_ATTR` and `STORE_ATTR`
that weren't already viable uops:

* Split LOAD_ATTR_METHOD_WITH_VALUES
* Split LOAD_ATTR_METHOD_NO_DICT
* Split LOAD_ATTR_SLOT
* Split STORE_ATTR_SLOT
* Split STORE_ATTR_INSTANCE_VALUE

Also:

* Add `-v` flag to code generator which prints a list of non-viable uops
  (easter-egg: it can print execution counts -- see source)
* Double _Py_UOP_MAX_TRACE_LENGTH to 128



I had dropped one of the DEOPT_IF() calls! :-(
2023-09-27 15:27:44 -07:00
Brandt Bucher 6c13e13b13
GH-104584: Don't call executors from JUMP_BACKWARD (GH-109347) 2023-09-13 10:26:50 -07: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
Guido van Rossum b86ce91bfe
gh-106581: Honor 'always_exits' in write_components() (#109338)
I must have overlooked this when refactoring the code generator.
The Tier 1 interpreter contained a few silly things like
```
            goto resume_frame;
            STACK_SHRINK(1);
```
(and other variations, some where the unconditional `goto` was hidden in a macro).
2023-09-12 17:58:40 +00:00
Nikita Sobolev 247ee1bf84
gh-109216: Fix possible memory leak in BUILD_MAP (#109257) 2023-09-12 15:07:22 +05:30
Guido van Rossum fbaf77eb9b
gh-109214: Rename SAVE_IP to _SET_IP, and similar (#109285)
* Rename SAVE_IP to _SET_IP
* Rename EXIT_TRACE to _EXIT_TRACE
* Rename SAVE_CURRENT_IP to _SAVE_CURRENT_IP
* Rename INSERT to _INSERT (This is for Ken Jin's abstract interpreter)
* Rename IS_NONE to _IS_NONE
* Rename JUMP_TO_TOP to _JUMP_TO_TOP
2023-09-11 15:39:19 -07:00
Guido van Rossum bcce5e2718
gh-109039: Branch prediction for Tier 2 interpreter (#109038)
This adds a 16-bit inline cache entry to the conditional branch instructions POP_JUMP_IF_{FALSE,TRUE,NONE,NOT_NONE} and their instrumented variants, which is used to keep track of the branch direction.

Each time we encounter these instructions we shift the cache entry left by one and set the bottom bit to whether we jumped.

Then when it's time to translate such a branch to Tier 2 uops, we use the bit count from the cache entry to decided whether to continue translating the "didn't jump" branch or the "jumped" branch.

The counter is initialized to a pattern of alternating ones and zeros to avoid bias.

The .pyc file magic number is updated. There's a new test, some fixes for existing tests, and a few miscellaneous cleanups.
2023-09-11 18:20:24 +00:00
Jelle Zijlstra 17f994174d
gh-109118: Fix runtime crash when NameError happens in PEP 695 function (#109123) 2023-09-09 02:49:20 +00:00
Mark Shannon 501f2dc527
GH-108614: Unbreak emscripten build (GH-109132) 2023-09-08 17:54:45 +01:00
Mark Shannon 0858328ca2
GH-108614: Add RESUME_CHECK instruction (GH-108630) 2023-09-07 14:39:03 +01:00
Mark Shannon 5a3672cb39
GH-108614: Remove TIER_ONE and TIER_TWO from _PUSH_FRAME (GH-108725) 2023-09-04 11:36:57 +01:00
Mark Shannon 059bd4d299
GH-108614: Remove non-debug uses of #if TIER_ONE and #if TIER_TWO from _POP_FRAME op. (GH-108685) 2023-08-31 11:34:52 +01:00
Guido van Rossum 47d7eba889
gh-108487: Move assert(self != NULL) down beyond DEOPT_IF() (#108510) 2023-08-28 10:17:00 -07:00
Brandt Bucher 4eae1e5342
GH-106581: Fix instrumentation in tier 2 (GH-108493) 2023-08-25 19:12:59 +00:00
Guido van Rossum ddf66b54ed
gh-106581: Split CALL_BOUND_METHOD_EXACT_ARGS into uops (#108462)
Instead of using `GO_TO_INSTRUCTION(CALL_PY_EXACT_ARGS)` we just add the macro elements of the latter to the macro for the former. This requires lengthening the uops array in struct opcode_macro_expansion. (It also required changes to stacking.py that were merged already.)
2023-08-24 17:36:00 -07:00
Guido van Rossum 88941d665f
gh-106581: Fix two bugs in the code generator's copy optimization (#108380)
I was comparing the last preceding poke with the *last* peek,
rather than the *first* peek.

Unfortunately this bug obscured another bug:
When the last preceding poke is UNUSED, the first peek disappears,
leaving the variable unassigned. This is how I fixed it:

- Rename CopyEffect to CopyItem.
- Change CopyItem to contain StackItems instead of StackEffects.
- Update those StackItems when adjusting the manager higher or lower.
- Assert that those StackItems' offsets are equivalent.
- Other clever things.

---------

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2023-08-24 19:10:51 +00:00
Guido van Rossum 61c7249759
gh-106581: Project through calls (#108067)
This finishes the work begun in gh-107760. When, while projecting a superblock, we encounter a call to a short, simple function, the superblock will now enter the function using `_PUSH_FRAME`, continue through it, and leave it using `_POP_FRAME`, and then continue through the original code. Multiple frame pushes and pops are even possible. It is also possible to stop appending to the superblock in the middle of a called function, when running out of space or encountering an unsupported bytecode.
2023-08-17 11:29:58 -07:00
Mark Shannon 006e44f950
GH-108035: Remove the _PyCFrame struct as it is no longer needed for performance. (GH-108036) 2023-08-17 11:16:03 +01:00
Guido van Rossum dc8fdf5fd5
gh-106581: Split CALL_PY_EXACT_ARGS into uops (#107760)
* Split `CALL_PY_EXACT_ARGS` into uops

This is only the first step for doing `CALL` in Tier 2.
The next step involves tracing into the called code object and back.
After that we'll have to do the remaining `CALL` specialization.
Finally we'll have to deal with `KW_NAMES`.

Note: this moves setting `frame->return_offset` directly in front of
`DISPATCH_INLINED()`, to make it easier to move it into `_PUSH_FRAME`.
2023-08-16 16:26:43 -07:00
Dong-hee Na bf707749e8
gh-106797: Remove warning logs from Python/generated_cases.c.h and executor_cases.c.h (gh-107889)
gh-106797: Remove warning logs from Python/generated_cases.c.h
2023-08-13 04:36:46 +09:00
Brandt Bucher 326f0ba1c5
GH-106485: Dematerialize instance dictionaries when possible (GH-106539) 2023-08-09 19:14:50 +00:00
Brandt Bucher a9caf9cf90
GH-105848: Simplify the arrangement of CALL's stack (GH-107788) 2023-08-09 18:19:39 +00:00
Brandt Bucher ea72c6fe3b
GH-107596: Specialize str[int] (GH-107597) 2023-08-08 13:42:43 -07:00
Guido van Rossum 400835ea16
gh-106812: Refactor cases_generator to allow uops with array stack effects (#107564)
Introducing a new file, stacking.py, that takes over several responsibilities related to symbolic evaluation of push/pop operations, with more generality.
2023-08-04 09:35:56 -07:00
Mark Shannon fa45958450
GH-107263: Increase C stack limit for most functions, except _PyEval_EvalFrameDefault() (GH-107535)
* Set C recursion limit to 1500, set cost of eval loop to 2 frames, and compiler mutliply to 2.
2023-08-04 10:10:29 +01:00
Brandt Bucher dfb55d9d7f
Use tstate->interp to get the interpreter state in bytecodes.c (GH-107506) 2023-07-31 14:18:38 -07:00
Guido van Rossum 5eb80a61f5
GH-104909: Move unused cache entries from uops to macros (#107444)
There's no need to use a dummy uop to skip unused cache entries. The macro syntax lets you write `unused/1` instead.

Similarly, move `unused/5` from op `_LOAD_ATTR_INSTANCE_VALUE` to macro `LOAD_ATTR_INSTANCE_VALUE`.
2023-07-31 08:55:33 -07:00
Mark Shannon c6539b36c1
GH-106895: Raise a ValueError when attempting to disable events that cannot be disabled. (GH-107337) 2023-07-27 15:27:11 +01:00
Mark Shannon 766d2518ae
GH-106897: Add RERAISE event to sys.monitoring. (GH-107291)
* Ensures that exception handling events are balanced. Each [re]raise event has a matching unwind/handled event.
2023-07-27 13:32:30 +01:00
Carl Meyer e5d5522612
gh-106917: fix super classmethod calls to non-classmethods (#106977) 2023-07-24 13:14:56 -07:00
Brandt Bucher 8f4de57699
GH-106701: Move _PyUopExecute to Python/executor.c (GH-106924) 2023-07-20 20:37:19 +00:00
Irit Katriel 9c81fc2dbe
gh-105481: do not auto-generate pycore_intrinsics.h (#106913) 2023-07-20 17:46:04 +01:00
Brandt Bucher 214a25dd81
GH-104584: Miscellaneous fixes for -Xuops (GH-106908) 2023-07-20 16:35:39 +00: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
Guido van Rossum 1e36ca63f9
Small fixes to code generator (#106845)
These repair nits I found in PR gh-106798 (issue gh-106797) and in PR gh-106716 (issue gh-106706).
2023-07-18 01:30:41 +00:00
Guido van Rossum 8e9a1a0322
gh-106603: Make uop struct a triple (opcode, oparg, operand) (#106794) 2023-07-17 12:12:33 -07:00
Guido van Rossum 2b94a05a0e
gh-106581: Add 10 new opcodes by allowing assert(kwnames == NULL) (#106707)
By turning `assert(kwnames == NULL)` into a macro that is not in the "forbidden" list, many instructions that formerly were skipped because they contained such an assert (but no other mention of `kwnames`) are now supported in Tier 2. This covers 10 instructions in total (all specializations of `CALL` that invoke some C code):
- `CALL_NO_KW_TYPE_1`
- `CALL_NO_KW_STR_1`
- `CALL_NO_KW_TUPLE_1`
- `CALL_NO_KW_BUILTIN_O`
- `CALL_NO_KW_BUILTIN_FAST`
- `CALL_NO_KW_LEN`
- `CALL_NO_KW_ISINSTANCE`
- `CALL_NO_KW_METHOD_DESCRIPTOR_O`
- `CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS`
- `CALL_NO_KW_METHOD_DESCRIPTOR_FAST`
2023-07-17 11:02:58 -07:00
Dong-hee Na 48956cc60e
gh-106797: Remove warning logs from Python/generated_cases.c.h (gh-106798) 2023-07-17 09:09:11 +09:00
Guido van Rossum 025995fead
gh-106529: Split FOR_ITER_{LIST,TUPLE} into uops (#106696)
Also rename `_ITER_EXHAUSTED_XXX` to `_IS_ITER_EXHAUSTED_XXX` to make it clear this is a test.
2023-07-13 17:27:35 -07:00
Mark Shannon 487861c6ae
GH-104909: Split LOAD_ATTR_INSTANCE_VALUE into micro-ops (GH-106678) 2023-07-13 16:36:19 +01:00
Guido van Rossum dd1884dc5d
gh-106529: Split FOR_ITER_RANGE into uops (#106638)
For an example of what this does for Tier 1 and Tier 2, see
https://github.com/python/cpython/issues/106529#issuecomment-1631649920
2023-07-12 10:23:59 -07:00
Guido van Rossum 7f55f58b6c
gh-106656: Remove --emit-line-directives from regen-cases (#106657)
If you prefer to see `#line` directives in generated_cases.c.h, run
```
make regen-cases CASESFLAG=-l
```
But please don't commit the result.
2023-07-12 16:12:39 +00:00
Mark Shannon b03755a234
GH-104909: Break LOAD_GLOBAL specializations in micro-ops. (GH-106677) 2023-07-12 14:34:14 +01:00
Serhiy Storchaka 4bf43710d1
gh-106307: C API: Add PyMapping_GetOptionalItem() function (GH-106308)
Also add PyMapping_GetOptionalItemString() function.
2023-07-11 23:04:12 +03:00
Mark Shannon c0c041a31b
GH-106529: Define POP_JUMP_IF_NONE in terms of POP_JUMP_IF_TRUE (GH-106599) 2023-07-11 11:33:59 +01:00
Victor Stinner 1f2921b72c
gh-106572: Convert PyObject_DelAttr() to a function (#106611)
* Convert PyObject_DelAttr() and PyObject_DelAttrString() macros to
  functions.
* Add PyObject_DelAttr() and PyObject_DelAttrString() functions to
  the stable ABI.
* Replace PyObject_SetAttr(obj, name, NULL) with
  PyObject_DelAttr(obj, name).
2023-07-11 11:38:22 +02:00
Mark Shannon 0c90e75610
GH-100288: Specialize LOAD_ATTR for simple class attributes. (#105990)
* Add two more specializations of LOAD_ATTR.
2023-07-10 11:40:35 +01:00
Mark Shannon 24fb627ea7
GH-106057: Handle recursion errors in inline class calls properly. (GH-106108) 2023-07-07 11:09:26 +01:00
Guido van Rossum 003ba71dcb
gh-104584: Fix error handling from backedge optimization (#106484)
When `_PyOptimizer_BackEdge` returns `NULL`, we should restore `next_instr` (and `stack_pointer`). To accomplish this we should jump to `resume_with_error` instead of just `error`.

The problem this causes is subtle -- the only repro I have is in PR gh-106393, at commit d7df54b139bcc47f5ea094bfaa9824f79bc45adc. But the fix is real (as shown later in that PR).

While we're at it, also improve the debug output: the offsets at which traces are identified are now measured in bytes, and always show the start offset. This makes it easier to correlate executor calls with optimizer calls, and either with `dis` output.

<!-- gh-issue-number: gh-104584 -->
* Issue: gh-104584
<!-- /gh-issue-number -->
2023-07-06 18:39:53 +00:00
Mark Shannon e5862113dd
GH-104584: Fix ENTER_EXECUTOR (GH-106141)
* Check eval-breaker in ENTER_EXECUTOR.

* Make sure that frame->prev_instr is set before entering executor.
2023-07-03 21:28:27 +01:00
Victor Stinner 8c5f74fc89
gh-106023: Update code using _PyObject_FastCall() (#106257)
Replace _PyObject_FastCall() calls with PyObject_Vectorcall().
2023-06-30 01:05:01 +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
Guido van Rossum 51fc725117
gh-104584: Baby steps towards generating and executing traces (#105924)
Added a new, experimental, tracing optimizer and interpreter (a.k.a. "tier 2"). This currently pessimizes, so don't use yet -- this is infrastructure so we can experiment with optimizing passes. To enable it, pass ``-Xuops`` or set ``PYTHONUOPS=1``. To get debug output, set ``PYTHONUOPSDEBUG=N`` where ``N`` is a debug level (0-4, where 0 is no debug output and 4 is excessively verbose).

All of this code is likely to change dramatically before the 3.13 feature freeze. But this is a first step.
2023-06-26 19:02:57 -07:00
Mark Shannon 04492cbc9a
GH-91095: Specialize calls to normal Python classes. (GH-99331) 2023-06-22 09:48:19 +01:00
Mark Shannon 581619941e
GH-104584: Assorted fixes for the optimizer API. (GH-105683)
* Add test for long loops

* Clear ENTER_EXECUTOR when deopting code objects.
2023-06-19 10:32:20 +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
Mark Shannon 7199584ac8
GH-100987: Allow objects other than code objects as the "executable" of an internal frame. (GH-105727)
* Add table describing possible executable classes for out-of-process debuggers.

* Remove shim code object creation code as it is no longer needed.

* Make lltrace a bit more robust w.r.t. non-standard frames.
2023-06-14 13:46:37 +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
Mark Shannon e830289c52
GH-105229: Remove remaining two-codeunit superinstructions (GH-105326)
* Remove LOAD_CONST__LOAD_FAST and LOAD_FAST__LOAD_CONST superinstructions.
2023-06-08 12:35:34 +01:00
Mark Shannon 064de0e3fc
GH-104610: Remove the use of PREDICT macros. (GH-104651) 2023-06-07 17:04:53 +01:00
Mark Shannon 0689340366
GH-105229: Replace some superinstructions with single instruction equivalent. (GH-105230) 2023-06-05 11:07:04 +01:00
Jelle Zijlstra 44bb03f856
gh-105214: Use named constants for MAKE_FUNCTION oparg (#105215) 2023-06-02 14:10:45 +00:00
Mark Shannon 4bfa01b9d9
GH-104584: Plugin optimizer API (GH-105100) 2023-06-02 11:46:18 +01:00
Irit Katriel 76b9c0cfaa
remove unused #includes of pycore_pymem.h (#105166) 2023-06-01 12:12:53 +01:00
Guido van Rossum df396b59af
gh-104909: Split BINARY_OP into micro-ops (#104910)
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
2023-05-31 08:09:23 -07:00
Carl Meyer 68c75c3153
gh-105035: fix super() calls on unusual types (e.g. meta-types) (#105094) 2023-05-30 14:36:24 -06:00
Mark Shannon 68b5f08b72
GH-104580: Don't cache eval breaker in interpreter (GH-104581)
Move eval-breaker to the front of the interpreter state.
2023-05-18 10:08:33 +01:00
Brandt Bucher b4a9747923
GH-103906: Remove immortal refcounting in the interpreter (GH-103909) 2023-05-16 14:36:02 -07: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
Brandt Bucher 1eb950ca55
GH-104405: Add missing PEP 523 checks (GH-104406) 2023-05-12 22:23:13 +00:00
Mark Shannon 45f5aa8fc7
GH-103082: Filter LINE events in VM, to simplify tool implementation. (GH-104387)
When monitoring LINE events, instrument all instructions that can have a predecessor on a different line.
Then check that the a new line has been hit in the instrumentation code.
This brings the behavior closer to that of 3.11, simplifying implementation and porting of tools.
2023-05-12 12:21:20 +01:00
Jelle Zijlstra 718b132772
gh-104413: Fix refleak when super attribute throws AttributeError (#104414) 2023-05-12 13:00:14 +05:30
Carl Meyer 77262458fe
gh-87729: improve hit rate of LOAD_SUPER_ATTR specialization (#104270) 2023-05-11 08:08:13 -06:00
Carl Meyer 1670729383
gh-87849: fix SEND specialization family definition (GH-104268) 2023-05-11 12:52:06 +01: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
Ken Jin ed95e8cbd4
gh-98003: Inline call frames for CALL_FUNCTION_EX (GH-98004) 2023-04-30 21:08:26 +08:00
Carl Meyer ef25febcf2
gh-87729: specialize LOAD_SUPER_ATTR_METHOD (#103809) 2023-04-25 17:45:51 +00: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
Mark Shannon efb8a2553c
GH-103488: Use return-offset, not yield-offset. (GH-103502)
* Use return-offset, not yield-offset, so that instruction pointer is correct when sending to a generator or coroutine.
2023-04-13 16:19:07 +01:00
Mark Shannon 411b169281
GH-103082: Implementation of PEP 669: Low Impact Monitoring for CPython (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
2023-04-12 12:04:55 +01:00
Brandt Bucher b4978ff872
GH-88691: Shrink the CALL caches (GH-103230) 2023-04-05 14:15:49 -07:00
Irit Katriel 848bdbe166
gh-102192: use PyErr_SetHandledException instead of the legacy PyErr_SetExcInfo (#103157) 2023-04-01 10:31:48 +05:30
Brett Cannon d97aef8ebf
Add missing variables to bytecodes.c (GH-103153)
The code works without this change, but it does cause C tooling to complain less about undeclared variables.
2023-03-31 14:23:55 -07:00
Brandt Bucher 121057aa36
GH-89987: Shrink the BINARY_SUBSCR caches (GH-103022) 2023-03-29 15:53:30 -07:00
Brandt Bucher 0444ae2487
GH-100982: Break up COMPARE_AND_BRANCH (GH-102801) 2023-03-23 15:25:09 -07:00
Irit Katriel 3468c768ce
gh-102859: Remove JUMP_IF_FALSE_OR_POP and JUMP_IF_TRUE_OR_POP (#102870) 2023-03-22 18:10:48 +00:00
Mark Shannon 7559f5fda9
GH-101291: Rearrange the size bits in PyLongObject (GH-102464)
* Eliminate all remaining uses of Py_SIZE and Py_SET_SIZE on PyLongObject, adding asserts.

* Change layout of size/sign bits in longobject to support future addition of immortal ints and tagged medium ints.

* Add functions to hide some internals of long object, and for setting sign and digit count.

* Replace uses of IS_MEDIUM_VALUE macro with _PyLong_IsCompact().
2023-03-22 14:49:51 +00:00
Nikita Sobolev 82eb9469e7
gh-102598: Remove obsolete optimization from FORMAT_VALUE opcode (#102599) 2023-03-21 00:47:15 -07:00
Irit Katriel ad77b80b05
gh-102192: Replace PyErr_Fetch/Restore etc by more efficient alternatives (#102816) 2023-03-19 15:17:59 +00:00
Guido van Rossum 70185de1ab
gh-102654: Insert #line directives in generated_cases.c.h (#102669)
This behavior is optional, because in some extreme cases it
may just make debugging harder. The tool defaults it to off,
but it is on in Makefile.pre.in.

Also note that this makes diffs to generated_cases.c.h noisier,
since whenever you insert or delete a line in bytecodes.c,
all subsequent #line directives will change.
2023-03-15 08:37:36 -07:00
Guido van Rossum 392f2ad3cb
gh-98831: Use DECREF_INPUTS() more (#102409) 2023-03-13 15:08:45 -07:00
Mark Shannon 2d370da570
GH-100987: Don't cache references to the names and consts array in _PyEval_EvalFrameDefault. (#102640)
* Rename local variables, names and consts, from the interpeter loop. Will allow non-code objects in frames for better introspection of C builtins and extensions.

* Remove unused dummy variables.
2023-03-13 18:35:37 +00:00
Mark Shannon 233e32f936
GH-102300: Reuse objects with refcount == 1 in float specialized binary ops. (GH-102301) 2023-03-13 10:34:54 +00:00
Brandt Bucher 08b67fb34f
GH-90997: Shrink the LOAD_GLOBAL caches (#102569) 2023-03-10 17:01:16 -08:00
Eric Snow b45d14b886
gh-100227: Move dict_state.global_version to PyInterpreterState (gh-102338)
https://github.com/python/cpython/issues/100227
2023-03-09 08:16:30 -07:00
Jacob Bower 8de59c1bb9
gh-102021 : Allow multiple input files for interpreter loop generator (#102022)
The input files no longer use `-i`.
2023-03-03 20:59:21 -08:00
Guido van Rossum b5ff382433
GH-102305: Expand some macros in generated_cases.c.h (#102309)
* Emit straight stack_pointer[-i] instead of PEEK(i), POKE(i, ...)
* Expand JUMPBY() and NEXTOPARG(), and fix a perf bug
2023-02-28 08:49:35 -08:00
Dennis Sweeney e3c3f9fec0
gh-102250: Fix double-decref in COMPARE_AND_BRANCH error case (GH-102287) 2023-02-27 10:46:40 +00:00
Mark Shannon 7c106a443f
GH-100982: Restrict FOR_ITER_RANGE to a single instruction to allow instrumentation. (GH-101985) 2023-02-22 11:11:57 +00:00
Steve Dower a99eb5cd99
gh-101907: Stop using _Py_OPCODE and _Py_OPARG macros (GH-101912)
* gh-101907: Removes use of non-standard C++ extension from Include/cpython/code.h

* Make cases_generator correct on Windows
2023-02-20 14:56:48 +00:00
Eclips4 68bd8c5e2e
gh-101952: Fix possible segfault in BUILD_SET opcode (#101958) 2023-02-16 09:46:43 -08:00
Mark Shannon c7766245c1
GH-87849: Fix refleak in SEND instruction. (GH-101908)
Fix refleak in SEND instruction.
2023-02-15 12:21:40 +00:00
Irit Katriel 81e3aa835c
gh-101799: implement PREP_RERAISE_STAR as an intrinsic function (#101800) 2023-02-14 11:54:13 +00:00
Mark Shannon 160f2fe2b9
GH-87849: Simplify stack effect of SEND and specialize it for generators and coroutines. (GH-101788) 2023-02-13 11:24:55 +00:00
Guido van Rossum 616aec1ff1
gh-98831: Modernize CALL and family (#101508)
Includes a slight improvement to `DECREF_INPUTS()`.
2023-02-08 11:40:10 -08:00
Mark Shannon feec49c407
GH-101578: Normalize the current exception (GH-101607)
* Make sure that the current exception is always normalized.

* Remove redundant type and traceback fields for the current exception.

* Add new API functions: PyErr_GetRaisedException, PyErr_SetRaisedException

* Add new API functions: PyException_GetArgs, PyException_SetArgs
2023-02-08 09:31:12 +00:00
Guido van Rossum a9f01448a9
gh-98831: Modernize CALL_FUNCTION_EX (#101627)
New generator feature: Move CHECK_EVAL_BREAKER() call to just before DISPATCH().
2023-02-07 20:03:22 -08:00
Guido van Rossum b2b85b5db9
gh-98831: Modernize FORMAT_VALUE (#101628)
Generator update: support balanced parentheses and brackets in conditions and size expressions.
2023-02-07 17:35:55 -08:00
Guido van Rossum aacbdb0c65
gh-98831: Finish the UNPACK_SEQUENCE family (#101666)
New generator feature: Generate useful glue for output arrays, so you can just write values to the output array (no bounds checking). Rewrote UNPACK_SEQUENCE_TWO_TUPLE to use this, and also UNPACK_SEQUENCE_{TUPLE,LIST}.
2023-02-07 15:44:37 -08:00
penguin_wwy 753fc8a5d6
gh-101632: Add the new RETURN_CONST opcode (#101633) 2023-02-07 22:32:21 +00:00
Irit Katriel dec1ab0387
gh-98831: rewrite UNPACK_EX, UNPACK_SEQUENCE, UNPACK_SEQUENCE_TWO_TUPLE in the instruction definition DSL (#101641) 2023-02-07 20:37:43 +00:00
Guido van Rossum d54b8d8fbd
gh-98831: Modernize the FOR_ITER family of instructions (#101626)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2023-02-07 08:28:28 -08:00
Irit Katriel 38752760c9
gh-98831: rewrite COPY and SWAP in the instruction definition DSL (#101620) 2023-02-06 22:45:18 +00:00
Irit Katriel 433fb3ef08
gh-98831: rewrite MAKE_FUNCTION and BUILD_SLICE in the instruction definition DSL (#101529) 2023-02-03 14:40:45 +00:00
Irit Katriel 04e06e20ee
gh-98831: rewrite SEND, GET_YIELD_FROM_ITER, RETURN_GENERATOR in the instruction definition DSL (#101516) 2023-02-03 11:30:21 +00:00
Irit Katriel 0675b8f032
gh-98831: rewrite RERAISE and CLEANUP_THROW in the instruction definition DSL (#101511) 2023-02-02 10:02:57 +00:00
Guido van Rossum ae9b38f424
gh-98831: Modernize the LOAD_GLOBAL family (#101502) 2023-02-01 13:12:49 -08:00
Irit Katriel b91b42d236
gh-98831: rewrite PUSH_EXC_INFO and conditional jumps in the instruction definition DSL (#101481) 2023-02-01 19:38:06 +00:00
Guido van Rossum 7840ff3cdb
gh-98831: Modernize the LOAD_ATTR family (#101488) 2023-02-01 10:56:52 -08:00
Irit Katriel 0062f538d9
gh-98831: rewrite BEFORE_ASYNC_WITH and END_ASYNC_FOR in the instruction definition DSL (#101458) 2023-01-31 18:47:50 +00:00
Irit Katriel 29a858b85f
gh-98831: rewrite GET_LEN, GET_ITER, BEFORE_WITH and a few simple opcodes in the instruction definition DSL (#101443) 2023-01-31 10:23:15 +00:00
Mark Shannon c1b1f51cd1
GH-101291: Refactor the PyLongObject struct into object header and PyLongValue struct. (GH-101292) 2023-01-30 10:03:04 +00:00
Guido van Rossum f5a3d91b6c
gh-98831: Support conditional effects; use for LOAD_ATTR (#101333) 2023-01-29 17:28:39 -08:00
Irit Katriel b400219df5
gh-98831: rewrite RAISE_VARARGS in the instruction definition DSL (#101306) 2023-01-25 22:29:56 +00:00
Irit Katriel 1a9d8c750b
gh-98831: rewrite pattern matching opcodes in the instruction definition DSL (#101287) 2023-01-24 22:39:13 +00:00
Mark Shannon f02fa64bf2
GH-100762: Don't call gen.throw() in gen.close(), unless necessary. (GH-101013)
* Store exception stack depth in YIELD_VALUE's oparg and use it avoid expensive gen.throw() in gen.close() where possible.
2023-01-24 17:25:37 +00:00
Irit Katriel 8c183cddd3
gh-98831: rewrite CHECK_EG_MATCH opcode in the instruction definition DSL (#101269) 2023-01-24 09:43:16 +00:00
Irit Katriel e9ccfe4a63
gh-100712: make it possible to disable specialization (for debugging) (#100713) 2023-01-19 18:14:55 +00:00
Guido van Rossum 80e3e3423c
GH-98831: Implement array support in cases generator (#100912)
You can now write things like this:
```
inst(BUILD_STRING, (pieces[oparg] -- str)) { ... }
inst(LIST_APPEND, (list, unused[oparg-1], v -- list, unused[oparg-1])) { ... }
```
Note that array output effects are only partially supported (they must be named `unused` or correspond to an input effect).
2023-01-17 15:59:19 -08:00
Mark Shannon 7b14c2ef19
GH-100982: Add COMPARE_AND_BRANCH instruction (GH-100983) 2023-01-16 12:35:21 +00:00
Mark Shannon 6e4e14d98f
GH-100923: Embed jump mask in COMPARE_OP oparg (GH-100924) 2023-01-11 20:40:43 +00:00
Irit Katriel 15c44789bb
gh-100758: Refactor initialisation of frame headers into a single function (_PyFrame_Initialize) (GH-100759) 2023-01-06 14:55:56 +00:00
Mark Shannon 78068126a1
GH-99005: More intrinsics (GH-100774)
* Remove UNARY_POSITIVE, LIST_TO_TUPLE and ASYNC_GEN_WRAP, replacing them with intrinsics.
2023-01-06 14:47:57 +00:00
Mark Shannon 28187141cc
GH-99005: Add CALL_INTRINSIC_1 instruction (GH-100771)
* Remove PRINT_EXPR instruction

* Remove STOPITERATION_ERROR instruction

* Remove IMPORT_STAR instruction
2023-01-05 16:05:51 +00:00
Mark Shannon f20c553a45
GH-100288: Remove LOAD_ATTR_METHOD_WITH_DICT instruction. (GH-100753) 2023-01-05 12:20:09 +00:00
Mark Shannon 15aecf8dd7
GH-100719: Remove the co_nplaincellvars field from code objects. (GH-100721) 2023-01-04 15:41:39 +00:00
L. A. F. Pereira e6d4440782
gh-100146: Steal references from stack when building a list (#100147)
When executing the BUILD_LIST opcode, steal the references from the stack,
in a manner similar to the BUILD_TUPLE opcode.  Implement this by offloading
the logic to a new private API, _PyList_FromArraySteal(), that works similarly
to _PyTuple_FromArraySteal().

This way, instead of performing multiple stack pointer adjustments while the
list is being initialized, the stack is adjusted only once and a fast memory
copy operation is performed in one fell swoop.
2023-01-03 10:49:49 -08:00
Guido van Rossum 08e5594cf3
GH-98831: Modernize a ton of simpler instructions (#100545)
* load_const and load_fast aren't families for now
* Don't decref unmoved names
* Modernize GET_ANEXT
* Modernize GET_AWAITABLE
* Modernize ASYNC_GEN_WRAP
* Modernize YIELD_VALUE
* Modernize POP_EXCEPT (in more than one way)
* Modernize PREP_RERAISE_STAR
* Modernize LOAD_ASSERTION_ERROR
* Modernize LOAD_BUILD_CLASS
* Modernize STORE_NAME
* Modernize LOAD_NAME
* Modernize LOAD_CLASSDEREF
* Modernize LOAD_DEREF
* Modernize STORE_DEREF
* Modernize COPY_FREE_VARS (mark it as done)
* Modernize LIST_TO_TUPLE
* Modernize LIST_EXTEND
* Modernize SET_UPDATE
* Modernize SETUP_ANNOTATIONS
* Modernize DICT_UPDATE
* Modernize DICT_MERGE
* Modernize MAP_ADD
* Modernize IS_OP
* Modernize CONTAINS_OP
* Modernize CHECK_EXC_MATCH
* Modernize IMPORT_NAME
* Modernize IMPORT_STAR
* Modernize IMPORT_FROM
* Modernize JUMP_FORWARD (mark it as done)
* Modernize JUMP_BACKWARD (mark it as done)
2022-12-27 17:11:03 -08:00
Ken Jin 36d358348d
Revert "gh-100288: Specialise LOAD_ATTR_METHOD for managed dictionaries (GH-100289)" (#100468)
This reverts commit c3c7848a48.
2022-12-24 01:48:43 +08:00
Ken Jin c3c7848a48
gh-100288: Specialise LOAD_ATTR_METHOD for managed dictionaries (GH-100289) 2022-12-24 00:26:42 +08:00