-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a twiggy garbage
command. Fixes issue #48.
#50
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much @data-pup!
This is near-perfect -- just a couple nitpicks below that should be fixed before we merge this.
Thanks again!
analyze/analyze.rs
Outdated
/// Find items that are not transitively referenced by any exports or public functions. | ||
pub fn garbage( | ||
_items: &ir::Items, | ||
_opts: &opt::Garbage, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variables with a leading underscore are usually reserved for unused variables. Stylistically, it is a little weird for these parameters to be used despite the leading underscore. These should be changed to plain items
and opts
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh shoot! I meant to change those, I had placed the garbage function declaration in with an unimplemented
macro when I was working on the plumbing elsewhere. Will do!
analyze/analyze.rs
Outdated
_items: &ir::Items, | ||
_opts: &opt::Garbage, | ||
) -> Result<Box<traits::Emit>, traits::Error> { | ||
fn get_reachable_items(_items: &ir::Items) -> BTreeSet<ir::Id> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
analyze/analyze.rs
Outdated
#[derive(Debug)] | ||
struct Garbage { | ||
items: Vec<ir::Id>, | ||
opts: opt::Garbage, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the opts
field ever used? If not, then we should remove it.
twiggy/tests/expectations/garbage
Outdated
@@ -0,0 +1,11 @@ | |||
Bytes │ Size % │ Item |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check in the WAT source used to generate garbage.wasm
too? That way we can easily make changes if we need to update it in the future.
twiggy/tests/expectations/garbage
Outdated
Bytes │ Size % │ Item | ||
───────┼────────┼──────── | ||
11 ┊ 13.10% ┊ code[2] | ||
8 ┊ 9.52% ┊ code[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably also build garbage.wasm
with the --debug-names
flag, so we get function names instead of code[N]
.
README.md
Outdated
transitively referenced by any exports or public functions. | ||
|
||
``` | ||
AWOO : Place output example here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to fill this out ;)
analyze/Cargo.toml
Outdated
@@ -15,3 +15,4 @@ path = "./analyze.rs" | |||
twiggy-ir = { version = "0.1.0", path = "../ir" } | |||
twiggy-opt = { version = "0.1.0", path = "../opt", default-features = false } | |||
twiggy-traits = { version = "0.1.0", path = "../traits" } | |||
petgraph = "0.4.12" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now we depend on an older point release in ir/Cargo.toml
:
ir/Cargo.toml:17:petgraph = "0.4.11"
Can you update that so that we have the same dependency? Thanks!
analyze/analyze.rs
Outdated
let mut table = Table::with_header(vec![ | ||
(Align::Right, "Bytes".to_string()), | ||
(Align::Right, "Size %".to_string()), | ||
(Align::Right, "Item".to_string()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This column should be titled "Garbage Item" just to help distinguish the output of this command.
Thanks for the review! I can take care of these changes tonight :) |
* Remove leading underscores in variables in the `garbage` function. * Check in the WAT source for the used for the garbage test fixture. * Compile the test fixture using wat2wasm's `--debug-names` flag. * Add missing example output to `README.md`. * Adjusted `petgraph` dependency to use same version used elsewhere in project. * Update name of item column when printing to stdout. * Remove extraneous `opts` member from the `Garbage` struct.
I added the patches from your review @fitzgen :) I left this as two separate commits so you can review it faster, but I can rebase these into a single commit if you would like! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect! Thanks!
This fixes #48, and adds a
garbage
subcommand. This includes a test fixture in the form of a wasm module, the source of which can be found here.Let me know if there are any changes or extra options we should add, I'd be happy to do so. Thanks for the mentoring instructions on this issue, had a lot of fun getting this done! Twiggy is a really neat project :D