Skip to content

Commit 844596c

Browse files
authored
GH-131498: Cases generator: Allow input and 'peek' variables to be modified (GH-132506)
1 parent be763e5 commit 844596c

File tree

9 files changed

+90
-116
lines changed

9 files changed

+90
-116
lines changed

Include/internal/pycore_uop_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/test/test_generated_cases.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,13 +1862,28 @@ def test_multiple_labels(self):
18621862

18631863
def test_reassigning_live_inputs(self):
18641864
input = """
1865-
inst(OP, (in -- )) {
1865+
inst(OP, (in -- in)) {
18661866
in = 0;
1867-
DEAD(in);
18681867
}
18691868
"""
1870-
with self.assertRaises(SyntaxError):
1871-
self.run_cases_test(input, "")
1869+
1870+
output = """
1871+
TARGET(OP) {
1872+
#if Py_TAIL_CALL_INTERP
1873+
int opcode = OP;
1874+
(void)(opcode);
1875+
#endif
1876+
frame->instr_ptr = next_instr;
1877+
next_instr += 1;
1878+
INSTRUCTION_STATS(OP);
1879+
_PyStackRef in;
1880+
in = stack_pointer[-1];
1881+
in = 0;
1882+
stack_pointer[-1] = in;
1883+
DISPATCH();
1884+
}
1885+
"""
1886+
self.run_cases_test(input, output)
18721887

18731888
def test_reassigning_dead_inputs(self):
18741889
input = """

Python/bytecodes.c

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4725,15 +4725,9 @@ dummy_func(
47254725
_CALL_KW_NON_PY +
47264726
_CHECK_PERIODIC;
47274727

4728-
op(_MAKE_CALLARGS_A_TUPLE, (func, unused, callargs, kwargs_in -- func, unused, tuple, kwargs_out)) {
4728+
op(_MAKE_CALLARGS_A_TUPLE, (func, unused, callargs, kwargs -- func, unused, callargs, kwargs)) {
47294729
PyObject *callargs_o = PyStackRef_AsPyObjectBorrow(callargs);
4730-
if (PyTuple_CheckExact(callargs_o)) {
4731-
tuple = callargs;
4732-
kwargs_out = kwargs_in;
4733-
DEAD(kwargs_in);
4734-
DEAD(callargs);
4735-
}
4736-
else {
4730+
if (!PyTuple_CheckExact(callargs_o)) {
47374731
int err = _Py_Check_ArgsIterable(tstate, PyStackRef_AsPyObjectBorrow(func), callargs_o);
47384732
if (err < 0) {
47394733
ERROR_NO_POP();
@@ -4742,10 +4736,9 @@ dummy_func(
47424736
if (tuple_o == NULL) {
47434737
ERROR_NO_POP();
47444738
}
4745-
kwargs_out = kwargs_in;
4746-
DEAD(kwargs_in);
4747-
PyStackRef_CLOSE(callargs);
4748-
tuple = PyStackRef_FromPyObjectSteal(tuple_o);
4739+
_PyStackRef temp = callargs;
4740+
callargs = PyStackRef_FromPyObjectSteal(tuple_o);
4741+
PyStackRef_CLOSE(temp);
47494742
}
47504743
}
47514744

@@ -4965,11 +4958,11 @@ dummy_func(
49654958

49664959
macro(BINARY_OP) = _SPECIALIZE_BINARY_OP + unused/4 + _BINARY_OP;
49674960

4968-
pure inst(SWAP, (bottom[1], unused[oparg-2], top[1] --
4969-
bottom[1], unused[oparg-2], top[1])) {
4970-
_PyStackRef temp = bottom[0];
4971-
bottom[0] = top[0];
4972-
top[0] = temp;
4961+
pure inst(SWAP, (bottom, unused[oparg-2], top --
4962+
bottom, unused[oparg-2], top)) {
4963+
_PyStackRef temp = bottom;
4964+
bottom = top;
4965+
top = temp;
49734966
assert(oparg >= 2);
49744967
}
49754968

Python/executor_cases.c.h

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

Python/generated_cases.c.h

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

Python/optimizer_cases.c.h

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

Tools/cases_generator/generators_common.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,6 @@ def emit_SimpleStmt(
500500
if tkn in local_stores:
501501
for var in storage.inputs:
502502
if var.name == tkn.text:
503-
if var.in_local or var.in_memory():
504-
msg = f"Cannot assign to already defined input variable '{tkn.text}'"
505-
raise analysis_error(msg, tkn)
506503
var.in_local = True
507504
var.memory_offset = None
508505
break

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