Skip to content

Commit 38a429f

Browse files
committed
use tagged ints for indexes. Work in progress
1 parent 7476442 commit 38a429f

16 files changed

+420
-372
lines changed

Include/internal/pycore_ceval.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,8 @@ PyAPI_FUNC(_PyStackRef) _PyFloat_FromDouble_ConsumeInputs(_PyStackRef left, _PyS
377377
extern int _PyRunRemoteDebugger(PyThreadState *tstate);
378378
#endif
379379

380+
_PyStackRef _PyForIter_NextWithIndex(PyObject *seq, _PyStackRef index);
381+
380382
#ifdef __cplusplus
381383
}
382384
#endif

Include/internal/pycore_code.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ extern void _Py_Specialize_CompareOp(_PyStackRef lhs, _PyStackRef rhs,
313313
_Py_CODEUNIT *instr, int oparg);
314314
extern void _Py_Specialize_UnpackSequence(_PyStackRef seq, _Py_CODEUNIT *instr,
315315
int oparg);
316-
extern void _Py_Specialize_ForIter(_PyStackRef iter, _Py_CODEUNIT *instr, int oparg);
316+
extern void _Py_Specialize_ForIter(_PyStackRef iter, _PyStackRef null_or_index, _Py_CODEUNIT *instr, int oparg);
317317
extern void _Py_Specialize_Send(_PyStackRef receiver, _Py_CODEUNIT *instr);
318318
extern void _Py_Specialize_ToBool(_PyStackRef value, _Py_CODEUNIT *instr);
319319
extern void _Py_Specialize_ContainsOp(_PyStackRef value, _Py_CODEUNIT *instr);

Include/internal/pycore_opcode_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_stackref.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ extern intptr_t PyStackRef_UntagInt(_PyStackRef ref);
233233

234234
extern _PyStackRef PyStackRef_TagInt(intptr_t i);
235235

236+
extern _PyStackRef PyStackRef_IncrementTaggedInt(_PyStackRef ref);
237+
236238
extern bool
237239
PyStackRef_IsNullOrInt(_PyStackRef ref);
238240

@@ -262,6 +264,14 @@ PyStackRef_UntagInt(_PyStackRef i)
262264
}
263265

264266

267+
static inline _PyStackRef
268+
PyStackRef_IncrementTaggedInt(_PyStackRef ref)
269+
{
270+
assert(ref.bits != (uintptr_t)-1); // Overflow
271+
return (_PyStackRef){ .bits = ref.bits + 4 };
272+
}
273+
274+
265275
#ifdef Py_GIL_DISABLED
266276

267277
#define Py_TAG_DEFERRED (1)
@@ -686,7 +696,13 @@ PyStackRef_XCLOSE(_PyStackRef ref)
686696

687697
#endif // !defined(Py_GIL_DISABLED) && defined(Py_STACKREF_DEBUG)
688698

689-
#define PyStackRef_TYPE(stackref) Py_TYPE(PyStackRef_AsPyObjectBorrow(stackref))
699+
static inline PyTypeObject *
700+
PyStackRef_TYPE(_PyStackRef stackref) {
701+
if (PyStackRef_IsTaggedInt(stackref)) {
702+
return &PyLong_Type;
703+
}
704+
return Py_TYPE(PyStackRef_AsPyObjectBorrow(stackref));
705+
}
690706

691707
// Converts a PyStackRef back to a PyObject *, converting the
692708
// stackref to a new reference.

Include/internal/pycore_uop_ids.h

Lines changed: 1 addition & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)