Skip to content

Commit e70bfd6

Browse files
committed
Remove all references to max stack
1 parent 54d8bfb commit e70bfd6

File tree

2 files changed

+2
-180
lines changed

2 files changed

+2
-180
lines changed

Lib/test/test_generated_cases.py

Lines changed: 0 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -77,171 +77,6 @@ def test_effect_sizes(self):
7777
self.assertEqual(stack.top_offset.to_c(), "1 - oparg - oparg*2 + oparg*4")
7878

7979

80-
class TestGenerateMaxStackEffect(unittest.TestCase):
81-
def check(self, input, output):
82-
analysis = analyze_forest(parse_src(input))
83-
buf = StringIO()
84-
writer = CWriter(buf, 0, False)
85-
opcode_metadata_generator.generate_max_stack_effect_function(analysis, writer)
86-
buf.seek(0)
87-
generated = buf.read()
88-
matches = re.search(r"(case OP: {[^}]+})", generated)
89-
if matches is None:
90-
self.fail(f"Couldn't find case statement for OP in:\n {generated}")
91-
self.assertEqual(output.strip(), matches.group(1))
92-
93-
def test_push_one(self):
94-
input = """
95-
inst(OP, (a -- b, c)) {
96-
SPAM();
97-
}
98-
"""
99-
output = """
100-
case OP: {
101-
*effect = 1;
102-
return 0;
103-
}
104-
"""
105-
self.check(input, output)
106-
107-
def test_cond_push(self):
108-
input = """
109-
inst(OP, (a -- b, c if (oparg))) {
110-
SPAM();
111-
}
112-
"""
113-
output = """
114-
case OP: {
115-
*effect = ((oparg) ? 1 : 0);
116-
return 0;
117-
}
118-
"""
119-
self.check(input, output)
120-
121-
def test_ops_pass_two(self):
122-
input = """
123-
op(A, (-- val1)) {
124-
val1 = SPAM();
125-
}
126-
op(B, (-- val2)) {
127-
val2 = SPAM();
128-
}
129-
op(C, (val1, val2 --)) {
130-
}
131-
macro(OP) = A + B + C;
132-
"""
133-
output = """
134-
case OP: {
135-
*effect = 2;
136-
return 0;
137-
}
138-
"""
139-
self.check(input, output)
140-
141-
def test_ops_pass_two_cond_push(self):
142-
input = """
143-
op(A, (-- val1, val2)) {
144-
val1 = 0;
145-
val2 = 1;
146-
}
147-
op(B, (val1, val2 -- val1, val2, val3 if (oparg))) {
148-
val3 = SPAM();
149-
}
150-
macro(OP) = A + B;
151-
"""
152-
output = """
153-
case OP: {
154-
*effect = Py_MAX(2, 2 + ((oparg) ? 1 : 0));
155-
return 0;
156-
}
157-
"""
158-
self.check(input, output)
159-
160-
def test_pop_push_array(self):
161-
input = """
162-
inst(OP, (values[oparg] -- values[oparg], above)) {
163-
SPAM(values, oparg);
164-
above = 0;
165-
}
166-
"""
167-
output = """
168-
case OP: {
169-
*effect = 1;
170-
return 0;
171-
}
172-
"""
173-
self.check(input, output)
174-
175-
def test_family(self):
176-
input = """
177-
op(A, (-- val1, val2)) {
178-
val1 = 0;
179-
val2 = 1;
180-
}
181-
op(B, (val1, val2 -- val3)) {
182-
val3 = 2;
183-
}
184-
macro(OP1) = A + B;
185-
186-
inst(OP, (-- val)) {
187-
val = 0;
188-
}
189-
190-
family(OP, 0) = { OP1 };
191-
"""
192-
output = """
193-
case OP: {
194-
*effect = 2;
195-
return 0;
196-
}
197-
"""
198-
self.check(input, output)
199-
200-
def test_family_intermediate_array(self):
201-
input = """
202-
op(A, (-- values[oparg])) {
203-
val1 = 0;
204-
val2 = 1;
205-
}
206-
op(B, (values[oparg] -- val3)) {
207-
val3 = 2;
208-
}
209-
macro(OP1) = A + B;
210-
211-
inst(OP, (-- val)) {
212-
val = 0;
213-
}
214-
215-
family(OP, 0) = { OP1 };
216-
"""
217-
output = """
218-
case OP: {
219-
*effect = Py_MAX(1, oparg);
220-
return 0;
221-
}
222-
"""
223-
self.check(input, output)
224-
225-
def test_negative_effect(self):
226-
input = """
227-
op(A, (val1 -- )) {
228-
}
229-
op(B, (val2 --)) {
230-
}
231-
op(C, (val3 --)) {
232-
}
233-
234-
macro(OP) = A + B + C;
235-
"""
236-
output = """
237-
case OP: {
238-
*effect = -1;
239-
return 0;
240-
}
241-
"""
242-
self.check(input, output)
243-
244-
24580
class TestGeneratedCases(unittest.TestCase):
24681
def setUp(self) -> None:
24782
super().setUp()
@@ -287,12 +122,6 @@ def run_cases_test(self, input: str, expected: str):
287122
_, labels_with_postlude = labels_with_prelude_and_postlude.split(tier1_generator.LABEL_START_MARKER)
288123
labels, _ = labels_with_postlude.split(tier1_generator.LABEL_END_MARKER)
289124
actual = instructions.strip() + "\n\n " + labels.strip()
290-
# if actual.strip() != expected.strip():
291-
# print("Actual:")
292-
# print(actual)
293-
# print("Expected:")
294-
# print(expected)
295-
# print("End")
296125

