FuncDecl
인터페이스, IR 분류
A ModuleDecl.funcs entry: a WGSL/GLSL function, either an ordinary helper or a pipeline entry point (stage set).
import type { FuncDecl } from 'typeshade'
시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.
구문
interface FuncDecl { readonly name: string; readonly params: readonly { name: string; type: ShaderType; builtin?: string; location?: number; interpolate?: string; attr?: string; /** How the function takes this parameter. Absent is by value, which is every parameter * but one that the callee writes through to the caller's own value. `'inout'` says it * does: GLSL ES 3.00 spells that `inout T name`, WGSL a pointer. * * The IR says WHICH parameters are written, not how a target spells it, because the two * targets do not agree on that. GLSL's `inout` is copy-in/copy-out and takes any l-value * argument; WGSL's pointer is a reference and carries the ADDRESS SPACE in its type, so a * function taking `ptr<function, T>` cannot be handed `&buf[i]`. The WGSL backend's own * pass makes one copy of the function per address space its calls use; nothing about * that reaches here, and GLSL emits the one function. */ mode?: 'inout'; }[]; readonly ret: ShaderType; readonly body: readonly Stmt[]; readonly attrs?: readonly string[]; readonly stage?: 'vertex' | 'fragment' | 'compute'; readonly workgroupSize?: number; readonly workgroupShape?: WorkgroupShape; readonly portable?: boolean; readonly kernel?: boolean; readonly retAttr?: string; readonly retBuiltin?: string; readonly opaque?: boolean; readonly span?: SourceSpan; readonly nameSpan?: SourceSpan; readonly allowEarlyReturn?: boolean; readonly lintDisable?: readonly string[]; readonly [ASSEMBLED_AS]?: string;}설명
A ModuleDecl.funcs entry: a WGSL/GLSL function, either an ordinary helper or a
pipeline entry point (stage set). This is the object fn builds: the
FnHandle it returns mixes these fields onto itself, so it is at once a typed
callable in other function bodies and, unwrapped, the plain FuncDecl that
module({ funcs }) collects. Every backend (WGSL, GLSL, CPU) walks body directly.
인스턴스 속성
name읽기 전용stringparams읽기 전용readonly { name: string; type: ShaderType; builtin?: string; location?: number; interpolate?: string; attr?: string; /** How the function takes this parameter. Absent is by value, which is every parameter * but one that the callee writes through to the caller's own value. `'inout'` says it * does: GLSL ES 3.00 spells that `inout T name`, WGSL a pointer. * * The IR says WHICH parameters are written, not how a target spells it, because the two * targets do not agree on that. GLSL's `inout` is copy-in/copy-out and takes any l-value * argument; WGSL's pointer is a reference and carries the ADDRESS SPACE in its type, so a * function taking `ptr<function, T>` cannot be handed `&buf[i]`. The WGSL backend's own * pass makes one copy of the function per address space its calls use; nothing about * that reaches here, and GLSL emits the one function. */ mode?: 'inout'; }[]ret읽기 전용ShaderTypebody읽기 전용readonly Stmt[]attrs선택 사항읽기 전용readonly string[]Stage and pipeline attributes emitted before
fn, such as@computeor@workgroup_size(64). Empty for ordinary helper functions. This is the emitted spelling;stageandworkgroupSizebelow are whatreflectand the backends read first, with these strings as the fallback for a hand-builtFuncDeclliteral.stage선택 사항읽기 전용'vertex' | 'fragment' | 'compute'Structured pipeline stage. Set by
fn()’sopts.stage.workgroupSize선택 사항읽기 전용numberStructured workgroup size for a compute stage: the
xextent.workgroupShape선택 사항읽기 전용WorkgroupShapeThe three workgroup extents of a compute stage, present when
yorzis not 1. An absent shape is[workgroupSize, 1, 1]; read it throughworkgroupShapeOf.portable선택 사항읽기 전용booleanMarks a compute entry as a portable kernel. Set by
fn()’sopts.portable, which rejects it on any other stage withSD0110. A portable kernel emits on both backends: as a native@computeentry on WGSL, and through thelowerComputeToFragmentrewrite on GLSL ES 3.00, which runs it as a fragment shader. The kernel must keep to the gather-only shape, where each invocation reads freely and stores exactly once to its own index of the output; any construct outside that shape fails validation withSD0111on every emit, on both backends.Structured only, with no
attrsspelling:portableis not a WGSL attribute, so declaring it changes nothing in the emitted source.kernel선택 사항읽기 전용booleanMarks a kernel function (Rule 8.22): an exported function, not an entry, that takes an array with no size. It runs on the host’s side of the call, which dispatches its loops, so the WGSL and GLSL backends leave it out of what they emit, and no function calls it (Rule 8.6). Its array parameters are the caller’s storage, passed by reference (Rule 8.23).
Structured only, with no
attrsspelling: it is not a WGSL attribute.retAttr선택 사항읽기 전용stringReturn-value attribute for a bare (non-struct) stage output, e.g. a fragment
-> @location(0) vec4<f32>.retBuiltin선택 사항읽기 전용stringStructured builtin id when
retAttrcame from abuiltin(name, type)FieldSpec. The spelling stays inretAttr; the id lives here so a backend can check it against its builtin vocabulary without re-parsing the attribute string.opaque선택 사항읽기 전용booleanKeep this function’s body out of its call sites: the emit optimizer never inlines a call to it.
fp64Lowersets it on every double-float helper it injects, because those bodies are error-free transformations that are algebraically trivial (e = b - (s - a)is 0 in real arithmetic), and flattening them hands the terms to passes and drivers that may legally cancel them.It is a property of the declaration, so it survives every rename a production emit applies to the function’s name.
Structured only, with no
attrsspelling (likeportableabove): it is not a WGSL attribute and changes nothing in the emitted source.span선택 사항읽기 전용SourceSpanWhere this function was declared in its authored
"use typeshade"source: the whole declaration, from the first decorator or theexportkeyword through the closing brace. Absent on an EDSL-authored or pass-synthesised function. Read it withsourceSpanOf.nameSpan선택 사항읽기 전용SourceSpanThe span of just this function’s name in its authored source, so a stack frame can highlight the identifier rather than the whole body. Absent whenever
spanis.allowEarlyReturn선택 사항읽기 전용booleanDocumented deviation from the single-exit lint rule: when true, the rule skips this function because it has an intentional early return, such as a guard that skips an expensive loop. Use sparingly, with a comment stating why.
lintDisable선택 사항읽기 전용readonly string[]Documented lint deviations: rule ids whose diagnostics are suppressed for this function (the general form of
allowEarlyReturn). Use sparingly, with a comment stating why.
함께 보기
소스
src/core/ir/nodes.ts, 588행, 커밋 c66579bf 기준