Skip to content

Commit 66f5826

Browse files
committed
Make death of variables explicit even for array variables.
1 parent 2b21bf9 commit 66f5826

File tree

7 files changed

+59
-108
lines changed

7 files changed

+59
-108
lines changed

Include/internal/pycore_uop_metadata.h

Lines changed: 3 additions & 3 deletions
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,7 @@ def test_array_input(self):
793793
input = """
794794
inst(OP, (below, values[oparg*2], above --)) {
795795
SPAM(values, oparg);
796+
DEAD(values);
796797
}
797798
"""
798799
output = """
@@ -1056,6 +1057,7 @@ def test_array_of_one(self):
10561057
input = """
10571058
inst(OP, (arg[1] -- out[1])) {
10581059
out[0] = arg[0];
1060+
DEAD(arg);
10591061
}
10601062
"""
10611063
output = """

Python/bytecodes.c

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,6 +1927,7 @@ dummy_func(
19271927
PyStackRef_CLOSE(value);
19281928
}
19291929
}
1930+
DEAD(values);
19301931
if (err) {
19311932
Py_DECREF(set_o);
19321933
ERROR_IF(true, error);
@@ -3583,15 +3584,15 @@ dummy_func(
35833584
#endif /* ENABLE_SPECIALIZATION_FT */
35843585
}
35853586

3586-
op(_MAYBE_EXPAND_METHOD, (callable[1], self_or_null[1], args[oparg] -- func[1], maybe_self[1], args[oparg])) {
3587+
op(_MAYBE_EXPAND_METHOD, (callable[1], self_or_null[1], args[oparg] -- callable[1], self_or_null[1], args[oparg])) {
35873588
(void)args;
35883589
if (PyStackRef_TYPE(callable[0]) == &PyMethod_Type && PyStackRef_IsNull(self_or_null[0])) {
35893590
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
35903591
PyObject *self = ((PyMethodObject *)callable_o)->im_self;
3591-
maybe_self[0] = PyStackRef_FromPyObjectNew(self);
3592+
self_or_null[0] = PyStackRef_FromPyObjectNew(self);
35923593
PyObject *method = ((PyMethodObject *)callable_o)->im_func;
35933594
_PyStackRef temp = callable[0];
3594-
func[0] = PyStackRef_FromPyObjectNew(method);
3595+
callable[0] = PyStackRef_FromPyObjectNew(method);
35953596
PyStackRef_CLOSE(temp);
35963597
}
35973598
}
@@ -3618,6 +3619,9 @@ dummy_func(
36183619
tstate, callable[0], locals,
36193620
arguments, total_args, NULL, frame
36203621
);
3622+
DEAD(args);
3623+
DEAD(self_or_null);
3624+
DEAD(callable);
36213625
// Manipulate stack directly since we leave using DISPATCH_INLINED().
36223626
SYNC_SP();
36233627
// The frame has stolen all the arguments from the stack,
@@ -3950,10 +3954,10 @@ dummy_func(
39503954
_CALL_TUPLE_1 +
39513955
_CHECK_PERIODIC;
39523956

3953-
op(_CHECK_AND_ALLOCATE_OBJECT, (type_version/2, callable[1], null[1], args[oparg] -- init[1], self[1], args[oparg])) {
3957+
op(_CHECK_AND_ALLOCATE_OBJECT, (type_version/2, callable[1], self_or_null[1], args[oparg] -- callable[1], self_or_null[1], args[oparg])) {
39543958
(void)args;
39553959
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
3956-
DEOPT_IF(!PyStackRef_IsNull(null[0]));
3960+
DEOPT_IF(!PyStackRef_IsNull(self_or_null[0]));
39573961
DEOPT_IF(!PyType_Check(callable_o));
39583962
PyTypeObject *tp = (PyTypeObject *)callable_o;
39593963
DEOPT_IF(FT_ATOMIC_LOAD_UINT32_RELAXED(tp->tp_version_tag) != type_version);
@@ -3969,9 +3973,9 @@ dummy_func(
39693973
if (self_o == NULL) {
39703974
ERROR_NO_POP();
39713975
}
3972-
self[0] = PyStackRef_FromPyObjectSteal(self_o);
3976+
self_or_null[0] = PyStackRef_FromPyObjectSteal(self_o);
39733977
_PyStackRef temp = callable[0];
3974-
init[0] = PyStackRef_FromPyObjectNew(init_func);
3978+
callable[0] = PyStackRef_FromPyObjectNew(init_func);
39753979
PyStackRef_CLOSE(temp);
39763980
}
39773981

@@ -3986,6 +3990,7 @@ dummy_func(
39863990
DEAD(self);
39873991
_PyInterpreterFrame *temp = _PyEvalFramePushAndInit(
39883992
tstate, init[0], NULL, args-1, oparg+1, NULL, shim);
3993+
DEAD(args);
39893994
SYNC_SP();
39903995
if (temp == NULL) {
39913996
_PyEval_FrameClearAndPop(tstate, shim);
@@ -4420,15 +4425,15 @@ dummy_func(
44204425
ERROR_IF(err, error);
44214426
}
44224427

4423-
op(_MAYBE_EXPAND_METHOD_KW, (callable[1], self_or_null[1], args[oparg], kwnames_in -- func[1], maybe_self[1], args[oparg], kwnames_out)) {
4428+
op(_MAYBE_EXPAND_METHOD_KW, (callable[1], self_or_null[1], args[oparg], kwnames_in -- callable[1], self_or_null[1], args[oparg], kwnames_out)) {
44244429
(void)args;
44254430
if (PyStackRef_TYPE(callable[0]) == &PyMethod_Type && PyStackRef_IsNull(self_or_null[0])) {
44264431
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
44274432
PyObject *self = ((PyMethodObject *)callable_o)->im_self;
4428-
maybe_self[0] = PyStackRef_FromPyObjectNew(self);
4433+
self_or_null[0] = PyStackRef_FromPyObjectNew(self);
44294434
PyObject *method = ((PyMethodObject *)callable_o)->im_func;
44304435
_PyStackRef temp = callable[0];
4431-
func[0] = PyStackRef_FromPyObjectNew(method);
4436+
callable[0] = PyStackRef_FromPyObjectNew(method);
44324437
PyStackRef_CLOSE(temp);
44334438
}
44344439
kwnames_out = kwnames_in;
@@ -4458,6 +4463,9 @@ dummy_func(
44584463
tstate, callable[0], locals,
44594464
arguments, positional_args, kwnames_o, frame
44604465
);
4466+
DEAD(args);
4467+
DEAD(self_or_null);
4468+
DEAD(callable);
44614469
PyStackRef_CLOSE(kwnames);
44624470
// Sync stack explicitly since we leave using DISPATCH_INLINED().
44634471
SYNC_SP();
@@ -4525,6 +4533,9 @@ dummy_func(
45254533
PyStackRef_CLOSE(kwnames);
45264534
// The frame has stolen all the arguments from the stack,
45274535
// so there is no need to clean them up.
4536+
DEAD(args);
4537+
DEAD(self_or_null);
4538+
DEAD(callable);
45284539
SYNC_SP();
45294540
ERROR_IF(temp == NULL, error);
45304541
new_frame = temp;

Python/executor_cases.c.h

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

0 commit comments

Comments
 (0)