Open matklad opened 4 years ago
I had a play with rust-reduce which did this kind of thing. I think some of the compiler team wanted to use it but the project's license wasn't compatible.
While I was playing I was thinking that it wasn't the best place to start - it would be far better to start from somewhere like rust-analyser so you knew before invoking the compiler which were likely legitimate transformations.
Ideally I'd like to be able to attempt to apply a minimizing assist and for RA to tell me if that would lead to problems without having to first invoke rustc. I know that's using way more than just ra_syntax but I think RA is uniquely positioned to be able to do the minimization elegantly (or at least in a fairly resource efficient way - potentially far faster than bruteforcing for large codebases).
One great usecase is for private companies using rust but hitting an ICE. They'd like to be able to give a repo to the rust team but they need to be able to quickly reduce their codebase to a minimum that shows the problem and is trivial enough that it can be made publicly available as a bug reproduction.
@matklad as you probably know the LSP better than anyone at this point. One alternative approach might be to create a language agnostic minimizer that communicated through the LSP to achieve its goals. I have no idea whether such a thing might be possible but it would definitely live in the 'fun' category... would that be completely mad idea to try something like that or is that in the outlandish but possible category?
Sometimes we have problems like "rust-analyzer crashes on my 2k crates project" (1, 2).
The first step of debugging these issues involves minimization of example. Doing this manually is really tedious. However, most of minimization steps are semi-automated: replacing function bodies with
loop {}
, inlining modules, deleting irrelevant functions, inlining external crates...We should build a tool which applies this transformations automatically!
Here are some design notes:
ra_syntax
crates. That is, it should be syntax driven, so that specifying transformations is natural, but it should not depend on semantic analysis of ra (otherwise, the tool itself will probably die on the problemantic code). The tool would probably need to understand simplemod foo;
declarations, but that's it.cargo run --pacakge ra_cli -- analysis-stats PATH
, you should be able to minimize it with justcargo run --pacakge ra_cli -- analysis-stats --minimize PATH
.cc @pnkfelix, I think that the work here might be useful for rustc as well?
ra_syntax
interface is relatively stable nowdays, so, regardless of what happens with rust-analyzer as a whole, maintaining this tool, after it is written, should not be a too big burden.