From patchwork Tue Feb 21 12:00:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59951 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1823974wrn; Tue, 21 Feb 2023 04:05:52 -0800 (PST) X-Google-Smtp-Source: AK7set8NfE69q6gnl8Ss4VjIkyfKOL8iLgb9zYeryLzl4R2/Wq+QxcdVGJhfSz9MsXwcO35Rxzz7 X-Received: by 2002:a17:906:e89:b0:8b2:3eb6:865a with SMTP id p9-20020a1709060e8900b008b23eb6865amr14235793ejf.0.1676981152149; Tue, 21 Feb 2023 04:05:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981152; cv=none; d=google.com; s=arc-20160816; b=nLfO9oLFCTPXip1MiO/2JEPGk8Eyw0RaEc0HWMz3cnayHEQm2L9Kj80dtwlbGUvkyA qHOaKb2k2OvGGD9iFwsQTCbxitlWhsQJ6dWEnvQFpxJoE+WIrs2aob08tietIDfOgvKw Yhp7xtj+ce0WeWtlgzkeezEqIDCaav4c6xG/U+buhkQ39Wm3aGcdT4UNO5Q/7+4YiPcy 8ohP1rPp12XkFgS9cZZQuszyHmuA1JECPdIgkQZ3tnEf4vqqvhQeAmZAhOwYkeGkm1fO zMYyQEVjNuuDRl3YD5MgbqLhjtemVFQXdlnpjqIjbanOqvWO/YGeWEsgwzLn+kO/euS+ F/mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dmarc-filter :delivered-to; bh=TaHQnynFAGUPhIrPRgIWIDffDPDM+dXpBpqe6QOmC68=; b=xDqh1koRla/qMFW+pZ4/d/omokW0l1+t8vk0NvJm8wTIM8qmXzgmUi3sLnOAH04Stb 6oc59ovy9GWMzNA2GuAy6Kqsq9rOFe7sRAMDWOH73i6BGgyiVFVJbd8GyGyLlDmcw0oG ym9EoNL1hJvDzDOuvZk49vgUpH7vpXkjQUIJ4YLTYMP4J0I0WqV3DVjvvPBbNsiuJuZk jiG74JENCaiDGYqmGXHqsjh3fwQJ5CitDwOD0Ha+vwONFFAXdAMnOnPeM6xZuWz+UdFQ 5n5eHif4pVpsikUA/7eRQAi20PaA1tESWpxZUA6jDAd5xofFxjBlmft+ooY+yjJVkAmA FRHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=PAh+22H6; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 29-20020a170906005d00b008b175a492e7si19996861ejg.584.2023.02.21.04.05.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:05:52 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=PAh+22H6; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 13E8B3836E99 for ; Tue, 21 Feb 2023 12:04:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 5F862384F4BF for ; Tue, 21 Feb 2023 12:03:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F862384F4BF 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-x42a.google.com with SMTP id t15so4266116wrz.7 for ; Tue, 21 Feb 2023 04:03:29 -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=VgZXSKtHuTdsjtURY2PPi2UpcF8jw0RgjRx3LLXB0R8qm701/Vf7r87tPeUc3Ki885 ykuByCJWRJG6mqFMVTXbGeTr+uHzUZimNMqxSeq97iBKr01d4xUObAc258hPrN/xlKgr hxnOBl7t+Vm87vVg+1cFXA30OvELr+NA2YHi9UWnV6HkNuZ5C3NwqG7E7nhcS62Ewbdf yevVq6TNtdSyTqFsP3Ta9KqoL9Ar4j0moWjxi5EWQnYCb6HTXhykm5uf4Cbx1nBNyadW NfM0P+Dk6EquWCeDRIe5lJKL/hC841UGAIN/smnBq8Jk3A0Da/HDDeJ2qy8gj/ggLDb9 GTmQ== X-Gm-Message-State: AO0yUKUikTNs2eupKVdMnR0kFBuy66gsojAtoS/shqGC5GM6FDjBI2BH 9KR8PiWTXl5jWO0ldQ1ktRZXXNSJwItuM/Kktg== 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> MIME-Version: 1.0 X-Spam-Status: No, score=-14.9 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=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: arthur.cohen@embecosm.com Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758442188532043802?= X-GMAIL-MSGID: =?utf-8?q?1758442188532043802?= 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))