diff options
-rw-r--r-- | ARCHITECTURE.md | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index d31290483..3b200bbc8 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md | |||
@@ -4,6 +4,33 @@ This document describes high-level architecture of rust-analyzer. | |||
4 | If you want to familiarize yourself with the code base, you are just | 4 | If you want to familiarize yourself with the code base, you are just |
5 | in the right place! | 5 | in the right place! |
6 | 6 | ||
7 | ## The Big Picture | ||
8 | |||
9 | ![](https://user-images.githubusercontent.com/1711539/50114578-e8a34280-0255-11e9-902c-7cfc70747966.png) | ||
10 | |||
11 | On the highest level, rust-analyzer is a thing which accepts input source code | ||
12 | from the client and produces a structured semantic model of the code. | ||
13 | |||
14 | More specifically, input data consists of a set of test files (`(PathBuf, | ||
15 | String)` pairs) and an information about project structure, the so called | ||
16 | `CrateGraph`. Crate graph specifies which files are crate roots, which cfg flags | ||
17 | are specified for each crate (TODO: actually implement this) and what are | ||
18 | dependencies between the crate. The analyzer keeps all these input data in | ||
19 | memory and never does any IO. Because the input data is source code, which | ||
20 | typically measures in tens of megabytes at most, keeping all input data in | ||
21 | memory is OK. | ||
22 | |||
23 | A "structured semantic model" is basically an object-oriented representations of | ||
24 | modules, functions and types which appear in the source code. This representation | ||
25 | is fully "resolved": all expressions have types, all references are bound to | ||
26 | declarations, etc. | ||
27 | |||
28 | The client can submit a small delta of input data (typically, a change to a | ||
29 | single file) and get a fresh code model which accounts for changes. | ||
30 | |||
31 | Underlying engine makes sure that model is computed lazily (on-demand) and can | ||
32 | be quickly updated for small modifications. | ||
33 | |||
7 | 34 | ||
8 | ## Code generation | 35 | ## Code generation |
9 | 36 | ||
@@ -86,7 +113,7 @@ current state, incorporates changes and handles out `Analysis` --- an | |||
86 | immutable consistent snapshot of world state at a point in time, which | 113 | immutable consistent snapshot of world state at a point in time, which |
87 | actually powers analysis. | 114 | actually powers analysis. |
88 | 115 | ||
89 | One interesting aspect of analysis is its support for cancelation. When a change | 116 | One interesting aspect of analysis is its support for cancellation. When a change |
90 | is applied to `AnalysisHost`, first all currently active snapshots are | 117 | is applied to `AnalysisHost`, first all currently active snapshots are |
91 | cancelled. Only after all snapshots are dropped the change actually affects the | 118 | cancelled. Only after all snapshots are dropped the change actually affects the |
92 | database. | 119 | database. |