Repository navigation
TypedPython spec: fixed-layout classes (N-11, M2b) - #91
Merged
Merged
Conversation
A class compiles to direct slot access only when its layout is fixed in CPython too: user-written __slots__ matching its annotated fields, base object, no metaclass/decorators, not subclassed or patched. The compiler never adds __slots__ (that would change __dict__/vars()/attribute semantics). Slot reads on an exactly-typed value are not effects; trivial __init__ lowers to allocate-and-fill; methods compile with an exact-type guard on self. Planned. Refs #41, #57
This was referenced Oct 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #41 #57. The spec comes first, before any code (leader's instruction).
Documentation (spec)
The key decision: a class compiles to direct slot access only when its layout is already fixed in CPython, that is, when the user wrote
__slots__themselves. The compiler never adds__slots__: that would change__dict__,vars()and attribute addition, and break the "same results as CPython" rule.Consequence for the benchmark: binary-trees'
Nodeneeds__slots__ = ("left", "right")in the benchmark source. That applies to every language column alike, so binary-trees' CPython baseline must be re-measured afterwards.Implementation follows in separate PRs:
FieldGet,FieldSet,New,IsExact