From 4484908a867fc742104d6ffe63b865a411203276 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 30 Jun 2020 13:03:08 +0200 Subject: Rewrite goto definition tests --- crates/ra_db/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_db/src') diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index 4a3ba57da..1ddacc1f6 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs @@ -80,7 +80,7 @@ pub struct FilePosition { pub offset: TextSize, } -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct FileRange { pub file_id: FileId, pub range: TextRange, -- cgit v1.2.3 From 307c6fec618d5e509c754362687253ef44bb5f3f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 1 Jul 2020 09:53:53 +0200 Subject: Use CrateName for semantic names --- crates/ra_db/src/input.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'crates/ra_db/src') diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index 7f3660118..a8cc588f9 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs @@ -94,6 +94,13 @@ impl fmt::Display for CrateName { } } +impl ops::Deref for CrateName { + type Target = str; + fn deref(&self) -> &Self::Target { + &*self.0 + } +} + #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub struct ProcMacroId(pub u32); @@ -138,7 +145,7 @@ pub struct Env { #[derive(Debug, Clone, PartialEq, Eq)] pub struct Dependency { pub crate_id: CrateId, - pub name: SmolStr, + pub name: CrateName, } impl CrateGraph { @@ -178,7 +185,7 @@ impl CrateGraph { if self.dfs_find(from, to, &mut FxHashSet::default()) { return Err(CyclicDependenciesError); } - self.arena.get_mut(&from).unwrap().add_dep(name.0, to); + self.arena.get_mut(&from).unwrap().add_dep(name, to); Ok(()) } @@ -247,7 +254,7 @@ impl CrateId { } impl CrateData { - fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) { + fn add_dep(&mut self, name: CrateName, crate_id: CrateId) { self.dependencies.push(Dependency { name, crate_id }) } } @@ -429,7 +436,10 @@ mod tests { .is_ok()); assert_eq!( graph[crate1].dependencies, - vec![Dependency { crate_id: crate2, name: "crate_name_with_dashes".into() }] + vec![Dependency { + crate_id: crate2, + name: CrateName::new("crate_name_with_dashes").unwrap() + }] ); } } -- cgit v1.2.3 From 80386ca5be78d8ea65483df3edeec1a89b09a5a3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 1 Jul 2020 10:03:07 +0200 Subject: Use Strings for display names --- crates/ra_db/src/fixture.rs | 8 +++++--- crates/ra_db/src/input.rs | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'crates/ra_db/src') diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs index 4f4fb4494..209713987 100644 --- a/crates/ra_db/src/fixture.rs +++ b/crates/ra_db/src/fixture.rs @@ -149,15 +149,17 @@ fn with_files( let crate_id = crate_graph.add_crate_root( file_id, meta.edition, - Some(CrateName::new(&krate).unwrap()), + Some(krate.clone()), meta.cfg, meta.env, Default::default(), ); - let prev = crates.insert(krate.clone(), crate_id); + let crate_name = CrateName::new(&krate).unwrap(); + let prev = crates.insert(crate_name.clone(), crate_id); assert!(prev.is_none()); for dep in meta.deps { - crate_deps.push((krate.clone(), dep)) + let dep = CrateName::new(&dep).unwrap(); + crate_deps.push((crate_name.clone(), dep)) } } else if meta.path == "/main.rs" || meta.path == "/lib.rs" { assert!(default_crate_root.is_none()); diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index a8cc588f9..445a1ee48 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs @@ -67,7 +67,7 @@ pub struct CrateGraph { #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct CrateId(pub u32); -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct CrateName(SmolStr); impl CrateName { @@ -124,7 +124,7 @@ pub struct CrateData { /// The name to display to the end user. /// This actual crate name can be different in a particular dependent crate /// or may even be missing for some cases, such as a dummy crate for the code snippet. - pub display_name: Option, + pub display_name: Option, pub cfg_options: CfgOptions, pub env: Env, pub dependencies: Vec, @@ -153,7 +153,7 @@ impl CrateGraph { &mut self, file_id: FileId, edition: Edition, - display_name: Option, + display_name: Option, cfg_options: CfgOptions, env: Env, proc_macro: Vec<(SmolStr, Arc)>, -- cgit v1.2.3 From 63ea8f2af097316523f54f09e1c54d515a1bb9fd Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 1 Jul 2020 15:18:51 +0200 Subject: Add a transitive deps iterator to `CrateGraph` --- crates/ra_db/src/input.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'crates/ra_db/src') diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index 445a1ee48..aaa492759 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs @@ -197,6 +197,23 @@ impl CrateGraph { self.arena.keys().copied() } + /// Returns an iterator over all transitive dependencies of the given crate. + pub fn transitive_deps(&self, of: CrateId) -> impl Iterator + '_ { + let mut worklist = vec![of]; + let mut deps = FxHashSet::default(); + + while let Some(krate) = worklist.pop() { + if !deps.insert(krate) { + continue; + } + + worklist.extend(self[krate].dependencies.iter().map(|dep| dep.crate_id)); + } + + deps.remove(&of); + deps.into_iter() + } + // FIXME: this only finds one crate with the given root; we could have multiple pub fn crate_id_for_crate_root(&self, file_id: FileId) -> Option { let (&crate_id, _) = -- cgit v1.2.3 From 4bbc385277bcab509c321b1374f72f1ef19d7750 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 7 Jul 2020 10:14:48 +0200 Subject: Switch to fully dynamically dispatched salsa This improves compile times quite a bit --- crates/ra_db/src/lib.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'crates/ra_db/src') diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index 1ddacc1f6..590efffa4 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs @@ -113,7 +113,7 @@ pub trait SourceDatabase: CheckCanceled + FileLoader + std::fmt::Debug { fn crate_graph(&self) -> Arc; } -fn parse_query(db: &impl SourceDatabase, file_id: FileId) -> Parse { +fn parse_query(db: &dyn SourceDatabase, file_id: FileId) -> Parse { let _p = profile("parse_query").detail(|| format!("{:?}", file_id)); let text = db.file_text(file_id); SourceFile::parse(&*text) @@ -136,10 +136,7 @@ pub trait SourceDatabaseExt: SourceDatabase { fn source_root_crates(&self, id: SourceRootId) -> Arc>; } -fn source_root_crates( - db: &(impl SourceDatabaseExt + SourceDatabase), - id: SourceRootId, -) -> Arc> { +fn source_root_crates(db: &dyn SourceDatabaseExt, id: SourceRootId) -> Arc> { let graph = db.crate_graph(); let res = graph .iter() -- cgit v1.2.3 From 35e4bb35062a5e9e72282f33a0feaa9aea2151c5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 8 Jul 2020 18:17:45 +0200 Subject: Document failed refactor --- crates/ra_db/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_db/src') diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index 590efffa4..183822601 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs @@ -93,9 +93,9 @@ pub trait FileLoader { fn file_text(&self, file_id: FileId) -> Arc; /// Note that we intentionally accept a `&str` and not a `&Path` here. This /// method exists to handle `#[path = "/some/path.rs"] mod foo;` and such, - /// so the input is guaranteed to be utf-8 string. We might introduce - /// `struct StrPath(str)` for clarity some day, but it's a bit messy, so we - /// get by with a `&str` for the time being. + /// so the input is guaranteed to be utf-8 string. One might be tempted to + /// introduce some kind of "utf-8 path with / separators", but that's a bad idea. Behold + /// `#[path = "C://no/way"]` fn resolve_path(&self, anchor: FileId, path: &str) -> Option; fn relevant_crates(&self, file_id: FileId) -> Arc>; } -- cgit v1.2.3 From 7ae696ba7642aba92c2eed012d9e02c09bab7460 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 8 Jul 2020 18:22:57 +0200 Subject: Remove unwanted dependency --- crates/ra_db/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_db/src') diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index 183822601..3a8fd44c4 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs @@ -18,7 +18,7 @@ pub use crate::{ }; pub use relative_path::{RelativePath, RelativePathBuf}; pub use salsa; -pub use vfs::{file_set::FileSet, AbsPathBuf, VfsPath}; +pub use vfs::{file_set::FileSet, VfsPath}; #[macro_export] macro_rules! impl_intern_key { -- cgit v1.2.3 From dab7f3d2c6cd035f446fbdcda2442954da4afd3a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 8 Jul 2020 19:09:42 +0200 Subject: Remove relative_path dependency --- crates/ra_db/src/lib.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'crates/ra_db/src') diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index 3a8fd44c4..f25be24fe 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs @@ -16,7 +16,6 @@ pub use crate::{ SourceRoot, SourceRootId, }, }; -pub use relative_path::{RelativePath, RelativePathBuf}; pub use salsa; pub use vfs::{file_set::FileSet, VfsPath}; -- cgit v1.2.3 From b68ef1231daf6eb1abeb06a30dc89af1254b833d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 21 Jul 2020 17:17:21 +0200 Subject: More Rustic API for Env --- crates/ra_db/src/fixture.rs | 2 +- crates/ra_db/src/input.rs | 17 ++++------------- 2 files changed, 5 insertions(+), 14 deletions(-) (limited to 'crates/ra_db/src') diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs index 209713987..2aafb9965 100644 --- a/crates/ra_db/src/fixture.rs +++ b/crates/ra_db/src/fixture.rs @@ -222,7 +222,7 @@ impl From for FileMeta { .edition .as_ref() .map_or(Edition::Edition2018, |v| Edition::from_str(&v).unwrap()), - env: Env::from(f.env.iter()), + env: f.env.into_iter().collect(), } } } diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index aaa492759..6f2e5cfc7 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs @@ -6,7 +6,7 @@ //! actual IO. See `vfs` and `project_model` in the `rust-analyzer` crate for how //! actual IO is done and lowered to input. -use std::{fmt, ops, str::FromStr, sync::Arc}; +use std::{fmt, iter::FromIterator, ops, str::FromStr, sync::Arc}; use ra_cfg::CfgOptions; use ra_syntax::SmolStr; @@ -298,18 +298,9 @@ impl fmt::Display for Edition { } } -impl<'a, T> From for Env -where - T: Iterator, -{ - fn from(iter: T) -> Self { - let mut result = Self::default(); - - for (k, v) in iter { - result.entries.insert(k.to_owned(), v.to_owned()); - } - - result +impl FromIterator<(String, String)> for Env { + fn from_iter>(iter: T) -> Self { + Env { entries: FromIterator::from_iter(iter) } } } -- cgit v1.2.3