Skip to content

Commit 83e921d

Browse files
Run 'x.py fmt'.
1 parent 6848ed2 commit 83e921d

File tree

3 files changed

+42
-101
lines changed

3 files changed

+42
-101
lines changed

src/librustc/dep_graph/graph.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@ use crate::ty::{self, TyCtxt};
22
use errors::Diagnostic;
33
use parking_lot::{Condvar, Mutex};
44
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
5+
use rustc_data_structures::profiling::QueryInvocationId;
56
use rustc_data_structures::sharded::{self, Sharded};
67
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
78
use rustc_data_structures::sync::{AtomicU32, AtomicU64, Lock, Lrc, Ordering};
89
use rustc_index::vec::{Idx, IndexVec};
910
use smallvec::SmallVec;
1011
use std::collections::hash_map::Entry;
11-
use rustc_data_structures::profiling::QueryInvocationId;
12-
use std::sync::atomic::Ordering::Relaxed;
1312
use std::env;
1413
use std::hash::Hash;
1514
use std::mem;
16-
use std::sync::atomic::Ordering::SeqCst;
15+
use std::sync::atomic::Ordering::Relaxed;
1716

1817
use crate::ich::{Fingerprint, StableHashingContext, StableHashingContextProvider};
1918

@@ -46,7 +45,7 @@ impl DepNodeIndex {
4645
impl std::convert::From<DepNodeIndex> for QueryInvocationId {
4746
#[inline]
4847
fn from(dep_node_index: DepNodeIndex) -> Self {
49-
QueryInvocationId(dep_node_index.as_u32())
48+
QueryInvocationId(dep_node_index.as_u32())
5049
}
5150
}
5251

@@ -125,10 +124,7 @@ impl DepGraph {
125124
}
126125

127126
pub fn new_disabled() -> DepGraph {
128-
DepGraph {
129-
data: None,
130-
virtual_dep_node_index: Lrc::new(AtomicU32::new(0)),
131-
}
127+
DepGraph { data: None, virtual_dep_node_index: Lrc::new(AtomicU32::new(0)) }
132128
}
133129

134130
/// Returns `true` if we are actually building the full dep-graph, and `false` otherwise.

src/librustc/ty/query/profiling_support.rs

Lines changed: 31 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use crate::hir::def_id::{CRATE_DEF_INDEX, CrateNum, DefId, DefIndex, LOCAL_CRATE};
1+
use crate::hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE};
22
use crate::hir::map::definitions::DefPathData;
33
use crate::ty::context::TyCtxt;
44
use crate::ty::query::config::QueryConfig;
55
use crate::ty::query::plumbing::QueryCache;
6-
use measureme::{StringId, StringComponent};
6+
use measureme::{StringComponent, StringId};
77
use rustc_data_structures::fx::FxHashMap;
88
use rustc_data_structures::profiling::SelfProfiler;
99
use rustc_data_structures::sharded::Sharded;
@@ -16,9 +16,7 @@ pub struct QueryKeyStringCache {
1616

1717
impl QueryKeyStringCache {
1818
pub fn new() -> QueryKeyStringCache {
19-
QueryKeyStringCache {
20-
def_id_cache: Default::default(),
21-
}
19+
QueryKeyStringCache { def_id_cache: Default::default() }
2220
}
2321
}
2422

@@ -29,24 +27,18 @@ pub struct QueryKeyStringBuilder<'p, 'c, 'tcx> {
2927
}
3028

3129
impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
32-
3330
pub fn new(
3431
profiler: &'p SelfProfiler,
3532
tcx: TyCtxt<'tcx>,
3633
string_cache: &'c mut QueryKeyStringCache,
3734
) -> QueryKeyStringBuilder<'p, 'c, 'tcx> {
38-
QueryKeyStringBuilder {
39-
profiler,
40-
tcx,
41-
string_cache,
42-
}
35+
QueryKeyStringBuilder { profiler, tcx, string_cache }
4336
}
4437

