lowerModule
On this page

lowerModule()

Function in Emit

Rewrites every matchExpr in a module into a form the backends can emit: a hoisted variable assigned from a switch statement, placed immediately before the statement that contained the expression.

import { lowerModule } from 'typeshade'

The signature, the description and the examples come from the compiler's own source at commit 26de7be8.

Syntax

function lowerModule(m: ModuleDecl): ModuleDecl

Parameters

m ModuleDecl

The module to rewrite. It is not modified.

Return value

ModuleDecl

A new module whose function bodies contain no matchExpr.

Exceptions

Error

When a matchExpr appears in a for loop header (the init, condition or update part). Hoisting it out of the header would evaluate it once where the loop evaluates it on every iteration. Compute the value into a var inside the loop body, or before the loop when it does not depend on the loop variable.

Description

WGSL and GLSL have switch only as a statement, so a multi-arm conditional expression cannot be emitted in place.

emitModule runs this pass automatically, so a shader author never calls it. It is exported for tests and for hosts that drive the emit pipeline step by step. The pass rebuilds every node it touches, so the returned module does not share node identity with the authored one and diagnostics cannot map its nodes back to authored source locations. Run validate and diagnose() on the module before this pass.

See also

Source

src/core/passes/match-lower.ts, line 62, at commit 26de7be8

Edit this page Report a problem