Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
0e995ad
wip: update type slots, stop-the-world
nascheme Mar 12, 2025
b173f17
Remove unneeded atomics for tp_flags.
nascheme Mar 13, 2025
d4ce112
Use stop-the-world for tp_flag changes too.
nascheme Mar 13, 2025
44eb332
Remove 'world_stops' and 'sys._get_world_stops'.
nascheme Mar 14, 2025
d132fab
Improve code comments.
nascheme Mar 14, 2025
658bcd5
Remove TSAN suppressions that seem unneeded.
nascheme Mar 14, 2025
ef2f07b
Add NEWS file.
nascheme Mar 14, 2025
ce8536d
Use mutex rather than critical sections.
nascheme Mar 22, 2025
b97a4b4
Merge 'origin/main' into gh-127266-type-slots-ts
nascheme Mar 26, 2025
ca00e74
Fix non-debug build.
nascheme Mar 26, 2025
6db4542
Improve comments.
nascheme Mar 26, 2025
398ac14
Merge 'origin/main' into gh-127266-type-slots-ts
nascheme Mar 27, 2025
75d6b71
Avoid unused function warning.
nascheme Mar 27, 2025
895a86a
Remove unwanted suppression (bad merge).
nascheme Mar 31, 2025
65e40f4
Fixes based on review feedback.
nascheme Mar 31, 2025
b68f1a1
Remove spurious assert().
nascheme Mar 31, 2025
9976b32
Merge 'origin/main' into gh-127266-type-slots-ts
nascheme Apr 1, 2025
1b84486
Omit mutex_tid member from default build.
nascheme Apr 1, 2025
2af9e49
Remove Py_TPFLAGS_EXPOSED flag and related logic.
nascheme Apr 1, 2025
f65e87c
Improve comment for TYPE_LOCK.
nascheme Apr 1, 2025
395a6d3
Re-add the ASSERT_NEW_OR_STOPPED() asserts.
nascheme Apr 1, 2025
e4f87e5
Further cleanups of the locking in typeobject.
nascheme Apr 3, 2025
2a66555
Fix data race in resolve_slotdups().
nascheme Apr 3, 2025
2efac26
Fix comment.
nascheme Apr 3, 2025
f7d2d36
Make the init of tp_dict thread-safe.
nascheme Apr 9, 2025
f3fd35a
Do some addtional locking simplification.
nascheme Apr 9, 2025
57c2a44
Avoid acquiring the types mutex if version is set.
nascheme Apr 10, 2025
7c0ccf5
Add check_invalid_reentrancy() call.
nascheme Apr 17, 2025
4fa77bb
Fix additional re-entrancy issues found.
nascheme Apr 17, 2025
caf6554
Add comment explaining class_name() code.
nascheme Apr 17, 2025
803d703
Merge 'origin/main' into gh-127266-type-slots-ts
nascheme Apr 17, 2025
90ea541
Use atomic load to avoid thread safety issue.
nascheme Apr 17, 2025
0dc0faf
Fix default debug build.
nascheme Apr 17, 2025
956e5d1
Move declaration to avoid syntax error.
nascheme Apr 17, 2025
2bb710c
Remove _PyType_GetVersionForCurrentState, unused.
nascheme Apr 21, 2025
3a9bc96
Fix for possible re-entrancy in has_custom_mro().
nascheme Apr 21, 2025
d742a53
Use correct FT_ATOMIC_ macro.
nascheme Apr 21, 2025
e7480c3
Remove TSAN suppression for 'assign_version_tag'.
nascheme Apr 21, 2025
e2ea281
Small efficiency fix for types_mutex_set_owned().
nascheme Apr 21, 2025
935bfca
Revert to using critical section with TYPE_LOCK.
nascheme Apr 21, 2025
1cff448
Merge 'origin/main' into gh-127266-type-slots-ts
nascheme Apr 21, 2025
a81e9e3
Invalidate type cache before calling watchers.
nascheme Apr 21, 2025
f5df0c3
Fixes for type_modified_unlocked().
nascheme Apr 22, 2025
7db281c
Major re-work, TYPE_LOCK protects more things.
nascheme Apr 22, 2025
da2a0ad
Merge 'origin/main' into gh-127266-type-slots-ts
nascheme Apr 23, 2025
986f23a
Fix non-debug build.
nascheme Apr 23, 2025
c404ed4
Revert unneeded code changes.
nascheme Apr 23, 2025
55af4ba
Merge branch 'origin/main' into gh-127266-type-slots-ts
nascheme Apr 23, 2025
0eb77da
Restore comment
nascheme Apr 24, 2025
16f15b2
Revert more changes.
nascheme Apr 24, 2025
0c328cc
Merge 'origin/main' into gh-127266-type-slots-ts
nascheme Apr 25, 2025
64547e9
Reduce item list size for a few tests.
nascheme Apr 25, 2025
fff1bd2
Merge 'origin/main' into gh-127266-type-slots-ts
nascheme Apr 28, 2025
5672352
Minor code tidy.
nascheme Apr 28, 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
Prev Previous commit
Next Next commit
Remove Py_TPFLAGS_EXPOSED flag and related logic.
This was useful for debugging logic but we don't want to use an
additional type flag.
  • Loading branch information
