Run 'x.py fmt'.
This commit is contained in:
parent
6848ed2d65
commit
83e921d770
3 changed files with 42 additions and 101 deletions
|
|
@ -2,18 +2,17 @@ use crate::ty::{self, TyCtxt};
|
|||
use errors::Diagnostic;
|
||||
use parking_lot::{Condvar, Mutex};
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::profiling::QueryInvocationId;
|
||||
use rustc_data_structures::sharded::{self, Sharded};
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_data_structures::sync::{AtomicU32, AtomicU64, Lock, Lrc, Ordering};
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
use smallvec::SmallVec;
|
||||
use std::collections::hash_map::Entry;
|
||||
use rustc_data_structures::profiling::QueryInvocationId;
|
||||
use std::sync::atomic::Ordering::Relaxed;
|
||||
use std::env;
|
||||
use std::hash::Hash;
|
||||
use std::mem;
|
||||
use std::sync::atomic::Ordering::SeqCst;
|
||||
use std::sync::atomic::Ordering::Relaxed;
|
||||
|
||||
use crate::ich::{Fingerprint, StableHashingContext, StableHashingContextProvider};
|
||||
|
||||
|
|
@ -46,7 +45,7 @@ impl DepNodeIndex {
|
|||
impl std::convert::From<DepNodeIndex> for QueryInvocationId {
|
||||
#[inline]
|
||||
fn from(dep_node_index: DepNodeIndex) -> Self {
|
||||
QueryInvocationId(dep_node_index.as_u32())
|
||||
QueryInvocationId(dep_node_index.as_u32())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -125,10 +124,7 @@ impl DepGraph {
|
|||
}
|
||||
|
||||
pub fn new_disabled() -> DepGraph {
|
||||
DepGraph {
|
||||
data: None,
|
||||
virtual_dep_node_index: Lrc::new(AtomicU32::new(0)),
|
||||
}
|
||||
DepGraph { data: None, virtual_dep_node_index: Lrc::new(AtomicU32::new(0)) }
|
||||
}
|
||||
|
||||
/// Returns `true` if we are actually building the full dep-graph, and `false` otherwise.
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use crate::hir::def_id::{CRATE_DEF_INDEX, CrateNum, DefId, DefIndex, LOCAL_CRATE};
|
||||
use crate::hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use crate::hir::map::definitions::DefPathData;
|
||||
use crate::ty::context::TyCtxt;
|
||||
use crate::ty::query::config::QueryConfig;
|
||||
use crate::ty::query::plumbing::QueryCache;
|
||||
use measureme::{StringId, StringComponent};
|
||||
use measureme::{StringComponent, StringId};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::profiling::SelfProfiler;
|
||||
use rustc_data_structures::sharded::Sharded;
|
||||
|
|
@ -16,9 +16,7 @@ pub struct QueryKeyStringCache {
|
|||
|
||||
impl QueryKeyStringCache {
|
||||
pub fn new() -> QueryKeyStringCache {
|
||||
QueryKeyStringCache {
|
||||
def_id_cache: Default::default(),
|
||||
}
|
||||
QueryKeyStringCache { def_id_cache: Default::default() }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -29,24 +27,18 @@ pub struct QueryKeyStringBuilder<'p, 'c, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
|
||||
|
||||
pub fn new(
|
||||
profiler: &'p SelfProfiler,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
string_cache: &'c mut QueryKeyStringCache,
|
||||
) -> QueryKeyStringBuilder<'p, 'c, 'tcx> {
|
||||
QueryKeyStringBuilder {
|
||||
profiler,
|
||||
tcx,
|
||||
string_cache,
|
||||
}
|
||||
QueryKeyStringBuilder { profiler, tcx, string_cache }
|
||||
}
|
||||
|
||||
// The current implementation is rather crude. In the future it might be a
|
||||
// good idea to base this on `ty::print` in order to get nicer and more
|
||||
// efficient query keys.
|
||||
fn def_id_to_string_id(&mut self, def_id: DefId) -> StringId {
|
||||
|
||||
if let Some(&string_id) = self.string_cache.def_id_cache.get(&def_id) {
|
||||
return string_id;
|
||||
}
|
||||
|
|
@ -55,16 +47,11 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
|
|||
|
||||
let (parent_string_id, start_index) = match def_key.parent {
|
||||
Some(parent_index) => {
|
||||
let parent_def_id = DefId {
|
||||
index: parent_index,
|
||||
krate: def_id.krate,
|
||||
};
|
||||
let parent_def_id = DefId { index: parent_index, krate: def_id.krate };
|
||||
|
||||
(self.def_id_to_string_id(parent_def_id), 0)
|
||||
}
|
||||
None => {
|
||||
(StringId::INVALID, 2)
|
||||
}
|
||||
None => (StringId::INVALID, 2),
|
||||
};
|
||||
|
||||
let dis_buffer = &mut [0u8; 16];
|
||||
|
|
@ -84,12 +71,10 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
|
|||
dis = "";
|
||||
end_index = 3;
|
||||
} else {
|
||||
write!(&mut dis_buffer[..],
|
||||
"[{}]",
|
||||
def_key.disambiguated_data.disambiguator
|
||||
).unwrap();
|
||||
write!(&mut dis_buffer[..], "[{}]", def_key.disambiguated_data.disambiguator)
|
||||
.unwrap();
|
||||
let end_of_dis = dis_buffer.iter().position(|&c| c == b']').unwrap();
|
||||
dis = std::str::from_utf8(&dis_buffer[.. end_of_dis + 1]).unwrap();
|
||||
dis = std::str::from_utf8(&dis_buffer[..end_of_dis + 1]).unwrap();
|
||||
end_index = 4;
|
||||
}
|
||||
}
|
||||
|
|
@ -99,12 +84,10 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
|
|||
StringComponent::Ref(parent_string_id),
|
||||
StringComponent::Value("::"),
|
||||
StringComponent::Value(&name[..]),
|
||||
StringComponent::Value(dis)
|
||||
StringComponent::Value(dis),
|
||||
];
|
||||
|
||||
let string_id = self.profiler.alloc_string(
|
||||
&components[start_index .. end_index]
|
||||
);
|
||||
let string_id = self.profiler.alloc_string(&components[start_index..end_index]);
|
||||
|
||||
self.string_cache.def_id_cache.insert(def_id, string_id);
|
||||
|
||||
|
|
@ -113,10 +96,7 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
|
|||
}
|
||||
|
||||
pub trait IntoSelfProfilingString {
|
||||
fn to_self_profile_string(
|
||||
&self,
|
||||
builder: &mut QueryKeyStringBuilder<'_, '_, '_>
|
||||
) -> StringId;
|
||||
fn to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_, '_>) -> StringId;
|
||||
}
|
||||
|
||||
// The default implementation of `IntoSelfProfilingString` just uses `Debug`
|
||||
|
|
@ -124,10 +104,9 @@ pub trait IntoSelfProfilingString {
|
|||
// The specialized impls below take care of making the `DefId` case more
|
||||
// efficient.
|
||||
impl<T: Debug> IntoSelfProfilingString for T {
|
||||
|
||||
default fn to_self_profile_string(
|
||||
&self,
|
||||
builder: &mut QueryKeyStringBuilder<'_, '_, '_>
|
||||
builder: &mut QueryKeyStringBuilder<'_, '_, '_>,
|
||||
) -> StringId {
|
||||
let s = format!("{:?}", self);
|
||||
builder.profiler.alloc_string(&s[..])
|
||||
|
|
@ -135,50 +114,32 @@ impl<T: Debug> IntoSelfProfilingString for T {
|
|||
}
|
||||
|
||||
impl IntoSelfProfilingString for DefId {
|
||||
|
||||
fn to_self_profile_string(
|
||||
&self,
|
||||
builder: &mut QueryKeyStringBuilder<'_, '_, '_>
|
||||
) -> StringId {
|
||||
fn to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_, '_>) -> StringId {
|
||||
builder.def_id_to_string_id(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoSelfProfilingString for CrateNum {
|
||||
|
||||
fn to_self_profile_string(
|
||||
&self,
|
||||
builder: &mut QueryKeyStringBuilder<'_, '_, '_>
|
||||
) -> StringId {
|
||||
builder.def_id_to_string_id(DefId {
|
||||
krate: *self,
|
||||
index: CRATE_DEF_INDEX,
|
||||
})
|
||||
fn to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_, '_>) -> StringId {
|
||||
builder.def_id_to_string_id(DefId { krate: *self, index: CRATE_DEF_INDEX })
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoSelfProfilingString for DefIndex {
|
||||
|
||||
fn to_self_profile_string(
|
||||
&self,
|
||||
builder: &mut QueryKeyStringBuilder<'_, '_, '_>
|
||||
) -> StringId {
|
||||
builder.def_id_to_string_id(DefId {
|
||||
krate: LOCAL_CRATE,
|
||||
index: *self,
|
||||
})
|
||||
fn to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_, '_>) -> StringId {
|
||||
builder.def_id_to_string_id(DefId { krate: LOCAL_CRATE, index: *self })
|
||||
}
|
||||
}
|
||||
|
||||
impl<T0, T1> IntoSelfProfilingString for (T0, T1)
|
||||
where T0: IntoSelfProfilingString+Debug,
|
||||
T1: IntoSelfProfilingString+Debug,
|
||||
where
|
||||
T0: IntoSelfProfilingString + Debug,
|
||||
T1: IntoSelfProfilingString + Debug,
|
||||
{
|
||||
default fn to_self_profile_string(
|
||||
&self,
|
||||
builder: &mut QueryKeyStringBuilder<'_, '_, '_>
|
||||
builder: &mut QueryKeyStringBuilder<'_, '_, '_>,
|
||||
) -> StringId {
|
||||
|
||||
let val0 = self.0.to_self_profile_string(builder);
|
||||
let val1 = self.1.to_self_profile_string(builder);
|
||||
|
||||
|
|
@ -202,7 +163,9 @@ pub(super) fn alloc_self_profile_query_strings_for_query_cache<'tcx, Q>(
|
|||
query_name: &'static str,
|
||||
query_cache: &Sharded<QueryCache<'tcx, Q>>,
|
||||
string_cache: &mut QueryKeyStringCache,
|
||||
) where Q: QueryConfig<'tcx> {
|
||||
) where
|
||||
Q: QueryConfig<'tcx>,
|
||||
{
|
||||
tcx.prof.with_profiler(|profiler| {
|
||||
let event_id_builder = profiler.event_id_builder();
|
||||
|
||||
|
|
@ -210,8 +173,7 @@ pub(super) fn alloc_self_profile_query_strings_for_query_cache<'tcx, Q>(
|
|||
// string representations. Each cache entry is uniquely
|
||||
// identified by its dep_node_index.
|
||||
if profiler.query_key_recording_enabled() {
|
||||
let mut query_string_builder =
|
||||
QueryKeyStringBuilder::new(profiler, tcx, string_cache);
|
||||
let mut query_string_builder = QueryKeyStringBuilder::new(profiler, tcx, string_cache);
|
||||
|
||||
let query_name = profiler.get_or_alloc_cached_string(query_name);
|
||||
|
||||
|
|
@ -226,9 +188,9 @@ pub(super) fn alloc_self_profile_query_strings_for_query_cache<'tcx, Q>(
|
|||
let mut query_keys_and_indices = Vec::with_capacity(len);
|
||||
|
||||
for shard in &shards {
|
||||
query_keys_and_indices.extend(shard.results.iter().map(|(q_key, q_val)| {
|
||||
(q_key.clone(), q_val.index)
|
||||
}));
|
||||
query_keys_and_indices.extend(
|
||||
shard.results.iter().map(|(q_key, q_val)| (q_key.clone(), q_val.index)),
|
||||
);
|
||||
}
|
||||
|
||||
query_keys_and_indices
|
||||
|
|
@ -265,10 +227,8 @@ pub(super) fn alloc_self_profile_query_strings_for_query_cache<'tcx, Q>(
|
|||
.map(|v| v.index)
|
||||
.map(|dep_node_index| dep_node_index.into());
|
||||
|
||||
profiler.bulk_map_query_invocation_id_to_single_string(
|
||||
query_invocation_ids,
|
||||
event_id,
|
||||
);
|
||||
profiler
|
||||
.bulk_map_query_invocation_id_to_single_string(query_invocation_ids, event_id);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -257,11 +257,7 @@ impl SelfProfilerRef {
|
|||
self.exec(EventFilter::GENERIC_ACTIVITIES, |profiler| {
|
||||
let event_id = profiler.get_or_alloc_cached_string(event_id);
|
||||
let event_id = EventId::from_label(event_id);
|
||||
TimingGuard::start(
|
||||
profiler,
|
||||
profiler.generic_activity_event_kind,
|
||||
event_id
|
||||
)
|
||||
TimingGuard::start(profiler, profiler.generic_activity_event_kind, event_id)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -290,11 +286,7 @@ impl SelfProfilerRef {
|
|||
#[inline(always)]
|
||||
pub fn query_blocked(&self) -> TimingGuard<'_> {
|
||||
self.exec(EventFilter::QUERY_BLOCKED, |profiler| {
|
||||
TimingGuard::start(
|
||||
profiler,
|
||||
profiler.query_blocked_event_kind,
|
||||
EventId::INVALID,
|
||||
)
|
||||
TimingGuard::start(profiler, profiler.query_blocked_event_kind, EventId::INVALID)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -438,7 +430,7 @@ impl SelfProfiler {
|
|||
let string_cache = self.string_cache.read();
|
||||
|
||||
if let Some(&id) = string_cache.get(s) {
|
||||
return id
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -448,21 +440,14 @@ impl SelfProfiler {
|
|||
*string_cache.entry(s).or_insert_with(|| self.profiler.alloc_string(s))
|
||||
}
|
||||
|
||||
pub fn map_query_invocation_id_to_string(
|
||||
&self,
|
||||
from: QueryInvocationId,
|
||||
to: StringId
|
||||
) {
|
||||
pub fn map_query_invocation_id_to_string(&self, from: QueryInvocationId, to: StringId) {
|
||||
let from = StringId::new_virtual(from.0);
|
||||
self.profiler.map_virtual_to_concrete_string(from, to);
|
||||
}
|
||||
|
||||
pub fn bulk_map_query_invocation_id_to_single_string<I>(
|
||||
&self,
|
||||
from: I,
|
||||
to: StringId
|
||||
)
|
||||
where I: Iterator<Item=QueryInvocationId> + ExactSizeIterator
|
||||
pub fn bulk_map_query_invocation_id_to_single_string<I>(&self, from: I, to: StringId)
|
||||
where
|
||||
I: Iterator<Item = QueryInvocationId> + ExactSizeIterator,
|
||||
{
|
||||
let from = from.map(|qid| StringId::new_virtual(qid.0));
|
||||
self.profiler.bulk_map_virtual_to_single_concrete_string(from, to);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue