pub fn compact(module: &mut Module)
Expand description
Remove unused types, expressions, and constants from module
.
Assume that the following are used by definition:
- global variables
- named constants and overrides
- special types
- functions and entry points, and within those:
- arguments
- local variables
- named expressions
Given those assumptions, determine which types, constants, overrides, and expressions (both function-local and global constant expressions) are actually used, and remove the rest, adjusting all handles as necessary. The result should always 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
would not pass validation, this may panic.