Commit Graph

973 Commits

Author SHA1 Message Date
Victor Stinner 135ec7cefb
gh-99537: Use Py_SETREF() function in C code (#99657)
Fix potential race condition in code patterns:

* Replace "Py_DECREF(var); var = new;" with "Py_SETREF(var, new);"
* Replace "Py_XDECREF(var); var = new;" with "Py_XSETREF(var, new);"
* Replace "Py_CLEAR(var); var = new;" with "Py_XSETREF(var, new);"

Other changes:

* Replace "old = var; var = new; Py_DECREF(var)"
  with "Py_SETREF(var, new);"
* Replace "old = var; var = new; Py_XDECREF(var)"
  with "Py_XSETREF(var, new);"
* And remove the "old" variable.
2022-11-22 13:39:11 +01:00
Victor Stinner 8211cf5d28
gh-99300: Replace Py_INCREF() with Py_NewRef() (#99530)
Replace Py_INCREF() and Py_XINCREF() using a cast with Py_NewRef()
and Py_XNewRef().
2022-11-16 18:34:24 +01:00
Irit Katriel a3ac9232f8
gh-87092: expose the compiler's codegen to python for unit tests (GH-99111) 2022-11-14 13:56:40 +00:00
Irit Katriel fb844e1931
gh-98762: Fix locations of match sub-patterns (GH-98775) 2022-11-12 18:42:17 +00:00
Irit Katriel 3dd6ee2c00
gh-99254: remove all unused consts from code objects (GH-99255) 2022-11-11 10:53:43 +00:00
Mark Shannon 1e197e63e2
GH-96421: Insert shim frame on entry to interpreter (GH-96319)
* Adds EXIT_INTERPRETER instruction to exit PyEval_EvalDefault()

* Simplifies RETURN_VALUE, YIELD_VALUE and RETURN_GENERATOR instructions as they no longer need to check for entry frames.
2022-11-10 12:34:57 +00:00
Victor Stinner 231d83b724
gh-99300: Use Py_NewRef() in Python/ directory (#99317)
Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and
Py_XNewRef() in C files of the Python/ directory.

Update Parser/asdl_c.py to regenerate Python/Python-ast.c.
2022-11-10 11:23:36 +01:00
Brandt Bucher c7f5708714
GH-98686: Get rid of "adaptive" and "quick" instructions (GH-99182) 2022-11-09 10:50:09 -08:00
Mark Shannon f4adb97506
GH-96793: Implement PEP 479 in bytecode. (GH-99006)
* Handle converting StopIteration to RuntimeError in bytecode.

* Add custom instruction for converting StopIteration into RuntimeError.
2022-11-03 11:38:51 +00:00
Irit Katriel df84b7b0bc
gh-87092: remove unused SET_LOC/UNSET_LOC macros (GH-98914) 2022-11-02 15:52:11 +00:00
Irit Katriel 6d683d8525
gh-87092: do not allocate PyFutureFeatures dynamically (GH-98913) 2022-11-02 15:13:07 +00:00
Irit Katriel 39448adc9d
gh-98811: use full source location to simplify __future__ imports error checking. This also fixes an incorrect error offset. (GH-98812) 2022-10-31 13:08:03 +00:00
Mark Shannon 22863df7ca
GH-96793: Change `FOR_ITER` to not pop the iterator on exhaustion. (GH-96801)
Change FOR_ITER to have the same stack effect regardless of whether it branches or not.
Performance is unchanged as FOR_ITER (and specialized forms jump over the cleanup code).
2022-10-27 11:55:03 +01:00
Irit Katriel a1a8828e42
gh-98461: Fix location of RETURN_VALUE in async generator bytecode. compiler_jump_if no longer needs a pointer to the loc. (GH-98494) 2022-10-25 12:26:26 +01:00
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