From d761435ba006227bc1a83f8450cfde000dac5aa3 Mon Sep 17 00:00:00 2001 From: Michal Terepeta Date: Wed, 8 Jan 2020 19:29:18 +0100 Subject: 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 --- crates/ra_db/src/fixture.rs | 6 +++--- crates/ra_db/src/input.rs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'crates/ra_db') 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 { let file_id = FileId(0); let rel_path: RelativePathBuf = "/main.rs".into(); - let mut source_root = SourceRoot::default(); + let mut source_root = SourceRoot::new_local(); source_root.insert_file(rel_path.clone(), file_id); let mut crate_graph = CrateGraph::default(); @@ -77,7 +77,7 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option = None; - let mut source_root = SourceRoot::default(); + let mut source_root = SourceRoot::new_local(); let mut source_root_id = WORKSPACE; let mut source_root_prefix: RelativePathBuf = "/".into(); let mut file_id = FileId(0); @@ -87,7 +87,7 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option { - let source_root = std::mem::replace(&mut source_root, SourceRoot::default()); + let source_root = std::mem::replace(&mut source_root, SourceRoot::new_local()); db.set_source_root(source_root_id, Arc::new(source_root)); source_root_id.0 += 1; 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); #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct SourceRootId(pub u32); -#[derive(Default, Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct SourceRoot { /// Sysroot or crates.io library. /// @@ -44,11 +44,11 @@ pub struct SourceRoot { } impl SourceRoot { - pub fn new() -> SourceRoot { - Default::default() + pub fn new_local() -> SourceRoot { + SourceRoot { is_library: false, files: Default::default() } } pub fn new_library() -> SourceRoot { - SourceRoot { is_library: true, ..SourceRoot::new() } + SourceRoot { is_library: true, files: Default::default() } } pub fn insert_file(&mut self, path: RelativePathBuf, file_id: FileId) { self.files.insert(path, file_id); -- cgit v1.2.3