Skip to content

gh-145742: Pre-tag operands for _LOAD_CONST_INLINE_BORROW variants#148081

Open
corona10 wants to merge 13 commits intopython:mainfrom
corona10:gh-145742-work
Open

gh-145742: Pre-tag operands for _LOAD_CONST_INLINE_BORROW variants#148081
corona10 wants to merge 13 commits intopython:mainfrom
corona10:gh-145742-work

Conversation

@corona10
Copy link
Copy Markdown
Member

@corona10 corona10 commented Apr 4, 2026

@corona10
Copy link
Copy Markdown
Member Author

corona10 commented Apr 5, 2026

@Fidget-Spinner @markshannon PTAL when you have times :)

@corona10
Copy link
Copy Markdown
Member Author

corona10 commented Apr 8, 2026

I’ve just resolved all the conflicts. Gentle ping to @markshannon and @Fidget-Spinner.

@markshannon
Copy link
Copy Markdown
Member

Thanks for doing this.

There is work underway to remove the many variants of _LOAD_CONST_INLINE_BORROW that also pop, swap or rotate.
Once that work is done, this PR should become much simpler.
I'd recommend leaving this for a week or two before attempting to resolve conflicts.

@corona10
Copy link
Copy Markdown
Member Author

corona10 commented Apr 9, 2026

Got it

@corona10
Copy link
Copy Markdown
Member Author

@markshannon I've resolved conflicts with the latest main and simplified the pre-tagging/untagging to be path-based (auto-tagging in add_op() when the opcode is a BORROW variant). PTAL.

Copy link
Copy Markdown
Member

@markshannon markshannon left a comment

Choose a reason for hiding this comment

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

Have you tested this with Py_STACKREF_DEBUG set?

#define PyStackRef_FromPreTagged(ptr) _PyStackRef_FromPreTagged((uintptr_t)(ptr))

/* Tag a PyObject pointer as a borrowed operand for BORROW variants. */
#define PyStackRef_TagBorrow(ptr) \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Doesn't it need defining for Py_STACKREF_DEBUG as well?
Can you make this an inline function, for type safety?

Comment thread Python/executor_cases.c.h
PyObject *ptr = (PyObject *)CURRENT_OPERAND0_64();
value = PyStackRef_FromPyObjectBorrow(ptr);
_PyFrame_SetStackPointer(frame, stack_pointer);
value = PyStackRef_FromPreTagged(ptr);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You need to whitelist PyStackRef_FromPreTagged as non-escaping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants