From: Utkarsh Bahuguna <[email protected]>

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]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/Rust-GCC/gccrs/commit/7b66227880aec8b1fdcb4b17086ea41c99f20629

The commit has been mentioned in the following issue(s):
 - Rust-GCC/gccrs#5061: https://github.com/Rust-GCC/gccrs/issues/5061

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/5062

 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 1b974b5cf..ad48e17a4 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;
-- 
2.56.0

Reply via email to