-
Notifications
You must be signed in to change notification settings - Fork 1
Advanced Concepts
Mathis Brossier edited this page Feb 19, 2025
·
8 revisions
Name Mangling is the compiler practice of renaming declarations to avoid conflicts when two declarations have the same name. Don't be surprised if you see your functions and structs be renamed in your WGSL output! WESL renames all declarations, except those in the root module (because they are exposed in the host code, as function entry-points, bindings and overrides).
Consider this WESL example:
// file util.rs:
fn foo() { ... }
// file main.rs:
fn foo() { ... }
@compute @workgroup_size(1)
fn main() {
super::util::foo();
foo();
}With name mangling, it generates this:
fn package_util_foo() { ... } // the `foo` funtion from util.rs gets renamed with its mangled absolute path (package::util::foo)
fn foo() { ... } // the `foo` function in the root module is not renamed
@compute @workgroup_size(1)
fn main() {
package_util_foo(); // references to super::util::foo also get renamed.
foo();
}
When your WESL linker bundles your shader files into one final WGSL output, it may remove unused declarations. Unused declarations are those not accessed by any entrypoint function or const_asserts (recursively).
In general, rare cases,
(TBD)
(TBD)
(TBD)
(TBD)
(TBD)