naga/keywords/
wgsl.rs

1/*!
2Keywords for [WGSL][wgsl] (WebGPU Shading Language).
3
4[wgsl]: https://gpuweb.github.io/gpuweb/wgsl.html
5*/
6
7use crate::proc::KeywordSet;
8use crate::racy_lock::RacyLock;
9
10// last sync: https://www.w3.org/TR/2025/CRD-WGSL-20250809/#keyword-summary
11pub const RESERVED: &[&str] = &[
12    // Keywords
13    "alias",
14    "break",
15    "case",
16    "const",
17    "const_assert",
18    "continue",
19    "continuing",
20    "default",
21    "diagnostic",
22    "discard",
23    "else",
24    "enable",
25    "false",
26    "fn",
27    "for",
28    "if",
29    "let",
30    "loop",
31    "override",
32    "requires",
33    "return",
34    "struct",
35    "switch",
36    "true",
37    "var",
38    "while",
39    // Reserved
40    "NULL",
41    "Self",
42    "abstract",
43    "active",
44    "alignas",
45    "alignof",
46    "as",
47    "asm",
48    "asm_fragment",
49    "async",
50    "attribute",
51    "auto",
52    "await",
53    "become",
54    "cast",
55    "catch",
56    "class",
57    "co_await",
58    "co_return",
59    "co_yield",
60    "coherent",
61    "column_major",
62    "common",
63    "compile",
64    "compile_fragment",
65    "concept",
66    "const_cast",
67    "consteval",
68    "constexpr",
69    "constinit",
70    "crate",
71    "debugger",
72    "decltype",
73    "delete",
74    "demote",
75    "demote_to_helper",
76    "do",
77    "dynamic_cast",
78    "enum",
79    "explicit",
80    "export",
81    "extends",
82    "extern",
83    "external",
84    "fallthrough",
85    "filter",
86    "final",
87    "finally",
88    "friend",
89    "from",
90    "fxgroup",
91    "get",
92    "goto",
93    "groupshared",
94    "highp",
95    "impl",
96    "implements",
97    "import",
98    "inline",
99    "instanceof",
100    "interface",
101    "layout",
102    "lowp",
103    "macro",
104    "macro_rules",
105    "match",
106    "mediump",
107    "meta",
108    "mod",
109    "module",
110    "move",
111    "mut",
112    "mutable",
113    "namespace",
114    "new",
115    "nil",
116    "noexcept",
117    "noinline",
118    "nointerpolation",
119    "non_coherent",
120    "noncoherent",
121    "noperspective",
122    "null",
123    "nullptr",
124    "of",
125    "operator",
126    "package",
127    "packoffset",
128    "partition",
129    "pass",
130    "patch",
131    "pixelfragment",
132    "precise",
133    "precision",
134    "premerge",
135    "priv",
136    "protected",
137    "pub",
138    "public",
139    "readonly",
140    "ref",
141    "regardless",
142    "register",
143    "reinterpret_cast",
144    "require",
145    "resource",
146    "restrict",
147    "self",
148    "set",
149    "shared",
150    "sizeof",
151    "smooth",
152    "snorm",
153    "static",
154    "static_assert",
155    "static_cast",
156    "std",
157    "subroutine",
158    "super",
159    "target",
160    "template",
161    "this",
162    "thread_local",
163    "throw",
164    "trait",
165    "try",
166    "type",
167    "typedef",
168    "typeid",
169    "typename",
170    "typeof",
171    "union",
172    "unless",
173    "unorm",
174    "unsafe",
175    "unsized",
176    "use",
177    "using",
178    "varying",
179    "virtual",
180    "volatile",
181    "wgsl",
182    "where",
183    "with",
184    "writeonly",
185    "yield",
186];
187
188/// The above set of reserved keywords, turned into a cached HashSet. This saves
189/// significant time during [`Namer::reset`](crate::proc::Namer::reset).
190///
191/// See <https://github.com/gfx-rs/wgpu/pull/7338> for benchmarks.
192pub static RESERVED_SET: RacyLock<KeywordSet> = RacyLock::new(|| KeywordSet::from_iter(RESERVED));
193
194/// Shadowable words that the WGSL backend should avoid using for declarations.
195///
196/// Includes:
197/// - [6.9. Predeclared Types and Type-Generators]
198/// - [6.3.1. Predeclared enumerants]
199/// - [17. Built-in Functions]
200///
201/// This set must be separate from the [`RESERVED`] set above since the
202/// [`Namer`](crate::proc::Namer) must ignore these identifiers if they appear
203/// as struct member names. This is because this set contains `fract` and `exp`
204/// which are also names used by return types of the `frexp` and `modf` built-in functions.
205///
206/// [6.9. Predeclared Types and Type-Generators]: https://www.w3.org/TR/WGSL/#predeclared-types
207/// [6.3.1. Predeclared enumerants]: https://www.w3.org/TR/WGSL/#predeclared-enumerants
208/// [17. Built-in Functions]: https://www.w3.org/TR/WGSL/#builtin-functions
209pub const BUILTIN_IDENTIFIERS: &[&str] = &[
210    // types
211    "bool",
212    "i32",
213    "u32",
214    "f32",
215    "f16",
216    "array",
217    "atomic",
218    "vec2",
219    "vec3",
220    "vec4",
221    "mat2x2",
222    "mat2x3",
223    "mat2x4",
224    "mat3x2",
225    "mat3x3",
226    "mat3x4",
227    "mat4x2",
228    "mat4x3",
229    "mat4x4",
230    "ptr",
231    "sampler",
232    "sampler_comparison",
233    "texture_1d",
234    "texture_2d",
235    "texture_2d_array",
236    "texture_3d",
237    "texture_cube",
238    "texture_cube_array",
239    "texture_multisampled_2d",
240    "texture_depth_multisampled_2d",
241    "texture_external",
242    "texture_storage_1d",
243    "texture_storage_2d",
244    "texture_storage_2d_array",
245    "texture_storage_3d",
246    "texture_depth_2d",
247    "texture_depth_2d_array",
248    "texture_depth_cube",
249    "texture_depth_cube_array",
250    // enumerants
251    "read",
252    "write",
253    "read_write",
254    "function",
255    "private",
256    "workgroup",
257    "uniform",
258    "storage",
259    "rgba8unorm",
260    "rgba8snorm",
261    "rgba8uint",
262    "rgba8sint",
263    "rgba16unorm",
264    "rgba16snorm",
265    "rgba16uint",
266    "rgba16sint",
267    "rgba16float",
268    "rg8unorm",
269    "rg8snorm",
270    "rg8uint",
271    "rg8sint",
272    "rg16unorm",
273    "rg16snorm",
274    "rg16uint",
275    "rg16sint",
276    "rg16float",
277    "r32uint",
278    "r32sint",
279    "r32float",
280    "rg32uint",
281    "rg32sint",
282    "rg32float",
283    "rgba32uint",
284    "rgba32sint",
285    "rgba32float",
286    "bgra8unorm",
287    "r8unorm",
288    "r8snorm",
289    "r8uint",
290    "r8sint",
291    "r16unorm",
292    "r16snorm",
293    "r16uint",
294    "r16sint",
295    "r16float",
296    "rgb10a2unorm",
297    "rgb10a2uint",
298    "rg11b10ufloat",
299    // functions
300    "bitcast",
301    "all",
302    "any",
303    "select",
304    "arrayLength",
305    "abs",
306    "acos",
307    "acosh",
308    "asin",
309    "asinh",
310    "atan",
311    "atanh",
312    "atan2",
313    "ceil",
314    "clamp",
315    "cos",
316    "cosh",
317    "countLeadingZeros",
318    "countOneBits",
319    "countTrailingZeros",
320    "cross",
321    "degrees",
322    "determinant",
323    "distance",
324    "dot",
325    "dot4U8Packed",
326    "dot4I8Packed",
327    "exp",
328    "exp2",
329    "extractBits",
330    "faceForward",
331    "firstLeadingBit",
332    "firstTrailingBit",
333    "floor",
334    "fma",
335    "fract",
336    "frexp",
337    "insertBits",
338    "inverseSqrt",
339    "ldexp",
340    "length",
341    "log",
342    "log2",
343    "max",
344    "min",
345    "mix",
346    "modf",
347    "normalize",
348    "pow",
349    "quantizeToF16",
350    "radians",
351    "reflect",
352    "refract",
353    "reverseBits",
354    "round",
355    "saturate",
356    "sign",
357    "sin",
358    "sinh",
359    "smoothstep",
360    "sqrt",
361    "step",
362    "tan",
363    "tanh",
364    "transpose",
365    "trunc",
366    "dpdx",
367    "dpdxCoarse",
368    "dpdxFine",
369    "dpdy",
370    "dpdyCoarse",
371    "dpdyFine",
372    "fwidth",
373    "fwidthCoarse",
374    "fwidthFine",
375    "textureDimensions",
376    "textureGather",
377    "textureGatherCompare",
378    "textureLoad",
379    "textureNumLayers",
380    "textureNumLevels",
381    "textureNumSamples",
382    "textureSample",
383    "textureSampleBias",
384    "textureSampleCompare",
385    "textureSampleCompareLevel",
386    "textureSampleGrad",
387    "textureSampleLevel",
388    "textureSampleBaseClampToEdge",
389    "textureStore",
390    "atomicLoad",
391    "atomicStore",
392    "atomicAdd",
393    "atomicSub",
394    "atomicMax",
395    "atomicMin",
396    "atomicAnd",
397    "atomicOr",
398    "atomicXor",
399    "atomicExchange",
400    "atomicCompareExchangeWeak",
401    "pack4x8snorm",
402    "pack4x8unorm",
403    "pack4xI8",
404    "pack4xU8",
405    "pack4xI8Clamp",
406    "pack4xU8Clamp",
407    "pack2x16snorm",
408    "pack2x16unorm",
409    "pack2x16float",
410    "unpack4x8snorm",
411    "unpack4x8unorm",
412    "unpack4xI8",
413    "unpack4xU8",
414    "unpack2x16snorm",
415    "unpack2x16unorm",
416    "unpack2x16float",
417    "storageBarrier",
418    "textureBarrier",
419    "workgroupBarrier",
420    "workgroupUniformLoad",
421    "subgroupAdd",
422    "subgroupExclusiveAdd",
423    "subgroupInclusiveAdd",
424    "subgroupAll",
425    "subgroupAnd",
426    "subgroupAny",
427    "subgroupBallot",
428    "subgroupBroadcast",
429    "subgroupBroadcastFirst",
430    "subgroupElect",
431    "subgroupMax",
432    "subgroupMin",
433    "subgroupMul",
434    "subgroupExclusiveMul",
435    "subgroupInclusiveMul",
436    "subgroupOr",
437    "subgroupShuffle",
438    "subgroupShuffleDown",
439    "subgroupShuffleUp",
440    "subgroupShuffleXor",
441    "subgroupXor",
442    "quadBroadcast",
443    "quadSwapDiagonal",
444    "quadSwapX",
445    "quadSwapY",
446    // not in the WGSL spec
447    "i64",
448    "u64",
449    "f64",
450    "push_constant",
451    "r64uint",
452];
453
454pub static BUILTIN_IDENTIFIER_SET: RacyLock<KeywordSet> =
455    RacyLock::new(|| KeywordSet::from_iter(BUILTIN_IDENTIFIERS));