Skip to content
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

Merged
merged 2 commits into from
May 9, 2018

Conversation

data-pup
Copy link
Member

@data-pup data-pup commented May 9, 2018

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

Copy link
Member

@fitzgen fitzgen left a 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!

/// Find items that are not transitively referenced by any exports or public functions.
pub fn garbage(
_items: &ir::Items,
_opts: &opt::Garbage,
Copy link
Member

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.

Copy link
Member Author

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!

_items: &ir::Items,
_opts: &opt::Garbage,
) -> Result<Box<traits::Emit>, traits::Error> {
fn get_reachable_items(_items: &ir::Items) -> BTreeSet<ir::Id> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

#[derive(Debug)]
struct Garbage {
items: Vec<ir::Id>,
opts: opt::Garbage,
Copy link
Member

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.

@@ -0,0 +1,11 @@
Bytes │ Size % │ Item
Copy link
Member

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.

Bytes │ Size % │ Item
───────┼────────┼────────
11 ┊ 13.10% ┊ code[2]
8 ┊ 9.52% ┊ code[1]
Copy link
Member

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.
Copy link
Member

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 ;)

@@ -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"
Copy link
Member

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!

let mut table = Table::with_header(vec![
(Align::Right, "Bytes".to_string()),
(Align::Right, "Size %".to_string()),
(Align::Right, "Item".to_string()),
Copy link
Member

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.

@data-pup
Copy link
Member Author

data-pup commented May 9, 2018

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.
@data-pup
Copy link
Member Author

data-pup commented May 9, 2018

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!

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! Thanks!

@fitzgen fitzgen merged commit db5e64a into rustwasm:master May 9, 2018
@data-pup data-pup deleted the add-garbage-subcommand branch August 20, 2018 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a twiggy garbage subcommand to find unreachable items
2 participants