impl<'tcx> Deref for Region<'tcx> {
type Target = RegionKind<'tcx>;
+ #[inline]
fn deref(&self) -> &RegionKind<'tcx> {
&self.0.0
}
_ => bug!("free_region_binding_scope invoked on inappropriate region: {:?}", self),
}
}
+
+ /// True for free regions other than `'static`.
+ pub fn is_free(self) -> bool {
+ matches!(*self, ty::ReEarlyBound(_) | ty::ReFree(_))
+ }
+
+ /// True if `self` is a free region or static.
+ pub fn is_free_or_static(self) -> bool {
+ match *self {
+ ty::ReStatic => true,
+ _ => self.is_free(),
+ }
+ }
}
/// Type utilities
/// Creates a hash of the type `Ty` which will be the same no matter what crate
/// context it's calculated within. This is used by the `type_id` intrinsic.
pub fn type_id_hash(self, ty: Ty<'tcx>) -> u64 {
- let mut hasher = StableHasher::new();
- let mut hcx = self.create_stable_hashing_context();
-
// We want the type_id be independent of the types free regions, so we
// erase them. The erase_regions() call will also anonymize bound
// regions, which is desirable too.
let ty = self.erase_regions(ty);
- hcx.while_hashing_spans(false, |hcx| ty.hash_stable(hcx, &mut hasher));
- hasher.finish()
+ self.with_stable_hashing_context(|mut hcx| {
+ let mut hasher = StableHasher::new();
+ hcx.while_hashing_spans(false, |hcx| ty.hash_stable(hcx, &mut hasher));
+ hasher.finish()
+ })
}
pub fn res_generics_def_id(self, res: Res) -> Option<DefId> {
ty
}
+ #[inline]
pub fn outer_exclusive_binder(self) -> ty::DebruijnIndex {
self.0.outer_exclusive_binder
}
impl DepNodeIndex {
pub const INVALID: DepNodeIndex = DepNodeIndex::MAX;
pub const SINGLETON_DEPENDENCYLESS_ANON_NODE: DepNodeIndex = DepNodeIndex::from_u32(0);
+ pub const FOREVER_RED_NODE: DepNodeIndex = DepNodeIndex::from_u32(1);
}
impl std::convert::From<DepNodeIndex> for QueryInvocationId {
}
impl DepNodeColor {
+ #[inline]
pub fn is_green(self) -> bool {
match self {
DepNodeColor::Red => false,
record_stats,
);
+ let colors = DepNodeColorMap::new(prev_graph_node_count);
+
// Instantiate a dependy-less node only once for anonymous queries.
let _green_node_index = current.intern_new_node(
profiler,
smallvec![],
Fingerprint::ZERO,
);
- debug_assert_eq!(_green_node_index, DepNodeIndex::SINGLETON_DEPENDENCYLESS_ANON_NODE);
+ assert_eq!(_green_node_index, DepNodeIndex::SINGLETON_DEPENDENCYLESS_ANON_NODE);
+
+ // Instantiate a dependy-less red node only once for anonymous queries.
+ let (_red_node_index, _prev_and_index) = current.intern_node(
+ profiler,
+ &prev_graph,
+ DepNode { kind: DepKind::RED, hash: Fingerprint::ZERO.into() },
+ smallvec![],
+ None,
+ false,
+ );
+ assert_eq!(_red_node_index, DepNodeIndex::FOREVER_RED_NODE);
+ assert!(matches!(_prev_and_index, None | Some((_, DepNodeColor::Red))));
DepGraph {
data: Some(Lrc::new(DepGraphData {
current,
processed_side_effects: Default::default(),
previous: prev_graph,
- colors: DepNodeColorMap::new(prev_graph_node_count),
+ colors,
debug_loaded_from_disk: Default::default(),
})),
virtual_dep_node_index: Lrc::new(AtomicU32::new(0)),
let dcx = cx.dep_context();
let hashing_timer = dcx.profiler().incr_result_hashing();
- let current_fingerprint = hash_result.map(|f| {
- let mut hcx = dcx.create_stable_hashing_context();
- f(&mut hcx, &result)
- });
+ let current_fingerprint =
+ hash_result.map(|f| dcx.with_stable_hashing_context(|mut hcx| f(&mut hcx, &result)));
let print_status = cfg!(debug_assertions) && dcx.sess().opts.debugging_opts.dep_tasks;
let nanos = duration.as_secs() * 1_000_000_000 + duration.subsec_nanos() as u64;
let mut stable_hasher = StableHasher::new();
nanos.hash(&mut stable_hasher);
+ let anon_id_seed = stable_hasher.finish();
#[cfg(debug_assertions)]
let forbidden_edge = match env::var("RUST_FORBID_DEP_GRAPH_EDGE") {
)
}),
prev_index_to_index: Lock::new(IndexVec::from_elem_n(None, prev_graph_node_count)),
- anon_id_seed: stable_hasher.finish(),
+ anon_id_seed,
#[cfg(debug_assertions)]
forbidden_edge,
total_read_count: AtomicU64::new(0),