From patchwork Wed Apr 5 14:03:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 79729 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp367496vqo; Wed, 5 Apr 2023 07:55:05 -0700 (PDT) X-Google-Smtp-Source: AKy350YTNoPAKSoZDRQvaL4Jd8CEnzqMLmDaZAhVxrI7xSHnzRsPuAjZ5Qu+dJQVXYjmq9EUUPeH X-Received: by 2002:a17:906:bfc9:b0:93d:b767:9fea with SMTP id us9-20020a170906bfc900b0093db7679feamr3328601ejb.31.1680706505452; Wed, 05 Apr 2023 07:55:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706505; cv=none; d=google.com; s=arc-20160816; b=kgc80QfcAZK89oSGlE85VhFzrR0GMBbs3Jpz6yqn9CX+Q6dAcgU1LlltsUZDznvAzq r2HF+kJkn3ajoMXqQeIjH3e4vYC/OjoSgnUJJFeRzLkyTbw47qdhRAP0Ma4trBSg65/O btkTL9nuBaVIOhO0lDyslDO6jFiiQ+zSm587nRxe/SHszn3gqkxv1q2m3NMXotiyBWlL jFezMuLxt8PShXuPZ5LgzNXRHxGcLX2qVQjToTE0sKIc95grvO/H4tykSoL4aUgaLkLU ByATeEYMU/RcbVyQP162f1riAgp+aqcg2RSpI2/vFYnfM6ZotTQ3D20eUfzv1J2g/14M NHpw== 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=pCfVERjAiIkTnxQujMkOHgn7E1ET95+MyREJa4QaQhE=; b=mlNF40k4h1G5pKaXIdEQY0KafvECG+VD78RqV/A1xn7rtZ3hz7arPT6uKU0Ij0RyN2 obQoBh6LeLidwfrpgH0Nf9Yy26nqHs3kl5OKJDhFL3hWoOec++XbWWZGNfzKGxlGGoBW 2NR37vGh8X+0XLzjYv+RtL15Ek+1fA2vUbEg2MO3QjGZ12o4prQELV4ENa8E9+xeH3ME IJOlUWPToKk9iUiPDt7e7WH4nGufc7at83UWMCNbVqT3Ut46u7VMFOl3QPMRLlvLhE4y eKm4CraW8dx+98+X8GoiXTxK5C6Mc/9ATqDux35+Gdvw689CXSc3/gWRD3Pj5aYT0TBt vI6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=JiI41H70; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id n7-20020aa7d047000000b004fd18a8023asi2418523edo.495.2023.04.05.07.55.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:55:05 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=JiI41H70; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 7BF923870886 for ; Wed, 5 Apr 2023 14:20:27 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id AF42A388206C for ; Wed, 5 Apr 2023 14:06:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AF42A388206C 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-wm1-x336.google.com with SMTP id m8so10053534wmq.5 for ; Wed, 05 Apr 2023 07:06:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703580; 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=pCfVERjAiIkTnxQujMkOHgn7E1ET95+MyREJa4QaQhE=; b=JiI41H70BT1Im6J0DIjLuVMJpjPwwFZf07wzkwVgGWXBvM5QoBljnORIyTxgbAu1Zh EmYPxyt+jf5Y+EV2IG0x8amhbBpORPuI7rozis66tidqP2FhTYrWtKdhnlNbr6+BsZuX PYIv67wJ4RDCXqhWedyVlwMsK49VSaApxup6MfVnZK8ipMzVv20vAPWTaHNJoRMw04eF hFJsXkDcjradBQUoYAA/rVr3nLopt4hsIB+7+WOGdNKeEjSEW7qKsCghRS0rLFgMMTWH CMd7/WcLYwQmJHlTxt2b/EyU16yl60I35I+ayQntLPSk0i1hOqTzkwpQx8zD3C80LiCx 5juQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703580; 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=pCfVERjAiIkTnxQujMkOHgn7E1ET95+MyREJa4QaQhE=; b=O/npUrixNW+CuB0PaLc8ZqMn7AJyGuUxTO1R5lx9ZEx5ES1H8YQ7Bp/RVbGFJ0fhQt hTx5igeVRfGvN+Hyf4gti0XUPGLhafqdKtawLEorIL1HyZWNavQGOWijoVYvGaceyc9D 1QKgtkgruwP+6SQwXeoxmdYngKMrsy8p7f5i9mz2V4oP+//A6cOzwc+J77bElyl3D8OX Ht0+bE1Ytkup7/qfrtLOeeqYdEq3BZFztjKUVAC1By+MDLYMUb9JAyrxFyx1awMV9Dbn 2ULQAvrGADCa73hKQ3NyrzTwD7Vs3HdSaSi8gUS8zf07GS5gv88HzMKINhCYV0RZ9JmL 088g== X-Gm-Message-State: AAQBX9d9gqZnN/CI2GdZkBWuZIia9sLaKhNa95j7DlSoFaNFoskW6O+c 2+6EMcSQP1dQIhzec8Br/a5czI5w3EZcT76P5g== X-Received: by 2002:a7b:cbd2:0:b0:3f0:5519:9049 with SMTP id n18-20020a7bcbd2000000b003f055199049mr5301601wmi.8.1680703579956; Wed, 05 Apr 2023 07:06:19 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:19 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 73/88] gccrs: Extract query_type from TypeCheckBase to be a simple extern Date: Wed, 5 Apr 2023 16:03:57 +0200 Message-Id: <20230405140411.3016563-74-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405140411.3016563-1-arthur.cohen@embecosm.com> References: <20230405140411.3016563-1-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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?1762348504728078025?= X-GMAIL-MSGID: =?utf-8?q?1762348504728078025?= From: Philip Herron Signed-off-by: Philip Herron gcc/rust/ChangeLog: * Make-lang.in: add new dependancy * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::query_type): refactor * typecheck/rust-hir-type-check-base.h: refactor * typecheck/rust-hir-type-check.h (RUST_HIR_TYPE_CHECK): refactor * typecheck/rust-type-util.cc: New file. * typecheck/rust-type-util.h: New file. --- gcc/rust/Make-lang.in | 1 + .../typecheck/rust-hir-type-check-base.cc | 73 ------------ gcc/rust/typecheck/rust-hir-type-check-base.h | 2 - gcc/rust/typecheck/rust-hir-type-check.h | 1 + gcc/rust/typecheck/rust-type-util.cc | 108 ++++++++++++++++++ gcc/rust/typecheck/rust-type-util.h | 38 ++++++ 6 files changed, 148 insertions(+), 75 deletions(-) create mode 100644 gcc/rust/typecheck/rust-type-util.cc create mode 100644 gcc/rust/typecheck/rust-type-util.h diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index 09bbe450bd5..06f64a01dce 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -134,6 +134,7 @@ GRS_OBJS = \ rust/rust-hir-type-check-implitem.o \ rust/rust-hir-dot-operator.o \ rust/rust-hir-path-probe.o \ + rust/rust-type-util.o \ rust/rust-coercion.o \ rust/rust-casts.o \ rust/rust-unify.o \ diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc b/gcc/rust/typecheck/rust-hir-type-check-base.cc index 6e42b7b7b23..e302e27f4ab 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-base.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc @@ -483,78 +483,5 @@ 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; - } - - HirId parent_impl_id = UNKNOWN_HIRID; - HIR::ImplItem *impl_item - = mappings->lookup_hir_implitem (reference, &parent_impl_id); - if (impl_item != nullptr) - { - HIR::ImplBlock *impl_block - = mappings->lookup_hir_impl_block (parent_impl_id); - rust_assert (impl_block != nullptr); - - // found an impl item - rust_debug_loc (impl_item->get_locus (), "resolved impl-item {%u} to", - reference); - - *result = TypeCheckItem::ResolveImplItem (*impl_block, *impl_item); - context->query_completed (reference); - return true; - } - - // is it an impl_type? - HIR::ImplBlock *impl_block_by_type = nullptr; - bool found_impl_block_type - = mappings->lookup_impl_block_type (reference, &impl_block_by_type); - if (found_impl_block_type) - { - *result = TypeCheckItem::ResolveImplBlockSelf (*impl_block_by_type); - context->query_completed (reference); - return true; - } - - // is it an extern item? - HirId parent_extern_block_id = UNKNOWN_HIRID; - HIR::ExternalItem *extern_item - = mappings->lookup_hir_extern_item (reference, &parent_extern_block_id); - if (extern_item != nullptr) - { - HIR::ExternBlock *block - = mappings->lookup_hir_extern_block (parent_extern_block_id); - rust_assert (block != nullptr); - - *result = TypeCheckTopLevelExternItem::Resolve (extern_item, *block); - context->query_completed (reference); - return true; - } - - // more? - 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; -} - } // namespace Resolver } // namespace Rust diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.h b/gcc/rust/typecheck/rust-hir-type-check-base.h index 335014339f3..b8ff2cf6dc9 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-base.h +++ b/gcc/rust/typecheck/rust-hir-type-check-base.h @@ -69,8 +69,6 @@ protected: const std::vector> &generic_params, std::vector &substitutions); - bool query_type (HirId reference, TyTy::BaseType **result); - Analysis::Mappings *mappings; Resolver *resolver; TypeCheckContext *context; diff --git a/gcc/rust/typecheck/rust-hir-type-check.h b/gcc/rust/typecheck/rust-hir-type-check.h index 512453947a6..6d4b9b8a62f 100644 --- a/gcc/rust/typecheck/rust-hir-type-check.h +++ b/gcc/rust/typecheck/rust-hir-type-check.h @@ -19,6 +19,7 @@ #ifndef RUST_HIR_TYPE_CHECK #define RUST_HIR_TYPE_CHECK +#include "rust-type-util.h" #include "rust-hir-full-decls.h" #include "rust-hir-map.h" #include "rust-tyty.h" diff --git a/gcc/rust/typecheck/rust-type-util.cc b/gcc/rust/typecheck/rust-type-util.cc new file mode 100644 index 00000000000..4e38826686b --- /dev/null +++ b/gcc/rust/typecheck/rust-type-util.cc @@ -0,0 +1,108 @@ +// Copyright (C) 2020-2022 Free Software Foundation, Inc. + +// This file is part of GCC. + +// GCC is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3, or (at your option) any later +// version. + +// GCC is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. + +// You should have received a copy of the GNU General Public License +// along with GCC; see the file COPYING3. If not see +// . + +#include "rust-type-util.h" +#include "rust-diagnostics.h" +#include "rust-hir-type-check.h" +#include "rust-name-resolver.h" +#include "rust-hir-visitor.h" +#include "rust-hir-map.h" +#include "rust-hir-type-check-item.h" +#include "rust-hir-type-check-implitem.h" + +namespace Rust { +namespace Resolver { + +bool +query_type (HirId reference, TyTy::BaseType **result) +{ + Analysis::Mappings *mappings = Analysis::Mappings::get (); + TypeCheckContext *context = TypeCheckContext::get (); + + 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; + } + + HirId parent_impl_id = UNKNOWN_HIRID; + HIR::ImplItem *impl_item + = mappings->lookup_hir_implitem (reference, &parent_impl_id); + if (impl_item != nullptr) + { + HIR::ImplBlock *impl_block + = mappings->lookup_hir_impl_block (parent_impl_id); + rust_assert (impl_block != nullptr); + + // found an impl item + rust_debug_loc (impl_item->get_locus (), "resolved impl-item {%u} to", + reference); + + *result = TypeCheckItem::ResolveImplItem (*impl_block, *impl_item); + context->query_completed (reference); + return true; + } + + // is it an impl_type? + HIR::ImplBlock *impl_block_by_type = nullptr; + bool found_impl_block_type + = mappings->lookup_impl_block_type (reference, &impl_block_by_type); + if (found_impl_block_type) + { + *result = TypeCheckItem::ResolveImplBlockSelf (*impl_block_by_type); + context->query_completed (reference); + return true; + } + + // is it an extern item? + HirId parent_extern_block_id = UNKNOWN_HIRID; + HIR::ExternalItem *extern_item + = mappings->lookup_hir_extern_item (reference, &parent_extern_block_id); + if (extern_item != nullptr) + { + HIR::ExternBlock *block + = mappings->lookup_hir_extern_block (parent_extern_block_id); + rust_assert (block != nullptr); + + *result = TypeCheckTopLevelExternItem::Resolve (extern_item, *block); + context->query_completed (reference); + return true; + } + + // more? + 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; +} + +} // namespace Resolver +} // namespace Rust diff --git a/gcc/rust/typecheck/rust-type-util.h b/gcc/rust/typecheck/rust-type-util.h new file mode 100644 index 00000000000..a3f9efc003b --- /dev/null +++ b/gcc/rust/typecheck/rust-type-util.h @@ -0,0 +1,38 @@ +// Copyright (C) 2020-2022 Free Software Foundation, Inc. + +// This file is part of GCC. + +// GCC is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3, or (at your option) any later +// version. + +// GCC is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. + +// You should have received a copy of the GNU General Public License +// along with GCC; see the file COPYING3. If not see +// . + +#ifndef RUST_TYPE_UTIL +#define RUST_TYPE_UTIL + +#include "rust-mapping-common.h" + +namespace Rust { + +namespace TyTy { +class BaseType; +} + +namespace Resolver { + +extern bool +query_type (HirId reference, TyTy::BaseType **result); + +} // namespace Resolver +} // namespace Rust + +#endif // RUST_TYPE_UTIL