diff options
author | Michal Terepeta <[email protected]> | 2020-01-08 18:29:18 +0000 |
---|---|---|
committer | Michal Terepeta <[email protected]> | 2020-01-08 18:42:27 +0000 |
commit | d761435ba006227bc1a83f8450cfde000dac5aa3 (patch) | |
tree | ed3369dca017123ad6eddd01b504b02a66bbd1ed /crates/ra_db/src | |
parent | 2ffaad10f24ad9d3d748a347e02f170f24833ec3 (diff) |
Remove the Default impl for SourceRoot
Let's be always explicit whether we create a library (i.e., an immutable
dependency) or a local `SourceRoot`, since it can have a large impact on
the validation performance in salsa. (we found it the hard way recently,
where the `Default` instance made it quite tricky to spot a bug)
Signed-off-by: Michal Terepeta <[email protected]>
Diffstat (limited to 'crates/ra_db/src')
-rw-r--r-- | crates/ra_db/src/fixture.rs | 6 | ||||
-rw-r--r-- | crates/ra_db/src/input.rs | 8 |
2 files changed, 7 insertions, 7 deletions
diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs index e8f335e33..30b598e9a 100644 --- a/crates/ra_db/src/fixture.rs +++ b/crates/ra_db/src/fixture.rs | |||
@@ -49,7 +49,7 @@ fn with_single_file(db: &mut dyn SourceDatabaseExt, text: &str) -> FileId { | |||
49 | let file_id = FileId(0); | 49 | let file_id = FileId(0); |
50 | let rel_path: RelativePathBuf = "/main.rs".into(); | 50 | let rel_path: RelativePathBuf = "/main.rs".into(); |
51 | 51 | ||
52 | let mut source_root = SourceRoot::default(); | 52 | let mut source_root = SourceRoot::new_local(); |
53 | source_root.insert_file(rel_path.clone(), file_id); | 53 | source_root.insert_file(rel_path.clone(), file_id); |
54 | 54 | ||
55 | let mut crate_graph = CrateGraph::default(); | 55 | let mut crate_graph = CrateGraph::default(); |
@@ -77,7 +77,7 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit | |||
77 | let mut crate_deps = Vec::new(); | 77 | let mut crate_deps = Vec::new(); |
78 | let mut default_crate_root: Option<FileId> = None; | 78 | let mut default_crate_root: Option<FileId> = None; |
79 | 79 | ||
80 | let mut source_root = SourceRoot::default(); | 80 | let mut source_root = SourceRoot::new_local(); |
81 | let mut source_root_id = WORKSPACE; | 81 | let mut source_root_id = WORKSPACE; |
82 | let mut source_root_prefix: RelativePathBuf = "/".into(); | 82 | let mut source_root_prefix: RelativePathBuf = "/".into(); |
83 | let mut file_id = FileId(0); | 83 | let mut file_id = FileId(0); |
@@ -87,7 +87,7 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit | |||
87 | for entry in fixture.iter() { | 87 | for entry in fixture.iter() { |
88 | let meta = match parse_meta(&entry.meta) { | 88 | let meta = match parse_meta(&entry.meta) { |
89 | ParsedMeta::Root { path } => { | 89 | ParsedMeta::Root { path } => { |
90 | let source_root = std::mem::replace(&mut source_root, SourceRoot::default()); | 90 | let source_root = std::mem::replace(&mut source_root, SourceRoot::new_local()); |
91 | db.set_source_root(source_root_id, Arc::new(source_root)); | 91 | db.set_source_root(source_root_id, Arc::new(source_root)); |
92 | source_root_id.0 += 1; | 92 | source_root_id.0 += 1; |
93 | source_root_prefix = path; | 93 | source_root_prefix = path; |
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index 2a7ed20d1..07269237a 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs | |||
@@ -33,7 +33,7 @@ pub struct FileId(pub u32); | |||
33 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] | 33 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] |
34 | pub struct SourceRootId(pub u32); | 34 | pub struct SourceRootId(pub u32); |
35 | 35 | ||
36 | #[derive(Default, Clone, Debug, PartialEq, Eq)] | 36 | #[derive(Clone, Debug, PartialEq, Eq)] |
37 | pub struct SourceRoot { | 37 | pub struct SourceRoot { |
38 | /// Sysroot or crates.io library. | 38 | /// Sysroot or crates.io library. |
39 | /// | 39 | /// |
@@ -44,11 +44,11 @@ pub struct SourceRoot { | |||
44 | } | 44 | } |
45 | 45 | ||
46 | impl SourceRoot { | 46 | impl SourceRoot { |
47 | pub fn new() -> SourceRoot { | 47 | pub fn new_local() -> SourceRoot { |
48 | Default::default() | 48 | SourceRoot { is_library: false, files: Default::default() } |
49 | } | 49 | } |
50 | pub fn new_library() -> SourceRoot { | 50 | pub fn new_library() -> SourceRoot { |
51 | SourceRoot { is_library: true, ..SourceRoot::new() } | 51 | SourceRoot { is_library: true, files: Default::default() } |
52 | } | 52 | } |
53 | pub fn insert_file(&mut self, path: RelativePathBuf, file_id: FileId) { | 53 | pub fn insert_file(&mut self, path: RelativePathBuf, file_id: FileId) { |
54 | self.files.insert(path, file_id); | 54 | self.files.insert(path, file_id); |