Function naga::compact::compact

source ·
pub fn compact(module: &mut Module)
Expand description

Remove unused types, expressions, and constants from module.

Assuming that all globals, named constants, special types, functions and entry points in module are used, determine which types, constants, and expressions (both function-local and global constant expressions) are actually used, and remove the rest, adjusting all handles as necessary. The result should be a module functionally identical to the original.

This may be useful to apply to modules generated in the snapshot tests. Our backends often generate temporary names based on handle indices, which means that adding or removing unused arena entries can affect the output even though they have no semantic effect. Such meaningless changes add noise to snapshot diffs, making accurate patch review difficult. Compacting the modules before generating snapshots makes the output independent of unused arena entries.

§Panics

If module has not passed validation, this may panic.