-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
Fix false positive for multi dep single use statements #120
Fix false positive for multi dep single use statements #120
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! Just want a bit more comments, please.
src/search_unused.rs
Outdated
// - `use (::)?(?i){name}(?-i)(::|;| as)`: matches `use foo;`, `use foo::bar`, `use foo as | ||
// bar;`, with |
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 we keep the previous formatting here? It's weird to read on two lines.
src/search_unused.rs
Outdated
// - `extern crate (?i){name}(?-i)( |;)`: matches `extern crate foo`, or `extern crate foo as | ||
// bar`. |
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
src/search_unused.rs
Outdated
// 2. Matches the crate's name with optional sub-modules | ||
// 3. Matches modules after the usage of the crate's name | ||
// | ||
// In order to avoid false usage detection of `not_my_dep::my_dep` the regexp unsures that the |
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.
// In order to avoid false usage detection of `not_my_dep::my_dep` the regexp unsures that the | |
// In order to avoid false usage detection of `not_my_dep::my_dep` the regexp ensures that the |
// engine doesn't support recursion). Therefore, sub modules are authorized up to 4 levels | ||
// deep. | ||
|
||
let sub_modules_match = r#"(?:::\w+)*(?:::\*|\s+as\s+\w+|::\{(?:[^{}]*(?:\{(?:[^{}]*(?:\{(?:[^{}]*(?:\{[^{}]*\})?[^{}]*)*\})?[^{}]*)*\})?[^{}]*)*\})?"#; |
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.
It's already a nice comment, but can I ask for a little bit more please: could you take each part of this regular expression, and tie it to the comment? (Which part is 1. in your list, 2. in your list, etc. and feel free to add more comment sections if necessary)
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.
I've linked the different parts 😊
Hi @bnjbvr , Sorry for the delay, I missed your comments 😞 I've addressed them and added a Have a nice day! |
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! I'm not a huge fan of the custom .rustfmt.toml
, so I'll get rid of it.
Thanks a lot for the comments, they make the regular expression slightly easier to understand (what a monster have we created here, now wondering if using a custom Rust syntax parser written with nom
would be easier…).
I've tried it out on one of my favorite Rust projects wasmtime
:
- wall clock time took a 18% slowdown hit, from 720ms -> 856ms
- user time took a 35% slowdown hit, from 2.7s -> 3.67s
While these are impressive in terms of relative numbers, since the tool is still running in less than a second on such a large code base, I consider it fine, especially since it's correcter (and what's the point of being fast if code isn't correct).
Merging, thanks a bunch 🙏
Resolves #91
This also resolves some false detections of
not_my_dep::my_dep_name::stuff_in_my_dep
😊 I couldn't find a way to avoid detection offutures
in with the single line regexpThis update does come at a small performance downside (that might be resolved by not instantiating a regexp per dependency?). On our repo of ~500k lines of machete goes from ~45s user time to ~48s of user time.