From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 618F83882055 for ; Wed, 5 Apr 2023 14:06:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 618F83882055 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-x331.google.com with SMTP id v6-20020a05600c470600b003f034269c96so11822466wmo.4 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=mh5WefupXZ3GaFQSf4pLEXEl3EqIbuU2C5ZqXq27YNLLw3YbSFja/PK5+BM2XZ8EGW FKYsGX3wuLexrDawqWOd7FS/4Y0v6X7KoDw2yFa/dEGgTJT2dc37mOoMkaNhLcgN5wj2 k00ed1nfvk8cO2UyKEG+6iMiBo4DSHJNkMrfbdg/cwVS1+A4sWNpLzGQYQchZayet5mf 5+buCXswcPiKX8L4SSYMA1PGIWP0kF70lHp+iJxuGH57iHDj5n/t1BAIFrInoWi8UzIS 7qy4AEO57RiGXMzasHvEziQYRCdusqCc7A6+b5lXIp16MCbXRwmVtAGDFT+LTLtIoLfY luTw== X-Gm-Message-State: AAQBX9fQJ/uDqSk72FD18Ga5W1XpiqoCDpGbIOrnYyA8K1RuufLKDTSi aTvYcLe1w3M5C0c5yu5iE78a/oilJyKn51sUzA== X-Google-Smtp-Source: AKy350bB2UeLtweYEp7yaQQWBqHjAO5F6jk4oFdlZrWb7hyWq/3pu85iHe2C9vm0R9URYf9wOm798Q== 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> Reply-To: arthur.cohen@embecosm.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.5 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=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 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 -- 2.40.0