rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.05k stars 1.56k forks source link

Build test-case minimization tool for rust-analyzer #3149

Open matklad opened 4 years ago

matklad commented 4 years ago

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:

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.

gilescope commented 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.

gilescope commented 4 years ago

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.

gilescope commented 4 years ago

@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?