From 8f1d3a3ffef623cdbecaf80ca6c1924a4758c9c1 Mon Sep 17 00:00:00 2001 From: xonx <119700621+xonx4l@users.noreply.github.com> Date: Fri, 23 Aug 2024 23:16:29 +0530 Subject: [PATCH 1/3] Update mod.rs --- compiler/rustc_middle/src/query/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 75166624f95a4..f64b9dcc0327e 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1809,6 +1809,9 @@ rustc_queries! { separate_provide_extern arena_cache } + query impls_in_crate(_:CrateNum) -> &'tcx [(DefId, Option)] { + desc { "fetching impls in a crate" } + } query stability_implications(_: CrateNum) -> &'tcx UnordMap { arena_cache desc { "calculating the implications between `#[unstable]` features defined in a crate" } From f6d47aa56666456f6803fd242cd4feb653de3d58 Mon Sep 17 00:00:00 2001 From: xonx <119700621+xonx4l@users.noreply.github.com> Date: Fri, 23 Aug 2024 23:58:28 +0530 Subject: [PATCH 2/3] impl for query --- compiler/rustc_hir_analysis/src/lib.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index 291d57f2a176f..80fc6c5e4f201 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -149,6 +149,28 @@ pub fn provide(providers: &mut Providers) { outlives::provide(providers); hir_wf_check::provide(providers); *providers = Providers { + impls_in_crate: |tcx, cnum| { + assert_eq!(cnum , LOCAL_CRATE); + let mut impls = Vec::new(); + for id in tcx.hir().items() { + if let Defkind::Impl = tcx.def_kind(id.owner_id){ + let def_id = id.owner_id.to_def_id(); + let simplified_self_ty = if let Some(trait_ref) = tcx.impl_trait_ref(def_id) { + Some(fast_reject::simplify_type( + tcx, + trait_ref.self_ty(), + TreatParams::AsInfer, + )) + } else { + None + }; + impls.push((def_id, simplified_self_ty)); + } + } + // Keeping the sorting here for now to maintain existing behaviour + impls.sort_by_cached_Key(|&(def_id, _)| tcx.def_path_hash(def_id)); + tcx.arena.alloc_slice(&impls) + }, inherit_sig_for_delegation_item: delegation::inherit_sig_for_delegation_item, ..*providers }; From 5687ca479f83e41a1eff3e98282625e2837b41a5 Mon Sep 17 00:00:00 2001 From: xonx <119700621+xonx4l@users.noreply.github.com> Date: Sat, 24 Aug 2024 00:25:05 +0530 Subject: [PATCH 3/3] Update encoder.rs --- compiler/rustc_metadata/src/rmeta/encoder.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 0d83f8c6c5c93..b34bd91e4467f 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -2002,6 +2002,16 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { let mut trait_impls: FxIndexMap)>> = FxIndexMap::default(); + for (impl_def_id, simplified_self_ty) in tcx.impls_in_crate(LOCAL_CRATE) { + if let Some(trait_ref) = tcx.impl_trait_ref(impl_def_id) { + let trait_ref = trait_ref.subst_identity(); + fx_hash_map + .entry(trait_ref.def_id) + .or_default() + .push((impl_def_id.index, simplified_self_ty)); + } + } + for id in tcx.hir().items() { let DefKind::Impl { of_trait } = tcx.def_kind(id.owner_id) else { continue;