5882: Don't expose indexing details
 r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-08-25 16:41:10 +00:00 committed by GitHub
commit 6141e2706a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 24 deletions

View file

@ -43,7 +43,7 @@ impl fmt::Debug for ProjectWorkspace {
f.debug_struct("Cargo").field("n_packages", &cargo.packages().len()).finish() f.debug_struct("Cargo").field("n_packages", &cargo.packages().len()).finish()
} }
ProjectWorkspace::Json { project } => { ProjectWorkspace::Json { project } => {
f.debug_struct("Json").field("n_crates", &project.crates.len()).finish() f.debug_struct("Json").field("n_crates", &project.n_crates()).finish()
} }
} }
} }
@ -202,9 +202,8 @@ impl ProjectWorkspace {
pub fn to_roots(&self) -> Vec<PackageRoot> { pub fn to_roots(&self) -> Vec<PackageRoot> {
match self { match self {
ProjectWorkspace::Json { project } => project ProjectWorkspace::Json { project } => project
.crates .crates()
.iter() .map(|(_, krate)| PackageRoot {
.map(|krate| PackageRoot {
is_member: krate.is_workspace_member, is_member: krate.is_workspace_member,
include: krate.include.clone(), include: krate.include.clone(),
exclude: krate.exclude.clone(), exclude: krate.exclude.clone(),
@ -243,9 +242,8 @@ impl ProjectWorkspace {
pub fn proc_macro_dylib_paths(&self) -> Vec<AbsPathBuf> { pub fn proc_macro_dylib_paths(&self) -> Vec<AbsPathBuf> {
match self { match self {
ProjectWorkspace::Json { project } => project ProjectWorkspace::Json { project } => project
.crates .crates()
.iter() .filter_map(|(_, krate)| krate.proc_macro_dylib_path.as_ref())
.filter_map(|krate| krate.proc_macro_dylib_path.as_ref())
.cloned() .cloned()
.collect(), .collect(),
ProjectWorkspace::Cargo { cargo, sysroot: _sysroot } => cargo ProjectWorkspace::Cargo { cargo, sysroot: _sysroot } => cargo
@ -258,7 +256,7 @@ impl ProjectWorkspace {
pub fn n_packages(&self) -> usize { pub fn n_packages(&self) -> usize {
match self { match self {
ProjectWorkspace::Json { project, .. } => project.crates.len(), ProjectWorkspace::Json { project, .. } => project.n_crates(),
ProjectWorkspace::Cargo { cargo, sysroot } => { ProjectWorkspace::Cargo { cargo, sysroot } => {
cargo.packages().len() + sysroot.crates().len() cargo.packages().len() + sysroot.crates().len()
} }
@ -276,10 +274,8 @@ impl ProjectWorkspace {
ProjectWorkspace::Json { project } => { ProjectWorkspace::Json { project } => {
let mut cfg_cache: FxHashMap<Option<&str>, Vec<CfgFlag>> = FxHashMap::default(); let mut cfg_cache: FxHashMap<Option<&str>, Vec<CfgFlag>> = FxHashMap::default();
let crates: FxHashMap<_, _> = project let crates: FxHashMap<_, _> = project
.crates .crates()
.iter() .filter_map(|(crate_id, krate)| {
.enumerate()
.filter_map(|(seq_index, krate)| {
let file_path = &krate.root_module; let file_path = &krate.root_module;
let file_id = load(&file_path)?; let file_id = load(&file_path)?;
@ -297,9 +293,8 @@ impl ProjectWorkspace {
let mut cfg_options = CfgOptions::default(); let mut cfg_options = CfgOptions::default();
cfg_options.extend(target_cfgs.iter().chain(krate.cfg.iter()).cloned()); cfg_options.extend(target_cfgs.iter().chain(krate.cfg.iter()).cloned());
// FIXME: No crate name in json definition such that we cannot add OUT_DIR to env
Some(( Some((
CrateId(seq_index as u32), crate_id,
crate_graph.add_crate_root( crate_graph.add_crate_root(
file_id, file_id,
krate.edition, krate.edition,
@ -313,19 +308,14 @@ impl ProjectWorkspace {
}) })
.collect(); .collect();
for (id, krate) in project.crates.iter().enumerate() { for (from, krate) in project.crates() {
for dep in &krate.deps { for dep in &krate.deps {
let from_crate_id = CrateId(id as u32);
let to_crate_id = dep.crate_id; let to_crate_id = dep.crate_id;
if let (Some(&from), Some(&to)) = if let (Some(&from), Some(&to)) =
(crates.get(&from_crate_id), crates.get(&to_crate_id)) (crates.get(&from), crates.get(&to_crate_id))
{ {
if crate_graph.add_dep(from, dep.name.clone(), to).is_err() { if let Err(_) = crate_graph.add_dep(from, dep.name.clone(), to) {
log::error!( log::error!("cyclic dependency {:?} -> {:?}", from, to_crate_id);
"cyclic dependency {:?} -> {:?}",
from_crate_id,
to_crate_id
);
} }
} }
} }

View file

@ -12,7 +12,7 @@ use crate::cfg_flag::CfgFlag;
/// Roots and crates that compose this Rust project. /// Roots and crates that compose this Rust project.
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Clone, Debug, Eq, PartialEq)]
pub struct ProjectJson { pub struct ProjectJson {
pub(crate) crates: Vec<Crate>, crates: Vec<Crate>,
} }
/// A crate points to the root module of a crate and lists the dependencies of the crate. This is /// A crate points to the root module of a crate and lists the dependencies of the crate. This is
@ -79,6 +79,12 @@ impl ProjectJson {
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
} }
} }
pub fn n_crates(&self) -> usize {
self.crates.len()
}
pub fn crates(&self) -> impl Iterator<Item = (CrateId, &Crate)> + '_ {
self.crates.iter().enumerate().map(|(idx, krate)| (CrateId(idx as u32), krate))
}
} }
#[derive(Deserialize)] #[derive(Deserialize)]