Skip to content

Commit 59fcd00

Browse files
committed
Auto merge of #14657 - rust-lang:revert-14475-crate-origins, r=Veykril
Revert "Handle dev-dependency cycles" Reverts #14475 I managed to fix the problem that causes the metric failures, but this still severely degrades IDE features in a way that makes the user experience ***worse*** than before. I am not sure how to address this, I wonder what the jetbrains plugin is doing in these cases.
2 parents a96bb45 + 10d7d73 commit 59fcd00

File tree

13 files changed

+52
-1798
lines changed

13 files changed

+52
-1798
lines changed

Cargo.lock

-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/base-db/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ doctest = false
1414
[dependencies]
1515
salsa = "0.17.0-pre.2"
1616
rustc-hash = "1.1.0"
17-
indexmap = "1.6.0"
1817

1918
la-arena = { version = "0.3.0", path = "../../lib/la-arena" }
2019

crates/base-db/src/input.rs

-11
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,6 @@ impl CrateGraph {
417417
Ok(())
418418
}
419419

420-
pub fn duplicate(&mut self, id: CrateId) -> CrateId {
421-
let data = self[id].clone();
422-
self.arena.alloc(data)
423-
}
424-
425420
pub fn add_dep(
426421
&mut self,
427422
from: CrateId,
@@ -617,12 +612,6 @@ impl ops::Index<CrateId> for CrateGraph {
617612
}
618613
}
619614

