8000 GH-132554: "Virtual" iterators by markshannon · Pull Request #132555 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
8000

GH-132554: "Virtual" iterators #132555

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 29 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7476442
FOR_ITER now pushes NULL as well as the iterator. Preparation for vir…
markshannon Apr 10, 2025
38a429f
use tagged ints for indexes. Work in progress
markshannon Apr 11, 2025
2caf56f
Remove debug code
markshannon Apr 15, 2025
588943a
Regenerate files
markshannon Apr 15, 2025
aa62e39
Tidy up list of non-escaping functions
markshannon Apr 16, 2025
88562ec
Fix up list iteration for FT build
markshannon Apr 16, 2025
025049d
Fix tier 2 FT build
markshannon Apr 16, 2025
35e389d
Remove debugging code
markshannon Apr 30, 2025
e8f4ce6
Merge branch 'main' into virtual-iterators
markshannon Apr 30, 2025
ed89950
Rename function
markshannon Apr 30, 2025
ec8d797
Restrict specialization in free-threaded build
markshannon Apr 30, 2025
cad1946
Merge branch 'main' into virtual-iterators
markshannon Apr 30, 2025
428735b
Add news
markshannon Apr 30, 2025
4c83848
handle tagged ints when doing type checks
markshannon Apr 30, 2025
f43ccc3
Fix long check
markshannon Apr 30, 2025
3fd46c3
Attempt to make _PyForIter_NextWithIndex thread safe.
markshannon Apr 30, 2025
433282f
Add review comment
markshannon Apr 30, 2025
e915a05
Simplify list indexing code
markshannon May 8, 2025
69a328d
Merge branch 'main' into virtual-iterators
markshannon May 8, 2025
6d1b93e
GET_ITER may leave the iterable on the stack
markshannon May 8, 2025
37ca285
Fix test_dis
markshannon May 8, 2025
f3b9074
Merge branch 'main' into virtual-iterators
markshannon May 19, 2025
0efab59
Merge branch 'main' into virtual-iterators
markshannon May 20, 2025
a0d814b
Merge branch 'main' into virtual-iterators
markshannon May 22, 2025
5cd55c4
Merge branch 'main' into virtual-iterators
markshannon May 22, 2025
867bd10
Merge branch 'main' into virtual-iterators
markshannon May 22, 2025
d9dc597
Clarify assert
markshannon May 27, 2025
d60ef23
Checked for tagged ints
markshannon May 27, 2025
9a9d20d
Address review comments
markshannon May 27, 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
8000
Diff view
Prev Previous commit
Next Next commit
Restrict specialization in free-threaded build
  • Loading branch information
markshannon committed Apr 30, 2025
commit ec8d7970c69fa36b19ff20cb38a1ee015ca9b75d
3 changes: 0 additions & 3 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3286,9 +3286,6 @@ dummy_func(
PyObject *iter_o = PyStackRef_AsPyObjectBorrow(iter);
EXIT_IF(Py_TYPE(iter_o) != &PyTuple_Type);
assert(PyStackRef_IsTaggedInt(null_or_index));
#ifdef Py_GIL_DISABLED
EXIT_IF(!_PyObject_IsUniquelyReferenced(iter_o));
#endif
}

replaced op(_ITER_JUMP_TUPLE, (iter, null_or_index -- iter, null_or_index)) {
Expand Down
6 changes: 0 additions & 6 deletions Python/executor_cases.c.h

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

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

21 changes: 16 additions & 5 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -2904,13 +2904,18 @@ _Py_Specialize_ForIter(_PyStackRef iter, _PyStackRef null_or_index, _Py_CODEUNIT
assert(_PyOpcode_Caches[FOR_ITER] == INLINE_CACHE_ENTRIES_FOR_ITER);
PyObject *iter_o = PyStackRef_AsPyObjectBorrow(iter);
PyTypeObject *tp = Py_TYPE(iter_o);

if (PyStackRef_IsNull(null_or_index)) {
#ifdef Py_GIL_DISABLED
// Only specialize for lists owned by this thread or shared
if (!_Py_IsOwnedByCurrentThread(iter_o) && !_PyObject_GC_IS_SHARED(iter_o)) {
goto failure;
}
// Only specialize for uniquely referenced iterators, so that we know
// they're only referenced by this one thread. This is more limiting
// than we need (even `it = iter(mylist); for item in it:` won't get
// specialized) but we don't have a way to check whether we're the only
// _thread_ who has access to the object.
if (!_PyObject_IsUniquelyReferenced(iter_o)) {
goto failure;
}
#endif
if (PyStackRef_IsNull(null_or_index)) {
if (tp == &PyRangeIter_Type) {
specialize(instr, FOR_ITER_RANGE);
return;
Expand All @@ -2930,6 +2935,12 @@ _Py_Specialize_ForIter(_PyStackRef iter, _PyStackRef null_or_index, _Py_CODEUNIT
}
else {
if (tp == &PyList_Type) {
#ifdef Py_GIL_DISABLED
// Only specialize for lists owned by this thread or shared
if (!_Py_IsOwnedByCurrentThread(iter_o) && !_PyObject_GC_IS_SHARED(iter_o)) {
goto failure;
}
#endif
specialize(instr, FOR_ITER_LIST);
return;
}
Expand Down
0