Skip to content

Commit 298a782

Browse files
committed
Auto merge of #106977 - michaelwoerister:unord_id_collections, r=oli-obk
Use UnordMap and UnordSet for id collections (DefIdMap, LocalDefIdMap, etc) This PR changes the `rustc_data_structures::define_id_collections!` macro to use `UnordMap` and `UnordSet` instead of `FxHashMap` and `FxHashSet`. This should account for a large portion of hash-maps being used in places where they can cause trouble. The changes required are moderate but non-zero: - In some places the collections are extracted into sorted vecs. - There are a few instances where for-loops have been changed to extends. ~~Let's see what the performance impact is. With a bit more refactoring, we might be able to get rid of some of the additional sorting -- but the change set is already big enough. Unless there's a performance impact, I'd like to do further changes in subsequent PRs.~~ Performance does not seem to be negatively affected ([perf-run here](rust-lang/rust#106977 (comment))). Part of [MCP 533](rust-lang/compiler-team#533). r? `@ghost`
2 parents ce460dc + c1b3589 commit 298a782

File tree

5 files changed

+30
-30
lines changed

5 files changed

+30
-30
lines changed

clippy_lints/src/inherent_impl.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,19 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {
5252
// List of spans to lint. (lint_span, first_span)
5353
let mut lint_spans = Vec::new();
5454

55-
for (_, impl_ids) in cx
55+
let inherent_impls = cx
5656
.tcx
57-
.crate_inherent_impls(())
58-
.inherent_impls
59-
.iter()
60-
.filter(|(&id, impls)| {
61-
impls.len() > 1
62-
// Check for `#[allow]` on the type definition
63-
&& !is_lint_allowed(
64-
cx,
65-
MULTIPLE_INHERENT_IMPL,
66-
cx.tcx.hir().local_def_id_to_hir_id(id),
67-
)
68-
})
69-
{
57+
.with_stable_hashing_context(|hcx| cx.tcx.crate_inherent_impls(()).inherent_impls.to_sorted(&hcx, true));
58+
59+
for (_, impl_ids) in inherent_impls.into_iter().filter(|(&id, impls)| {
60+
impls.len() > 1
61+
// Check for `#[allow]` on the type definition
62+
&& !is_lint_allowed(
63+
cx,
64+
MULTIPLE_INHERENT_IMPL,
65+
cx.tcx.hir().local_def_id_to_hir_id(id),
66+
)
67+
}) {
7068
for impl_id in impl_ids.iter().map(|id| id.expect_local()) {
7169
match type_map.entry(cx.tcx.type_of(impl_id)) {
7270
Entry::Vacant(e) => {

clippy_lints/src/len_zero.rs

Lines changed: 1 addition & 1 deletion
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

clippy_lints/src/loops/while_immutable_condition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr<'_>, expr: &'
3535
} else {
3636
return;
3737
};
38-
let mutable_static_in_cond = var_visitor.def_ids.iter().any(|(_, v)| *v);
38+
let mutable_static_in_cond = var_visitor.def_ids.items().any(|(_, v)| *v);
3939

4040
let mut has_break_or_return_visitor = HasBreakOrReturnVisitor {
4141
has_break_or_return: false,

clippy_lints/src/missing_trait_methods.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,21 @@ impl<'tcx> LateLintPass<'tcx> for MissingTraitMethods {
8080
}
8181
}
8282

83-
for assoc in provided.values() {
84-
let source_map = cx.tcx.sess.source_map();
85-
let definition_span = source_map.guess_head_span(cx.tcx.def_span(assoc.def_id));
83+
cx.tcx.with_stable_hashing_context(|hcx| {
84+
for assoc in provided.values_sorted(&hcx, true) {
85+
let source_map = cx.tcx.sess.source_map();
86+
let definition_span = source_map.guess_head_span(cx.tcx.def_span(assoc.def_id));
8687

87-
span_lint_and_help(
88-
cx,
89-
MISSING_TRAIT_METHODS,
90-
source_map.guess_head_span(item.span),
91-
&format!("missing trait method provided by default: `{}`", assoc.name),
92-
Some(definition_span),
93-
"implement the method",
94-
);
95-
}
88+
span_lint_and_help(
89+
cx,
90+
MISSING_TRAIT_METHODS,
91+
source_map.guess_head_span(item.span),
92+
&format!("missing trait method provided by default: `{}`", assoc.name),
93+
Some(definition_span),
94+
"implement the method",
95+
);
96+
}
97+
})
9698
}
9799
}
98100
}

clippy_lints/src/pass_by_ref_or_value.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ impl<'tcx> PassByRefOrValue {
190190
// Don't lint if an unsafe pointer is created.
191191
// TODO: Limit the check only to unsafe pointers to the argument (or part of the argument)
192192
// which escape the current function.
193-
if typeck.node_types().iter().any(|(_, &ty)| ty.is_unsafe_ptr())
193+
if typeck.node_types().items().any(|(_, &ty)| ty.is_unsafe_ptr())
194194
|| typeck
195195
.adjustments()
196-
.iter()
196+
.items()
197197
.flat_map(|(_, a)| a)
198198
.any(|a| matches!(a.kind, Adjust::Pointer(PointerCast::UnsafeFnPointer)))
199199
{

0 commit comments

Comments
 (0)