diff options
author | Aleksey Kladov <[email protected]> | 2019-01-19 13:10:32 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-21 08:27:01 +0000 |
commit | cb8dfab21c85f79b97cfd8e5cf3cff88c2e6d269 (patch) | |
tree | 98ef8fe47914c39e6d86879d43917e79ac698815 | |
parent | 7e1d866481aa6f11dbe96c4d47b6b61b276f07b3 (diff) |
finish modules section
-rw-r--r-- | guide.md | 19 |
1 files changed, 10 insertions, 9 deletions
@@ -281,10 +281,9 @@ file", which could then be reused by several semantic models if this file | |||
281 | happens to be a part of several crates. | 281 | happens to be a part of several crates. |
282 | 282 | ||
283 | Rust analyzer uses a similar representation of syntax trees to that of `Roslyn` | 283 | Rust analyzer uses a similar representation of syntax trees to that of `Roslyn` |
284 | and Swift's new | 284 | and Swift's new [libsyntax]. Swift's docs give an excellent overview of the |
285 | [libsyntax](https://github.com/apple/swift/tree/5e2c815edfd758f9b1309ce07bfc01c4bc20ec23/lib/Syntax). | 285 | approach, so I skip this part here and instead outline the main characteristics |
286 | Swift's docs give an excellent overview of the approach, so I skip this part | 286 | of the syntax trees: |
287 | here and instead outline the main characteristics of the syntax trees: | ||
288 | 287 | ||
289 | * Syntax trees are fully lossless. Converting **any** text to a syntax tree and | 288 | * Syntax trees are fully lossless. Converting **any** text to a syntax tree and |
290 | back is a total identity function. All whitespace and comments are explicitly | 289 | back is a total identity function. All whitespace and comments are explicitly |
@@ -313,6 +312,7 @@ here and instead outline the main characteristics of the syntax trees: | |||
313 | The implementation is based on the generic [rowan] crate on top of which a | 312 | The implementation is based on the generic [rowan] crate on top of which a |
314 | [rust-specific] AST is generated. | 313 | [rust-specific] AST is generated. |
315 | 314 | ||
315 | [libsyntax]: https://github.com/apple/swift/tree/5e2c815edfd758f9b1309ce07bfc01c4bc20ec23/lib/Syntax | ||
316 | [rowan]: https://github.com/rust-analyzer/rowan/tree/100a36dc820eb393b74abe0d20ddf99077b61f88 | 316 | [rowan]: https://github.com/rust-analyzer/rowan/tree/100a36dc820eb393b74abe0d20ddf99077b61f88 |
317 | [rust-specific]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_syntax/src/ast/generated.rs | 317 | [rust-specific]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_syntax/src/ast/generated.rs |
318 | 318 | ||
@@ -323,8 +323,9 @@ The next step in constructing the semantic model is ... | |||
323 | The algorithm for building a tree of modules is to start with a crate root | 323 | The algorithm for building a tree of modules is to start with a crate root |
324 | (remember, each `Crate` from a `CrateGraph` has a `FileId`), collect all mod | 324 | (remember, each `Crate` from a `CrateGraph` has a `FileId`), collect all mod |
325 | declarations and recursively process child modules. This is handled by the | 325 | declarations and recursively process child modules. This is handled by the |
326 | [`module_tree_query`](https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/module_tree.rs#L116-L123), | 326 | [`module_tree_query`], with a two slight variations. |
327 | with a two slight variations. | 327 | |
328 | [`module_tree_query`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/module_tree.rs#L116-L123 | ||
328 | 329 | ||
329 | First, rust analyzer builds a module tree for all crates in a source root | 330 | First, rust analyzer builds a module tree for all crates in a source root |
330 | simultaneously. The main reason for this is historical (`module_tree` predates | 331 | simultaneously. The main reason for this is historical (`module_tree` predates |
@@ -345,12 +346,12 @@ names. Now, changing the whitespace results in `submodules_query` being | |||
345 | re-executed for a *single* module, but because the result of this query stays | 346 | re-executed for a *single* module, but because the result of this query stays |
346 | the same, we don't have to re-execute [`module_tree_query`]. In fact, we only | 347 | the same, we don't have to re-execute [`module_tree_query`]. In fact, we only |
347 | need to re-execute it when we add/remove new files or when we change mod | 348 | need to re-execute it when we add/remove new files or when we change mod |
348 | declarations, | 349 | declarations. |
349 | 350 | ||
350 | [`submodules_query`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/module_tree.rs#L41) | 351 | [`submodules_query`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/module_tree.rs#L41) |
351 | 352 | ||
352 | 353 | We store the resulting modules in a `Vec`-based indexed arena. The indices in | |
353 | 354 | the arena becomes module identifiers. | |
354 | 355 | ||
355 | 356 | ||
356 | ## Location Interner pattern | 357 | ## Location Interner pattern |