Skip to content

Commit 3637425

Browse files
[3.11] bpo-40514: Drop EXPERIMENTAL_ISOLATED_SUBINTERPRETERS (gh-93185) (GH-93306)
(cherry picked from commit caa279d) This was added for bpo-40514 (gh-84694) to test out a per-interpreter GIL. However, it has since proven unnecessary to keep the experiment in the repo. (It can be done as a branch in a fork like normal.) So here we are removing: * the configure option * the macro * the code enabled by the macro Automerge-Triggered-By: GH:ericsnowcurrently
1 parent cf63b80 commit 3637425

18 files changed

+10
-234
lines changed

Doc/whatsnew/3.11.rst

+5
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,11 @@ Removed
14251425
Python's test suite."
14261426
(Contributed by Victor Stinner in :issue:`46852`.)
14271427

1428+
* The ``--experimental-isolated-subinterpreters`` configure flag
1429+
(and corresponding ``EXPERIMENTAL_ISOLATED_SUBINTERPRETERS``)
1430+
have been removed.
1431+
1432+
14281433
Porting to Python 3.11
14291434
======================
14301435

Include/internal/pycore_ceval.h

-4
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,7 @@ _PyEval_Vector(PyThreadState *tstate,
8080
PyObject* const* args, size_t argcount,
8181
PyObject *kwnames);
8282

83-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
84-
extern int _PyEval_ThreadsInitialized(PyInterpreterState *interp);
85-
#else
8683
extern int _PyEval_ThreadsInitialized(struct pyruntimestate *runtime);
87-
#endif
8884
extern PyStatus _PyEval_InitGIL(PyThreadState *tstate);
8985
extern void _PyEval_FiniGIL(PyInterpreterState *interp);
9086

Include/internal/pycore_interp.h

-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ struct _ceval_state {
5151
/* Request for dropping the GIL */
5252
_Py_atomic_int gil_drop_request;
5353
struct _pending_calls pending;
54-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
55-
struct _gil_runtime_state gil;
56-
#endif
5754
};
5855

5956

Include/internal/pycore_pystate.h

-12
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,10 @@ _Py_ThreadCanHandlePendingCalls(void)
6464
/* Variable and macro for in-line access to current thread
6565
and interpreter state */
6666

67-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
68-
PyAPI_FUNC(PyThreadState*) _PyThreadState_GetTSS(void);
69-
#endif
70-
7167
static inline PyThreadState*
7268
_PyRuntimeState_GetThreadState(_PyRuntimeState *runtime)
7369
{
74-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
75-
return _PyThreadState_GetTSS();
76-
#else
7770
return (PyThreadState*)_Py_atomic_load_relaxed(&runtime->gilstate.tstate_current);
78-
#endif
7971
}
8072

8173
/* Get the current Python thread state.
@@ -90,11 +82,7 @@ _PyRuntimeState_GetThreadState(_PyRuntimeState *runtime)
9082
static inline PyThreadState*
9183
_PyThreadState_GET(void)
9284
{
93-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
94-
return _PyThreadState_GetTSS();
95-
#else
9685
return _PyRuntimeState_GetThreadState(&_PyRuntime);
97-
#endif
9886
}
9987

10088
PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalError_TstateNULL(const char *func);

Include/internal/pycore_runtime.h

-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ struct _ceval_runtime_state {
2323
the main thread of the main interpreter can handle signals: see
2424
_Py_ThreadCanHandleSignals(). */
2525
_Py_atomic_int signals_pending;
26-
#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
2726
struct _gil_runtime_state gil;
28-
#endif
2927
};
3028

3129
/* GIL state */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The ``--experimental-isolated-subinterpreters`` configure option and
2+
``EXPERIMENTAL_ISOLATED_SUBINTERPRETERS`` macro have been removed.

Modules/_xxsubinterpretersmodule.c

-15
Original file line numberDiff line numberDiff line change
@@ -1932,20 +1932,6 @@ _run_script_in_interpreter(PyInterpreterState *interp, const char *codestr,
19321932
return -1;
19331933
}
19341934

