Skip to content

PLDI cleanup#87

Open
xFrednet wants to merge 6 commits intoimmutable-mainfrom
pldi-cleanup
Open

PLDI cleanup#87
xFrednet wants to merge 6 commits intoimmutable-mainfrom
pldi-cleanup

Conversation

@xFrednet
Copy link
Collaborator

Removing some old technical debt.

@xFrednet xFrednet changed the title Pldi cleanup PLDI cleanup Mar 15, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes older immutability/freezing “technical debt” by consolidating the “freezable” mechanism around set_freezable() storage (attribute / ob_flags), dropping the old register-based approach, and renaming the public query API from isfrozen to is_frozen (with a compatibility alias in Lib/immutable.py).

Changes:

  • Remove _PyImmutability_RegisterFreezable / _immutable.register_freezable and the associated weakref/set bookkeeping.
  • Rename _immutable.isfrozen_immutable.is_frozen, and update the Python-facing API + tests accordingly.
  • Initialize built-in freezable/shallow-immutable types via _PyImmutability_SetFreezable / _PyImmutability_RegisterShallowImmutable.

Reviewed changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
Python/pystate.c Removes interpreter cleanup of the deleted freezable-types state.
Python/immutability.c Refactors immutability state init and freezable bookkeeping; updates traversal behavior and SetFreezable semantics.
Modules/clinic/_immutablemodule.c.h Regenerates clinic output: drops register_freezable, renames isfrozenis_frozen.
Modules/arraymodule.c Switches module type registration from _RegisterFreezable to _SetFreezable.
Modules/_test_reachable.c Switches test types to _SetFreezable.
Modules/_struct.c Switches module type registration to _SetFreezable.
Modules/_immutablemodule.c Drops register_freezable and NotFreezable export; renames isfrozenis_frozen.
Modules/_elementtree.c Switches module type registration to _SetFreezable.
Modules/_decimal/_decimal.c Switches decimal types to _SetFreezable.
Modules/_datetimemodule.c Switches datetime C-API types to _SetFreezable.
Modules/_ctypes/_ctypes.c Switches ctypes type registration macro to _SetFreezable.
Modules/_collectionsmodule.c Switches collections types to _SetFreezable.
Lib/test/test_freeze/test_weakref.py Updates imports/usages to is_frozen.
Lib/test/test_freeze/test_set_freezable.py Updates imports/usages and removes reliance on _immutable.register_freezable.
Lib/test/test_freeze/test_rollback.py Updates imports/usages to is_frozen.
Lib/test/test_freeze/test_reachable.py Updates imports/usages to is_frozen.
Lib/test/test_freeze/test_prefreeze.py Updates imports/usages to is_frozen.
Lib/test/test_freeze/test_multi_freeze.py Updates imports/usages to is_frozen.
Lib/test/test_freeze/test_module_proxy.py Updates imports/usages to is_frozen.
Lib/test/test_freeze/test_implicit.py Updates imports/usages to is_frozen.
Lib/test/test_freeze/test_decorators.py Updates imports/usages to is_frozen.
Lib/test/test_freeze/test_ctypes.py Updates imports/usages to is_frozen.
Lib/test/test_freeze/test_core.py Removes NotFreezable-based tests; updates to is_frozen.
Lib/test/test_freeze/test_common.py Adjusts common test helpers to drop NotFreezable and use is_frozen.
Lib/immutable.py Renames exported query API to is_frozen, keeps runtime alias isfrozen.
Include/internal/pycore_immutability.h Removes freezable_types and moves enum out; leaves immutability state shape updated.
Include/cpython/immutability.h Moves _Py_freezable_status enum here; updates _PyImmutability_SetFreezable signature.
Comments suppressed due to low confidence (1)

Lib/immutable.py:60

  • all no longer includes the backward-compatible alias isfrozen even though the module still defines it. If the intent is to keep isfrozen working “for now”, consider including it in all (and potentially documenting/deprecating it) so from immutable import * remains compatible during the transition.
__all__ = [
    "freeze",
    "is_frozen",
    "set_freezable",
    "NotFreezableError",
    "ImmutableModule",
    "FREEZABLE_YES",
    "FREEZABLE_NO",
    "FREEZABLE_EXPLICIT",
    "FREEZABLE_PROXY",

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +1509 to 1521
assert(PyErr_Occurred() == NULL);
int rc = PyObject_SetAttr(obj, &_Py_ID(__freezable__), value);
Py_DECREF(value);
if (rc == 0) {
return 0;
} else {
// Attempting to set the attribute can cause different errors
// depending on the type implementation. We just clear it here
// and store the freezability in the object fields instead.
// This should be safe, since `PyErr` should never be set when
// this function is called.
PyErr_Clear();
}
Comment on lines 101 to 103
state->warned_types = _Py_hashtable_new(
_Py_hashtable_hash_ptr,
_Py_hashtable_compare_direct);
Comment on lines +155 to +165
&PyClassMethod_Type, // TODO(Immutable): mjp I added this, is it correct? Discuss with maj
&PyClassMethodDescr_Type,
&PyStaticMethod_Type,
&PyMethod_Type,
&PyCapsule_Type,
&PyCode_Type,
&PyCell_Type,
&PyFrame_Type,
&_PyWeakref_RefType,
&PyModule_Type, // TODO(Immutable): mjp I added this, is it correct? Discuss with maj
&_PyImmModule_Type,
Comment on lines +34 to +35
if self.obj == None:
return
Comment on lines 13 to 17
struct _Py_immutability_state {
int late_init_done;
PyObject *freezable_types;
_Py_hashtable_t *shallow_immutable_types;
PyObject *destroy_cb;
_Py_hashtable_t *warned_types;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants