Auto merge of #120812 - compiler-errors:impl-sorting, r=lcnr
Remove unnecessary impl sorting in queries and metadata Removes unnecessary impl sorting because queries already return their keys in HIR definition order: https://github.com/rust-lang/rust/issues/120371#issuecomment-1926422838 r? `@cjgillot` or `@lcnr` -- unless I totally misunderstood what was being asked for here? 😆 fixes #120371
This commit is contained in:
commit
0f8534e79e
10 changed files with 75 additions and 95 deletions
|
@ -40,7 +40,6 @@ use rustc_data_structures::intern::Interned;
|
|||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_data_structures::steal::Steal;
|
||||
use rustc_data_structures::tagged_ptr::CopyTaggedPtr;
|
||||
use rustc_data_structures::unord::UnordMap;
|
||||
use rustc_errors::{Diag, ErrorGuaranteed, StashKey};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{CtorKind, CtorOf, DefKind, DocLinkResMap, LifetimeRes, Res};
|
||||
|
@ -2083,6 +2082,8 @@ pub fn provide(providers: &mut Providers) {
|
|||
*providers = Providers {
|
||||
trait_impls_of: trait_def::trait_impls_of_provider,
|
||||
incoherent_impls: trait_def::incoherent_impls_provider,
|
||||
trait_impls_in_crate: trait_def::trait_impls_in_crate_provider,
|
||||
traits: trait_def::traits_provider,
|
||||
const_param_default: consts::const_param_default,
|
||||
vtable_allocation: vtable::vtable_allocation_provider,
|
||||
..*providers
|
||||
|
@ -2096,8 +2097,8 @@ pub fn provide(providers: &mut Providers) {
|
|||
/// (constructing this map requires touching the entire crate).
|
||||
#[derive(Clone, Debug, Default, HashStable)]
|
||||
pub struct CrateInherentImpls {
|
||||
pub inherent_impls: LocalDefIdMap<Vec<DefId>>,
|
||||
pub incoherent_impls: UnordMap<SimplifiedType, Vec<LocalDefId>>,
|
||||
pub inherent_impls: FxIndexMap<LocalDefId, Vec<DefId>>,
|
||||
pub incoherent_impls: FxIndexMap<SimplifiedType, Vec<LocalDefId>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, HashStable)]
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
use crate::traits::specialization_graph;
|
||||
use crate::ty::fast_reject::{self, SimplifiedType, TreatParams};
|
||||
use crate::ty::{Ident, Ty, TyCtxt};
|
||||
use hir::def_id::LOCAL_CRATE;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use std::iter;
|
||||
use tracing::debug;
|
||||
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::def_id::LOCAL_CRATE;
|
||||
use rustc_macros::{Decodable, Encodable, HashStable};
|
||||
|
||||
use crate::query::LocalCrate;
|
||||
use crate::traits::specialization_graph;
|
||||
use crate::ty::fast_reject::{self, SimplifiedType, TreatParams};
|
||||
use crate::ty::{Ident, Ty, TyCtxt};
|
||||
|
||||
/// A trait's definition with type information.
|
||||
#[derive(HashStable, Encodable, Decodable)]
|
||||
pub struct TraitDef {
|
||||
|
@ -274,3 +277,27 @@ pub(super) fn incoherent_impls_provider(
|
|||
|
||||
Ok(tcx.arena.alloc_slice(&impls))
|
||||
}
|
||||
|
||||
pub(super) fn traits_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> &[DefId] {
|
||||
let mut traits = Vec::new();
|
||||
for id in tcx.hir().items() {
|
||||
if matches!(tcx.def_kind(id.owner_id), DefKind::Trait | DefKind::TraitAlias) {
|
||||
traits.push(id.owner_id.to_def_id())
|
||||
}
|
||||
}
|
||||
|
||||
tcx.arena.alloc_slice(&traits)
|
||||
}
|
||||
|
||||
pub(super) fn trait_impls_in_crate_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> &[DefId] {
|
||||
let mut trait_impls = Vec::new();
|
||||
for id in tcx.hir().items() {
|
||||
if matches!(tcx.def_kind(id.owner_id), DefKind::Impl { .. })
|
||||
&& tcx.impl_trait_ref(id.owner_id).is_some()
|
||||
{
|
||||
trait_impls.push(id.owner_id.to_def_id())
|
||||
}
|
||||
}
|
||||
|
||||
tcx.arena.alloc_slice(&trait_impls)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue