From 687e391bc3a9682b6fe956a2e39a8a3935047158 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 29 Jun 2022 11:56:28 +1000 Subject: [PATCH] Avoid constructing an unnecessary `InferCtxt`. Currently, `search_for_structural_match_violation` constructs an `infcx` from a `tcx` and then only uses the `tcx` within the `infcx`. This is wasteful because `infcx` is a big type. This commit changes it to use the `tcx` directly. When compiling `pest-2.1.3`, this changes the memcpy stats reported by DHAT for a `check full` build from this: ``` 433,008,916 bytes (100%, 99,787.93/Minstr) in 2,148,668 blocks (100%, 495.17/Minstr), avg size 201.52 bytes ``` to this: ``` 101,422,347 bytes (99.98%, 25,243.59/Minstr) in 1,318,407 blocks (99.96%, 328.15/Minstr), avg size 76.93 bytes ``` This translates to a 4.3% reduction in instruction counts. --- .../rustc_trait_selection/src/traits/structural_match.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/structural_match.rs b/compiler/rustc_trait_selection/src/traits/structural_match.rs index 8db1d4cfbe8b..725df69974c9 100644 --- a/compiler/rustc_trait_selection/src/traits/structural_match.rs +++ b/compiler/rustc_trait_selection/src/traits/structural_match.rs @@ -58,10 +58,7 @@ pub fn search_for_structural_match_violation<'tcx>( tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, ) -> Option> { - // FIXME: we should instead pass in an `infcx` from the outside. - tcx.infer_ctxt().enter(|infcx| { - ty.visit_with(&mut Search { tcx: infcx.tcx, span, seen: FxHashSet::default() }).break_value() - }) + ty.visit_with(&mut Search { tcx, span, seen: FxHashSet::default() }).break_value() } /// This method returns true if and only if `adt_ty` itself has been marked as