|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "2019-11-18 IDE team meeting" |
| 4 | +author: Aleksey Kladov, Igor Matuszewski |
| 5 | +team: the IDE team <https://www.rust-lang.org/governance/teams/dev-tools#ides> |
| 6 | +--- |
| 7 | + |
| 8 | +Meeting run by nikomatsakis. Minutes written by nikomatsakis. |
| 9 | +Attending: nikomatsakis, pnkfelix, Xanewok, matklad |
| 10 | +[Notes](https://hackmd.io/fAnj6pNqRRGIyDQ4el5tcQ) |
| 11 | + |
| 12 | +# The Rust IDE |
| 13 | +In the last compiler/IDE team meeting we've discussed the overall direction for IDE support in Rust. |
| 14 | + |
| 15 | +At the moment, the two IDEs developed as part of the Rust project are Rust Language Server (RLS) and rust-analyzer. |
| 16 | +The former is currently being shipped with the Rust distribution while the latter serves as a foundation for the "RLS 2.0" working group. |
| 17 | + |
| 18 | +Unfortunately, these are actively developed in separation without much code-sharing between the two. |
| 19 | +We'd like to change that and to find out how we can unify these efforts. |
| 20 | +Therefore, we've been having a series of talks with the aim of elaborating the design space and creating a proposal for how to improve the situation going forward. |
| 21 | + |
| 22 | +This blog post gives a short summary from our most recent meeting. |
| 23 | + |
| 24 | +# Why 2 IDEs? |
| 25 | +The main benefits of rust-analyzer is greater performance (because of fully-lazy compilation model) and somewhat richer feature-set (due to more flexible analysis API). |
| 26 | +The main benefits of RLS is precision (it uses `rustc` under the hood). |
| 27 | +Additionally, RLS is the main consumer of save-analysis infrastructure, which is a good fit for tools which need a static view of the codebase, such as [cargo-src](https://github.com/rust-dev-tools/cargo-src) or [lsif](https://code.visualstudio.com/blogs/2019/02/19/lsif). |
| 28 | + |
| 29 | +# Save-analysis |
| 30 | + |
| 31 | +What is "save-analysis"? |
| 32 | +It is an unstable format which rustc uses to record information about the compiled code. |
| 33 | +It contains a pretty high-level information. |
| 34 | +For example, for each identifier in the source-crate, save-analyzer will map this identifier to a definition and list of usages. |
| 35 | +`env RUSTFLAGS="-Zunstable-options -Zsave-analysis" cargo check` can be used to instruct `rustc` to produce save-analysis files (in JSON format). |
| 36 | +Because save-analysis is produced directly from rustc iternal data structures, it is guaranteed to be correct (modulo bugs in rustc itself). |
| 37 | + |
| 38 | +# Query model |
| 39 | + |
| 40 | +The fundamental problem with save-analysis is that it is computed for the whole crate at once. |
| 41 | +This is pretty slow for non-trivial crates, and is also wasteful. |
| 42 | +At any given moment in time, only a small fraction of analysis information is really required. |
| 43 | +rust-analyzer solves this by using [`salsa`](https://github.com/salsa-rs/salsa) queries for code analysis. |
| 44 | +The result is a compilation model which is fully lazy across the whole crate graph. |
| 45 | +This model is similar to what rustc is using internally, but is more lazy both "vertically" and "horizontally". |
| 46 | +Vertically, `rustc` starts to be incremental only after parsing and macro expansion; rust-analyzer is incremental on per-file basis. |
| 47 | +Horizontally, `rustc` compiles one crate at a time; rust-analyzer uses queries for the whole crate graph. |
| 48 | + |
| 49 | +# Way forward |
| 50 | +Our current hypothesis is that it is possible to integrate both approaches without doubling the engineering effort. |
| 51 | +Specifically, we will add an option to rust-analyzer to use save-analysis for find-usages and rename functionality. |
| 52 | +That way, we'll get precise results for most important queries, without slowing down completion. |
| 53 | +Unlike RLS, however, rust-analyzer will not link to rustc and instead will rely on cargo for running the compiler and producing save-analysis data. |
| 54 | +If this approach works, we will consider freezing RLS and focusing fully on rust-analyzer. |
| 55 | +Long term, the plan is to unify the save-analysis fallback path and the lazy analysis. |
| 56 | + |
| 57 | +In parallel to this RLS/rust-analyzer unification effort, we continue to pursue rustc library-ification, with a specific focus on traits solving (via chalk) and type inference. |
| 58 | +"Library-ification" is a term we've been using for the process of extracting code out of rustc into re-usable libaries which can be shared by both rustc and rust-analyzer. |
| 59 | +The goal is to use library-ification to gradually reduce the amount of duplicated code between rustc and rust-analyzer, with the goal of eventually either having a single code-base, or having the vast majority of the logic be shared. |
0 commit comments