Remove #![allow(rustc::potential_query_instability)] from rustc_infer
Change reported_violations to use IndexSet It is being used to iterate and to insert, without a lot of lookups so hopefully it won't be a perf hit Change MiniGraph.nodes to use IndexSet It is being used to iterate and to insert, without performing lookups so hopefully it won't be a perf hit Change RegionConstraintData.givens to a FxIndexSet This might result in a perf hit. Remove was being used in `givens`, and `FxIndexSet` doesn't allow calling remove without losing the fixed iteration order. So it was necessary to change remove to `shift_remove`, but this method is slower. Change OpaqueTypesVisitor to use stable sets and maps This could also be a perf hit. Make TraitObject visitor use a stable set
This commit is contained in:
parent
a9ef10019f
commit
e9502010b4
@ -2,7 +2,7 @@
|
|||||||
#![deny(rustc::diagnostic_outside_of_impl)]
|
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||||
//! Error reporting machinery for lifetime errors.
|
//! Error reporting machinery for lifetime errors.
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxIndexSet;
|
||||||
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, MultiSpan};
|
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, MultiSpan};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::intravisit::Visitor;
|
use rustc_hir::intravisit::Visitor;
|
||||||
@ -276,7 +276,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||||||
fn get_impl_ident_and_self_ty_from_trait(
|
fn get_impl_ident_and_self_ty_from_trait(
|
||||||
&self,
|
&self,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
trait_objects: &FxHashSet<DefId>,
|
trait_objects: &FxIndexSet<DefId>,
|
||||||
) -> Option<(Ident, &'tcx hir::Ty<'tcx>)> {
|
) -> Option<(Ident, &'tcx hir::Ty<'tcx>)> {
|
||||||
let tcx = self.infcx.tcx;
|
let tcx = self.infcx.tcx;
|
||||||
match tcx.hir().get_if_local(def_id) {
|
match tcx.hir().get_if_local(def_id) {
|
||||||
@ -830,7 +830,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||||||
};
|
};
|
||||||
debug!(?param);
|
debug!(?param);
|
||||||
|
|
||||||
let mut visitor = TraitObjectVisitor(FxHashSet::default());
|
let mut visitor = TraitObjectVisitor(FxIndexSet::default());
|
||||||
visitor.visit_ty(param.param_ty);
|
visitor.visit_ty(param.param_ty);
|
||||||
|
|
||||||
let Some((ident, self_ty)) =
|
let Some((ident, self_ty)) =
|
||||||
@ -843,7 +843,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||||||
fn suggest_constrain_dyn_trait_in_impl(
|
fn suggest_constrain_dyn_trait_in_impl(
|
||||||
&self,
|
&self,
|
||||||
err: &mut Diagnostic,
|
err: &mut Diagnostic,
|
||||||
found_dids: &FxHashSet<DefId>,
|
found_dids: &FxIndexSet<DefId>,
|
||||||
ident: Ident,
|
ident: Ident,
|
||||||
self_ty: &hir::Ty<'_>,
|
self_ty: &hir::Ty<'_>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
|
@ -58,7 +58,7 @@ use crate::traits::{
|
|||||||
StatementAsExpression,
|
StatementAsExpression,
|
||||||
};
|
};
|
||||||
|
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
|
||||||
use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed, IntoDiagnosticArg};
|
use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed, IntoDiagnosticArg};
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString, MultiSpan};
|
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString, MultiSpan};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
@ -1498,9 +1498,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
values = None;
|
values = None;
|
||||||
}
|
}
|
||||||
struct OpaqueTypesVisitor<'tcx> {
|
struct OpaqueTypesVisitor<'tcx> {
|
||||||
types: FxHashMap<TyCategory, FxHashSet<Span>>,
|
types: FxIndexMap<TyCategory, FxIndexSet<Span>>,
|
||||||
expected: FxHashMap<TyCategory, FxHashSet<Span>>,
|
expected: FxIndexMap<TyCategory, FxIndexSet<Span>>,
|
||||||
found: FxHashMap<TyCategory, FxHashSet<Span>>,
|
found: FxIndexMap<TyCategory, FxIndexSet<Span>>,
|
||||||
ignore_span: Span,
|
ignore_span: Span,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
}
|
}
|
||||||
@ -1538,7 +1538,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
&self,
|
&self,
|
||||||
err: &mut Diagnostic,
|
err: &mut Diagnostic,
|
||||||
target: &str,
|
target: &str,
|
||||||
types: &FxHashMap<TyCategory, FxHashSet<Span>>,
|
types: &FxIndexMap<TyCategory, FxIndexSet<Span>>,
|
||||||
) {
|
) {
|
||||||
for (key, values) in types.iter() {
|
for (key, values) in types.iter() {
|
||||||
let count = values.len();
|
let count = values.len();
|
||||||
@ -3254,7 +3254,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
if blk.expr.is_some() {
|
if blk.expr.is_some() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let mut shadowed = FxHashSet::default();
|
let mut shadowed = FxIndexSet::default();
|
||||||
let mut candidate_idents = vec![];
|
let mut candidate_idents = vec![];
|
||||||
let mut find_compatible_candidates = |pat: &hir::Pat<'_>| {
|
let mut find_compatible_candidates = |pat: &hir::Pat<'_>| {
|
||||||
if let hir::PatKind::Binding(_, hir_id, ident, _) = &pat.kind
|
if let hir::PatKind::Binding(_, hir_id, ident, _) = &pat.kind
|
||||||
|
@ -9,7 +9,7 @@ use crate::infer::error_reporting::nice_region_error::NiceRegionError;
|
|||||||
use crate::infer::lexical_region_resolve::RegionResolutionError;
|
use crate::infer::lexical_region_resolve::RegionResolutionError;
|
||||||
use crate::infer::{SubregionOrigin, TypeTrace};
|
use crate::infer::{SubregionOrigin, TypeTrace};
|
||||||
use crate::traits::ObligationCauseCode;
|
use crate::traits::ObligationCauseCode;
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxIndexSet;
|
||||||
use rustc_errors::{ErrorGuaranteed, MultiSpan};
|
use rustc_errors::{ErrorGuaranteed, MultiSpan};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::intravisit::Visitor;
|
use rustc_hir::intravisit::Visitor;
|
||||||
@ -73,7 +73,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||||||
|
|
||||||
// Next, let's figure out the set of trait objects with implicit static bounds
|
// Next, let's figure out the set of trait objects with implicit static bounds
|
||||||
let ty = self.tcx().type_of(*impl_def_id);
|
let ty = self.tcx().type_of(*impl_def_id);
|
||||||
let mut v = super::static_impl_trait::TraitObjectVisitor(FxHashSet::default());
|
let mut v = super::static_impl_trait::TraitObjectVisitor(FxIndexSet::default());
|
||||||
v.visit_ty(ty);
|
v.visit_ty(ty);
|
||||||
let mut traits = vec![];
|
let mut traits = vec![];
|
||||||
for matching_def_id in v.0 {
|
for matching_def_id in v.0 {
|
||||||
|
@ -4,7 +4,7 @@ use crate::infer::error_reporting::nice_region_error::NiceRegionError;
|
|||||||
use crate::infer::lexical_region_resolve::RegionResolutionError;
|
use crate::infer::lexical_region_resolve::RegionResolutionError;
|
||||||
use crate::infer::{SubregionOrigin, TypeTrace};
|
use crate::infer::{SubregionOrigin, TypeTrace};
|
||||||
use crate::traits::{ObligationCauseCode, UnifyReceiverContext};
|
use crate::traits::{ObligationCauseCode, UnifyReceiverContext};
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxIndexSet;
|
||||||
use rustc_errors::{struct_span_err, Applicability, Diagnostic, ErrorGuaranteed, MultiSpan};
|
use rustc_errors::{struct_span_err, Applicability, Diagnostic, ErrorGuaranteed, MultiSpan};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::intravisit::{walk_ty, Visitor};
|
use rustc_hir::intravisit::{walk_ty, Visitor};
|
||||||
@ -236,7 +236,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||||||
// Same case of `impl Foo for dyn Bar { fn qux(&self) {} }` introducing a `'static`
|
// Same case of `impl Foo for dyn Bar { fn qux(&self) {} }` introducing a `'static`
|
||||||
// lifetime as above, but called using a fully-qualified path to the method:
|
// lifetime as above, but called using a fully-qualified path to the method:
|
||||||
// `Foo::qux(bar)`.
|
// `Foo::qux(bar)`.
|
||||||
let mut v = TraitObjectVisitor(FxHashSet::default());
|
let mut v = TraitObjectVisitor(FxIndexSet::default());
|
||||||
v.visit_ty(param.param_ty);
|
v.visit_ty(param.param_ty);
|
||||||
if let Some((ident, self_ty)) =
|
if let Some((ident, self_ty)) =
|
||||||
self.get_impl_ident_and_self_ty_from_trait(item_def_id, &v.0)
|
self.get_impl_ident_and_self_ty_from_trait(item_def_id, &v.0)
|
||||||
@ -408,7 +408,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||||||
fn get_impl_ident_and_self_ty_from_trait(
|
fn get_impl_ident_and_self_ty_from_trait(
|
||||||
&self,
|
&self,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
trait_objects: &FxHashSet<DefId>,
|
trait_objects: &FxIndexSet<DefId>,
|
||||||
) -> Option<(Ident, &'tcx hir::Ty<'tcx>)> {
|
) -> Option<(Ident, &'tcx hir::Ty<'tcx>)> {
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
match tcx.hir().get_if_local(def_id) {
|
match tcx.hir().get_if_local(def_id) {
|
||||||
@ -490,7 +490,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut v = TraitObjectVisitor(FxHashSet::default());
|
let mut v = TraitObjectVisitor(FxIndexSet::default());
|
||||||
v.visit_ty(ty);
|
v.visit_ty(ty);
|
||||||
|
|
||||||
// Get the `Ident` of the method being called and the corresponding `impl` (to point at
|
// Get the `Ident` of the method being called and the corresponding `impl` (to point at
|
||||||
@ -506,7 +506,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||||||
fn suggest_constrain_dyn_trait_in_impl(
|
fn suggest_constrain_dyn_trait_in_impl(
|
||||||
&self,
|
&self,
|
||||||
err: &mut Diagnostic,
|
err: &mut Diagnostic,
|
||||||
found_dids: &FxHashSet<DefId>,
|
found_dids: &FxIndexSet<DefId>,
|
||||||
ident: Ident,
|
ident: Ident,
|
||||||
self_ty: &hir::Ty<'_>,
|
self_ty: &hir::Ty<'_>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
@ -538,7 +538,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Collect all the trait objects in a type that could have received an implicit `'static` lifetime.
|
/// Collect all the trait objects in a type that could have received an implicit `'static` lifetime.
|
||||||
pub struct TraitObjectVisitor(pub FxHashSet<DefId>);
|
pub struct TraitObjectVisitor(pub FxIndexSet<DefId>);
|
||||||
|
|
||||||
impl<'tcx> TypeVisitor<'tcx> for TraitObjectVisitor {
|
impl<'tcx> TypeVisitor<'tcx> for TraitObjectVisitor {
|
||||||
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||||
|
@ -149,6 +149,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||||||
region: ty::BoundRegionKind,
|
region: ty::BoundRegionKind,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let late_bound_regions = self.tcx().collect_referenced_late_bound_regions(&ty);
|
let late_bound_regions = self.tcx().collect_referenced_late_bound_regions(&ty);
|
||||||
|
// We are only checking is any region meets the condition so order doesn't matter
|
||||||
|
#[allow(rustc::potential_query_instability)]
|
||||||
late_bound_regions.iter().any(|r| *r == region)
|
late_bound_regions.iter().any(|r| *r == region)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -842,6 +842,9 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||||||
// are placeholders as upper bounds, but the universe of the
|
// are placeholders as upper bounds, but the universe of the
|
||||||
// variable `'a`, or some variable that `'a` has to outlive, doesn't
|
// variable `'a`, or some variable that `'a` has to outlive, doesn't
|
||||||
// permit those placeholders.
|
// permit those placeholders.
|
||||||
|
//
|
||||||
|
// We only iterate to find the min, which means it doesn't cause reproducibility issues
|
||||||
|
#[allow(rustc::potential_query_instability)]
|
||||||
let min_universe = lower_vid_bounds
|
let min_universe = lower_vid_bounds
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|vid| self.var_infos[vid].universe)
|
.map(|vid| self.var_infos[vid].universe)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::infer::CombinedSnapshot;
|
use crate::infer::CombinedSnapshot;
|
||||||
use rustc_data_structures::{
|
use rustc_data_structures::{
|
||||||
|
fx::FxIndexMap,
|
||||||
graph::{scc::Sccs, vec_graph::VecGraph},
|
graph::{scc::Sccs, vec_graph::VecGraph},
|
||||||
undo_log::UndoLogs,
|
undo_log::UndoLogs,
|
||||||
};
|
};
|
||||||
@ -371,7 +372,7 @@ rustc_index::newtype_index! {
|
|||||||
/// an edge `R1 -> R2` in the graph.
|
/// an edge `R1 -> R2` in the graph.
|
||||||
struct MiniGraph<'tcx> {
|
struct MiniGraph<'tcx> {
|
||||||
/// Map from a region to the index of the node in the graph.
|
/// Map from a region to the index of the node in the graph.
|
||||||
nodes: FxHashMap<ty::Region<'tcx>, LeakCheckNode>,
|
nodes: FxIndexMap<ty::Region<'tcx>, LeakCheckNode>,
|
||||||
|
|
||||||
/// Map from node index to SCC, and stores the successors of each SCC. All
|
/// Map from node index to SCC, and stores the successors of each SCC. All
|
||||||
/// the regions in the same SCC are equal to one another, and if `S1 -> S2`,
|
/// the regions in the same SCC are equal to one another, and if `S1 -> S2`,
|
||||||
@ -388,7 +389,7 @@ impl<'tcx> MiniGraph<'tcx> {
|
|||||||
where
|
where
|
||||||
'tcx: 'a,
|
'tcx: 'a,
|
||||||
{
|
{
|
||||||
let mut nodes = FxHashMap::default();
|
let mut nodes = FxIndexMap::default();
|
||||||
let mut edges = Vec::new();
|
let mut edges = Vec::new();
|
||||||
|
|
||||||
// Note that if `R2: R1`, we get a callback `r1, r2`, so `target` is first parameter.
|
// Note that if `R2: R1`, we get a callback `r1, r2`, so `target` is first parameter.
|
||||||
@ -438,7 +439,7 @@ impl<'tcx> MiniGraph<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn add_node(
|
fn add_node(
|
||||||
nodes: &mut FxHashMap<ty::Region<'tcx>, LeakCheckNode>,
|
nodes: &mut FxIndexMap<ty::Region<'tcx>, LeakCheckNode>,
|
||||||
r: ty::Region<'tcx>,
|
r: ty::Region<'tcx>,
|
||||||
) -> LeakCheckNode {
|
) -> LeakCheckNode {
|
||||||
let l = nodes.len();
|
let l = nodes.len();
|
||||||
|
@ -7,7 +7,7 @@ use super::{
|
|||||||
InferCtxtUndoLogs, MiscVariable, RegionVariableOrigin, Rollback, Snapshot, SubregionOrigin,
|
InferCtxtUndoLogs, MiscVariable, RegionVariableOrigin, Rollback, Snapshot, SubregionOrigin,
|
||||||
};
|
};
|
||||||
|
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
|
||||||
use rustc_data_structures::intern::Interned;
|
use rustc_data_structures::intern::Interned;
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_data_structures::undo_log::UndoLogs;
|
use rustc_data_structures::undo_log::UndoLogs;
|
||||||
@ -125,7 +125,7 @@ pub struct RegionConstraintData<'tcx> {
|
|||||||
/// we record the fact that `'a <= 'b` is implied by the fn
|
/// we record the fact that `'a <= 'b` is implied by the fn
|
||||||
/// signature, and then ignore the constraint when solving
|
/// signature, and then ignore the constraint when solving
|
||||||
/// equations. This is a bit of a hack but seems to work.
|
/// equations. This is a bit of a hack but seems to work.
|
||||||
pub givens: FxHashSet<(Region<'tcx>, ty::RegionVid)>,
|
pub givens: FxIndexSet<(Region<'tcx>, ty::RegionVid)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents a constraint that influences the inference process.
|
/// Represents a constraint that influences the inference process.
|
||||||
|
@ -12,7 +12,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)]
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use super::ObjectSafetyViolation;
|
use super::ObjectSafetyViolation;
|
||||||
|
|
||||||
use crate::infer::InferCtxt;
|
use crate::infer::InferCtxt;
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxIndexSet;
|
||||||
use rustc_errors::{struct_span_err, DiagnosticBuilder, ErrorGuaranteed, MultiSpan};
|
use rustc_errors::{struct_span_err, DiagnosticBuilder, ErrorGuaranteed, MultiSpan};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
@ -56,7 +56,7 @@ pub fn report_object_safety_error<'tcx>(
|
|||||||
);
|
);
|
||||||
err.span_label(span, format!("`{}` cannot be made into an object", trait_str));
|
err.span_label(span, format!("`{}` cannot be made into an object", trait_str));
|
||||||
|
|
||||||
let mut reported_violations = FxHashSet::default();
|
let mut reported_violations = FxIndexSet::default();
|
||||||
let mut multi_span = vec![];
|
let mut multi_span = vec![];
|
||||||
let mut messages = vec![];
|
let mut messages = vec![];
|
||||||
for violation in violations {
|
for violation in violations {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user