nascheme committed Apr 1, 2025
commit 2af9e4954d8cf58481203e21ce4185d1293209f4
4 changes: 2 additions & 2 deletions Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,8 @@ given type object has a specified feature.
/* Objects behave like an unbound method */
#define Py_TPFLAGS_METHOD_DESCRIPTOR (1UL << 17)

/* Type structure is potentially exposed (revealed) to other threads */
#define Py_TPFLAGS_EXPOSED (1UL << 19)
/* Unused. Legacy flag */
#define Py_TPFLAGS_VALID_VERSION_TAG (1UL << 19)

/* Type is abstract and cannot be instantiated */
#define Py_TPFLAGS_IS_ABSTRACT (1UL << 20)
Expand Down
25 changes: 0 additions & 25 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@ types_world_is_stopped(void)
return interp->stoptheworld.world_stopped;
}

// Checks that either the type has not yet been exposed (revealed) to other
// threads (it was newly created and the Py_TPFLAGS_EXPOSED flag is not set
// yet) or the world is stopped and we can safely update it without races.
#define ASSERT_NEW_OR_STOPPED(tp) \
assert((((tp)->tp_flags & Py_TPFLAGS_EXPOSED) == 0) || types_world_is_stopped())

static void
types_stop_world(void)
{
Expand Down Expand Up @@ -166,7 +160,6 @@ types_mutex_unlock(void)
#define types_stop_world()
#define types_start_world()
#define ASSERT_TYPE_LOCK_HELD()
#define ASSERT_NEW_OR_STOPPED(tp)

#endif

Expand Down Expand Up @@ -436,15 +429,13 @@ type_set_flags(PyTypeObject *tp, unsigned long flags)
// be active).
ASSERT_TYPE_LOCK_HELD();
}
ASSERT_NEW_OR_STOPPED(tp);
tp->tp_flags = flags;
}

