Use UnordSet instead of FxHashSet in define_id_collections!().
This commit is contained in:
parent
65d2f2a5f9
commit
8a1de57a4a
6 changed files with 49 additions and 18 deletions
|
@ -8,7 +8,7 @@ use rustc_codegen_ssa::coverageinfo::map::{Counter, CounterExpression};
|
||||||
use rustc_codegen_ssa::traits::{ConstMethods, CoverageInfoMethods};
|
use rustc_codegen_ssa::traits::{ConstMethods, CoverageInfoMethods};
|
||||||
use rustc_data_structures::fx::FxIndexSet;
|
use rustc_data_structures::fx::FxIndexSet;
|
||||||
use rustc_hir::def::DefKind;
|
use rustc_hir::def::DefKind;
|
||||||
use rustc_hir::def_id::DefIdSet;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_llvm::RustString;
|
use rustc_llvm::RustString;
|
||||||
use rustc_middle::bug;
|
use rustc_middle::bug;
|
||||||
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
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 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(())
|
.mir_keys(())
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|local_def_id| {
|
.filter_map(|local_def_id| {
|
||||||
|
@ -317,7 +317,9 @@ fn add_unused_functions(cx: &CodegenCx<'_, '_>) {
|
||||||
|
|
||||||
let codegenned_def_ids = tcx.codegened_and_inlined_items(());
|
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);
|
let codegen_fn_attrs = tcx.codegen_fn_attrs(non_codegenned_def_id);
|
||||||
|
|
||||||
// If a function is marked `#[no_coverage]`, then skip generating a
|
// If a function is marked `#[no_coverage]`, then skip generating a
|
||||||
|
|
|
@ -964,16 +964,19 @@ pub fn provide(providers: &mut Providers) {
|
||||||
};
|
};
|
||||||
|
|
||||||
let (defids, _) = tcx.collect_and_partition_mono_items(cratenum);
|
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);
|
let CodegenFnAttrs { optimize, .. } = tcx.codegen_fn_attrs(*id);
|
||||||
match optimize {
|
match optimize {
|
||||||
attr::OptimizeAttr::None => continue,
|
attr::OptimizeAttr::None | attr::OptimizeAttr::Size => false,
|
||||||
attr::OptimizeAttr::Size => continue,
|
attr::OptimizeAttr::Speed => true,
|
||||||
attr::OptimizeAttr::Speed => {
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if any_for_speed {
|
||||||
return for_speed;
|
return for_speed;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
tcx.sess.opts.optimize
|
tcx.sess.opts.optimize
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ pub type IndexEntry<'a, K, V> = indexmap::map::Entry<'a, K, V>;
|
||||||
macro_rules! define_id_collections {
|
macro_rules! define_id_collections {
|
||||||
($map_name:ident, $set_name:ident, $entry_name:ident, $key:ty) => {
|
($map_name:ident, $set_name:ident, $entry_name:ident, $key:ty) => {
|
||||||
pub type $map_name<T> = $crate::fx::FxHashMap<$key, T>;
|
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>;
|
pub type $entry_name<'a, T> = $crate::fx::StdEntry<'a, $key, T>;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,17 +38,17 @@ impl<T, I: Iterator<Item = T>> UnordItems<T, I> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[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)
|
self.0.all(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[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)
|
self.0.any(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[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))
|
UnordItems(self.0.filter(f))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,6 +96,15 @@ impl<T, I: Iterator<Item = T>> UnordItems<T, I> {
|
||||||
pub fn count(self) -> usize {
|
pub fn count(self) -> usize {
|
||||||
self.0.count()
|
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> {
|
impl<'a, T: Clone + 'a, I: Iterator<Item = &'a T>> UnordItems<&'a T, I> {
|
||||||
|
@ -193,6 +202,11 @@ impl<V: Eq + Hash> UnordSet<V> {
|
||||||
pub fn extend<I: Iterator<Item = V>>(&mut self, items: UnordItems<V, I>) {
|
pub fn extend<I: Iterator<Item = V>>(&mut self, items: UnordItems<V, I>) {
|
||||||
self.inner.extend(items.0)
|
self.inner.extend(items.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn clear(&mut self) {
|
||||||
|
self.inner.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: Hash + Eq> Extend<V> for UnordSet<V> {
|
impl<V: Hash + Eq> Extend<V> for UnordSet<V> {
|
||||||
|
@ -201,6 +215,12 @@ impl<V: Hash + Eq> Extend<V> for UnordSet<V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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> {
|
impl<HCX, V: Hash + Eq + HashStable<HCX>> HashStable<HCX> for UnordSet<V> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) {
|
fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) {
|
||||||
|
|
|
@ -19,6 +19,7 @@ use rustc_middle::ty::TypeckResults;
|
||||||
use rustc_middle::ty::{self, ClosureSizeProfileData, Ty, TyCtxt};
|
use rustc_middle::ty::{self, ClosureSizeProfileData, Ty, TyCtxt};
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
use smallvec::SmallVec;
|
||||||
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ops::ControlFlow;
|
use std::ops::ControlFlow;
|
||||||
|
@ -458,12 +459,17 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
||||||
|
|
||||||
fn visit_coercion_casts(&mut self) {
|
fn visit_coercion_casts(&mut self) {
|
||||||
let fcx_typeck_results = self.fcx.typeck_results.borrow();
|
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);
|
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 {
|
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) {
|
fn visit_user_provided_tys(&mut self) {
|
||||||
|
|
|
@ -219,7 +219,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items
|
||||||
let is_empty = sym!(is_empty);
|
let is_empty = sym!(is_empty);
|
||||||
|
|
||||||
let is_empty_method_found = current_and_super_traits
|
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))
|
.flat_map(|&i| cx.tcx.associated_items(i).filter_by_name_unhygienic(is_empty))
|
||||||
.any(|i| {
|
.any(|i| {
|
||||||
i.kind == ty::AssocKind::Fn
|
i.kind == ty::AssocKind::Fn
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue