Skip to content

Commit 0d6e5a9

Browse files
bors[bot]michalt
andauthored
Merge #2771
2771: Remove the Default impl for SourceRoot r=matklad a=michalt 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 <michal.terepeta@gmail.com> Co-authored-by: Michal Terepeta <michal.terepeta@gmail.com>
2 parents 5ced6f4 + d761435 commit 0d6e5a9

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

crates/ra_db/src/fixture.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn with_single_file(db: &mut dyn SourceDatabaseExt, text: &str) -> FileId {
4949
let file_id = FileId(0);
5050
let rel_path: RelativePathBuf = "/main.rs".into();
5151

52-
let mut source_root = SourceRoot::default();
52+
let mut source_root = SourceRoot::new_local();
5353
source_root.insert_file(rel_path.clone(), file_id);
5454

5555
let mut crate_graph = CrateGraph::default();
@@ -77,7 +77,7 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
7777
let mut crate_deps = Vec::new();
7878
let mut default_crate_root: Option<FileId> = None;
7979

80-
let mut source_root = SourceRoot::default();
80+
let mut source_root = SourceRoot::new_local();
8181
let mut source_root_id = WORKSPACE;
8282
let mut source_root_prefix: RelativePathBuf = "/".into();
8383
let mut file_id = FileId(0);
@@ -87,7 +87,7 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
8787
for entry in fixture.iter() {
8888
let meta = match parse_meta(&entry.meta) {
8989
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());
9191
db.set_source_root(source_root_id, Arc::new(source_root));
9292
source_root_id.0 += 1;
9393
source_root_prefix = path;

crates/ra_db/src/input.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct FileId(pub u32);
3333
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
3434
pub struct SourceRootId(pub u32);
3535

36-
#[derive(Default, Clone, Debug, PartialEq, Eq)]
36+
#[derive(Clone, Debug, PartialEq, Eq)]
3737
pub struct SourceRoot {
3838
/// Sysroot or crates.io library.
3939
///
@@ -44,11 +44,11 @@ pub struct SourceRoot {
4444
}
4545

4646
impl SourceRoot {
47-
pub fn new() -> SourceRoot {
48-
Default::default()
47+
pub fn new_local() -> SourceRoot {
48+
SourceRoot { is_library: false, files: Default::default() }
4949
}
5050
pub fn new_library() -> SourceRoot {
51-
SourceRoot { is_library: true, ..SourceRoot::new() }
51+
SourceRoot { is_library: true, files: Default::default() }
5252
}
5353
pub fn insert_file(&mut self, path: RelativePathBuf, file_id: FileId) {
5454
self.files.insert(path, file_id);

crates/ra_ide/src/change.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ impl RootDatabase {
176176
if !change.new_roots.is_empty() {
177177
let mut local_roots = Vec::clone(&self.local_roots());
178178
for (root_id, is_local) in change.new_roots {
179-
let root = if is_local { SourceRoot::new() } else { SourceRoot::new_library() };
179+
let root =
180+
if is_local { SourceRoot::new_local() } else { SourceRoot::new_library() };
180181
let durability = durability(&root);
181182
self.set_source_root_with_durability(root_id, Arc::new(root), durability);
182183
if is_local {

0 commit comments

Comments
 (0)