Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2 Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 57 additions & 8 deletions 65 Lib/test/test_generated_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def skip_if_different_mount_drives():
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

Expand Down Expand Up @@ -60,9 +60,9 @@ def test_effect_sizes(self):
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):
Expand Down Expand Up @@ -602,7 +602,11 @@ def test_array_error_if(self):
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();
Expand Down Expand Up @@ -908,19 +912,17 @@ def test_used_unused_used(self):
next_instr += 1;
INSTRUCTION_STATS(TEST);
_PyStackRef w;
_PyStackRef x;
_PyStackRef y;
// FIRST
w = stack_pointer[-1];
{
use(w);
}
// SECOND
x = w;
{
}
// THIRD
y = x;
y = w;
{
use(y);
}
Expand Down Expand Up @@ -1024,6 +1026,7 @@ def test_pop_on_error_peeks(self):
}

op(THIRD, (j, k --)) {
j,k; // Mark j and k as used
ERROR_IF(cond, error);
}

Expand Down Expand Up @@ -1054,6 +1057,7 @@ def test_pop_on_error_peeks(self):
k = b;
j = a;
{
j,k; // Mark j and k as used
if (cond) goto pop_2_error;
}
stack_pointer += -2;
Expand All @@ -1063,6 +1067,51 @@ def test_pop_on_error_peeks(self):
"""
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:
Expand Down
9 changes: 4 additions & 5 deletions 9 Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1357,8 +1357,8 @@ dummy_func(
(void)counter;
}

op(_UNPACK_SEQUENCE, (seq -- unused[oparg])) {
_PyStackRef *top = stack_pointer + oparg - 1;
op(_UNPACK_SEQUENCE, (seq -- output[oparg])) {
_PyStackRef *top = output + oparg;
int res = _PyEval_UnpackIterableStackRef(tstate, seq, oparg, -1, top);
DECREF_INPUTS();
ERROR_IF(res == 0, error);
Expand Down Expand Up @@ -1401,9 +1401,8 @@ dummy_func(
DECREF_INPUTS();
}

inst(UNPACK_EX, (seq -- unused[oparg & 0xFF], unused, unused[oparg >> 8])) {
int totalargs = 1 + (oparg & 0xFF) + (oparg >> 8);
_PyStackRef *top = stack_pointer + totalargs - 1;
inst(UNPACK_EX, (seq -- left[oparg & 0xFF], unused, right[oparg >> 8])) {
_PyStackRef *top = right + (oparg >> 8);
int res = _PyEval_UnpackIterableStackRef(tstate, seq, oparg & 0xFF, oparg >> 8, top);
DECREF_INPUTS();
ERROR_IF(res == 0, error);
Expand Down
12 changes: 8 additions & 4 deletions 12 Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.