Auto merge of #103723 - CastilloDel:master, r=jackh726

Remove allow(rustc::potential_query_instability) in rustc_trait_selection

Related to https://github.com/rust-lang/rust/issues/84447

This PR needs to be benchmarked to check for regressions.
This commit is contained in:
bors 2022-11-09 13:45:27 +00:00
commit cc9b259b5e
10 changed files with 37 additions and 30 deletions

View file

@ -1,7 +1,7 @@
use super::potentially_plural_count; use super::potentially_plural_count;
use crate::errors::LifetimesOrBoundsMismatchOnTrait; use crate::errors::LifetimesOrBoundsMismatchOnTrait;
use hir::def_id::{DefId, LocalDefId}; 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_errors::{pluralize, struct_span_err, Applicability, DiagnosticId, ErrorGuaranteed};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
@ -256,7 +256,7 @@ fn compare_predicate_entailment<'tcx>(
// Compute placeholder form of impl and trait method tys. // Compute placeholder form of impl and trait method tys.
let tcx = infcx.tcx; 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( let impl_sig = infcx.replace_bound_vars_with_fresh_vars(
impl_m_span, 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_sig = ocx.normalize(norm_cause.clone(), param_env, unnormalized_trait_sig);
let trait_return_ty = trait_sig.output(); 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()), unnormalized_trait_sig.inputs_and_output.iter().chain(trait_sig.inputs_and_output.iter()),
); );

View file