4538
// The current implementation is rather crude. In the future it might be a
4639
// good idea to base this on `ty::print` in order to get nicer and more
4740
// efficient query keys.
4841
fn def_id_to_string_id(&mut self, def_id: DefId) -> StringId {
49-
5042
if let Some(&string_id) = self.string_cache.def_id_cache.get(&def_id) {
5143
return string_id;
5244
}
@@ -55,16 +47,11 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
5547

5648
let (parent_string_id, start_index) = match def_key.parent {
5749
Some(parent_index) => {
58-
let parent_def_id = DefId {
59-
index: parent_index,
60-
krate: def_id.krate,
61-
};
50+
let parent_def_id = DefId { index: parent_index, krate: def_id.krate };
6251

6352
(self.def_id_to_string_id(parent_def_id), 0)
6453
}
65-
None => {
66-
(StringId::INVALID, 2)
67-
}
54+
None => (StringId::INVALID, 2),
6855
};
6956

7057
let dis_buffer = &mut [0u8; 16];
@@ -84,12 +71,10 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
8471
dis = "";
8572
end_index = 3;
8673
} else {
87-
write!(&mut dis_buffer[..],
88-
"[{}]",
89-
def_key.disambiguated_data.disambiguator
90-
).unwrap();
74+
write!(&mut dis_buffer[..], "[{}]", def_key.disambiguated_data.disambiguator)
75+
.unwrap();
9176
let end_of_dis = dis_buffer.iter().position(|&c| c == b']').unwrap();
92-
dis = std::str::from_utf8(&dis_buffer[.. end_of_dis + 1]).unwrap();
77+
dis = std::str::from_utf8(&dis_buffer[..end_of_dis + 1]).unwrap();
9378
end_index = 4;
9479
}
9580
}
@@ -99,12 +84,10 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
9984
StringComponent::Ref(parent_string_id),
10085
StringComponent::Value("::"),
10186
StringComponent::Value(&name[..]),
102-
StringComponent::Value(dis)
87+
StringComponent::Value(dis),
10388
];
10489

105-
let string_id = self.profiler.alloc_string(
106-
&components[start_index .. end_index]
107-
);
90+
let string_id = self.profiler.alloc_string(&components[start_index..end_index]);
10891

10992
self.string_cache.def_id_cache.insert(def_id, string_id);
11093

@@ -113,72 +96,50 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
11396
}
11497

11598
pub trait IntoSelfProfilingString {
116-
fn to_self_profile_string(
117-
&self,
118-
builder: &mut QueryKeyStringBuilder<'_, '_, '_>
119-
) -> StringId;
99+
fn to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_, '_>) -> StringId;
120100
}
121101

122102
// The default implementation of `IntoSelfProfilingString` just uses `Debug`
123103
// which is slow and causes lots of duplication of string data.
124104
// The specialized impls below take care of making the `DefId` case more
125105
// efficient.
126106
impl<T: Debug> IntoSelfProfilingString for T {
127-
128107
default fn to_self_profile_string(
129108
&self,
130-
builder: &mut QueryKeyStringBuilder<'_, '_, '_>
109+
builder: &mut QueryKeyStringBuilder<'_, '_, '_>,
131110
) -> StringId {
132111
let s = format!("{:?}", self);
133112
builder.profiler.alloc_string(&s[..])
134113
}
135114
}
136115

137116
impl IntoSelfProfilingString for DefId {
138-
139-
fn to_self_profile_string(
140-
&self,
141-
builder: &mut QueryKeyStringBuilder<'_, '_, '_>
142-
) -> StringId {
117+
fn to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_, '_>) -> StringId {
143118
builder.def_id_to_string_id(*self)
144119
}
145120
}
146121

147122
impl IntoSelfProfilingString for CrateNum {
148-
149-
fn to_self_profile_string(
150-
&self,
151-
builder: &mut QueryKeyStringBuilder<'_, '_, '_>
152-
) -> StringId {
153-
builder.def_id_to_string_id(DefId {
154-
krate: *self,
155-
index: CRATE_DEF_INDEX,
156-
})
123+
fn to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_, '_>) -> StringId {
124+
builder.def_id_to_string_id(DefId { krate: *self, index: CRATE_DEF_INDEX })
157125
}
158126
}
159127

160128
impl IntoSelfProfilingString for DefIndex {
161-
162-
fn to_self_profile_string(
163-
&self,
164-
builder: &mut QueryKeyStringBuilder<'_, '_, '_>
165-
) -> StringId {
166-
builder.def_id_to_string_id(DefId {
167-
krate: LOCAL_CRATE,
168-
index: *self,
169-
})
129+
fn to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_, '_>) -> StringId {
130+
builder.def_id_to_string_id(DefId { krate: LOCAL_CRATE, index: *self })
170131
}
171132
}
172133

