Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #18020 - Veykril:cyclic-deps, r=Veykril
minor: Downgrade cyclic deps error to warning As the issue here is no longer workable for us and this appearing for some repos due to package cycles which can cause we should downgrade it as some people tend to think this breaks r-a when it doesn't
bors 2024-09-01
parent 8d1d5cd · parent 2e2f798 · commit 1875784
-rw-r--r--crates/base-db/src/input.rs54
-rw-r--r--crates/project-model/src/workspace.rs2
2 files changed, 8 insertions, 48 deletions
diff --git a/crates/base-db/src/input.rs b/crates/base-db/src/input.rs
index 3616fa9fd8..032e4a8e4a 100644
--- a/crates/base-db/src/input.rs
+++ b/crates/base-db/src/input.rs
@@ -374,37 +374,6 @@ impl CrateGraph {
self.arena.alloc(data)
}
- /// Remove the crate from crate graph. If any crates depend on this crate, the dependency would be replaced
- /// with the second input.
- pub fn remove_and_replace(
- &mut self,
- id: CrateId,
- replace_with: CrateId,
- ) -> Result<(), CyclicDependenciesError> {
- for (x, data) in self.arena.iter() {
- if x == id {
- continue;
- }
- for edge in &data.dependencies {
- if edge.crate_id == id {
- self.check_cycle_after_dependency(edge.crate_id, replace_with)?;
- }
- }
- }
- // if everything was ok, start to replace
- for (x, data) in self.arena.iter_mut() {
- if x == id {
- continue;
- }
- for edge in &mut data.dependencies {
- if edge.crate_id == id {
- edge.crate_id = replace_with;
- }
- }
- }
- Ok(())
- }
-
pub fn add_dep(
&mut self,
from: CrateId,
@@ -412,26 +381,17 @@ impl CrateGraph {
) -> Result<(), CyclicDependenciesError> {
let _p = tracing::info_span!("add_dep").entered();
- self.check_cycle_after_dependency(from, dep.crate_id)?;
-
- self.arena[from].add_dep(dep);
- Ok(())
- }
-
- /// Check if adding a dep from `from` to `to` creates a cycle. To figure
- /// that out, look for a path in the *opposite* direction, from `to` to
- /// `from`.
- fn check_cycle_after_dependency(
- &self,
- from: CrateId,
- to: CrateId,
- ) -> Result<(), CyclicDependenciesError> {
- if let Some(path) = self.find_path(&mut FxHashSet::default(), to, from) {
+ // Check if adding a dep from `from` to `to` creates a cycle. To figure
+ // that out, look for a path in the *opposite* direction, from `to` to
+ // `from`.
+ if let Some(path) = self.find_path(&mut FxHashSet::default(), dep.crate_id, from) {
let path = path.into_iter().map(|it| (it, self[it].display_name.clone())).collect();
let err = CyclicDependenciesError { path };
- assert!(err.from().0 == from && err.to().0 == to);
+ assert!(err.from().0 == from && err.to().0 == dep.crate_id);
return Err(err);
}
+
+ self.arena[from].add_dep(dep);
Ok(())
}
diff --git a/crates/project-model/src/workspace.rs b/crates/project-model/src/workspace.rs
index 7834238ace..4fc9ef3d36 100644
--- a/crates/project-model/src/workspace.rs
+++ b/crates/project-model/src/workspace.rs
@@ -1554,6 +1554,6 @@ fn add_proc_macro_dep(crate_graph: &mut CrateGraph, from: CrateId, to: CrateId,
fn add_dep_inner(graph: &mut CrateGraph, from: CrateId, dep: Dependency) {
if let Err(err) = graph.add_dep(from, dep) {
- tracing::error!("{}", err)
+ tracing::warn!("{}", err)
}
}