bool
TypeCheckBase::query_type (HirId reference, TyTy::BaseType **result)
{
+ if (context->query_in_progress (reference))
+ return false;
+
if (context->lookup_type (reference, result))
return true;
+ context->insert_query (reference);
+
HIR::Item *item = mappings->lookup_hir_item (reference);
if (item != nullptr)
{
rust_debug_loc (item->get_locus (), "resolved item {%u} to", reference);
*result = TypeCheckItem::Resolve (*item);
+ context->query_completed (reference);
return true;
}
reference);
*result = TypeCheckItem::ResolveImplItem (*impl_block, *impl_item);
+ context->query_completed (reference);
return true;
}
if (found_impl_block_type)
{
*result = TypeCheckItem::ResolveImplBlockSelf (*impl_block_by_type);
+ context->query_completed (reference);
return true;
}
rust_assert (block != nullptr);
*result = TypeCheckTopLevelExternItem::Resolve (extern_item, *block);
+ context->query_completed (reference);
return true;
}
Location possible_locus = mappings->lookup_location (reference);
rust_debug_loc (possible_locus, "query system failed to resolve: [%u]",
reference);
+ context->query_completed (reference);
return false;
}
return true;
}
+ void insert_query (HirId id) { querys_in_progress.insert (id); }
+
+ void query_completed (HirId id) { querys_in_progress.erase (id); }
+
+ bool query_in_progress (HirId id) const
+ {
+ return querys_in_progress.find (id) != querys_in_progress.end ();
+ }
+
private:
TypeCheckContext ();
// predicates
std::map<HirId, TyTy::TypeBoundPredicate> predicates;
+
+ // query context lookups
+ std::set<HirId> querys_in_progress;
};
class TypeResolution
if (!impl->has_trait_ref ())
return true;
- TyTy::BaseType *impl_type = TypeCheckItem::ResolveImplBlockSelf (*impl);
- if (impl_type->get_kind () == TyTy::TypeKind::ERROR)
+ HirId impl_ty_id = impl->get_type ()->get_mappings ().get_hirid ();
+ TyTy::BaseType *impl_type = nullptr;
+ if (!query_type (impl_ty_id, &impl_type))
return true;
if (!receiver->can_eq (impl_type, false))