Skip to content

GH-127705: Use _PyStackRefs in the default build. #127875

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 75 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
2ec65dc
Initial implementation of tagged stackrefs for GIL build. Requires fi…
markshannon Oct 9, 2024
9a5c3a6
Merge branch 'main' into use-stackrefs
markshannon Oct 11, 2024
ee7f3a6
Streamline PyStackRef_XCLOSE and PyStackRef_CLEAR.
markshannon Oct 11, 2024
21d7e87
Fix error handling with not stackref outputs in code generator
markshannon Oct 11, 2024
370e77b
Merge branch 'main' into use-stackrefs
markshannon Oct 14, 2024
2636c04
Attempt to fix _BINARY_OP_INPLACE_ADD_UNICODE and use tag references …
markshannon Oct 14, 2024
5a38e03
Merge branch 'main' into use-stackrefs
markshannon Oct 14, 2024
a79aa47
Show frame locals in lltrace
markshannon Oct 14, 2024
a90e644
Fix _PyFrame_Copy and add some asserts to make reference heap safe
markshannon Oct 15, 2024
83e0323
Improve efficiency of _PyStackRef_FromPyObjectNew a bit
markshannon Oct 16, 2024
7fb6a48
Merge branch 'main' into use-stackrefs
markshannon Oct 22, 2024
7e6deef
Merge branch 'main' into use-stackrefs
markshannon Oct 29, 2024
f03f745
Make making heap safe more efficient
markshannon Oct 29, 2024
67670f0
Merge branch 'main' into use-stackrefs
markshannon Dec 2, 2024
ff9d044
Fix up after merge
markshannon Dec 2, 2024
3334c14
Merge branch 'main' into use-stackrefs
markshannon Dec 4, 2024
b7a8b5d
Restore immortality bit
markshannon Dec 4, 2024
49d0d42
Fix validity check
markshannon Dec 4, 2024
3a12d18
Add PyStackRef_IsMortal
markshannon Dec 5, 2024
497fb9f
Reduce overhead of stackrefs a tiny bit for mortal objects
markshannon Dec 5, 2024
4768a38
Merge branch 'main' into use-stackrefs
markshannon Dec 5, 2024
806c28a
Attempt to use tagged RC for a bit of extra speed
markshannon Dec 5, 2024
c540f28
Merge branch 'main' into use-stackrefs
markshannon Dec 6, 2024
0c20416
Revert addition of LOAD_FAST_WITH_COUNT
markshannon Dec 6, 2024
c88bcbc
Avoid INCREF + Steal pairs by using New or return stack ref directly
markshannon Dec 6, 2024
f5dec96
Avoid masking when comparing to True and False
markshannon Dec 6, 2024
bf2dca5
Merge branch 'main' into use-stackrefs
markshannon Dec 10, 2024
1069d98
Revert not-quite-true assert
markshannon Dec 10, 2024
2e752fc
Merge branch 'main' into use-stackrefs
markshannon Dec 12, 2024
d23ae47
Fix up after merge
markshannon Dec 12, 2024
382d101
Merge branch 'main' into use-stackrefs
markshannon Dec 13, 2024
d230f68
Fix compiler errors and warnings
markshannon Dec 13, 2024
1de6add
Merge branch 'main' into use-stackrefs
markshannon Dec 18, 2024
ad7e1e6
Merge branch 'main' into use-stackrefs
markshannon Dec 20, 2024
c96387a
Merge branch 'main' into use-stackrefs
markshannon Feb 4, 2025
69e993c
Post merge fix up
markshannon Feb 4, 2025
2a361c9
Merge branch 'main' into use-stackrefs
markshannon Feb 17, 2025
2efa0bd
Post merge fixups
markshannon Feb 17, 2025
036ffc5
Post merge fixup 2
markshannon Feb 17, 2025
ea43b6d
Revert changes to _PyLong_Add as not relevant to this PR
markshannon Feb 17, 2025
db7e049
Fix up a couple of comments
markshannon Feb 17, 2025
26e7868
Add news
markshannon Feb 17, 2025
d3da41c
Clarifications
markshannon Feb 17, 2025
9711f62
Fixup comments
markshannon Feb 17, 2025
d61e0bf
Tidy up frame ownership changes
markshannon Feb 17, 2025
2bc9ace
Get Py_STACKREF_DEBUG working again
markshannon Feb 18, 2025
12b961b
Turn off Py_STACKREF_DEBUG
markshannon Feb 18, 2025
00cd065
Reduce diff
markshannon Feb 18, 2025
0bea1f1
Reduce diff
markshannon Feb 18, 2025
0bae25d
Reduce diff
markshannon Feb 18, 2025
327f5c3
Merge branch 'main' into use-stackrefs
markshannon Feb 18, 2025
a527aaf
Fix immortality test
markshannon Feb 18, 2025
375bd16
Merge remote-tracking branch 'faster/use-stackrefs' into use-stackrefs
markshannon Feb 18, 2025
3b25dc3
Merge branch 'main' into use-stackrefs
markshannon Feb 19, 2025
56509f4
Add some asserts
markshannon Feb 19, 2025
d270553
Fix refcount accounting
markshannon Feb 20, 2025
98e132b
Use Sam's suggestion to avoid branching
markshannon Feb 20, 2025
522c0e7
Merge branch 'main' into use-stackrefs
markshannon Feb 25, 2025
b1edb96
Post merge fixup
markshannon Feb 25, 2025
4b0ef08
Revert changes to nogil flags
markshannon Feb 25, 2025
c501175
Revert erroneous change to FT refcount initialization
markshannon Feb 27, 2025
4702d58
Use macros on Windows
markshannon Feb 25, 2025
3e64d74
Fix typo
markshannon Feb 26, 2025
0b7a544
Fix macro
markshannon Feb 27, 2025
17b97c6
Make sure PyStackRef_DUP returns a reference
markshannon Feb 27, 2025
bf863cd
Avoid branch for known mortal objects
markshannon Feb 27, 2025
b7b9c6a
Merge branch 'main' into use-stackrefs
markshannon Feb 28, 2025
1e66e50
Don't evaluate macro argument twice
markshannon Feb 28, 2025
3e929d7
Add missing backslash
markshannon Feb 28, 2025
3ef8571
Merge branch 'main' into use-stackrefs
markshannon Mar 3, 2025
e2f1387
Update Misc/NEWS.d/next/Core_and_Builtins/2025-02-17-12-48-00.gh-issu…
markshannon Mar 3, 2025
36f6034
Use consistent return types for PyStackRef_IsHeapSafe
markshannon Mar 5, 2025
0f9c865
Drop 'immortal' bit. Only use 'counted' bit.
markshannon Mar 7, 2025
37f1e18
Remove use of Py_TAG_IMMORTAL
markshannon Mar 7, 2025
d744179
Rename functions and add comment
markshannon Mar 10, 2025
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 Include/internal/pycore_ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ _Py_eval_breaker_bit_is_set(PyThreadState *tstate, uintptr_t bit)
void _Py_set_eval_breaker_bit_all(PyInterpreterState *interp, uintptr_t bit);
void _Py_unset_eval_breaker_bit_all(PyInterpreterState *interp, uintptr_t bit);

