From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id E91BA3851C20 for ; Tue, 21 Feb 2023 12:03:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E91BA3851C20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wr1-x42c.google.com with SMTP id o4so4163132wrs.4 for ; Tue, 21 Feb 2023 04:03:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=TaHQnynFAGUPhIrPRgIWIDffDPDM+dXpBpqe6QOmC68=; b=PAh+22H6pvgQvrHolCR98Ooeu1N98+3Pzk+fJjAGzIiLiHSUkaze2l73Bv6vDGX64L ryQUeYCBwUZIiLhNk8v0Qb53rM5CzYlkcximnu58VtjlDD0e/gCv7IcZPOc2Hs+fGZmQ OC2STGubJvJ1HpwHDN/9OyKfrwzEWE5/WGw+Rz3XmwvJiB5O+h0gGpgXyeHqcYRwsq2E ptcxoANzVagiyzH/MnnsqHb/l5AeFWs33Ru83zSI3SEfBV3Fs+mui2om9BLSaVqvyg5V YDHgCx8C1ddEO7UdOLpmB1KiIojpjzg5VRsa2LKAnjZcIRjZZwjBEWK7phLBgSLmVBlO vppQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=TaHQnynFAGUPhIrPRgIWIDffDPDM+dXpBpqe6QOmC68=; b=X8rgw0ltX9dtSSTMr4ocrXdsqYRZu8LTSbK++U9R5WzpDHFLs0vuZYKq3dKiX6zhyu Na5U1qczigxgBZmcrSowgD9qdbQrHaYeDCe6eNQi4520zkSA2Kc6TS4diuajrmqkiXWn peSYb8xRwNym98MKLtt9iVkSxRP09huHfeqssLn0gcQK3HiuYkTL5HPMKdsbGLcBiwnG KRJOSIRbH2vVQDeb32MeiIpZoKGC+DGFvO5nFKvPB5AozVNCrV3vNSaLP1AOy74zTSZU VTeF+e8ZjDDCe+ZKq44K9hTzpKDtbN6BdUXmOHjevvG0ZJ8x9CUmUXbUTZjgjGioDRnL LBQA== X-Gm-Message-State: AO0yUKVX/OLAK7gUHEmhFog8/qD74hDeOjOztiZ4kg+SMjffDKwy6Jop iruDWpQ5Fubtb7GX/AikmNJl X-Google-Smtp-Source: AK7set+sGMbU4ZNdxW0Z+dx3KC+tvZ0RvIQ4I7rXmsx/FTsvFgB3yrR8g1RbSiToHOloybi5CTRObQ== X-Received: by 2002:a5d:458a:0:b0:2c5:5ed5:2e6a with SMTP id p10-20020a5d458a000000b002c55ed52e6amr3120890wrq.5.1676981007719; Tue, 21 Feb 2023 04:03:27 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id c15-20020adffb4f000000b002c55b0e6ef1sm5013811wrs.4.2023.02.21.04.03.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:26 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 004/103] gccrs: Add catch for recusive type queries Date: Tue, 21 Feb 2023 13:00:54 +0100 Message-Id: <20230221120230.596966-5-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230221120230.596966-1-arthur.cohen@embecosm.com> References: <20230221120230.596966-1-arthur.cohen@embecosm.com> Reply-To: arthur.cohen@embecosm.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: Philip Herron When we have a type query where by generic substitution occurs we can hit the case where we need to Probe the bounds of the substited item to determine whether the the bounds are compatible this can cause us to end up querying the same type recursively. Fixes #1550 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::query_type): Check for recursive queries. * typecheck/rust-hir-type-check.h: New functions: `query_completed`, `query_in_progress`, `insert_query`. * typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::scan): Use `query_type` API. --- gcc/rust/typecheck/rust-hir-type-check-base.cc | 10 ++++++++++ gcc/rust/typecheck/rust-hir-type-check.h | 12 ++++++++++++ gcc/rust/typecheck/rust-tyty-bounds.cc | 5 +++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc b/gcc/rust/typecheck/rust-hir-type-check-base.cc index cf496d3eb19..85826aec8fe 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-base.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc @@ -495,14 +495,20 @@ TypeCheckBase::resolve_generic_params ( 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; } @@ -520,6 +526,7 @@ TypeCheckBase::query_type (HirId reference, TyTy::BaseType **result) reference); *result = TypeCheckItem::ResolveImplItem (*impl_block, *impl_item); + context->query_completed (reference); return true; } @@ -530,6 +537,7 @@ TypeCheckBase::query_type (HirId reference, TyTy::BaseType **result) if (found_impl_block_type) { *result = TypeCheckItem::ResolveImplBlockSelf (*impl_block_by_type); + context->query_completed (reference); return true; } @@ -544,6 +552,7 @@ TypeCheckBase::query_type (HirId reference, TyTy::BaseType **result) rust_assert (block != nullptr); *result = TypeCheckTopLevelExternItem::Resolve (extern_item, *block); + context->query_completed (reference); return true; } @@ -551,6 +560,7 @@ TypeCheckBase::query_type (HirId reference, TyTy::BaseType **result) 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; } diff --git a/gcc/rust/typecheck/rust-hir-type-check.h b/gcc/rust/typecheck/rust-hir-type-check.h index 3e9c9c4d21a..a1dd8052246 100644 --- a/gcc/rust/typecheck/rust-hir-type-check.h +++ b/gcc/rust/typecheck/rust-hir-type-check.h @@ -372,6 +372,15 @@ public: 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 (); @@ -406,6 +415,9 @@ private: // predicates std::map predicates; + + // query context lookups + std::set querys_in_progress; }; class TypeResolution diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc b/gcc/rust/typecheck/rust-tyty-bounds.cc index 5b5ff751e2b..1a2ed3b7422 100644 --- a/gcc/rust/typecheck/rust-tyty-bounds.cc +++ b/gcc/rust/typecheck/rust-tyty-bounds.cc @@ -34,8 +34,9 @@ TypeBoundsProbe::scan () 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)) -- 2.39.1