Skip to content

Commit 7ebd71e

Browse files
authored
GH-131498: Remove conditional stack effects (GH-131499)
* Adds some missing #includes
1 parent 443c0cd commit 7ebd71e

23 files changed

+129
-272
lines changed

Include/internal/pycore_jit.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
extern "C" {
66
#endif
77

8+
#include "pycore_interp.h"
9+
#include "pycore_optimizer.h"
10+
#include "pycore_stackref.h"
11+
812
#ifndef Py_BUILD_CORE
913
# error "this header requires Py_BUILD_CORE define"
1014
#endif

Lib/test/test_generated_cases.py

Lines changed: 6 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ class TestEffects(unittest.TestCase):
5959
def test_effect_sizes(self):
6060
stack = Stack()
6161
inputs = [
62-
x := StackItem("x", None, "", "1"),
63-
y := StackItem("y", None, "", "oparg"),
64-
z := StackItem("z", None, "", "oparg*2"),
62+
x := StackItem("x", None, "1"),
63+
y := StackItem("y", None, "oparg"),
64+
z := StackItem("z", None, "oparg*2"),
6565
]
6666
outputs = [
67-
StackItem("x", None, "", "1"),
68-
StackItem("b", None, "", "oparg*4"),
69-
StackItem("c", None, "", "1"),
67+
StackItem("x", None, "1"),
68+
StackItem("b", None, "oparg*4"),
69+
StackItem("c", None, "1"),
7070
]
7171
stack.pop(z)
7272
stack.pop(y)
@@ -903,98 +903,6 @@ def test_array_error_if(self):
903903
"""
904904
self.run_cases_test(input, output)
905905

906-
def test_cond_effect(self):
907-
input = """
908-
inst(OP, (aa, input if ((oparg & 1) == 1), cc -- xx, output if (oparg & 2), zz)) {
909-
output = SPAM(oparg, aa, cc, input);
910-
INPUTS_DEAD();
911-
xx = 0;
912-
zz = 0;
913-
}
914-
"""
915-
output = """
916-
TARGET(OP) {
917-
#if Py_TAIL_CALL_INTERP
918-
int opcode = OP;
919-
(void)(opcode);
920-
#endif
921-
frame->instr_ptr = next_instr;
922-
next_instr += 1;
923-
INSTRUCTION_STATS(OP);
924-
_PyStackRef aa;
925-
_PyStackRef input = PyStackRef_NULL;
926-
_PyStackRef cc;
927-
_PyStackRef xx;
928-
_PyStackRef output = PyStackRef_NULL;
929-
_PyStackRef zz;
930-
cc = stack_pointer[-1];
931-
if ((oparg & 1) == 1) { input = stack_pointer[-1 - (((oparg & 1) == 1) ? 1 : 0)]; }
932-
aa = stack_pointer[-2 - (((oparg & 1) == 1) ? 1 : 0)];
933-
output = SPAM(oparg, aa, cc, input);
934-
xx = 0;
935-
zz = 0;
936-
stack_pointer[-2 - (((oparg & 1) == 1) ? 1 : 0)] = xx;
937-
if (oparg & 2) stack_pointer[-1 - (((oparg & 1) == 1) ? 1 : 0)] = output;
938-
stack_pointer[-1 - (((oparg & 1) == 1) ? 1 : 0) + ((oparg & 2) ? 1 : 0)] = zz;
939-
stack_pointer += -(((oparg & 1) == 1) ? 1 : 0) + ((oparg & 2) ? 1 : 0);
940-
assert(WITHIN_STACK_BOUNDS());
941-
DISPATCH();
942-
}
943-
"""
944-
self.run_cases_test(input, output)
945-
946-
def test_macro_cond_effect(self):
947-
input = """
948-
op(A, (left, middle, right --)) {
949-
USE(left, middle, right);
950-
INPUTS_DEAD();
951-
}
952-
op(B, (-- deep, extra if (oparg), res)) {
953-
deep = -1;
954-
res = 0;
955-
extra = 1;
956-
INPUTS_DEAD();
957-
}
958-
macro(M) = A + B;
959-
"""
960-
output = """
961-
TARGET(M) {
962-
#if Py_TAIL_CALL_INTERP
963-
int opcode = M;
964-
(void)(opcode);
965-
#endif
966-
frame->instr_ptr = next_instr;
967-
next_instr += 1;
968-
INSTRUCTION_STATS(M);
969-
_PyStackRef left;
970-
_PyStackRef middle;
971-
_PyStackRef right;
972-
_PyStackRef deep;
973-
_PyStackRef extra = PyStackRef_NULL;
974-
_PyStackRef res;
975-
// A
976-
{
977-
right = stack_pointer[-1];
978-
middle = stack_pointer[-2];
979-
left = stack_pointer[-3];
980-
USE(left, middle, right);
981-
}
982-
// B
983-
{
984-
deep = -1;
985-
res = 0;
986-
extra = 1;
987-
}
988-
stack_pointer[-3] = deep;
989-
if (oparg) stack_pointer[-2] = extra;
990-
stack_pointer[-2 + ((oparg) ? 1 : 0)] = res;
991-
stack_pointer += -1 + ((oparg) ? 1 : 0);
992-
assert(WITHIN_STACK_BOUNDS());
993-
DISPATCH();
994-
}
995-
"""
996-
self.run_cases_test(input, output)
997-
998906
def test_macro_push_push(self):
999907
input = """
1000908
op(A, (-- val1)) {

Modules/_testinternalcapi.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "pycore_instruction_sequence.h" // _PyInstructionSequence_New()
2929
#include "pycore_interpframe.h" // _PyFrame_GetFunction()
3030
#include "pycore_object.h" // _PyObject_IsFreed()
31+
#include "pycore_optimizer.h" // _Py_Executor_DependsOn
3132
#include "pycore_pathconfig.h" // _PyPathConfig_ClearGlobal()
3233
#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
3334
#include "pycore_pylifecycle.h" // _PyInterpreterConfig_InitFromDict()

Objects/codeobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "pycore_interpframe.h" // FRAME_SPECIALS_SIZE
1010
#include "pycore_opcode_metadata.h" // _PyOpcode_Caches
1111
#include "pycore_opcode_utils.h" // RESUME_AT_FUNC_START
12+
#include "pycore_optimizer.h" // _Py_ExecutorDetach
1213
#include "pycore_pymem.h" // _PyMem_FreeDelayed()
1314
#include "pycore_pystate.h" // _PyInterpreterState_GET()
1415
#include "pycore_setobject.h" // _PySet_NextEntry()

Python/bytecodes.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
#define guard
6060
#define override
6161
#define specializing
62-
#define split
6362
#define replicate(TIMES)
6463
#define tier1
6564
#define no_save_ip
@@ -1686,8 +1685,10 @@ dummy_func(
16861685
ERROR_IF(PyStackRef_IsNull(*res), error);
16871686
}
16881687

1689-
op(_PUSH_NULL_CONDITIONAL, ( -- null if (oparg & 1))) {
1690-
null = PyStackRef_NULL;
1688+
op(_PUSH_NULL_CONDITIONAL, ( -- null[oparg & 1])) {
1689+
if (oparg & 1) {
1690+
null[0] = PyStackRef_NULL;
1691+
}
16911692
}
16921693

16931694
macro(LOAD_GLOBAL) =

Python/executor_cases.c.h

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy