Commit 04cf5da
authored
Object header slimming: prefix allocation for ObjExt (RustPython#7334)
* Object header slimming: prefix allocation for ObjExt
Extract dict, weak_list, and slots fields from PyInner<T> into a
separate ObjExt struct allocated as a prefix before PyInner using
Layout::extend(). Objects that don't need these fields (int, str,
float, list, tuple, dict, etc.) skip the prefix entirely.
- Add HAS_WEAKREF flag to PyTypeFlags for per-type weakref control
- Add HAS_EXT bit to GcBits indicating prefix presence
- Define ObjExt struct with dict, weak_list, slots
- Shrink PyInner header from ~80-88 bytes to ~32 bytes for lightweight objects
- Update all accessor methods to go through ext_ref()
- Update bootstrap type hierarchy to use prefix allocation
- Add __weakref__ getset descriptor for heap types
- Set HAS_WEAKREF on builtin types that support weak references
- Remove test_weak_keyed_bad_delitem expectedFailure (now passes)
* Add HAS_WEAKREF to _asyncio Future/Task, rename weakref helpers
- Add HAS_WEAKREF flag to PyFuture and PyTask (matches CPython)
- Rename subtype_getweakref/setweakref to subtype_get_weakref/set_weakref
to fix cspell unknown word lint
* Add HAS_WEAKREF to array, deque, _grouper; remove expectedFailure markers
- Add HAS_WEAKREF to PyArray and PyDeque (matches CPython)
- Add HAS_WEAKREF to PyItertoolsGrouper (internal use by groupby)
- Remove 6 expectedFailure markers from test_dataclasses for weakref/slots
tests that now pass
* Add HAS_WEAKREF to code, union, partial, lock, IO, mmap, sre, sqlite3, typevar types
Add HAS_WEAKREF flag to built-in types that support weakref:
- PyCode, PyUnion, PyPartial, Lock, RLock
- All IO base/concrete classes (_IOBase, _RawIOBase, _BufferedIOBase,
_TextIOBase, BufferedReader, BufferedWriter, BufferedRandom,
BufferedRWPair, TextIOWrapper, StringIO, BytesIO, FileIO,
WindowsConsoleIO)
- PyMmap, sre Pattern, sqlite3 Connection/Cursor
- TypeVar, ParamSpec, ParamSpecArgs, ParamSpecKwargs, TypeVarTuple
Remove 3 expectedFailure markers from test_descr for now-passing tests.
* Add HAS_DICT to type flags and handle non-METHOD/CLASS in descr_get
- Add HAS_DICT flag to PyType (type metaclass) alongside existing
HAS_WEAKREF. All type objects are instances of type and need dict
support, matching CPython's PyType_Type.
- Replace unimplemented!() in PyMethodDescriptor::descr_get with
fallback to bind obj directly, matching CPython's method_get which
uses PyCFunction_NewEx for non-METH_METHOD methods.
* Fix ext detection, HeapMethodDef ownership, WASM error
- Remove HAS_EXT gc_bits flag; detect ext from type flags
using raw pointer reads to avoid Stacked Borrows violations
- Store HeapMethodDef owner in payload instead of dict hack
- Clear dict entries in gc_clear_raw to break cycles
- Add WASM error fallback when exception serialization fails1 parent 3b91466 commit 04cf5da
40 files changed
Lines changed: 566 additions & 258 deletions
File tree
- .cspell.dict
- Lib/test
- test_dataclasses
- crates
- stdlib/src
- vm/src
- builtins
- function
- object
- stdlib
- types
- wasm/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| 62 | + | |
61 | 63 | | |
62 | 64 | | |
63 | 65 | | |
| |||
89 | 91 | | |
90 | 92 | | |
91 | 93 | | |
92 | | - | |
93 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3672 | 3672 | | |
3673 | 3673 | | |
3674 | 3674 | | |
3675 | | - | |
3676 | 3675 | | |
3677 | 3676 | | |
3678 | 3677 | | |
| |||
3687 | 3686 | | |
3688 | 3687 | | |
3689 | 3688 | | |
3690 | | - | |
3691 | 3689 | | |
3692 | 3690 | | |
3693 | 3691 | | |
| |||
3748 | 3746 | | |
3749 | 3747 | | |
3750 | 3748 | | |
3751 | | - | |
3752 | 3749 | | |
3753 | 3750 | | |
3754 | 3751 | | |
| |||
3767 | 3764 | | |
3768 | 3765 | | |
3769 | 3766 | | |
3770 | | - | |
3771 | 3767 | | |
3772 | 3768 | | |
3773 | 3769 | | |
| |||
3785 | 3781 | | |
3786 | 3782 | | |
3787 | 3783 | | |
3788 | | - | |
3789 | 3784 | | |
3790 | 3785 | | |
3791 | 3786 | | |
| |||
3830 | 3825 | | |
3831 | 3826 | | |
3832 | 3827 | | |
3833 | | - | |
3834 | 3828 | | |
3835 | 3829 | | |
3836 | 3830 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1321 | 1321 | | |
1322 | 1322 | | |
1323 | 1323 | | |
1324 | | - | |
1325 | 1324 | | |
1326 | 1325 | | |
1327 | 1326 | | |
| |||
2294 | 2293 | | |
2295 | 2294 | | |
2296 | 2295 | | |
2297 | | - | |
2298 | 2296 | | |
2299 | 2297 | | |
2300 | 2298 | | |
| |||
3976 | 3974 | | |
3977 | 3975 | | |
3978 | 3976 | | |
3979 | | - | |
3980 | 3977 | | |
3981 | 3978 | | |
3982 | 3979 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1862 | 1862 | | |
1863 | 1863 | | |
1864 | 1864 | | |
1865 | | - | |
1866 | 1865 | | |
1867 | 1866 | | |
1868 | 1867 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | | - | |
| 163 | + | |
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| |||
1169 | 1169 | | |
1170 | 1170 | | |
1171 | 1171 | | |
1172 | | - | |
| 1172 | + | |
1173 | 1173 | | |
1174 | 1174 | | |
1175 | 1175 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
976 | 976 | | |
977 | 977 | | |
978 | 978 | | |
979 | | - | |
| 979 | + | |
980 | 980 | | |
981 | 981 | | |
982 | 982 | | |
| |||
1629 | 1629 | | |
1630 | 1630 | | |
1631 | 1631 | | |
1632 | | - | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
1633 | 1636 | | |
1634 | 1637 | | |
1635 | 1638 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
698 | 698 | | |
699 | 699 | | |
700 | 700 | | |
701 | | - | |
| 701 | + | |
702 | 702 | | |
703 | 703 | | |
704 | 704 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
851 | 851 | | |
852 | 852 | | |
853 | 853 | | |
854 | | - | |
| 854 | + | |
855 | 855 | | |
856 | 856 | | |
857 | 857 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
317 | 317 | | |
318 | 318 | | |
319 | 319 | | |
320 | | - | |
| 320 | + | |
321 | 321 | | |
322 | 322 | | |
323 | 323 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
44 | 47 | | |
45 | 48 | | |
46 | 49 | | |
| |||
0 commit comments