GH-135379: Remove types from stack items in code generator. (GH-135384) · python/cpython@c87b5b2 · GitHub
Skip to content

Commit c87b5b2

Browse files
authored
GH-135379: Remove types from stack items in code generator. (GH-135384)
* Make casts explicit in the instruction definitions
1 parent 49d7236 commit c87b5b2

13 files changed

Lines changed: 257 additions & 255 deletions

Include/internal/pycore_stackref.h

Lines changed: 26 additions & 0 deletions

Lib/test/test_generated_cases.py

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ class TestEffects(unittest.TestCase):
5656
def test_effect_sizes(self):
5757
stack = Stack()
5858
inputs = [
59-
x := StackItem("x", None, "1"),
60-
y := StackItem("y", None, "oparg"),
61-
z := StackItem("z", None, "oparg*2"),
59+
x := StackItem("x", "1"),
60+
y := StackItem("y", "oparg"),
61+
z := StackItem("z", "oparg*2"),
6262
]
6363
outputs = [
64-
StackItem("x", None, "1"),
65-
StackItem("b", None, "oparg*4"),
66-
StackItem("c", None, "1"),
64+
StackItem("x", "1"),
65+
StackItem("b", "oparg*4"),
66+
StackItem("c", "1"),
6767
]
6868
null = CWriter.null()
6969
stack.pop(z, null)
@@ -1103,32 +1103,6 @@ def test_array_of_one(self):
11031103
"""
11041104
self.run_cases_test(input, output)
11051105

1106-
def test_pointer_to_stackref(self):
1107-
input = """
1108-
inst(OP, (arg: _PyStackRef * -- out)) {
1109-
out = *arg;
1110-
DEAD(arg);
1111-
}
1112-
"""
1113-
output = """
1114-
TARGET(OP) {
1115-
#if Py_TAIL_CALL_INTERP
1116-
int opcode = OP;
1117-
(void)(opcode);
1118-
#endif
1119-
frame->instr_ptr = next_instr;
1120-
next_instr += 1;
1121-
INSTRUCTION_STATS(OP);
1122-
_PyStackRef *arg;
1123-
_PyStackRef out;
1124-
arg = (_PyStackRef *)stack_pointer[-1].bits;
1125-
out = *arg;
1126-
stack_pointer[-1] = out;
1127-
DISPATCH();
1128-
}
1129-
"""
1130-
self.run_cases_test(input, output)
1131-
11321106
def test_unused_cached_value(self):
11331107
input = """
11341108
op(FIRST, (arg1 -- out)) {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
The cases generator no longer accepts type annotations on stack items.
2+
Conversions to non-default types are now done explictly in bytecodes.c and
3+
optimizer_bytecodes.c. This will simplify code generation for top-of-stack
4+
caching and other future features.

Python/bytecodes.c

Lines changed: 33 additions & 30 deletions

0 commit comments

Comments
 (0)