620-
impl ops::IndexMut<CrateId> for CrateGraph {
621-
fn index_mut(&mut self, crate_id: CrateId) -> &mut CrateData {
622-
&mut self.arena[crate_id]
623-
}
624-
}
625-
626615
impl CrateData {
627616
fn add_dep(&mut self, dep: Dependency) {
628617
self.dependencies.push(dep)

crates/base-db/src/lib.rs

+6-19
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ mod input;
66
mod change;
77
pub mod fixture;
88

9-
use std::{hash::BuildHasherDefault, panic, sync::Arc};
9+
use std::{panic, sync::Arc};
1010

11-
use indexmap::IndexSet;
12-
use rustc_hash::FxHasher;
11+
use rustc_hash::FxHashSet;
1312
use syntax::{ast, Parse, SourceFile, TextRange, TextSize};
1413

1514
pub use crate::{
@@ -60,10 +59,7 @@ pub trait FileLoader {
6059
/// Text of the file.
6160
fn file_text(&self, file_id: FileId) -> Arc<str>;
6261
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId>;
63-
fn relevant_crates(
64-
&self,
65-
file_id: FileId,
66-
) -> Arc<IndexSet<CrateId, BuildHasherDefault<FxHasher>>>;
62+
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>>;
6763
}
6864

6965
/// Database which stores all significant input facts: source code and project
@@ -103,16 +99,10 @@ pub trait SourceDatabaseExt: SourceDatabase {
10399
#[salsa::input]
104100
fn source_root(&self, id: SourceRootId) -> Arc<SourceRoot>;
105101

106-
fn source_root_crates(
107-
&self,
108-
id: SourceRootId,
109-
) -> Arc<IndexSet<CrateId, BuildHasherDefault<FxHasher>>>;
102+
fn source_root_crates(&self, id: SourceRootId) -> Arc<FxHashSet<CrateId>>;
110103
}
111104

112-
fn source_root_crates(
113-
db: &dyn SourceDatabaseExt,
114-
id: SourceRootId,
115-
) -> Arc<IndexSet<CrateId, BuildHasherDefault<FxHasher>>> {
105+
fn source_root_crates(db: &dyn SourceDatabaseExt, id: SourceRootId) -> Arc<FxHashSet<CrateId>> {
116106
let graph = db.crate_graph();
117107
let res = graph
118108
.iter()
@@ -138,10 +128,7 @@ impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> {
138128
source_root.resolve_path(path)
139129
}
140130

141-
fn relevant_crates(
142-
&self,
143-
file_id: FileId,
144-
) -> Arc<IndexSet<CrateId, BuildHasherDefault<FxHasher>>> {
131+
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
145132
let _p = profile::span("relevant_crates");
146133
let source_root = self.0.file_source_root(file_id);
147134
self.0.source_root_crates(source_root)

crates/hir-def/src/test_db.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
//! Database used for testing `hir_def`.
22
33
use std::{
4-
fmt,
5-
hash::BuildHasherDefault,
6-
panic,
4+
fmt, panic,
75
sync::{Arc, Mutex},
86
};
97

@@ -13,8 +11,7 @@ use base_db::{
1311
Upcast,
1412
};
1513
use hir_expand::{db::ExpandDatabase, InFile};
16-
use indexmap::IndexSet;
17-
use rustc_hash::FxHasher;
14+
use rustc_hash::FxHashSet;
1815
use syntax::{algo, ast, AstNode};
1916

2017
use crate::{
@@ -80,10 +77,7 @@ impl FileLoader for TestDB {
8077
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId> {
8178
FileLoaderDelegate(self).resolve_path(path)
8279
}
83-
fn relevant_crates(
84-
&self,
85-
file_id: FileId,
86-
) -> Arc<IndexSet<CrateId, BuildHasherDefault<FxHasher>>> {
80+
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
8781
FileLoaderDelegate(self).relevant_crates(file_id)
8882
}
8983
}

crates/hir-ty/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ la-arena = { version = "0.3.0", path = "../../lib/la-arena" }
3030
once_cell = "1.17.0"
3131
typed-arena = "2.0.1"
3232
rustc_index = { version = "0.0.20221221", package = "hkalbasi-rustc-ap-rustc_index", default-features = false }
33-
indexmap = "1.6.0"
3433

3534
# local deps
3635
stdx.workspace = true

crates/hir-ty/src/test_db.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
//! Database used for testing `hir`.
22
33
use std::{
4-
fmt,
5-
hash::BuildHasherDefault,
6-
panic,
4+
fmt, panic,
75
sync::{Arc, Mutex},
86
};
97

@@ -13,8 +11,7 @@ use base_db::{
1311
};
1412
use hir_def::{db::DefDatabase, ModuleId};
1513
use hir_expand::db::ExpandDatabase;
16-
use indexmap::IndexSet;
17-
use rustc_hash::FxHasher;
14+
use rustc_hash::FxHashSet;
1815
use stdx::hash::NoHashHashMap;
1916
use syntax::TextRange;
2017
use test_utils::extract_annotations;
@@ -85,10 +82,7 @@ impl FileLoader for TestDB {
8582
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId> {
8683
FileLoaderDelegate(self).resolve_path(path)
8784
}
88-
fn relevant_crates(
89-
&self,
90-
file_id: FileId,
91-
) -> Arc<IndexSet<CrateId, BuildHasherDefault<FxHasher>>> {
85+
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
9286
FileLoaderDelegate(self).relevant_crates(file_id)
9387
}
9488
}

crates/hir/src/semantics/source_to_def.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ impl SourceToDefCtx<'_, '_> {
119119
pub(super) fn file_to_def(&self, file: FileId) -> SmallVec<[ModuleId; 1]> {
120120
let _p = profile::span("SourceBinder::to_module_def");
121121
let mut mods = SmallVec::new();
122-
// HACK: We iterate in reverse so that dev-dependency duplicated crates appear first in this
123-
// Most code only deals with one module and we want to prefer the test enabled code where possible
124-
for &crate_id in self.db.relevant_crates(file).iter().rev() {
122+
for &crate_id in self.db.relevant_crates(file).iter() {
125123
// FIXME: inner items
126124
let crate_def_map = self.db.crate_def_map(crate_id);
127125
mods.extend(

crates/ide-db/src/lib.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub mod syntax_helpers {
4343
pub use parser::LexedStr;
4444
}
4545

46-
use std::{fmt, hash::BuildHasherDefault, mem::ManuallyDrop, sync::Arc};
46+
use std::{fmt, mem::ManuallyDrop, sync::Arc};
4747

4848
use base_db::{
4949
salsa::{self, Durability},
@@ -53,7 +53,6 @@ use hir::{
5353
db::{DefDatabase, ExpandDatabase, HirDatabase},
5454
symbols::FileSymbolKind,
5555
};
56-
use indexmap::IndexSet;
5756

5857
use crate::{line_index::LineIndex, symbol_index::SymbolsDatabase};
5958
pub use rustc_hash::{FxHashMap, FxHashSet, FxHasher};
@@ -120,10 +119,7 @@ impl FileLoader for RootDatabase {
120119
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId> {
121120
FileLoaderDelegate(self).resolve_path(path)
122121
}
123-
fn relevant_crates(
124-
&self,
125-
file_id: FileId,
126-
) -> Arc<IndexSet<CrateId, BuildHasherDefault<FxHasher>>> {
122+
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
127123
FileLoaderDelegate(self).relevant_crates(file_id)
128124
}
129125
}

crates/project-model/src/tests.rs

+1-15
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{
55

66
use base_db::{CrateGraph, FileId, ProcMacroPaths};
77
use cfg::{CfgAtom, CfgDiff};
8-
use expect_test::{expect, expect_file, Expect, ExpectFile};
8+
use expect_test::{expect, Expect};
99
use paths::{AbsPath, AbsPathBuf};
1010
use serde::de::DeserializeOwned;
1111

@@ -114,11 +114,6 @@ fn check_crate_graph(crate_graph: CrateGraph, expect: Expect) {
114114
replace_root(&mut crate_graph, false);
115115
expect.assert_eq(&crate_graph);
116116
}
117-
fn check_crate_graph_f(crate_graph: CrateGraph, expect: ExpectFile) {
118-
let mut crate_graph = format!("{crate_graph:#?}");
119-
replace_root(&mut crate_graph, false);
120-
expect.assert_eq(&crate_graph);
121-
}
122117

123118
#[test]
124119
fn cargo_hello_world_project_model_with_wildcard_overrides() {
@@ -1671,12 +1666,3 @@ fn rust_project_is_proc_macro_has_proc_macro_dep() {
16711666
// on the proc_macro sysroot crate.
16721667
crate_data.dependencies.iter().find(|&dep| dep.name.deref() == "proc_macro").unwrap();
16731668
}
1674-
1675-
#[test]
1676-
fn cargo_dev_dependencies() {
1677-
let (crate_graph, _proc_macros) = load_cargo("complex-with-dev-deps.json");
1678-
check_crate_graph_f(
1679-
crate_graph,
1680-
expect_file!["../test_data/cargo_dev_dependencies-crate-graph.txt"],
1681-
)
1682-
}

0 commit comments

Comments
 (0)