Rule 8.29
Chapter 8, Functions and entry points Test
A class is its struct and its functions. Every rule that applies to a struct applies to the class’s fields, and every rule that applies to a function applies to its constructor, its methods, its accessors and its static functions, in every place a struct or a function can be: a binding, a local, a workgroup variable, a kernel function’s array, a Buffer, the host face, the CPU tier, the oracle, the host view, reflection and a package. A method that changes its object (Rule 8.10) is, at a call, a write to the object it is called on, as an argument of a parameter that its function writes is (Rule 8.25), for the proof of Rule 8.22 and for the facts of Rule 11.13. Where a place admits a function under a condition (Rule 8.20), it admits a method under the same condition and refuses it with the same reason. Construction is a call of the constructor wherever it happens.
The rule text and the parts under it are the compiler's own English, as the design document writes them.
Rationale
the compiler lowers a class to a struct and to functions (surface §26): new P(…) is P_new(…) and nothing is allocated, a method is a function over its object, and a method that changes its object takes it by reference, as a parameter that its function writes is, by the model of change 0040. So a class written once means one thing wherever it stands, and a library whose units are classes rests on that; this rule says so, and the class arm holds it, as Rule 11.20 is held for the common modules.
The rule states no symmetry it cannot keep. A method that reaches a binding, a workgroup variable or a builtin that a host call does not run yet has no host call yet, and the host view says so with the reason (Rule 8.20). A host call of a method runs on the CPU tier and never dispatches (proposal 0109). A read of a Buffer is asynchronous (Rule 11.8).
Derives from
How it is verified
Checked by a test. A test, a gate script or a CI workflow names this rule, and the traceability check fails when a file listed below stops naming it.
Where the rule says the compiler enforces it:
the class arm of the differential gate, scripts/class-arm.ts, which bun run gate:differential runs: for each exported class of the .shade.ts examples and of journeys/class-twins/ it writes a twin module that imports the class, and holds each member a host could call, built and called as an entry’s local and as a kernel function’s element, on WebGPU, WebGL2, the CPU tier and the oracle, and as a host calls it on the host class of change 0109, to the f32 oracle’s own constructor and member function, bit for bit or within the envelope of a determinism row; a member the host face refuses is listed with the face’s reason, and the host class must refuse it with that reason; pinned for the proof by src/compiler/ts/kernel-loops.test.ts and for the facts by src/core/fuse-plan.test.ts, each form (a method that changes its object, one that reads it, a static function, and a method that hands a field to a parameter that its function writes) written through a member and inline, the proof’s verdict and the planner’s groups, dispatches and reasons the same.
The files that verify it at commit af54ddad5, each at the first line that names the rule:
Explained in
The sections of the surface document that explain this rule, at commit af54ddad5:
See also
Source
The rule at commit af54ddad5:
docs/language-design.md:1206(the design document)reqs/rules/RULE-0829.md(its traceability item)