mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 11:20:54 +00:00
Prefer test duped crates for ide features
This commit is contained in:
parent
a4c7a87755
commit
e205af259d
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -87,6 +87,7 @@ name = "base-db"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"cfg",
|
||||
"indexmap",
|
||||
"la-arena",
|
||||
"profile",
|
||||
"rustc-hash",
|
||||
@ -579,6 +580,7 @@ dependencies = [
|
||||
"hir-def",
|
||||
"hir-expand",
|
||||
"hkalbasi-rustc-ap-rustc_index",
|
||||
"indexmap",
|
||||
"intern",
|
||||
"itertools",
|
||||
"la-arena",
|
||||
|
@ -14,6 +14,7 @@ doctest = false
|
||||
[dependencies]
|
||||
salsa = "0.17.0-pre.2"
|
||||
rustc-hash = "1.1.0"
|
||||
indexmap = "1.6.0"
|
||||
|
||||
la-arena = { version = "0.3.0", path = "../../lib/la-arena" }
|
||||
|
||||
|
@ -6,9 +6,10 @@ mod input;
|
||||
mod change;
|
||||
pub mod fixture;
|
||||
|
||||
use std::{panic, sync::Arc};
|
||||
use std::{hash::BuildHasherDefault, panic, sync::Arc};
|
||||
|
||||
use rustc_hash::FxHashSet;
|
||||
use indexmap::IndexSet;
|
||||
use rustc_hash::FxHasher;
|
||||
use syntax::{ast, Parse, SourceFile, TextRange, TextSize};
|
||||
|
||||
pub use crate::{
|
||||
@ -59,7 +60,10 @@ pub trait FileLoader {
|
||||
/// Text of the file.
|
||||
fn file_text(&self, file_id: FileId) -> Arc<str>;
|
||||
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId>;
|
||||
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>>;
|
||||
fn relevant_crates(
|
||||
&self,
|
||||
file_id: FileId,
|
||||
) -> Arc<IndexSet<CrateId, BuildHasherDefault<FxHasher>>>;
|
||||
}
|
||||
|
||||
/// Database which stores all significant input facts: source code and project
|
||||
@ -99,10 +103,16 @@ pub trait SourceDatabaseExt: SourceDatabase {
|
||||
#[salsa::input]
|
||||
fn source_root(&self, id: SourceRootId) -> Arc<SourceRoot>;
|
||||
|
||||
fn source_root_crates(&self, id: SourceRootId) -> Arc<FxHashSet<CrateId>>;
|
||||
fn source_root_crates(
|
||||
&self,
|
||||
id: SourceRootId,
|
||||
) -> Arc<IndexSet<CrateId, BuildHasherDefault<FxHasher>>>;
|
||||
}
|
||||
|
||||
fn source_root_crates(db: &dyn SourceDatabaseExt, id: SourceRootId) -> Arc<FxHashSet<CrateId>> {
|
||||
fn source_root_crates(
|
||||
db: &dyn SourceDatabaseExt,
|
||||
id: SourceRootId,
|
||||
) -> Arc<IndexSet<CrateId, BuildHasherDefault<FxHasher>>> {
|
||||
let graph = db.crate_graph();
|
||||
let res = graph
|
||||
.iter()
|
||||
@ -128,7 +138,10 @@ impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> {
|
||||
source_root.resolve_path(path)
|
||||
}
|
||||
|
||||
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
|
||||
fn relevant_crates(
|
||||
&self,
|
||||
file_id: FileId,
|
||||
) -> Arc<IndexSet<CrateId, BuildHasherDefault<FxHasher>>> {
|
||||
let _p = profile::span("relevant_crates");
|
||||
let source_root = self.0.file_source_root(file_id);
|
||||
self.0.source_root_crates(source_root)
|
||||
|
@ -1,7 +1,9 @@
|
||||
//! Database used for testing `hir_def`.
|
||||
|
||||
use std::{
|
||||
fmt, panic,
|
||||
fmt,
|
||||
hash::BuildHasherDefault,
|
||||
panic,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
@ -11,7 +13,8 @@ use base_db::{
|
||||
Upcast,
|
||||
};
|
||||
use hir_expand::{db::ExpandDatabase, InFile};
|
||||
use rustc_hash::FxHashSet;
|
||||
use indexmap::IndexSet;
|
||||
use rustc_hash::FxHasher;
|
||||
use syntax::{algo, ast, AstNode};
|
||||
|
||||
use crate::{
|
||||
@ -77,7 +80,10 @@ impl FileLoader for TestDB {
|
||||
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId> {
|
||||
FileLoaderDelegate(self).resolve_path(path)
|
||||
}
|
||||
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
|
||||
fn relevant_crates(
|
||||
&self,
|
||||
file_id: FileId,
|
||||
) -> Arc<IndexSet<CrateId, BuildHasherDefault<FxHasher>>> {
|
||||
FileLoaderDelegate(self).relevant_crates(file_id)
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ la-arena = { version = "0.3.0", path = "../../lib/la-arena" }
|
||||
once_cell = "1.17.0"
|
||||
typed-arena = "2.0.1"
|
||||
rustc_index = { version = "0.0.20221221", package = "hkalbasi-rustc-ap-rustc_index", default-features = false }
|
||||
indexmap = "1.6.0"
|
||||
|
||||
# local deps
|
||||
stdx.workspace = true
|
||||
|
@ -1,7 +1,9 @@
|
||||
//! Database used for testing `hir`.
|
||||
|
||||
use std::{
|
||||
fmt, panic,
|
||||
fmt,
|
||||
hash::BuildHasherDefault,
|
||||
panic,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
@ -11,7 +13,8 @@ use base_db::{
|
||||
};
|
||||
use hir_def::{db::DefDatabase, ModuleId};
|
||||
use hir_expand::db::ExpandDatabase;
|
||||
use rustc_hash::FxHashSet;
|
||||
use indexmap::IndexSet;
|
||||
use rustc_hash::FxHasher;
|
||||
use stdx::hash::NoHashHashMap;
|
||||
use syntax::TextRange;
|
||||
use test_utils::extract_annotations;
|
||||
@ -82,7 +85,10 @@ impl FileLoader for TestDB {
|
||||
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId> {
|
||||
FileLoaderDelegate(self).resolve_path(path)
|
||||
}
|
||||
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
|
||||
fn relevant_crates(
|
||||
&self,
|
||||
file_id: FileId,
|
||||
) -> Arc<IndexSet<CrateId, BuildHasherDefault<FxHasher>>> {
|
||||
FileLoaderDelegate(self).relevant_crates(file_id)
|
||||
}
|
||||
}
|
||||
|
@ -119,7 +119,9 @@ impl SourceToDefCtx<'_, '_> {
|
||||
pub(super) fn file_to_def(&self, file: FileId) -> SmallVec<[ModuleId; 1]> {
|
||||
let _p = profile::span("SourceBinder::to_module_def");
|
||||
let mut mods = SmallVec::new();
|
||||
for &crate_id in self.db.relevant_crates(file).iter() {
|
||||
// HACK: We iterate in reverse so that dev-dependency duplicated crates appear first in this
|
||||
// Most code only deals with one module and we want to prefer the test enabled code where possible
|
||||
for &crate_id in self.db.relevant_crates(file).iter().rev() {
|
||||
// FIXME: inner items
|
||||
let crate_def_map = self.db.crate_def_map(crate_id);
|
||||
mods.extend(
|
||||
|
@ -43,7 +43,7 @@ pub mod syntax_helpers {
|
||||
pub use parser::LexedStr;
|
||||
}
|
||||
|
||||
use std::{fmt, mem::ManuallyDrop, sync::Arc};
|
||||
use std::{fmt, hash::BuildHasherDefault, mem::ManuallyDrop, sync::Arc};
|
||||
|
||||
use base_db::{
|
||||
salsa::{self, Durability},
|
||||
@ -53,6 +53,7 @@ use hir::{
|
||||
db::{DefDatabase, ExpandDatabase, HirDatabase},
|
||||
symbols::FileSymbolKind,
|
||||
};
|
||||
use indexmap::IndexSet;
|
||||
|
||||
use crate::{line_index::LineIndex, symbol_index::SymbolsDatabase};
|
||||
pub use rustc_hash::{FxHashMap, FxHashSet, FxHasher};
|
||||
@ -119,7 +120,10 @@ impl FileLoader for RootDatabase {
|
||||
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId> {
|
||||
FileLoaderDelegate(self).resolve_path(path)
|
||||
}
|
||||
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
|
||||
fn relevant_crates(
|
||||
&self,
|
||||
file_id: FileId,
|
||||
) -> Arc<IndexSet<CrateId, BuildHasherDefault<FxHasher>>> {
|
||||
FileLoaderDelegate(self).relevant_crates(file_id)
|
||||
}
|
||||
}
|
||||
|
@ -938,7 +938,7 @@ fn cargo_to_crate_graph(
|
||||
// Get all dependencies of the workspace members that are used as dev-dependencies
|
||||
for pkg in cargo.packages() {
|
||||
for dep in &cargo[pkg].dependencies {
|
||||
if dep.kind == DepKind::Dev {
|
||||
if dep.kind == DepKind::Dev && cargo[dep.pkg].is_member {
|
||||
work.push(dep.pkg);
|
||||
}
|
||||
}
|
||||
@ -955,6 +955,10 @@ fn cargo_to_crate_graph(
|
||||
}
|
||||
v.insert({
|
||||
let duped = crate_graph.duplicate(to);
|
||||
tracing::info!(
|
||||
"duplicating workspace crate {:?} as it is being used as a dev-dependency: {to:?} -> {duped:?}",
|
||||
crate_graph[to].display_name
|
||||
);
|
||||
if let Some(proc_macro) = proc_macros.get(&to).cloned() {
|
||||
proc_macros.insert(duped, proc_macro);
|
||||
}
|
||||
@ -1008,7 +1012,12 @@ fn cargo_to_crate_graph(
|
||||
|
||||
for (&pkg, targets) in &pkg_crates {
|
||||
for &(krate, _) in targets {
|
||||
if test_dupes.get(&krate).is_some() {
|
||||
if let Some(&dupe) = test_dupes.get(&krate) {
|
||||
tracing::info!(
|
||||
"{krate:?} {:?} {dupe:?} {:?}",
|
||||
crate_graph[krate].cfg_options,
|
||||
crate_graph[dupe].cfg_options
|
||||
);
|
||||
// if the crate got duped as a dev-dep the dupe already has test set
|
||||
continue;
|
||||
}
|
||||
|
@ -244,14 +244,14 @@
|
||||
prelude: true,
|
||||
},
|
||||
Dependency {
|
||||
crate_id: Idx::<CrateData>(8),
|
||||
crate_id: Idx::<CrateData>(7),
|
||||
name: CrateName(
|
||||
"ra_playground",
|
||||
),
|
||||
prelude: true,
|
||||
},
|
||||
Dependency {
|
||||
crate_id: Idx::<CrateData>(7),
|
||||
crate_id: Idx::<CrateData>(5),
|
||||
name: CrateName(
|
||||
"regex",
|
||||
),
|
||||
@ -328,14 +328,14 @@
|
||||
prelude: true,
|
||||
},
|
||||
Dependency {
|
||||
crate_id: Idx::<CrateData>(8),
|
||||
crate_id: Idx::<CrateData>(7),
|
||||
name: CrateName(
|
||||
"ra_playground",
|
||||
),
|
||||
prelude: true,
|
||||
},
|
||||
Dependency {
|
||||
crate_id: Idx::<CrateData>(7),
|
||||
crate_id: Idx::<CrateData>(5),
|
||||
name: CrateName(
|
||||
"regex",
|
||||
),
|
||||
@ -552,104 +552,6 @@
|
||||
channel: None,
|
||||
},
|
||||
7: CrateData {
|
||||
root_file_id: FileId(
|
||||
6,
|
||||
),
|
||||
edition: Edition2018,
|
||||
version: Some(
|
||||
"1.7.3",
|
||||
),
|
||||
display_name: Some(
|
||||
CrateDisplayName {
|
||||
crate_name: CrateName(
|
||||
"regex",
|
||||
),
|
||||
canonical_name: "regex",
|
||||
},
|
||||
),
|
||||
cfg_options: CfgOptions(
|
||||
[
|
||||
"debug_assertions",
|
||||
"feature=aho-corasick",
|
||||
"feature=default",
|
||||
"feature=memchr",
|
||||
"feature=perf",
|
||||
"feature=perf-cache",
|
||||
"feature=perf-dfa",
|
||||
"feature=perf-inline",
|
||||
"feature=perf-literal",
|
||||
"feature=std",
|
||||
"feature=unicode",
|
||||
"feature=unicode-age",
|
||||
"feature=unicode-bool",
|
||||
"feature=unicode-case",
|
||||
"feature=unicode-gencat",
|
||||
"feature=unicode-perl",
|
||||
"feature=unicode-script",
|
||||
"feature=unicode-segment",
|
||||
"test",
|
||||
],
|
||||
),
|
||||
potential_cfg_options: Some(
|
||||
CfgOptions(
|
||||
[
|
||||
"debug_assertions",
|
||||
"feature=aho-corasick",
|
||||
"feature=default",
|
||||
"feature=memchr",
|
||||
"feature=pattern",
|
||||
"feature=perf",
|
||||
"feature=perf-cache",
|
||||
"feature=perf-dfa",
|
||||
"feature=perf-inline",
|
||||
"feature=perf-literal",
|
||||
"feature=std",
|
||||
"feature=unicode",
|
||||
"feature=unicode-age",
|
||||
"feature=unicode-bool",
|
||||
"feature=unicode-case",
|
||||
"feature=unicode-gencat",
|
||||
"feature=unicode-perl",
|
||||
"feature=unicode-script",
|
||||
"feature=unicode-segment",
|
||||
"feature=unstable",
|
||||
"feature=use_std",
|
||||
],
|
||||
),
|
||||
),
|
||||
env: Env {
|
||||
entries: {
|
||||
"CARGO_PKG_LICENSE": "",
|
||||
"CARGO_PKG_VERSION_MAJOR": "1",
|
||||
"CARGO_MANIFEST_DIR": "$ROOT$.cargo/registry/src/github.com-1ecc6299db9ec823/regex-1.7.3",
|
||||
"CARGO_PKG_VERSION": "1.7.3",
|
||||
"CARGO_PKG_AUTHORS": "",
|
||||
"CARGO_CRATE_NAME": "regex",
|
||||
"CARGO_PKG_LICENSE_FILE": "",
|
||||
"CARGO_PKG_HOMEPAGE": "",
|
||||
"CARGO_PKG_DESCRIPTION": "",
|
||||
"CARGO_PKG_NAME": "regex",
|
||||
"CARGO_PKG_VERSION_PATCH": "3",
|
||||
"CARGO": "cargo",
|
||||
"CARGO_PKG_REPOSITORY": "",
|
||||
"CARGO_PKG_VERSION_MINOR": "7",
|
||||
"CARGO_PKG_VERSION_PRE": "",
|
||||
},
|
||||
},
|
||||
dependencies: [],
|
||||
origin: Library {
|
||||
repo: Some(
|
||||
"https://github.com/rust-lang/regex",
|
||||
),
|
||||
name: "regex",
|
||||
},
|
||||
is_proc_macro: false,
|
||||
target_layout: Err(
|
||||
"target_data_layout not loaded",
|
||||
),
|
||||
channel: None,
|
||||
},
|
||||
8: CrateData {
|
||||
root_file_id: FileId(
|
||||
4,
|
||||
),
|
||||
|
Loading…
x
Reference in New Issue
Block a user