Skip to content
Permalink
Browse files

rustc_metadata: Cleanup generation of crate dependency lists

  • Loading branch information
petrochenkov committed Nov 23, 2019
1 parent f453d11 commit 0525cf9d6895027e2b7cd361784db4965f97a6ed
@@ -807,7 +807,7 @@ impl<'a> CrateLoader<'a> {
// Before we inject any dependencies, make sure we don't inject a
// circular dependency by validating that this crate doesn't
// transitively depend on any crates satisfying `needs_dep`.
for dep in self.cstore.crate_dependencies_in_rpo(krate) {
for dep in self.cstore.crate_dependencies_in_reverse_postorder(krate) {
let data = self.cstore.get_crate_data(dep);
if needs_dep(&data) {
self.sess.err(&format!("the crate `{}` cannot depend \
@@ -5,7 +5,7 @@ use crate::rmeta::CrateMetadata;

use rustc_data_structures::sync::Lrc;
use rustc_index::vec::IndexVec;
use rustc::hir::def_id::CrateNum;
use rustc::hir::def_id::{LOCAL_CRATE, CrateNum};
use syntax::ast;
use syntax::edition::Edition;
use syntax::expand::allocator::AllocatorKind;
@@ -55,45 +55,40 @@ impl CStore {
self.metas[cnum] = Some(Lrc::new(data));
}

crate fn iter_crate_data<I>(&self, mut i: I)
where I: FnMut(CrateNum, &CrateMetadata)
{
for (k, v) in self.metas.iter_enumerated() {
if let &Some(ref v) = v {
i(k, v);
crate fn iter_crate_data(&self, mut f: impl FnMut(CrateNum, &CrateMetadata)) {
for (cnum, data) in self.metas.iter_enumerated() {
if let Some(data) = data {
f(cnum, data);
}
}
}

crate fn crate_dependencies_in_rpo(&self, krate: CrateNum) -> Vec<CrateNum> {
let mut ordering = Vec::new();
self.push_dependencies_in_postorder(&mut ordering, krate);
ordering.reverse();
ordering
}
fn push_dependencies_in_postorder(&self, deps: &mut Vec<CrateNum>, cnum: CrateNum) {
if !deps.contains(&cnum) {
let data = self.get_crate_data(cnum);
for &dep in data.dependencies.borrow().iter() {
if dep != cnum {
self.push_dependencies_in_postorder(deps, dep);
}
}

crate fn push_dependencies_in_postorder(&self, ordering: &mut Vec<CrateNum>, krate: CrateNum) {
if ordering.contains(&krate) {
return;
deps.push(cnum);
}
}

let data = self.get_crate_data(krate);
for &dep in data.dependencies.borrow().iter() {
if dep != krate {
self.push_dependencies_in_postorder(ordering, dep);
}
crate fn crate_dependencies_in_postorder(&self, cnum: CrateNum) -> Vec<CrateNum> {
let mut deps = Vec::new();
if cnum == LOCAL_CRATE {
self.iter_crate_data(|cnum, _| self.push_dependencies_in_postorder(&mut deps, cnum));
} else {
self.push_dependencies_in_postorder(&mut deps, cnum);
}

ordering.push(krate);
deps
}

crate fn do_postorder_cnums_untracked(&self) -> Vec<CrateNum> {
let mut ordering = Vec::new();
for (num, v) in self.metas.iter_enumerated() {
if let &Some(_) = v {
self.push_dependencies_in_postorder(&mut ordering, num);
}
}
return ordering
crate fn crate_dependencies_in_reverse_postorder(&self, cnum: CrateNum) -> Vec<CrateNum> {
let mut deps = self.crate_dependencies_in_postorder(cnum);
deps.reverse();
deps
}
}
@@ -517,7 +517,7 @@ impl CrateStore for cstore::CStore {
}

fn postorder_cnums_untracked(&self) -> Vec<CrateNum> {
self.do_postorder_cnums_untracked()
self.crate_dependencies_in_postorder(LOCAL_CRATE)
}

fn encode_metadata(&self, tcx: TyCtxt<'_>) -> EncodedMetadata {

0 comments on commit 0525cf9

Please sign in to comment.
You can’t perform that action at this time.