TS8006
이 페이지에서

TS8006

프런트엔드 코드 LOOP_BOUND

컴파일러가 종료를 증명할 수 없는 for 루프입니다. 카운터를 경계와 비교하지 않거나, 본문이 경계를 씁니다.

레지스트리에는 이 상수에 대한 문서 주석이 없습니다. 그래서 위 설명은 컴파일러가 이 코드와 함께 내는 메시지를 보고 이 사이트가 쓴 것입니다.

레지스트리 설명과 컴파일러 메시지는 컴파일러 원문이라 한국어 페이지에서도 영어로 둡니다.

예제

example.shade.ts
"use typeshade"
@fragment
export function main(@location(0) uv: vec2): vec4 {
let g = 0.
let n: i32 = 8
for (let i = 0; i < n; i++) {
n -= 1
g += 0.1
}
return vec4(g, g, g, 1.)
}

빌드할 때 고정된 컴파일러로 이 프로그램을 컴파일하면 다음 진단이 나옵니다.

TS8006 error, 7행: for bound reads "n", which the loop body writes, so it does not bound the loop. Read it into a const before the loop, or write the loop as a while.

고치는 법

같은 프로그램을 고친 모습입니다. 진단 없이 컴파일됩니다.

example.shade.ts
"use typeshade"
@fragment
export function main(@location(0) uv: vec2): vec4 {
let g = 0.
let n: i32 = 8
const count = n
for (let i = 0; i < count; i++) {
n -= 1
g += 0.1
}
return vec4(g, g, g, 1.)
}

이 코드가 적용하는 규칙

규칙 7.5 테스트
A for loop must be counted: an i32 or u32 induction variable, a constant step, and an exit that compares the induction variable to a bound; the start and the bound may be runtime values, the loop body must not write the bound, and the step must move the variable toward the bound.
규칙 7.9 테스트
An expression must be evaluated left to right, as TypeScript and WGSL both evaluate it, and a call that writes (its object, a module variable, a storage binding, an atomic location) inside a larger expression must take effect in that order on every target.

함께 보기

소스

커밋 c66579bf에서 컴파일러가 이 코드를 내는 곳입니다. 파일마다 한 줄씩 적었습니다.

이 페이지 편집 문제 보고