From patchwork Tue Feb 21 12:02:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60048 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1843153wrn; Tue, 21 Feb 2023 04:51:47 -0800 (PST) X-Google-Smtp-Source: AK7set98lk193+XV0DYmTOMcCYBlI76O0oImMwsSCZxcpwxoVD3OkNFk29yEmAaSjyDsHyxZrEC4 X-Received: by 2002:a17:906:2412:b0:8b1:76dd:f5ef with SMTP id z18-20020a170906241200b008b176ddf5efmr15277531eja.5.1676983907234; Tue, 21 Feb 2023 04:51:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983907; cv=none; d=google.com; s=arc-20160816; b=wvUqjBdTZMXCwv6AfmlwZqQvH5EwUh9Bgb+pEA8LhTVNZ8TI/HrAyY5tggtr48ajig 51ZOIgqAMfTra8qfS36QCsoIxeLOJAlsqORuD8Ky3X141XH+ibyZPjyPZO3bkBurBiGZ UhKxQ4dP4TDN2XCGkaSBjeBV8W7NEpI+YVMQqG7sr3y8ULsgusKRYwDSsRLFfh0HqXo5 3jwk8xoZ0nMpLtItd4Rf/WSWDh/iHVWhXPk8TDvY9rPqrKY3piocQ3ZNzfXFlt9ITCnD Qc2svYlQCysY7ghJCUm4TL69L+dhZrmmytWgTlrq1ZYZq51hdh/vxNBdsnsPJTcDnfmT B9sQ== 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=yZlZt4j9P/smfbN3QvZnPuZ4v0SL3o91p7g0NzW0OHQ=; b=P2CM4BQUy7PyOUwv8AeUpPRVK8v9KlaIoMZOeDxi0WYLZea88/IS0uPzvcq51CorB9 1bhGd8O19elZsPdmtIY4c8j4AVNrebDcoAtHEGqrYmpgDtjnhSOWuki8JdpaWiGJwVK1 7t0ukMRp+1WZTi6oOGvwcGkPAMHHXo5xwMvUZNFpWUlhuUaPMxJQPNw4tPX9/kkVQelR w3Luha0tXp7uq+AaO/mdg1WCk0MpPiLapLDhVcrx5/Mwv4zVIAZhYw9dzqCS86jPmhmL n5VmDbGycWJPlKbNY2UluvwAPdwft3VXgLDcJlL4WlmMoUupfY6+zE4LhR3zG/DgImfP fOMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=VxIm8foz; 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 x2-20020aa7d382000000b004accf2c84bdsi3550353edq.604.2023.02.21.04.51.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:51:47 -0800 (PST) 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=VxIm8foz; 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 4EEA239137E2 for ; Tue, 21 Feb 2023 12:17:33 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 3694B3888816 for ; Tue, 21 Feb 2023 12:04:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3694B3888816 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-x42b.google.com with SMTP id l1so3888165wry.10 for ; Tue, 21 Feb 2023 04:04:38 -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=yZlZt4j9P/smfbN3QvZnPuZ4v0SL3o91p7g0NzW0OHQ=; b=VxIm8foz/BLDJcnVaTwAEtz1RieZftWjdEVblkEoMUfohcSTZfGLPbPG/CNoU2HxDh ddfnfWupxWfbEch9m/+UIMqMNRu4njWXsyF3UkqfYwXARe46D8gufpDolG38iIet4tVW tw+Rje8L3gytqIBiCm1C6HpVFUgdezEMXTaoFjJAVjJ+/1lhE6TZmIci05/Ow3BOipZD 5p//l6ztL7J8WD/ra+m8zdjgNQmJhoWgupxJ+6w/JiRoGiN8reCek77l/cZqpJJWEJVX Op63nHE5Sa4MzX9Vhe6ZU631jdYLZZJCs+KnKnk1+eRNA/7XR28YuTKwIl1SscW66Hkp x2bw== 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=yZlZt4j9P/smfbN3QvZnPuZ4v0SL3o91p7g0NzW0OHQ=; b=G5wCCukd9pIUZhJrD0QRSQ1KdO8WpXTNiHrOQ0YUZdZupvW0qvEjX0oW6slcNEp9Ir IvJCtJmMw1FDSa64pMviUpJmb8yNXO3PwQrotxzoHcEIk7J7E/cpQx3htLt4C+l8HgwB rbfFhwvNrsKWlkl7RCvTkErtsYp9vdb0LYF5ofTnn+OId6EoRrS7WByBTbc7NAfh/uE9 EUAYxwpOz12az6XNsgE1Pj9iqtvQucXsr43JG0yO3kOIu6OfSmAmBXAV6eyN60SWBAAC JHm/bvPqt1NeyuphLghWH90TV4EN5jnPdTKrkqSNOlgRUFhm7BoS5RKQ8x+RAMvZoiAv yq4A== X-Gm-Message-State: AO0yUKUW5xumS7OztzK4wqmBPiJHOEbjuLNFIhV8cpzQjmQQbPPs5epH ZfrmSuPtlA4lysoGzIfhJZvrD3s2SsNCoGpN9w== X-Received: by 2002:adf:f208:0:b0:2c5:4660:2892 with SMTP id p8-20020adff208000000b002c546602892mr2700393wro.59.1676981077569; Tue, 21 Feb 2023 04:04:37 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id c15-20020adffb4f000000b002c55b0e6ef1sm5013811wrs.4.2023.02.21.04.04.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:37 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 093/103] gccrs: Get rid of make builtin macro Date: Tue, 21 Feb 2023 13:02:23 +0100 Message-Id: <20230221120230.596966-94-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.7 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?1758445077225670050?= X-GMAIL-MSGID: =?utf-8?q?1758445077225670050?= From: Philip Herron This macro is a mess and a helper method is much better for this case. gcc/rust/ChangeLog: * resolve/rust-name-resolver.cc (MKBUILTIN_TYPE): Remove macro. (Rib::Rib): Remove `mappings` field. (Resolver::generate_builtins): Use `setup_builtin` instead of macro. (Resolver::setup_builtin): New function. * resolve/rust-name-resolver.h: Declare `setup_builtin`, add FIXME comment. --- gcc/rust/resolve/rust-name-resolver.cc | 87 +++++++++++++------------- gcc/rust/resolve/rust-name-resolver.h | 7 ++- 2 files changed, 46 insertions(+), 48 deletions(-) diff --git a/gcc/rust/resolve/rust-name-resolver.cc b/gcc/rust/resolve/rust-name-resolver.cc index b94713d3c30..cc1ec2b9dc7 100644 --- a/gcc/rust/resolve/rust-name-resolver.cc +++ b/gcc/rust/resolve/rust-name-resolver.cc @@ -19,40 +19,17 @@ #include "rust-name-resolver.h" #include "rust-ast-full.h" -#define MKBUILTIN_TYPE(_X, _R, _TY) \ - do \ - { \ - AST::PathIdentSegment seg (_X, Linemap::predeclared_location ()); \ - auto typePath = ::std::unique_ptr ( \ - new AST::TypePathSegment (::std::move (seg), false, \ - Linemap::predeclared_location ())); \ - ::std::vector< ::std::unique_ptr > segs; \ - segs.push_back (::std::move (typePath)); \ - auto builtin_type \ - = new AST::TypePath (::std::move (segs), \ - Linemap::predeclared_location (), false); \ - _R.push_back (builtin_type); \ - tyctx->insert_builtin (_TY->get_ref (), builtin_type->get_node_id (), \ - _TY); \ - mappings->insert_node_to_hir (builtin_type->get_node_id (), \ - _TY->get_ref ()); \ - mappings->insert_canonical_path ( \ - builtin_type->get_node_id (), \ - CanonicalPath::new_seg (builtin_type->get_node_id (), _X)); \ - } \ - while (0) - namespace Rust { namespace Resolver { Rib::Rib (CrateNum crateNum, NodeId node_id) - : crate_num (crateNum), node_id (node_id), - mappings (Analysis::Mappings::get ()) + : crate_num (crateNum), node_id (node_id) {} void Rib::insert_name ( const CanonicalPath &path, NodeId id, Location locus, bool shadow, + std::function dup_cb) { auto it = path_mappings.find (path); @@ -69,8 +46,8 @@ Rib::insert_name ( } path_mappings[path] = id; - reverse_path_mappings.insert (std::pair (id, path)); - decls_within_rib.insert (std::pair (id, locus)); + reverse_path_mappings.insert ({id, path}); + decls_within_rib.insert ({id, locus}); references[id] = {}; } @@ -387,24 +364,24 @@ Resolver::generate_builtins () auto str = new TyTy::StrType (mappings->get_next_hir_id ()); auto never = new TyTy::NeverType (mappings->get_next_hir_id ()); - MKBUILTIN_TYPE ("u8", builtins, u8); - MKBUILTIN_TYPE ("u16", builtins, u16); - MKBUILTIN_TYPE ("u32", builtins, u32); - MKBUILTIN_TYPE ("u64", builtins, u64); - MKBUILTIN_TYPE ("u128", builtins, u128); - MKBUILTIN_TYPE ("i8", builtins, i8); - MKBUILTIN_TYPE ("i16", builtins, i16); - MKBUILTIN_TYPE ("i32", builtins, i32); - MKBUILTIN_TYPE ("i64", builtins, i64); - MKBUILTIN_TYPE ("i128", builtins, i128); - MKBUILTIN_TYPE ("bool", builtins, rbool); - MKBUILTIN_TYPE ("f32", builtins, f32); - MKBUILTIN_TYPE ("f64", builtins, f64); - MKBUILTIN_TYPE ("usize", builtins, usize); - MKBUILTIN_TYPE ("isize", builtins, isize); - MKBUILTIN_TYPE ("char", builtins, char_tyty); - MKBUILTIN_TYPE ("str", builtins, str); - MKBUILTIN_TYPE ("!", builtins, never); + setup_builtin ("u8", u8); + setup_builtin ("u16", u16); + setup_builtin ("u32", u32); + setup_builtin ("u64", u64); + setup_builtin ("u128", u128); + setup_builtin ("i8", i8); + setup_builtin ("i16", i16); + setup_builtin ("i32", i32); + setup_builtin ("i64", i64); + setup_builtin ("i128", i128); + setup_builtin ("bool", rbool); + setup_builtin ("f32", f32); + setup_builtin ("f64", f64); + setup_builtin ("usize", usize); + setup_builtin ("isize", isize); + setup_builtin ("char", char_tyty); + setup_builtin ("str", str); + setup_builtin ("!", never); // unit type () TyTy::TupleType *unit_tyty @@ -418,6 +395,26 @@ Resolver::generate_builtins () set_unit_type_node_id (unit_type->get_node_id ()); } +void +Resolver::setup_builtin (const std::string &name, TyTy::BaseType *tyty) +{ + AST::PathIdentSegment seg (name, Linemap::predeclared_location ()); + auto typePath = ::std::unique_ptr ( + new AST::TypePathSegment (::std::move (seg), false, + Linemap::predeclared_location ())); + ::std::vector< ::std::unique_ptr > segs; + segs.push_back (::std::move (typePath)); + auto builtin_type + = new AST::TypePath (::std::move (segs), Linemap::predeclared_location (), + false); + builtins.push_back (builtin_type); + tyctx->insert_builtin (tyty->get_ref (), builtin_type->get_node_id (), tyty); + mappings->insert_node_to_hir (builtin_type->get_node_id (), tyty->get_ref ()); + mappings->insert_canonical_path ( + builtin_type->get_node_id (), + CanonicalPath::new_seg (builtin_type->get_node_id (), name)); +} + void Resolver::insert_resolved_name (NodeId refId, NodeId defId) { diff --git a/gcc/rust/resolve/rust-name-resolver.h b/gcc/rust/resolve/rust-name-resolver.h index 302b0de15cc..d2f740e0315 100644 --- a/gcc/rust/resolve/rust-name-resolver.h +++ b/gcc/rust/resolve/rust-name-resolver.h @@ -30,8 +30,9 @@ namespace Resolver { class Rib { public: - // Rust uses local_def_ids assigned by def_collector on the AST - // lets use NodeId instead + // FIXME + // Rust uses local_def_ids assigned by def_collector on the AST. Consider + // moving to a local-def-id Rib (CrateNum crateNum, NodeId node_id); // this takes the relative paths of items within a compilation unit for lookup @@ -59,7 +60,6 @@ private: std::map reverse_path_mappings; std::map decls_within_rib; std::map> references; - Analysis::Mappings *mappings; }; class Scope @@ -172,6 +172,7 @@ private: Resolver (); void generate_builtins (); + void setup_builtin (const std::string &name, TyTy::BaseType *tyty); Analysis::Mappings *mappings; TypeCheckContext *tyctx;