static void
type_set_flags_with_mask(PyTypeObject *tp, unsigned long mask, unsigned long flags)
{
ASSERT_TYPE_LOCK_HELD();
ASSERT_NEW_OR_STOPPED(tp);
unsigned long new_flags = (tp->tp_flags & ~mask) | flags;
type_set_flags(tp, new_flags);
}
Expand Down Expand Up @@ -580,7 +571,6 @@ static inline void
set_tp_bases(PyTypeObject *self, PyObject *bases, int initial)
{
assert(PyTuple_CheckExact(bases));
ASSERT_NEW_OR_STOPPED(self);
if (self->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN) {
// XXX tp_bases can probably be statically allocated for each
// static builtin type.
Expand Down Expand Up @@ -638,7 +628,6 @@ _PyType_GetMRO(PyTypeObject *self)
static inline void
set_tp_mro(PyTypeObject *self, PyObject *mro, int initial)
{
ASSERT_NEW_OR_STOPPED(self);
if (mro != NULL) {
assert(PyTuple_CheckExact(mro));
if (self->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN) {
Expand Down Expand Up @@ -1717,7 +1706,6 @@ static int
mro_hierarchy(PyTypeObject *type, PyObject *temp)
{
ASSERT_TYPE_LOCK_HELD();
ASSERT_NEW_OR_STOPPED(type);

PyObject *old_mro;
int res = mro_internal(type, &old_mro);
Expand Down Expand Up @@ -3564,7 +3552,6 @@ static int
mro_internal_unlocked(PyTypeObject *type, int initial, PyObject **p_old_mro)
{
ASSERT_TYPE_LOCK_HELD();
ASSERT_NEW_OR_STOPPED(type);

PyObject *new_mro, *old_mro;
int reent;
Expand Down Expand Up @@ -3614,7 +3601,6 @@ static int
mro_internal(PyTypeObject *type, PyObject **p_old_mro)
{
int res;
ASSERT_NEW_OR_STOPPED(type);
res = mro_internal_unlocked(type, 0, p_old_mro);
return res;
}
Expand Down Expand Up @@ -4694,8 +4680,6 @@ type_new_impl(type_new_ctx *ctx)
}

assert(_PyType_CheckConsistency(type));
// After this point, other threads can potentally use this type.
type->tp_flags |= Py_TPFLAGS_EXPOSED;

return (PyObject *)type;

Expand Down Expand Up @@ -5409,8 +5393,6 @@ PyType_FromMetaclass(
}

assert(_PyType_CheckConsistency(type));
// After this point, other threads can potentally use this type.
type->tp_flags |= Py_TPFLAGS_EXPOSED;

finally:
if (PyErr_Occurred()) {
Expand Down Expand Up @@ -8668,7 +8650,6 @@ static int
type_ready_mro(PyTypeObject *type, int initial)
{
ASSERT_TYPE_LOCK_HELD();
ASSERT_NEW_OR_STOPPED(type);

if (type->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN) {
if (!initial) {
Expand Down Expand Up @@ -8744,7 +8725,6 @@ static int
type_ready_inherit(PyTypeObject *type)
{
ASSERT_TYPE_LOCK_HELD();
ASSERT_NEW_OR_STOPPED(type);

/* Inherit special flags from dominant base */
PyTypeObject *base = type->tp_base;
Expand Down Expand Up @@ -8942,7 +8922,6 @@ static int
type_ready(PyTypeObject *type, int initial)
{
ASSERT_TYPE_LOCK_HELD();
ASSERT_NEW_OR_STOPPED(type);

_PyObject_ASSERT((PyObject *)type, !is_readying(type));
start_readying(type);
Expand Down Expand Up @@ -11275,7 +11254,6 @@ static pytype_slotdef *
update_one_slot(PyTypeObject *type, pytype_slotdef *p)
{
ASSERT_TYPE_LOCK_HELD();
ASSERT_NEW_OR_STOPPED(type);

PyObject *descr;
PyWrapperDescrObject *d;
Expand Down Expand Up @@ -11392,7 +11370,6 @@ static int
update_slots_callback(PyTypeObject *type, void *data)
{
ASSERT_TYPE_LOCK_HELD();
ASSERT_NEW_OR_STOPPED(type);

pytype_slotdef **pp = (pytype_slotdef **)data;
for (; *pp; pp++) {
Expand All @@ -11411,7 +11388,6 @@ update_slot(PyTypeObject *type, PyObject *name)
int offset;

ASSERT_TYPE_LOCK_HELD();
ASSERT_NEW_OR_STOPPED(type);
assert(types_world_is_stopped());
assert(PyUnicode_CheckExact(name));
assert(PyUnicode_CHECK_INTERNED(name));
Expand Down Expand Up @@ -11466,7 +11442,6 @@ update_all_slots(PyTypeObject* type)
pytype_slotdef *p;

ASSERT_TYPE_LOCK_HELD();
ASSERT_NEW_OR_STOPPED(type);

/* Clear the VALID_VERSION flag of 'type' and all its subclasses. */
type_modified_unlocked(type);
Expand Down