1935-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
1936-
// Switch to interpreter.
1937-
PyThreadState *new_tstate = PyInterpreterState_ThreadHead(interp);
1938-
PyThreadState *save1 = PyEval_SaveThread();
1939-
1940-
(void)PyThreadState_Swap(new_tstate);
1941-
1942-
// Run the script.
1943-
_sharedexception *exc = NULL;
1944-
int result = _run_script(interp, codestr, shared, &exc);
1945-
1946-
// Switch back.
1947-
PyEval_RestoreThread(save1);
1948-
#else
19491935
// Switch to interpreter.
19501936
PyThreadState *save_tstate = NULL;
19511937
if (interp != PyInterpreterState_Get()) {
@@ -1963,7 +1949,6 @@ _run_script_in_interpreter(PyInterpreterState *interp, const char *codestr,
19631949
if (save_tstate != NULL) {
19641950
PyThreadState_Swap(save_tstate);
19651951
}
1966-
#endif
19671952

19681953
// Propagate any exception out to the caller.
19691954
if (exc != NULL) {

Modules/gcmodule.c

-8
Original file line numberDiff line numberDiff line change
@@ -1195,14 +1195,6 @@ gc_collect_main(PyThreadState *tstate, int generation,
11951195
assert(gcstate->garbage != NULL);
11961196
assert(!_PyErr_Occurred(tstate));
11971197

1198-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
1199-
if (tstate->interp->config._isolated_interpreter) {
1200-
// bpo-40533: The garbage collector must not be run on parallel on
1201-
// Python objects shared by multiple interpreters.
1202-
return 0;
1203-
}
1204-
#endif
1205-
12061198
if (gcstate->debug & DEBUG_STATS) {
12071199
PySys_WriteStderr("gc: collecting generation %d...\n", generation);
12081200
show_stats_each_generations(gcstate);

Objects/typeobject.c

+3-22
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ typedef struct PySlot_Offset {
5454
} PySlot_Offset;
5555

5656

57-
/* bpo-40521: Interned strings are shared by all subinterpreters */
58-
#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
59-
# define INTERN_NAME_STRINGS
60-
#endif
61-
6257
static PyObject *
6358
slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
6459

@@ -4009,7 +4004,7 @@ type_setattro(PyTypeObject *type, PyObject *name, PyObject *value)
40094004
if (name == NULL)
40104005
return -1;
40114006
}
4012-
#ifdef INTERN_NAME_STRINGS
4007+
/* bpo-40521: Interned strings are shared by all subinterpreters */
40134008
if (!PyUnicode_CHECK_INTERNED(name)) {
40144009
PyUnicode_InternInPlace(&name);
40154010
if (!PyUnicode_CHECK_INTERNED(name)) {
@@ -4019,7 +4014,6 @@ type_setattro(PyTypeObject *type, PyObject *name, PyObject *value)
40194014
return -1;
40204015
}
40214016
}
4022-
#endif
40234017
}
40244018
else {
40254019
/* Will fail in _PyObject_GenericSetAttrWithDict. */
@@ -8456,17 +8450,11 @@ _PyTypes_InitSlotDefs(void)
84568450
for (slotdef *p = slotdefs; p->name; p++) {
84578451
/* Slots must be ordered by their offset in the PyHeapTypeObject. */
84588452
assert(!p[1].name || p->offset <= p[1].offset);
8459-
#ifdef INTERN_NAME_STRINGS
8453+
/* bpo-40521: Interned strings are shared by all subinterpreters */
84608454
p->name_strobj = PyUnicode_InternFromString(p->name);
84618455
if (!p->name_strobj || !PyUnicode_CHECK_INTERNED(p->name_strobj)) {
84628456
return _PyStatus_NO_MEMORY();
84638457
}
8464-
#else
8465-
p->name_strobj = PyUnicode_FromString(p->name);
8466-
if (!p->name_strobj) {
8467-
return _PyStatus_NO_MEMORY();
8468-
}
8469-
#endif
84708458
}
84718459
slotdefs_initialized = 1;
84728460
return _PyStatus_OK();
@@ -8491,24 +8479,17 @@ update_slot(PyTypeObject *type, PyObject *name)
84918479
int offset;
84928480

84938481
assert(PyUnicode_CheckExact(name));
8494-
#ifdef INTERN_NAME_STRINGS
84958482
assert(PyUnicode_CHECK_INTERNED(name));
8496-
#endif
84978483

84988484
assert(slotdefs_initialized);
84998485
pp = ptrs;
85008486
for (p = slotdefs; p->name; p++) {
85018487
assert(PyUnicode_CheckExact(p->name_strobj));
85028488
assert(PyUnicode_CheckExact(name));
8503-
#ifdef INTERN_NAME_STRINGS
8489+
/* bpo-40521: Using interned strings. */
85048490
if (p->name_strobj == name) {
85058491
*pp++ = p;
85068492
}
8507-
#else
8508-
if (p->name_strobj == name || _PyUnicode_EQ(p->name_strobj, name)) {
8509-
*pp++ = p;
8510-
}
8511-
#endif
85128493
}
85138494
*pp = NULL;
85148495
for (pp = ptrs; *pp; pp++) {

Objects/unicodeobject.c

-18
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,6 @@ extern "C" {
219219
# define OVERALLOCATE_FACTOR 4
220220
#endif
221221

222-
/* bpo-40521: Interned strings are shared by all interpreters. */
223-
#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
224-
# define INTERNED_STRINGS
225-
#endif
226-
227222
/* This dictionary holds all interned unicode strings. Note that references
228223
to strings in this dictionary are *not* counted in the string's ob_refcnt.
229224
When the interned string reaches a refcnt of 0 the string deallocation
@@ -232,9 +227,7 @@ extern "C" {
232227
Another way to look at this is that to say that the actual reference
233228
count of a string is: s->ob_refcnt + (s->state ? 2 : 0)
234229
*/
235-
#ifdef INTERNED_STRINGS
236230
static PyObject *interned = NULL;
237-
#endif
238231

239232
/* Forward declaration */
240233
static inline int
@@ -1924,10 +1917,8 @@ unicode_dealloc(PyObject *unicode)
19241917
switch (PyUnicode_CHECK_INTERNED(unicode)) {
19251918
case SSTATE_NOT_INTERNED:
19261919
break;
1927-
19281920
case SSTATE_INTERNED_MORTAL:
19291921
{
1930-
#ifdef INTERNED_STRINGS
19311922
/* Revive the dead object temporarily. PyDict_DelItem() removes two
19321923
references (key and value) which were ignored by
19331924
PyUnicode_InternInPlace(). Use refcnt=3 rather than refcnt=2
@@ -1941,7 +1932,6 @@ unicode_dealloc(PyObject *unicode)
19411932
}
19421933
assert(Py_REFCNT(unicode) == 1);
19431934
Py_SET_REFCNT(unicode, 0);
1944-
#endif
19451935
break;
19461936
}
19471937

@@ -11314,13 +11304,11 @@ _PyUnicode_EqualToASCIIId(PyObject *left, _Py_Identifier *right)
1131411304
if (PyUnicode_CHECK_INTERNED(left))
1131511305
return 0;
1131611306

11317-
#ifdef INTERNED_STRINGS
1131811307
assert(_PyUnicode_HASH(right_uni) != -1);
1131911308
Py_hash_t hash = _PyUnicode_HASH(left);
1132011309
if (hash != -1 && hash != _PyUnicode_HASH(right_uni)) {
1132111310
return 0;
1132211311
}
11323-
#endif
1132411312

1132511313
return unicode_compare_eq(left, right_uni);
1132611314
}
@@ -15562,7 +15550,6 @@ PyUnicode_InternInPlace(PyObject **p)
1556215550
return;
1556315551
}
1556415552

15565-
#ifdef INTERNED_STRINGS
1556615553
if (PyUnicode_READY(s) == -1) {
1556715554
PyErr_Clear();
1556815555
return;
@@ -15593,11 +15580,6 @@ PyUnicode_InternInPlace(PyObject **p)
1559315580
this. */
1559415581
Py_SET_REFCNT(s, Py_REFCNT(s) - 2);
1559515582
_PyUnicode_STATE(s).interned = SSTATE_INTERNED_MORTAL;
15596-
#else
15597-
// PyDict expects that interned strings have their hash
15598-
// (PyASCIIObject.hash) already computed.
15599-
(void)unicode_hash(s);
15600-
#endif
1560115583
}
1560215584

1560315585
void

0 commit comments

Comments
 (0)