Skip to content

Commit 36dd3d4

Browse files
Make iteration order of region_scope_tree query stable
1 parent d4a4c1d commit 36dd3d4

File tree

2 files changed

+21
-26
lines changed

2 files changed

+21
-26
lines changed

compiler/rustc_middle/src/middle/region.rs

+4-25
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/borrow_check.html
88
99
use crate::ty::TyCtxt;
10-
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
11-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
10+
use rustc_data_structures::fx::FxIndexMap;
11+
use rustc_data_structures::unord::UnordMap;
1212
use rustc_hir as hir;
1313
use rustc_hir::{HirIdMap, Node};
1414
use rustc_macros::HashStable;
15-
use rustc_query_system::ich::StableHashingContext;
1615
use rustc_span::{Span, DUMMY_SP};
1716

1817
use std::fmt;
@@ -205,7 +204,7 @@ impl Scope {
205204
pub type ScopeDepth = u32;
206205

207206
/// The region scope tree encodes information about region relationships.
208-
#[derive(Default, Debug)]
207+
#[derive(Default, Debug, HashStable)]
209208
pub struct ScopeTree {
210209
/// If not empty, this body is the root of this region hierarchy.
211210
pub root_body: Option<hir::HirId>,
@@ -306,7 +305,7 @@ pub struct ScopeTree {
306305
/// The reason is that semantically, until the `box` expression returns,
307306
/// the values are still owned by their containing expressions. So
308307
/// we'll see that `&x`.
309-
pub yield_in_scope: FxHashMap<Scope, Vec<YieldData>>,
308+
pub yield_in_scope: UnordMap<Scope, Vec<YieldData>>,
310309
}
311310

312311
/// Identifies the reason that a given expression is an rvalue candidate
@@ -404,23 +403,3 @@ impl ScopeTree {
404403
self.yield_in_scope.get(&scope).map(Deref::deref)
405404
}
406405
}
407-
408-
impl<'a> HashStable<StableHashingContext<'a>> for ScopeTree {
409-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
410-
let ScopeTree {
411-
root_body,
412-
ref parent_map,
413-
ref var_map,
414-
ref destruction_scopes,
415-
ref rvalue_candidates,
416-
ref yield_in_scope,
417-
} = *self;
418-
419-
root_body.hash_stable(hcx, hasher);
420-
parent_map.hash_stable(hcx, hasher);
421-
var_map.hash_stable(hcx, hasher);
422-
destruction_scopes.hash_stable(hcx, hasher);
423-
rvalue_candidates.hash_stable(hcx, hasher);
424-
yield_in_scope.hash_stable(hcx, hasher);
425-
}
426-
}

compiler/rustc_span/src/def_id.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::{HashStableContext, Symbol};
22
use rustc_data_structures::fingerprint::Fingerprint;
3-
use rustc_data_structures::stable_hasher::{Hash64, HashStable, StableHasher, ToStableHashKey};
3+
use rustc_data_structures::stable_hasher::{
4+
Hash64, HashStable, StableHasher, StableOrd, ToStableHashKey,
5+
};
46
use rustc_data_structures::unhash::Unhasher;
57
use rustc_data_structures::AtomicRef;
68
use rustc_index::Idx;
@@ -132,6 +134,11 @@ impl Default for DefPathHash {
132134
}
133135
}
134136

137+
// Safety: `DefPathHash` sort order is not affected (de)serialization.
138+
unsafe impl StableOrd for DefPathHash {
139+
const CAN_USE_UNSTABLE_SORT: bool = true;
140+
}
141+
135142
/// A [`StableCrateId`] is a 64-bit hash of a crate name, together with all
136143
/// `-Cmetadata` arguments, and some other data. It is to [`CrateNum`] what [`DefPathHash`] is to
137144
/// [`DefId`]. It is stable across compilation sessions.
@@ -490,6 +497,15 @@ impl<CTX: HashStableContext> ToStableHashKey<CTX> for CrateNum {
490497
}
491498
}
492499

500+
impl<CTX: HashStableContext> ToStableHashKey<CTX> for DefPathHash {
501+
type KeyType = DefPathHash;
502+
503+
#[inline]
504+
fn to_stable_hash_key(&self, _: &CTX) -> DefPathHash {
505+
*self
506+
}
507+
}
508+
493509
macro_rules! typed_def_id {
494510
($Name:ident, $LocalName:ident) => {
495511
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, HashStable_Generic)]

0 commit comments

Comments
 (0)