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::racy_lock::RacyLock;
8
9use hashbrown::HashSet;
10
11// https://gpuweb.github.io/gpuweb/wgsl/#keyword-summary
12// last sync: https://github.com/gpuweb/gpuweb/blob/39f2321f547c8f0b7f473cf1d47fba30b1691303/wgsl/index.bs
13pub const RESERVED: &[&str] = &[
14    // Type-defining Keywords
15    "array",
16    "atomic",
17    "bool",
18    "f32",
19    "f16",
20    "i32",
21    "i64",
22    "mat2x2",
23    "mat2x3",
24    "mat2x4",
25    "mat3x2",
26    "mat3x3",
27    "mat3x4",
28    "mat4x2",
29    "mat4x3",
30    "mat4x4",
31    "ptr",
32    "sampler",
33    "sampler_comparison",
34    "texture_1d",
35    "texture_2d",
36    "texture_2d_array",
37    "texture_3d",
38    "texture_cube",
39    "texture_cube_array",
40    "texture_multisampled_2d",
41    "texture_storage_1d",
42    "texture_storage_2d",
43    "texture_storage_2d_array",
44    "texture_storage_3d",
45    "texture_depth_2d",
46    "texture_depth_2d_array",
47    "texture_depth_cube",
48    "texture_depth_cube_array",
49    "texture_depth_multisampled_2d",
50    "u32",
51    "u64",
52    "vec2",
53    "vec3",
54    "vec4",
55    // Other Keywords
56    "alias",
57    "bitcast",
58    "break",
59    "case",
60    "const",
61    "continue",
62    "continuing",
63    "default",
64    "discard",
65    "else",
66    "enable",
67    "false",
68    "fn",
69    "for",
70    "if",
71    "let",
72    "loop",
73    "override",
74    "return",
75    "static_assert",
76    "struct",
77    "switch",
78    "true",
79    "type",
80    "var",
81    "while",
82    // Reserved Words
83    "CompileShader",
84    "ComputeShader",
85    "DomainShader",
86    "GeometryShader",
87    "Hullshader",
88    "NULL",
89    "Self",
90    "abstract",
91    "active",
92    "alignas",
93    "alignof",
94    "as",
95    "asm",
96    "asm_fragment",
97    "async",
98    "attribute",
99    "auto",
100    "await",
101    "become",
102    "binding_array",
103    "cast",
104    "catch",
105    "class",
106    "co_await",
107    "co_return",
108    "co_yield",
109    "coherent",
110    "column_major",
111    "common",
112    "compile",
113    "compile_fragment",
114    "concept",
115    "const_cast",
116    "consteval",
117    "constexpr",
118    "constinit",
119    "crate",
120    "debugger",
121    "decltype",
122    "delete",
123    "demote",
124    "demote_to_helper",
125    "do",
126    "dynamic_cast",
127    "enum",
128    "explicit",
129    "export",
130    "extends",
131    "extern",
132    "external",
133    "fallthrough",
134    "filter",
135    "final",
136    "finally",
137    "friend",
138    "from",
139    "fxgroup",
140    "get",
141    "goto",
142    "groupshared",
143    "handle",
144    "highp",
145    "impl",
146    "implements",
147    "import",
148    "inline",
149    "inout",
150    "instanceof",
151    "interface",
152    "layout",
153    "lowp",
154    "macro",
155    "macro_rules",
156    "match",
157    "mediump",
158    "meta",
159    "mod",
160    "module",
161    "move",
162    "mut",
163    "mutable",
164    "namespace",
165    "new",
166    "nil",
167    "noexcept",
168    "noinline",
169    "nointerpolation",
170    "noperspective",
171    "null",
172    "nullptr",
173    "of",
174    "operator",
175    "package",
176    "packoffset",
177    "partition",
178    "pass",
179    "patch",
180    "pixelfragment",
181    "precise",
182    "precision",
183    "premerge",
184    "priv",
185    "protected",
186    "pub",
187    "public",
188    "readonly",
189    "ref",
190    "regardless",
191    "register",
192    "reinterpret_cast",
193    "requires",
194    "resource",
195    "restrict",
196    "self",
197    "set",
198    "shared",
199    "signed",
200    "sizeof",
201    "smooth",
202    "snorm",
203    "static",
204    "static_assert",
205    "static_cast",
206    "std",
207    "subroutine",
208    "super",
209    "target",
210    "template",
211    "this",
212    "thread_local",
213    "throw",
214    "trait",
215    "try",
216    "typedef",
217    "typeid",
218    "typename",
219    "typeof",
220    "union",
221    "unless",
222    "unorm",
223    "unsafe",
224    "unsized",
225    "use",
226    "using",
227    "varying",
228    "virtual",
229    "volatile",
230    "wgsl",
231    "where",
232    "with",
233    "writeonly",
234    "yield",
235];
236
237/// The above set of reserved keywords, turned into a cached HashSet. This saves
238/// significant time during [`Namer::reset`](crate::proc::Namer::reset).
239///
240/// See <https://github.com/gfx-rs/wgpu/pull/7338> for benchmarks.
241pub static RESERVED_SET: RacyLock<HashSet<&'static str>> = RacyLock::new(|| {
242    let mut set = HashSet::default();
243    set.reserve(RESERVED.len());
244    for &word in RESERVED {
245        set.insert(word);
246    }
247    set
248});