https://gcc.gnu.org/g:2df5b70679bc0ad8216f6ca0bb7a2891baa2c801

commit r17-6269-g2df5b70679bc0ad8216f6ca0bb7a2891baa2c801
Author: Utkarsh Bahuguna <[email protected]>
Date:   Fri Nov 6 01:01:41 2026 +0530

    gccrs: Reuse an impl's self type when probing methods
    
    Method probing resolved the self type of every impl with a matching
    method name again on every probe, generics and bounds included, and
    none of that is ever freed. On core that ran the checker out of memory.
    After the first time the type is already in the context, so hand that
    back.
    
    Fixes Rust-GCC/gccrs#5061
    
    Assisted-by: Claude Opus (Anthropic)
    
    gcc/rust/ChangeLog:
    
            * typecheck/rust-hir-type-check-item.cc
            (TypeCheckItem::ResolveImplBlockSelf): Return the self type from the
            context when it is already there.
    
    Signed-off-by: Utkarsh Bahuguna <[email protected]>

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-item.cc | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc 
b/gcc/rust/typecheck/rust-hir-type-check-item.cc
index 1b974b5cfb37..ad48e17a42de 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-item.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc
@@ -220,6 +220,15 @@ TyTy::BaseType *
 TypeCheckItem::ResolveImplBlockSelf (HIR::ImplBlock &impl_block)
 {
   TypeCheckItem resolver;
+
+  // method probing asks for this on every impl it looks at, and redoing
+  // the generics and bounds each time is what runs core out of memory
+  TyTy::BaseType *self = nullptr;
+  if (resolver.context->lookup_type (
+       impl_block.get_type ().get_mappings ().get_hirid (), &self)
+      && self->get_kind () != TyTy::TypeKind::ERROR)
+    return self;
+
   auto lifetime_pin = resolver.context->push_clean_lifetime_resolver (true);
 
   bool failed_flag = false;

Reply via email to