rustc_metadata: Cleanup generation of crate dependency lists
This commit is contained in:
parent
f453d1127d
commit
0525cf9d68
@ -807,7 +807,7 @@ fn inject_dependency_if(&self,
|
||||
// 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 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);
|
||||
}
|
||||
}
|
||||
|
||||
deps.push(cnum);
|
||||
}
|
||||
}
|
||||
|
||||
crate fn push_dependencies_in_postorder(&self, ordering: &mut Vec<CrateNum>, krate: CrateNum) {
|
||||
if ordering.contains(&krate) {
|
||||
return;
|
||||
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);
|
||||
}
|
||||
|
||||
let data = self.get_crate_data(krate);
|
||||
for &dep in data.dependencies.borrow().iter() {
|
||||
if dep != krate {
|
||||
self.push_dependencies_in_postorder(ordering, dep);
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ fn crates_untracked(&self) -> Vec<CrateNum>
|
||||
}
|
||||
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user