Use UnordSet instead of FxHashSet in define_id_collections!().

This commit is contained in:
Michael Woerister 2022-12-02 16:27:25 +01:00
parent 65d2f2a5f9
commit 8a1de57a4a
6 changed files with 49 additions and 18 deletions

View File

@ -8,7 +8,7 @@
use rustc_codegen_ssa::traits::{ConstMethods, CoverageInfoMethods};
use rustc_data_structures::fx::FxIndexSet;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefIdSet;
use rustc_hir::def_id::DefId;
use rustc_llvm::RustString;
use rustc_middle::bug;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
@ -291,7 +291,7 @@ fn add_unused_functions(cx: &CodegenCx<'_, '_>) {
let ignore_unused_generics = tcx.sess.instrument_coverage_except_unused_generics();
let eligible_def_ids: DefIdSet = tcx
let eligible_def_ids: Vec<DefId> = tcx
.mir_keys(())
.iter()
.filter_map(|local_def_id| {
@ -317,7 +317,9 @@ fn add_unused_functions(cx: &CodegenCx<'_, '_>) {
let codegenned_def_ids = tcx.codegened_and_inlined_items(());
for &non_codegenned_def_id in eligible_def_ids.difference(codegenned_def_ids) {
for non_codegenned_def_id in
eligible_def_ids.into_iter().filter(|id| !codegenned_def_ids.contains(id))
{
let codegen_fn_attrs = tcx.codegen_fn_attrs(non_codegenned_def_id);
// If a function is marked `#[no_coverage]`, then skip generating a

View File

@ -964,16 +964,19 @@ pub fn provide(providers: &mut Providers) {
};
let (defids, _) = tcx.collect_and_partition_mono_items(cratenum);
for id in &*defids {
let any_for_speed = defids.items().any(|id| {
let CodegenFnAttrs { optimize, .. } = tcx.codegen_fn_attrs(*id);
match optimize {
attr::OptimizeAttr::None => continue,
attr::OptimizeAttr::Size => continue,
attr::OptimizeAttr::Speed => {
attr::OptimizeAttr::None | attr::OptimizeAttr::Size => false,
attr::OptimizeAttr::Speed => true,
}
});
if any_for_speed {
return for_speed;
}
}
}
tcx.sess.opts.optimize
};
}

View File

@ -12,7 +12,7 @@
macro_rules! define_id_collections {
($map_name:ident, $set_name:ident, $entry_name:ident, $key:ty) => {
pub type $map_name<T> = $crate::fx::FxHashMap<$key, T>;
pub type $set_name = $crate::fx::FxHashSet<$key>;
pub type $set_name = $crate::unord::UnordSet<$key>;
pub type $entry_name<'a, T> = $crate::fx::StdEntry<'a, $key, T>;
};
}

View File

@ -38,17 +38,17 @@ pub fn map<U, F: Fn(T) -> U>(self, f: F) -> UnordItems<U, impl Iterator<Item = U
}
#[inline]
pub fn all<U, F: Fn(T) -> bool>(mut self, f: F) -> bool {
pub fn all<F: Fn(T) -> bool>(mut self, f: F) -> bool {
self.0.all(f)
}
#[inline]
pub fn any<U, F: Fn(T) -> bool>(mut self, f: F) -> bool {
pub fn any<F: Fn(T) -> bool>(mut self, f: F) -> bool {
self.0.any(f)
}
#[inline]
pub fn filter<U, F: Fn(&T) -> bool>(self, f: F) -> UnordItems<T, impl Iterator<Item = T>> {
pub fn filter<F: Fn(&T) -> bool>(self, f: F) -> UnordItems<T, impl Iterator<Item = T>> {
UnordItems(self.0.filter(f))
}
@ -96,6 +96,15 @@ pub fn product<S>(self) -> S
pub fn count(self) -> usize {
self.0.count()
}
#[inline]
pub fn flat_map<U, F, O>(self, f: F) -> UnordItems<O, impl Iterator<Item = O>>
where
U: IntoIterator<Item = O>,
F: Fn(T) -> U,
{
UnordItems(self.0.flat_map(f))
}
}
impl<'a, T: Clone + 'a, I: Iterator<Item = &'a T>> UnordItems<&'a T, I> {
@ -193,6 +202,11 @@ pub fn into_items(self) -> UnordItems<V, impl Iterator<Item = V>> {
pub fn extend<I: Iterator<Item = V>>(&mut self, items: UnordItems<V, I>) {
self.inner.extend(items.0)
}
#[inline]
pub fn clear(&mut self) {
self.inner.clear();
}
}
impl<V: Hash + Eq> Extend<V> for UnordSet<V> {
@ -201,6 +215,12 @@ fn extend<T: IntoIterator<Item = V>>(&mut self, iter: T) {
}
}
impl<V: Hash + Eq> FromIterator<V> for UnordSet<V> {
fn from_iter<T: IntoIterator<Item = V>>(iter: T) -> Self {
UnordSet { inner: FxHashSet::from_iter(iter) }
}
}
impl<HCX, V: Hash + Eq + HashStable<HCX>> HashStable<HCX> for UnordSet<V> {
#[inline]
fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) {

View File

@ -19,6 +19,7 @@
use rustc_middle::ty::{self, ClosureSizeProfileData, Ty, TyCtxt};
use rustc_span::symbol::sym;
use rustc_span::Span;
use smallvec::SmallVec;
use std::mem;
use std::ops::ControlFlow;
@ -458,12 +459,17 @@ fn visit_closures(&mut self) {
fn visit_coercion_casts(&mut self) {
let fcx_typeck_results = self.fcx.typeck_results.borrow();
let fcx_coercion_casts = fcx_typeck_results.coercion_casts();
assert_eq!(fcx_typeck_results.hir_owner, self.typeck_results.hir_owner);
self.tcx().with_stable_hashing_context(|hcx| {
let fcx_coercion_casts: SmallVec<[_; 32]> =
fcx_typeck_results.coercion_casts().items().cloned().into_sorted_small_vec(&hcx);
for local_id in fcx_coercion_casts {
self.typeck_results.set_coercion_cast(*local_id);
self.typeck_results.set_coercion_cast(local_id);
}
});
}
fn visit_user_provided_tys(&mut self) {

View File

@ -219,7 +219,7 @@ fn fill_trait_set(traitt: DefId, set: &mut DefIdSet, cx: &LateContext<'_>) {
let is_empty = sym!(is_empty);
let is_empty_method_found = current_and_super_traits
.iter()
.items()
.flat_map(|&i| cx.tcx.associated_items(i).filter_by_name_unhygienic(is_empty))
.any(|i| {
i.kind == ty::AssocKind::Fn