규칙 8.29
8장, 함수와 진입점 테스트
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 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).
출처
검증 방식
테스트로 확인합니다. 테스트나 게이트 스크립트, CI 워크플로가 이 규칙을 가리키고, 아래 파일 가운데 하나라도 규칙을 더는 가리키지 않으면 추적 검사가 실패합니다.
컴파일러가 이 규칙을 적용하는 곳을 규칙이 직접 적은 내용입니다.
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.
커밋 af54ddad5에서 이 규칙을 확인하는 파일입니다. 파일마다 규칙을 처음 가리키는 줄로 연결했습니다.
설명하는 절
커밋 af54ddad5의 언어 문서에서 이 규칙을 설명하는 절입니다.
함께 보기
소스
커밋 af54ddad5의 규칙 원문:
docs/language-design.md:1206(설계 문서)reqs/rules/RULE-0829.md(추적 항목)