@ -1,7 +1,7 @@
use crate::constrained_generic_params::{identify_constrained_generic_params, Parameter}; use crate::constrained_generic_params::{identify_constrained_generic_params, Parameter};
use hir::def::DefKind; use hir::def::DefKind;
use rustc_ast as ast; use rustc_ast as ast;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed}; use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
@ -412,7 +412,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
.iter() .iter()
.copied() .copied()
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
&FxHashSet::default(), &FxIndexSet::default(),
gat_def_id.def_id, gat_def_id.def_id,
gat_generics, gat_generics,
) )
@ -462,10 +462,10 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
.into_iter() .into_iter()
.filter(|clause| match clause.kind().skip_binder() { .filter(|clause| match clause.kind().skip_binder() {
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => { ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => {
!region_known_to_outlive(tcx, gat_hir, param_env, &FxHashSet::default(), a, b) !region_known_to_outlive(tcx, gat_hir, param_env, &FxIndexSet::default(), a, b)
} }
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(a, b)) => { ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(a, b)) => {
!ty_known_to_outlive(tcx, gat_hir, param_env, &FxHashSet::default(), a, b) !ty_known_to_outlive(tcx, gat_hir, param_env, &FxIndexSet::default(), a, b)
} }
_ => bug!("Unexpected PredicateKind"), _ => bug!("Unexpected PredicateKind"),
}) })
@ -547,7 +547,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<'tcx>>(
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
item_hir: hir::HirId, item_hir: hir::HirId,
to_check: T, to_check: T,
wf_tys: &FxHashSet<Ty<'tcx>>, wf_tys: &FxIndexSet<Ty<'tcx>>,
gat_def_id: LocalDefId, gat_def_id: LocalDefId,
gat_generics: &'tcx ty::Generics, gat_generics: &'tcx ty::Generics,
) -> Option<FxHashSet<ty::Predicate<'tcx>>> { ) -> Option<FxHashSet<ty::Predicate<'tcx>>> {
@ -654,7 +654,7 @@ fn ty_known_to_outlive<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
id: hir::HirId, id: hir::HirId,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
wf_tys: &FxHashSet<Ty<'tcx>>, wf_tys: &FxIndexSet<Ty<'tcx>>,
ty: Ty<'tcx>, ty: Ty<'tcx>,
region: ty::Region<'tcx>, region: ty::Region<'tcx>,
) -> bool { ) -> bool {
@ -671,7 +671,7 @@ fn region_known_to_outlive<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
id: hir::HirId, id: hir::HirId,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
wf_tys: &FxHashSet<Ty<'tcx>>, wf_tys: &FxIndexSet<Ty<'tcx>>,
region_a: ty::Region<'tcx>, region_a: ty::Region<'tcx>,
region_b: ty::Region<'tcx>, region_b: ty::Region<'tcx>,
) -> bool { ) -> bool {
@ -695,7 +695,7 @@ fn resolve_regions_with_wf_tys<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
id: hir::HirId, id: hir::HirId,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
wf_tys: &FxHashSet<Ty<'tcx>>, wf_tys: &FxIndexSet<Ty<'tcx>>,
add_constraints: impl for<'a> FnOnce(&'a InferCtxt<'tcx>, &'a RegionBoundPairs<'tcx>), add_constraints: impl for<'a> FnOnce(&'a InferCtxt<'tcx>, &'a RegionBoundPairs<'tcx>),
) -> bool { ) -> bool {
// Unfortunately, we have to use a new `InferCtxt` each call, because // Unfortunately, we have to use a new `InferCtxt` each call, because

View file

@ -10,6 +10,7 @@ pub(crate) use self::undo_log::{InferCtxtUndoLogs, Snapshot, UndoLog};
use crate::traits::{self, ObligationCause, PredicateObligations, TraitEngine, TraitEngineExt}; use crate::traits::{self, ObligationCause, PredicateObligations, TraitEngine, TraitEngineExt};
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use rustc_data_structures::undo_log::Rollback; use rustc_data_structures::undo_log::Rollback;
@ -294,7 +295,7 @@ pub struct InferCtxt<'tcx> {
/// the set of predicates on which errors have been reported, to /// the set of predicates on which errors have been reported, to
/// avoid reporting the same error twice. /// avoid reporting the same error twice.
pub reported_trait_errors: RefCell<FxHashMap<Span, Vec<ty::Predicate<'tcx>>>>, pub reported_trait_errors: RefCell<FxIndexMap<Span, Vec<ty::Predicate<'tcx>>>>,
pub reported_closure_mismatch: RefCell<FxHashSet<(Span, Option<Span>)>>, pub reported_closure_mismatch: RefCell<FxHashSet<(Span, Option<Span>)>>,

View file

@ -10,7 +10,6 @@
//! //!
//! This API is completely unstable and subject to change. //! This API is completely unstable and subject to change.
#![allow(rustc::potential_query_instability)]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(control_flow_enum)] #![feature(control_flow_enum)]

View file

@ -12,7 +12,7 @@ use rustc_middle::ty::fold::{TypeFolder, TypeSuperFoldable};
use rustc_middle::ty::visit::TypeVisitable; use rustc_middle::ty::visit::TypeVisitable;
use rustc_middle::ty::{PolyTraitRef, Region, RegionVid}; use rustc_middle::ty::{PolyTraitRef, Region, RegionVid};
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
use std::collections::hash_map::Entry; use std::collections::hash_map::Entry;
use std::collections::VecDeque; use std::collections::VecDeque;
@ -27,8 +27,8 @@ pub enum RegionTarget<'tcx> {
#[derive(Default, Debug, Clone)] #[derive(Default, Debug, Clone)]
pub struct RegionDeps<'tcx> { pub struct RegionDeps<'tcx> {
larger: FxHashSet<RegionTarget<'tcx>>, larger: FxIndexSet<RegionTarget<'tcx>>,
smaller: FxHashSet<RegionTarget<'tcx>>, smaller: FxIndexSet<RegionTarget<'tcx>>,
} }
pub enum AutoTraitResult<A> { pub enum AutoTraitResult<A> {
@ -266,7 +266,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
})); }));
let computed_preds = param_env.caller_bounds().iter(); let computed_preds = param_env.caller_bounds().iter();
let mut user_computed_preds: FxHashSet<_> = user_env.caller_bounds().iter().collect(); let mut user_computed_preds: FxIndexSet<_> = user_env.caller_bounds().iter().collect();
let mut new_env = param_env; let mut new_env = param_env;
let dummy_cause = ObligationCause::dummy(); let dummy_cause = ObligationCause::dummy();
@ -389,7 +389,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
/// not just one specific lifetime (e.g., `'static`). /// not just one specific lifetime (e.g., `'static`).
fn add_user_pred( fn add_user_pred(
&self, &self,
user_computed_preds: &mut FxHashSet<ty::Predicate<'tcx>>, user_computed_preds: &mut FxIndexSet<ty::Predicate<'tcx>>,
new_pred: ty::Predicate<'tcx>, new_pred: ty::Predicate<'tcx>,
) { ) {
let mut should_add_new = true; let mut should_add_new = true;
@ -585,7 +585,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
&self, &self,
ty: Ty<'_>, ty: Ty<'_>,
nested: impl Iterator<Item = Obligation<'tcx, ty::Predicate<'tcx>>>, nested: impl Iterator<Item = Obligation<'tcx, ty::Predicate<'tcx>>>,
computed_preds: &mut FxHashSet<ty::Predicate<'tcx>>, computed_preds: &mut FxIndexSet<ty::Predicate<'tcx>>,
fresh_preds: &mut FxHashSet<ty::Predicate<'tcx>>, fresh_preds: &mut FxHashSet<ty::Predicate<'tcx>>,
predicates: &mut VecDeque<ty::PolyTraitPredicate<'tcx>>, predicates: &mut VecDeque<ty::PolyTraitPredicate<'tcx>>,
select: &mut SelectionContext<'_, 'tcx>, select: &mut SelectionContext<'_, 'tcx>,

View file

@ -4,7 +4,7 @@ use std::fmt::Debug;
use super::TraitEngine; use super::TraitEngine;
use super::{ChalkFulfillmentContext, FulfillmentContext}; use super::{ChalkFulfillmentContext, FulfillmentContext};
use crate::infer::InferCtxtExt; use crate::infer::InferCtxtExt;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxIndexSet;
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_infer::infer::at::ToTrace; use rustc_infer::infer::at::ToTrace;
use rustc_infer::infer::canonical::{ use rustc_infer::infer::canonical::{
@ -154,10 +154,10 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
span: Span, span: Span,
def_id: LocalDefId, def_id: LocalDefId,
) -> FxHashSet<Ty<'tcx>> { ) -> FxIndexSet<Ty<'tcx>> {
let tcx = self.infcx.tcx; let tcx = self.infcx.tcx;
let assumed_wf_types = tcx.assumed_wf_types(def_id); let assumed_wf_types = tcx.assumed_wf_types(def_id);
let mut implied_bounds = FxHashSet::default(); let mut implied_bounds = FxIndexSet::default();
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
let cause = ObligationCause::misc(span, hir_id); let cause = ObligationCause::misc(span, hir_id);
for ty in assumed_wf_types { for ty in assumed_wf_types {

View file

@ -15,7 +15,7 @@ use crate::traits::query::normalize::AtExt as _;
use crate::traits::specialize::to_pretty_impl_header; use crate::traits::specialize::to_pretty_impl_header;
use on_unimplemented::OnUnimplementedNote; use on_unimplemented::OnUnimplementedNote;
use on_unimplemented::TypeErrCtxtExt as _; use on_unimplemented::TypeErrCtxtExt as _;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
use rustc_errors::{ use rustc_errors::{
pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed,
MultiSpan, Style, MultiSpan, Style,
@ -379,7 +379,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
index: Option<usize>, // None if this is an old error index: Option<usize>, // None if this is an old error
} }
let mut error_map: FxHashMap<_, Vec<_>> = self let mut error_map: FxIndexMap<_, Vec<_>> = self
.reported_trait_errors .reported_trait_errors
.borrow() .borrow()
.iter() .iter()

View file

@ -2,7 +2,7 @@ use crate::infer::InferCtxt;
use crate::traits::query::type_op::{self, TypeOp, TypeOpOutput}; use crate::traits::query::type_op::{self, TypeOp, TypeOpOutput};
use crate::traits::query::NoSolution; use crate::traits::query::NoSolution;
use crate::traits::ObligationCause; use crate::traits::ObligationCause;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxIndexSet;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::HirId; use rustc_hir::HirId;
use rustc_middle::ty::{self, ParamEnv, Ty}; use rustc_middle::ty::{self, ParamEnv, Ty};
@ -22,7 +22,7 @@ pub trait InferCtxtExt<'a, 'tcx> {
&'a self, &'a self,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
body_id: hir::HirId, body_id: hir::HirId,
tys: FxHashSet<Ty<'tcx>>, tys: FxIndexSet<Ty<'tcx>>,
) -> Bounds<'a, 'tcx>; ) -> Bounds<'a, 'tcx>;
} }
@ -103,7 +103,7 @@ impl<'a, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'tcx> {
&'a self, &'a self,
param_env: ParamEnv<'tcx>, param_env: ParamEnv<'tcx>,
body_id: HirId, body_id: HirId,
tys: FxHashSet<Ty<'tcx>>, tys: FxIndexSet<Ty<'tcx>>,
) -> Bounds<'a, 'tcx> { ) -> Bounds<'a, 'tcx> {
tys.into_iter() tys.into_iter()
.map(move |ty| { .map(move |ty| {

View file

@ -2,6 +2,12 @@
//! //!
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/resolution.html#selection //! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/resolution.html#selection
// FIXME: The `map` field in ProvisionalEvaluationCache should be changed to
// a `FxIndexMap` to avoid query instability, but right now it causes a perf regression. This would be
// fixed or at least lightened by the addition of the `drain_filter` method to `FxIndexMap`
// Relevant: https://github.com/rust-lang/rust/pull/103723 and https://github.com/bluss/indexmap/issues/242
#![allow(rustc::potential_query_instability)]
use self::EvaluationResult::*; use self::EvaluationResult::*;
use self::SelectionCandidate::*; use self::SelectionCandidate::*;
@ -24,7 +30,8 @@ use crate::traits::error_reporting::TypeErrCtxtExt;
use crate::traits::project::ProjectAndUnifyResult; use crate::traits::project::ProjectAndUnifyResult;
use crate::traits::project::ProjectionCacheKeyExt; use crate::traits::project::ProjectionCacheKeyExt;
use crate::traits::ProjectionCacheKey; use crate::traits::ProjectionCacheKey;
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet}; use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_errors::{Diagnostic, ErrorGuaranteed}; use rustc_errors::{Diagnostic, ErrorGuaranteed};
use rustc_hir as hir; use rustc_hir as hir;

View file

@ -16,7 +16,7 @@ use crate::errors::NegativePositiveConflict;
use crate::infer::{InferCtxt, InferOk, TyCtxtInferExt}; use crate::infer::{InferCtxt, InferOk, TyCtxtInferExt};
use crate::traits::select::IntercrateAmbiguityCause; use crate::traits::select::IntercrateAmbiguityCause;
use crate::traits::{self, coherence, FutureCompatOverlapErrorKind, ObligationCause}; use crate::traits::{self, coherence, FutureCompatOverlapErrorKind, ObligationCause};
use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; use rustc_data_structures::fx::FxIndexSet;
use rustc_errors::{struct_span_err, DiagnosticBuilder, EmissionGuarantee}; use rustc_errors::{struct_span_err, DiagnosticBuilder, EmissionGuarantee};
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_middle::ty::{self, ImplSubject, TyCtxt}; use rustc_middle::ty::{self, ImplSubject, TyCtxt};
@ -435,7 +435,7 @@ pub(crate) fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Opti
// FIXME: Currently only handles ?Sized. // FIXME: Currently only handles ?Sized.
// Needs to support ?Move and ?DynSized when they are implemented. // Needs to support ?Move and ?DynSized when they are implemented.
let mut types_without_default_bounds = FxHashSet::default(); let mut types_without_default_bounds = FxIndexSet::default();
let sized_trait = tcx.lang_items().sized_trait(); let sized_trait = tcx.lang_items().sized_trait();
if !substs.is_empty() { if !substs.is_empty() {