PyAPI_FUNC(PyObject *) _PyFloat_FromDouble_ConsumeInputs(_PyStackRef left, _PyStackRef right, double value);
PyAPI_FUNC(_PyStackRef) _PyFloat_FromDouble_ConsumeInputs(_PyStackRef left, _PyStackRef right, double value);

#ifdef __cplusplus
}
Expand Down
25 changes: 17 additions & 8 deletions Include/internal/pycore_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,26 @@ _PyFrame_NumSlotsForCodeObject(PyCodeObject *code)

static inline void _PyFrame_Copy(_PyInterpreterFrame *src, _PyInterpreterFrame *dest)
{
*dest = *src;
dest->f_executable = PyStackRef_MakeHeapSafe(src->f_executable);
// Don't leave a dangling pointer to the old frame when creating generators
// and coroutines:
dest->previous = NULL;
dest->f_funcobj = PyStackRef_MakeHeapSafe(src->f_funcobj);
dest->f_globals = src->f_globals;
dest->f_builtins = src->f_builtins;
dest->f_locals = src->f_locals;
dest->frame_obj = src->frame_obj;
dest->instr_ptr = src->instr_ptr;
#ifdef Py_GIL_DISABLED
dest->tlbc_index = src->tlbc_index;
#endif
assert(src->stackpointer != NULL);
int stacktop = (int)(src->stackpointer - src->localsplus);
assert(stacktop >= _PyFrame_GetCode(src)->co_nlocalsplus);
assert(stacktop >= 0);
dest->stackpointer = dest->localsplus + stacktop;
for (int i = 1; i < stacktop; i++) {
dest->localsplus[i] = src->localsplus[i];
for (int i = 0; i < stacktop; i++) {
dest->localsplus[i] = PyStackRef_MakeHeapSafe(src->localsplus[i]);
}
// Don't leave a dangling pointer to the old frame when creating generators
// and coroutines:
dest->previous = NULL;
}

#ifdef Py_GIL_DISABLED
Expand Down Expand Up @@ -393,7 +402,7 @@ _PyFrame_PushTrampolineUnchecked(PyThreadState *tstate, PyCodeObject *code, int

PyAPI_FUNC(_PyInterpreterFrame *)
_PyEvalFramePushAndInit(PyThreadState *tstate, _PyStackRef func,
PyObject *locals, _PyStackRef const* args,
PyObject *locals, _PyStackRef const *args,
size_t argcount, PyObject *kwnames,
_PyInterpreterFrame *previous);

Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ PyAPI_FUNC(int) _PyObject_IsFreed(PyObject *);
#define _PyObject_HEAD_INIT(type) \
{ \
.ob_refcnt = _Py_IMMORTAL_INITIAL_REFCNT, \
.ob_flags = _Py_STATICALLY_ALLOCATED_FLAG, \
.ob_flags = _Py_STATIC_FLAG_BITS, \
.ob_type = (type) \
}
#else
Expand Down
6 changes: 3 additions & 3 deletions Include/internal/pycore_opcode_metadata.h

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

Loading
Loading