Rule 8.25
Chapter 8, Functions and entry points Test
An object parameter that its function writes is the caller’s object, and the call passes the variable itself, unmarked: reading the parameter reads that object, and assigning to a field or an element of it writes it, for the call (change 0142).
The compiler reads which parameters a function writes (isWrittenObjectParameter in src/compiler/ts/object-reference/written.ts, Rule 8.8); the author writes no qualifier.
A function declared at the top of the file or of a namespace takes its object parameters this way; the other kinds take values in this version (Rule 8.8).
The argument takes what a method that changes its object takes as that object (Rule 8.10): a let, a const whose initializer built its value or names a place (Rules 6.10 and 8.8, rule 1), a module variable, an element of a read_write storage binding, this where it may be written, a parameter the function writes, or a field or an element of one of those, of exactly the parameter’s type; a parameter that holds a copy, any other const, a read-only binding and a component of a vector must be refused with the edit; a column of a matrix is a place. A parameter the function writes is passed on as itself.
A literal, a new, an object literal or a call that gives a new object is no refusal: the compiler holds the value in a local for the call, where nothing else sees the write. A call that may give back an object that has a name (Rule 8.8, rule 3) is refused as not supported yet (TS8073, change 0142, stage 2): the sentence says the expression “may be an object that already has a name” and asks for a name first. A call of a function whose every return names one parameter is named by a const (Rule 8.8, rule 1), and the name is passed.
A number, a bool, a vector and a matrix parameter is a value, and a write to it, or to a component of it, is TS8018 whose sentence says to return the value.
A list assignment, [a, b] = f(a, b), takes two results apart; each place of the list is a name, a field or an element, and a rest element, a hole and a default are refused (TS8018, lowerListAssign in src/compiler/ts/lower/statement.ts).
@inout and @out are removed (change 0142): a parameter written with one is TS8073, with one sentence for an object parameter ("@inout" was removed (change 0142): an object parameter is the caller's object with no mark. Delete "@inout".) and one for a value parameter ("@inout" was removed (change 0142): a number, a bool, a vector and a matrix are values. Return the value, and write [a, b] = f(a, b) for more than one.), the same in both halves.
The type forms a: inout<T> and a: out<T> must be refused with TS8028, which carries the removal sentence, wherever a type is written.
No call fills an array parameter with zeros, and an argument assigns no variable of the caller (Rule 7.6): an array parameter holds the values the caller gave it.
The place is the one the argument names when the call is made: an index is evaluated once, before the body runs, and a write the call makes to it moves nothing.
One call must not take two references whose places share a root (the local, module variable or binding they are reached through) when the callee writes either, nor a reference to a module variable or a binding the callee reads or writes by its name when either side is written; a method’s object and a variable a local function writes count as references (Rules 8.10 and 8.17), and an argument the callee only reads in place (Rule 8.28) counts as a read, which Rule 8.28 passes as a copy where the callee writes its place.
The refusal is TS8074, and it says that the form is not supported yet (change 0142, stage 2): JavaScript allows f(a, a), and the stage that follows which name each write reaches ends it.
A local function captures a parameter that its function writes as it captures any variable (Rule 8.17): it reads and writes the caller’s object, and hands it on as itself.
A reference reaches each target as its own spelling of the parameter the callee writes through: a pointer on WGSL, ptr<AS, T> with &place at the call and one copy of the function for each address space its calls use, an inout parameter on GLSL ES 3.00, or there, for a module variable, a copy of the function that writes the variable by its name (Rule 8.28), and on the CPU a copy in and a store back to the same place on return.
The rule text and the parts under it are the compiler's own English, as the design document writes them.
Rationale
in JavaScript an object argument is the object itself, so a function that writes its parameter changes the caller’s object. The compiler reads which parameters a function writes, so no mark says it (OD-3, OD-5); the model is the one TypeShade already gives this (Rule 8.10), so no new IR reaches the surface. The call is unmarked, as a GLSL or HLSL call with inout is.
A number is a value in JavaScript, so a function that changes one returns it, and [a, b] = f(a, b) takes two results apart.
A reference lives for one call because a target copies only there: GLSL ES 3.00 copies an inout argument in at the call and out at the return, in an order it leaves undefined, so two references to one place in one call are the one way two targets could disagree, and WGSL’s alias analysis refuses exactly those calls.
A vector’s component is no place WGSL takes the address of; a matrix’s column is one, and the CPU paths read and store it back through their column helpers, as they write m[i] = v.
A local function’s capture outlives no call: the local function is a function of the module that takes what it captures as parameters (Rule 8.17), so a captured reference is a reference handed on, which each target already spells.
Derives from
change 0040 in changes/ (the lowering); change 0142 in changes/; docs/owner-decisions.md, OD-5 and OD-9; Alias analysis and Function calls in the WGSL specification; the GLSL ES 3.00 specification, section 6.1.1.
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:
TS8073 REFERENCE for an argument that is no place and TS8074 REFERENCE_ALIAS in src/compiler/ts/lower/references.ts, whose comment records the alias rule measured on Tint; isWrittenObjectParameter in src/compiler/ts/object-reference/written.ts, which reads the parameters a function writes from the source, and src/compiler/ts/object-share.ts, which reads the stores and the places that must stay (Rule 8.8, rules 2, 4 and 5); TS8073 for a written qualifier (refuseRemovedQualifiers in src/compiler/ts/decorated-form.ts) and TS8028 for the type form, which tshc migrate (src/cli/migrate.ts) removes from an object parameter and reports on a value parameter; the editor’s TS1206 filter for a removed qualifier in src/language-service/diagnostics.ts; the store back to a field or an element in src/core/oracle.ts, src/core/cpu-codegen.ts and src/core/debug/interp.ts; pinned by src/compiler/ts/reference-parameters.test.ts, which reads each program in the compiler and the editor, src/compiler/ts/object-reference.test.ts and src/compiler/ts/host-kernel-out.test.ts, and examples/gallery/reference-parameters/reference-parameters.shade.ts through the compile gate.
The files that verify it at commit af54ddad5, each at the first line that names the rule:
-
examples/shade-examples.test.ts:28 -
src/cli/migrate.ts:3 -
src/compiler/ts/attribute-types.test.ts:1 -
src/compiler/ts/attribute-types.ts:1 -
src/compiler/ts/decorated-form.ts:1 -
src/compiler/ts/definite-assignment.test.ts:1 -
src/compiler/ts/host-face.test.ts:163 -
src/compiler/ts/host-kernel-out.test.ts:2 -
src/compiler/ts/lower/references.ts:1 -
src/compiler/ts/object-reference-removed-forms.test.ts:1 -
src/compiler/ts/object-reference-reviews.test.ts:1 -
src/compiler/ts/object-reference-unread.test.ts:1 -
src/compiler/ts/object-reference.test.ts:1 -
src/compiler/ts/object-reference.ts:1 -
src/compiler/ts/object-reference/written.ts:1 -
src/compiler/ts/object-share.ts:1 -
src/compiler/ts/reference-parameters.test.ts:1 -
src/compiler/ts/reference-reads.test.ts:1 -
src/core/cpu-codegen.ts:207 -
src/core/debug/interp.ts:145 -
src/core/oracle.ts:216 -
src/language-service/diagnostics.ts:1
Error codes that enforce it
The diagnostic codes the rule names under Enforced by, or whose registry text names the rule:
-
TS8028ATTRIBUTE_NAME - A decorator or an entry form that this surface does not read: an identifier outside the attribute vocabulary (
@vertex,@fragment,@compute,@builtin,@location), such as a misspelled@vertx; a WGSL attribute that the surface writes another way or does not borrow, such as a written@diagnostic(…); a stage written as a call, such asvertex(f); an entry that is written in a form that Rule 8.1 refuses, such asexport default; or a decorator on a declaration or in a place that takes none (Rule 6.7). Without this code the decorated function or field would silently stop being an entry point or an I/O field. -
TS8073REFERENCE - A reference form that is not supported yet (Rule 8.8, change 0142):
@inoutor@out, which are removed because an object parameter is the caller's object with no mark, and a call that may give back an object that has a name. The message names the edit. -
TS8074REFERENCE_ALIAS - Two names for one object in one call, where a write reaches one of them:
f(a, a)wherefwrites one of the two, or a module variable passed to a function that also uses its name. The message says that the form is not supported yet (change 0142).
See also
Source
The rule at commit af54ddad5:
docs/language-design.md:1164(the design document)reqs/rules/RULE-0825.md(its traceability item)