mirror of
https://github.com/python/cpython.git
synced 2025-10-17 04:08:28 +00:00
GH-122155: Track local variables between pops and pushes in cases generator (GH-122286)
This commit is contained in:
parent
46f5a4f9e1
commit
a9d56e38a0
13 changed files with 463 additions and 159 deletions
|
@ -31,7 +31,7 @@ test_tools.skip_if_missing("cases_generator")
|
|||
with test_tools.imports_under_tool("cases_generator"):
|
||||
from analyzer import StackItem
|
||||
import parser
|
||||
from stack import Stack
|
||||
from stack import Local, Stack
|
||||
import tier1_generator
|
||||
import optimizer_generator
|
||||
|
||||
|
@ -60,9 +60,9 @@ class TestEffects(unittest.TestCase):
|
|||
stack.pop(y)
|
||||
stack.pop(x)
|
||||
for out in outputs:
|
||||
stack.push(out)
|
||||
self.assertEqual(stack.base_offset.to_c(), "-1 - oparg*2 - oparg")
|
||||
self.assertEqual(stack.top_offset.to_c(), "1 - oparg*2 - oparg + oparg*4")
|
||||
stack.push(Local.local(out))
|
||||
self.assertEqual(stack.base_offset.to_c(), "-1 - oparg - oparg*2")
|
||||
self.assertEqual(stack.top_offset.to_c(), "1 - oparg - oparg*2 + oparg*4")
|
||||
|
||||
|
||||
class TestGeneratedCases(unittest.TestCase):
|
||||
|
@ -602,7 +602,11 @@ class TestGeneratedCases(unittest.TestCase):
|
|||
frame->instr_ptr = next_instr;
|
||||
next_instr += 1;
|
||||
INSTRUCTION_STATS(OP);
|
||||
if (oparg == 0) { stack_pointer += -1 - oparg; goto somewhere; }
|
||||
if (oparg == 0) {
|
||||
stack_pointer += -1 - oparg;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
goto somewhere;
|
||||
}
|
||||
stack_pointer += -1 - oparg;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
DISPATCH();
|
||||
|
@ -908,7 +912,6 @@ class TestGeneratedCases(unittest.TestCase):
|
|||
next_instr += 1;
|
||||
INSTRUCTION_STATS(TEST);
|
||||
_PyStackRef w;
|
||||
_PyStackRef x;
|
||||
_PyStackRef y;
|
||||
// FIRST
|
||||
w = stack_pointer[-1];
|
||||
|
@ -916,11 +919,10 @@ class TestGeneratedCases(unittest.TestCase):
|
|||
use(w);
|
||||
}
|
||||
// SECOND
|
||||
x = w;
|
||||
{
|
||||
}
|
||||
// THIRD
|
||||
y = x;
|
||||
y = w;
|
||||
{
|
||||
use(y);
|
||||
}
|
||||
|
@ -1024,6 +1026,7 @@ class TestGeneratedCases(unittest.TestCase):
|
|||
}
|
||||
|
||||
op(THIRD, (j, k --)) {
|
||||
j,k; // Mark j and k as used
|
||||
ERROR_IF(cond, error);
|
||||
}
|
||||
|
||||
|
@ -1054,6 +1057,7 @@ class TestGeneratedCases(unittest.TestCase):
|
|||
k = b;
|
||||
j = a;
|
||||
{
|
||||
j,k; // Mark j and k as used
|
||||
if (cond) goto pop_2_error;
|
||||
}
|
||||
stack_pointer += -2;
|
||||
|
@ -1063,6 +1067,51 @@ class TestGeneratedCases(unittest.TestCase):
|
|||
"""
|
||||
self.run_cases_test(input, output)
|
||||
|
||||
def test_push_then_error(self):
|
||||
|
||||
input = """
|
||||
op(FIRST, ( -- a)) {
|
||||
a = 1;
|
||||
}
|
||||
|
||||
op(SECOND, (a -- a, b)) {
|
||||
b = 1;
|
||||
ERROR_IF(cond, error);
|
||||
}
|
||||
|
||||
macro(TEST) = FIRST + SECOND;
|
||||
"""
|
||||
|
||||
output = """
|
||||
TARGET(TEST) {
|
||||
frame->instr_ptr = next_instr;
|
||||
next_instr += 1;
|
||||
INSTRUCTION_STATS(TEST);
|
||||
_PyStackRef a;
|
||||
_PyStackRef b;
|
||||
// FIRST
|
||||
{
|
||||
a = 1;
|
||||
}
|
||||
// SECOND
|
||||
{
|
||||
b = 1;
|
||||
if (cond) {
|
||||
stack_pointer[0] = a;
|
||||
stack_pointer += 1;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
stack_pointer[0] = a;
|
||||
stack_pointer[1] = b;
|
||||
stack_pointer += 2;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
DISPATCH();
|
||||
}
|
||||
"""
|
||||
self.run_cases_test(input, output)
|
||||
|
||||
|
||||
class TestGeneratedAbstractCases(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue