Skip to content

Immutability Implementation Adjustments for PLDI and the PEP #64

@xFrednet

Description

@xFrednet
  • Remove old code from the immutable module, for example immutable_register_freezable
  • Modules & Types should be unfreezable by default
    • PLDI specific: Modules should have the Proxy immutability by default or different default should be documented
    • Use PyModuleDef_Slot to allow modules to opt-in/out of immutability
  • Add escape hatches (§6.2):
    • Sub-interpreter Local
    • Cell type
  • Remove not freezable type once explicit freezability is in.
  • Fix (most) "freeze: type 'XYZ' has no tp_traverse and no tp_reachable" warnings

David

  • How do we handle weak references??
    • _PyWeakref_GET_REF needs a _Py_IsImmutable branch which requires a TryIncref which is hard for SCCs...
    • Freeing requires GILs of different interpreters

MatP

  • Split immutable module into a Python module and a C module
  • Add new tp_reachable (same signature as tp_traverse) to PyTypeObject (Needed for the PEP)
    • Add dict_reachable since dict_traverse doesn't visit unicode strings.
  • Support immutability by construction (§5.3 in the paper)
    • Add register_shallow_freezable(𝑡𝑦𝑝𝑒)
    • Make these objects immutable on first observation
  • Add set_freezable() with the values YES, NO, EXPLICIT and PROXY(For modules) to the immutable module
    • Implement the Explicit freezability
    • Check for freezability in freezing code
    • Remove special casing for blocking_on and module_locks which should never be frozen
    • There is a check in traverse_freeze which should be removed in favour of this mechanism. Probably in check_freezable
  • Allow freeze() to take multiple arguments
  • Make freeze() return the (first) passed in object
  • Fix rollback of SCC given failed freeze.

Tobias

  • Investigate naming convention, should isfrozen be is_frozen?
    • Either adjust paper (which uses is_frozen)
    • Or our implementation which uses isfrozen
  • Add @freezable, @frozen, @explicitlyFreezable and @unfreezable decorator
  • Add mutable(obj, ...) context manager to temporarily set freezability to No
    • Maybe add a C mechanism which could be used in a similar way

Fred

  • Expose mutable module state in sys.mut_modules
  • Make shadow_function_globals less smart (Don't freeze values based on strings which might index)
  • Some test were failing for module objects in proxy mode
  • Add pre-freeze hook (and check for it)
    • Change module and functions to use the pre-freeze hook instead of if-statement
  • Add Py_mod_reachable to module slots

Pending TODOs, but not critical for PLDI or DPO:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions