Skip to content

Commit 5109c0b

Browse files
committed
Drop support for stitched sysroot
1 parent faaba55 commit 5109c0b

File tree

7 files changed

+12
-1168
lines changed

7 files changed

+12
-1168
lines changed

src/tools/rust-analyzer/crates/project-model/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ fn parse_cfg(s: &str) -> Result<cfg::CfgAtom, String> {
263263
pub enum RustSourceWorkspaceConfig {
264264
CargoMetadata(CargoMetadataConfig),
265265
Json(ProjectJson),
266-
Stitched,
267266
}
268267

269268
impl Default for RustSourceWorkspaceConfig {

src/tools/rust-analyzer/crates/project-model/src/sysroot.rs

Lines changed: 2 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,10 @@
44
//! but we can't process `.rlib` and need source code instead. The source code
55
//! is typically installed with `rustup component add rust-src` command.
66
7-
use std::{
8-
env, fs,
9-
ops::{self, Not},
10-
path::Path,
11-
process::Command,
12-
};
7+
use std::{env, fs, ops::Not, path::Path, process::Command};
138

149
use anyhow::{format_err, Result};
15-
use base_db::CrateName;
1610
use itertools::Itertools;
17-
use la_arena::{Arena, Idx};
1811
use paths::{AbsPath, AbsPathBuf, Utf8PathBuf};
1912
use rustc_hash::FxHashMap;
2013
use stdx::format_to;
@@ -37,58 +30,9 @@ pub struct Sysroot {
3730
pub enum RustLibSrcWorkspace {
3831
Workspace(CargoWorkspace),
3932
Json(ProjectJson),
40-
Stitched(Stitched),
4133
Empty,
4234
}
4335

44-
#[derive(Debug, Clone, Eq, PartialEq)]
45-
pub struct Stitched {
46-
crates: Arena<RustLibSrcCrateData>,
47-
}
48-
49-
impl ops::Index<RustLibSrcCrate> for Stitched {
50-
type Output = RustLibSrcCrateData;
51-
fn index(&self, index: RustLibSrcCrate) -> &RustLibSrcCrateData {
52-
&self.crates[index]
53-
}
54-
}
55-
56-
impl Stitched {
57-
pub(crate) fn public_deps(
58-
&self,
59-
) -> impl Iterator<Item = (CrateName, RustLibSrcCrate, bool)> + '_ {
60-
// core is added as a dependency before std in order to
61-
// mimic rustcs dependency order
62-
[("core", true), ("alloc", false), ("std", true), ("test", false)].into_iter().filter_map(
63-
move |(name, prelude)| {
64-
Some((CrateName::new(name).unwrap(), self.by_name(name)?, prelude))
65-
},
66-
)
67-
}
68-
69-
pub(crate) fn proc_macro(&self) -> Option<RustLibSrcCrate> {
70-
self.by_name("proc_macro")
71-
}
72-
73-
pub(crate) fn crates(&self) -> impl ExactSizeIterator<Item = RustLibSrcCrate> + '_ {
74-
self.crates.iter().map(|(id, _data)| id)
75-
}
76-
77-
fn by_name(&self, name: &str) -> Option<RustLibSrcCrate> {
78-
let (id, _data) = self.crates.iter().find(|(_id, data)| data.name == name)?;
79-
Some(id)
80-
}
81-
}
82-
83-
pub(crate) type RustLibSrcCrate = Idx<RustLibSrcCrateData>;
84-
85-
#[derive(Debug, Clone, Eq, PartialEq)]
86-
pub(crate) struct RustLibSrcCrateData {
87-
pub(crate) name: String,
88-
pub(crate) root: ManifestPath,
89-
pub(crate) deps: Vec<RustLibSrcCrate>,
90-
}
91-
9236
impl Sysroot {
9337
pub const fn empty() -> Sysroot {
9438
Sysroot {
@@ -116,7 +60,6 @@ impl Sysroot {
11660
match &self.workspace {
11761
RustLibSrcWorkspace::Workspace(ws) => ws.packages().next().is_none(),
11862
RustLibSrcWorkspace::Json(project_json) => project_json.n_crates() == 0,
119-
RustLibSrcWorkspace::Stitched(stitched) => stitched.crates.is_empty(),
12063
RustLibSrcWorkspace::Empty => true,
12164
}
12265
}
@@ -129,7 +72,6 @@ impl Sysroot {
12972
match &self.workspace {
13073
RustLibSrcWorkspace::Workspace(ws) => ws.packages().count(),
13174
RustLibSrcWorkspace::Json(project_json) => project_json.n_crates(),
132-
RustLibSrcWorkspace::Stitched(c) => c.crates().count(),
13375
RustLibSrcWorkspace::Empty => 0,
13476
}
13577
}
@@ -258,51 +200,8 @@ impl Sysroot {
258200
} else if let RustSourceWorkspaceConfig::Json(project_json) = sysroot_source_config {
259201
return Some(RustLibSrcWorkspace::Json(project_json.clone()));
260202
}
261-
tracing::debug!("Stitching sysroot library: {src_root}");
262-
263-
let mut stitched = Stitched { crates: Arena::default() };
264-
265-
for path in SYSROOT_CRATES.trim().lines() {
266-
let name = path.split('/').last().unwrap();
267-
let root = [format!("{path}/src/lib.rs"), format!("lib{path}/lib.rs")]
268-
.into_iter()
269-
.map(|it| src_root.join(it))
270-
.filter_map(|it| ManifestPath::try_from(it).ok())
271-
.find(|it| fs::metadata(it).is_ok());
272-
273-
if let Some(root) = root {
274-
stitched.crates.alloc(RustLibSrcCrateData {
275-
name: name.into(),
276-
root,
277-
deps: Vec::new(),
278-
});
279-
}
280-
}
281-
282-
if let Some(std) = stitched.by_name("std") {
283-
for dep in STD_DEPS.trim().lines() {
284-
if let Some(dep) = stitched.by_name(dep) {
285-
stitched.crates[std].deps.push(dep)
286-
}
287-
}
288-
}
289-
290-
if let Some(alloc) = stitched.by_name("alloc") {
291-
for dep in ALLOC_DEPS.trim().lines() {
292-
if let Some(dep) = stitched.by_name(dep) {
293-
stitched.crates[alloc].deps.push(dep)
294-
}
295-
}
296-
}
297203

298-
if let Some(proc_macro) = stitched.by_name("proc_macro") {
299-
for dep in PROC_MACRO_DEPS.trim().lines() {
300-
if let Some(dep) = stitched.by_name(dep) {
301-
stitched.crates[proc_macro].deps.push(dep)
302-
}
303-
}
304-
}
305-
Some(RustLibSrcWorkspace::Stitched(stitched))
204+
None
306205
}
307206

308207
pub fn set_workspace(&mut self, workspace: RustLibSrcWorkspace) {
@@ -317,7 +216,6 @@ impl Sysroot {
317216
.crates()
318217
.filter_map(|(_, krate)| krate.display_name.clone())
319218
.any(|name| name.canonical_name().as_str() == "core"),
320-
RustLibSrcWorkspace::Stitched(stitched) => stitched.by_name("core").is_some(),
321219
RustLibSrcWorkspace::Empty => true,
322220
};
323221
if !has_core {
@@ -493,33 +391,3 @@ fn get_rust_lib_src(sysroot_path: &AbsPath) -> Option<AbsPathBuf> {
493391
None
494392
}
495393
}
496-
497-
const SYSROOT_CRATES: &str = "
498-
alloc
499-
backtrace
500-
core
501-
panic_abort
502-
panic_unwind
503-
proc_macro
504-
profiler_builtins
505-
std
506-
stdarch/crates/std_detect
507-
test
508-
unwind";
509-
510-
const ALLOC_DEPS: &str = "core";
511-
512-
const STD_DEPS: &str = "
513-
alloc
514-
panic_unwind
515-
panic_abort
516-
core
517-
profiler_builtins
518-
unwind
519-
std_detect
520-
test";
521-
522-
// core is required for our builtin derives to work in the proc_macro lib currently
523-
const PROC_MACRO_DEPS: &str = "
524-
std
525-
core";

src/tools/rust-analyzer/crates/project-model/src/tests.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::ops::Deref;
2-
31
use base_db::{CrateGraph, ProcMacroPaths};
42
use cargo_metadata::Metadata;
53
use cfg::{CfgAtom, CfgDiff};
@@ -225,18 +223,6 @@ fn rust_project_cfg_groups() {
225223
check_crate_graph(crate_graph, expect_file!["../test_data/output/rust_project_cfg_groups.txt"]);
226224
}
227225

228-
#[test]
229-
fn rust_project_is_proc_macro_has_proc_macro_dep() {
230-
let (crate_graph, _proc_macros) = load_rust_project("is-proc-macro-project.json");
231-
// Since the project only defines one crate (outside the sysroot crates),
232-
// it should be the one with the biggest Id.
233-
let crate_id = crate_graph.iter().max().unwrap();
234-
let crate_data = &crate_graph[crate_id];
235-
// Assert that the project crate with `is_proc_macro` has a dependency
236-
// on the proc_macro sysroot crate.
237-
crate_data.dependencies.iter().find(|&dep| *dep.name.deref() == sym::proc_macro).unwrap();
238-
}
239-
240226
#[test]
241227
fn crate_graph_dedup_identical() {
242228
let (mut crate_graph, proc_macros) = load_cargo("regex-metadata.json");

src/tools/rust-analyzer/crates/project-model/src/workspace.rs

Lines changed: 5 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::{
2323
cargo_workspace::{CargoMetadataConfig, DepKind, PackageData, RustLibSource},
2424
env::{cargo_config_env, inject_cargo_env, inject_cargo_package_env, inject_rustc_tool_env},
2525
project_json::{Crate, CrateArrayIdx},
26-
sysroot::{RustLibSrcCrate, RustLibSrcWorkspace},
26+
sysroot::RustLibSrcWorkspace,
2727
toolchain_info::{rustc_cfg, target_data_layout, target_tuple, version, QueryConfig},
2828
CargoConfig, CargoWorkspace, CfgOverrides, InvocationStrategy, ManifestPath, Package,
2929
ProjectJson, ProjectManifest, RustSourceWorkspaceConfig, Sysroot, TargetData, TargetKind,
@@ -437,7 +437,9 @@ impl ProjectWorkspace {
437437
if let Some(sysroot_project) = sysroot_project {
438438
sysroot.load_workspace(&RustSourceWorkspaceConfig::Json(*sysroot_project))
439439
} else {
440-
sysroot.load_workspace(&RustSourceWorkspaceConfig::Stitched)
440+
sysroot.load_workspace(&RustSourceWorkspaceConfig::CargoMetadata(
441+
sysroot_metadata_config(&config.extra_env, &targets),
442+
))
441443
}
442444
});
443445

@@ -690,7 +692,7 @@ impl ProjectWorkspace {
690692
exclude: krate.exclude.clone(),
691693
})
692694
.collect(),
693-
RustLibSrcWorkspace::Stitched(_) | RustLibSrcWorkspace::Empty => vec![],
695+
RustLibSrcWorkspace::Empty => vec![],
694696
};
695697

696698
r.push(PackageRoot {
@@ -1627,60 +1629,7 @@ fn sysroot_to_crate_graph(
16271629

16281630
extend_crate_graph_with_sysroot(crate_graph, cg, pm)
16291631
}
1630-
RustLibSrcWorkspace::Stitched(stitched) => {
1631-
let cfg_options = Arc::new({
1632-
let mut cfg_options = CfgOptions::default();
1633-
cfg_options.extend(rustc_cfg);
1634-
cfg_options.insert_atom(sym::debug_assertions.clone());
1635-
cfg_options.insert_atom(sym::miri.clone());
1636-
cfg_options
1637-
});
1638-
let sysroot_crates: FxHashMap<RustLibSrcCrate, CrateId> = stitched
1639-
.crates()
1640-
.filter_map(|krate| {
1641-
let file_id = load(&stitched[krate].root)?;
1642-
1643-
let display_name = CrateDisplayName::from_canonical_name(&stitched[krate].name);
1644-
let crate_id = crate_graph.add_crate_root(
1645-
file_id,
1646-
Edition::CURRENT_FIXME,
1647-
Some(display_name),
1648-
None,
1649-
cfg_options.clone(),
1650-
None,
1651-
Env::default(),
1652-
CrateOrigin::Lang(LangCrateOrigin::from(&*stitched[krate].name)),
1653-
false,
1654-
None,
1655-
);
1656-
Some((krate, crate_id))
1657-
})
1658-
.collect();
1659-
1660-
for from in stitched.crates() {
1661-
for &to in stitched[from].deps.iter() {
1662-
let name = CrateName::new(&stitched[to].name).unwrap();
1663-
if let (Some(&from), Some(&to)) =
1664-
(sysroot_crates.get(&from), sysroot_crates.get(&to))
1665-
{
1666-
add_dep(crate_graph, from, name, to);
1667-
}
1668-
}
1669-
}
16701632

1671-
let public_deps = SysrootPublicDeps {
1672-
deps: stitched
1673-
.public_deps()
1674-
.filter_map(|(name, idx, prelude)| {
1675-
Some((name, *sysroot_crates.get(&idx)?, prelude))
1676-
})
1677-
.collect::<Vec<_>>(),
1678-
};
1679-
1680-
let libproc_macro =
1681-
stitched.proc_macro().and_then(|it| sysroot_crates.get(&it).copied());
1682-
(public_deps, libproc_macro)
1683-
}
16841633
RustLibSrcWorkspace::Empty => (SysrootPublicDeps { deps: vec![] }, None),
16851634
}
16861635
}

src/tools/rust-analyzer/crates/project-model/test_data/is-proc-macro-project.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)