crates
is already deterministic
This commit is contained in:
parent
5b9cc2068f
commit
01bcddbdc4
3 changed files with 29 additions and 43 deletions
|
@ -277,7 +277,7 @@ fn attempt_static(tcx: TyCtxt<'_>) -> Option<DependencyList> {
|
||||||
let all_crates_available_as_rlib = tcx
|
let all_crates_available_as_rlib = tcx
|
||||||
.crates(())
|
.crates(())
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.copied()
|
||||||
.filter_map(|cnum| {
|
.filter_map(|cnum| {
|
||||||
if tcx.dep_kind(cnum).macros_only() {
|
if tcx.dep_kind(cnum).macros_only() {
|
||||||
return None;
|
return None;
|
||||||
|
@ -291,10 +291,11 @@ fn attempt_static(tcx: TyCtxt<'_>) -> Option<DependencyList> {
|
||||||
|
|
||||||
// All crates are available in an rlib format, so we're just going to link
|
// All crates are available in an rlib format, so we're just going to link
|
||||||
// everything in explicitly so long as it's actually required.
|
// everything in explicitly so long as it's actually required.
|
||||||
let last_crate = tcx.crates(()).len();
|
let mut ret = tcx
|
||||||
let mut ret = (1..last_crate + 1)
|
.crates(())
|
||||||
.map(|cnum| {
|
.iter()
|
||||||
if tcx.dep_kind(CrateNum::new(cnum)) == CrateDepKind::Explicit {
|
.map(|&cnum| {
|
||||||
|
if tcx.dep_kind(cnum) == CrateDepKind::Explicit {
|
||||||
Linkage::Static
|
Linkage::Static
|
||||||
} else {
|
} else {
|
||||||
Linkage::NotLinked
|
Linkage::NotLinked
|
||||||
|
|
|
@ -304,17 +304,7 @@ pub fn provide(providers: &mut Providers) {
|
||||||
// traversal, but not globally minimal across all crates.
|
// traversal, but not globally minimal across all crates.
|
||||||
let bfs_queue = &mut VecDeque::new();
|
let bfs_queue = &mut VecDeque::new();
|
||||||
|
|
||||||
// Preferring shortest paths alone does not guarantee a
|
for &cnum in tcx.crates(()) {
|
||||||
// deterministic result; so sort by crate num to avoid
|
|
||||||
// hashtable iteration non-determinism. This only makes
|
|
||||||
// things as deterministic as crate-nums assignment is,
|
|
||||||
// which is to say, its not deterministic in general. But
|
|
||||||
// we believe that libstd is consistently assigned crate
|
|
||||||
// num 1, so it should be enough to resolve #46112.
|
|
||||||
let mut crates: Vec<CrateNum> = (*tcx.crates(())).to_owned();
|
|
||||||
crates.sort();
|
|
||||||
|
|
||||||
for &cnum in crates.iter() {
|
|
||||||
// Ignore crates without a corresponding local `extern crate` item.
|
// Ignore crates without a corresponding local `extern crate` item.
|
||||||
if tcx.missing_extern_crate_item(cnum) {
|
if tcx.missing_extern_crate_item(cnum) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -323,9 +313,6 @@ pub fn provide(providers: &mut Providers) {
|
||||||
bfs_queue.push_back(DefId { krate: cnum, index: CRATE_DEF_INDEX });
|
bfs_queue.push_back(DefId { krate: cnum, index: CRATE_DEF_INDEX });
|
||||||
}
|
}
|
||||||
|
|
||||||
// (restrict scope of mutable-borrow of `visible_parent_map`)
|
|
||||||
{
|
|
||||||
let visible_parent_map = &mut visible_parent_map;
|
|
||||||
let mut add_child = |bfs_queue: &mut VecDeque<_>, child: &Export, parent: DefId| {
|
let mut add_child = |bfs_queue: &mut VecDeque<_>, child: &Export, parent: DefId| {
|
||||||
if child.vis != ty::Visibility::Public {
|
if child.vis != ty::Visibility::Public {
|
||||||
return;
|
return;
|
||||||
|
@ -353,7 +340,6 @@ pub fn provide(providers: &mut Providers) {
|
||||||
add_child(bfs_queue, child, def);
|
add_child(bfs_queue, child, def);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
visible_parent_map
|
visible_parent_map
|
||||||
},
|
},
|
||||||
|
|
|
@ -1708,9 +1708,10 @@ impl EncodeContext<'a, 'tcx> {
|
||||||
|
|
||||||
fn encode_crate_deps(&mut self) -> Lazy<[CrateDep]> {
|
fn encode_crate_deps(&mut self) -> Lazy<[CrateDep]> {
|
||||||
empty_proc_macro!(self);
|
empty_proc_macro!(self);
|
||||||
let crates = self.tcx.crates(());
|
|
||||||
|
|
||||||
let mut deps = crates
|
let deps = self
|
||||||
|
.tcx
|
||||||
|
.crates(())
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&cnum| {
|
.map(|&cnum| {
|
||||||
let dep = CrateDep {
|
let dep = CrateDep {
|
||||||
|
@ -1724,8 +1725,6 @@ impl EncodeContext<'a, 'tcx> {
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
deps.sort_by_key(|&(cnum, _)| cnum);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
// Sanity-check the crate numbers
|
// Sanity-check the crate numbers
|
||||||
let mut expected_cnum = 1;
|
let mut expected_cnum = 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue