Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Speed improvements for cargo based linting #29

Closed
aomader opened this issue Jul 12, 2015 · 5 comments
Closed

Speed improvements for cargo based linting #29

aomader opened this issue Jul 12, 2015 · 5 comments

Comments

@aomader
Copy link
Contributor

aomader commented Jul 12, 2015

Instead of using cargo build to generate the lint messages, it might make sense to use cargo rustc in combination with -Z no-trans, as it is already done with rustc based linting. The downside of this approach is, that one has to specify which target to build, .i.e., --lib, --bin NAME, etc, which might require multiple runs to really get all messages.

@HybridEidolon
Copy link
Contributor

I'll add that because cargo build is used, the entire crate and all of its dependencies is built upon saving a file. This causes a number of problems:

  1. if you tab into a terminal to run cargo build, undefined behavior occurs due to two instances of cargo building the same thing. More often than not this causes errors and fails to output rlibs and the executables. This gets much worse when dependencies aren't fully built.
  2. if you save two or more files in quick succession, multiple cargo builds are initiated. Same issue as Spawning rustc process on every save #16, this can result in total saturation of the computer's resources.

The main issue can be solved if cargo had an option to only build the crate specified by the -p argument or the current crate, and simply return a non-zero exit code otherwise. The linter could then identify that error code and respond with a warning telling the user to first run a full cargo build of the dependencies. An additional option to build only dependencies would be helpful here, since the current crate code is expected not to build if linting is necessary anyway.

The side effects (and issue #16) can be solved by rate-limiting linting such that only one lint can be running at any time. This is probably an issue with the linter package itself, only it becomes such a problem for rust and not other languages due to it being a compiled language using the compiler directly for linting. I think the linter API should have an option to rate-limit calls to lint per linter, since this same problem can affect other compiled languages.

Cargo issue for build only: rust-lang/cargo#1891

@wackywendell
Copy link

Another way around this is cargo check, which is part of cargo-extras. An option to use that instead of build or instead of rustc -Z no-trans would be nice. cargo check is just a shortcut for rustc -Z no-trans, but I believe it has the added benefit of checking the whole crate instead of just the current file.

@colin-kiegel
Copy link
Contributor

PR #43 adds an option for cargo check to linter-rust. :-)

@wackywendell
Copy link

Hurray!

@White-Oak
Copy link
Member

This one should probably be closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants