Skip to content

Commit 042e6d8

Browse files
authored
Merge pull request #19451 from Veykril/push-tuqmmvkrtpzl
refactor: Use MEDIUM durability for crate-graph changes, high for library source files
2 parents 62e7d9f + 454e4be commit 042e6d8

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

crates/base-db/src/change.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl FileChange {
5555
if let Some(roots) = self.roots {
5656
for (idx, root) in roots.into_iter().enumerate() {
5757
let root_id = SourceRootId(idx as u32);
58-
let durability = durability(&root);
58+
let durability = source_root_durability(&root);
5959
for file_id in root.iter() {
6060
db.set_file_source_root_with_durability(file_id, root_id, durability);
6161
}
@@ -68,7 +68,7 @@ impl FileChange {
6868
let source_root_id = db.file_source_root(file_id);
6969
let source_root = db.source_root(source_root_id.source_root_id(db));
7070

71-
let durability = durability(&source_root.source_root(db));
71+
let durability = file_text_durability(&source_root.source_root(db));
7272
// XXX: can't actually remove the file, just reset the text
7373
let text = text.unwrap_or_default();
7474
db.set_file_text_with_durability(file_id, &text, durability)
@@ -81,6 +81,10 @@ impl FileChange {
8181
}
8282
}
8383

84-
fn durability(source_root: &SourceRoot) -> Durability {
84+
fn source_root_durability(source_root: &SourceRoot) -> Durability {
85+
if source_root.is_library { Durability::MEDIUM } else { Durability::LOW }
86+
}
87+
88+
fn file_text_durability(source_root: &SourceRoot) -> Durability {
8589
if source_root.is_library { Durability::HIGH } else { Durability::LOW }
8690
}

crates/base-db/src/input.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ impl CrateGraphBuilder {
491491
if **old_all_crates != *all_crates {
492492
db.set_all_crates_with_durability(
493493
Arc::new(all_crates.into_boxed_slice()),
494-
Durability::HIGH,
494+
Durability::MEDIUM,
495495
);
496496
}
497497

@@ -549,30 +549,30 @@ impl CrateGraphBuilder {
549549
Entry::Occupied(entry) => {
550550
let old_crate = *entry.get();
551551
if crate_data != *old_crate.data(db) {
552-
old_crate.set_data(db).with_durability(Durability::HIGH).to(crate_data);
552+
old_crate.set_data(db).with_durability(Durability::MEDIUM).to(crate_data);
553553
}
554554
if krate.extra != *old_crate.extra_data(db) {
555555
old_crate
556556
.set_extra_data(db)
557-
.with_durability(Durability::HIGH)
557+
.with_durability(Durability::MEDIUM)
558558
.to(krate.extra.clone());
559559
}
560560
if krate.cfg_options != *old_crate.cfg_options(db) {
561561
old_crate
562562
.set_cfg_options(db)
563-
.with_durability(Durability::HIGH)
563+
.with_durability(Durability::MEDIUM)
564564
.to(krate.cfg_options.clone());
565565
}
566566
if krate.env != *old_crate.env(db) {
567567
old_crate
568568
.set_env(db)
569-
.with_durability(Durability::HIGH)
569+
.with_durability(Durability::MEDIUM)
570570
.to(krate.env.clone());
571571
}
572572
if krate.ws_data != *old_crate.workspace_data(db) {
573573
old_crate
574574
.set_workspace_data(db)
575-
.with_durability(Durability::HIGH)
575+
.with_durability(Durability::MEDIUM)
576576
.to(krate.ws_data.clone());
577577
}
578578
old_crate
@@ -585,7 +585,7 @@ impl CrateGraphBuilder {
585585
krate.cfg_options.clone(),
586586
krate.env.clone(),
587587
)
588-
.durability(Durability::HIGH)
588+
.durability(Durability::MEDIUM)
589589
.new(db);
590590
entry.insert(input);
591591
input

crates/ide-db/src/apply_change.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ impl RootDatabase {
2929
local_roots.insert(root_id);
3030
}
3131
}
32-
self.set_local_roots_with_durability(Arc::new(local_roots), Durability::HIGH);
33-
self.set_library_roots_with_durability(Arc::new(library_roots), Durability::HIGH);
32+
self.set_local_roots_with_durability(Arc::new(local_roots), Durability::MEDIUM);
33+
self.set_library_roots_with_durability(Arc::new(library_roots), Durability::MEDIUM);
3434
}
3535
change.apply(self);
3636
}

crates/ide-db/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ impl RootDatabase {
220220
// This needs to be here otherwise `CrateGraphBuilder` will panic.
221221
db.set_all_crates(Arc::new(Box::new([])));
222222
CrateGraphBuilder::default().set_in_db(&mut db);
223-
db.set_proc_macros_with_durability(Default::default(), Durability::HIGH);
224-
db.set_local_roots_with_durability(Default::default(), Durability::HIGH);
225-
db.set_library_roots_with_durability(Default::default(), Durability::HIGH);
223+
db.set_proc_macros_with_durability(Default::default(), Durability::MEDIUM);
224+
db.set_local_roots_with_durability(Default::default(), Durability::MEDIUM);
225+
db.set_library_roots_with_durability(Default::default(), Durability::MEDIUM);
226226
db.set_expand_proc_attr_macros_with_durability(false, Durability::HIGH);
227227
db.update_base_query_lru_capacities(lru_capacity);
228228
db

0 commit comments

Comments
 (0)