You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by GitBox <gi...@apache.org> on 2026/02/27 19:10:15 UTC
[GH] (tvm-ffi/2026-02-27/slots): Workflow run "CI" failed!
The GitHub Actions job "CI" on tvm-ffi.git/2026-02-27/slots has failed.
Run started by GitHub user junrushao (triggered by junrushao).
Head commit for run:
7d9de2a643fca66bd269ec195b50e8143582e98d / Junru Shao <ju...@nvidia.com>
feat(python)!: enforce __slots__=() for Object subclasses via _ObjectSlotsMeta
Architecture:
- Split Cython `Object` into two layers: `CObject` (extension type owning
the raw `void* chandle`) and `Object` (Python class with `_ObjectSlotsMeta`
metaclass that auto-injects `__slots__=()`).
- `_ObjectSlotsMeta(ABCMeta)` intercepts `__new__` to inject `__slots__=()`
into any subclass namespace that omits it, preventing per-instance
`__dict__` allocation across the entire Object hierarchy.
- Removed the `slots: bool = True` keyword argument from
`_ObjectSlotsMeta.__new__`/`__init__`; subclasses that need a `__dict__`
declare `__slots__ = ("__dict__",)` explicitly — no metaclass opt-out.
- `Module` uses `__slots__ = ("__dict__",)` to allow dynamic attribute
caching; `__getattr__` simplified to store directly in `__dict__` and
let normal attribute lookup serve as the cache on subsequent access.
- `CObject.__init__` now raises `TypeError`, guarding against accidental
creation of NULL-handle objects from Python.
- `object_repr()` replaces the module-global `_REPR_PRINT` lazy cache with
a local import from `_ffi_api`, eliminating mutable global state.
- Fallback class generation simplified: set attributes directly on the
already-created class instead of rebuilding `__dict__` and re-calling
`type()`.
Public Interfaces:
- New exported Cython type `CObject` (base extension type).
- `Object` is now a Python class (metaclass=`_ObjectSlotsMeta`) extending
`CObject`; `isinstance(x, Object)` still works for `CObject` instances
via custom `__instancecheck__`/`__subclasscheck__`.
- `_ObjectSlotsMeta` no longer accepts `slots` keyword argument.
- New public function `object_repr(obj: CObject) -> str`.
- `__object_repr__` removed (was module-private).
- `core.pyi` updated to reflect the new two-level hierarchy.
- `DLDeviceType`: added `kDLMAIA=17`, renumbered `kDLTrn` from 17 to 18.
UI/UX:
- Object subclasses can no longer carry arbitrary instance attributes;
any `obj.foo = bar` on an unslotted attribute now raises
`AttributeError`.
- `Module.__getattr__` stores looked-up functions in `__dict__` directly;
subsequent access hits `__dict__` without entering `__getattr__` again.
Behavioral Changes:
- All `Object`-derived classes automatically receive `__slots__=()` unless
they explicitly declare their own.
- Subclasses that need per-instance state (e.g. `Module`) declare
`__slots__ = ("__dict__",)` to opt in to a `__dict__`.
- `Error`, `Function`, `Tensor`, `OpaquePyObject` now extend `CObject`
directly (Cython extension types cannot use a Python metaclass).
- Container `__repr__` methods (Array, List, Map, Dict) removed; inherited
`CObject.__repr__` delegates to `object_repr()`.
- `ffi.Shape` added to the set of deep-copy-supported containers in
`_setup_copy_methods`.
- `_deepcopy_supported` uses direct `_ffi_api.DeepCopy` import instead of
`lru_cache`-wrapped `get_global_func`.
- `AccessPath.__init__` no longer calls `super().__init__()` (which now
raises `TypeError`).
Docs:
- Inline docstrings updated for `CObject`, `Object`, `object_repr`.
- Removed stale note forbidding `__dict__` in `__slots__` from Object
docstring.
- No external doc updates; gap: `docs/concepts/` object docs should
mention the two-level CObject/Object split.
Tests:
- Executed: `uv run pytest -vvs tests/python`
- Result: 532 passed, 23 skipped, 1 xfailed
Untested Edge Cases:
- Third-party code that sets arbitrary attributes on Object subclasses
will break; low risk since this is an intentional invariant enforcement.
- `_ObjectSlotsMeta.__instancecheck__` performance under deep inheritance
hierarchies; low risk, ABCMeta has its own caching.
BREAKING CHANGE: All `Object` subclasses now enforce `__slots__=()` by
default. Code that dynamically sets instance attributes on Object-derived
classes will raise `AttributeError`. Migrate by declaring needed slots
explicitly (e.g., `__slots__ = ("my_attr",)` or `__slots__ = ("__dict__",)`)
or storing state in a separate non-Object container. `_ObjectSlotsMeta`
no longer accepts `slots` keyword argument. `DLDeviceType.kDLTrn`
renumbered from 17 to 18; `kDLMAIA=17` added.
Report URL: https://github.com/apache/tvm-ffi/actions/runs/22500041781
With regards,
GitHub Actions via GitBox
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org