Rule 7.7
On this page

Rule 7.7

Chapter 7, Expressions and statements Test

discard must be written as a bare statement, the identifier alone (discard), and may stand in a fragment entry and in a helper no vertex or compute entry can reach. The check closes over the call graph, and discard() is not a call the surface has.

The rule text and the parts under it are the compiler's own English, as the design document writes them.

Rationale

WGSL’s discard is a statement of the fragment stage; TypeScript has no statement to borrow, so the ambient library declares discard as a constant of type void (§9.3, family 5) and the compiler lowers an expression statement that is exactly that identifier to the statement, with the stage rule kept.

Derives from

Discard Statement (“must only be used in a fragment shader stage”); surface §10; declare const discard: void in src/language-service/ambient.ts.

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:

src/compiler/ts/builtins.test.ts (discard: lowers to the discard statement, emits it on both targets); TS8099 names the entry, or the helper and the entry, on the wrong stage; discard() is TS8004, which says that discard is a statement and is written without the parentheses (src/compiler/ts/unknown-names.test.ts).

The files that verify it at commit 26de7be8, each at the first line that names the rule:

Explained in

The sections of the surface document that explain this rule, at commit 26de7be8:

Error codes that enforce it

The diagnostic codes the rule names under Enforced by, or whose registry text names the rule:

TS8004 UNKNOWN_FN
A call to a function the file neither declares nor imports.
TS8099 UNSUPPORTED
UNSUPPORTED (TS8099) is the one deliberate exception to "sequential": it is the catch-all for a diagnostic whose site does not yet deserve its own code, so it stays parked past the sequential range instead of at its head.

See also

Source

The rule at commit 26de7be8:

Edit this page Report a problem