규칙 2.1
이 페이지에서

규칙 2.1

2장, 표면 이름의 출처 테스트

Every author-facing name must come from exactly one of three sources:

  • (a) WGSL, as the specification spells it: a built-in function, a predeclared type or type-generator including the predeclared vecNf/vecNi/vecNu aliases, an attribute reached as a decorator, a built-in value passed as a string, or an extension name;
  • (b) ECMAScript, as TypeScript’s standard library declares it: a literal, an operator, a statement, the declaration forms, and a type, a function, an object or a member of the standard library, with the members the compiler represents. Declared today: a member of Math, a method of console, a method Array.prototype has, written on an array (surface §63), the declaration forms class, interface, enum, and namespace, the standard-library declarations the ambient file restates for a lib: [] program (Map and Set among them, with the members a kernel function’s parameter has, change 0080), and the shapes surface §14 and §28 admit;
  • (c) the TypeShade extensions enumerated in §9.3 of this document, one row per name with its reason.

An attribute name with which a stage or a dispatch is written (vertex, fragment, compute, workgroup_size) is an author-facing name reached as a decorator (2.1(a)); @compute([…]) folds WGSL’s @compute and @workgroup_size into one TypeShade spelling.

규칙 본문과 그 아래 항목은 설계 문서에 적힌 컴파일러 원문이라 한국어 페이지에서도 영어로 둡니다.

근거

a name with a source has a meaning an author can look up; a name with no source has only the compiler’s word for what it does.

출처

PR #166’s body, section “A design rule this lane settled” (“No TypeShade-internal helper becomes an author-facing spelling”), and Declaration and Scope; changes/0100-typescript-meaning.md (section 2) for source (b).

검증 방식

테스트로 확인합니다. 테스트나 게이트 스크립트, CI 워크플로가 이 규칙을 가리키고, 아래 파일 가운데 하나라도 규칙을 더는 가리키지 않으면 추적 검사가 실패합니다.

컴파일러가 이 규칙을 적용하는 곳을 규칙이 직접 적은 내용입니다.

src/core/spec-conformance/surface-names.test.ts, which classifies every declared name against fixtures/wgsl-names.json, the running engine’s Math and console, and TYPESHADE_EXTENSIONS, and holds each method the library declares on an array to the running engine’s Array.prototype; and the front end, which resolves a name by what declares it and never by its spelling (proposal 0008): a name nothing declares is TS8022 for a value and TS8004 for a callee, in a body a call lowers and in one no call lowers alike, and TS8002 for a type wherever it is written, the base a class or an interface extends and an argument of a WGSL generic that is a type argument of a class included, except inside the extents of @compute([…]) or @workgroup_size([…]), where a name nothing declares is TS8037, in the compiler and in the editor alike (Rule 8.7), once, in the compiler and in the editor alike (TypeScript’s TS2304, TS2583, TS2584, TS2591 and TS2580 merge into it, and TS2585 for a Map or a Set read as a value, change 0080), a name the file declares is the file’s whatever it spells, ahead of a type the library declares of the name, and a declaration of the file wins over a §9.3 constant of its name, and an enum, a namespace, a class or a type the file declares, read as a value, says what it is and the value it offers, once (TS8022, TypeScript’s report about its typeof merged into it), pinned by src/compiler/ts/host-names.test.ts and src/language-service/diagnostics.test.ts; the two spellings ECMAScript’s strict mode lets no declaration bind, eval and arguments, are refused once where a variable, a parameter or a function binds one, TS8068, as TypeScript’s TS1215 refuses them (TS1215, TS1210 and TS1100 merge into it, and so does what TypeScript says of a later write of the name), while a class, an enum, a namespace or a type of the name is the file’s, as TypeScript takes it, pinned by src/compiler/ts/host-names.test.ts; a new finds its class the same way, with what another block of a namespace exports, and a type annotation inside a namespace finds the class the new there builds, pinned by src/compiler/ts/new-expression.test.ts; the ambient library’s own types and values are names the compiler knows are declared, a type of its own says it is one where a type, a value or a callee is read (TypeScript’s TS2693 merges into it), and a shader type is none of them, pinned by src/language-service/ambient-parity.test.ts and src/compiler/ts/host-names.test.ts; and a member is looked up on its receiver, so a class field reverse or a method swizzle is the class’s, pinned by src/compiler/ts/class-methods.test.ts; a function a namespace of the file declares under the name ref is an ordinary function of the file, since the library no longer declares one (Rule 8.25), pinned by src/compiler/ts/reference-parameters.test.ts.

커밋 af54ddad5에서 이 규칙을 확인하는 파일입니다. 파일마다 규칙을 처음 가리키는 줄로 연결했습니다.

설명하는 절

커밋 af54ddad5의 언어 문서에서 이 규칙을 설명하는 절입니다.

적용하는 오류 코드

규칙이 Enforced by 항목에서 가리키는 진단 코드와, 레지스트리 설명에서 이 규칙을 가리키는 진단 코드입니다.

TS8002 UNKNOWN_TYPE
아무것도 선언하지 않은 타입 이름입니다. 매개변수, 타입 인자, 별칭, implements 절, 기반 클래스 어디에 써도 걸리고, 이 표면이 매퍼가 읽는 자리에서 받지 않는 타입도 여기에 속합니다(규칙 2.1). 파일이 선언했지만 구조체로 모으지 않은 기반은 STRUCT_FIELD입니다.
TS8004 UNKNOWN_FN
파일이 선언하지도 가져오지도 않은 함수를 부르거나, ECMAScript 표기가 있어서 언어에서 뺀 내장 함수를 부릅니다. arrayLength(xs)가 그 예이며, 메시지가 대신 쓸 xs.length를 알려 줍니다(규칙 9.9).
TS8011
Retired codes.
TS8012
Retired codes.
TS8022 UNKNOWN_NAME
TypeShade가 풀지 못하는 이름을 가리킵니다. 함수 호출(UNKNOWN_FN)이나 타입 이름(UNKNOWN_TYPE)은 아닙니다. 라이브러리가 TypeScript 자체를 위해 선언한 이름(Object, Math, Symbol)이나 파일이 enum, 네임스페이스, 클래스, 타입으로 선언한 이름을 값으로 읽으면, 메시지가 그 이름이 무엇인지 알려 줍니다.
TS8037 WORKGROUP_ARG
@compute(...)의 인자가 정수 하나에서 셋으로 이루어진 배열 리터럴이 아닙니다. 객체, 숫자 하나, 식별자, 빈 배열, 원소가 넷인 배열이 그렇습니다. 기본 한도 검사는 WORKGROUP_SHAPE입니다.
TS8068 RESERVED_NAME
변수, 매개변수, 함수가 eval이나 arguments를 이름으로 씁니다. ECMAScript의 엄격 모드와 그에 따르는 TypeScript가 어떤 선언도 허용하지 않는 이름입니다(규칙 2.1).

함께 보기

소스

커밋 af54ddad5의 규칙 원문:

이 페이지 편집 문제 보고