297126
self.assertEqual(actual.strip(), expected.strip())
298127

Python/flowgraph.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -760,11 +760,6 @@ make_cfg_traversal_stack(basicblock *entryblock) {
760760
typedef struct {
761761
/* The stack effect of the instruction. */
762762
int net;
763-
764-
/* The maximum stack usage of the instruction. Some instructions may
765-
* temporarily push extra values to the stack while they are executing.
766-
*/
767-
int max;
768763
} stack_effects;
769764

770765
Py_LOCAL(int)
@@ -784,11 +779,9 @@ get_stack_effects(int opcode, int oparg, int jump, stack_effects *effects)
784779
}
785780
if (IS_BLOCK_PUSH_OPCODE(opcode) && !jump) {
786781
effects->net = 0;
787-
effects->max = 0;
788782
return 0;
789783
}
790784
effects->net = pushed - popped;
791-
assert(effects->max >= effects->net);
792785
return 0;
793786
}
794787

@@ -849,7 +842,7 @@ calculate_stackdepth(cfg_builder *g)
849842
"Invalid CFG, stack underflow");
850843
goto error;
851844
}
852-
maxdepth = Py_MAX(maxdepth, depth + effects.max);
845+
maxdepth = Py_MAX(maxdepth, depth);
853846
if (HAS_TARGET(instr->i_opcode) && instr->i_opcode != END_ASYNC_FOR) {
854847
if (get_stack_effects(instr->i_opcode, instr->i_oparg, 1, &effects) < 0) {
855848
PyErr_Format(PyExc_SystemError,
@@ -859,7 +852,7 @@ calculate_stackdepth(cfg_builder *g)
859852
}
860853
int target_depth = depth + effects.net;
861854
assert(target_depth >= 0); /* invalid code or bug in stackdepth() */
862-
maxdepth = Py_MAX(maxdepth, depth + effects.max);
855+
maxdepth = Py_MAX(maxdepth, depth);
863856
if (stackdepth_push(&sp, instr->i_target, target_depth) < 0) {
864857
goto error;
865858
}

0 commit comments

Comments
 (0)