Skip to content

Commit 41c6218

Browse files
remove all temporary immortalization
1 parent 32aaf2b commit 41c6218

File tree

5 files changed

+0
-104
lines changed

5 files changed

+0
-104
lines changed

Include/internal/pycore_gc.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -344,14 +344,6 @@ struct _gc_runtime_state {
344344
collections, and are awaiting to undergo a full collection for
345345
the first time. */
346346
Py_ssize_t long_lived_pending;
347-
348-
/* gh-117783: Deferred reference counting is not fully implemented yet, so
349-
as a temporary measure we treat objects using deferred reference
350-
counting as immortal. The value may be zero, one, or a negative number:
351-
0: immortalize deferred RC objects once the first thread is created
352-
1: immortalize all deferred RC objects immediately
353-
<0: suppressed; don't immortalize objects */
354-
int immortalize;
355347
#endif
356348
};
357349

Modules/_testinternalcapi.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,27 +1968,13 @@ get_py_thread_id(PyObject *self, PyObject *Py_UNUSED(ignored))
19681968
static PyObject *
19691969
suppress_immortalization(PyObject *self, PyObject *value)
19701970
{
1971-
#ifdef Py_GIL_DISABLED
1972-
int suppress = PyObject_IsTrue(value);
1973-
if (suppress < 0) {
1974-
return NULL;
1975-
}
1976-
PyInterpreterState *interp = PyInterpreterState_Get();
1977-
// Subtract two to suppress immortalization (so that 1 -> -1)
1978-
_Py_atomic_add_int(&interp->gc.immortalize, suppress ? -2 : 2);
1979-
#endif
19801971
Py_RETURN_NONE;
19811972
}
19821973

19831974
static PyObject *
19841975
get_immortalize_deferred(PyObject *self, PyObject *Py_UNUSED(ignored))
19851976
{
1986-
#ifdef Py_GIL_DISABLED
1987-
PyInterpreterState *interp = PyInterpreterState_Get();
1988-
return PyBool_FromLong(_Py_atomic_load_int(&interp->gc.immortalize) >= 0);
1989-
#else
19901977
Py_RETURN_FALSE;
1991-
#endif
19921978
}
19931979

19941980
static PyObject *

Objects/codeobject.c

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,6 @@ PyCode_ClearWatcher(int watcher_id)
105105
static int
106106
should_intern_string(PyObject *o)
107107
{
108-
#ifdef Py_GIL_DISABLED
109-
// The free-threaded build interns (and immortalizes) all string constants
110-
// unless we've disabled immortalizing objects that use deferred reference
111-
// counting.
112-
PyInterpreterState *interp = _PyInterpreterState_GET();
113-
if (_Py_atomic_load_int(&interp->gc.immortalize) < 0) {
114-
return 1;
115-
}
116-
#endif
117-
118108
// compute if s matches [a-zA-Z0-9_]
119109
const unsigned char *s, *e;
120110

@@ -130,10 +120,6 @@ should_intern_string(PyObject *o)
130120
return 1;
131121
}
132122

133-
#ifdef Py_GIL_DISABLED
134-
static PyObject *intern_one_constant(PyObject *op);
135-
#endif
136-
137123
static int
138124
intern_strings(PyObject *tuple)
139125
{
@@ -235,27 +221,6 @@ intern_constants(PyObject *tuple, int *modified)
235221
}
236222
Py_DECREF(tmp);
237223
}
238-
239-
// Intern non-string constants in the free-threaded build, but only if
240-
// we are also immortalizing objects that use deferred reference
241-
// counting.
242-
PyThreadState *tstate = PyThreadState_GET();
243-
if (!_Py_IsImmortal(v) && !PyCode_Check(v) &&
244-
!PyUnicode_CheckExact(v) &&
245-
_Py_atomic_load_int(&tstate->interp->gc.immortalize) >= 0)
246-
{
247-
PyObject *interned = intern_one_constant(v);
248-
if (interned == NULL) {
249-
return -1;
250-
}
251-
else if (interned != v) {
252-
PyTuple_SET_ITEM(tuple, i, interned);
253-
Py_SETREF(v, interned);
254-
if (modified) {
255-
*modified = 1;
256-
}
257-
}
258-
}
259224
#endif
260225
}
261226
return 0;
@@ -2495,36 +2460,6 @@ _PyCode_ConstantKey(PyObject *op)
24952460
}
24962461

24972462
#ifdef Py_GIL_DISABLED
2498-
static PyObject *
2499-
intern_one_constant(PyObject *op)
2500-
{
2501-
PyInterpreterState *interp = _PyInterpreterState_GET();
2502-
_Py_hashtable_t *consts = interp->code_state.constants;
2503-
2504-
assert(!PyUnicode_CheckExact(op)); // strings are interned separately
2505-
2506-
_Py_hashtable_entry_t *entry = _Py_hashtable_get_entry(consts, op);
2507-
if (entry == NULL) {
2508-
if (_Py_hashtable_set(consts, op, op) != 0) {
2509-
return NULL;
2510-
}
2511-
2512-
#ifdef Py_REF_DEBUG
2513-
Py_ssize_t refcnt = Py_REFCNT(op);
2514-
if (refcnt != 1) {
2515-
// Adjust the reftotal to account for the fact that we only
2516-
// restore a single reference in _PyCode_Fini.
2517-
_Py_AddRefTotal(_PyThreadState_GET(), -(refcnt - 1));
2518-
}
2519-
#endif
2520-
2521-
_Py_SetImmortal(op);
2522-
return op;
2523-
}
2524-
2525-
assert(_Py_IsImmortal(entry->value));
2526-
return (PyObject *)entry->value;
2527-
}
25282463

25292464
static int
25302465
compare_constants(const void *key1, const void *key2) {

Python/bltinmodule.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -866,21 +866,8 @@ builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
866866
if (str == NULL)
867867
goto error;
868868

869-
#ifdef Py_GIL_DISABLED
870-
// gh-118527: Disable immortalization of code constants for explicit
871-
// compile() calls to get consistent frozen outputs between the default
872-
// and free-threaded builds.
873-
// Subtract two to suppress immortalization (so that 1 -> -1)
874-
PyInterpreterState *interp = _PyInterpreterState_GET();
875-
_Py_atomic_add_int(&interp->gc.immortalize, -2);
876-
#endif
877-
878869
result = Py_CompileStringObject(str, filename, start[compile_mode], &cf, optimize);
879870

880-
#ifdef Py_GIL_DISABLED
881-
_Py_atomic_add_int(&interp->gc.immortalize, 2);
882-
#endif
883-
884871
Py_XDECREF(source_copy);
885872
goto finally;
886873

Python/gc_free_threading.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -755,10 +755,6 @@ _PyGC_Init(PyInterpreterState *interp)
755755
{
756756
GCState *gcstate = &interp->gc;
757757

758-
// gh-117783: immortalize objects that would use deferred refcounting
759-
// once the first non-main thread is created (but not in subinterpreters).
760-
gcstate->immortalize = _Py_IsMainInterpreter(interp) ? 0 : -1;
761-
762758
gcstate->garbage = PyList_New(0);
763759
if (gcstate->garbage == NULL) {
764760
return _PyStatus_NO_MEMORY();

0 commit comments

Comments
 (0)