Reduce the scope of allow(rustc::potential_query_instability) in rustc_trait_selection

Make InferCtxtExt use a FxIndexMap

This should be faster, because the map is only being used to iterate,
which is supposed to be faster with the IndexMap

Make the user_computed_preds use an IndexMap

It is being used mostly for iteration, so the change shouldn't result in
a perf hit

Make the RegionDeps fields use an IndexMap

This change could be a perf hit. Both `larger` and `smaller` are used
for iteration, but they are also used for insertions.

Make types_without_default_bounds use an IndexMap

It uses extend, but it also iterates and removes items. Not sure if
this will be a perf hit.

Make InferTtxt.reported_trait_errors use an IndexMap

This change brought a lot of other changes. The map seems to have been
mostly used for iteration, so the performance shouldn't suffer.

Add FIXME to change ProvisionalEvaluationCache.map to use an IndexMap

Right now this results in a perf hit. IndexMap doesn't have
the `drain_filter` API, so in `on_completion` we now need to iterate two
times over the map.
This commit is contained in:
CastilloDel 2022-10-28 23:32:41 +02:00
parent ddfe1e87f7
commit 755ca4b9aa
10 changed files with 37 additions and 30 deletions

View file

@ -1,7 +1,7 @@
use super::potentially_plural_count;
use crate::errors::LifetimesOrBoundsMismatchOnTrait;
use hir::def_id::{DefId, LocalDefId};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticId, ErrorGuaranteed};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
@ -256,7 +256,7 @@ fn compare_predicate_entailment<'tcx>(
// Compute placeholder form of impl and trait method tys.
let tcx = infcx.tcx;
let mut wf_tys = FxHashSet::default();
let mut wf_tys = FxIndexSet::default();
let impl_sig = infcx.replace_bound_vars_with_fresh_vars(
impl_m_span,
@ -479,7 +479,7 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
let trait_sig = ocx.normalize(norm_cause.clone(), param_env, unnormalized_trait_sig);
let trait_return_ty = trait_sig.output();
let wf_tys = FxHashSet::from_iter(
let wf_tys = FxIndexSet::from_iter(
unnormalized_trait_sig.inputs_and_output.iter().chain(trait_sig.inputs_and_output.iter()),
);