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

@ -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);