diff options
-rw-r--r-- | ARCHITECTURE.md | 4 | ||||
-rw-r--r-- | Cargo.lock | 6 | ||||
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 3 | ||||
-rw-r--r-- | crates/ra_db/src/input.rs | 56 |
4 files changed, 51 insertions, 18 deletions
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 3b200bbc8..823db0034 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md | |||
@@ -91,7 +91,9 @@ We use [salsa][https://github.com/salsa-rs/salsa] crate for incremental and | |||
91 | on-demand computation. Roughly, you can think of salsa as a key-value store, but | 91 | on-demand computation. Roughly, you can think of salsa as a key-value store, but |
92 | it also can compute derived values using specified functions. The `ra_db` crate | 92 | it also can compute derived values using specified functions. The `ra_db` crate |
93 | provides a basic infrastructure for interracting with salsa. Crucially, it | 93 | provides a basic infrastructure for interracting with salsa. Crucially, it |
94 | defines most of the "input" queries: facts supplied by the client of the analyzer. | 94 | defines most of the "input" queries: facts supplied by the client of the |
95 | analyzer. Reading the docs of the `ra_db::input` module should be useful: | ||
96 | everithing else is strictly derived from thouse inputs. | ||
95 | 97 | ||
96 | ### `crates/ra_hir` | 98 | ### `crates/ra_hir` |
97 | 99 | ||
diff --git a/Cargo.lock b/Cargo.lock index 7ebe6e67f..5e5db84c3 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -546,7 +546,7 @@ name = "parking_lot" | |||
546 | version = "0.7.0" | 546 | version = "0.7.0" |
547 | source = "registry+https://github.com/rust-lang/crates.io-index" | 547 | source = "registry+https://github.com/rust-lang/crates.io-index" |
548 | dependencies = [ | 548 | dependencies = [ |
549 | "lock_api 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", | 549 | "lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", |
550 | "parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", | 550 | "parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", |
551 | ] | 551 | ] |
552 | 552 | ||
@@ -567,10 +567,10 @@ name = "parking_lot_core" | |||
567 | version = "0.4.0" | 567 | version = "0.4.0" |
568 | source = "registry+https://github.com/rust-lang/crates.io-index" | 568 | source = "registry+https://github.com/rust-lang/crates.io-index" |
569 | dependencies = [ | 569 | dependencies = [ |
570 | "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", | 570 | "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", |
571 | "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", | 571 | "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", |
572 | "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", | 572 | "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", |
573 | "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", | 573 | "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", |
574 | "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", | 574 | "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", |
575 | ] | 575 | ] |
576 | 576 | ||
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index c4291885a..b44d9297a 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -105,9 +105,6 @@ impl AnalysisHostImpl { | |||
105 | self.db | 105 | self.db |
106 | .query_mut(ra_db::FileTextQuery) | 106 | .query_mut(ra_db::FileTextQuery) |
107 | .set(remove_file.file_id, Default::default()); | 107 | .set(remove_file.file_id, Default::default()); |
108 | self.db | ||
109 | .query_mut(ra_db::FileRelativePathQuery) | ||
110 | .set(remove_file.file_id, Default::default()); | ||
111 | source_root.files.remove(&remove_file.path); | 108 | source_root.files.remove(&remove_file.path); |
112 | } | 109 | } |
113 | self.db | 110 | self.db |
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index cccf37cc2..095730521 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs | |||
@@ -1,3 +1,6 @@ | |||
1 | /// This modules specifies the input to rust-analyzer. In some sense, this is | ||
2 | /// **the** most important module, because all other fancy stuff is strickly | ||
3 | /// derived from this input. | ||
1 | use std::sync::Arc; | 4 | use std::sync::Arc; |
2 | 5 | ||
3 | use rustc_hash::{FxHashMap}; | 6 | use rustc_hash::{FxHashMap}; |
@@ -5,20 +8,48 @@ use relative_path::RelativePathBuf; | |||
5 | use ra_syntax::SmolStr; | 8 | use ra_syntax::SmolStr; |
6 | use salsa; | 9 | use salsa; |
7 | 10 | ||
8 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] | 11 | /// `FileId` is an integer which uniquely identifies a file. File paths are |
9 | pub struct SourceRootId(pub u32); | 12 | /// messy and system-dependent, so most of the code should work directly with |
10 | 13 | /// `FileId`, without inspecting the path. The mapping between `FileId` and path | |
14 | /// and `SourceRoot` is constant. File rename is represented as a pair of | ||
15 | /// deletion/creation. | ||
11 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | 16 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
12 | pub struct FileId(pub u32); | 17 | pub struct FileId(pub u32); |
13 | 18 | ||
14 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | 19 | /// Files are grouped into source roots. A source root is a directory on the |
15 | pub struct CrateId(pub u32); | 20 | /// file systems which is watched for changes. Typically it corresponds to a |
21 | /// Cargo package. Source roots *might* be nested: in this case, file belongs to | ||
22 | /// the nearest enclosing source root. Path to files are always relative to a | ||
23 | /// source root, and analyzer does not know the root path of the source root at | ||
24 | /// all. So, a file from one source root can't refere a file in another source | ||
25 | /// root by path. | ||
26 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] | ||
27 | pub struct SourceRootId(pub u32); | ||
28 | |||
29 | #[derive(Default, Clone, Debug, PartialEq, Eq)] | ||
30 | pub struct SourceRoot { | ||
31 | pub files: FxHashMap<RelativePathBuf, FileId>, | ||
32 | } | ||
16 | 33 | ||
34 | /// `CrateGraph` is a bit of information which turns a set of text files into a | ||
35 | /// number of Rust crates. Each Crate is the `FileId` of it's root module, the | ||
36 | /// set of cfg flags (not yet implemented) and the set of dependencies. Note | ||
37 | /// that, due to cfg's, there might be several crates for a single `FileId`! As | ||
38 | /// in the rust-lang proper, a crate does not have a name. Instead, names are | ||
39 | /// specified on dependency edges. That is, a crate might be known under | ||
40 | /// different names in different dependant crates. | ||
41 | /// | ||
42 | /// Note that `CrateGraph` is build-system agnostic: it's a concept of the Rust | ||
43 | /// langauge proper, not a concept of the build system. In practice, we get | ||
44 | /// `CrateGraph` by lowering `cargo metadata` output. | ||
17 | #[derive(Debug, Clone, Default, PartialEq, Eq)] | 45 | #[derive(Debug, Clone, Default, PartialEq, Eq)] |
18 | pub struct CrateGraph { | 46 | pub struct CrateGraph { |
19 | arena: FxHashMap<CrateId, CrateData>, | 47 | arena: FxHashMap<CrateId, CrateData>, |
20 | } | 48 | } |
21 | 49 | ||
50 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
51 | pub struct CrateId(pub u32); | ||
52 | |||
22 | #[derive(Debug, Clone, PartialEq, Eq)] | 53 | #[derive(Debug, Clone, PartialEq, Eq)] |
23 | struct CrateData { | 54 | struct CrateData { |
24 | file_id: FileId, | 55 | file_id: FileId, |
@@ -57,7 +88,7 @@ impl CrateGraph { | |||
57 | assert!(prev.is_none()); | 88 | assert!(prev.is_none()); |
58 | crate_id | 89 | crate_id |
59 | } | 90 | } |
60 | //FIXME: check that we don't have cycles here. | 91 | // FIXME: check that we don't have cycles here. |
61 | // Just a simple depth first search from `to` should work, | 92 | // Just a simple depth first search from `to` should work, |
62 | // the graph is small. | 93 | // the graph is small. |
63 | pub fn add_dep(&mut self, from: CrateId, name: SmolStr, to: CrateId) { | 94 | pub fn add_dep(&mut self, from: CrateId, name: SmolStr, to: CrateId) { |
@@ -83,6 +114,7 @@ impl CrateGraph { | |||
83 | 114 | ||
84 | salsa::query_group! { | 115 | salsa::query_group! { |
85 | pub trait FilesDatabase: salsa::Database { | 116 | pub trait FilesDatabase: salsa::Database { |
117 | /// Text of the file. | ||
86 | fn file_text(file_id: FileId) -> Arc<String> { | 118 | fn file_text(file_id: FileId) -> Arc<String> { |
87 | type FileTextQuery; | 119 | type FileTextQuery; |
88 | storage input; | 120 | storage input; |
@@ -92,30 +124,32 @@ salsa::query_group! { | |||
92 | type FileRelativePathQuery; | 124 | type FileRelativePathQuery; |
93 | storage input; | 125 | storage input; |
94 | } | 126 | } |
127 | /// Source root of the file. | ||
95 | fn file_source_root(file_id: FileId) -> SourceRootId { | 128 | fn file_source_root(file_id: FileId) -> SourceRootId { |
96 | type FileSourceRootQuery; | 129 | type FileSourceRootQuery; |
97 | storage input; | 130 | storage input; |
98 | } | 131 | } |
132 | /// Contents of the source root. | ||
99 | fn source_root(id: SourceRootId) -> Arc<SourceRoot> { | 133 | fn source_root(id: SourceRootId) -> Arc<SourceRoot> { |
100 | type SourceRootQuery; | 134 | type SourceRootQuery; |
101 | storage input; | 135 | storage input; |
102 | } | 136 | } |
137 | /// The set of "local" (that is, from the current workspace) roots. | ||
138 | /// Files in local roots are assumed to change frequently. | ||
103 | fn local_roots() -> Arc<Vec<SourceRootId>> { | 139 | fn local_roots() -> Arc<Vec<SourceRootId>> { |
104 | type LocalRootsQuery; | 140 | type LocalRootsQuery; |
105 | storage input; | 141 | storage input; |
106 | } | 142 | } |
143 | /// The set of roots for crates.io libraries. | ||
144 | /// Files in libraries are assumed to never change. | ||
107 | fn library_roots() -> Arc<Vec<SourceRootId>> { | 145 | fn library_roots() -> Arc<Vec<SourceRootId>> { |
108 | type LibraryRootsQuery; | 146 | type LibraryRootsQuery; |
109 | storage input; | 147 | storage input; |
110 | } | 148 | } |
149 | /// The crate graph. | ||
111 | fn crate_graph() -> Arc<CrateGraph> { | 150 | fn crate_graph() -> Arc<CrateGraph> { |
112 | type CrateGraphQuery; | 151 | type CrateGraphQuery; |
113 | storage input; | 152 | storage input; |
114 | } | 153 | } |
115 | } | 154 | } |
116 | } | 155 | } |
117 | |||
118 | #[derive(Default, Clone, Debug, PartialEq, Eq)] | ||
119 | pub struct SourceRoot { | ||
120 | pub files: FxHashMap<RelativePathBuf, FileId>, | ||
121 | } | ||