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]>
Tested on x86_64-pc-linux-gnu.
---
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 1b974b5cfb3..ad48e17a42d 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.55.0