rustwasm/twiggy

Add a `twiggy garbage` subcommand to find unreachable items

Closed this issue · 5 comments

This would print code and data that is not transitively referenced by any exports / public functions. Since linkers and compilers tend to remove dead code, this is more likely to find bugs in our IR graph, but that is also a useful thing ;)

This looks like it would be fun! I would love to try and tackle this one. I can start looking into it tomorrow I believe. Let me know if you have any advice :)

@data-pup great! I would suggest using petgraph::visit::Dfs traversal starting from the meta-root to collect the set of all items that are not garbage (ie transitively reachable from some exported or public item). Then, I would iterate over all items, filtering them down to just the items that aren't in the reachable set (ie are garbage), and then sort those garbage items by size. Does that all make sense?

This would mostly be implemented in analyze/analyze.rs. Although there is a bit of plumbing to add in most of the crates.

aa3330d is a good example of what implementing a new sub command is like.

Awesome! That makes sense to me 🙂

I think I'm getting pretty close to having this done! I should be able to open a PR today for review :D