Skip to content

GH-115419: Improve list of escaping functions #118054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2024
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
24 changes: 12 additions & 12 deletions Include/internal/pycore_opcode_metadata.h

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

24 changes: 12 additions & 12 deletions Include/internal/pycore_uop_metadata.h

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

4 changes: 3 additions & 1 deletion Python/optimizer_analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,9 @@ remove_unneeded_uops(_PyUOpInstruction *buffer, int buffer_size)
return pc + 1;
default:
{
bool needs_ip = false;
/* _PUSH_FRAME doesn't escape or error, but it
* does need the IP for the return address */
bool needs_ip = opcode == _PUSH_FRAME;
if (_PyUop_Flags[opcode] & HAS_ESCAPES_FLAG) {
needs_ip = true;
may_have_escaped = true;
Expand Down
10 changes: 10 additions & 0 deletions Tools/cases_generator/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,15 @@ def has_error_without_pop(op: parser.InstDef) -> bool:
"_PyObject_InlineValues",
"_PyDictValues_AddToInsertionOrder",
"Py_DECREF",
"Py_XDECREF",
Comment on lines 360 to +361
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would seem technically wrong to treat decref as non-escaping, but I understand it's expedient and also 99.999% correct. Or am I missing something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct. We already have Py_DECREF on this list, so adding Py_XDECREF is consistent.

"_Py_DECREF_SPECIALIZED",
"DECREF_INPUTS_AND_REUSE_FLOAT",
"PyUnicode_Append",
"_PyLong_IsZero",
"Py_SIZE",
"Py_TYPE",
"PyList_GET_ITEM",
"PyList_SET_ITEM",
"PyTuple_GET_ITEM",
"PyList_GET_SIZE",
"PyTuple_GET_SIZE",
Expand Down Expand Up @@ -400,8 +402,14 @@ def has_error_without_pop(op: parser.InstDef) -> bool:
"PySlice_New",
"_Py_LeaveRecursiveCallPy",
"CALL_STAT_INC",
"STAT_INC",
"maybe_lltrace_resume_frame",
"_PyUnicode_JoinArray",
"_PyEval_FrameClearAndPop",
"_PyFrame_StackPush",
"PyCell_New",
"PyFloat_AS_DOUBLE",
"_PyFrame_PushUnchecked",
)

ESCAPING_FUNCTIONS = (
Expand All @@ -427,6 +435,8 @@ def makes_escaping_api_call(instr: parser.InstDef) -> bool:
continue
if tkn.text in ESCAPING_FUNCTIONS:
return True
if tkn.text == "tp_vectorcall":
return True
if not tkn.text.startswith("Py") and not tkn.text.startswith("_Py"):
continue
if tkn.text.endswith("Check"):
Expand Down
Loading