During RustConf, the small introduction to the Rust Language Service reminded me of an idea I had about a year ago. The idea was to show, in an IDE, the areas where a variable/expression was borrowed immutably, borrowed mutably or moved. Last week I decided to reach out on twitter to @jntrnr and @nrc (the guys who presented the Rust Language Service during RustConf). It turns out someone else, @evestera, saw my tweet and had thought of the exact same idea (down to the colors, except I had orange instead of red) and was already working on it for his master’s thesis http://erik.vestera.as/rustvis/specs.
I’d like to use this post as a way to organize the work around this as well as discuss improvements to the design. @eddyb helped me out on IRC by pointing out where in the compiler I could get the information necessary (src/librustc_borrowck/borrowck/gather_loans/mod.rs is where the important information for this is gathered by the compiler). I’ll add more details later on, but I wanted to put this out there before I got busy and forgot again.
One area that will be important but hasn’t been easy for me to figure out is how to deal with non-lexical lifetimes (which @jntrnr brought up on twitter). Using multiple colors can get confusing once the number of branches grows even a little. The colors have a meaning associated with them, and I think having too many colors would make it very confusing to follow.
The output could be something along the lines of:
[
{type: "live", start: 5, end: 7},
{type: "live", start: 12, end: 467},
{type: "imm", start: 123, end: 456},
{type: "mut", start: 234, end: 345},
{type: "mov", start: 457, end: 467},
...
]
or
[
"live": [{start: 5, end: 7}, {start:12, end:467}],
...
]
The reason for multiple live
sections would be for function parameters. I don’t think it would make sense to highlight all parameters if the value of interest is the first param.
The only code I have at the moment is a very basic compiler plugin that isn’t usable yet. I’m not even sure if this is the right approach for something like the Rust Language Service. Rather than waste more time on my own I thought I’d reach out for help, and help out @evestera however I can.
Once this is in place, it opens up the possibility for an idea I have about editing Rust in a VR environment. I can add details if anyone would like, but I didn’t want to pollute the post with something nowhere near ready for dev.