From ef2b84ddf119c950272c5f1eb321f3f9e90bedd4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 8 Sep 2019 09:48:45 +0300 Subject: introduce hir debugging infra This is to make debugging rust-analyzer easier. The idea is that `dbg!(krate.debug(db))` will print the actual, fuzzy crate name, instead of precise ID. Debug printing infra is a separate thing, to make sure that the actual hir doesn't have access to global information. Do not use `.debug` for `log::` logging: debugging executes queries, and might introduce unneded dependencies to the crate graph --- crates/ra_db/src/input.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'crates/ra_db') diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index d1ee3c036..a1ace61b6 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs @@ -82,6 +82,12 @@ pub struct CyclicDependencies; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct CrateId(pub u32); +impl CrateId { + pub fn shift(self, amount: u32) -> CrateId { + CrateId(self.0 + amount) + } +} + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum Edition { Edition2018, @@ -178,15 +184,19 @@ impl CrateGraph { /// Extends this crate graph by adding a complete disjoint second crate /// graph. - pub fn extend(&mut self, other: CrateGraph) { + /// + /// The ids of the crates in the `other` graph are shifted by the return + /// amount. + pub fn extend(&mut self, other: CrateGraph) -> u32 { let start = self.arena.len() as u32; self.arena.extend(other.arena.into_iter().map(|(id, mut data)| { - let new_id = CrateId(id.0 + start); + let new_id = id.shift(start); for dep in &mut data.dependencies { - dep.crate_id = CrateId(dep.crate_id.0 + start); + dep.crate_id = dep.crate_id.shift(start); } (new_id, data) })); + start } fn dfs_find(&self, target: CrateId, from: CrateId, visited: &mut FxHashSet) -> bool { -- cgit v1.2.3