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 <michal.terepeta@gmail.com>
This commit is contained in:
Michal Terepeta 2020-01-08 19:29:18 +01:00
parent 2ffaad10f2
commit d761435ba0
3 changed files with 9 additions and 8 deletions

View file

@ -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<FilePosit
let mut crate_deps = Vec::new();
let mut default_crate_root: Option<FileId> = 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<FilePosit
for entry in fixture.iter() {
let meta = match parse_meta(&entry.meta) {
ParsedMeta::Root { path } => {
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;