Skip to content

TypedPython spec: fixed-layout classes (N-11, M2b) - #91

Merged
b-re-w merged 1 commit into
developfrom
work/m2b-classes-spec
Oct 3, 2026
Merged

b-re-w merged 1 commit into
developfrom
work/m2b-classes-spec

Conversation

@b-re-w

@b-re-w b-re-w commented Oct 3, 2026

Copy link
Copy Markdown
Member

Refs #41 #57. The spec comes first, before any code (leader's instruction).

Documentation (spec)

  • SPEC N-11, planned: fixed-layout classes.
  • Design §4.3.3.

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' Node needs __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:

  • IR: FieldGet, FieldSet, New, IsExact
  • verifier, front end and C back end

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
@b-re-w
b-re-w merged commit 2d7ae6a into develop Oct 3, 2026
5 checks passed
@b-re-w
b-re-w deleted the work/m2b-classes-spec branch October 3, 2026 10:13
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.

1 participant