validate()
함수, 진단 분류
Check an authored module against the structural rules every emit depends on, and throw a ValidationError when any of them fails.
import { validate } from 'typeshade'
시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.
구문
function validate(m: ModuleDecl): void매개변수
mModuleDeclthe authored module, as built, before any pass has rewritten its nodes.
반환값
void
예외
@link ValidationErrorcarrying every error-severity diagnostic, with code
SD0020.ValidationErrorCheck an authored module against the structural rules every emit depends on, and throw a ValidationError when any of them fails. emitModule, emitGlslModule and compileModule each run this check first, before they rewrite the module for their target, so a structurally invalid module is reported at the line that authored it and never reaches the driver as invalid WGSL or GLSL.
설명
emitModule, emitGlslModule and compileModule each run this check
first, before they rewrite the module for their target, so a structurally invalid module
is reported at the line that authored it and never reaches the driver as invalid WGSL or
GLSL. Call it directly when you want that answer without emitting.
One error reports every failure. validate collects every error-severity diagnostic, and
the throw carries them all on err.diagnostics; the message renders the same list as
text. Each diagnostic names its code (SD0107 and its siblings), the ruleId that
raised it, the fn it was found in, and, with setSourceTracing on, the
file:line:col that authored the node.
It runs the core rules: duplicate struct or function names, binding collisions, a function
path that ends without returning a value, mixed scalar types in one expression, a call
whose arity or argument types disagree with the function it names, a fragment-only builtin
read outside a fragment entry, a portable kernel that cannot emit on both backends, and a
local that shadows another in the same function. These hold for every module, including
modules assembled with composeModule and compute kernels that return early on
purpose. Style rules are lint-only; run lintModule or diagnose for those.
예제
예제
import { validate, ValidationError } from 'typeshade'
try { validate(MODULE)} catch (e) { if (e instanceof ValidationError) for (const d of e.diagnostics) report(d.code, d.message) else throw e}관련 가이드
함께 보기
소스
src/core/passes/validate.ts, 119행, 커밋 c66579bf 기준