1
Fork 0

crates is already deterministic

This commit is contained in:
lcnr 2021-09-17 09:13:16 +02:00
parent 5b9cc2068f
commit 01bcddbdc4
3 changed files with 29 additions and 43 deletions

View file

@ -277,7 +277,7 @@ fn attempt_static(tcx: TyCtxt<'_>) -> Option<DependencyList> {
let all_crates_available_as_rlib = tcx
.crates(())
.iter()
.cloned()
.copied()
.filter_map(|cnum| {
if tcx.dep_kind(cnum).macros_only() {
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
// everything in explicitly so long as it's actually required.
let last_crate = tcx.crates(()).len();
let mut ret = (1..last_crate + 1)
.map(|cnum| {
if tcx.dep_kind(CrateNum::new(cnum)) == CrateDepKind::Explicit {
let mut ret = tcx
.crates(())
.iter()
.map(|&cnum| {
if tcx.dep_kind(cnum) == CrateDepKind::Explicit {
Linkage::Static
} else {
Linkage::NotLinked

View file

@ -304,17 +304,7 @@ pub fn provide(providers: &mut Providers) {
// traversal, but not globally minimal across all crates.
let bfs_queue = &mut VecDeque::new();
// Preferring shortest paths alone does not guarantee a
// 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() {
for &cnum in tcx.crates(()) {
// Ignore crates without a corresponding local `extern crate` item.
if tcx.missing_extern_crate_item(cnum) {
continue;
@ -323,9 +313,6 @@ pub fn provide(providers: &mut Providers) {
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| {
if child.vis != ty::Visibility::Public {
return;
@ -353,7 +340,6 @@ pub fn provide(providers: &mut Providers) {
add_child(bfs_queue, child, def);
}
}
}
visible_parent_map
},

View file

@ -1708,9 +1708,10 @@ impl EncodeContext<'a, 'tcx> {
fn encode_crate_deps(&mut self) -> Lazy<[CrateDep]> {
empty_proc_macro!(self);
let crates = self.tcx.crates(());
let mut deps = crates
let deps = self
.tcx
.crates(())
.iter()
.map(|&cnum| {
let dep = CrateDep {
@ -1724,8 +1725,6 @@ impl EncodeContext<'a, 'tcx> {
})
.collect::<Vec<_>>();
deps.sort_by_key(|&(cnum, _)| cnum);
{
// Sanity-check the crate numbers
let mut expected_cnum = 1;