173134
impl<T0, T1> IntoSelfProfilingString for (T0, T1)
174-
where T0: IntoSelfProfilingString+Debug,
175-
T1: IntoSelfProfilingString+Debug,
135+
where
136+
T0: IntoSelfProfilingString + Debug,
137+
T1: IntoSelfProfilingString + Debug,
176138
{
177139
default fn to_self_profile_string(
178140
&self,
179-
builder: &mut QueryKeyStringBuilder<'_, '_, '_>
141+
builder: &mut QueryKeyStringBuilder<'_, '_, '_>,
180142
) -> StringId {
181-
182143
let val0 = self.0.to_self_profile_string(builder);
183144
let val1 = self.1.to_self_profile_string(builder);
184145

@@ -202,16 +163,17 @@ pub(super) fn alloc_self_profile_query_strings_for_query_cache<'tcx, Q>(
202163
query_name: &'static str,
203164
query_cache: &Sharded<QueryCache<'tcx, Q>>,
204165
string_cache: &mut QueryKeyStringCache,
205-
) where Q: QueryConfig<'tcx> {
166+
) where
167+
Q: QueryConfig<'tcx>,
168+
{
206169
tcx.prof.with_profiler(|profiler| {
207170
let event_id_builder = profiler.event_id_builder();
208171

209172
// Walk the entire query cache and allocate the appropriate
210173
// string representations. Each cache entry is uniquely
211174
// identified by its dep_node_index.
212175
if profiler.query_key_recording_enabled() {
213-
let mut query_string_builder =
214-
QueryKeyStringBuilder::new(profiler, tcx, string_cache);
176+
let mut query_string_builder = QueryKeyStringBuilder::new(profiler, tcx, string_cache);
215177

216178
let query_name = profiler.get_or_alloc_cached_string(query_name);
217179

@@ -226,9 +188,9 @@ pub(super) fn alloc_self_profile_query_strings_for_query_cache<'tcx, Q>(
226188
let mut query_keys_and_indices = Vec::with_capacity(len);
227189

228190
for shard in &shards {
229-
query_keys_and_indices.extend(shard.results.iter().map(|(q_key, q_val)| {
230-
(q_key.clone(), q_val.index)
231-
}));
191+
query_keys_and_indices.extend(
192+
shard.results.iter().map(|(q_key, q_val)| (q_key.clone(), q_val.index)),
193+
);
232194
}
233195

234196
query_keys_and_indices
@@ -265,10 +227,8 @@ pub(super) fn alloc_self_profile_query_strings_for_query_cache<'tcx, Q>(
265227
.map(|v| v.index)
266228
.map(|dep_node_index| dep_node_index.into());
267229

268-
profiler.bulk_map_query_invocation_id_to_single_string(
269-
query_invocation_ids,
270-
event_id,
271-
);
230+
profiler
231+
.bulk_map_query_invocation_id_to_single_string(query_invocation_ids, event_id);
272232
}
273233
}
274234
});

src/librustc_data_structures/profiling.rs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,7 @@ impl SelfProfilerRef {
257257
self.exec(EventFilter::GENERIC_ACTIVITIES, |profiler| {
258258
let event_id = profiler.get_or_alloc_cached_string(event_id);
259259
let event_id = EventId::from_label(event_id);
260-
TimingGuard::start(
261-
profiler,
262-
profiler.generic_activity_event_kind,
263-
event_id
264-
)
260+
TimingGuard::start(profiler, profiler.generic_activity_event_kind, event_id)
265261
})
266262
}
267263

@@ -290,11 +286,7 @@ impl SelfProfilerRef {
290286
#[inline(always)]
291287
pub fn query_blocked(&self) -> TimingGuard<'_> {
292288
self.exec(EventFilter::QUERY_BLOCKED, |profiler| {
293-
TimingGuard::start(
294-
profiler,
295-
profiler.query_blocked_event_kind,
296-
EventId::INVALID,
297-
)
289+
TimingGuard::start(profiler, profiler.query_blocked_event_kind, EventId::INVALID)
298290
})
299291
}
300292

@@ -438,7 +430,7 @@ impl SelfProfiler {
438430
let string_cache = self.string_cache.read();
439431

440432
if let Some(&id) = string_cache.get(s) {
441-
return id
433+
return id;
442434
}
443435
}
444436

@@ -448,21 +440,14 @@ impl SelfProfiler {
448440
*string_cache.entry(s).or_insert_with(|| self.profiler.alloc_string(s))
449441
}
450442

451-
pub fn map_query_invocation_id_to_string(
452-
&self,
453-
from: QueryInvocationId,
454-
to: StringId
455-
) {
443+
pub fn map_query_invocation_id_to_string(&self, from: QueryInvocationId, to: StringId) {
456444
let from = StringId::new_virtual(from.0);
457445
self.profiler.map_virtual_to_concrete_string(from, to);
458446
}
459447

460-
pub fn bulk_map_query_invocation_id_to_single_string<I>(
461-
&self,
462-
from: I,
463-
to: StringId
464-
)
465-
where I: Iterator<Item=QueryInvocationId> + ExactSizeIterator
448+
pub fn bulk_map_query_invocation_id_to_single_string<I>(&self, from: I, to: StringId)
449+
where
450+
I: Iterator<Item = QueryInvocationId> + ExactSizeIterator,
466451
{
467452
let from = from.map(|qid| StringId::new_virtual(qid.0));
468453
self.profiler.bulk_map_virtual_to_single_concrete_string(from, to);

0 commit comments

Comments
 (0)