|
1 | | -use crate::common; |
2 | | -use crate::proc::KeywordSet; |
| 1 | +use crate::proc::{concrete_int_scalars, vector_size_str, vector_sizes, KeywordSet}; |
3 | 2 | use crate::racy_lock::RacyLock; |
4 | | -use alloc::vec::Vec; |
5 | | -use alloc::{boxed::Box, format}; |
| 3 | +use alloc::{format, string::String, vec::Vec}; |
6 | 4 |
|
7 | 5 | // MSLS - Metal Shading Language Specification: |
8 | 6 | // https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf |
9 | 7 | // |
10 | 8 | // C++ - Standard for Programming Language C++ (N4431) |
11 | 9 | // https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4431.pdf |
12 | | -pub const RESERVED: &[&str] = &[ |
| 10 | +const RESERVED: &[&str] = &[ |
13 | 11 | // Undocumented |
14 | 12 | "assert", // found in https://github.com/gfx-rs/wgpu/issues/5347 |
15 | 13 | // Standard for Programming Language C++ (N4431): 2.5 Alternative tokens |
@@ -363,65 +361,31 @@ pub const RESERVED: &[&str] = &[ |
363 | 361 | super::writer::EXTERNAL_TEXTURE_WRAPPER_STRUCT, |
364 | 362 | ]; |
365 | 363 |
|
366 | | -const CONCRETE_INTEGER_SCALARS: [crate::Scalar; 4] = [ |
367 | | - crate::Scalar::I32, |
368 | | - crate::Scalar::U32, |
369 | | - crate::Scalar::I64, |
370 | | - crate::Scalar::U64, |
371 | | -]; |
372 | | - |
373 | | -const CONCRETE_VECTOR_SIZES: [crate::VectorSize; 3] = [ |
374 | | - crate::VectorSize::Bi, |
375 | | - crate::VectorSize::Tri, |
376 | | - crate::VectorSize::Quad, |
377 | | -]; |
378 | | - |
379 | | -/// The above set of reserved keywords, turned into a cached HashSet. This saves |
380 | | -/// significant time during [`Namer::reset`](crate::proc::Namer::reset). |
381 | | -/// |
382 | | -/// See <https://github.com/gfx-rs/wgpu/pull/7338> for benchmarks. |
383 | | -pub static RESERVED_SET: RacyLock<KeywordSet> = RacyLock::new(|| { |
384 | | - let mut set = KeywordSet::from_iter(RESERVED); |
385 | | - // Add all concrete integer dot product function variants. |
386 | | - // These are generated to match the names produced by |
387 | | - // `Writer::get_dot_wrapper_function_helper_name`, ensuring they stay in sync. |
388 | | - let mut dot_function_names: Vec<&'static str> = Vec::new(); |
389 | | - for scalar in CONCRETE_INTEGER_SCALARS { |
390 | | - // Map scalar to MSL type name (matching the logic in Scalar::to_msl_name) |
391 | | - let type_name = match scalar { |
392 | | - crate::Scalar { |
393 | | - kind: crate::ScalarKind::Sint, |
394 | | - width: 4, |
395 | | - } => "int", |
396 | | - crate::Scalar { |
397 | | - kind: crate::ScalarKind::Uint, |
398 | | - width: 4, |
399 | | - } => "uint", |
400 | | - crate::Scalar { |
401 | | - kind: crate::ScalarKind::Sint, |
402 | | - width: 8, |
403 | | - } => "long", |
404 | | - crate::Scalar { |
405 | | - kind: crate::ScalarKind::Uint, |
406 | | - width: 8, |
407 | | - } => "ulong", |
408 | | - _ => continue, // Skip non-integer or unsupported types |
409 | | - }; |
410 | | - |
411 | | - for size in CONCRETE_VECTOR_SIZES { |
412 | | - let size_suffix = common::vector_size_str(size); |
| 364 | +// The set of concrete integer dot product function variants. |
| 365 | +// This must match the set of names that could be produced by |
| 366 | +// `Writer::get_dot_wrapper_function_helper_name`. |
| 367 | +static DOT_FUNCTION_NAMES: RacyLock<Vec<String>> = RacyLock::new(|| { |
| 368 | + let mut names = Vec::new(); |
| 369 | + for scalar in concrete_int_scalars().map(crate::Scalar::to_msl_name) { |
| 370 | + for size_suffix in vector_sizes().map(vector_size_str) { |
413 | 371 | let fun_name = format!( |
414 | 372 | "{}_{}{}", |
415 | 373 | super::writer::DOT_FUNCTION_PREFIX, |
416 | | - type_name, |
| 374 | + scalar, |
417 | 375 | size_suffix |
418 | 376 | ); |
419 | | - // Convert to &'static str by leaking the String |
420 | | - // (In theory) This is safe because these are generated once and cached |
421 | | - let leaked = Box::leak(fun_name.into_boxed_str()); |
422 | | - dot_function_names.push(leaked); |
| 377 | + names.push(fun_name); |
423 | 378 | } |
424 | 379 | } |
425 | | - set.extend(dot_function_names); |
| 380 | + names |
| 381 | +}); |
| 382 | + |
| 383 | +/// The above set of reserved keywords, turned into a cached HashSet. This saves |
| 384 | +/// significant time during [`Namer::reset`](crate::proc::Namer::reset). |
| 385 | +/// |
| 386 | +/// See <https://github.com/gfx-rs/wgpu/pull/7338> for benchmarks. |
| 387 | +pub static RESERVED_SET: RacyLock<KeywordSet> = RacyLock::new(|| { |
| 388 | + let mut set = KeywordSet::from_iter(RESERVED); |
| 389 | + set.extend(DOT_FUNCTION_NAMES.iter().map(String::as_str)); |
426 | 390 | set |
427 | 391 | }); |
0 commit comments