Skip to content

Commit 8a1de57

Browse files
Use UnordSet instead of FxHashSet in define_id_collections!().
1 parent 65d2f2a commit 8a1de57

File tree

6 files changed

+49
-18
lines changed

6 files changed

+49
-18
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_codegen_ssa::coverageinfo::map::{Counter, CounterExpression};
88
use rustc_codegen_ssa::traits::{ConstMethods, CoverageInfoMethods};
99
use rustc_data_structures::fx::FxIndexSet;
1010
use rustc_hir::def::DefKind;
11-
use rustc_hir::def_id::DefIdSet;
11+
use rustc_hir::def_id::DefId;
1212
use rustc_llvm::RustString;
1313
use rustc_middle::bug;
1414
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
@@ -291,7 +291,7 @@ fn add_unused_functions(cx: &CodegenCx<'_, '_>) {
291291

292292
let ignore_unused_generics = tcx.sess.instrument_coverage_except_unused_generics();
293293

294-
let eligible_def_ids: DefIdSet = tcx
294+
let eligible_def_ids: Vec<DefId> = tcx
295295
.mir_keys(())
296296
.iter()
297297
.filter_map(|local_def_id| {
@@ -317,7 +317,9 @@ fn add_unused_functions(cx: &CodegenCx<'_, '_>) {
317317

318318
let codegenned_def_ids = tcx.codegened_and_inlined_items(());
319319

320-
for &non_codegenned_def_id in eligible_def_ids.difference(codegenned_def_ids) {
320+
for non_codegenned_def_id in
321+
eligible_def_ids.into_iter().filter(|id| !codegenned_def_ids.contains(id))
322+
{
321323
let codegen_fn_attrs = tcx.codegen_fn_attrs(non_codegenned_def_id);
322324

323325
// If a function is marked `#[no_coverage]`, then skip generating a

compiler/rustc_codegen_ssa/src/base.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -964,16 +964,19 @@ pub fn provide(providers: &mut Providers) {
964964
};
965965

966966
let (defids, _) = tcx.collect_and_partition_mono_items(cratenum);
967-
for id in &*defids {
967+
968+
let any_for_speed = defids.items().any(|id| {
968969
let CodegenFnAttrs { optimize, .. } = tcx.codegen_fn_attrs(*id);
969970
match optimize {
970-
attr::OptimizeAttr::None => continue,
971-
attr::OptimizeAttr::Size => continue,
972-
attr::OptimizeAttr::Speed => {
973-
return for_speed;
974-
}
971+
attr::OptimizeAttr::None | attr::OptimizeAttr::Size => false,
972+
attr::OptimizeAttr::Speed => true,
975973
}
974+
});
975+
976+
if any_for_speed {
977+
return for_speed;
976978
}
979+
977980
tcx.sess.opts.optimize
978981
};
979982
}

compiler/rustc_data_structures/src/fx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub type IndexEntry<'a, K, V> = indexmap::map::Entry<'a, K, V>;
1212
macro_rules! define_id_collections {
1313
($map_name:ident, $set_name:ident, $entry_name:ident, $key:ty) => {
1414
pub type $map_name<T> = $crate::fx::FxHashMap<$key, T>;
15-
pub type $set_name = $crate::fx::FxHashSet<$key>;
15+
pub type $set_name = $crate::unord::UnordSet<$key>;
1616
pub type $entry_name<'a, T> = $crate::fx::StdEntry<'a, $key, T>;
1717
};
1818
}

compiler/rustc_data_structures/src/unord.rs

+23-3
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ impl<T, I: Iterator<Item = T>> UnordItems<T, I> {
3838
}
3939

4040
#[inline]
41-
pub fn all<U, F: Fn(T) -> bool>(mut self, f: F) -> bool {
41+
pub fn all<F: Fn(T) -> bool>(mut self, f: F) -> bool {
4242
self.0.all(f)
4343
}
4444

4545
#[inline]
46-
pub fn any<U, F: Fn(T) -> bool>(mut self, f: F) -> bool {
46+
pub fn any<F: Fn(T) -> bool>(mut self, f: F) -> bool {
4747
self.0.any(f)
4848
}
4949

5050
#[inline]
51-
pub fn filter<U, F: Fn(&T) -> bool>(self, f: F) -> UnordItems<T, impl Iterator<Item = T>> {
51+
pub fn filter<F: Fn(&T) -> bool>(self, f: F) -> UnordItems<T, impl Iterator<Item = T>> {
5252
UnordItems(self.0.filter(f))
5353
}
5454

@@ -96,6 +96,15 @@ impl<T, I: Iterator<Item = T>> UnordItems<T, I> {
9696
pub fn count(self) -> usize {
9797
self.0.count()
9898
}
99+
100+
#[inline]
101+
pub fn flat_map<U, F, O>(self, f: F) -> UnordItems<O, impl Iterator<Item = O>>
102+
where
103+
U: IntoIterator<Item = O>,
104+
F: Fn(T) -> U,
105+
{
106+
UnordItems(self.0.flat_map(f))
107+
}
99108
}
100109

101110
impl<'a, T: Clone + 'a, I: Iterator<Item = &'a T>> UnordItems<&'a T, I> {
@@ -193,6 +202,11 @@ impl<V: Eq + Hash> UnordSet<V> {
193202
pub fn extend<I: Iterator<Item = V>>(&mut self, items: UnordItems<V, I>) {
194203
self.inner.extend(items.0)
195204
}
205+
206+
#[inline]
207+
pub fn clear(&mut self) {
208+
self.inner.clear();
209+
}
196210
}
197211

198212
impl<V: Hash + Eq> Extend<V> for UnordSet<V> {
@@ -201,6 +215,12 @@ impl<V: Hash + Eq> Extend<V> for UnordSet<V> {
201215
}
202216
}
203217

218+
impl<V: Hash + Eq> FromIterator<V> for UnordSet<V> {
219+
fn from_iter<T: IntoIterator<Item = V>>(iter: T) -> Self {
220+
UnordSet { inner: FxHashSet::from_iter(iter) }
221+
}
222+
}
223+
204224
impl<HCX, V: Hash + Eq + HashStable<HCX>> HashStable<HCX> for UnordSet<V> {
205225
#[inline]
206226
fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) {

compiler/rustc_hir_typeck/src/writeback.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc_middle::ty::TypeckResults;
1919
use rustc_middle::ty::{self, ClosureSizeProfileData, Ty, TyCtxt};
2020
use rustc_span::symbol::sym;
2121
use rustc_span::Span;
22+
use smallvec::SmallVec;
2223

2324
use std::mem;
2425
use std::ops::ControlFlow;
@@ -458,12 +459,17 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
458459

459460
fn visit_coercion_casts(&mut self) {
460461
let fcx_typeck_results = self.fcx.typeck_results.borrow();
461-
let fcx_coercion_casts = fcx_typeck_results.coercion_casts();
462+
462463
assert_eq!(fcx_typeck_results.hir_owner, self.typeck_results.hir_owner);
463464

464-
for local_id in fcx_coercion_casts {
465-
self.typeck_results.set_coercion_cast(*local_id);
466-
}
465+
self.tcx().with_stable_hashing_context(|hcx| {
466+
let fcx_coercion_casts: SmallVec<[_; 32]> =
467+
fcx_typeck_results.coercion_casts().items().cloned().into_sorted_small_vec(&hcx);
468+
469+
for local_id in fcx_coercion_casts {
470+
self.typeck_results.set_coercion_cast(local_id);
471+
}
472+
});
467473
}
468474

469475
fn visit_user_provided_tys(&mut self) {

src/tools/clippy/clippy_lints/src/len_zero.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items
219219
let is_empty = sym!(is_empty);
220220

221221
let is_empty_method_found = current_and_super_traits
222-
.iter()
222+
.items()
223223
.flat_map(|&i| cx.tcx.associated_items(i).filter_by_name_unhygienic(is_empty))
224224
.any(|i| {
225225
i.kind == ty::AssocKind::Fn

0 commit comments

Comments
 (0)