From patchwork Tue Feb 21 12:00:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59952 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1824228wrn; Tue, 21 Feb 2023 04:06:27 -0800 (PST) X-Google-Smtp-Source: AK7set+oR1F7coKGYqWDG6bXpgfsLAnXcx3CZPjnqQWYmOmmpzCuWCSuGLl8LCMHvChD9elUWdDn X-Received: by 2002:a05:6402:4d:b0:4ac:b32e:b6f with SMTP id f13-20020a056402004d00b004acb32e0b6fmr5834305edu.23.1676981187363; Tue, 21 Feb 2023 04:06:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981187; cv=none; d=google.com; s=arc-20160816; b=nlOBu6PxDl//glZx5+Bim4RzrCxVGfSdbQGkD18g1P6u2ll2lLj3HGMaZ+DZkKEKvl 7MWq0cHcgmHQvfAltDoJghfHyz709Rz3itp8t5tkqVj6sv1NpvD1GtdGiEZxaDpRHcUr iUyxgjuF0lcXyY91UEJCKxN68v2r3xdIvsIWzwwGEeeSR9Dt0Pm6Ou5HiGoqzVKBBgUb ON7jHPbwtTZ7eNJQhP94uhDdBiuJDxmo6BHMgg7RkewQA27p3+u8L/hK8suLKFmdr6sQ 20ZuHe3Wa0S2ZHxbI/P0MSW5Oki1ZrdHnh3+qXn8UGiC8HCWDIWTZC0Ymq+yW92N8xB6 octg== 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=WvIXClx801McHQjUiEmAWWq+hA6OrhKovqL7/pMpQ6Y=; b=asBR/mg7lpUry7dT6muqBw61PCOo75t/Zq8wF8Robu29raL/0nJkVObU9dv/y9oaLg wGCcoQGZ8JZZM4cbmZnRMvY+U0+rxojUW39zvQh9xUBCecrvKNR1vzfG2fXbyOtvaxEq tVCgNLT7lob1uhJCi7F9g9sjkJzyKPSWcpKL7vDLwg+GID0t/h2ymK4KnkwyOdO9cRNC uhN0JN23tseBzViH62XG/5F9vQqeg4PAmi7D2UKDJxpYK1ShOZfjuhOpeKibUS4psj6/ yTG7abFHHlzENezDRPr/bT3awmUJomvFmiFWZK1Gn+N0CD8DNoMDcMsoG1xy/o5pKzcz hkvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=XaZwtBKb; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u22-20020aa7d0d6000000b004ab44dde183si630889edo.281.2023.02.21.04.06.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:06:27 -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=XaZwtBKb; 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 CBA86383FE22 for ; Tue, 21 Feb 2023 12:04:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 0649A385B516 for ; Tue, 21 Feb 2023 12:03:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0649A385B516 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 j2so3980164wrh.9 for ; Tue, 21 Feb 2023 04:03:14 -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=WvIXClx801McHQjUiEmAWWq+hA6OrhKovqL7/pMpQ6Y=; b=XaZwtBKbN20sOTvkTwLz1cXjGXhvgF4IrGVE8gJT7KoxQ5PNJ+Jz22B6xuIKIPcJjs og7R/19CzZv6fN/qsJpE/5mClW7sBxfg4MyyS3bMmgVhjDB/QbGWs/mwr6dnzzxO2smO FmUxm+8em6HvVufm9WgOuKhs8m8GmnBMPbV+oghIl2mGKlmiRbm8+bSEOeZyLkDyUdrH pYIbxVcBIDQZav8swSKMdEE5cnxwZaD5GUZZpZ80o/Wv3Dz6/tQShNuz947V64nWo7Ov XdTEcQtcfWLo39I9g5FuucUIBJ8fd79NLAx8Gwr2f8JUj8w4sNdrnneM8w6TKYjOMcfX SLhA== 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=WvIXClx801McHQjUiEmAWWq+hA6OrhKovqL7/pMpQ6Y=; b=V+CQAgUwdNZVmnsjBa2HoRa8CLhehAoGsfoE0MVh8pKY1cZb8XbOq4y1hd0GiybQw1 ElihRZuTwejXGEizUA4lJSXIaeJhJsKp3ILp6dBxOFoQJ8KslG225y+PGhSmkAdO/ieN /dh50WdBW9TRN67GADV1Q5wYNWRaViCCPEq5jEqX9ZyAjZrBEMrVS0mrJ+tYN7DIw7fu BCqUYx0BrZ+1JQ5onseovC6Dh8O2mHv6baiTYdbVhpSa+/mtPUA8GpMaaKGGWeCgYYph mR3QknXhLVeq2UqLmXx2QW1hz0xY+kf8Y/HY3hOJcti41gFhC6kBLltAd74DldTULID+ 12fQ== X-Gm-Message-State: AO0yUKWhYZc6SeuiaQzxQIU7BdCObp7DPyfy9DleXczYGNwu56YLMAGt Zf6aOqU3gEdgbTw+mJ095d1M2vqC6iAuEivX/w== X-Received: by 2002:adf:fd07:0:b0:2bf:e39d:c8a7 with SMTP id e7-20020adffd07000000b002bfe39dc8a7mr5437063wrr.44.1676980993438; Tue, 21 Feb 2023 04:03:13 -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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:13 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 001/103] gccrs: Fix missing dead code analysis ICE on local enum definition Date: Tue, 21 Feb 2023 13:00:50 +0100 Message-Id: <20230221120230.596966-2-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?1758442225449610547?= X-GMAIL-MSGID: =?utf-8?q?1758442225449610547?= From: Philip Herron When resolving local enum's within a Block the name resolution info is not at the top of the stack so this patch introduces a new mappings class for miscellaneous name resolutions which can be used during path analaysis. Fixes #1272 gcc/rust/ChangeLog: * resolve/rust-name-resolver.h: Add miscellenaous item mappings. * resolve/rust-name-resolver.cc (Resolver::insert_resolved_misc): Use new mappings. (Resolver::lookup_resolved_misc): Likewise. * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): Adapt function to insert into miscelleanous mappings. * checks/lints/rust-lint-marklive.cc (MarkLive::find_ref_node_id): Allow lookup in miscelleanous mappings in mark-live phase. gcc/testsuite/ChangeLog: * rust/compile/issue-1272.rs: New test. --- gcc/rust/checks/lints/rust-lint-marklive.cc | 7 +++++-- gcc/rust/resolve/rust-name-resolver.cc | 20 +++++++++++++++++++ gcc/rust/resolve/rust-name-resolver.h | 6 ++++++ .../typecheck/rust-hir-type-check-path.cc | 5 +++++ gcc/testsuite/rust/compile/issue-1272.rs | 8 ++++++++ 5 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/rust/compile/issue-1272.rs diff --git a/gcc/rust/checks/lints/rust-lint-marklive.cc b/gcc/rust/checks/lints/rust-lint-marklive.cc index 14115c86f26..c914b549257 100644 --- a/gcc/rust/checks/lints/rust-lint-marklive.cc +++ b/gcc/rust/checks/lints/rust-lint-marklive.cc @@ -273,8 +273,11 @@ MarkLive::find_ref_node_id (NodeId ast_node_id, NodeId &ref_node_id) { if (!resolver->lookup_resolved_name (ast_node_id, &ref_node_id)) { - bool ok = resolver->lookup_resolved_type (ast_node_id, &ref_node_id); - rust_assert (ok); + if (!resolver->lookup_resolved_type (ast_node_id, &ref_node_id)) + { + bool ok = resolver->lookup_resolved_misc (ast_node_id, &ref_node_id); + rust_assert (ok); + } } } diff --git a/gcc/rust/resolve/rust-name-resolver.cc b/gcc/rust/resolve/rust-name-resolver.cc index 77d98d5f364..b94713d3c30 100644 --- a/gcc/rust/resolve/rust-name-resolver.cc +++ b/gcc/rust/resolve/rust-name-resolver.cc @@ -499,5 +499,25 @@ Resolver::lookup_resolved_macro (NodeId refId, NodeId *defId) return true; } +void +Resolver::insert_resolved_misc (NodeId refId, NodeId defId) +{ + auto it = misc_resolved_items.find (refId); + rust_assert (it == misc_resolved_items.end ()); + + misc_resolved_items[refId] = defId; +} + +bool +Resolver::lookup_resolved_misc (NodeId refId, NodeId *defId) +{ + auto it = misc_resolved_items.find (refId); + if (it == misc_resolved_items.end ()) + return false; + + *defId = it->second; + return true; +} + } // namespace Resolver } // namespace Rust diff --git a/gcc/rust/resolve/rust-name-resolver.h b/gcc/rust/resolve/rust-name-resolver.h index 6f4dda06a5c..302b0de15cc 100644 --- a/gcc/rust/resolve/rust-name-resolver.h +++ b/gcc/rust/resolve/rust-name-resolver.h @@ -126,6 +126,9 @@ public: void insert_resolved_macro (NodeId refId, NodeId defId); bool lookup_resolved_macro (NodeId refId, NodeId *defId); + void insert_resolved_misc (NodeId refId, NodeId defId); + bool lookup_resolved_misc (NodeId refId, NodeId *defId); + // proxy for scoping Scope &get_name_scope () { return name_scope; } Scope &get_type_scope () { return type_scope; } @@ -202,6 +205,9 @@ private: std::map resolved_labels; std::map resolved_macros; + // misc + std::map misc_resolved_items; + // keep track of the current module scope ids std::vector current_module_stack; }; diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc index f404ea64bcc..305d73f76f9 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-path.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc @@ -462,6 +462,11 @@ TypeCheckExpr::resolve_segments (NodeId root_resolved_node_id, resolver->insert_resolved_type (expr_mappings.get_nodeid (), resolved_node_id); } + else + { + resolver->insert_resolved_misc (expr_mappings.get_nodeid (), + resolved_node_id); + } infered = tyseg; } diff --git a/gcc/testsuite/rust/compile/issue-1272.rs b/gcc/testsuite/rust/compile/issue-1272.rs new file mode 100644 index 00000000000..08adaaf944b --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-1272.rs @@ -0,0 +1,8 @@ +fn main() -> i32 { + enum E { + X(u8), + } + let _v = E::X(4); + + 0 +} From patchwork Tue Feb 21 12:00:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59957 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1825031wrn; Tue, 21 Feb 2023 04:08:11 -0800 (PST) X-Google-Smtp-Source: AK7set8uMpJ6FK2hvbOGtMNeUpDHKpmATKVv8rCOjF/p8ikjVOvMCKjUJkJagF3LR1MUGkzcltb7 X-Received: by 2002:aa7:cd77:0:b0:4ab:f51:85da with SMTP id ca23-20020aa7cd77000000b004ab0f5185damr5245763edb.3.1676981290939; Tue, 21 Feb 2023 04:08:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981290; cv=none; d=google.com; s=arc-20160816; b=XNdnYft4uTq8Von3z5BmoYDFqf3tOxNnG3XcjZHfR9rTRr4Ep9uVA7X8jv2OZVlZTc 2b4YCL6YsYl3HPki17FA+rCbsKW69M3dGJHlY+M0zvkIKtA1pbp8EVNmU1Mbqgy8T/ku Eh6ASgpui/fZJh+vWhg2/meZezogwuJB5JUr4oh364SZ+N0F6ma8FWWw041f8lFKekFS xWzTRP1lfl/z8JFKrPcr3DF22OjhqYvdIgkP4xcsatNxFIK4oDjfV5e6PjYvPNBkSYSA JRj3M0BBNwUyE4EzukkEkyJs0EmprXH0a50A5FamEX49EAvrGvGUEuznSrFfHoOnoQrL cTyA== 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=9m3/Zgartqb6Ny/0Roc5igEZF2/c2FErqZu5Hq7YMys=; b=ayxvYJxuSapxsznaZnGo/R7itH1Zmg52fjp3hbp7dxPRtajPukrwOAf3eCOMHD/vUi pKsxjkKaYH4og/gfj0NzAv9ONgyQ5xx4v+uULbiBL5b3ULVyrJc1QAnt6SZopWMB+57q 7SLXtMSMoGxOcBxp3ko1VlZcIxsQdyU4uJFdp4HNfGS5V+9Z5EY3KIQwG0fvQ3yl1F4u VqUybmF9UhcCm1qFdFoyPWD41mbolW+OJU0kHTGBx+Orz/DA9cwe3beLqEoWzWlX0ysM PLF6O03E1odiTvOxeV7vo1FCZReImYIkzodMSgMeh/yNTsXHobJhFCFA/458ODd4n+ZZ AMgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=ZlkyxRUT; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id w19-20020aa7da53000000b004ad0463a5edsi18888361eds.553.2023.02.21.04.08.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:08:10 -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=ZlkyxRUT; 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 CFCFC3896C0D for ; Tue, 21 Feb 2023 12:04:57 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id CBEA0384F4A2 for ; Tue, 21 Feb 2023 12:03:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CBEA0384F4A2 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-x433.google.com with SMTP id p8so4289057wrt.12 for ; Tue, 21 Feb 2023 04:03:27 -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=9m3/Zgartqb6Ny/0Roc5igEZF2/c2FErqZu5Hq7YMys=; b=ZlkyxRUT/OvB82l3waBcP8fZ3x46ZeVT+3wJN5ne+PBddjAov+EQnB9Z8uFYNIDI/3 x1D3kQeaWpK56psr7iwAGOUaUDNPXqEM20POANzWooG5IZuGNTjATZdVjOOemhsZlE8x /8xrMcgq1GjQUpwbZCo5dUB3iZQUrrV5k+JAgsW2H0DLKSWHWMunTJ9XqZARjjaMqNk+ gMUnvA/Iu66+vNo7kbrPfvkZzW6TWWy6Ae8M2h+1nPgeQas88Z5n5gd4qGXEg/NDFup/ vMMt5ldMKigDWcLs+BHouLh5dbVV97Eo2LchQWk9pgBVRF7ddDGVh8Sp3H/sPF2HGY21 MGjQ== 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=9m3/Zgartqb6Ny/0Roc5igEZF2/c2FErqZu5Hq7YMys=; b=jnH3fQw/9XtaYifqsXih+VyN7nH4VKVq3lHcbzrR7w/rjSN7TSnN1jnkG94rpoxkSh K18AdFnfuBAS1hPCpLPPemEq8UFUr3aNOwBMehQx+Dq4Wswj903SK1nUEWmoeXSXsOXl r5bma8xxhfnz1eDMhqRnNbBe9xBVoPCnIL8Fuyh7fFfpmyfz9pMddf3y02sjPqtZYhf9 U/JSxk2ic4E1DzLWQBQ+CMsUaIJcDmboNaIaiKZu9yO3ZuG3S/Z5V72yu+DAuXXJngm0 aY5ZEppbRViJcEObI6s4wIOVKe+nqsyWYUldFfYpJ65OEJK4LAmP4bCmj8ArpIV4+ik7 UTqA== X-Gm-Message-State: AO0yUKU2JFng5TkZD5fROcoliR69gwrqyAIAGDaMllD63hAB7x9Hbttc v4l0/GfwS9qXqgqpmssguMNnYmzNlII0PM4CZw== X-Received: by 2002:adf:dd86:0:b0:2c5:a370:df65 with SMTP id x6-20020adfdd86000000b002c5a370df65mr3965670wrl.10.1676981005931; Tue, 21 Feb 2023 04:03:25 -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.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:25 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 002/103] gccrs: visibility: Rename get_public_vis_type -> get_vis_type Date: Tue, 21 Feb 2023 13:00:52 +0100 Message-Id: <20230221120230.596966-3-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.3 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?1758442333716931313?= X-GMAIL-MSGID: =?utf-8?q?1758442333716931313?= From: Arthur Cohen gcc/rust/ChangeLog: * ast/rust-item.h: Rename get_public_vis_type. * hir/rust-ast-lower.cc (translate_visibility): Use new name. --- gcc/rust/ast/rust-item.h | 2 +- gcc/rust/hir/rust-ast-lower.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 93497a391ce..d66dd615319 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -634,7 +634,7 @@ public: : vis_type (vis_type), in_path (std::move (in_path)) {} - VisType get_public_vis_type () const { return vis_type; } + VisType get_vis_type () const { return vis_type; } // Returns whether visibility is in an error state. bool is_error () const diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc index d88c343f9ef..4f1bfd1f0c1 100644 --- a/gcc/rust/hir/rust-ast-lower.cc +++ b/gcc/rust/hir/rust-ast-lower.cc @@ -36,7 +36,7 @@ translate_visibility (const AST::Visibility &vis) if (vis.is_error ()) return Visibility::create_error (); - switch (vis.get_public_vis_type ()) + switch (vis.get_vis_type ()) { case AST::Visibility::PUB: return Visibility (Visibility::VisType::PUBLIC); From patchwork Tue Feb 21 12:00:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59950 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1823764wrn; Tue, 21 Feb 2023 04:05:23 -0800 (PST) X-Google-Smtp-Source: AK7set8nxCgrxG6i50eTbFaDe91t7CkdozHl1fShPTLHDUZ46nepbeagdXzJlOdk6w1Ev7/VWpBs X-Received: by 2002:a17:907:cc97:b0:88f:13f0:4565 with SMTP id up23-20020a170907cc9700b0088f13f04565mr8653916ejc.69.1676981122973; Tue, 21 Feb 2023 04:05:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981122; cv=none; d=google.com; s=arc-20160816; b=FLR+qQJ/H5YXNvCNa/O1JbHk8vgtfFo6cSNR7yWyd3NembEBtMV+/9FggRB/XPOB5z SunOfKLbLX+XDmCKH2m1x3K2FajLdc+9Fb0p+FryN5c1fS9W2VxzvcQzc7tsnbG3Wir1 ro2YxLsJkQn9WUWwazInHPXgvQa4O+84XjHrxMg7S5+itKmFx8tvCXvXSZ4+DdWXbn0P ObNQCDXgtLJwJqsaJJSSVIFIKh6erQm58RLcYld+Lmz6HjMdWOUfm87qLZaV/jBSULXy 4K/MOqAjeobdPqurhT/Z+qZYl1CMLJ0bNy8xWX9+zOQOA4pP/LqQ2+4bSaO2lViRFYCV CBmw== 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=zknrg5IxglaK3KByVVKC5dlYvyS0JUps+E2x3OUOq98=; b=LWjH5SAZ/oMu9g4pOpb5EIEHcD9nVFZRRoaJHCQ5PgboQ4ysoWjLKDOIh+wZnJajUb 2Sc3ULRZaMrFU/r/CFehii0q8WY4cKKtUk8TAFFG4f+QEanNqIiXehL2XY2llSJhuuz+ zmkYgfBwMvJ4YaZvvKte85dv/Z2Hy1KjSVkCyDm2huSvNHBn+Rxsotb6YY+EyhE8Dxqb 81vN1UJpS12CtS6rMsgRO6MRmAC2jF296e5bdE1TgD62Y7rihrHienZPO9J4E1kR3Vos pWP30VRvJEOE8hCj4t5/NsiQsA9aqfhu4Hawp+7o56i6Pch6muZULSmkLmAxrwMPOb8N VEVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=WSBDzgIM; 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 bf22-20020a170906c51600b008b1816e7564si13513333ejb.100.2023.02.21.04.05.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:05:22 -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=WSBDzgIM; 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 4C51E384F493 for ; Tue, 21 Feb 2023 12:03:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 48F85384F4AF for ; Tue, 21 Feb 2023 12:03:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 48F85384F4AF 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-x42e.google.com with SMTP id r7so3989830wrz.6 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=zknrg5IxglaK3KByVVKC5dlYvyS0JUps+E2x3OUOq98=; b=WSBDzgIMG48rPqNfaXYM7djMbx272ZPTwHHEtvVnN96zchJD95ETG8Wtod6jQlNR2V njrYSSnT7JFsicf47W8qC4sXTngNXmWRIjCi+SamVVN3R4ASKBWmxT1EWuHWuG5/ysm+ r3AypLee/olZPjOne8rJQ8aW7/wj0eCRqeOJNJ0nb4SMefpxQTyCEBlaFRWe1Mwji13q HAyPcRl8SWf3iyaBeEvJMyZTFNCqq1qdvL/irLDg50HPUDPWkFjaA+PoZzQ78soaEhgF ZuZ/ci3mUHHI/44vzEqOMf5iCJ/kpthA42tF/5cf7UYyU2ci/8aNCiU2lQdD0lP0bxve DjbA== 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=zknrg5IxglaK3KByVVKC5dlYvyS0JUps+E2x3OUOq98=; b=aTlY8Ypc9bm4LeeIZ6oLOckSb/bb4mSYuBYoSKEesUL4fKLmtAdzflpmT5IKkUJSXE IS6QVHblecet8rkQ7W2i0Go4JD/KG4/tAubn6PqSKS+Di+Zb//xV3IS1sEINPn4MXN2t tBq4Z6wbTNQX+eKPGwPiocaZxE3QWYs0qPAfmJli+Q3Pi8GbG9zppv+vBhNmDypPEbpm aFVBrr/9wMsnJ4YIECrXOg/zEh+woAlmJci3Cpnlza7tUFh4Gp1Lbvu3GmUSChGhw337 jA7Hd/4/thGDuCqIMMCHPOWBquhZmUiTE6azZn8omMJe1fTkFRR81r/V3s9HveczBYi4 nSjA== X-Gm-Message-State: AO0yUKVhWKEVHgHyT8kNezHONkWQ/6c+jE+nVQo8h5WzlW1TQHN1Jvqx Zo+hbH4hL3fNtw3G+GrLQToDYGioxUHbS5v8YA== X-Received: by 2002:a5d:65c5:0:b0:2c5:5a65:799f with SMTP id e5-20020a5d65c5000000b002c55a65799fmr4349916wrw.34.1676981006649; Tue, 21 Feb 2023 04:03:26 -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, Arthur Cohen Subject: [committed 003/103] gccrs: dump: Emit visibility when dumping items Date: Tue, 21 Feb 2023 13:00:53 +0100 Message-Id: <20230221120230.596966-4-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.3 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?1758442157789204990?= X-GMAIL-MSGID: =?utf-8?q?1758442157789204990?= From: Arthur Cohen gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::emit_visibility): New function. (Dump::visit): Call into `emit_visibility`. (Dump::format_function_common): Likewise. * ast/rust-ast-dump.h: Declare `emit_visibility`. --- gcc/rust/ast/rust-ast-dump.cc | 142 +++++++++++++++++++++++++--------- gcc/rust/ast/rust-ast-dump.h | 17 +++- 2 files changed, 123 insertions(+), 36 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 0b2dac9b2ff..3d1b42d70e3 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2023 Free Software Foundation, Inc. +// Copyright (C) 2020-2022 Free Software Foundation, Inc. // This file is part of GCC. @@ -17,6 +17,7 @@ // . #include "rust-ast-dump.h" +#include "rust-diagnostics.h" namespace Rust { namespace AST { @@ -51,7 +52,7 @@ Dump::go (AST::Crate &crate) { stream << indentation; item->accept_vis (*this); - stream << "\n"; + stream << '\n'; } } @@ -72,8 +73,7 @@ Dump::format_function_param (FunctionParam ¶m) void Dump::emit_attrib (const Attribute &attrib) { - stream << "#"; - stream << "["; + stream << "#["; for (size_t i = 0; i < attrib.get_path ().get_segments ().size (); i++) { @@ -108,6 +108,38 @@ Dump::emit_attrib (const Attribute &attrib) stream << "]"; } +void +Dump::emit_visibility (const Visibility &vis) +{ + switch (vis.get_vis_type ()) + { + case Visibility::PUB: + stream << "pub "; + break; + case Visibility::PUB_CRATE: + stream << "pub(crate) "; + break; + case Visibility::PUB_SELF: + stream << "pub(self) "; + break; + case Visibility::PUB_SUPER: + stream << "pub(super) "; + break; + case Visibility::PUB_IN_PATH: + stream << "pub(in " << vis.get_path ().as_string () << ") "; + break; + case Visibility::PRIV: + break; + } +} + +std::ostream & +Dump::emit_indented_string (const std::string &value, + const std::string &comment) +{ + return stream << indentation << value << comment; +} + void Dump::visit (Token &tok) {} @@ -141,7 +173,9 @@ Dump::visit (ConstGenericParam &lifetime_param) // rust-path.h void Dump::visit (PathInExpression &path) -{} +{ + stream << path.as_string (); +} void Dump::visit (TypePathSegment &segment) @@ -163,7 +197,9 @@ Dump::visit (TypePath &path) void Dump::visit (QualifiedPathInExpression &path) -{} +{ + stream << path.as_string (); +} void Dump::visit (QualifiedPathInType &path) @@ -207,53 +243,52 @@ Dump::visit (NegationExpr &expr) void Dump::visit (ArithmeticOrLogicalExpr &expr) { - expr.get_left_expr ()->accept_vis (*this); - stream << " "; - + auto op = ""; switch (expr.get_expr_type ()) { case ArithmeticOrLogicalOperator::ADD: - stream << "+"; + op = "+"; break; case ArithmeticOrLogicalOperator::SUBTRACT: - stream << "-"; + op = "-"; break; case ArithmeticOrLogicalOperator::MULTIPLY: - stream << "*"; + op = "*"; break; case ArithmeticOrLogicalOperator::DIVIDE: - stream << "/"; + op = "/"; break; case ArithmeticOrLogicalOperator::MODULUS: - stream << "%"; + op = "%"; break; case ArithmeticOrLogicalOperator::BITWISE_AND: - stream << "&"; + op = "&"; break; case ArithmeticOrLogicalOperator::BITWISE_OR: - stream << "|"; + op = "|"; break; case ArithmeticOrLogicalOperator::BITWISE_XOR: - stream << "^"; + op = "^"; break; case ArithmeticOrLogicalOperator::LEFT_SHIFT: - stream << "<<"; + op = "<<"; break; case ArithmeticOrLogicalOperator::RIGHT_SHIFT: - stream << ">>"; + op = ">>"; break; } - stream << " "; + expr.get_left_expr ()->accept_vis (*this); + stream << " " << op << " "; expr.get_right_expr ()->accept_vis (*this); } @@ -331,7 +366,23 @@ Dump::visit (StructExprStructBase &expr) void Dump::visit (CallExpr &expr) -{} +{ + expr.get_function_expr ()->accept_vis (*this); + stream << '('; + + indentation.increment (); + + for (auto &arg : expr.get_params ()) + { + stream << '\n' << indentation; + arg->accept_vis (*this); + stream << ','; + } + + indentation.decrement (); + + stream << '\n' << indentation << ')'; +} void Dump::visit (MethodCallExpr &expr) @@ -355,13 +406,14 @@ Dump::visit (BlockExpr &expr) { stream << indentation; stmt->accept_vis (*this); - stream << ";\n"; + stream << "; /* stmt */\n"; } if (expr.has_tail_expr ()) { stream << indentation; expr.get_tail_expr ()->accept_vis (*this); + stream << " /* tail expr */"; } indentation.decrement (); @@ -495,7 +547,10 @@ Dump::visit (TypeBoundWhereClauseItem &item) void Dump::visit (Method &method) { - stream << indentation << "fn " << method.get_method_name () << '('; + // FIXME: Do we really need to dump the indentation here? + stream << indentation; + emit_visibility (method.get_visibility ()); + stream << "fn " << method.get_method_name () << '('; auto &self = method.get_self_param (); stream << self.as_string (); @@ -552,6 +607,7 @@ Dump::visit (UseDeclaration &use_decl) void Dump::visit (Function &function) { + emit_visibility (function.get_visibility ()); stream << "fn " << function.get_function_name (); if (function.has_generics ()) @@ -647,6 +703,7 @@ void Dump::format_function_common (std::unique_ptr &return_type, std::unique_ptr &block) { + // FIXME: This should format the ` fn ( [args] )` as well if (return_type) { stream << "-> "; @@ -656,8 +713,10 @@ Dump::format_function_common (std::unique_ptr &return_type, if (block) { if (return_type) - stream << ' '; - block->accept_vis (*this); + { + stream << ' '; + block->accept_vis (*this); + } } else stream << ";\n"; @@ -685,7 +744,13 @@ void Dump::visit (TraitItemMethod &item) { auto method = item.get_trait_method_decl (); - stream << indentation << "fn " << method.get_identifier () << '('; + + // FIXME: Do we really need to dump the indentation here? + stream << indentation; + + // FIXME: Can we have visibility here? + // emit_visibility (method.get_visibility ()); + stream << "fn " << method.get_identifier () << '('; auto &self = method.get_self_param (); stream << self.as_string (); @@ -725,6 +790,8 @@ Dump::visit (Trait &trait) stream << "\n" << indentation; } + emit_visibility (trait.get_visibility ()); + stream << "trait " << trait.get_identifier (); // Traits actually have an implicit Self thrown at the start so we must expect @@ -784,12 +851,15 @@ Dump::visit (TraitImpl &impl) impl.get_trait_path ().accept_vis (*this); stream << " for "; impl.get_type ()->accept_vis (*this); - stream << " {\n"; + indentation.increment (); for (auto &item : impl.get_impl_items ()) - item->accept_vis (*this); + { + stream << indentation; + item->accept_vis (*this); + } indentation.decrement (); stream << "\n}\n"; @@ -802,6 +872,8 @@ Dump::visit (ExternalStaticItem &item) void Dump::visit (ExternalFunctionItem &function) { + emit_visibility (function.get_visibility ()); + stream << "fn " << function.get_identifier () << '('; for (size_t i = 0; i < function.get_function_params ().size (); i++) @@ -830,11 +902,7 @@ Dump::visit (ExternBlock &block) stream << "extern "; if (block.has_abi ()) - { - stream << "\""; - stream << block.get_abi (); - stream << "\" "; - } + stream << "\"" << block.get_abi () << "\" "; stream << "{\n"; indentation.increment (); @@ -1014,11 +1082,15 @@ Dump::visit (LetStmt &stmt) void Dump::visit (ExprStmtWithoutBlock &stmt) -{} +{ + stmt.get_expr ()->accept_vis (*this); +} void Dump::visit (ExprStmtWithBlock &stmt) -{} +{ + stmt.get_expr ()->accept_vis (*this); +} // rust-type.h void diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h index 955dbc0bebc..a5a99f2b03e 100644 --- a/gcc/rust/ast/rust-ast-dump.h +++ b/gcc/rust/ast/rust-ast-dump.h @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2023 Free Software Foundation, Inc. +// Copyright (C) 2020-2022 Free Software Foundation, Inc. // This file is part of GCC. @@ -80,8 +80,23 @@ private: * Format a function's definition parameter */ void format_function_param (FunctionParam ¶m); + + /** + * Emit an attribute + */ void emit_attrib (const Attribute &attrib); + /** + * Emit an item's visibility + */ + void emit_visibility (const Visibility &vis); + + /** + * Emit an indented string with an optional extra comment + */ + std::ostream &emit_indented_string (const std::string &value, + const std::string &comment = ""); + // rust-ast.h void visit (Token &tok); void visit (DelimTokenTree &delim_tok_tree); 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)) From patchwork Tue Feb 21 12:00:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59971 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1827670wrn; Tue, 21 Feb 2023 04:14:36 -0800 (PST) X-Google-Smtp-Source: AK7set9qUX57KEbsjyyB0feEV3PFlV4ZfJzeCa6ppXAuSOR+iOXQ4Ta3ZxBzv7CL0ZNTMc36a2KU X-Received: by 2002:a17:906:57c6:b0:8b1:fc1a:7d19 with SMTP id u6-20020a17090657c600b008b1fc1a7d19mr14385862ejr.3.1676981676638; Tue, 21 Feb 2023 04:14:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981676; cv=none; d=google.com; s=arc-20160816; b=Ax2ROCHyp7KaM81U59yPD7cVprQDdCZSPoyvpb0HhiS6ydOSuFPAR7h3oo+4tTaBrv XWO8t0s1Xd3vWgoiLhdEyZ9dDcX1E+3yZy8RbPWUAlQBdNAoIBfP8djv9rRwUDeWechJ A+KMMHGMm5Rc6STxQccpPIyF0KzUYYtZV34W41Z734Jw9R1PE4e4TMV6cXnGheBcQyRM alJj0Vmw0iVKxZodkL8fo301IlfE8ZEd3ZY3AgjBbiPQCnVcjMEfAYTX+8FnhrfKUn6N aOsP5x0ybQQd29Q6bwxP0rC0ytVYokPb/ndXcmXgwVrbQ5XJ2ZJ2OhXcVsZw/Hsa3Exx ggUg== 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=dkZNfYo5adB+2p9cQ/FuEDLBDNUVW7F9W4GLQmDwl0s=; b=NyXggzF5IVDIpmCcD5nCiRiXNF5QnAnpy+nMtRYu2hi609e6EPBfuNrGW1EOrkHGHk iU/uJhhDMmgb8x2spW0m+lT46E5Mn1Ld0WiXFLVG/P5XGv56t+Gc8KfO1s8UMQc7Z12d 985kmF0Ef4kimAT9dWgSckDJe+s89GswAmQNHSjJUUddaluTF2OzW5lMiD8mKxbQhRCV TIuck3L7dlTI1S0HEUIxq4m/82G3VTP+yP9Mz1qvD81Gl+ihGWNm50eeb+UDVR8juwW3 qFXRFKgEu13hXPQZLzx5OQvrjqXlV1cUpODHcNpTXb9C2UHe0Y2OTm2w7ExTCs9e0Vlz IC8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=JzF7NeEc; 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 21-20020a170906009500b0088c5e867083si23945830ejc.807.2023.02.21.04.14.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:14:36 -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=JzF7NeEc; 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 78AB5395A466 for ; Tue, 21 Feb 2023 12:07:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 3059E3851AB8 for ; Tue, 21 Feb 2023 12:03:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3059E3851AB8 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-x430.google.com with SMTP id t13so4087804wrv.13 for ; Tue, 21 Feb 2023 04:03:30 -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=dkZNfYo5adB+2p9cQ/FuEDLBDNUVW7F9W4GLQmDwl0s=; b=JzF7NeEccF0w2fIZwF9fzuyZPcXY3OThG5r2rKrIudNFpxWdC81CMMhi0NGB39Wzbo cQ6baAzuESmp+m4x4Krj1dZhs0WhhFeBagdro0/DHoLaME93Tc9J9lIesDgW516GBT3w jNs0EMY+tNTryK+FkQvSkUgSzLQUceUGXMVH6wS7UtX8+03L1aK1rfa06YsJ9k7OQOGR U9qzboofwz/tu1c0ZNYwhPOI/hZqt1TMi6djnlXdK6ZQUUsmOjP/7Z2rKjyqF0IUSx8b L9rTsfGBKQfkAOoabG7xckj94KzDn4W//eXimBxUpjQAoGwa3wVxydRUXP+agLpXyywE e/mA== 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=dkZNfYo5adB+2p9cQ/FuEDLBDNUVW7F9W4GLQmDwl0s=; b=Im83JRFKmGoD2ATUSEUOWRx+LKU8DhTOj7ESQgXrKeIoyZg8z+kWemM5rRMOsr6q9n NBFirJs6i1kgCIiN9aXJD+4JILJtGQH8z2x8bd8wJ2eC4t8qR1cbAYjOkuAnjaVesvG9 VNy222tiw7BqRNOntsD7EZ8Lab32YX829G/pehz3VYjqRKgc/tJ/1TYDhI/xKC69IKBs SvAFhUQSQPW12G/NP1fV6FbxPk0q7KQLQPKXjmSG7Fq8vz8LHttoyc/wzctH6wtKuiKs FWsJT4V03fhjN/CATweLYE3iCJimJlIYi7Pj1l3Vt+oTL58QbdWKNq2Di8gn4Jc/rnDV +87A== X-Gm-Message-State: AO0yUKW03y9X9bAS6JFvqglP5CloGnWCvRaFStngefO/+ewBB5tpBV0p HCLtu7gGNhP2yLPXftxIvt3Dk/llb5TmWB6KUw== X-Received: by 2002:a5d:49c1:0:b0:2c5:5ca4:ef14 with SMTP id t1-20020a5d49c1000000b002c55ca4ef14mr3278998wrs.9.1676981008741; Tue, 21 Feb 2023 04:03:28 -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.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:27 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Faisal Abbas , Faisal Abbas <90.abbasfaisal@gmail.com> Subject: [committed 005/103] gccrs: testing: try loop in const function Date: Tue, 21 Feb 2023 13:00:55 +0100 Message-Id: <20230221120230.596966-6-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?1758442738785378692?= X-GMAIL-MSGID: =?utf-8?q?1758442738785378692?= From: Faisal Abbas Signed-off-by: Faisal Abbas <90.abbasfaisal@gmail.com> gcc/testsuite/ChangeLog: * rust/compile/const9.rs: New test. Signed-off-by: Faisal Abbas --- gcc/testsuite/rust/compile/const9.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 gcc/testsuite/rust/compile/const9.rs diff --git a/gcc/testsuite/rust/compile/const9.rs b/gcc/testsuite/rust/compile/const9.rs new file mode 100644 index 00000000000..e71a62a33b1 --- /dev/null +++ b/gcc/testsuite/rust/compile/const9.rs @@ -0,0 +1,18 @@ +// { dg-options "-w -O0 -fdump-tree-gimple" } +const fn test(mut x: i32) -> i32 { + loop { + if x == 10 { + break; + } + + x = x + 1; + } + return x; +} + +const X: i32 = test(0); + +fn main() { + // { dg-final { scan-tree-dump-times {x = 10} 1 gimple } } + let x = X; +} From patchwork Tue Feb 21 12:00:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59964 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1825857wrn; Tue, 21 Feb 2023 04:10:04 -0800 (PST) X-Google-Smtp-Source: AK7set9wEeNcvBlz0NCFLbXO4IR3NVD19/0AuiI/jMn+2OpDWX8UMX9ay4U6pxsOOm6UziDheth9 X-Received: by 2002:a05:6402:3216:b0:4a3:43c1:8430 with SMTP id g22-20020a056402321600b004a343c18430mr5040083eda.4.1676981404164; Tue, 21 Feb 2023 04:10:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981404; cv=none; d=google.com; s=arc-20160816; b=p0IIGkPs5CVrqh4Uh4S1ML8M6RuZdqMp/QWMvKaaBT6+VeTONP+fLM1mJNM0vcw2fI L5V244nBOANtS05fhjImxd8DxaEZsH6ivNesxaRnrCore43RDl/5EDrYi490ibzZk+iA ylkmvLJmURXOvB2nnTJe7rmVsrCGibP124CAtNvIkDVsdzJm9qckOF7ZfG4RLbPuLAxn GvHN9baDrzA3jF/4bS8TJ8o7Y5fh8s9wj+rBDWQYDk8sAo42Z6z525/zKWp8xB5jsZmr gZQk7wVS/kaothgZ5sYac5J4cecFH/UNCVNhPKqPEuoCbUgcJILFh6cwm1HteJdDpEBT ZfAQ== 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=wVtykWZX9lkBNauDFT/JMu19+rzQAZ+3UNWK/c5HQGc=; b=g2qCZ17gfz2Fyxpj+0pLAKmFe4+mgK8nFjKBeMEMkS1yNWVJPX4aAsPi5G/go7NlAD 8kfuQ0inl+0HttaHHPeHKdVJTlxjEAjx9u0z1e8qnm9Hazcgm/1WlBBAEeJMkCezPFyp xAPUp3G6lCl2aci13Tm/hE3mFSEMm2VU9CaKWVHV7bP3jYFR4/YBYuDhG9oRoEbcff8B fbD8a+oL4QT4FzmowuvL0rfz481tC9pxhPH3/X86VvrpMH5RnwAs9hVqBe4KqNWn0fT0 RRv7VQNvpK+3nOEQzSu6oM6EEWsm8E6rPwii0epf1rUV0XWv1EdIGt7AQVn/tz5dWjeB iKCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=ROVjL1Bv; 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 v15-20020a17090651cf00b008c607dd7ce8si11743743ejk.842.2023.02.21.04.10.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:10:04 -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=ROVjL1Bv; 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 7C58B3850401 for ; Tue, 21 Feb 2023 12:05:36 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id B746C384FB69 for ; Tue, 21 Feb 2023 12:03:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B746C384FB69 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-x42f.google.com with SMTP id p8so4289201wrt.12 for ; Tue, 21 Feb 2023 04:03:30 -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=wVtykWZX9lkBNauDFT/JMu19+rzQAZ+3UNWK/c5HQGc=; b=ROVjL1Bv0RgSguGHReRqtzsB/Uug5P4AR4lJpQOT1kV/zffLVkjwHWUxi+zDCCZrWG UIRGhuZhNWUiXgzdv4/6SzoJ5sOpUSO/IQU8UT93QNgvYyybevIMyHi0uwpurP73+oll L8CWKqdJ+j37RbHwmePS+n1vmB6NLgvq3gwiL5aWGrAUZa6vqRQAeNJXNkDnP3YUlQmx Uo8TWbPX97Y00iQJ5sAiM4qJVqvlY8Jy0/N29SRldAhtaiV8sjRc6FHozyEtTn1Mb3WP A5KgTKiAiwtG1wdCispqdrWfzGn+DB9iz/BaItcTkLH9BglHv7QrJ5oCzYtJ4DeAj4hk wa9Q== 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=wVtykWZX9lkBNauDFT/JMu19+rzQAZ+3UNWK/c5HQGc=; b=Ra60s0aBzXUPAjkFhFKHvt5aQhE1DWVp+8vush/vriM3/XILKYC2p71OKxsTfHNW60 WJRzRl5iL4mJgxPw6e00cB9/4gJP+jWA+Z687RMDZ9SzXzvgEdAbSY5nB8hn69RmVIxi sW6x0BiPz9YRbAGaz0UZBjPvZpHFgDtkgy3ajX3lCMlxE+2GvXrGGoQcjFgfrKqtv1zi gFU8Fvet6rbrNvzpoR+bwKvtRdxbyk56Y0B8NWqpd2m/YqJUnZQhQ8BfcmoDRLRhuJNQ vLSrlLCuDnp01wB9oeZ3Zm8/ki9zSvrXCojjNpX3/SjuwKNv3CXKs4ijMpbGEEqBZiQX WLVw== X-Gm-Message-State: AO0yUKVFAzhrFyiYl/yHcOfPC5vbXcTzBCrW9DjQ8ovjBPt/qTkS+6hC VgG093m5pPe5FzWOpr3/t+bMUcWsxgcUdSJs5Q== X-Received: by 2002:a5d:6f15:0:b0:2c5:51a5:9ef8 with SMTP id ay21-20020a5d6f15000000b002c551a59ef8mr2758553wrb.8.1676981009337; Tue, 21 Feb 2023 04:03:29 -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.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:28 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, David Faust Subject: [committed 006/103] gccrs: ast: dump assignment and compound assignment expr Date: Tue, 21 Feb 2023 13:00:56 +0100 Message-Id: <20230221120230.596966-7-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=ham 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?1758442452745053155?= X-GMAIL-MSGID: =?utf-8?q?1758442452745053155?= From: David Faust gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Dump assignment and compound assignment expressions. --- gcc/rust/ast/rust-ast-dump.cc | 56 +++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 3d1b42d70e3..f3d0e2d9974 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -306,11 +306,63 @@ Dump::visit (TypeCastExpr &expr) void Dump::visit (AssignmentExpr &expr) -{} +{ + expr.visit_lhs (*this); + stream << " = "; + expr.visit_rhs (*this); +} void Dump::visit (CompoundAssignmentExpr &expr) -{} +{ + auto op = ""; + switch (expr.get_expr_type ()) + { + case CompoundAssignmentOperator::ADD: + op = "+"; + break; + + case CompoundAssignmentOperator::SUBTRACT: + op = "-"; + break; + + case CompoundAssignmentOperator::MULTIPLY: + op = "*"; + break; + + case CompoundAssignmentOperator::DIVIDE: + op = "/"; + break; + + case CompoundAssignmentOperator::MODULUS: + op = "%"; + break; + + case CompoundAssignmentOperator::BITWISE_AND: + op = "&"; + break; + + case CompoundAssignmentOperator::BITWISE_OR: + op = "|"; + break; + + case CompoundAssignmentOperator::BITWISE_XOR: + op = "^"; + break; + + case CompoundAssignmentOperator::LEFT_SHIFT: + op = "<<"; + break; + + case CompoundAssignmentOperator::RIGHT_SHIFT: + op = ">>"; + break; + } + + expr.get_left_expr ()->accept_vis (*this); + stream << " " << op << "= "; + expr.get_right_expr ()->accept_vis (*this); +} void Dump::visit (GroupedExpr &expr) From patchwork Tue Feb 21 12:00: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: 59967 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1826557wrn; Tue, 21 Feb 2023 04:11:57 -0800 (PST) X-Google-Smtp-Source: AK7set9tcOO8+Jmik2oKSwHXXFweQIs9GzWjJuDT5Jq1cIvbUPugdgsP2Nz5C4O7UMK9HxJQjQQk X-Received: by 2002:aa7:d752:0:b0:4ac:c29d:5c4a with SMTP id a18-20020aa7d752000000b004acc29d5c4amr4112829eds.29.1676981517234; Tue, 21 Feb 2023 04:11:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981517; cv=none; d=google.com; s=arc-20160816; b=GhBvoixxef5AQqxMoZStbCM4hVqi+Y6a1ouqA05nFqwFXbb1AKrz0G93T+PR8pLrV6 0Azzbu/3jUp/ACLz/KW0dqeMjOlg6nqmRzBTcz34gODjSdzVADkIVF9Lf51lfMzBg0XP rkie5xpEVcoBjI9ZViRb3bWmDGBs/h5KZcxfo4g4RxxuVReuEqcdwIZlm5W6JABSld+w +f4u6pYMQNV3Uzc7/BxSdOVq49R36q6Es/gXGtqXoWAQpqGChNZsyOTrYxbb9J+PRV0Z 3xJML0GFbMCYq5UDmTuLsU+64yPfbhS7yLWlgtNC/sIOriyExNdjBKQPOeb2etHN4k3E YgMw== 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=beoTZAkXMpWXV11eIpUnCzAF3XRmMfF23Y+q6Nr5MCg=; b=qHGPTbPRPZC7VY+cfFZ+nVoxX25SWCusv8rQ6Ia6IFgYESrySRZCcSER5GWibc91j6 ZFm3Nq8TXhZar48ngOYe6dO88ZsMjntl9y3G4PPNaolljpZhRHXCmgEnJaix8L0hikFe 2oUKKdk+lSmSY2bDgO9Lg0VkNySrgSXUIYzgoGK38UJP9XGY1p6a7huKqdVTTWYbLZur lHFWJX/8zUKHKsJOvm/YABG1D/8iVAu45OPimxWowT6TxY+B9t7G4doqjvncDi1C4RXu hubfXsLSg/zsg8avSgEtx+wMvzo/y0m4ZVW2e8YrhETgg4RsgbcxQFOwxN6DJvKkCP7e G9gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=gdOM+D8S; 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 j8-20020a50ed08000000b0048e82d753a3si814592eds.227.2023.02.21.04.11.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:11:57 -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=gdOM+D8S; 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 6F1FA3952512 for ; Tue, 21 Feb 2023 12:06:15 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 C62C33857438 for ; Tue, 21 Feb 2023 12:03:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C62C33857438 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 r7so3990029wrz.6 for ; Tue, 21 Feb 2023 04:03:30 -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=beoTZAkXMpWXV11eIpUnCzAF3XRmMfF23Y+q6Nr5MCg=; b=gdOM+D8Shd7I2ocsMxfamtvhte2Y9m63OqB8Q+uNSVVwF3Js+apmcpTerVw6LrdPAc Cr7WW93AmHWSdj6y0MHIANbmTht8y2E/UbJlnD4VIsHZC4WWh2ZL05/q5VzZQR9zeea0 RD6DXFSFs4X9pNk0Ic11EChVctHXbywYfh91wemCSZ46uvdLYPBZ5+1wJhPrOcgKgMWY /d1HgXe/fjppW/2o+Fk/aILhAXpRou+YYmUQS7ngsiYFSJlG4Aj74YCZXOwOqXOlM9r7 8iZytv/MasVKwxqKa8lJA59dRMQ1P3FIbDefOKNfXnqNq8Ezo8vmr199bRV+ma+frDzs x65w== 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=beoTZAkXMpWXV11eIpUnCzAF3XRmMfF23Y+q6Nr5MCg=; b=M/9AbAQr4mU3fa/V+wOWEyuFwuFDyRgbdjmyqQ1MJFqKBgXU7PQ3odtj+uFvon3jGH ktHu5taUYJo/ZfkCSDqsVVLatnIHfTELIgfzBntgyyxXCrrAF+WnRBvkQQCZwCN06++f hL5in5XVju0QlGy3O/Cdfkj28ih9b3YUQYsl7ZNy6Yqsh/Lnydpz84UGBWlRzWEqZtAF G46PXJrCyE+CDIlwcXFEEgNEXT27FlapfTANbAlYdms3cbxIQHo+2/BFMBQM0Ji2SqBj 2XjW4/NpRtYxXD9acoqhqvJst1MPAxBmmLVouTKZe7qyfugDtO+CDn28zhs69iZHaMs9 v+4A== X-Gm-Message-State: AO0yUKWbflSt+unWRwUG6tQ3E1SMxT6cbSkZJ6Fr/dYYj3FJ2CWymffH fwH5SJsnAm7XFnq7l7vpuPc4V16R5KF81J0dhQ== X-Received: by 2002:a5d:414f:0:b0:2c5:455b:4e8a with SMTP id c15-20020a5d414f000000b002c5455b4e8amr4545089wrq.50.1676981010040; Tue, 21 Feb 2023 04:03:30 -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.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:29 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, David Faust Subject: [committed 007/103] gccrs: ast: dump If expressions Date: Tue, 21 Feb 2023 13:00:57 +0100 Message-Id: <20230221120230.596966-8-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=ham 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?1758442571373041508?= X-GMAIL-MSGID: =?utf-8?q?1758442571373041508?= From: David Faust gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Implement visitor for If expressions. --- gcc/rust/ast/rust-ast-dump.cc | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index f3d0e2d9974..bc4f7a3a5c1 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -534,15 +534,31 @@ Dump::visit (ForLoopExpr &expr) void Dump::visit (IfExpr &expr) -{} +{ + stream << "if "; + expr.vis_if_condition (*this); + expr.vis_if_block (*this); +} void Dump::visit (IfExprConseqElse &expr) -{} +{ + stream << "if "; + expr.vis_if_condition (*this); + expr.vis_if_block (*this); + stream << indentation << "else "; + expr.vis_else_block (*this); +} void Dump::visit (IfExprConseqIf &expr) -{} +{ + stream << "if "; + expr.vis_if_condition (*this); + expr.vis_if_block (*this); + stream << indentation << "else if "; + expr.vis_conseq_if_expr (*this); +} void Dump::visit (IfExprConseqIfLet &expr) From patchwork Tue Feb 21 12:00:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59955 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1824912wrn; Tue, 21 Feb 2023 04:07:56 -0800 (PST) X-Google-Smtp-Source: AK7set9UKJhgwBPkOkC6TkfcrJR7Z9pO60B15MV3NbDQCVD0fhcrcYoqcapHa9Y4jhpPd0W12A5A X-Received: by 2002:a05:6402:b38:b0:4ac:bd6e:9975 with SMTP id bo24-20020a0564020b3800b004acbd6e9975mr4675368edb.20.1676981276265; Tue, 21 Feb 2023 04:07:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981276; cv=none; d=google.com; s=arc-20160816; b=BzbWDbz4Ei7B2DuJRAzs8jliIZUjDpHFRkTg/BhvgQ2W24TzgeaP3IHa+l6zRBPAFK ziZHwSeNZmqQtaQcatGUnXenSBuGCJe3bNkIYSbqR/1MF434ag4+FIY9ZCOSlg7haX4B bisgeYDIu5vZVOVXxifsbRhZ96cJaXV1HAdq+E89l+hX56wXflea3EJsX8nRMZDPg8Al pMP920HJ7bu3tWXK0lVmzoBY1j2DWZgBOqcMfcfX2WqK3JL++in2Mtvznbmew8Myte14 IMTjhjmRrVDUzC5i6Gm9G4L8vJ/pvVTvtDotpPB1PGpOissAjpPH7fePTKL4emOjhm1c VZyg== 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=Wy32g5WnNnlbrMJWBS95j4VbYYgvfyhaBRzC6glmet0=; b=wzXdMMtxVKDiIib83ylWUBiDoiBqLV/GW6IzRNavaz2m3U5w7mhbuMUk98azoaN0iw rG+cZJfCND4jnxjEoGAC+Q8tx2hXGgY+BPiUr/8Xht7pdj5hy90434OvRVTNJcwPv0rr 8Z4WFyqRG06l+YI2neA1TK1SYp2tz/uvYDKiEwHVTYXVCz/mBb/dLYRFSVJRx+/pnVjl qwSfBqLAaHn1FwaboBGmEOWb7OekefstdRWcbGoyfOgApNpX/w6zeW5m44waMKDRkgBw GEg0n0q7QvrPB1g/rqRHuygPizWpAPLUyXJi8129qKXYfKLrmjGy8NJ1bXOUT+bHWoTk QSNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b="Ym/abc/F"; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id g18-20020a056402115200b004acc6cedef7si8383752edw.66.2023.02.21.04.07.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:07:56 -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="Ym/abc/F"; 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 6B7F6388B6AF for ; Tue, 21 Feb 2023 12:04:52 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 2DD16384DD00 for ; Tue, 21 Feb 2023 12:03:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2DD16384DD00 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 z8so3882171wrm.8 for ; Tue, 21 Feb 2023 04:03:32 -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=Wy32g5WnNnlbrMJWBS95j4VbYYgvfyhaBRzC6glmet0=; b=Ym/abc/FN8ZrHVt2HzP8X4TWe/1Pv1fScZYrVFyRFtjgYjshjZKiV7O9lK8Ep7ZqHS foDdeVvMjXw277BYnbxKH6pjvSyE0CKimUOT10rw5ZIfEn5tncX+xF4teZPEcrghx8nA N7fgWLytQ498PFZZdjV33MHLm4QdG7XheQPkI/DmaXxQYyjC2QO829J6E56t8OGiWSGT /qZR1S2ddcOq0fRrG6Dh8pvmFf3smQl1byRzSFAJq4EslNKfk7DWlXvFyK9cW9gSfaa9 iWH6krF7uzqyB3sZiQC5qUzPp1+VpCOB7XdVpP2dDr6ttaRrKnV4Fot+4lnj6IIo1nSs P5rQ== 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=Wy32g5WnNnlbrMJWBS95j4VbYYgvfyhaBRzC6glmet0=; b=gyhJC3hMQDXObQnArhTpx6DlJIm+unRXysTOvJQ2APUnEsZYghQMeQYdTbqoPdfUNM WieWdk50zRtQZ6T/FMVIdTN0EnEf0E+HxrQq5rhfl4pWNrjbE3ei2L3Wae7G01X5keuT AHzZWiko4N4mdv0/jYFZ1p9LbX3aGcsDPhGA1UFsiXtalbgT3/gkevWUXsTh51Msedxz s5NSkO9MDZwiu4rblNivhau955S2XYSUEkEB543o2v7ONAzWUR6QY3+CS6VU0SqiWYmN ygxGqR5YjpbSoJv1/XJ/0n2NV58C5Bv0ZTV8w6YDclleUwtwhi+06je9t1ZZlZFIDexn JBVw== X-Gm-Message-State: AO0yUKX7NBbxCYY/fi0Ht08dTivOQEIL215KSs7FBbaYWvXTYnJwIXOG DfxCtH4KkwrynpE78VQXJCzzIA18c92F82XvxA== X-Received: by 2002:a5d:4ccd:0:b0:2c3:eaff:aae7 with SMTP id c13-20020a5d4ccd000000b002c3eaffaae7mr3963186wrt.17.1676981010786; Tue, 21 Feb 2023 04:03:30 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:30 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 008/103] gccrs: builtins: Move implementation into source file Date: Tue, 21 Feb 2023 13:00:58 +0100 Message-Id: <20230221120230.596966-9-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, 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?1758442318750580853?= X-GMAIL-MSGID: =?utf-8?q?1758442318750580853?= From: Arthur Cohen gcc/rust/ChangeLog: * Make-lang.in: Add `rust-builtins.o` as target * backend/rust-builtins.h: Refactor to new file. * backend/rust-builtins.cc: New file. --- gcc/rust/Make-lang.in | 1 + gcc/rust/backend/rust-builtins.cc | 143 ++++++++++++++++++++++++++++++ gcc/rust/backend/rust-builtins.h | 120 +++---------------------- 3 files changed, 156 insertions(+), 108 deletions(-) create mode 100644 gcc/rust/backend/rust-builtins.cc diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index 7dad27a5dcd..a24025cb31c 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -156,6 +156,7 @@ GRS_OBJS = \ rust/rust-imports.o \ rust/rust-import-archive.o \ rust/rust-extern-crate.o \ + rust/rust-builtins.o \ $(END) # removed object files from here diff --git a/gcc/rust/backend/rust-builtins.cc b/gcc/rust/backend/rust-builtins.cc new file mode 100644 index 00000000000..14dc037edac --- /dev/null +++ b/gcc/rust/backend/rust-builtins.cc @@ -0,0 +1,143 @@ +// 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-builtins.h" + +namespace Rust { +namespace Compile { + +static const int builtin_const = 1 << 0; +static const int builtin_noreturn = 1 << 1; +static const int builtin_novops = 1 << 2; + +BuiltinsContext & +BuiltinsContext::get () +{ + static BuiltinsContext instance; + return instance; +} + +bool +BuiltinsContext::lookup_simple_builtin (const std::string &name, tree *builtin) +{ + auto it = rust_intrinsic_to_gcc_builtin.find (name); + if (it == rust_intrinsic_to_gcc_builtin.end ()) + return false; + + return lookup_gcc_builtin (it->second, builtin); +} + +BuiltinsContext::BuiltinsContext () { setup (); } + +void +BuiltinsContext::setup_overflow_fns () +{ + tree overflow_type + = build_varargs_function_type_list (boolean_type_node, NULL_TREE); + + define_builtin ("add_overflow", BUILT_IN_ADD_OVERFLOW, + "__builtin_add_overflow", "add_overflow", overflow_type, 0); + define_builtin ("sub_overflow", BUILT_IN_SUB_OVERFLOW, + "__builtin_sub_overflow", "sub_overflow", overflow_type, 0); + define_builtin ("mul_overflow", BUILT_IN_MUL_OVERFLOW, + "__builtin_mul_overflow", "mul_overflow", overflow_type, 0); +} + +void +BuiltinsContext::setup_math_fns () +{ + tree math_function_type_f32 + = build_function_type_list (float_type_node, float_type_node, NULL_TREE); + + define_builtin ("sinf32", BUILT_IN_SINF, "__builtin_sinf", "sinf", + math_function_type_f32, builtin_const); + define_builtin ("sqrtf32", BUILT_IN_SQRTF, "__builtin_sqrtf", "sqrtf", + math_function_type_f32, builtin_const); +} + +void +BuiltinsContext::setup () +{ + setup_math_fns (); + setup_overflow_fns (); + + define_builtin ("unreachable", BUILT_IN_UNREACHABLE, "__builtin_unreachable", + NULL, build_function_type (void_type_node, void_list_node), + builtin_const | builtin_noreturn); + + define_builtin ("abort", BUILT_IN_ABORT, "__builtin_abort", "abort", + build_function_type (void_type_node, void_list_node), + builtin_const | builtin_noreturn); + + define_builtin ("breakpoint", BUILT_IN_TRAP, "__builtin_trap", "breakpoint", + build_function_type (void_type_node, void_list_node), + builtin_const | builtin_noreturn); + + define_builtin ("memcpy", BUILT_IN_MEMCPY, "__builtin_memcpy", "memcpy", + build_function_type_list (build_pointer_type (void_type_node), + build_pointer_type (void_type_node), + build_pointer_type (void_type_node), + size_type_node, NULL_TREE), + 0); +} + +static void +handle_flags (tree decl, int flags) +{ + if (flags & builtin_const) + TREE_READONLY (decl) = 1; + if (flags & builtin_noreturn) + TREE_READONLY (decl) = 1; + if (flags & builtin_novops) + DECL_IS_NOVOPS (decl) = 1; +} + +void +BuiltinsContext::define_builtin (const std::string rust_name, + built_in_function bcode, const char *name, + const char *libname, tree fntype, int flags) +{ + tree decl = add_builtin_function (name, fntype, bcode, BUILT_IN_NORMAL, + libname, NULL_TREE); + handle_flags (decl, flags); + set_builtin_decl (bcode, decl, true); + + this->builtin_functions_[name] = decl; + if (libname != NULL) + { + decl = add_builtin_function (libname, fntype, bcode, BUILT_IN_NORMAL, + NULL, NULL_TREE); + handle_flags (decl, flags); + + this->builtin_functions_[libname] = decl; + } + + rust_intrinsic_to_gcc_builtin[rust_name] = name; +} + +bool +BuiltinsContext::lookup_gcc_builtin (const std::string &name, tree *builtin) +{ + auto it = builtin_functions_.find (name); + if (it == builtin_functions_.end ()) + return false; + + *builtin = it->second; + return true; +} + +} // namespace Compile +} // namespace Rust diff --git a/gcc/rust/backend/rust-builtins.h b/gcc/rust/backend/rust-builtins.h index 5cd84010723..e421fa43755 100644 --- a/gcc/rust/backend/rust-builtins.h +++ b/gcc/rust/backend/rust-builtins.h @@ -78,88 +78,18 @@ namespace Compile { class BuiltinsContext { public: - static BuiltinsContext &get () - { - static BuiltinsContext instance; - return instance; - } + static BuiltinsContext &get (); - bool lookup_simple_builtin (const std::string &name, tree *builtin) - { - auto it = rust_intrinsic_to_gcc_builtin.find (name); - if (it == rust_intrinsic_to_gcc_builtin.end ()) - return false; - - return lookup_gcc_builtin (it->second, builtin); - } + bool lookup_simple_builtin (const std::string &name, tree *builtin); private: - static const int builtin_const = 1 << 0; - static const int builtin_noreturn = 1 << 1; - static const int builtin_novops = 1 << 2; - - BuiltinsContext () { setup (); } - - void setup_overflow_fns () - { - tree overflow_type - = build_varargs_function_type_list (boolean_type_node, NULL_TREE); - - define_builtin ("add_overflow", BUILT_IN_ADD_OVERFLOW, - "__builtin_add_overflow", "add_overflow", overflow_type, 0); - define_builtin ("sub_overflow", BUILT_IN_SUB_OVERFLOW, - "__builtin_sub_overflow", "sub_overflow", overflow_type, 0); - define_builtin ("mul_overflow", BUILT_IN_MUL_OVERFLOW, - "__builtin_mul_overflow", "mul_overflow", overflow_type, 0); - } - - void setup_math_fns () - { - tree math_function_type_f32 - = build_function_type_list (float_type_node, float_type_node, NULL_TREE); - - define_builtin ("sinf32", BUILT_IN_SINF, "__builtin_sinf", "sinf", - math_function_type_f32, builtin_const); - define_builtin ("sqrtf32", BUILT_IN_SQRTF, "__builtin_sqrtf", "sqrtf", - math_function_type_f32, builtin_const); - } - - void setup () - { - setup_math_fns (); - setup_overflow_fns (); - - define_builtin ("unreachable", BUILT_IN_UNREACHABLE, - "__builtin_unreachable", NULL, - build_function_type (void_type_node, void_list_node), - builtin_const | builtin_noreturn); - - define_builtin ("abort", BUILT_IN_ABORT, "__builtin_abort", "abort", - build_function_type (void_type_node, void_list_node), - builtin_const | builtin_noreturn); - - define_builtin ("breakpoint", BUILT_IN_TRAP, "__builtin_trap", "breakpoint", - build_function_type (void_type_node, void_list_node), - builtin_const | builtin_noreturn); - - define_builtin ( - "memcpy", BUILT_IN_MEMCPY, "__builtin_memcpy", "memcpy", - build_function_type_list (build_pointer_type (void_type_node), - build_pointer_type (void_type_node), - build_pointer_type (void_type_node), - size_type_node, NULL_TREE), - 0); - } - - static void handle_flags (tree decl, int flags) - { - if (flags & builtin_const) - TREE_READONLY (decl) = 1; - if (flags & builtin_noreturn) - TREE_READONLY (decl) = 1; - if (flags & builtin_novops) - DECL_IS_NOVOPS (decl) = 1; - } + BuiltinsContext (); + + void setup_overflow_fns (); + + void setup_math_fns (); + + void setup (); // Define a builtin function. BCODE is the builtin function code // defined by builtins.def. NAME is the name of the builtin function. @@ -169,35 +99,9 @@ private: // NORETURN_P is true if the function has the noreturn attribute. void define_builtin (const std::string rust_name, built_in_function bcode, const char *name, const char *libname, tree fntype, - int flags) - { - tree decl = add_builtin_function (name, fntype, bcode, BUILT_IN_NORMAL, - libname, NULL_TREE); - handle_flags (decl, flags); - set_builtin_decl (bcode, decl, true); - - this->builtin_functions_[name] = decl; - if (libname != NULL) - { - decl = add_builtin_function (libname, fntype, bcode, BUILT_IN_NORMAL, - NULL, NULL_TREE); - handle_flags (decl, flags); - - this->builtin_functions_[libname] = decl; - } - - rust_intrinsic_to_gcc_builtin[rust_name] = name; - } - - bool lookup_gcc_builtin (const std::string &name, tree *builtin) - { - auto it = builtin_functions_.find (name); - if (it == builtin_functions_.end ()) - return false; - - *builtin = it->second; - return true; - } + int flags); + + bool lookup_gcc_builtin (const std::string &name, tree *builtin); // A mapping of the GCC built-ins exposed to GCC Rust. std::map builtin_functions_; From patchwork Tue Feb 21 12:00:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59960 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1825509wrn; Tue, 21 Feb 2023 04:09:14 -0800 (PST) X-Google-Smtp-Source: AK7set8PbevG8s0E2cBlucjY6bHpqwtpI9A4YizQ71rmRZjHYL8UQFiBQHKBDQ8MF3+9nKv/2JQr X-Received: by 2002:a17:906:50f:b0:8b1:2ebf:386c with SMTP id j15-20020a170906050f00b008b12ebf386cmr11559674eja.11.1676981354809; Tue, 21 Feb 2023 04:09:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981354; cv=none; d=google.com; s=arc-20160816; b=uO5T3IKia+2qw0uwLXIw6avsIUe+bVit8Um1teqjQwSK7tRJVm9do1lkqWRrUCZk/B pjn6xtuzcgHVI9cSXQBx43YHr3uWEhEmI9M7XtpF2NtZQQP8653997/6A7Frvu7BhCqz ubWZLjtlypAZbklQtWCJA5PiL6Frv/8Qg/zVYA9xWrPc9pmrxa5291ix8GoBboWdXQM7 cr/2fBFaTpfuF4Q1vo7VZRI693K0SanxymCQJChHTJVAyj/qnlVJwDUfShFnYA4evRSF 6diZuGo1o/l4EuJs1XUP9UTxAvMeTQPEPm4QNW/ut9DsefGXlnP//rw6zPbdJBOeNbHQ UEgg== 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=4utmg1NwcPV2YkYr1y4pmt6K18H/2biGjSbd2PxHTOo=; b=Q2+sjn9hya3+qwCK0L4blMUh2dS36A2w928AgOyrsSUDB4Re7gkCvnkXTTbVF3rIk9 kDWbdNrCWeJFiPozgXfwYzjhNRPUGF7WV/2Vr0aUkhQcKRKlAnZYfIaIyod+tU631Rbr JDf+pjHV9IbTknk4itVo2o/jrOBwccBGKQgBCZH/IIhGoqCD6cxd+qHHvB2vRVdHjcrJ R7KqjJCdYBUdbKXU0xeWrURujVW7tN9CGXxQqoF/it73RA132d9waqfOax2u1/Fqo25i ozrFrMZU63XSvrXh7Af7hpoPup7k/4uG2fnXZoxnvzzRSIVYBpYCnamRAPtVcqYd+Uix A7jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=TaKPY4aG; 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 bp14-20020a170907918e00b008e21a3323d0si716215ejb.673.2023.02.21.04.09.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:09:14 -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=TaKPY4aG; 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 905BC389838E for ; Tue, 21 Feb 2023 12:05:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 5CE3A384F486 for ; Tue, 21 Feb 2023 12:03:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5CE3A384F486 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 o4so4163325wrs.4 for ; Tue, 21 Feb 2023 04:03:32 -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=4utmg1NwcPV2YkYr1y4pmt6K18H/2biGjSbd2PxHTOo=; b=TaKPY4aGAMHt/zYIyoKGpUl0pCEU1swWhPsNtPfzp/nXDdWY7ZxeRuCughBAmSemvq C4ZOGRVQ/MIp+8WnQwJPGjU+VZKfFAlUGtn053HlzWwB0xc4rqGGKterNhd+DzSQrvj7 K4m4L7FVTA12n93sEx925NUkSc2Xe0IKjKmR2oOPJ/Q9h1HQAopDAdWuGYw9KblWMdZc G8cM/cRFwT7aZn0cSNYbgB4CGFe6VtwHjFSUQ+7P3GkvYZPzGUPa3drUB0FIzeuIDT9F F0C3E9/23mc+n6ViD7tUngAT8AxXDLmXCJOmn2IwOaNdZvaNLn71gl867GGxGdiKB2JD 5fdQ== 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=4utmg1NwcPV2YkYr1y4pmt6K18H/2biGjSbd2PxHTOo=; b=JfTZhmDbr17yO99176o5TtnFNpCcReifBpKiXFCiHv+bgrdFViXpMaaUYBJutVkO7d q4gbtuqdGeh/SJV4or55VceLoWVqGUZQkjY/N0ucov89pWByNtJZqs2jMbzcSRtOTFN2 +HDJo61QdCMxVwjCLVE610XRAsNpRvIHwIQ2p1vdUta51rP2HVAPL8ay9Kmb4im9DPB5 8k0G3QfnfQMp2XxIYHDUGfCPRXhoDPZ97x49MPtPMeo/McToVs2ZJwYf0lODX6wgLr3i mxKSTd0afwkBySf8O+YNNPnFx8VckPB6h9Qws4Bvl2SKbw/ieM2jDLpyElPigB/e+CKn zk3w== X-Gm-Message-State: AO0yUKU1lXYepxB/EJDnSpOuH/4SFamKOJNwQw6wAYaVYRAVwUOnP2pj AecFOjMNDj66AYEDJeHozuqU/IbRIdHHTZNvjQ== X-Received: by 2002:a5d:4105:0:b0:2c5:5eff:5c81 with SMTP id l5-20020a5d4105000000b002c55eff5c81mr3682839wrp.38.1676981011534; Tue, 21 Feb 2023 04:03:31 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:31 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 009/103] gccrs: Track DefId on ADT variants Date: Tue, 21 Feb 2023 13:00:59 +0100 Message-Id: <20230221120230.596966-10-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.4 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?1758442401272483763?= X-GMAIL-MSGID: =?utf-8?q?1758442401272483763?= From: Philip Herron We must track the DefID on variants for algebraic data types as this will allow us to enforce unique'ness on path queries relating to this. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-enumitem.cc (TypeCheckEnumItem::visit): Adjust VariantDef ctor calls with DefID. * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Likewise. * typecheck/rust-tyty.h (VariantDef): Add defid parameter to ctor. --- .../typecheck/rust-hir-type-check-enumitem.cc | 4 ++++ .../typecheck/rust-hir-type-check-item.cc | 9 +++++--- gcc/rust/typecheck/rust-tyty.h | 22 ++++++++++--------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc index dd3cb12d17b..30db967f4e0 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc @@ -82,6 +82,7 @@ TypeCheckEnumItem::visit (HIR::EnumItem &item) RustIdent ident{*canonical_path, item.get_locus ()}; variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (), + item.get_mappings ().get_defid (), item.get_identifier (), ident, discim_expr); } @@ -111,6 +112,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemDiscriminant &item) RustIdent ident{*canonical_path, item.get_locus ()}; variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (), + item.get_mappings ().get_defid (), item.get_identifier (), ident, item.get_discriminant_expression ().get ()); } @@ -159,6 +161,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemTuple &item) RustIdent ident{*canonical_path, item.get_locus ()}; variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (), + item.get_mappings ().get_defid (), item.get_identifier (), ident, TyTy::VariantDef::VariantType::TUPLE, discim_expr, fields); @@ -206,6 +209,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemStruct &item) RustIdent ident{*canonical_path, item.get_locus ()}; variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (), + item.get_mappings ().get_defid (), item.get_identifier (), ident, TyTy::VariantDef::VariantType::STRUCT, discrim_expr, fields); diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc b/gcc/rust/typecheck/rust-hir-type-check-item.cc index e39dd537d6e..af1e39670ce 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-item.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc @@ -125,7 +125,8 @@ TypeCheckItem::visit (HIR::TupleStruct &struct_decl) // its a single variant ADT std::vector variants; variants.push_back (new TyTy::VariantDef ( - struct_decl.get_mappings ().get_hirid (), struct_decl.get_identifier (), + struct_decl.get_mappings ().get_hirid (), + struct_decl.get_mappings ().get_defid (), struct_decl.get_identifier (), ident, TyTy::VariantDef::VariantType::TUPLE, nullptr, std::move (fields))); // Process #[repr(X)] attribute, if any @@ -179,7 +180,8 @@ TypeCheckItem::visit (HIR::StructStruct &struct_decl) // its a single variant ADT std::vector variants; variants.push_back (new TyTy::VariantDef ( - struct_decl.get_mappings ().get_hirid (), struct_decl.get_identifier (), + struct_decl.get_mappings ().get_hirid (), + struct_decl.get_mappings ().get_defid (), struct_decl.get_identifier (), ident, TyTy::VariantDef::VariantType::STRUCT, nullptr, std::move (fields))); // Process #[repr(X)] attribute, if any @@ -273,7 +275,8 @@ TypeCheckItem::visit (HIR::Union &union_decl) // there is only a single variant std::vector variants; variants.push_back (new TyTy::VariantDef ( - union_decl.get_mappings ().get_hirid (), union_decl.get_identifier (), + union_decl.get_mappings ().get_hirid (), + union_decl.get_mappings ().get_defid (), union_decl.get_identifier (), ident, TyTy::VariantDef::VariantType::STRUCT, nullptr, std::move (fields))); TyTy::BaseType *type diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index e3cf4d667c7..a033fcad6c9 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -1063,9 +1063,9 @@ public: return ""; } - VariantDef (HirId id, std::string identifier, RustIdent ident, + VariantDef (HirId id, DefId defid, std::string identifier, RustIdent ident, HIR::Expr *discriminant) - : id (id), identifier (identifier), ident (ident), + : id (id), defid (defid), identifier (identifier), ident (ident), discriminant (discriminant) { @@ -1073,11 +1073,11 @@ public: fields = {}; } - VariantDef (HirId id, std::string identifier, RustIdent ident, + VariantDef (HirId id, DefId defid, std::string identifier, RustIdent ident, VariantType type, HIR::Expr *discriminant, std::vector fields) - : id (id), identifier (identifier), ident (ident), type (type), - discriminant (discriminant), fields (fields) + : id (id), defid (defid), identifier (identifier), ident (ident), + type (type), discriminant (discriminant), fields (fields) { rust_assert ( (type == VariantType::NUM && fields.empty ()) @@ -1085,8 +1085,8 @@ public: } VariantDef (const VariantDef &other) - : id (other.id), identifier (other.identifier), ident (other.ident), - type (other.type), discriminant (other.discriminant), + : id (other.id), defid (other.defid), identifier (other.identifier), + ident (other.ident), type (other.type), discriminant (other.discriminant), fields (other.fields) {} @@ -1105,7 +1105,7 @@ public: static VariantDef &get_error_node () { static VariantDef node - = VariantDef (UNKNOWN_HIRID, "", + = VariantDef (UNKNOWN_HIRID, UNKNOWN_DEFID, "", {Resolver::CanonicalPath::create_empty (), Linemap::unknown_location ()}, nullptr); @@ -1116,6 +1116,7 @@ public: bool is_error () const { return get_id () == UNKNOWN_HIRID; } HirId get_id () const { return id; } + DefId get_defid () const { return defid; } VariantType get_variant_type () const { return type; } bool is_data_variant () const { return type != VariantType::NUM; } @@ -1211,7 +1212,7 @@ public: for (auto &f : fields) cloned_fields.push_back ((StructFieldType *) f->clone ()); - return new VariantDef (id, identifier, ident, type, discriminant, + return new VariantDef (id, defid, identifier, ident, type, discriminant, cloned_fields); } @@ -1221,7 +1222,7 @@ public: for (auto &f : fields) cloned_fields.push_back ((StructFieldType *) f->monomorphized_clone ()); - return new VariantDef (id, identifier, ident, type, discriminant, + return new VariantDef (id, defid, identifier, ident, type, discriminant, cloned_fields); } @@ -1229,6 +1230,7 @@ public: private: HirId id; + DefId defid; std::string identifier; RustIdent ident; VariantType type; From patchwork Tue Feb 21 12:01:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59976 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1828814wrn; Tue, 21 Feb 2023 04:17:14 -0800 (PST) X-Google-Smtp-Source: AK7set9LpyuaXAJ9wtsYfeOqZXbPAbgxwe5bgDdNGrQ1AXNGezyFUDIuWypRPrmPohyOtwdlntM+ X-Received: by 2002:a17:907:3203:b0:8b1:304e:58a7 with SMTP id xg3-20020a170907320300b008b1304e58a7mr17568316ejb.56.1676981833922; Tue, 21 Feb 2023 04:17:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981833; cv=none; d=google.com; s=arc-20160816; b=r8blJFXzr+cwnNH2tgSsP7HOKsCuhvYN9tTWOfUCO9av/0a8U37Ua1iTwpV1XDRKgS /ZAbfMJ5QUFNWyJ1AXwTbbjcleCZ21To8W5UjEKqszeSB+VVPfgctLE1IiWj+wyCiKHb /doekNA8x/787OHgVHR5IY7WESH7pRYp3jcZvE0qsjiOJ5uOsN0RfGQFKzLPT7WAsCER prqLAOQsK3FgrOt45dk59zCIahziLvFWT07sVT8bnwXA05dvo5zUtDTLBC27sG/8jZF7 5U0Y0fcJwB4BNqM/CZQ+CklLhWgB0YDrVjSqY/7zDWoYNfg7H2hilg5zbrYYHx0U2X+z BM3A== 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=NsL4s9f2skORHiTcIxGhWJbiRNKg2rP6QnKS1kE3nWs=; b=l/vH8I6AJjhRwTuKinuS8AMB0Jg4/Gbx1drrOGO97Hk98r4WP+4+mEkiThUtxYCbm7 J1PSUMCDo3ujh7atuijy5n91DVyUEH8X/gHWRptBrzeZckYGHL4BhtHtE9aNEKtAeAAA qvzdPkBmXvBN5iPSNE0p0FS6YnFG3aJaI2lRqPDfrr1lv1Werx1iQGeu1TOjPvSf5GfL jzhBcWE1iAeyF5nn4T8TRzeO/gep5WUUstrX2IykqQie/O2M8vgcAgrMmvh7boURHnAF CiRX6zsMfDza/4E+nl3/2NtRKtZv7Z3Z8Ek7U4jq97FSd4Ysql+Ss4aIQVBnnOxBTZSM s0UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Pm959yUa; 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 13-20020a170906028d00b008b13afdbdefsi25212922ejf.822.2023.02.21.04.17.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:17:13 -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=Pm959yUa; 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 97DF63AA88FD for ; Tue, 21 Feb 2023 12:08:04 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 6B0E5384DD39 for ; Tue, 21 Feb 2023 12:03:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6B0E5384DD39 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-x430.google.com with SMTP id t15so4266329wrz.7 for ; Tue, 21 Feb 2023 04:03:33 -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=NsL4s9f2skORHiTcIxGhWJbiRNKg2rP6QnKS1kE3nWs=; b=Pm959yUad3JmdNtkIlaMBBqWqnENSH7fKfZnuoJ6kLodx5tqa/Ulpm6UiS3VODtOrN 9vAth+LtkwXqfu11QSGHostkNbbjxA6HA4mjQM138PbyCiwtoN/YctHXaMwNym5oIZTp 49bUmw0ioHVMcsdxjRvBi5VviMEe7FOTc3d99dMHcVtmKwEMJe3IC5iSR81ezCGHgjRZ zOYVvrIDDxwsHNZLyaBxnMH6WBAoR4EcogbPoPzoTQ8yIMFWJC/yceskde1KV5PZzqsl rLdMjL47M6Y7cWj6ajOmmYJKxU9uYMT79hzAVDHshi5T3Wki4QZ9ac4qracE8SvNFJmO 5Kaw== 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=NsL4s9f2skORHiTcIxGhWJbiRNKg2rP6QnKS1kE3nWs=; b=Wg206hZyBniw0QGZenTHqqF53uKKXYnzw9YmoKoCKkAD5cM33tRoZiB9P+s5bXIVUc tscwCQQRl56FOP40/l1d+6XDCduSIDXBZeXt0dAkFFCeo6ooFbr8WTGifI3lnFlpnkYd BYK1iIBdu+/Tb37bzwXigrIbmHk969IhBWHrqx8JWNCQLSj5MJsSdXnZQW4vGKN+iIKQ JwtKP+mAiGNkHyhPmou4gDhHxQojJ155fPie2OH0WwDvP5uNvYaORHoW1BQcHQlJaD// uHh1SgKN94E9x8t0+5sfNE0DYQbUMgRWMznTto3oVzZQYNrwxeXvyXpYpI0XVFk4hhKh KQUQ== X-Gm-Message-State: AO0yUKVj2By8c49B80uereNdYtroQIShJncorgoWiVk1VQtJ2KxQOo1C 65s0FGPT/OWjqe0QY/5wQLJD84l4wnXixAt6Mw== X-Received: by 2002:a5d:56c9:0:b0:2c3:e07d:46cc with SMTP id m9-20020a5d56c9000000b002c3e07d46ccmr4267689wrw.41.1676981012016; Tue, 21 Feb 2023 04:03:32 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:31 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 010/103] gccrs: Ensure uniqueness on Path probe's Date: Tue, 21 Feb 2023 13:01:00 +0100 Message-Id: <20230221120230.596966-11-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.4 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?1758442903370207810?= X-GMAIL-MSGID: =?utf-8?q?1758442903370207810?= From: Philip Herron When we lookup names in paths such as Foo::bar, foo is a type we resolve and then we lookup 'bar' based on what type Foo is which includes probing relevant bounds of this type. We currently return a vector of possible candidates and this patch changes it so that we return a set of unique items based on DefId. Addresses #1555 gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::resolve_method_address): Use auto and minor change in candidate init. * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): Likewise. * typecheck/rust-hir-type-check-type.cc: Likewise. * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): Likewise. Removecall to set_ty_ref. * typecheck/rust-hir-path-probe.h (struct PathProbeCandidate): Add locus initializer in ctor, implement get_defid. (class PathProbeType::Probe): return a set instead of vector. Adjust class impl. (class ReportMultipleCandidateError): Do not inherit from HIRImplVisitor anymore and remove corresponding impl. Adjust for change in Probe. Simplify Report handling. (class PathProbeImplTrait::Probe): Adjust return type. --- gcc/rust/backend/rust-compile-expr.cc | 4 +- gcc/rust/backend/rust-compile-resolve-path.cc | 8 +- gcc/rust/typecheck/rust-hir-path-probe.h | 108 ++++++++---------- .../typecheck/rust-hir-type-check-path.cc | 2 +- .../typecheck/rust-hir-type-check-type.cc | 2 +- 5 files changed, 58 insertions(+), 66 deletions(-) diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index d58e2258947..ddf914f6736 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -1982,7 +1982,7 @@ CompileExpr::resolve_method_address (TyTy::FnType *fntype, HirId ref, // trait-impl-item's definition auto root = receiver->get_root (); - std::vector candidates + auto candidates = Resolver::PathProbeType::Probe (root, segment, true /* probe_impls */, false /* probe_bounds */, true /* ignore_mandatory_trait_items */); @@ -2011,7 +2011,7 @@ CompileExpr::resolve_method_address (TyTy::FnType *fntype, HirId ref, // implementation and we should just return error_mark_node rust_assert (candidates.size () == 1); - auto &candidate = candidates.at (0); + auto &candidate = *candidates.begin (); rust_assert (candidate.is_impl_candidate ()); rust_assert (candidate.ty->get_kind () == TyTy::TypeKind::FNDEF); TyTy::FnType *candidate_call = static_cast (candidate.ty); diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc index 2cc9505692a..ab8e628c75c 100644 --- a/gcc/rust/backend/rust-compile-resolve-path.cc +++ b/gcc/rust/backend/rust-compile-resolve-path.cc @@ -251,7 +251,7 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType *lookup, // item so its up to us to figure out if this path should resolve // to an trait-impl-block-item or if it can be defaulted to the // trait-impl-item's definition - std::vector candidates + auto candidates = Resolver::PathProbeImplTrait::Probe (receiver, final_segment, trait_ref); if (candidates.size () == 0) @@ -270,7 +270,9 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType *lookup, } else { - Resolver::PathProbeCandidate &candidate = candidates.at (0); + rust_assert (candidates.size () == 1); + + auto candidate = *candidates.begin (); rust_assert (candidate.is_impl_candidate ()); HIR::ImplBlock *impl = candidate.item.impl.parent; @@ -288,8 +290,6 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType *lookup, else return CompileInherentImplItem::Compile (impl_item, ctx, lookup, true, expr_locus); - - lookup->set_ty_ref (impl_item->get_impl_mappings ().get_hirid ()); } } } diff --git a/gcc/rust/typecheck/rust-hir-path-probe.h b/gcc/rust/typecheck/rust-hir-path-probe.h index c957487dd2a..6d6bcf8e7cd 100644 --- a/gcc/rust/typecheck/rust-hir-path-probe.h +++ b/gcc/rust/typecheck/rust-hir-path-probe.h @@ -80,17 +80,17 @@ struct PathProbeCandidate PathProbeCandidate (CandidateType type, TyTy::BaseType *ty, Location locus, EnumItemCandidate enum_field) - : type (type), ty (ty), item (enum_field) + : type (type), ty (ty), locus (locus), item (enum_field) {} PathProbeCandidate (CandidateType type, TyTy::BaseType *ty, Location locus, ImplItemCandidate impl) - : type (type), ty (ty), item (impl) + : type (type), ty (ty), locus (locus), item (impl) {} PathProbeCandidate (CandidateType type, TyTy::BaseType *ty, Location locus, TraitItemCandidate trait) - : type (type), ty (ty), item (trait) + : type (type), ty (ty), locus (locus), item (trait) {} std::string as_string () const @@ -123,12 +123,45 @@ struct PathProbeCandidate } bool is_error () const { return type == ERROR; } + + DefId get_defid () const + { + switch (type) + { + case ENUM_VARIANT: + return item.enum_field.variant->get_defid (); + break; + + case IMPL_CONST: + case IMPL_TYPE_ALIAS: + case IMPL_FUNC: + return item.impl.impl_item->get_impl_mappings ().get_defid (); + break; + + case TRAIT_ITEM_CONST: + case TRAIT_TYPE_ALIAS: + case TRAIT_FUNC: + return item.trait.item_ref->get_mappings ().get_defid (); + break; + + case ERROR: + default: + return UNKNOWN_DEFID; + } + + return UNKNOWN_DEFID; + } + + bool operator< (const PathProbeCandidate &c) const + { + return get_defid () < c.get_defid (); + } }; class PathProbeType : public TypeCheckBase, public HIR::HIRImplVisitor { public: - static std::vector + static std::set Probe (const TyTy::BaseType *receiver, const HIR::PathIdentSegment &segment_name, bool probe_impls, bool probe_bounds, bool ignore_mandatory_trait_items, @@ -203,7 +236,7 @@ public: PathProbeCandidate candidate{ PathProbeCandidate::CandidateType::IMPL_TYPE_ALIAS, ty, alias.get_locus (), impl_item_candidate}; - candidates.push_back (std::move (candidate)); + candidates.insert (std::move (candidate)); } } @@ -222,7 +255,7 @@ public: PathProbeCandidate candidate{ PathProbeCandidate::CandidateType::IMPL_CONST, ty, constant.get_locus (), impl_item_candidate}; - candidates.push_back (std::move (candidate)); + candidates.insert (std::move (candidate)); } } @@ -241,7 +274,7 @@ public: PathProbeCandidate candidate{ PathProbeCandidate::CandidateType::IMPL_FUNC, ty, function.get_locus (), impl_item_candidate}; - candidates.push_back (std::move (candidate)); + candidates.insert (std::move (candidate)); } } @@ -259,7 +292,7 @@ protected: PathProbeCandidate candidate{ PathProbeCandidate::CandidateType::ENUM_VARIANT, receiver->clone (), mappings->lookup_location (adt->get_ty_ref ()), enum_item_candidate}; - candidates.push_back (std::move (candidate)); + candidates.insert (std::move (candidate)); } void process_impl_items_for_candidates () @@ -338,8 +371,9 @@ protected: impl}; PathProbeCandidate candidate{candidate_type, trait_item_tyty, - trait_ref->get_locus (), trait_item_candidate}; - candidates.push_back (std::move (candidate)); + trait_item_ref->get_locus (), + trait_item_candidate}; + candidates.insert (std::move (candidate)); } void @@ -383,7 +417,7 @@ protected: PathProbeCandidate candidate{candidate_type, trait_item_tyty, trait_item_ref->get_locus (), trait_item_candidate}; - candidates.push_back (std::move (candidate)); + candidates.insert (std::move (candidate)); } protected: @@ -428,72 +462,30 @@ protected: const TyTy::BaseType *receiver; const HIR::PathIdentSegment &search; - std::vector candidates; + std::set candidates; HIR::ImplBlock *current_impl; DefId specific_trait_id; }; -class ReportMultipleCandidateError : private TypeCheckBase, - private HIR::HIRImplVisitor +class ReportMultipleCandidateError : private TypeCheckBase { public: - static void Report (std::vector &candidates, + static void Report (std::set &candidates, const HIR::PathIdentSegment &query, Location query_locus) { RichLocation r (query_locus); - ReportMultipleCandidateError visitor (r); for (auto &c : candidates) - { - switch (c.type) - { - case PathProbeCandidate::CandidateType::ERROR: - case PathProbeCandidate::CandidateType::ENUM_VARIANT: - gcc_unreachable (); - break; - - case PathProbeCandidate::CandidateType::IMPL_CONST: - case PathProbeCandidate::CandidateType::IMPL_TYPE_ALIAS: - case PathProbeCandidate::CandidateType::IMPL_FUNC: - c.item.impl.impl_item->accept_vis (visitor); - break; - - case PathProbeCandidate::CandidateType::TRAIT_ITEM_CONST: - case PathProbeCandidate::CandidateType::TRAIT_TYPE_ALIAS: - case PathProbeCandidate::CandidateType::TRAIT_FUNC: - r.add_range (c.item.trait.item_ref->get_locus ()); - break; - } - } + r.add_range (c.locus); rust_error_at (r, "multiple applicable items in scope for: %s", query.as_string ().c_str ()); } - - void visit (HIR::TypeAlias &alias) override - { - r.add_range (alias.get_locus ()); - } - - void visit (HIR::ConstantItem &constant) override - { - r.add_range (constant.get_locus ()); - } - - void visit (HIR::Function &function) override - { - r.add_range (function.get_locus ()); - } - -private: - ReportMultipleCandidateError (RichLocation &r) : TypeCheckBase (), r (r) {} - - RichLocation &r; }; class PathProbeImplTrait : public PathProbeType { public: - static std::vector + static std::set Probe (const TyTy::BaseType *receiver, const HIR::PathIdentSegment &segment_name, const TraitReference *trait_reference) diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc index 305d73f76f9..6f1fd416c19 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-path.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc @@ -337,7 +337,7 @@ TypeCheckExpr::resolve_segments (NodeId root_resolved_node_id, return; } - auto &candidate = candidates.at (0); + auto &candidate = *candidates.begin (); prev_segment = tyseg; tyseg = candidate.ty; diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc index 5a6d00a0e9d..a91d15c8e2c 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-type.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc @@ -462,7 +462,7 @@ TypeCheckType::resolve_segments ( return new TyTy::ErrorType (expr_id); } - auto &candidate = candidates.at (0); + auto &candidate = *candidates.begin (); prev_segment = tyseg; tyseg = candidate.ty; From patchwork Tue Feb 21 12:01:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59958 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1825153wrn; Tue, 21 Feb 2023 04:08:28 -0800 (PST) X-Google-Smtp-Source: AK7set8fU7bDS65+zLE6ZRkQRFIf+mrBGCYyxk15XoFhbw6cxb77nOiNiZDjgghMywhxnJUC/eCO X-Received: by 2002:a17:906:4914:b0:8b1:7eaf:4708 with SMTP id b20-20020a170906491400b008b17eaf4708mr15617442ejq.65.1676981308014; Tue, 21 Feb 2023 04:08:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981308; cv=none; d=google.com; s=arc-20160816; b=tj6U2Ad7DknDqbXzjn1GUKctGqEEUPazynHWU/TgtLl95Cau563G5669HhZNC5ooIl iXjKXz/TWKL4rBtt6q1eeM9m3y9J7HlmAFmhwU8rEXXDc39+flPPL4GDcWt2hFI1PSjE Qr547PXypkEq1vN4EEZLjw5ryBlxopuw5joG0BSWFCV68mq03YtVePxmX5xZSy7L1PMe Be/yYEGjAFrYAzBawsv3jO90qK5J2uOurxRauDAgLaa9dYpIiEcHSJSYF6o3WWC+PCvq WNyx6AfaMWz9Xipa5aQHZxaTT2SoBFF1JTv7PCQLCe+j4FjChQzzyAE/DOvkhfQG2s5I RVpA== 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=bdJtvjW+kVPvmSQZ+NCJb+ySr4zY4gBrlQB15L7NmAc=; b=ZPLzOEbyfMr2N3ux3zm5QPfHlMRQaZuGsu5eBBeZVLqsjyHEJx5HZY4wGzG092bw+U q9RfCu3TSiSujTWdjulRoxsFTrbjyYPTxQLILxcGo25jzSnoMt0Pe5eLrgnBlIx1/oUO Z2Rmlf9i/njEAYVOcJziW16RTd23yEvxwvqHGzF6R+Z8kNBYJKoTZGOBMUjZfQUSlzTu WUN8csNwoWRvyUsjxUpoFti4hSEiu77HtcKYlUJ4TnKw7I1q+1qxMBKq471RDCsE/s1y M6+1mqD9cOxYseWEBfuSd7kbSidrRTIWtIwsEjZ5kO66VI3DrUk1HX4zWVOTAbFC/iC8 z27w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b="BW1/hPs1"; 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 30-20020a170906005e00b008dd40fa813asi3729970ejg.359.2023.02.21.04.08.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:08:28 -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="BW1/hPs1"; 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 04771388B69C for ; Tue, 21 Feb 2023 12:05:03 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 3589538654A3 for ; Tue, 21 Feb 2023 12:03:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3589538654A3 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-x436.google.com with SMTP id c12so4161774wrw.1 for ; Tue, 21 Feb 2023 04:03:34 -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=bdJtvjW+kVPvmSQZ+NCJb+ySr4zY4gBrlQB15L7NmAc=; b=BW1/hPs1Rg4+UZbyq1biI3KIh64L89nLH5f1E5SbMGbPnWg1a+PpSFIIB1vygTONrs W2Gkq+gjJCN1pW388AG0Zk0NH/+BhVfVBBZFHd/H6q8DcZfm9tA2qjLRWsuEO12gRMy5 R4S57Q7SYM6TZlEtiQHXTtA1u1jBOPp6dzZpU381eEGQ4ifSAmHd8xB+7i/2WXWucJq5 xqcbSKZGuqOZSz5iDZ9Z5U/K5+XIDRHck4BY+YFWNQjFWBS4WhJkisw0eDOz+iTuNMMM ftnrOZFeMUDhfjGMQVHGNNe4jXWI4VpTe7Ljs0R5gAQdvSSla8q5wlaDLvN/0uffHcEq AFcA== 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=bdJtvjW+kVPvmSQZ+NCJb+ySr4zY4gBrlQB15L7NmAc=; b=eNR8yiAIyfu54gR0brVNuCu5jvZoZS2G8hwvIr4+5aurPqZyaO24i8xu/SnffeY8Rz vyqG0wi2gtSEW+NUJHuau/O8LPt73qyfP7pZ3RwlZnQaXzZdJJhQb92zhXnx242nXwUj ntJQ2AO3dC6zFj99Cu7dqGLV+VwiFoXsBVfIT13faGt2/1fPVu4VRMWbRSaar7XooNS3 +PlrHuhsBk3cx9Dae479wQCAVwjCByROx5a+CvEJ4CiXpD5x9XeqXXgH011AjMW6+AYZ s0ZhWJKdDoe9Le+Q0JF7rtiRvostwtHc8ISNlbZ5cAa8kLLCmoOb+tmUNQLsDZJGMRUy dnZQ== X-Gm-Message-State: AO0yUKVjeHzt49YUeL9X2Y26gjs5f6fx4J8Nci+ZCf6QpAGRHGAex8yn Nqh4aKIHm3fh1jpWcGF6+ivAYPH1rB0OFIJh6g== X-Received: by 2002:a5d:4712:0:b0:2c5:4c6f:27c6 with SMTP id y18-20020a5d4712000000b002c54c6f27c6mr3925758wrq.5.1676981012759; Tue, 21 Feb 2023 04:03:32 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:32 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 011/103] gccrs: Support looking up super traits for trait items Date: Tue, 21 Feb 2023 13:01:01 +0100 Message-Id: <20230221120230.596966-12-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?1758442351990573149?= X-GMAIL-MSGID: =?utf-8?q?1758442351990573149?= From: Philip Herron When supporting calls to super traits we need to allow lookups based on the super traits as specified on the TraitReferences. Fixes #1555 gcc/rust/ChangeLog: * typecheck/rust-hir-trait-ref.h (lookup_trait_item): Add lookup in super_trait. gcc/testsuite/ChangeLog: * rust/compile/torture/issue-1555.rs: New test. --- gcc/rust/typecheck/rust-hir-trait-ref.h | 19 ++++++++ .../rust/compile/torture/issue-1555.rs | 48 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 gcc/testsuite/rust/compile/torture/issue-1555.rs diff --git a/gcc/rust/typecheck/rust-hir-trait-ref.h b/gcc/rust/typecheck/rust-hir-trait-ref.h index f6a3328c5f6..7eeb3300387 100644 --- a/gcc/rust/typecheck/rust-hir-trait-ref.h +++ b/gcc/rust/typecheck/rust-hir-trait-ref.h @@ -336,6 +336,15 @@ public: return true; } } + + // lookup super traits + for (const auto &super_trait : super_traits) + { + bool found = super_trait->lookup_trait_item (ident, ref); + if (found) + return true; + } + return false; } @@ -351,6 +360,16 @@ public: if (ident.compare (item.get_identifier ()) == 0) return &item; } + + // lookup super traits + for (const auto &super_trait : super_traits) + { + const TraitItemReference *res + = super_trait->lookup_trait_item (ident, type); + if (!res->is_error ()) + return res; + } + return &TraitItemReference::error_node (); } diff --git a/gcc/testsuite/rust/compile/torture/issue-1555.rs b/gcc/testsuite/rust/compile/torture/issue-1555.rs new file mode 100644 index 00000000000..adb48911648 --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/issue-1555.rs @@ -0,0 +1,48 @@ +extern "C" { + fn printf(s: *const i8, ...); +} + +struct Foo(i32); +trait Bar { + fn baz(&self); +} + +trait Baz: Bar { + fn qux(&self); +} + +impl Bar for Foo { + fn baz(&self) { + unsafe { + let a = "baz %i\n\0"; + let b = a as *const str; + let c = b as *const i8; + + printf(c, self.0); + } + } +} + +impl Baz for Foo { + fn qux(&self) { + unsafe { + let a = "qux %i\n\0"; + let b = a as *const str; + let c = b as *const i8; + + printf(c, self.0); + } + } +} + +fn static_dispatch(t: &T) { + t.baz(); + t.qux(); +} + +pub fn main() { + let a; + a = &Foo(123); + + static_dispatch(a); +} From patchwork Tue Feb 21 12:01:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59966 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1826109wrn; Tue, 21 Feb 2023 04:10:46 -0800 (PST) X-Google-Smtp-Source: AK7set/KislAF5JZDbiLehU0+NYfAL1L7kjFcGb7AQ0BH7p/4fgc8zD0PZjcIZJU/ia766oKtYbr X-Received: by 2002:a17:906:4550:b0:8b1:7ae8:ba6f with SMTP id s16-20020a170906455000b008b17ae8ba6fmr15096387ejq.16.1676981445979; Tue, 21 Feb 2023 04:10:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981445; cv=none; d=google.com; s=arc-20160816; b=GHZz4vGOax6bcFgTpOdl3bhVEGzZuaoKUGkwMtIlrcSeR0kloV5QWIGZfsXVFJJBU9 AAhnv4PwFZn4uNV37gpCxLDaTcnfhuVEMKc70h9ZzT7giapVnX8NhmUarbmmnliAfu9h fR5VhJ34JBz8TIbWUiLU+Fhzgk10Zb+7y2JzYH2xpKDry6Zyl9jIenroY7qC95NkJh+r x/kg3/zwIq3n41qysFa9ZrVeU2W7JeqV4F4ZxsuzYGzH4AAg6EOXfF10WAGJTAxr00ZJ PwSpanNaB+EnQoFGHXsWah/h+Xx4aj2gOQklEfH/9rzfXfBhJUMDNEpcYVcL4BBoF+9l aH/A== 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=g35FVS5hWKiVZYjGcvh/C4yA17IWzOjf0SOlF8H+5Y4=; b=XmUGPgDAkrgc8e/EOLlU5pxq3Fzq7XbFl+N/bs5MA/ybDozWS55KLT23C0w1eyJQzX 4bQoh3dOaYkqtfijeERrineHOeckzGjC1Q96IvEMLR3IO6F2hyTwnte33Mn4Ycihiavh g+UOAa1iKEAguivv3O6v+Q9YRprPBcLzNqpIb85lOTLyyTpP3UVC9qQsjOLM8nFBx1e9 /u2fueNNJJt03klUdtsjAcTa60E0A/l66g5xzGJCPrxI8C0sCvwkOvhgkAcMwBbYnXfN zX1Yjl9e9L4n3dMAN8YYfbF+J1BhMMJi9EUdrAqVGsx+OfQDQhf6jQT06h8y9GTh9LXI NH7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=dSGbsPjT; 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 18-20020a170906209200b008dc4d55dda4si5250867ejq.705.2023.02.21.04.10.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:10:45 -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=dSGbsPjT; 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 7A63C3947408 for ; Tue, 21 Feb 2023 12:05:52 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id F3B6738493D9 for ; Tue, 21 Feb 2023 12:03:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F3B6738493D9 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-x32d.google.com with SMTP id o4-20020a05600c4fc400b003e1f5f2a29cso3397334wmq.4 for ; Tue, 21 Feb 2023 04:03:34 -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=g35FVS5hWKiVZYjGcvh/C4yA17IWzOjf0SOlF8H+5Y4=; b=dSGbsPjT2PqFPw56Xbysha0ndwFCKVqFYxwB/clzG27VLRg476ag72MmYM6pc4qMPA ON2g5T2LclWwIJuJtzQv6dDSjclE52r+s9RPxL5uosNxmn6tMLlrEq+mDMyzZDijs04b Wtef5jtm4Conygfrb+uMMG+r0AH/YLIu4796VtuEJtRH+jaB8sAW724imYRDAaImnWuP XCPv3laNLWG7a5CwfdDmAMJIlkEHnlq3ndAGSZQ2s4yiu/ggLT3VA8nJb4qr3GHXmeep WAeVESgzqwyckWTzGUS8xwd8wgtY86jxkjUQ3GpMIZx3Nc5gvmCGUN8I4K6FRDlLFL7S 6jjw== 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=g35FVS5hWKiVZYjGcvh/C4yA17IWzOjf0SOlF8H+5Y4=; b=IbsWU0C3DjCKze1VnFp43NnJ2Z4m1llPa+4ArO12vLd+Ao0ZVHfv0cl/49NlBHhBZX JyCVrQ2N7G7mbo4q0D+2zP7DHOLtQHtvApiu4B4gai6ijM7tICMFNf/MiEger3r+IvW0 XPfY47KpgJdN/T1XmCQK8ve9fYItqYQFdYcyHfAp661X0t4Qof763SvCKmbFO3oS7aGK FPFDiS5tAb4m+omuQn9vcBRjM3bxcVUsrUkPRj+qmcIE3SFKcwKt1JRsldVKAWWzSkVX ug5NERwFQb37+MS5BsPFiLlELl+jCPhybfO92Zf7861yk4gmASIxgZRB4MbuC/d5N/D6 RnMA== X-Gm-Message-State: AO0yUKUsy4rLMKEZS+7n0tYtXpXPcf7pgvLnuwPpGHC+9n1cz50BlWXS JIbIo5lU8Cy3Ivh11UzDUvudI0ppIkI/FGY0PQ== X-Received: by 2002:a05:600c:2b45:b0:3e0:c5e:ad52 with SMTP id e5-20020a05600c2b4500b003e00c5ead52mr3374671wmf.6.1676981013506; Tue, 21 Feb 2023 04:03:33 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:32 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, David Faust Subject: [committed 012/103] gccrs: ast: dump: add emit_generic_params helper Date: Tue, 21 Feb 2023 13:01:02 +0100 Message-Id: <20230221120230.596966-13-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=ham 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?1758442496379809008?= X-GMAIL-MSGID: =?utf-8?q?1758442496379809008?= From: David Faust gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): move generic params dump ... (Dump::emit_generic_params): ... here. * ast/rust-ast-dump.h (emit_generic_params): New. --- gcc/rust/ast/rust-ast-dump.cc | 30 +++++++++++++++++------------- gcc/rust/ast/rust-ast-dump.h | 3 +++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index bc4f7a3a5c1..b192556647c 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -140,6 +140,22 @@ Dump::emit_indented_string (const std::string &value, return stream << indentation << value << comment; } +void +Dump::emit_generic_params (std::vector> ¶ms) +{ + stream << "<"; + for (size_t i = 0; i < params.size (); i++) + { + auto ¶m = params.at (i); + param->accept_vis (*this); + + bool has_next = (i + 1) < params.size (); + if (has_next) + stream << ", "; + } + stream << ">"; +} + void Dump::visit (Token &tok) {} @@ -679,19 +695,7 @@ Dump::visit (Function &function) stream << "fn " << function.get_function_name (); if (function.has_generics ()) - { - stream << "<"; - for (size_t i = 0; i < function.get_generic_params ().size (); i++) - { - auto ¶m = function.get_generic_params ().at (i); - param->accept_vis (*this); - - bool has_next = (i + 1) < function.get_generic_params ().size (); - if (has_next) - stream << ", "; - } - stream << ">"; - } + emit_generic_params (function.get_generic_params ()); stream << '('; auto ¶ms = function.get_function_params (); diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h index a5a99f2b03e..1bbefb38454 100644 --- a/gcc/rust/ast/rust-ast-dump.h +++ b/gcc/rust/ast/rust-ast-dump.h @@ -97,6 +97,9 @@ private: std::ostream &emit_indented_string (const std::string &value, const std::string &comment = ""); + // Emit formatted string for generic parameters. + void emit_generic_params (std::vector> ¶ms); + // rust-ast.h void visit (Token &tok); void visit (DelimTokenTree &delim_tok_tree); From patchwork Tue Feb 21 12:01:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59970 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1826976wrn; Tue, 21 Feb 2023 04:13:00 -0800 (PST) X-Google-Smtp-Source: AK7set97lx+vo1rjl/cc5qU7Bb4G3neA9nYnKD3VGIt0fu9mF7aM46pdEjVokyAjzM3zUABUWB6G X-Received: by 2002:a05:6402:18e:b0:49b:7416:e3ff with SMTP id r14-20020a056402018e00b0049b7416e3ffmr3038709edv.5.1676981580768; Tue, 21 Feb 2023 04:13:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981580; cv=none; d=google.com; s=arc-20160816; b=v74KNfvGPRC5B+PRVPfz0CgbIARFFOPlSV+mIDoLt6qXvjQ9OxDJx4nWeYsmFa3biA ZjLxEwrOpPuSDCMkUnvDYaSG8di2rfyW10gXzB2lzOkNkv3iKKMpayy8c/jKrGupFJtY aWA7l5h/U8o4MXaFW9CWsVxbK8CyrvGrcA1PadCUGVt3gLfMSzeSvNGq0kZK4oMYRJnK rkXQ5sVSw0aSrPC/7b31WnHozEcv4540SdkjOU55uYwkDoXcGK+w9y8ikU7mJS5MKH1y kZjjvJpTSSFNOZ6huZuqjWHvDF5cG5B23uLDMQpmpGBSRVozFDu0rvr4+qZpYJ1AddSP 0U9g== 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=tJwh/YmAJ2py2ku/xMA2IypoS6a5fFPBtjWDiCL6jqA=; b=UDjByQw2I+JrGbkfuu84Vbj4zrq9+3uTAOidM6UBunTHmlRVM5eRWugZTWKhlkoKMQ QZTOx6nXLnszc6Fje68uoQublw7IVkDr4S+hP8IYZWGnFq6MtqflFUNcx6UFyXUmr7yE rfQ/DHkV0NLjST6ED2GgF58Dc998/zKD3xVVC/+spDE3lvXEIlEU0hKsq/lj2wT/qM+4 p+jWqEuN1kFgzEY/tsJ899VChBHXOfuX6FlaRREkagXvf6zwRAMqw3r2vKhl3L5DUQ+A UNcyNdOX+TDZ3xvp2Tf18EbGaTX0AjEOkca71zfvnDiTo33jCNhMbRWH/EB10/i0R7Yd kAVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@embecosm.com header.s=google header.b="bOYiDb/+"; 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 p8-20020aa7d308000000b004acc183f530si929520edq.229.2023.02.21.04.13.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:13:00 -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=fail header.i=@embecosm.com header.s=google header.b="bOYiDb/+"; 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 9AE663954C6D for ; Tue, 21 Feb 2023 12:06:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 854D838493F8 for ; Tue, 21 Feb 2023 12:03:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 854D838493F8 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-x42e.google.com with SMTP id o4so4163460wrs.4 for ; Tue, 21 Feb 2023 04:03:35 -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=tJwh/YmAJ2py2ku/xMA2IypoS6a5fFPBtjWDiCL6jqA=; b=bOYiDb/+tt7Um9tX49L7IGLB7hCkKyWvmjdot6mTU8naCZvVUsRNRT+tGdnoB1Mfnz f2SNEY88E6IGY2G7FG/za0sRgcJPZ+6rDK+EeRuwcMPycijw1H+zaMaAvdoCYheMTe2h TPxuQClX0pX4eaBKsfQypilV9lAsceBcVhMtlk1pDQ1I+bjZ+jq+4AgTOzZSNE+UYHLJ EZnQBWnVWp0g7olBbEWMTsPmk0DefatYFpt2kKdhRB3fQKMvLm2IxPMCcedqfSkv55WH 1br3mNIm15U6aQlBhhyO1NWt3RY77BM48nuwiIWGxVTqGC/4ZWhpGAngal7WlrztBd6+ FkHg== 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=tJwh/YmAJ2py2ku/xMA2IypoS6a5fFPBtjWDiCL6jqA=; b=MSAUdV+p3J05S4Z69XfwYbfaYYGYq4pNWUDQ5QFbtXuoxF3KMZINRwcM79+An6zDos dvasqn9proxjh+YSBxSeAwNbJyhRwTU7VofwKqnJ/JJGcPjDdSTKTN2A7oVYE470QifI oOVMzNBUUG4SX9W8+SLOEypUQ32/Q21ZOSsmVVf2QMclKS/neP64wwAcMm8H7wBvts+t BVmcVp/aNyGwUjHtFyjJ4X9xT2KScWsGHRi72zvOuHEMzO72lJYCVJSHp2vbG11b9Avv MfdsszYLgo8BJ0fCTuOx35bj3H5JapGlRtAnINkhtHk17yO8cBboeAsGHbl+9Gz+0yQ8 BjPg== X-Gm-Message-State: AO0yUKV8Y2tyvDDOoNin8+y4iu35pvL5Tn8wfwk6OVXTcYAjuzlvuVGF kb+BRLSQIm3JRAs3awDMX/NZg7mnVd79pBwTcw== X-Received: by 2002:adf:e9c7:0:b0:2c5:7c26:c2cc with SMTP id l7-20020adfe9c7000000b002c57c26c2ccmr3926694wrn.29.1676981014144; Tue, 21 Feb 2023 04:03:34 -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.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:33 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, David Faust Subject: [committed 013/103] gccrs: ast: dump: add format_{tuple, struct}_field helpers Date: Tue, 21 Feb 2023 13:01:03 +0100 Message-Id: <20230221120230.596966-14-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=ham 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?1758442637985767229?= X-GMAIL-MSGID: =?utf-8?q?1758442637985767229?= From: David Faust gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::format_tuple_field): New. (Dump::format_struct_field): New. * ast/rust-ast-dump.h (format_tuple_field): New. (format_struct_field): New. --- gcc/rust/ast/rust-ast-dump.cc | 17 +++++++++++++++++ gcc/rust/ast/rust-ast-dump.h | 6 ++++++ 2 files changed, 23 insertions(+) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index b192556647c..6f2f81630b0 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -156,6 +156,23 @@ Dump::emit_generic_params (std::vector> ¶ms) stream << ">"; } +void +Dump::format_tuple_field (TupleField &field) +{ + // TODO: do we need to emit outer attrs here? + emit_visibility (field.get_visibility ()); + field.get_field_type ()->accept_vis (*this); +} + +void +Dump::format_struct_field (StructField &field) +{ + // TODO: do we need to emit outer attrs here? + emit_visibility (field.get_visibility ()); + stream << field.get_field_name () << ": "; + field.get_field_type ()->accept_vis (*this); +} + void Dump::visit (Token &tok) {} diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h index 1bbefb38454..2da2736c95b 100644 --- a/gcc/rust/ast/rust-ast-dump.h +++ b/gcc/rust/ast/rust-ast-dump.h @@ -100,6 +100,12 @@ private: // Emit formatted string for generic parameters. void emit_generic_params (std::vector> ¶ms); + // Format a single field of a tuple. + void format_tuple_field (TupleField &field); + + // Format a single field of a struct. + void format_struct_field (StructField &field); + // rust-ast.h void visit (Token &tok); void visit (DelimTokenTree &delim_tok_tree); From patchwork Tue Feb 21 12:01:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59972 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1827824wrn; Tue, 21 Feb 2023 04:14:57 -0800 (PST) X-Google-Smtp-Source: AK7set99iltsJi5Zonj0cD0t2Nr5ZE3z9w/wdNSc6ahrIXRwwBjlm5P2t5itYTzaySqdtKCK/IV5 X-Received: by 2002:a17:906:af10:b0:8aa:c038:974c with SMTP id lx16-20020a170906af1000b008aac038974cmr11919857ejb.54.1676981697080; Tue, 21 Feb 2023 04:14:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981697; cv=none; d=google.com; s=arc-20160816; b=hrXaA/e5hggQOq3vSYuVJmw1OXLtWHJ0ZY7NS4glC8LSQXoB5Y06wwBh2QPiW+gon1 sHcJhkS/U0AoIGZmJ1kCHjUKH23p8AG6g42AhcH2dFBFx5R9ctCMr0WXwe71pwtHWu90 aEOBpnhgvqOMQVfzMscCmR4QIaTyrwxqr5VRcctUIJ7wkKiI/P7F+taQEfUpOBrq/5wQ XMM+SlKLaw2T5utbEYNryKAhLNnDaLFQFeGgdDbSWmlcQjaswlkxFjIJzfPy63OEHO95 Ha7wXuIJc82KnT1FsrDiaHu0v1OJ5Q+subQvmUUckZQdMpR/CXHZISYVmLkSrHdlTgJG 5A2g== 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=VPoZB0P7NXPdmRarj5QWxhLM4hB1pT7x7XSIrJO7pmc=; b=df/2K0/KtqGB6JuvmZot7P42Hj6u3lxezEsu0jNdp7Mg2nj/bCO/TmtMpzm9JYxCbo NG86uNiHGjvi7WjG5kKWLATBu1OCGKWgvb2KWoX/wLZr4m8QEY2YGQkt5IZJKP9af9KE q37RKLidy0pawY5rrretVP9XR17Y8eNg+ZvhVK/A6OWzHYrBSj2/uoJZz8nqZXe/uDmn ZwoEbsGX02pF9BmXiaBOO+nYfiuNqu3KZr/w1AsduMQWzXLlYy2ENWiwfHYdmj5JT2MP CpCqcbxkAp4RPvGYzSb/vJc1kxA1enhHt3kBnIEzSME1M0Vz64JoUQDsCKrnSv1QyooI H41w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=FKywTj1Q; 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 h12-20020a170906530c00b008c3baa1f86asi11843913ejo.851.2023.02.21.04.14.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:14:57 -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=FKywTj1Q; 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 11D11395A43A for ; Tue, 21 Feb 2023 12:07:23 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 57C3D384F4AF for ; Tue, 21 Feb 2023 12:03:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 57C3D384F4AF 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-x42e.google.com with SMTP id j2so3981375wrh.9 for ; Tue, 21 Feb 2023 04:03:36 -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=VPoZB0P7NXPdmRarj5QWxhLM4hB1pT7x7XSIrJO7pmc=; b=FKywTj1Q6/Iy3g43h49UDGw73doDc5cSaT4Q2V32WZQ4fOadD962koLffyGarofgMd wSrhnfCQZTnmY9BBwcu+LFnJVXq+gMa//EqHIolPLc6YkDYxlVix2kHX5Y9BLdZx4Orr 4uhqYX8aAp5CGZD8juRtKnmg6euwG3ygFamliEJdg4h8dzXn0xJC9M5pkKn61XiojyoV qrE4v/8RAbt4nPO8QYJJQelYymfKWCvoccyol8eHHK44vhYI+uGlcJRQ5M192hgzOe4m Aw1xxfwJiMafzahfrEt0UUaoY06nV/ACQTxRtcweJOfQpsfIyPEGP4yWOMvDrTqQkscq p+Eg== 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=VPoZB0P7NXPdmRarj5QWxhLM4hB1pT7x7XSIrJO7pmc=; b=rp28jLw0q8MVF4xi0Bs94nbrX5w8e9sd+QdL71a9sM7yA+cyjuLBjDBnvGvNBBu/bL taD9cqRlmnKVe++ZTNhVEiHdM6haHFAE0rTvVLCxvNM51iM6H+shRJ3Y/6WUXvvZAgod wBCLLRlB69WMWsgqFRO9uz+K4CIPtRQPJc5NjAdd6O284ktMy9ujk4cOfeba949Z95H0 Y5RQCUvCb/bh1QmC1RQTR9bV+xGyUkiG2PpHK3iPW05LjaBTiulMROPQJhLgrpJW/Sql iShGKfn3ZMDVK0iDidO6QTT641tWv08LyLZyxYI4eSB1B5UP6//jxyC5iyrPRdmLkXD2 gzFg== X-Gm-Message-State: AO0yUKWDkF5rQ824cXT/7i++O+ptxREkzfBS79VKYOmsDVt19FNqkUN7 fjNSahsG6meqpYvkfKJN3T6FNlkb4DogMQ+jSQ== X-Received: by 2002:a5d:404d:0:b0:2c5:a07e:55e1 with SMTP id w13-20020a5d404d000000b002c5a07e55e1mr4353134wrp.17.1676981014875; Tue, 21 Feb 2023 04:03:34 -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.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:34 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, David Faust Subject: [committed 014/103] gccrs: ast: dump structs, enums and unions Date: Tue, 21 Feb 2023 13:01:04 +0100 Message-Id: <20230221120230.596966-15-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=ham 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?1758442760138762513?= X-GMAIL-MSGID: =?utf-8?q?1758442760138762513?= From: David Faust gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Fill empty functions for structs, enums and unions. --- gcc/rust/ast/rust-ast-dump.cc | 135 ++++++++++++++++++++++++++++++++-- 1 file changed, 127 insertions(+), 8 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 6f2f81630b0..7cbdfa21fcb 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -750,35 +750,154 @@ Dump::visit (TypeAlias &type_alias) void Dump::visit (StructStruct &struct_item) -{} +{ + stream << "struct " << struct_item.get_identifier (); + if (struct_item.has_generics ()) + emit_generic_params (struct_item.get_generic_params ()); + + // FIXME: where-clause + + stream << " {"; + + auto &fields = struct_item.get_fields (); + + indentation.increment (); + for (auto &field : fields) + { + stream << '\n' << indentation; + format_struct_field (field); + stream << ','; + } + indentation.decrement (); + + if (fields.size () > 0) + stream << '\n' << indentation; + stream << "}\n"; +} void Dump::visit (TupleStruct &tuple_struct) -{} +{ + stream << "struct " << tuple_struct.get_identifier (); + if (tuple_struct.has_generics ()) + emit_generic_params (tuple_struct.get_generic_params ()); + + // FIXME: where-clause + + stream << '('; + + auto &fields = tuple_struct.get_fields (); + if (fields.size () >= 1) + { + format_tuple_field (fields[0]); + for (size_t i = 1; i < fields.size (); i++) + { + stream << ", "; + format_tuple_field (fields[i]); + } + } + stream << ");\n"; +} void Dump::visit (EnumItem &item) -{} +{ + stream << item.get_identifier (); +} void Dump::visit (EnumItemTuple &item) -{} +{ + stream << item.get_identifier () << '('; + auto &fields = item.get_tuple_fields (); + if (fields.size () >= 1) + { + format_tuple_field (fields[0]); + for (size_t i = 1; i < fields.size (); i++) + { + stream << ", "; + format_tuple_field (fields[i]); + } + } + stream << ')'; +} void Dump::visit (EnumItemStruct &item) -{} +{ + stream << item.get_identifier () << " {"; + + auto &fields = item.get_struct_fields (); + + indentation.increment (); + for (auto &field : fields) + { + stream << '\n' << indentation; + format_struct_field (field); + stream << ','; + } + indentation.decrement (); + + if (fields.size () > 0) + stream << '\n' << indentation; + stream << '}'; +} void Dump::visit (EnumItemDiscriminant &item) -{} +{ + stream << item.get_identifier () << " = "; + item.get_expr ()->accept_vis (*this); +} void Dump::visit (Enum &enum_item) -{} +{ + stream << "enum " << enum_item.get_identifier (); + if (enum_item.has_generics ()) + emit_generic_params (enum_item.get_generic_params ()); + + // FIXME: where-clause + + stream << " {"; + auto &variants = enum_item.get_variants (); + if (variants.size () >= 1) + { + stream << '\n'; + indentation.increment (); + for (auto &var : variants) + { + stream << indentation; + var->accept_vis (*this); + stream << ",\n"; + } + indentation.decrement (); + } + + stream << "}\n"; +} void Dump::visit (Union &union_item) -{} +{ + stream << "union " << union_item.get_identifier (); + if (union_item.has_generics ()) + emit_generic_params (union_item.get_generic_params ()); + + // FIXME: where-clause + + stream << " {"; + indentation.increment (); + for (auto &field : union_item.get_variants ()) + { + stream << '\n' << indentation; + format_struct_field (field); + stream << ','; + } + indentation.decrement (); + + stream << '\n' << indentation << "}\n"; +} void Dump::visit (ConstantItem &const_item) From patchwork Tue Feb 21 12:01:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59968 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1826716wrn; Tue, 21 Feb 2023 04:12:20 -0800 (PST) X-Google-Smtp-Source: AK7set//yxE7sdTbbqbHhYnccVjBCCoJzRY5CNnKMP/EJooBwEwppcFFn8byXrraihBSvo+4rwEy X-Received: by 2002:aa7:d347:0:b0:4a2:4ed3:c151 with SMTP id m7-20020aa7d347000000b004a24ed3c151mr4757047edr.39.1676981540908; Tue, 21 Feb 2023 04:12:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981540; cv=none; d=google.com; s=arc-20160816; b=Pu8UGiTbhpSsbBqG6KmTlwkU3/gAvtdi7aXUwDe4jiJe9dzCPNs7kuz1FioqJ/lUV+ bYMyxBp2hxr+9ZOUknebFZWFinsGa5ScOmIgrYXSn5/WuElN+9GsPNM7kDwNQnEd0dSB xCLMhfgKMND18bFF3ybOXSzsWuY1lxAplC0QUWuYIUSExJhkOmbXnfRyuPUQg/L63RvT h1HsTd/q0kJbbeyaYChDfYDM5WBtzNyrKV5sdfjJg4/EJ2m+WcdcNMxcTqYKbM4ojc3T u9kKDd5S3dnTwMuUtgvtavH45/CpOzptKTkvw+q98vKh6e39U1YJ8cQWcW7QtaUDVIUu p40g== 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=wlIGld7I7N2rxYXmhrMc0SdS9t1SlMANLJLEt/RxdnA=; b=f6h69AhiDUCV3tgZj5hqFW9SrDD9N6my9jFb5ePPv2ZhZWaET+j1nS1A8YZgP96vvw h9KfzoTVdwoOMX1dxxOHy6oWCw2RpRP1eAa//B3nxCahe+WJZPQ6OMgfvwAAxVlmjs9K 9umfgfITbALDzHHfpkZY9rT16Ud6OYe5bJ1AECA7tam4L1d8q95VM0IsP0NF5511yjYo gb8ufe6ybvfD09blPyFQuFGH5HtOYoDil2LF21fiTF5WSmZNMTmDh4zvXNrxtyxFTvZN YppQ7lDvEhRN000CHizk0K0NPh3DK+SMapbNa1qHUlhYuw8+H0zO6teaAo5B0rtQpVyL OjdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=V2vbMMkV; 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 c20-20020aa7c754000000b004ace1d19cb9si18033778eds.361.2023.02.21.04.12.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:12:20 -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=V2vbMMkV; 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 B799738A9091 for ; Tue, 21 Feb 2023 12:06:23 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 7A3AA385B53C for ; Tue, 21 Feb 2023 12:03:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7A3AA385B53C 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-x432.google.com with SMTP id c5so4848457wrr.5 for ; Tue, 21 Feb 2023 04:03:36 -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=wlIGld7I7N2rxYXmhrMc0SdS9t1SlMANLJLEt/RxdnA=; b=V2vbMMkVjUNOydlfgaxmNuwNX74FHomxYLZKqPiN2eoDvIAqnXoQAeLabv7Xc732TA bJNE8UCWrA/v4WAWivJpJVtXyBrIpRRXr7CYmEd53TWG0keju5x18vJw4mROe/WDQTL2 FCONfKAnSN3dxPZjXG4IjDEyQav1b2PPPrtX8VC9S0sZrn5kpZH1A6+DxZs43FqLgr8E FPaIyuUB6c/DNnrBiWFNUvjZxBqnlpeQwzOQiMM8les/EqOylx9Vgx7R6J/4QPi/J9CV qgosU7MnkHoHwTcI/UcMSIg69ket1gnz8x/LMpcsgYR/3wGDJYLSvWdbj6kkJQfNzwC8 1y4A== 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=wlIGld7I7N2rxYXmhrMc0SdS9t1SlMANLJLEt/RxdnA=; b=JQmfw4j8PK4U9QOy2gM8WdSohtCamE1bSrCbE759yZVa5iXXbdYAt5Q0tbAKuRwLux +j4JMA0cQYC+RMZoR489lSy51OXzWO1ajA2zpguLwhP7sDaVya/FfcoLXIDDLa1YvqA4 oN1/+jIU4Pd5RnbNLnx32yloX25pEW8YEBA2/ofCQWWkBeQj+Mog8v2E9m0uWQLup3ua tGk8LFjIB4wCeGhj6l9qRw0QEnONp+P1n1x43u0pqh4dSYY86ZQ5+LMbO9OvX48/zbZU DVSCsBVNq4EWxWt7k++DZ7Azm0qgZDvlH3Ik0484yfbyyBHZG6PCalWRyMKgEVdHxjio k4lA== X-Gm-Message-State: AO0yUKX41qT69LrmYuUEzcw5Sfk4h+S/CQyUZ6dvTuiFctioMP3wUi5a SGW+uUshQTzZKGizldCXHRayqDDSzc15j7707w== X-Received: by 2002:a5d:5045:0:b0:2c5:8a5a:fc01 with SMTP id h5-20020a5d5045000000b002c58a5afc01mr4263468wrt.11.1676981015773; Tue, 21 Feb 2023 04:03:35 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:35 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 015/103] gccrs: intrinsics: Add data prefetching intrinsics Date: Tue, 21 Feb 2023 13:01:05 +0100 Message-Id: <20230221120230.596966-16-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?1758442596707914801?= X-GMAIL-MSGID: =?utf-8?q?1758442596707914801?= From: Arthur Cohen gcc/rust/ChangeLog: * backend/rust-builtins.cc (BuiltinsContext::setup): Declare prefetch intrinsics. * backend/rust-compile-intrinsic.cc (enum class Prefetch): Add kinds of prefetch intrinsics. (prefetch_data_handler): New function. (prefetch_read_data): Likewise. (prefetch_write_data): Likewise. gcc/testsuite/ChangeLog: * rust/execute/torture/prefetch_data.rs: New test. --- gcc/rust/backend/rust-builtins.cc | 6 ++ gcc/rust/backend/rust-compile-intrinsic.cc | 97 +++++++++++++++++-- .../rust/execute/torture/prefetch_data.rs | 17 ++++ 3 files changed, 111 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/rust/execute/torture/prefetch_data.rs diff --git a/gcc/rust/backend/rust-builtins.cc b/gcc/rust/backend/rust-builtins.cc index 14dc037edac..d6f8cb6f495 100644 --- a/gcc/rust/backend/rust-builtins.cc +++ b/gcc/rust/backend/rust-builtins.cc @@ -92,6 +92,12 @@ BuiltinsContext::setup () build_pointer_type (void_type_node), size_type_node, NULL_TREE), 0); + + define_builtin ("prefetch", BUILT_IN_PREFETCH, "__builtin_prefetch", + "prefetch", + build_varargs_function_type_list ( + build_pointer_type (const_ptr_type_node), NULL_TREE), + builtin_const); } static void diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc b/gcc/rust/backend/rust-compile-intrinsic.cc index 616919677c9..a418b863210 100644 --- a/gcc/rust/backend/rust-compile-intrinsic.cc +++ b/gcc/rust/backend/rust-compile-intrinsic.cc @@ -17,6 +17,7 @@ #include "rust-compile-intrinsic.h" #include "rust-compile-context.h" #include "rust-compile-type.h" +#include "rust-compile-expr.h" #include "rust-compile-fnparam.h" #include "rust-builtins.h" #include "rust-diagnostics.h" @@ -28,6 +29,8 @@ #include "fold-const.h" #include "langhooks.h" +#include "print-tree.h" + namespace Rust { namespace Compile { @@ -44,6 +47,15 @@ wrapping_op_handler (Context *ctx, TyTy::FnType *fntype, tree_code op); static tree copy_nonoverlapping_handler (Context *ctx, TyTy::FnType *fntype); +enum class Prefetch +{ + Read, + Write +}; + +static tree +prefetch_data_handler (Context *ctx, TyTy::FnType *fntype, Prefetch kind); + static inline tree rotate_left_handler (Context *ctx, TyTy::FnType *fntype) { @@ -70,18 +82,32 @@ wrapping_mul_handler (Context *ctx, TyTy::FnType *fntype) { return wrapping_op_handler (ctx, fntype, MULT_EXPR); } +static inline tree +prefetch_read_data (Context *ctx, TyTy::FnType *fntype) +{ + return prefetch_data_handler (ctx, fntype, Prefetch::Read); +} +static inline tree +prefetch_write_data (Context *ctx, TyTy::FnType *fntype) +{ + return prefetch_data_handler (ctx, fntype, Prefetch::Write); +} static const std::map> - generic_intrinsics = {{"offset", &offset_handler}, - {"size_of", &sizeof_handler}, - {"transmute", &transmute_handler}, - {"rotate_left", &rotate_left_handler}, - {"rotate_right", &rotate_right_handler}, - {"wrapping_add", &wrapping_add_handler}, - {"wrapping_sub", &wrapping_sub_handler}, - {"wrapping_mul", &wrapping_mul_handler}, - {"copy_nonoverlapping", ©_nonoverlapping_handler}}; + generic_intrinsics = { + {"offset", &offset_handler}, + {"size_of", &sizeof_handler}, + {"transmute", &transmute_handler}, + {"rotate_left", &rotate_left_handler}, + {"rotate_right", &rotate_right_handler}, + {"wrapping_add", &wrapping_add_handler}, + {"wrapping_sub", &wrapping_sub_handler}, + {"wrapping_mul", &wrapping_mul_handler}, + {"copy_nonoverlapping", ©_nonoverlapping_handler}, + {"prefetch_read_data", &prefetch_read_data}, + {"prefetch_write_data", &prefetch_write_data}, +}; Intrinsics::Intrinsics (Context *ctx) : ctx (ctx) {} @@ -515,5 +541,58 @@ copy_nonoverlapping_handler (Context *ctx, TyTy::FnType *fntype) return fndecl; } +static tree +prefetch_data_handler (Context *ctx, TyTy::FnType *fntype, Prefetch kind) +{ + rust_assert (fntype->get_params ().size () == 2); + + tree lookup = NULL_TREE; + if (check_for_cached_intrinsic (ctx, fntype, &lookup)) + return lookup; + + auto fndecl = compile_intrinsic_function (ctx, fntype); + + // prefetching isn't pure and shouldn't be discarded after GIMPLE + TREE_READONLY (fndecl) = 0; + TREE_SIDE_EFFECTS (fndecl) = 1; + + std::vector args; + compile_fn_params (ctx, fntype, fndecl, &args); + + if (!ctx->get_backend ()->function_set_parameters (fndecl, args)) + return error_mark_node; + + enter_intrinsic_block (ctx, fndecl); + + auto addr = ctx->get_backend ()->var_expression (args[0], Location ()); + auto locality = ctx->get_backend ()->var_expression (args[1], Location ()); + + mpz_t zero; + mpz_t one; + mpz_init_set_ui (zero, 0); + mpz_init_set_ui (one, 1); + + auto rw_flag_value = kind == Prefetch::Write ? one : zero; + auto rw_flag + = ctx->get_backend ()->integer_constant_expression (integer_type_node, + rw_flag_value); + auto prefetch_raw = NULL_TREE; + auto ok + = BuiltinsContext::get ().lookup_simple_builtin ("prefetch", &prefetch_raw); + rust_assert (ok); + auto prefetch + = build_fold_addr_expr_loc (Location ().gcc_location (), prefetch_raw); + + auto prefetch_call + = ctx->get_backend ()->call_expression (prefetch, {addr, rw_flag, locality}, + nullptr, Location ()); + + ctx->add_statement (prefetch_call); + + finalize_intrinsic_block (ctx, fndecl); + + return fndecl; +} + } // namespace Compile } // namespace Rust diff --git a/gcc/testsuite/rust/execute/torture/prefetch_data.rs b/gcc/testsuite/rust/execute/torture/prefetch_data.rs new file mode 100644 index 00000000000..dc049b136dd --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/prefetch_data.rs @@ -0,0 +1,17 @@ +#![feature(intrinsics)] + +extern "rust-intrinsic" { + fn prefetch_read_data(addr: *const T, locality: i32); + fn prefetch_write_data(addr: *const T, locality: i32); +} + +fn main() -> i32 { + let a = [1, 2, 3, 4]; + + unsafe { + prefetch_read_data(&a, 3); + prefetch_write_data(&a[0], 3); + } + + 0 +} From patchwork Tue Feb 21 12:01:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59969 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1826804wrn; Tue, 21 Feb 2023 04:12:33 -0800 (PST) X-Google-Smtp-Source: AK7set9fFpmyhEjzjKqYFnCPG5TWLShyLzk9TL7B+NoLn3U71H1715LaQcBBXvSHqUmGd6OGBTVG X-Received: by 2002:aa7:d5c9:0:b0:4ad:6db4:b922 with SMTP id d9-20020aa7d5c9000000b004ad6db4b922mr4853175eds.14.1676981553288; Tue, 21 Feb 2023 04:12:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981553; cv=none; d=google.com; s=arc-20160816; b=mequPJCBn8iZGUWYwI3VnjvqwQunyz7W476QnoCSgH2/W7qPsk94wX+TaxcMNN7vCT Rd5+1WTIlu6qaJgZlNEw7lkJNb/argtcNa2KXzBOZjIlyVdlC+ckF8vkSmBXqV+6k5QX JliYQX2PxV2rOwLPLFbNTynQYWJUZ/6V3V/26vy39e1RBVcc4/nbk2gWNejyTTEVe19v AIrGI1x7RgzPfKJXRp3i8x3Qfq8Tdh2L7da2DLLAZzM+VzYLIm1ZnLE6At1Y9RVR5FpM WPpFKP4i8tBHKP69xwm3QRb2e6Gp6suKAY/KBDtzocUm6zoZVZ7kWb60XWfTqWIijpyQ gtIQ== 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=3DSDX42u7UBLloU8IjNfd1l6UUlH+44+y1aYaZdS/E8=; b=O0IEhQt5tMV0BJkMyvBUJUu1UbP2vhCkiD1O89CojfwzuLXhl5Mi5nNws+k+llHbcW M2uyxagCtA5vNbqyXeWXkeQ09euo6Ezl4vYzyLm9lkhkpULS85Ii1dkTmHyhkZAx9COL wRetfYGPBiAsqdH2ELT1f7xpkMYnryJ7qfxxnTq+LZOD/VY4oIvFYnuKMV6FCEGhLMSa IMlZOB6Hj1+FOye9gwInrWj9oTgMue7MhWzMHugRbdDbpKSzZrkOgqzSygR8uYvaU+Rb 6sW4mcpqrIlM02azU8E1ZVnWZ1FKlfsP5ekYSR/iGbWyquD0njpkj5QTJimEKeKSpQVB eOig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=VT1p5UxS; 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 by11-20020a0564021b0b00b004acdbd726cbsi4586058edb.7.2023.02.21.04.12.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:12:33 -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=VT1p5UxS; 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 B66CF383817F for ; Tue, 21 Feb 2023 12:06:27 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 17845384692A for ; Tue, 21 Feb 2023 12:03:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 17845384692A 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 bo30so3601255wrb.0 for ; Tue, 21 Feb 2023 04:03: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=3DSDX42u7UBLloU8IjNfd1l6UUlH+44+y1aYaZdS/E8=; b=VT1p5UxSt49/umGiKmHngU5aMVhAg/zOdd7gk9a94lBGcx+3EjwNQ0k2TCKbqdlTvR 4K7Jv4phyXYciWDHNKsf3HJnB2XM71vBhnJj3YVKTX2kyEfPRBLoqbROzJLClzjz7S4c R3Lwl19v3nbEcdiyuIwh7gQgZC6t2iYEBjiC6HKMhDsxpCRoh8mVhmwp55UtQxYD7jOQ dYu8BUc/fLS70yEmMQ5aYdYM5iMf81a0fZ5aBKNhckoULviZFL8QoPM6rgUJ59FWm1L2 12YNLszVjWM3xuEqpdYjcx/NbyoJjZEZLUm8iPmNrbf+4/Cc+s1CNIDIt7VzQdibs6si t96A== 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=3DSDX42u7UBLloU8IjNfd1l6UUlH+44+y1aYaZdS/E8=; b=3sEE5uH7ZT9IrgKklAh6FVV7kJx3wA/6b2cmtVanMn80tKHNXTgB5kuH7ul8vGzDcP bb8OqT3J5av3lqIsWgM8Hpd6pX2v/7/9VdJaZX+ICRqNnlal1nhI0KJIixeQPt/Lillj rHWRtl+TuWkx38oiS5gb1MDWysxPcAD11X+RTkmsNCAtHnNup3Omirfcd/aOW7feUMr9 hvEbi8FTPdPOW0SmsRmY0WGxkN99ltdRY+O38/fmLNsLoSWohn/2G38kSh8VNCp3UAWD GFQG2jJX/AUAAtn/zyVYZGN5DsIhaXYG8kEk1qo0G8UmOaVWFDJccTaLTzBl0rVHD7fm tu6A== X-Gm-Message-State: AO0yUKVSzAJXJckPRMQguJFkMEwnzw3BqtkLC4NlelDm0cuTu2dBksBi sN09bw0ke81odxsZGsphRfX09lJzHDrfHOb/6g== X-Received: by 2002:adf:d84b:0:b0:2c5:48b9:7307 with SMTP id k11-20020adfd84b000000b002c548b97307mr4225392wrl.64.1676981016530; Tue, 21 Feb 2023 04:03:36 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:36 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, =?utf-8?q?Marc_Poulhi=C3=A8s?= Subject: [committed 016/103] gccrs: fix ICE on missing closing paren Date: Tue, 21 Feb 2023 13:01:06 +0100 Message-Id: <20230221120230.596966-17-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?1758442609544542347?= X-GMAIL-MSGID: =?utf-8?q?1758442609544542347?= From: Marc Poulhiès Fix crash (segfault) on a missing closing parenthesis when parsing the expressions in a block. The returned `expr` was missing a check before being used. Add corresponding test. Signed-off-by: Marc Poulhiès gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_stmt_or_expr_without_block): Check if `expr` is valid after parsing it. gcc/testsuite/ChangeLog: * rust/compile/missing_closing_paren.rs: New test. --- gcc/rust/parse/rust-parse-impl.h | 15 +++++++++++---- .../rust/compile/missing_closing_paren.rs | 3 +++ 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/rust/compile/missing_closing_paren.rs diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 72207a1bc22..a4a912f8c1d 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -11738,10 +11738,17 @@ Parser::parse_stmt_or_expr_without_block () // must be expression statement lexer.skip_token (); - std::unique_ptr stmt ( - new AST::ExprStmtWithoutBlock (std::move (expr), - t->get_locus ())); - return ExprOrStmt (std::move (stmt)); + if (expr) + { + std::unique_ptr stmt ( + new AST::ExprStmtWithoutBlock (std::move (expr), + t->get_locus ())); + return ExprOrStmt (std::move (stmt)); + } + else + { + return ExprOrStmt::create_error (); + } } // return expression diff --git a/gcc/testsuite/rust/compile/missing_closing_paren.rs b/gcc/testsuite/rust/compile/missing_closing_paren.rs new file mode 100644 index 00000000000..895c3133c3b --- /dev/null +++ b/gcc/testsuite/rust/compile/missing_closing_paren.rs @@ -0,0 +1,3 @@ +fn foo() { + (""; // { dg-error "unexpected token .*" } +} From patchwork Tue Feb 21 12:01:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59982 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1830160wrn; Tue, 21 Feb 2023 04:20:34 -0800 (PST) X-Google-Smtp-Source: AK7set+zjbVdfUOcwOxPviCkxVMQmDUGXdpAKK1x5D69Re4HqxYaYreBVxM8n6WwdObTQDl1jS69 X-Received: by 2002:a17:907:80e:b0:7c1:6e08:4c20 with SMTP id wv14-20020a170907080e00b007c16e084c20mr18088223ejb.7.1676982034838; Tue, 21 Feb 2023 04:20:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982034; cv=none; d=google.com; s=arc-20160816; b=UgmLCbS4fKxst6Us5UfSmc75/hBXXIOmjK3mvnC6QG2Hfsw/h184xkSPx9YmCaFBwy 3+vMeBT4tJnS23EqEzBC33i2ut950Nj4FpN6nOrYZom5h/CX0qVayoeEKmSGudkDhtda ijd5APP2IKJGkgKyYZUDLm8a+mlh1PTwzsqx07oU5iM078GjxPjKdywIYNUj34eMJj4r mGRkts7ksxxtc8wqP256GIK03tcxXAqkiM21SXYWVSORtbHXOfZt1DhvqieyEIjxGNk7 I2Js9uvbxurLduWlScxyobo9pUJ9V5iUbLiSaka3tv6ioMfVLjTkJYBJGY9CEj7bJBkK sMMg== 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=XCfXLfwt/nylHF8oGosbCMkCQaynuY55Hg6q7BdHAtQ=; b=kzjykcDUTW43BCaEklHq9gIOR28zQktROrA/1An2mWVl6kiXJbgSnTV9eMY0v1LbJN dWNlpiK/uQ/V4JQkPLiyUxXf/nrFJBPaXKr4qvj1vz4BEQRdbI60b2stB0vrPXsTaJHg 1tVlVlSQFfNRsYwcfrSx2IO8s4ksfBOdL3Gin2Ad6qI9z8CyuAQpGAv1Dz70vU2xOWTr RjQ/jdZYfGsKWDeijFegSkraiu+MUFKbSvscRZKATuLjezZA9FWRrmVGj5GwUbaceQzQ XGwE6gpI3Ud3fUh1jDtEb0VLCVyUwpApmKqoflOs6XiTbJ64zclu+mulaG7jVrVj3nHe SR4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=W4alW4nW; 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 j19-20020a170906105300b008b14fa7ded2si22982576ejj.777.2023.02.21.04.20.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:20:34 -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=W4alW4nW; 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 164D93898382 for ; Tue, 21 Feb 2023 12:08:59 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id CA4963844745 for ; Tue, 21 Feb 2023 12:03:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CA4963844745 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-x330.google.com with SMTP id bg37-20020a05600c3ca500b003e21e018039so4144924wmb.3 for ; Tue, 21 Feb 2023 04:03: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=XCfXLfwt/nylHF8oGosbCMkCQaynuY55Hg6q7BdHAtQ=; b=W4alW4nWD/WY6ergH1LirkWHZ1gP8frNyi0ensu0fSuLyJkTFE/BLetZmVSQFst866 ZlQB1jWtYCPENDwa+Zhr2Yj7N3UKhMSyAFDuyiXEeXdafX/kmlRWXmIgxfsQBq7B7f44 BT44e1s9X2oOtMDH9Pox3rE4pYNMsD3Wb/YV1AWJknCYJFqFV+jaqVgKCL/4pVULPaUq 6bvaPpWXpCY1zz45arVNcqappNJdqtIS8bjQykr/hmBIAbxJy8nzMaFig0h0ZPRa4uLa 126avKt58hW+imWa+5Voo6khG8/RdBaGLN8yFqNddbihWx8IF5rJJjJr/WFdysRTWkks O0vw== 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=XCfXLfwt/nylHF8oGosbCMkCQaynuY55Hg6q7BdHAtQ=; b=Umfvq/Z1xMbBM3suK98YKtW1zk+mJz6YeEp3Gsalrc7KsuWjb/OA5WuHCTD2SixKhr oIC7/9KyXngibiYLRPK/XjnDdQRjXb7lX96BNvf6TkSiRQZn+8cIom5yt0nMprW6+Rm5 3ZenYzOa4RsgYqIjYS4hA16iDFQns9E8z/H4e2ZKyNMb+OKF1GcjaLnvzWj4DwsrKVSc XyJKNAxD0Nnb8W8Nq+pUDWacvNSy8HmWdBUmbQM2ET8tUV/bPjyD25WEegU4BldEWH3q oUI3R89MPmlO/ipJI3G8SgtmiW/JVppLEv7YlmgfK+2kOADQaZAGHdteR9EaydtWhBkf QEkQ== X-Gm-Message-State: AO0yUKUqBuVBcevguSjYgBoLHXgcpPFvGW70I3l6ij5S2ut8IImEk4+G umcqi/8ZsQPBPQVgqqitviDHNLgvJtYGov8wcg== X-Received: by 2002:a05:600c:2ed3:b0:3dc:2137:d67d with SMTP id q19-20020a05600c2ed300b003dc2137d67dmr3316082wmn.16.1676981017313; Tue, 21 Feb 2023 04:03: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.03.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:36 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 017/103] gccrs: mappings: Add MacroInvocation -> MacroRulesDef mappings Date: Tue, 21 Feb 2023 13:01:07 +0100 Message-Id: <20230221120230.596966-18-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=ham 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?1758443113823565873?= X-GMAIL-MSGID: =?utf-8?q?1758443113823565873?= From: Arthur Cohen gcc/rust/ChangeLog: * util/rust-hir-map.h: Add new mappings. * util/rust-hir-map.cc (Mappings::insert_macro_invocation): Add insertion function into mappings. (Mappings::lookup_macro_invocation): Add lookup function for mappings. --- gcc/rust/util/rust-hir-map.cc | 22 ++++++++++++++++++++++ gcc/rust/util/rust-hir-map.h | 6 ++++++ 2 files changed, 28 insertions(+) diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index 80434489fcd..7ea782ed4c4 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -866,6 +866,28 @@ Mappings::lookup_macro_def (NodeId id, AST::MacroRulesDefinition **def) return true; } +void +Mappings::insert_macro_invocation (AST::MacroInvocation &invoc, + AST::MacroRulesDefinition *def) +{ + auto it = macroInvocations.find (invoc.get_macro_node_id ()); + rust_assert (it == macroInvocations.end ()); + + macroInvocations[invoc.get_macro_node_id ()] = def; +} + +bool +Mappings::lookup_macro_invocation (AST::MacroInvocation &invoc, + AST::MacroRulesDefinition **def) +{ + auto it = macroInvocations.find (invoc.get_macro_node_id ()); + if (it == macroInvocations.end ()) + return false; + + *def = it->second; + return true; +} + void Mappings::insert_visibility (NodeId id, Privacy::ModuleVisibility visibility) { diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h index 474bd5fa229..addd9efc3b0 100644 --- a/gcc/rust/util/rust-hir-map.h +++ b/gcc/rust/util/rust-hir-map.h @@ -269,6 +269,11 @@ public: bool lookup_macro_def (NodeId id, AST::MacroRulesDefinition **def); + void insert_macro_invocation (AST::MacroInvocation &invoc, + AST::MacroRulesDefinition *def); + bool lookup_macro_invocation (AST::MacroInvocation &invoc, + AST::MacroRulesDefinition **def); + void insert_visibility (NodeId id, Privacy::ModuleVisibility visibility); bool lookup_visibility (NodeId id, Privacy::ModuleVisibility &def); @@ -334,6 +339,7 @@ private: // macros std::map macroMappings; + std::map macroInvocations; // crate names std::map crate_names; From patchwork Tue Feb 21 12:01:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59975 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1828766wrn; Tue, 21 Feb 2023 04:17:06 -0800 (PST) X-Google-Smtp-Source: AK7set9vIs6vdU5/r9UVqVWqQCawCnkvMbAZqVeOLP/kcTN3r7dKqMbd98SdO3YCd+fiOjaTIzqH X-Received: by 2002:a05:6402:5484:b0:4ab:f47:c6e8 with SMTP id fg4-20020a056402548400b004ab0f47c6e8mr3343096edb.21.1676981826230; Tue, 21 Feb 2023 04:17:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981826; cv=none; d=google.com; s=arc-20160816; b=02QkPv0Z/zDqYPIlVut1ga/fgiAf4qKkpyiOFHKbHazm3mJlHmVvBEdLUT5yFQGeCs eu6c6JvRRnbRjjZdKS/2K4oW52OvHUVouYKOom8wQlLwE06ZMZtPWJf5F72S0IJ3tHAJ NmBQ2XPy3YVsG7p90we3f2wcn8RJYQPWQUfHasgG+AjD+VVVRcdwmPWOSFtUMILO7eiz hxFjGSUUFGPDdW7Un/AGjVkKYJoAXXLIQlt00ZFxW3boysZaVM9doJjRs1GW54C5sRp2 1vnh3PoOpUOozvLOvMQRD7LnsEGSZDe/fAef1hI5Fbykmx8SudXvg/kGRZlIqi6Wq72Q Y0ww== 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=klE7pGoD1SIEPTpYZuJlAwv0JaPCHEP6htefXjZ+BGA=; b=x9VIm7v20Na7IRmZC0gCoE1jOQtxsyS+4QTryaLsfrDkQ9hSmtDxAbWtfhmWN0Hvt4 GvZL5Rd3zv3j4NByHIgImRbazlJ6/FwVmU8dCnCKehOKhzYCTf2q0xVGp/TZ1rhc65CO W+C/8ruZljUcImwFK1/StDhJW0xXWAdoNY93xlVo5H6g0OZMlOCJWx7TdV388MvIey5f 0VzbrLwvE/29ulFu8hhmaOcI7vBDzssjvLq6fm72Ix9Xpgr5X7Ks6CQk8tjwrV2a4S+x AxHU293yuaabYG7hobpgHQNmzIFTvGOyNgMAq5V95hEuNo1QT9HOOb7kel/NNwa8N3aL X1CQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=LRbWVdQu; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b8-20020aa7c6c8000000b004ace747fdc0si18343714eds.526.2023.02.21.04.17.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:17:06 -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=LRbWVdQu; 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 01238383FDF2 for ; Tue, 21 Feb 2023 12:08:03 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 A80A23846063 for ; Tue, 21 Feb 2023 12:03:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A80A23846063 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 j2so3981557wrh.9 for ; Tue, 21 Feb 2023 04:03: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=klE7pGoD1SIEPTpYZuJlAwv0JaPCHEP6htefXjZ+BGA=; b=LRbWVdQu8AR89cP2/eZlPGu9VYQ5W5KDzGQ9jlW7JqbpQ0/tJkpYF1ks2MS508n5bf rmTXsU6ZDLJglfhKc25q6BJ9Ejg4Th6wBnY+JRDyWw405GTQW0RApfrYeHyB5VaTPW2M 9P3sTckWGCONKzs7PT3c1NryAFrTcJGBffYJCcQ0Krt/XgX55eXy31Z+RnTpezXctQ8r 8GBQJl+5CiNueK03eRZH6kwtsjONHas0lmKN/FZkn54c0vtBm34bB4+0RnFkV1vFmqna mBp6AJrr75ElBXZe8DUdrhEVL2ModEgfa3fIE+lFlPlzSn7aLvQrG7Fz6/K/VJCKTAFW SFkw== 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=klE7pGoD1SIEPTpYZuJlAwv0JaPCHEP6htefXjZ+BGA=; b=b5lXkNXIuC+2ZQTYy+a9+EgH0ofETsRz8OjOB78yyr7lj+xsNSdEFDQ/d+9tTzXXWx 9iDmxfBqCGdaE3/Eq9j3QMPwzNdl5gnRPit2rJbb/Qno7kHV3IopjINdJon7UKOcL/Rm lw4mS0bk8FoKGtUcMb4nHGTIkugt+FbmQjkOjUfZdtQWzgyw2sRnG9IymTVqEwg4hggN ZP26vvesTjxytr4uIKbXKG5stnGuEUFcf3zGieiu98KVjjddMwOlGHacyyZx+DTHviYU KCSgsQeyhNWuLIoW9KxlK/Lok4KPX+HKKhQB6IDIFmghlQOtCIpAbBAfPcWI/2HP2ht5 ic0Q== X-Gm-Message-State: AO0yUKUpHIDRVOzOBOvj2+fvrO3cGHZ6USU6d6ZektcBLscRXVMfYuMW W/o2xWC5vcrIMzbnZOggaFgczFe0w8npSzAPOA== X-Received: by 2002:a5d:5a9a:0:b0:2c5:5878:e5ad with SMTP id bp26-20020a5d5a9a000000b002c55878e5admr2563142wrb.33.1676981017984; Tue, 21 Feb 2023 04:03: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.03.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:37 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 018/103] gccrs: rust-ast-resolve-item: Add note about resolving glob uses Date: Tue, 21 Feb 2023 13:01:08 +0100 Message-Id: <20230221120230.596966-19-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.4 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?1758442895255137005?= X-GMAIL-MSGID: =?utf-8?q?1758442895255137005?= From: Arthur Cohen gcc/rust/ChangeLog: * resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Add note for glob import resolving. --- gcc/rust/resolve/rust-ast-resolve-item.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc index e5eb6e491e3..193e6834334 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.cc +++ b/gcc/rust/resolve/rust-ast-resolve-item.cc @@ -968,6 +968,14 @@ ResolveItem::visit (AST::UseDeclaration &use_item) { auto to_resolve = flatten_use_dec_to_paths (use_item); + // FIXME: I think this does not actually resolve glob use-decls and is going + // the wrong way about it. RFC #1560 specifies the following: + // + // > When we find a glob import, we have to record a 'back link', so that when + // a public name is added for the supplying module, we can add it for the + // importing module. + // + // Which is the opposite of what we're doing if I understand correctly? for (auto &path : to_resolve) ResolvePath::go (&path); } From patchwork Tue Feb 21 12:01:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59986 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1831016wrn; Tue, 21 Feb 2023 04:23:03 -0800 (PST) X-Google-Smtp-Source: AK7set9QGIkO0LNwbckPD4CoSM0llgjUvqmKluqWoCgaL7M9bjBXQApfciXwYZb2xwNHoeyomCv9 X-Received: by 2002:a17:907:388c:b0:8b1:2dda:b60d with SMTP id sq12-20020a170907388c00b008b12ddab60dmr8325377ejc.20.1676982183532; Tue, 21 Feb 2023 04:23:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982183; cv=none; d=google.com; s=arc-20160816; b=lvATRpDwe5O9mOJNsFQkCgTFKpQoLU5Tnk1PPB/r6QglSHy57mMAHpOiSeqYgKCC8C E4F1yt+Ye1PKgRKMTgDerGsH++4KpMIW6qQpmMentnxKhhOoc2OV0HNJkWg+2coINE7p ymEdiTE4lhiy3/AFBV8b7HprUfxy7/o/pSpB1d3RxM3wYAn5ttwmFHoe1tG3gC7X9BPy FzRUtcmYZOM2drTQVYjNJ1stOQVj01LILm+jPEDk4mXDG9Zk/+e0CAQ744xcRbQr5D4L 2lhv4zop+FEfSLXGx1l2lpJD6fs6WKEnEIfLVG7Wvsk3lcK1RR9uG6cjwRo4CYO6Z8eK nKQg== 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=j8r7kNDCFWXkJ7ptre3ZdzURRpaTRXGDaDNJ2FC4p8Y=; b=0wsAzYv9FNybYWXEsCpGpXRrhNjbrdKqKELVP1TKCpSkdfvwwDXI+Tl1AZySDgwAhC nFnquQAXUJruGa04I7/DU7lZAU3ccE/ELbrMSXquv92bfUe29pT478zykv+gtsNY6VY4 5MObuWgLaVFUZv7gAs4AA6nZQl+iNJ2pAnOEtQ/pA9x1MyP2hdPi5wrac7w9QgjUNF7z BzhPDpDjfHTOtvETG+gE4SskcdUF2hbhSjXztiOAuZk/M6zTNGd3m4Pja1JkpoiyHUeY NtjG7NTLpgzW0UYHnEmHXIBocUZKdb4d0q+6zhN7V3c/cDH84kK7dzFXTmzXw3PFHVuW LRzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b="cv/x646h"; 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 fe8-20020a1709072a4800b008d68d018141si4537801ejc.402.2023.02.21.04.23.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:23:03 -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="cv/x646h"; 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 B24203833D88 for ; Tue, 21 Feb 2023 12:09:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id B403E385E004 for ; Tue, 21 Feb 2023 12:03:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B403E385E004 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-x42e.google.com with SMTP id r7so3990539wrz.6 for ; Tue, 21 Feb 2023 04:03:39 -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=j8r7kNDCFWXkJ7ptre3ZdzURRpaTRXGDaDNJ2FC4p8Y=; b=cv/x646h4/PJEPhmKmc2PPHjfOVRp5+kVPH+Pu5cXVhTFbbdtQMt8BRzmWOwLZ6AXS +9LxU4IrAIeAE1AptLvbUuMcZVQ0/EXqr/N04MnEoUvl+I7/ndAlOPev10eIDQUgB6uK 3ipxfx8wRvOMGP7mO/r8hE9YnMGw3JY5mSnmhk22fpbeurw+DMywsw0EByZiao+RiTeL M5GjCIpHgMl/ks/VvHCvHLW+B1F0u7s4bibEldmWmblQiCGG6RsCh6LPfQNLSS8bxdlz pEHVss32SfJMDJxjGoiJ74ePoUL0ZST2bqoAm5s+SLo90PjblhBU3XMVFqsWLIl2Ho0n prVg== 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=j8r7kNDCFWXkJ7ptre3ZdzURRpaTRXGDaDNJ2FC4p8Y=; b=yT4njO6TDHryBp+cCgG7SRPsgf/gS0S4wD8ymw1W+wqA2TNzt+E0QEn9CHVVE+dVzh +XTTWeA/ySzU2PMsjqzvj4uNosyIUHwPcvsIfB5wpqEpdQGEVyga9moomOst1QJxSDjv rCYXaK0WiM2kXj0i3RFKkFVmPl3JbqMdkr9b3aOEOVlhX82mBenAkTBXTXjtYo96K22k o4suYoXza/fGH61GUnlIS6wIZZiL2BQoZvj6LjTtkdkeGSVgs9CzrDdgH734cNCYLlD3 /8RYu8aAOKRMaQcwQA4cv8DG+Ts1JUOaRgQcwIrDd/oCGj4yE5ATGIY+d2jqAtFOrVJi YPdw== X-Gm-Message-State: AO0yUKXURIr+XE69uVGE58IBGuzZUyz66jc8fKQc7gNqTsE1tn43r2/F A8KG82H7EdZMlP+LSZpfKOjHJdNq5J/3sXT32w== X-Received: by 2002:a05:6000:5c1:b0:2c5:8b23:bb26 with SMTP id bh1-20020a05600005c100b002c58b23bb26mr2082784wrb.22.1676981019060; Tue, 21 Feb 2023 04:03:39 -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.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:38 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 019/103] gccrs: ast: Add accept_vis() method to `GenericArg` Date: Tue, 21 Feb 2023 13:01:09 +0100 Message-Id: <20230221120230.596966-20-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=ham 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?1758443270465032468?= X-GMAIL-MSGID: =?utf-8?q?1758443270465032468?= From: Arthur Cohen gcc/rust/ChangeLog: * ast/rust-path.h: Add `accept_vis` method to `GenericArg` class. --- gcc/rust/ast/rust-path.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h index b12e4c2bafa..9683ad6ad68 100644 --- a/gcc/rust/ast/rust-path.h +++ b/gcc/rust/ast/rust-path.h @@ -207,6 +207,23 @@ public: Kind get_kind () const { return kind; } const Location &get_locus () const { return locus; } + void accept_vis (AST::ASTVisitor &visitor) + { + switch (get_kind ()) + { + case Kind::Const: + get_expression ()->accept_vis (visitor); + break; + case Kind::Type: + get_type ()->accept_vis (visitor); + break; + case Kind::Either: + break; + case Kind::Error: + gcc_unreachable (); + } + } + std::unique_ptr &get_expression () { rust_assert (kind == Kind::Const); From patchwork Tue Feb 21 12:01:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59985 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1830952wrn; Tue, 21 Feb 2023 04:22:51 -0800 (PST) X-Google-Smtp-Source: AK7set/eKXwlTFH6lAXqUy6phKSSzsD8Zr74cnVWBY4ojbrGp/9eKYC88grwdhOnzayw3QKsMnaM X-Received: by 2002:a17:906:518d:b0:8b1:78b6:bbd7 with SMTP id y13-20020a170906518d00b008b178b6bbd7mr16867521ejk.10.1676982171335; Tue, 21 Feb 2023 04:22:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982171; cv=none; d=google.com; s=arc-20160816; b=uubS1YidU/ylTowqOuXjNf8BZKr//SeV3XZYAsREBmhzfkumbLpqZq0wU4SjQHLjpi xZ147t17UwLdCROh5rLH4LVXO5VYGlMa4XqRCC3RGakMuNAj9hUNFMkHQg8pxFNmCmKp C5YvYJJLqXwOe8HGLDrAUHmWbtRlg4cVazMhh4QRCd5jJAa88n9c7IISx8/+0c3BM58k +aUQBl9B6cOhnQYD1S8OqZiisH+yuh+ioZr+Nunf8/lcCLyLnveIlXxuZi+1Yo6KwovL 8lBXA/Ju/jct2q95BSmKbJAfrq78Cz4n3sZbQmVO3NLPB6StzCN/EgwifDCyaUZk/xaA Xl5A== 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=UbYudOgQO4NVEakJVgQWp9ilHKeTksUOG5BewiE/bI8=; b=sNKHk0W4KikZ+WbB+whXhPzdCRjA8NR7joDDGRAo1iW6QDnj1pIhY9c+p5Z07vapE2 PZhDGwZ1caoFk2yk6H42yOrK/zqVlQ5Y5rZckiRPkPA2Beje9LeuAgujQW+bO7uV+Tsa g/u5z6qsJ2KqzUsg75i5ijKe/UuLV+FNR6Mg4kO5Lci/tFvJTSQWASZMD5Cbj/l7ZWDQ R365fknhP9HT6Y+BqJo72LAVR5e2/WlmurFjXOIaw9D3BG/oiZ7u8yUJicUfaQScorx9 8soEEGJvxlCyhtJqSyTMVkB+uroadZjTpteKeaVHLvEXzWZ23V5xJI4b6qw73LGrdoG9 +Mxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=OX1vCnxe; 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 gc31-20020a1709072b1f00b008b5a2c222f0si13549519ejc.904.2023.02.21.04.22.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:22:51 -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=OX1vCnxe; 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 A0E08391B963 for ; Tue, 21 Feb 2023 12:09:32 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id EDC4A384180D for ; Tue, 21 Feb 2023 12:03:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EDC4A384180D 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-x42f.google.com with SMTP id c5so4848735wrr.5 for ; Tue, 21 Feb 2023 04:03:41 -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=UbYudOgQO4NVEakJVgQWp9ilHKeTksUOG5BewiE/bI8=; b=OX1vCnxeQXirWAhxzpp6/TmPwYA7Apk55RtzlKweLI57sLZQC5eaBRKzgU/lPypQIR QUrZ4LqBvuvwPoql4l152Yb0ut5TaF5S/7w8F79Npu1CzlF4IaGkXdMb6j39pp+3jKjm dvP/fQJguhjDD5PAqYZonL9mCsm++Z9dZis32qzzTMw00d1lavdP9wvP02ACOoFfE2Le xIabKzCI/Fo9Gxc3sKmwo1tMnR+xQ6ZLgLN9tOxv87pP1ZfdSe2/zzrFOAzbS59avCnA iGNNrX4EC184q7XQ76SkSP0l/N9c2yXzErykkOYyD3n6J821IyunOQKlPBHAyVv1uRQQ hnwA== 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=UbYudOgQO4NVEakJVgQWp9ilHKeTksUOG5BewiE/bI8=; b=RmQmpakaOHeqgwgusftbHmp73DWsYRBaH3B0MWDCMHFyn6PMXF97b7/FXDdKykoUOV eHVb8F6JODIWXzWR1Fy6+e4lybvjgXNw91aXWw9g9aUu236QNfGYdYMJPC00Lz7gH9ze 5NBBubTMWEb6tWf8KcoyEWbvsu+2gvFHup0ll22bSc7Qoc6HyjjI+IHIHaWtTAyqOwC+ kKOAUftBfw1J7Wf6kZ8xN5k9DO0rG4JFboT3BRxn8p0+xgWB/ZWh6rBd2kgACJV195e2 eue8NLZ4oP+6MpLA3ezkKT3YzmajohUBpgENIISRtcJUQ9CED+7jXmGrAtPxLsnjS5zQ 7dig== X-Gm-Message-State: AO0yUKUXU/Tui438/i65DRh2uVPB7NHYntsfCMss1WSwCPn3PTtMO4nu v28NkQcX8hXrv+02ocTHBBmcmWW6019E+/ojsQ== X-Received: by 2002:a5d:6045:0:b0:2c5:6c26:1f73 with SMTP id j5-20020a5d6045000000b002c56c261f73mr4786454wrt.20.1676981020059; Tue, 21 Feb 2023 04:03:40 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:39 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 020/103] gccrs: early-name-resolver: Add simple macro name resolution Date: Tue, 21 Feb 2023 13:01:10 +0100 Message-Id: <20230221120230.596966-21-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, 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 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?1758443257501199346?= X-GMAIL-MSGID: =?utf-8?q?1758443257501199346?= From: Arthur Cohen This name resolver performs the same macro name resolution as what was previously done by the AttrVisitor visitor and macro expander. It also resolves macro expressions in builtin-macros properly, as well as expanded AST nodes when necessary. gcc/rust/ChangeLog: * Make-lang.in: Compile early name resolver. * expand/rust-attribute-visitor.cc (AttrVisitor::visit): Move macro name resolution. * expand/rust-macro-builtins.cc (try_expand_macro_expression): Run ENR when recursively expanding macros. * expand/rust-macro-expand.cc (MacroExpander::expand_invoc): No longer perform name resolution in `expand_invoc`. * expand/rust-macro-expand.h (struct MacroExpander): Keep ENR within MacroExpander. * rust-session-manager.cc (Session::expansion): Run ENR. * resolve/rust-early-name-resolver.cc: New file. * resolve/rust-early-name-resolver.h: New file. --- gcc/rust/Make-lang.in | 1 + gcc/rust/expand/rust-attribute-visitor.cc | 10 - gcc/rust/expand/rust-macro-builtins.cc | 9 +- gcc/rust/expand/rust-macro-expand.cc | 30 +- gcc/rust/expand/rust-macro-expand.h | 4 + gcc/rust/resolve/rust-early-name-resolver.cc | 1087 ++++++++++++++++++ gcc/rust/resolve/rust-early-name-resolver.h | 210 ++++ gcc/rust/rust-session-manager.cc | 4 + 8 files changed, 1320 insertions(+), 35 deletions(-) create mode 100644 gcc/rust/resolve/rust-early-name-resolver.cc create mode 100644 gcc/rust/resolve/rust-early-name-resolver.h diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index a24025cb31c..a906516bd33 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -93,6 +93,7 @@ GRS_OBJS = \ rust/rust-ast-lower-base.o \ rust/rust-ast-lower-pattern.o \ rust/rust-ast-lower-item.o \ + rust/rust-early-name-resolver.o \ rust/rust-name-resolver.o \ rust/rust-ast-resolve.o \ rust/rust-ast-resolve-base.o \ diff --git a/gcc/rust/expand/rust-attribute-visitor.cc b/gcc/rust/expand/rust-attribute-visitor.cc index 673f0432a30..a1895749b82 100644 --- a/gcc/rust/expand/rust-attribute-visitor.cc +++ b/gcc/rust/expand/rust-attribute-visitor.cc @@ -2877,16 +2877,6 @@ AttrVisitor::visit (AST::MacroRulesDefinition &rules_def) rules_def.mark_for_strip (); return; } - - // I don't think any macro rules can be stripped in any way - - auto path = Resolver::CanonicalPath::new_seg (rules_def.get_node_id (), - rules_def.get_rule_name ()); - expander.resolver->get_macro_scope ().insert (path, rules_def.get_node_id (), - rules_def.get_locus ()); - expander.mappings->insert_macro_def (&rules_def); - rust_debug_loc (rules_def.get_locus (), "inserting macro def: [%s]", - path.get ().c_str ()); } void diff --git a/gcc/rust/expand/rust-macro-builtins.cc b/gcc/rust/expand/rust-macro-builtins.cc index 606f33c65bc..a230ad9f2d8 100644 --- a/gcc/rust/expand/rust-macro-builtins.cc +++ b/gcc/rust/expand/rust-macro-builtins.cc @@ -24,6 +24,7 @@ #include "rust-macro-invoc-lexer.h" #include "rust-lex.h" #include "rust-parse.h" +#include "rust-early-name-resolver.h" #include "rust-attribute-visitor.h" namespace Rust { @@ -70,9 +71,11 @@ try_expand_macro_expression (AST::Expr *expr, MacroExpander *expander) { rust_assert (expander); - auto vis = Rust::AttrVisitor (*expander); - expr->accept_vis (vis); - return expander->take_expanded_fragment (vis); + auto attr_visitor = Rust::AttrVisitor (*expander); + auto early_name_resolver = Resolver::EarlyNameResolver (); + expr->accept_vis (early_name_resolver); + expr->accept_vis (attr_visitor); + return expander->take_expanded_fragment (attr_visitor); } /* Expand and then extract a string literal from the macro */ diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc index fbf33209c5f..d94cd118700 100644 --- a/gcc/rust/expand/rust-macro-expand.cc +++ b/gcc/rust/expand/rust-macro-expand.cc @@ -23,6 +23,7 @@ #include "rust-diagnostics.h" #include "rust-parse.h" #include "rust-attribute-visitor.h" +#include "rust-early-name-resolver.h" namespace Rust { AST::ASTFragment @@ -138,32 +139,17 @@ MacroExpander::expand_invoc (AST::MacroInvocation &invoc, bool has_semicolon) // - else is unreachable // - derive container macro - unreachable - // lookup the rules for this macro - NodeId resolved_node = UNKNOWN_NODEID; - NodeId source_node = UNKNOWN_NODEID; - if (has_semicolon) - source_node = invoc.get_macro_node_id (); - else - source_node = invoc.get_pattern_node_id (); - auto seg - = Resolver::CanonicalPath::new_seg (source_node, - invoc_data.get_path ().as_string ()); - - bool found = resolver->get_macro_scope ().lookup (seg, &resolved_node); - if (!found) - { - rust_error_at (invoc.get_locus (), "unknown macro: [%s]", - seg.get ().c_str ()); - return; - } + auto fragment = AST::ASTFragment::create_error (); + invoc_data.set_expander (this); // lookup the rules AST::MacroRulesDefinition *rules_def = nullptr; - bool ok = mappings->lookup_macro_def (resolved_node, &rules_def); - rust_assert (ok); + bool ok = mappings->lookup_macro_invocation (invoc, &rules_def); - auto fragment = AST::ASTFragment::create_error (); - invoc_data.set_expander (this); + // If there's no rule associated with the invocation, we can simply return + // early. The early name resolver will have already emitted an error. + if (!ok) + return; if (rules_def->is_builtin ()) fragment diff --git a/gcc/rust/expand/rust-macro-expand.h b/gcc/rust/expand/rust-macro-expand.h index bef140236b3..187d79f9a28 100644 --- a/gcc/rust/expand/rust-macro-expand.h +++ b/gcc/rust/expand/rust-macro-expand.h @@ -25,6 +25,7 @@ #include "rust-ast.h" #include "rust-macro.h" #include "rust-hir-map.h" +#include "rust-early-name-resolver.h" #include "rust-name-resolver.h" #include "rust-macro-invoc-lexer.h" @@ -323,10 +324,13 @@ struct MacroExpander AST::ASTFragment old_fragment = std::move (expanded_fragment); auto accumulator = std::vector (); expanded_fragment = AST::ASTFragment::create_error (); + auto early_name_resolver = Resolver::EarlyNameResolver (); for (auto &node : old_fragment.get_nodes ()) { expansion_depth++; + + node.accept_vis (early_name_resolver); node.accept_vis (vis); // we'll decide the next move according to the outcome of the macro // expansion diff --git a/gcc/rust/resolve/rust-early-name-resolver.cc b/gcc/rust/resolve/rust-early-name-resolver.cc new file mode 100644 index 00000000000..6b1f1e9c52f --- /dev/null +++ b/gcc/rust/resolve/rust-early-name-resolver.cc @@ -0,0 +1,1087 @@ +// 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-early-name-resolver.h" +#include "rust-ast-full.h" +#include "rust-name-resolver.h" + +namespace Rust { +namespace Resolver { + +EarlyNameResolver::EarlyNameResolver () + : resolver (*Resolver::get ()), mappings (*Analysis::Mappings::get ()) +{} + +void +EarlyNameResolver::go (AST::Crate &crate) +{ + // FIXME: Is that valid? Why is the regular name resolution doing + // mappings->get_next_node_id()? + resolver.get_macro_scope ().push (crate.get_node_id ()); + + for (auto &item : crate.items) + item->accept_vis (*this); + + // FIXME: Should we pop the macro scope? +} + +void +EarlyNameResolver::resolve_generic_args (AST::GenericArgs &generic_args) +{ + for (auto &arg : generic_args.get_generic_args ()) + arg.accept_vis (*this); + + for (auto &arg : generic_args.get_binding_args ()) + arg.get_type ()->accept_vis (*this); +} + +void +EarlyNameResolver::resolve_qualified_path_type (AST::QualifiedPathType &path) +{ + path.get_type ()->accept_vis (*this); + + if (path.has_as_clause ()) + path.get_as_type_path ().accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::Token &tok) +{} + +void +EarlyNameResolver::visit (AST::DelimTokenTree &delim_tok_tree) +{} + +void +EarlyNameResolver::visit (AST::AttrInputMetaItemContainer &input) +{} + +void +EarlyNameResolver::visit (AST::IdentifierExpr &ident_expr) +{} + +void +EarlyNameResolver::visit (AST::Lifetime &lifetime) +{} + +void +EarlyNameResolver::visit (AST::LifetimeParam &lifetime_param) +{} + +void +EarlyNameResolver::visit (AST::ConstGenericParam &const_param) +{} + +// FIXME: ARTHUR: Do we need to perform macro resolution for paths as well? +// std::arch::asm!()? +void +EarlyNameResolver::visit (AST::PathInExpression &path) +{ + for (auto &segment : path.get_segments ()) + if (segment.has_generic_args ()) + resolve_generic_args (segment.get_generic_args ()); +} + +void +EarlyNameResolver::visit (AST::TypePathSegment &segment) +{} + +void +EarlyNameResolver::visit (AST::TypePathSegmentGeneric &segment) +{ + if (segment.has_generic_args ()) + resolve_generic_args (segment.get_generic_args ()); +} + +void +EarlyNameResolver::visit (AST::TypePathSegmentFunction &segment) +{ + for (auto &type : segment.get_type_path_function ().get_params ()) + type->accept_vis (*this); + + segment.get_type_path_function ().get_return_type ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::TypePath &path) +{ + for (auto &seg : path.get_segments ()) + seg->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::QualifiedPathInExpression &path) +{ + resolve_qualified_path_type (path.get_qualified_path_type ()); + + for (auto &segment : path.get_segments ()) + if (segment.has_generic_args ()) + resolve_generic_args (segment.get_generic_args ()); +} + +void +EarlyNameResolver::visit (AST::QualifiedPathInType &path) +{ + resolve_qualified_path_type (path.get_qualified_path_type ()); + + for (auto &segment : path.get_segments ()) + segment->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::LiteralExpr &expr) +{} + +void +EarlyNameResolver::visit (AST::AttrInputLiteral &attr_input) +{} + +void +EarlyNameResolver::visit (AST::MetaItemLitExpr &meta_item) +{} + +void +EarlyNameResolver::visit (AST::MetaItemPathLit &meta_item) +{} + +void +EarlyNameResolver::visit (AST::BorrowExpr &expr) +{ + expr.get_borrowed_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::DereferenceExpr &expr) +{ + expr.get_dereferenced_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::ErrorPropagationExpr &expr) +{ + expr.get_propagating_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::NegationExpr &expr) +{ + expr.get_negated_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::ArithmeticOrLogicalExpr &expr) +{ + expr.get_left_expr ()->accept_vis (*this); + expr.get_right_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::ComparisonExpr &expr) +{ + expr.get_left_expr ()->accept_vis (*this); + expr.get_right_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::LazyBooleanExpr &expr) +{ + expr.get_left_expr ()->accept_vis (*this); + expr.get_right_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::TypeCastExpr &expr) +{ + expr.get_casted_expr ()->accept_vis (*this); + expr.get_type_to_cast_to ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::AssignmentExpr &expr) +{ + expr.get_left_expr ()->accept_vis (*this); + expr.get_right_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::CompoundAssignmentExpr &expr) +{ + expr.get_left_expr ()->accept_vis (*this); + expr.get_right_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::GroupedExpr &expr) +{ + expr.get_expr_in_parens ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::ArrayElemsValues &elems) +{ + for (auto &expr : elems.get_values ()) + expr->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::ArrayElemsCopied &elems) +{ + elems.get_elem_to_copy ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::ArrayExpr &expr) +{ + expr.get_array_elems ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::ArrayIndexExpr &expr) +{ + expr.get_array_expr ()->accept_vis (*this); + expr.get_index_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::TupleExpr &expr) +{ + for (auto &elem : expr.get_tuple_elems ()) + elem->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::TupleIndexExpr &expr) +{ + expr.get_tuple_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::StructExprStruct &expr) +{} + +void +EarlyNameResolver::visit (AST::StructExprFieldIdentifier &field) +{} + +void +EarlyNameResolver::visit (AST::StructExprFieldIdentifierValue &field) +{ + field.get_value ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::StructExprFieldIndexValue &field) +{ + field.get_value ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::StructExprStructFields &expr) +{ + for (auto &field : expr.get_fields ()) + field->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::StructExprStructBase &expr) +{} + +void +EarlyNameResolver::visit (AST::CallExpr &expr) +{ + expr.get_function_expr ()->accept_vis (*this); + for (auto ¶m : expr.get_params ()) + param->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::MethodCallExpr &expr) +{ + expr.get_receiver_expr ()->accept_vis (*this); + for (auto ¶m : expr.get_params ()) + param->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::FieldAccessExpr &expr) +{ + expr.get_receiver_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::ClosureExprInner &expr) +{ + expr.get_definition_expr ()->accept_vis (*this); + + for (auto ¶m : expr.get_params ()) + param.get_type ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::BlockExpr &expr) +{ + for (auto &stmt : expr.get_statements ()) + stmt->accept_vis (*this); + + if (expr.has_tail_expr ()) + expr.get_tail_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::ClosureExprInnerTyped &expr) +{ + expr.get_definition_block ()->accept_vis (*this); + + for (auto ¶m : expr.get_params ()) + param.get_type ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::ContinueExpr &expr) +{} + +void +EarlyNameResolver::visit (AST::BreakExpr &expr) +{ + if (expr.has_break_expr ()) + expr.get_break_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::RangeFromToExpr &expr) +{ + expr.get_from_expr ()->accept_vis (*this); + expr.get_to_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::RangeFromExpr &expr) +{ + expr.get_from_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::RangeToExpr &expr) +{ + expr.get_to_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::RangeFullExpr &expr) +{} + +void +EarlyNameResolver::visit (AST::RangeFromToInclExpr &expr) +{ + expr.get_from_expr ()->accept_vis (*this); + expr.get_to_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::RangeToInclExpr &expr) +{ + expr.get_to_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::ReturnExpr &expr) +{ + if (expr.has_returned_expr ()) + expr.get_returned_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::UnsafeBlockExpr &expr) +{ + expr.get_block_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::LoopExpr &expr) +{ + expr.get_loop_block ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::WhileLoopExpr &expr) +{ + expr.get_predicate_expr ()->accept_vis (*this); + expr.get_loop_block ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::WhileLetLoopExpr &expr) +{ + expr.get_scrutinee_expr ()->accept_vis (*this); + expr.get_loop_block ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::ForLoopExpr &expr) +{ + expr.get_iterator_expr ()->accept_vis (*this); + expr.get_loop_block ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::IfExpr &expr) +{ + expr.get_condition_expr ()->accept_vis (*this); + expr.get_if_block ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::IfExprConseqElse &expr) +{ + expr.get_condition_expr ()->accept_vis (*this); + expr.get_if_block ()->accept_vis (*this); + expr.get_else_block ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::IfExprConseqIf &expr) +{ + expr.get_condition_expr ()->accept_vis (*this); + expr.get_if_block ()->accept_vis (*this); + expr.get_conseq_if_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::IfExprConseqIfLet &expr) +{ + expr.get_condition_expr ()->accept_vis (*this); + expr.get_if_block ()->accept_vis (*this); + expr.get_conseq_if_let_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::IfLetExpr &expr) +{ + expr.get_value_expr ()->accept_vis (*this); + expr.get_if_block ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::IfLetExprConseqElse &expr) +{ + expr.get_value_expr ()->accept_vis (*this); + expr.get_if_block ()->accept_vis (*this); + expr.get_else_block ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::IfLetExprConseqIf &expr) +{ + expr.get_value_expr ()->accept_vis (*this); + expr.get_if_block ()->accept_vis (*this); + expr.get_conseq_if_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::IfLetExprConseqIfLet &expr) +{ + expr.get_value_expr ()->accept_vis (*this); + expr.get_if_block ()->accept_vis (*this); + expr.get_conseq_if_let_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::MatchExpr &expr) +{ + expr.get_scrutinee_expr ()->accept_vis (*this); + for (auto &match_arm : expr.get_match_cases ()) + { + if (match_arm.get_arm ().has_match_arm_guard ()) + match_arm.get_arm ().get_guard_expr ()->accept_vis (*this); + + for (auto &pattern : match_arm.get_arm ().get_patterns ()) + pattern->accept_vis (*this); + + match_arm.get_expr ()->accept_vis (*this); + } +} + +void +EarlyNameResolver::visit (AST::AwaitExpr &expr) +{ + expr.get_awaited_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::AsyncBlockExpr &expr) +{ + expr.get_block_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::TypeParam ¶m) +{ + for (auto &bound : param.get_type_param_bounds ()) + bound->accept_vis (*this); + + if (param.has_type ()) + param.get_type ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::LifetimeWhereClauseItem &item) +{} + +void +EarlyNameResolver::visit (AST::TypeBoundWhereClauseItem &item) +{ + for (auto &bound : item.get_type_param_bounds ()) + bound->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::Method &method) +{ + if (method.has_generics ()) + for (auto &generic : method.get_generic_params ()) + generic->accept_vis (*this); + + if (method.get_self_param ().has_type ()) + method.get_self_param ().get_type ()->accept_vis (*this); + + for (auto ¶m : method.get_function_params ()) + param.get_type ()->accept_vis (*this); + + if (method.has_return_type ()) + method.get_return_type ()->accept_vis (*this); + + method.get_definition ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::Module &module) +{ + for (auto &item : module.get_items ()) + item->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::ExternCrate &crate) +{} + +void +EarlyNameResolver::visit (AST::UseTreeGlob &use_tree) +{} + +void +EarlyNameResolver::visit (AST::UseTreeList &use_tree) +{} + +void +EarlyNameResolver::visit (AST::UseTreeRebind &use_tree) +{} + +void +EarlyNameResolver::visit (AST::UseDeclaration &use_decl) +{} + +void +EarlyNameResolver::visit (AST::Function &function) +{ + if (function.has_generics ()) + for (auto &generic : function.get_generic_params ()) + generic->accept_vis (*this); + + for (auto ¶m : function.get_function_params ()) + param.get_type ()->accept_vis (*this); + + if (function.has_return_type ()) + function.get_return_type ()->accept_vis (*this); + + function.get_definition ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::TypeAlias &type_alias) +{ + type_alias.get_type_aliased ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::StructStruct &struct_item) +{ + for (auto &field : struct_item.get_fields ()) + field.get_field_type ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::TupleStruct &tuple_struct) +{ + for (auto &field : tuple_struct.get_fields ()) + field.get_field_type ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::EnumItem &item) +{} + +void +EarlyNameResolver::visit (AST::EnumItemTuple &item) +{} + +void +EarlyNameResolver::visit (AST::EnumItemStruct &item) +{} + +void +EarlyNameResolver::visit (AST::EnumItemDiscriminant &item) +{} + +void +EarlyNameResolver::visit (AST::Enum &enum_item) +{} + +void +EarlyNameResolver::visit (AST::Union &union_item) +{} + +void +EarlyNameResolver::visit (AST::ConstantItem &const_item) +{ + const_item.get_type ()->accept_vis (*this); + const_item.get_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::StaticItem &static_item) +{ + static_item.get_type ()->accept_vis (*this); + static_item.get_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::TraitItemFunc &item) +{ + auto &decl = item.get_trait_function_decl (); + + if (decl.has_return_type ()) + decl.get_return_type ()->accept_vis (*this); + + for (auto &generic : decl.get_generic_params ()) + generic->accept_vis (*this); + + for (auto ¶m : decl.get_function_params ()) + param.get_type ()->accept_vis (*this); + + if (item.has_definition ()) + item.get_definition ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::TraitItemMethod &item) +{ + // FIXME: Can we factor this with the above function? + auto &decl = item.get_trait_method_decl (); + + if (decl.has_return_type ()) + decl.get_return_type ()->accept_vis (*this); + + for (auto &generic : decl.get_generic_params ()) + generic->accept_vis (*this); + + for (auto ¶m : decl.get_function_params ()) + param.get_type ()->accept_vis (*this); + + if (item.has_definition ()) + item.get_definition ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::TraitItemConst &item) +{ + item.get_type ()->accept_vis (*this); + + if (item.has_expr ()) + item.get_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::TraitItemType &item) +{} + +void +EarlyNameResolver::visit (AST::Trait &trait) +{ + for (auto &item : trait.get_trait_items ()) + item->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::InherentImpl &impl) +{ + impl.get_type ()->accept_vis (*this); + + for (auto &generic : impl.get_generic_params ()) + generic->accept_vis (*this); + + for (auto &item : impl.get_impl_items ()) + item->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::TraitImpl &impl) +{ + impl.get_type ()->accept_vis (*this); + + for (auto &generic : impl.get_generic_params ()) + generic->accept_vis (*this); + + for (auto &item : impl.get_impl_items ()) + item->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::ExternalStaticItem &item) +{ + item.get_type ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::ExternalFunctionItem &item) +{ + for (auto &generic : item.get_generic_params ()) + generic->accept_vis (*this); + + for (auto ¶m : item.get_function_params ()) + param.get_type ()->accept_vis (*this); + + if (item.has_return_type ()) + item.get_return_type ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::ExternBlock &block) +{ + for (auto &item : block.get_extern_items ()) + item->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::MacroMatchFragment &match) +{} + +void +EarlyNameResolver::visit (AST::MacroMatchRepetition &match) +{} + +void +EarlyNameResolver::visit (AST::MacroMatcher &matcher) +{} + +void +EarlyNameResolver::visit (AST::MacroRulesDefinition &rules_def) +{ + auto path = CanonicalPath::new_seg (rules_def.get_node_id (), + rules_def.get_rule_name ()); + resolver.get_macro_scope ().insert (path, rules_def.get_node_id (), + rules_def.get_locus ()); + mappings.insert_macro_def (&rules_def); + rust_debug_loc (rules_def.get_locus (), "inserting macro def: [%s]", + path.get ().c_str ()); +} + +void +EarlyNameResolver::visit (AST::MacroInvocation &invoc) +{ + auto &invoc_data = invoc.get_invoc_data (); + auto has_semicolon = invoc.has_semicolon (); + + // ?? + // switch on type of macro: + // - '!' syntax macro (inner switch) + // - procedural macro - "A token-based function-like macro" + // - 'macro_rules' (by example/pattern-match) macro? or not? "an + // AST-based function-like macro" + // - else is unreachable + // - attribute syntax macro (inner switch) + // - procedural macro attribute syntax - "A token-based attribute + // macro" + // - legacy macro attribute syntax? - "an AST-based attribute macro" + // - non-macro attribute: mark known + // - else is unreachable + // - derive macro (inner switch) + // - derive or legacy derive - "token-based" vs "AST-based" + // - else is unreachable + // - derive container macro - unreachable + + // lookup the rules for this macro + NodeId resolved_node = UNKNOWN_NODEID; + NodeId source_node = UNKNOWN_NODEID; + if (has_semicolon) + source_node = invoc.get_macro_node_id (); + else + source_node = invoc.get_pattern_node_id (); + auto seg + = CanonicalPath::new_seg (source_node, invoc_data.get_path ().as_string ()); + + bool found = resolver.get_macro_scope ().lookup (seg, &resolved_node); + if (!found) + { + rust_error_at (invoc.get_locus (), "unknown macro: [%s]", + seg.get ().c_str ()); + return; + } + + // lookup the rules + AST::MacroRulesDefinition *rules_def = nullptr; + bool ok = mappings.lookup_macro_def (resolved_node, &rules_def); + rust_assert (ok); + + mappings.insert_macro_invocation (invoc, rules_def); +} + +// FIXME: ARTHUR: Do we need to resolve these as well here? + +void +EarlyNameResolver::visit (AST::MetaItemPath &meta_item) +{} + +void +EarlyNameResolver::visit (AST::MetaItemSeq &meta_item) +{} + +void +EarlyNameResolver::visit (AST::MetaWord &meta_item) +{} + +void +EarlyNameResolver::visit (AST::MetaNameValueStr &meta_item) +{} + +void +EarlyNameResolver::visit (AST::MetaListPaths &meta_item) +{} + +void +EarlyNameResolver::visit (AST::MetaListNameValueStr &meta_item) +{} + +void +EarlyNameResolver::visit (AST::LiteralPattern &pattern) +{} + +void +EarlyNameResolver::visit (AST::IdentifierPattern &pattern) +{ + if (pattern.has_pattern_to_bind ()) + pattern.get_pattern_to_bind ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::WildcardPattern &pattern) +{} + +void +EarlyNameResolver::visit (AST::RangePatternBoundLiteral &bound) +{} + +void +EarlyNameResolver::visit (AST::RangePatternBoundPath &bound) +{} + +void +EarlyNameResolver::visit (AST::RangePatternBoundQualPath &bound) +{} + +void +EarlyNameResolver::visit (AST::RangePattern &pattern) +{ + pattern.get_lower_bound ()->accept_vis (*this); + pattern.get_upper_bound ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::ReferencePattern &pattern) +{ + pattern.get_referenced_pattern ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::StructPatternFieldTuplePat &field) +{ + field.get_index_pattern ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::StructPatternFieldIdentPat &field) +{ + field.get_ident_pattern ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::StructPatternFieldIdent &field) +{} + +void +EarlyNameResolver::visit (AST::StructPattern &pattern) +{} + +void +EarlyNameResolver::visit (AST::TupleStructItemsNoRange &tuple_items) +{ + for (auto &pattern : tuple_items.get_patterns ()) + pattern->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::TupleStructItemsRange &tuple_items) +{ + for (auto &pattern : tuple_items.get_lower_patterns ()) + pattern->accept_vis (*this); + for (auto &pattern : tuple_items.get_upper_patterns ()) + pattern->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::TupleStructPattern &pattern) +{ + pattern.get_items ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::TuplePatternItemsMultiple &tuple_items) +{ + for (auto &pattern : tuple_items.get_patterns ()) + pattern->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::TuplePatternItemsRanged &tuple_items) +{ + for (auto &pattern : tuple_items.get_lower_patterns ()) + pattern->accept_vis (*this); + for (auto &pattern : tuple_items.get_upper_patterns ()) + pattern->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::TuplePattern &pattern) +{ + pattern.get_items ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::GroupedPattern &pattern) +{ + pattern.get_pattern_in_parens ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::SlicePattern &pattern) +{ + for (auto &item : pattern.get_items ()) + item->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::EmptyStmt &stmt) +{} + +void +EarlyNameResolver::visit (AST::LetStmt &stmt) +{ + if (stmt.has_type ()) + stmt.get_type ()->accept_vis (*this); + + if (stmt.has_init_expr ()) + stmt.get_init_expr ()->accept_vis (*this); + + stmt.get_pattern ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::ExprStmtWithoutBlock &stmt) +{ + stmt.get_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::ExprStmtWithBlock &stmt) +{ + stmt.get_expr ()->accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::TraitBound &bound) +{} + +void +EarlyNameResolver::visit (AST::ImplTraitType &type) +{} + +void +EarlyNameResolver::visit (AST::TraitObjectType &type) +{} + +void +EarlyNameResolver::visit (AST::ParenthesisedType &type) +{} + +void +EarlyNameResolver::visit (AST::ImplTraitTypeOneBound &type) +{} + +void +EarlyNameResolver::visit (AST::TraitObjectTypeOneBound &type) +{} + +void +EarlyNameResolver::visit (AST::TupleType &type) +{} + +void +EarlyNameResolver::visit (AST::NeverType &type) +{} + +void +EarlyNameResolver::visit (AST::RawPointerType &type) +{} + +void +EarlyNameResolver::visit (AST::ReferenceType &type) +{} + +void +EarlyNameResolver::visit (AST::ArrayType &type) +{} + +void +EarlyNameResolver::visit (AST::SliceType &type) +{} + +void +EarlyNameResolver::visit (AST::InferredType &type) +{} + +void +EarlyNameResolver::visit (AST::BareFunctionType &type) +{ + for (auto ¶m : type.get_function_params ()) + param.get_type ()->accept_vis (*this); + + if (type.has_return_type ()) + type.get_return_type ()->accept_vis (*this); +} + +} // namespace Resolver +} // namespace Rust diff --git a/gcc/rust/resolve/rust-early-name-resolver.h b/gcc/rust/resolve/rust-early-name-resolver.h new file mode 100644 index 00000000000..c53ab9f3d6a --- /dev/null +++ b/gcc/rust/resolve/rust-early-name-resolver.h @@ -0,0 +1,210 @@ +// 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_EARLY_NAME_RESOLVER_H +#define RUST_EARLY_NAME_RESOLVER_H + +#include "rust-name-resolver.h" +#include "rust-system.h" +#include "rust-ast.h" +#include "rust-ast-visitor.h" + +namespace Rust { +namespace Resolver { + +class EarlyNameResolver : public AST::ASTVisitor +{ +public: + EarlyNameResolver (); + + void go (AST::Crate &crate); + +private: + Resolver &resolver; + Analysis::Mappings &mappings; + + /** + * Early name-resolve generic args, which can be macro invocations + */ + void resolve_generic_args (AST::GenericArgs &generic_args); + + /** + * Early name-resolve a qualified path type, which can contain macro + * invocations + */ + void resolve_qualified_path_type (AST::QualifiedPathType &path); + + virtual void visit (AST::Token &tok); + virtual void visit (AST::DelimTokenTree &delim_tok_tree); + virtual void visit (AST::AttrInputMetaItemContainer &input); + virtual void visit (AST::IdentifierExpr &ident_expr); + virtual void visit (AST::Lifetime &lifetime); + virtual void visit (AST::LifetimeParam &lifetime_param); + virtual void visit (AST::ConstGenericParam &const_param); + virtual void visit (AST::PathInExpression &path); + virtual void visit (AST::TypePathSegment &segment); + virtual void visit (AST::TypePathSegmentGeneric &segment); + virtual void visit (AST::TypePathSegmentFunction &segment); + virtual void visit (AST::TypePath &path); + virtual void visit (AST::QualifiedPathInExpression &path); + virtual void visit (AST::QualifiedPathInType &path); + virtual void visit (AST::LiteralExpr &expr); + virtual void visit (AST::AttrInputLiteral &attr_input); + virtual void visit (AST::MetaItemLitExpr &meta_item); + virtual void visit (AST::MetaItemPathLit &meta_item); + virtual void visit (AST::BorrowExpr &expr); + virtual void visit (AST::DereferenceExpr &expr); + virtual void visit (AST::ErrorPropagationExpr &expr); + virtual void visit (AST::NegationExpr &expr); + virtual void visit (AST::ArithmeticOrLogicalExpr &expr); + virtual void visit (AST::ComparisonExpr &expr); + virtual void visit (AST::LazyBooleanExpr &expr); + virtual void visit (AST::TypeCastExpr &expr); + virtual void visit (AST::AssignmentExpr &expr); + virtual void visit (AST::CompoundAssignmentExpr &expr); + virtual void visit (AST::GroupedExpr &expr); + virtual void visit (AST::ArrayElemsValues &elems); + virtual void visit (AST::ArrayElemsCopied &elems); + virtual void visit (AST::ArrayExpr &expr); + virtual void visit (AST::ArrayIndexExpr &expr); + virtual void visit (AST::TupleExpr &expr); + virtual void visit (AST::TupleIndexExpr &expr); + virtual void visit (AST::StructExprStruct &expr); + virtual void visit (AST::StructExprFieldIdentifier &field); + virtual void visit (AST::StructExprFieldIdentifierValue &field); + virtual void visit (AST::StructExprFieldIndexValue &field); + virtual void visit (AST::StructExprStructFields &expr); + virtual void visit (AST::StructExprStructBase &expr); + virtual void visit (AST::CallExpr &expr); + virtual void visit (AST::MethodCallExpr &expr); + virtual void visit (AST::FieldAccessExpr &expr); + virtual void visit (AST::ClosureExprInner &expr); + virtual void visit (AST::BlockExpr &expr); + virtual void visit (AST::ClosureExprInnerTyped &expr); + virtual void visit (AST::ContinueExpr &expr); + virtual void visit (AST::BreakExpr &expr); + virtual void visit (AST::RangeFromToExpr &expr); + virtual void visit (AST::RangeFromExpr &expr); + virtual void visit (AST::RangeToExpr &expr); + virtual void visit (AST::RangeFullExpr &expr); + virtual void visit (AST::RangeFromToInclExpr &expr); + virtual void visit (AST::RangeToInclExpr &expr); + virtual void visit (AST::ReturnExpr &expr); + virtual void visit (AST::UnsafeBlockExpr &expr); + virtual void visit (AST::LoopExpr &expr); + virtual void visit (AST::WhileLoopExpr &expr); + virtual void visit (AST::WhileLetLoopExpr &expr); + virtual void visit (AST::ForLoopExpr &expr); + virtual void visit (AST::IfExpr &expr); + virtual void visit (AST::IfExprConseqElse &expr); + virtual void visit (AST::IfExprConseqIf &expr); + virtual void visit (AST::IfExprConseqIfLet &expr); + virtual void visit (AST::IfLetExpr &expr); + virtual void visit (AST::IfLetExprConseqElse &expr); + virtual void visit (AST::IfLetExprConseqIf &expr); + virtual void visit (AST::IfLetExprConseqIfLet &expr); + virtual void visit (AST::MatchExpr &expr); + virtual void visit (AST::AwaitExpr &expr); + virtual void visit (AST::AsyncBlockExpr &expr); + virtual void visit (AST::TypeParam ¶m); + virtual void visit (AST::LifetimeWhereClauseItem &item); + virtual void visit (AST::TypeBoundWhereClauseItem &item); + virtual void visit (AST::Method &method); + virtual void visit (AST::Module &module); + virtual void visit (AST::ExternCrate &crate); + virtual void visit (AST::UseTreeGlob &use_tree); + virtual void visit (AST::UseTreeList &use_tree); + virtual void visit (AST::UseTreeRebind &use_tree); + virtual void visit (AST::UseDeclaration &use_decl); + virtual void visit (AST::Function &function); + virtual void visit (AST::TypeAlias &type_alias); + virtual void visit (AST::StructStruct &struct_item); + virtual void visit (AST::TupleStruct &tuple_struct); + virtual void visit (AST::EnumItem &item); + virtual void visit (AST::EnumItemTuple &item); + virtual void visit (AST::EnumItemStruct &item); + virtual void visit (AST::EnumItemDiscriminant &item); + virtual void visit (AST::Enum &enum_item); + virtual void visit (AST::Union &union_item); + virtual void visit (AST::ConstantItem &const_item); + virtual void visit (AST::StaticItem &static_item); + virtual void visit (AST::TraitItemFunc &item); + virtual void visit (AST::TraitItemMethod &item); + virtual void visit (AST::TraitItemConst &item); + virtual void visit (AST::TraitItemType &item); + virtual void visit (AST::Trait &trait); + virtual void visit (AST::InherentImpl &impl); + virtual void visit (AST::TraitImpl &impl); + virtual void visit (AST::ExternalStaticItem &item); + virtual void visit (AST::ExternalFunctionItem &item); + virtual void visit (AST::ExternBlock &block); + virtual void visit (AST::MacroMatchFragment &match); + virtual void visit (AST::MacroMatchRepetition &match); + virtual void visit (AST::MacroMatcher &matcher); + virtual void visit (AST::MacroRulesDefinition &rules_def); + virtual void visit (AST::MacroInvocation ¯o_invoc); + virtual void visit (AST::MetaItemPath &meta_item); + virtual void visit (AST::MetaItemSeq &meta_item); + virtual void visit (AST::MetaWord &meta_item); + virtual void visit (AST::MetaNameValueStr &meta_item); + virtual void visit (AST::MetaListPaths &meta_item); + virtual void visit (AST::MetaListNameValueStr &meta_item); + virtual void visit (AST::LiteralPattern &pattern); + virtual void visit (AST::IdentifierPattern &pattern); + virtual void visit (AST::WildcardPattern &pattern); + virtual void visit (AST::RangePatternBoundLiteral &bound); + virtual void visit (AST::RangePatternBoundPath &bound); + virtual void visit (AST::RangePatternBoundQualPath &bound); + virtual void visit (AST::RangePattern &pattern); + virtual void visit (AST::ReferencePattern &pattern); + virtual void visit (AST::StructPatternFieldTuplePat &field); + virtual void visit (AST::StructPatternFieldIdentPat &field); + virtual void visit (AST::StructPatternFieldIdent &field); + virtual void visit (AST::StructPattern &pattern); + virtual void visit (AST::TupleStructItemsNoRange &tuple_items); + virtual void visit (AST::TupleStructItemsRange &tuple_items); + virtual void visit (AST::TupleStructPattern &pattern); + virtual void visit (AST::TuplePatternItemsMultiple &tuple_items); + virtual void visit (AST::TuplePatternItemsRanged &tuple_items); + virtual void visit (AST::TuplePattern &pattern); + virtual void visit (AST::GroupedPattern &pattern); + virtual void visit (AST::SlicePattern &pattern); + virtual void visit (AST::EmptyStmt &stmt); + virtual void visit (AST::LetStmt &stmt); + virtual void visit (AST::ExprStmtWithoutBlock &stmt); + virtual void visit (AST::ExprStmtWithBlock &stmt); + virtual void visit (AST::TraitBound &bound); + virtual void visit (AST::ImplTraitType &type); + virtual void visit (AST::TraitObjectType &type); + virtual void visit (AST::ParenthesisedType &type); + virtual void visit (AST::ImplTraitTypeOneBound &type); + virtual void visit (AST::TraitObjectTypeOneBound &type); + virtual void visit (AST::TupleType &type); + virtual void visit (AST::NeverType &type); + virtual void visit (AST::RawPointerType &type); + virtual void visit (AST::ReferenceType &type); + virtual void visit (AST::ArrayType &type); + virtual void visit (AST::SliceType &type); + virtual void visit (AST::InferredType &type); + virtual void visit (AST::BareFunctionType &type); +}; + +} // namespace Resolver +} // namespace Rust + +#endif // RUST_EARLY_NAME_RESOLVER_H diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc index 4ee7175b48b..6f51bd2e5a1 100644 --- a/gcc/rust/rust-session-manager.cc +++ b/gcc/rust/rust-session-manager.cc @@ -38,6 +38,7 @@ #include "rust-imports.h" #include "rust-extern-crate.h" #include "rust-attributes.h" +#include "rust-early-name-resolver.h" #include "diagnostic.h" #include "input.h" @@ -805,6 +806,9 @@ Session::injection (AST::Crate &crate) void Session::expansion (AST::Crate &crate) { + /* We need to name resolve macros and imports here */ + Resolver::EarlyNameResolver ().go (crate); + rust_debug ("started expansion"); /* rustc has a modification to windows PATH temporarily here, which may end From patchwork Tue Feb 21 12:01:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59973 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1827853wrn; Tue, 21 Feb 2023 04:15:00 -0800 (PST) X-Google-Smtp-Source: AK7set+Xpp6smsu+oVZLsGE3fQvn9B51obUMO20xuS75x0s8tFr/SDV/ItMqffxsTgrQiyBHRXzS X-Received: by 2002:a17:906:1d45:b0:884:930:b014 with SMTP id o5-20020a1709061d4500b008840930b014mr9925110ejh.6.1676981700607; Tue, 21 Feb 2023 04:15:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981700; cv=none; d=google.com; s=arc-20160816; b=igu6/2uLLr7418B1gl644kjPn7uMa6bFI5PZynadfHJ3IVCE+2TMbMF0/XRhfTyrl5 8SHSTpGWbtdGC6s/cMiHke2+9dgZleEKgBWhVb4RcVrDTFUck4eoPr41S/84W6LXOkW8 0g1bOPtJtqWKtAKBGlv5cKNxQ2osoZPojyrciaixsBM9ijxuTHG727F+HxkDNS+RYKur qMlDK9f0rxgBHC+5T3oi9cKU19KgLGx2d0oX8+MP6Kvj8jpIURUAxcHR4y/mhNcF5fYN cpHkwbOMJTN6paEJuGTcZkZ5lVF4KkOBianOpXs7yMWs4mn9IdN7/EoEXr0up1iEOj6W D2IA== 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=ZwW22c3vcHXu7MbxASXuWQFb4wPjX3d85Vq6Q7E0s0Y=; b=TEvXULZDqT8DhuZRKZ7MkH0rBfUPu9ClOBHAn88l3sIhUEp2fALaChNoMDCmlh4kxm 35pDAvaIIh22mM6DH26b5yfv9lAeZfM2FAwFFccaLWJ8FkHakuD73c8LUoSQOWy2tDZA nc+1lMgnUKRgMKmzx9cEjeCCHbkFCz6/31moqZ+DB7i0L8BTj+9qIonUzejjCjsGpGWm Jd1+cT1TKxd29CK1auF5cx8lhzSqdxWCFrM2gVNFW6cGUkSBZUqFsgZdQIBX12SRK9V1 S4UhYay+0JihfogpLXMJvllMJiyIcFC91EdMthT0dC1FWt8CdfjYVGS2kkzDbHpwQW02 Nv4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Bn2QQhkj; 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 16-20020a170906015000b008bc21b16e15si14898042ejh.993.2023.02.21.04.15.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:15:00 -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=Bn2QQhkj; 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 1A9BF395B46C for ; Tue, 21 Feb 2023 12:07:24 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id E5E91384476D for ; Tue, 21 Feb 2023 12:03:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E5E91384476D 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-x332.google.com with SMTP id p3-20020a05600c358300b003e206711347so2928165wmq.0 for ; Tue, 21 Feb 2023 04:03:42 -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=ZwW22c3vcHXu7MbxASXuWQFb4wPjX3d85Vq6Q7E0s0Y=; b=Bn2QQhkjgNFbB9qDfD8HQYl11INgh+oiV3oQ/2itCGY9QvRw2jRzHHdj8rHvGYcwd2 5ZAPzkpe9tli8P+g96F/0gNWHQGkALU3NAnHDkE4xS8+sOWu4bNq5cMqN1P6/2GPOrsj eN+J8P2xfHtvsLtO9qzyrFFeocJiwaznbbK2BDRUiWOBoAO+JECu1/TaTGprfq4KW1m8 BB+rPtpKuC65efpQ58iTbjU+TYt/GYQocXoWFleqVdKpp5XsBVh7nOPbnRFozwuSHQy8 Ingkbz7MdPogd/tocYwymV4vQAawh1VfnENN8jTTVLDlATlJ+kwysH2oAQU2OXX4OEFN o2Qg== 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=ZwW22c3vcHXu7MbxASXuWQFb4wPjX3d85Vq6Q7E0s0Y=; b=HbtcgaLtN2Brde7h+RBTXJxiSxtCxcSm9xBmEj/mDsgs6A4kPh2cY3kw1o9w+EYswy mOsk+DShx5YX2ac6cPJ8S2xl9URxEwImwZTUv+lQsIsB477+q/NzqgwoMEuMadXyWVCA 1PuACKAgzHJqGXQKsR02TUUAaEO3BMahGWFqIvpLjA7WPlqJaqAOh7cWDdTCIj/RyYa/ 84rs+TaGF424gPEXtFenrOoDUBnUGKYCyEBe+cukRiagk4UMsTO53qhsfybJLK17Wwo3 Z6Co1tvo8qgUXd2Ie8WBT+HgI1TLPMYfsrjzlENnAqTIuxfTSCFC3ZjlL3mkRx0e6z8U tIRw== X-Gm-Message-State: AO0yUKUHHk7t7Oc3iVIJQ0kLxGbWWhQ0+NHGCHQ2FldalMpsN3KmilEC foPqjYRs9CGwZu9wXhQObJAGKhIN1l2maZ9ECw== X-Received: by 2002:a05:600c:3084:b0:3dd:97d6:8f2e with SMTP id g4-20020a05600c308400b003dd97d68f2emr3295229wmn.17.1676981021266; Tue, 21 Feb 2023 04:03:41 -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.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:40 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 021/103] gccrs: Support type resolution on super traits on dyn objects Date: Tue, 21 Feb 2023 13:01:11 +0100 Message-Id: <20230221120230.596966-22-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=ham 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?1758442763483055819?= X-GMAIL-MSGID: =?utf-8?q?1758442763483055819?= From: Philip Herron When checking if specified bounds satisfy other bounds we must lookup the super traits. To finish the support for super traits we need to redo the computation of method addresses to support super traits. Addresses #914 gcc/rust/ChangeLog: * backend/rust-compile.cc: Add note about missing support for super traits. * typecheck/rust-tyty.cc (BaseType::satisfies_bound): New function. (BaseType::bounds_compatible): New function. (DynamicObjectType::get_object_items): New function. * typecheck/rust-hir-trait-ref.h: Use new API to perform type resolution on dyn objects. --- gcc/rust/backend/rust-compile.cc | 2 ++ gcc/rust/typecheck/rust-hir-trait-ref.h | 24 +++++++++++++++++ gcc/rust/typecheck/rust-tyty.cc | 35 ++++++++----------------- 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index 13f42438b56..db08b3d595b 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -247,6 +247,8 @@ HIRCompileBase::compute_address_for_trait_item ( // Algo: // check if there is an impl-item for this trait-item-ref first // else assert that the trait-item-ref has an implementation + // + // FIXME this does not support super traits TyTy::TypeBoundPredicateItem predicate_item = predicate->lookup_associated_item (ref->get_identifier ()); diff --git a/gcc/rust/typecheck/rust-hir-trait-ref.h b/gcc/rust/typecheck/rust-hir-trait-ref.h index 7eeb3300387..0df35265959 100644 --- a/gcc/rust/typecheck/rust-hir-trait-ref.h +++ b/gcc/rust/typecheck/rust-hir-trait-ref.h @@ -380,6 +380,16 @@ public: return item_refs; } + void get_trait_items_and_supers ( + std::vector &result) const + { + for (const auto &item : item_refs) + result.push_back (&item); + + for (const auto &super_trait : super_traits) + super_trait->get_trait_items_and_supers (result); + } + void on_resolved () { for (auto &item : item_refs) @@ -451,6 +461,20 @@ public: return trait_substs; } + bool satisfies_bound (const TraitReference &reference) const + { + if (is_equal (reference)) + return true; + + for (const auto &super_trait : super_traits) + { + if (super_trait->satisfies_bound (reference)) + return true; + } + + return false; + } + private: const HIR::Trait *hir_trait_ref; std::vector item_refs; diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index 64fe0f6cfb0..e2f79971337 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -136,22 +136,18 @@ bool BaseType::satisfies_bound (const TypeBoundPredicate &predicate) const { const Resolver::TraitReference *query = predicate.get (); - for (auto &bound : specified_bounds) + for (const auto &bound : specified_bounds) { const Resolver::TraitReference *item = bound.get (); - bool found = item->get_mappings ().get_defid () - == query->get_mappings ().get_defid (); - if (found) + if (item->satisfies_bound (*query)) return true; } auto probed = Resolver::TypeBoundsProbe::Probe (this); - for (auto &b : probed) + for (const auto &b : probed) { const Resolver::TraitReference *bound = b.first; - bool found = bound->get_mappings ().get_defid () - == query->get_mappings ().get_defid (); - if (found) + if (bound->satisfies_bound (*query)) return true; } @@ -191,7 +187,6 @@ BaseType::bounds_compatible (const BaseType &other, Location locus, rust_error_at (r, "bounds not satisfied for %s %<%s%> is not satisfied", other.get_name ().c_str (), missing_preds.c_str ()); - // rust_assert (!emit_error); } } @@ -2956,23 +2951,15 @@ DynamicObjectType::get_object_items () const for (auto &bound : get_specified_bounds ()) { const Resolver::TraitReference *trait = bound.get (); - for (auto &item : trait->get_trait_items ()) - { - if (item.get_trait_item_type () - == Resolver::TraitItemReference::TraitItemType::FN - && item.is_object_safe ()) - items.push_back ({&item, &bound}); - } + std::vector trait_items; + trait->get_trait_items_and_supers (trait_items); - for (auto &super_trait : trait->get_super_traits ()) + for (auto &item : trait_items) { - for (auto &item : super_trait->get_trait_items ()) - { - if (item.get_trait_item_type () - == Resolver::TraitItemReference::TraitItemType::FN - && item.is_object_safe ()) - items.push_back ({&item, &bound}); - } + if (item->get_trait_item_type () + == Resolver::TraitItemReference::TraitItemType::FN + && item->is_object_safe ()) + items.push_back ({item, &bound}); } } return items; From patchwork Tue Feb 21 12:01:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59989 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1831715wrn; Tue, 21 Feb 2023 04:24:54 -0800 (PST) X-Google-Smtp-Source: AK7set99K7JAzUC0We6sBYQPS4EgVZIhPKlAXjSo4ZuYynsU/9YH3n6SgJmY0yGFADQ9KJ7dzifb X-Received: by 2002:aa7:c518:0:b0:4ad:1e35:771f with SMTP id o24-20020aa7c518000000b004ad1e35771fmr5394709edq.35.1676982294163; Tue, 21 Feb 2023 04:24:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982294; cv=none; d=google.com; s=arc-20160816; b=Ked+iSQS7Rs0l5Aert38jEX4ISUfU5pYk+Nolyk9OzRV8rDrbHHTiPpMjAGofxtOht Y3o7JlrQw4kMYliz8xRaDvoWzZRB6rG/VwjbGguJzsTor/yUjoOoeAdVQ/C+VgcADWv3 lJ8TMff2zTa5St2vvWJt3Ojhk/jdgT5gr1JT+URbdMqwGrGMC7tcDSV0CUQbMHUSqVP4 3flbGpJ+BycpNR9u1/v9ieX4GMhM+UY1g3m8lRm45+/PCsdAj3qrxszEvcxXN4eMZnEa S5MBEZKjBHhf36yoTzluVQ75QnmoK2y2Ih6R3nAU5BmtTzkrL5vTwL90iZFYvfdbAAkq gEWA== 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=7KR4CVS6TqOuydT8CFiWtdPOh+/9CuQWBcnE+zJXDzU=; b=u46sn0cSWAWS3esP33divfngcwl8T6qGrqjAZ8eLeC0pmgs8xESM4BwKG5ZPtqWGfS fvJTZNaYv3sHyKe6KGxPMABaWj5+P/Rs0TjkapOCpmkXjPg9J7EvlO3bqoCcRsUXvXeA 9SLENjHJEeFNT/HJhmgNfiR1Tc+JLEGgtNk+CEP1HVfSek5gomCv2TCecgwZ+b62WyYf YztKDaylQ9fC6HOb96sb12MH7uQpt7xIKOlttsQ8d7xtDU0mvuSek7udH+DHX2nsbflt 8xzvCVFeE+/l9H5ir5x+K5AzSDr6vfHArM/dRdpTx/K/zO8hWJlcgCqY6+Q9dnr92CfF oW3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=RlXRYxPH; 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 x4-20020aa7d6c4000000b004ad152b8f57si17712583edr.552.2023.02.21.04.24.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:24:54 -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=RlXRYxPH; 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 B7D43380E0F9 for ; Tue, 21 Feb 2023 12:10:03 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id 8A357384182F for ; Tue, 21 Feb 2023 12:03:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8A357384182F 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-x32e.google.com with SMTP id p18-20020a05600c359200b003dc57ea0dfeso3355536wmq.0 for ; Tue, 21 Feb 2023 04:03:43 -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=7KR4CVS6TqOuydT8CFiWtdPOh+/9CuQWBcnE+zJXDzU=; b=RlXRYxPHHSH4h8aJjgnKklFwoOpuJdlWMXj4Gvs8DHbV2b6TV2UndQdupT69Zsc9D2 6SiEj1IQ3zHDKC/6IdHTnEL3COb0/Un1m46Jtudgliin1Y0uD0Uno+K6TTEYCZaB/CG+ 4qGNurWApKwqn6hg4KJct08BJz9q48tN+gNKS2WsTP4ufYru/5XP5jGpu64QWU6zr80R uRDA953DYF17rtFLgVwdlggZ4WA7P4PKybkhPdrSa8d3/0p4neyiEoeFjZL2MPboBMx9 G5y4vtzgKUSgMUigIy4DAQeYu0xiFh/lOlyAlh9WAJ3Sas7WfITEVcNqviamUatxApim VceQ== 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=7KR4CVS6TqOuydT8CFiWtdPOh+/9CuQWBcnE+zJXDzU=; b=FIwIZw37DiDYVvDt36X6FPD7JVUOClIiKoFXFZMU2BH4C7UXOwqYv4b2kDIxdw07KY KYmY19dLXWC199ZL11ZrptrEu5bJAJSyeHouZtNjdbYSb8tBrwFwLVUw2BcjizsggLXq 2gbqBgvS8d/s8NpEVW18jSjFS30tgMJCfetY0ozGrM+Z3JED9pN8dlApeKMXqgSPu5GI PzNrc9SEOXdQK3dAF6nyNhR/UfPYYePjsbGSRODrKUpf2WyNe2eGCeZS2ktVva/CCtq7 nXaIKNqGQioUoyaiotbPFwlfzLt5cR3PVpZ4MTjL3EQdyWsR+veureHrFxCBY8SIu8ON qziQ== X-Gm-Message-State: AO0yUKXGnUp6r4wBxUTVo+C00tr71WSqr4O++c46czKEZdGRI+/Ag1np wUgihsIA/Kv1deHQhlz4f5s1t1ayZq1V+ioaVw== X-Received: by 2002:a05:600c:181c:b0:3e1:f8b3:6333 with SMTP id n28-20020a05600c181c00b003e1f8b36333mr2634715wmp.27.1676981022108; Tue, 21 Feb 2023 04:03:42 -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.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:41 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 022/103] gccrs: Add mappings for fn_once lang item Date: Tue, 21 Feb 2023 13:01:12 +0100 Message-Id: <20230221120230.596966-23-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.4 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?1758443386239110602?= X-GMAIL-MSGID: =?utf-8?q?1758443386239110602?= From: Philip Herron gcc/rust/ChangeLog: * util/rust-lang-item.h: Add `fn_once` lang item. --- gcc/rust/util/rust-lang-item.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gcc/rust/util/rust-lang-item.h b/gcc/rust/util/rust-lang-item.h index 4d9dc8a3d3a..c7e0e5c811d 100644 --- a/gcc/rust/util/rust-lang-item.h +++ b/gcc/rust/util/rust-lang-item.h @@ -73,6 +73,9 @@ public: MUT_PTR, CONST_SLICE_PTR, + // functions + FN_ONCE, + UNKNOWN, }; @@ -218,6 +221,10 @@ public: { return ItemType::CONST_SLICE_PTR; } + else if (item.compare ("fn_once") == 0) + { + return ItemType::FN_ONCE; + } return ItemType::UNKNOWN; } @@ -296,6 +303,8 @@ public: return "mut_ptr"; case CONST_SLICE_PTR: return "const_slice_ptr"; + case FN_ONCE: + return "fn_once"; case UNKNOWN: return ""; From patchwork Tue Feb 21 12:01:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59981 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1830113wrn; Tue, 21 Feb 2023 04:20:29 -0800 (PST) X-Google-Smtp-Source: AK7set9YTCWLocVDwMxeBiVa97gUHGl2a1a9VVbHxxTu2tA384XIl5HLvTXe4gUhDWRb7I6fAP0E X-Received: by 2002:aa7:d88f:0:b0:4af:59c0:744a with SMTP id u15-20020aa7d88f000000b004af59c0744amr338188edq.24.1676982028932; Tue, 21 Feb 2023 04:20:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982028; cv=none; d=google.com; s=arc-20160816; b=vNwLUfS88ffbzyweNoeE1Cp1ixN6FaaeJAktpXxzpty1KjUx3NVqYJ6ivU7cR78F6t 8blOBEx933us38TkEwz4U7AIjrqBTaU2xKKhY3QO1HJdZI8c1bwK48+c8IpD3zDmPGv6 zbDtf4RDGrR+nTwBugzk2tK1m+Cs3MlHo9UhiEhkCS7ySct06J64qLKed6MayrfAXJxQ KXM1NwOUmH9L7dQV2R78qZgDByuJXAc5ybhQLMuTcfQTbvnwMf05lSSFXv2XKiqSPws8 DOrrNXQosGy+9ZyeZdmHK2JAgPvvXgtqc8FXSKGFfH/snJ87c49iP4wjcqrNN13Pfkew Ft0Q== 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=srSagA01ccZ68G2aMDpa/IU9PN7iqhFdTZ/jo0frXcc=; b=FQd3c75xhK3zO3iafsUtTBnUUSADyeI+g0SA+6vbMruH9x9MuspfDr+QrY/8Upmn0q 9PlN/2/ZUqV7sDbGAIWIWe4Po7CwKrj4jiCXoH3gUwPoUoLBD0Iae/RPa630rH6Frn5z riGb+uGmFyNEgqZRDqK30R2yutWcJsHO++N2x1cFXyJycJ7A9kat37BfobVlBymWLRKZ zMsbQVGNXohdWq3/R+vPp4wQuop7N788ix0WRriON70623OGQhZqdcY1XQq8T7b2nhHb nFSyDmDTM1lszg5r0f7jGIfG+0Y5g00gl3Kq1f60+EZh5eq48KzfO7gv/5FTQ7vXlpdH R2mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=ajUON463; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d15-20020aa7ce0f000000b004ad05f8a5cbsi18146852edv.266.2023.02.21.04.20.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:20:28 -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=ajUON463; 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 2BE0A381BB89 for ; Tue, 21 Feb 2023 12:08:57 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id 6920F384DD30 for ; Tue, 21 Feb 2023 12:03:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6920F384DD30 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-x431.google.com with SMTP id l1so3885226wry.10 for ; Tue, 21 Feb 2023 04:03:43 -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=srSagA01ccZ68G2aMDpa/IU9PN7iqhFdTZ/jo0frXcc=; b=ajUON463a4s8hQtEFxoq72CGEN00nVouaNrORTq+BkOQUfw1hDep5TJJOHizorrUHn WDwSlUuj82X57r+C6fF5+S+0NDRNcvfrxTokZWzanh4sBL/dBJfgHOninfOKLBaLoRfg UnrHxUpAGmTiQ0ivS/h27jOhFVSxvpiEzAGQnUEoSolUvUB117gFAPh5r+YAlBt0CnAT qdY+JAqt/lUtGrsr0y5mF4DQ/6Q15DD4qTI1XLj2lgJvHrs7dBTDxS3UUpJaUmbcopAK HtCopIvfUwmMVpWhv689kmp/1o1qsObMhTALcnbhwgKpbAfCA3pcqhgm7XbPrcGLzaFJ QaJg== 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=srSagA01ccZ68G2aMDpa/IU9PN7iqhFdTZ/jo0frXcc=; b=VppxEaxF8qXml4OUVoKtPZBgfNlU6nYNdFmUhjEArqSeW6NjhW0ivmxEqywik4KfY9 hW9z4mgbb3we/nlmVvuBA+6kgHMAV51hnIQZeX5TmirCLfp0mZrF79EKK8SsSx2EUtsn dk/SSPOMsuOY3p+d7z//srSnjxvHGAKkTiXow/kQugoUlEcCBi3pwcCuiCe8BZmqC/NH ex3vmFaW+FiNY/RlqX4fdPGJgL7nm/zaoqU7JITfWNEaYFUPFIru3BBOrIotSnuZ9mzc 01wO3gFfJr/DBOcJ2r7BB2+x1FKmZn3XeLjWZa/LJoXtrRsiDNkbkOO3f0+YjCK8GZem ufmg== X-Gm-Message-State: AO0yUKU6+gfeDhRzCJKAg3wCzMszkxVj/5NBg2I94a0FcbVh8IATSggp shF2axAcPKdaFuu1ikFB+BljNxXOkwKRnJra+A== X-Received: by 2002:a05:6000:114e:b0:2c4:9d7:c7da with SMTP id d14-20020a056000114e00b002c409d7c7damr3303047wrx.65.1676981022702; Tue, 21 Feb 2023 04:03:42 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:42 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 023/103] gccrs: Add ABI mappings for rust-call to map to ABI::RUST Date: Tue, 21 Feb 2023 13:01:13 +0100 Message-Id: <20230221120230.596966-24-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=ham 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?1758443108290961686?= X-GMAIL-MSGID: =?utf-8?q?1758443108290961686?= From: Philip Herron gcc/rust/ChangeLog: * util/rust-abi.cc (get_abi_from_string): Add missing "rust-call" possibility for ABI variant. --- gcc/rust/util/rust-abi.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gcc/rust/util/rust-abi.cc b/gcc/rust/util/rust-abi.cc index 6477c3790af..36abb21520d 100644 --- a/gcc/rust/util/rust-abi.cc +++ b/gcc/rust/util/rust-abi.cc @@ -23,6 +23,8 @@ get_abi_from_string (const std::string &abi) { if (abi.compare ("rust") == 0) return Rust::ABI::RUST; + else if (abi.compare ("rust-call") == 0) + return Rust::ABI::RUST; else if (abi.compare ("rust-intrinsic") == 0) return Rust::ABI::INTRINSIC; else if (abi.compare ("C") == 0) From patchwork Tue Feb 21 12:01:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59978 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1829165wrn; Tue, 21 Feb 2023 04:18:04 -0800 (PST) X-Google-Smtp-Source: AK7set8fDRHdeCgvofcXE1ZLYy+uEgqQJpOyHCx5WUZRUDdUCH2PtptSf/c7GMFd4gAq81SmmhBi X-Received: by 2002:a17:906:bcd8:b0:8b1:2bde:5c70 with SMTP id lw24-20020a170906bcd800b008b12bde5c70mr13115750ejb.2.1676981884553; Tue, 21 Feb 2023 04:18:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981884; cv=none; d=google.com; s=arc-20160816; b=g98K32PaVZWOgQog2oQ/zPQdXg1z2rAKUu+sgvbyPaKhbFDT76AxaH+y6xPwsj7LNy /MNm6tdDOxvD2I8DqiGWgjBSTArElthAL6/WEZ4LfRZZs+kI4a3FVmMhaJjAH/8JqEwq p6Hg53mzw6Nn7W8HojME2z8neQRxaX/YVObn0MEGFh228lQWQp6lA3W3LUIdY3csSLNS CT7CsnmCYPsslbCTlJJo1ZpE+jMVWF2QE5cNKGCUsJersaN++mrfFDTj7GJa9OX6sxmh nGLIFzoiY7R1gCy/6Rgcr/I3h79KCJb34m9fQqsU8vTBNxBRl1/wv4NJCuKDDlKAvk2z SnPA== 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=TOP34unwJwUagxyVW0QAXQemUlwOVdeI9VVsZKH6Baw=; b=Ct+BHyhc0DMI8gPuHzxAGFDl4QGs8UKLOBFsVTTEWRVA3LDdZ7kug1fCH+Pzq44DOs DiUAYwlQPodRlLo96RGCesFfo1XOQ+H4zQSGFJB0Xv0tfaM3BFkK0oMXHnEUC7x2Atgo pC0x9Q3f3JDXX7aDICRn+KpgktfNmn+mk/PtLw5fXBaj+eijX8KA7E9bnlW00tJGJXCS xkdAGdoFpRwzVyMcwnmhUkFUCfPq5L+Xz/YNPPa6wQcKfQtVVgrN22aRkAw5G4sinbhX 4cOI7t2uAnEr/H3rl5oqHOKe+zG4EZWSoCWYOps1AFHzL0/DJOcGO9BL+TvSp67tVnih ZmOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b="YYpI2/f5"; 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 k24-20020a05640212d800b004acb31af1e8si18173458edx.561.2023.02.21.04.18.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:18:04 -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="YYpI2/f5"; 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 EF9AC39960F7 for ; Tue, 21 Feb 2023 12:08:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 36C08383FE03 for ; Tue, 21 Feb 2023 12:03:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 36C08383FE03 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-x436.google.com with SMTP id c12so4162418wrw.1 for ; Tue, 21 Feb 2023 04:03:44 -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=TOP34unwJwUagxyVW0QAXQemUlwOVdeI9VVsZKH6Baw=; b=YYpI2/f5Nlc0qTsm0Qe9GZBNeNx0Rp7onMyKO8DkzO6zFmIGo2uD+PQ+TR7DmSC3IN bMCQTpzRszvErzchgTm2Ui1b7ytmjHJFwP8XZg1Ney1+Y1s9xyLShDL4Nq1062QGaKMu vcItBNAR+TY4IrHsMh799yi2mu5wXuZUI12ZDGLAZMS+dpYM67PWTv8GATxOzjHzoRrT JDTMP7qr+z9u/8bmKcRGIGC2FBb6BnV+t+q1wKjM5hWDy+H4HUVyK3Qc7MfOxZWvf5ED DDijT30Y2cP8JNdREqvQuxmGG4afZ1sou1YGpbu+sTUFbpG3Qi2XktU1nr8oakPU6rLR b1RQ== 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=TOP34unwJwUagxyVW0QAXQemUlwOVdeI9VVsZKH6Baw=; b=xt5xasBL2avCTQe/FoSmF1M6W7vq17SVw4MsUBUfeDQayhKmaGj9tArgk5kKefDQLo YtypiU9xmLhxDMQCDj19c+EPwfd+hv6KrHT7agwal55p69tMQbMNuMdeF+DkgVdSimdp fIZAgVly/yphpWOWelYAQbt7SusCkJ+jNUK5QdegT1h9XyeccJ4YWi0azCDrxX2b+Ct2 ea0FcJT/djdcGxMzJ4VPN2BEXEFf7u4HZ8HVcMbC4+68Ex4vfVo9ZsVbZOeNHFwsY4g+ nIjaweHxEfzfedDM5VUTgnZ4kBgu1m6ynyyK+fv1GRJUl445DysnT0vf95jYPdiX+yzH KMLw== X-Gm-Message-State: AO0yUKVf24IavSg8oRF9qHCxuUz8YzKhWydhhE7KuqCc46AYsDpoL1kP NuB2vAUvUGyeDjDDW2UOadyYZS8zSYvcK04Ahw== X-Received: by 2002:adf:e389:0:b0:2c3:e0a0:93f with SMTP id e9-20020adfe389000000b002c3e0a0093fmr3963886wrm.8.1676981023404; Tue, 21 Feb 2023 04:03:43 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:42 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 024/103] gccrs: Method resolution must support multiple candidates Date: Tue, 21 Feb 2023 13:01:14 +0100 Message-Id: <20230221120230.596966-25-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.4 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?1758442956507981635?= X-GMAIL-MSGID: =?utf-8?q?1758442956507981635?= From: Philip Herron This patch fixes bad method resolution in our operator_overload_9 case. When we have a &mut reference to something and we deref we must resolve to the mutable reference impl block. The interface we are using to resolve methods is the can_eq interface which allows for permissive mutability which means allowing for mutable reference being unified with an immutable one. This meant we actual match against both the immutable and mutable version leading to multiple candidate error. The fix here adds a method resolution flag to the can_eq interface so that we enforce mutability equality. The other hack is that we do not allow can_eq of ParamTypes to generic Slices. I think there is some subtle thing going on for that case. The Rustc method resolver actually filters the impl blocks for reference types based looking up the relevant lang items we need to do this as well but is a much larger refactor to our method resolver which should be done seperately. Fixes #1588 gcc/rust/ChangeLog: * typecheck/rust-autoderef.cc: Add support for multiple resolution candidates. * typecheck/rust-hir-dot-operator.cc (MethodResolver::MethodResolver): Edit `try_result` field and change constructor. (MethodResolver::Probe): Return set of candidates instead of singular candidate. (MethodResolver::select): Add better implementation to account for multiple candidates. * typecheck/rust-hir-dot-operator.h (struct MethodCandidate): Overload comparison operator in order to store them in `std::set`. * typecheck/rust-hir-inherent-impl-overlap.h: Do not fail assertion on missing type. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Adapt code to use multiple candidates. * typecheck/rust-tyty.cc (set_cmp_autoderef_mode): Add code to handle automatic derefs properly. (reset_cmp_autoderef_mode): Add helper function to reset said mode. * typecheck/rust-tyty.h (set_cmp_autoderef_mode): Declare function. (reset_cmp_autoderef_mode): Likewise. * typecheck/rust-tyty-cmp.h: Add handling of `autoderef_cmp_flag` gcc/testsuite/ChangeLog: * rust/compile/generics7.rs: Fix test with missing assertion. * rust/execute/torture/operator_overload_9.rs: Fix test assertion. --- gcc/rust/typecheck/rust-autoderef.cc | 12 ++- gcc/rust/typecheck/rust-hir-dot-operator.cc | 80 ++++++++++++++++--- gcc/rust/typecheck/rust-hir-dot-operator.h | 16 +++- .../rust-hir-inherent-impl-overlap.h | 5 +- .../typecheck/rust-hir-type-check-expr.cc | 35 +++++++- gcc/rust/typecheck/rust-tyty-cmp.h | 14 +++- gcc/rust/typecheck/rust-tyty.cc | 13 +++ gcc/rust/typecheck/rust-tyty.h | 5 ++ gcc/testsuite/rust/compile/generics7.rs | 6 +- .../execute/torture/operator_overload_9.rs | 2 +- 10 files changed, 157 insertions(+), 31 deletions(-) diff --git a/gcc/rust/typecheck/rust-autoderef.cc b/gcc/rust/typecheck/rust-autoderef.cc index ca43f847e98..fe05aeec388 100644 --- a/gcc/rust/typecheck/rust-autoderef.cc +++ b/gcc/rust/typecheck/rust-autoderef.cc @@ -139,15 +139,23 @@ resolve_operator_overload_fn ( return false; auto segment = HIR::PathIdentSegment (associated_item_name); - auto candidate + auto candidates = MethodResolver::Probe (ty, HIR::PathIdentSegment (associated_item_name), true); - bool have_implementation_for_lang_item = !candidate.is_error (); + bool have_implementation_for_lang_item = !candidates.empty (); if (!have_implementation_for_lang_item) return false; + // multiple candidates? + if (candidates.size () > 1) + { + // error out? probably not for this case + return false; + } + // Get the adjusted self + auto candidate = *candidates.begin (); Adjuster adj (ty); TyTy::BaseType *adjusted_self = adj.adjust_type (candidate.adjustments); diff --git a/gcc/rust/typecheck/rust-hir-dot-operator.cc b/gcc/rust/typecheck/rust-hir-dot-operator.cc index ed2df11da45..84fa8d4f08b 100644 --- a/gcc/rust/typecheck/rust-hir-dot-operator.cc +++ b/gcc/rust/typecheck/rust-hir-dot-operator.cc @@ -25,18 +25,17 @@ namespace Resolver { MethodResolver::MethodResolver (bool autoderef_flag, const HIR::PathIdentSegment &segment_name) - : AutoderefCycle (autoderef_flag), segment_name (segment_name), - try_result (MethodCandidate::get_error ()) + : AutoderefCycle (autoderef_flag), segment_name (segment_name), result () {} -MethodCandidate +std::set MethodResolver::Probe (const TyTy::BaseType *receiver, const HIR::PathIdentSegment &segment_name, bool autoderef_flag) { MethodResolver resolver (autoderef_flag, segment_name); - bool ok = resolver.cycle (receiver); - return ok ? resolver.try_result : MethodCandidate::get_error (); + resolver.cycle (receiver); + return resolver.result; } void @@ -177,8 +176,18 @@ MethodResolver::select (const TyTy::BaseType &receiver) (unsigned long) trait_fns.size (), (unsigned long) predicate_items.size ()); - for (auto impl_item : inherent_impl_fns) + // see the follow for the proper fix to get rid of this we need to assemble + // candidates based on a match expression gathering the relevant impl blocks + // https://github.com/rust-lang/rust/blob/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/compiler/rustc_typeck/src/check/method/probe.rs#L580-L694 + TyTy::set_cmp_autoderef_mode (); + + bool found_possible_candidate = false; + for (auto &impl_item : inherent_impl_fns) { + bool is_trait_impl_block = impl_item.impl_block->has_trait_ref (); + if (is_trait_impl_block) + continue; + TyTy::FnType *fn = impl_item.ty; rust_assert (fn->is_method ()); @@ -190,13 +199,50 @@ MethodResolver::select (const TyTy::BaseType &receiver) { PathProbeCandidate::ImplItemCandidate c{impl_item.item, impl_item.impl_block}; - try_result = MethodCandidate{ + auto try_result = MethodCandidate{ PathProbeCandidate (PathProbeCandidate::CandidateType::IMPL_FUNC, fn, impl_item.item->get_locus (), c), adjustments}; - return true; + result.insert (std::move (try_result)); + found_possible_candidate = true; } } + if (found_possible_candidate) + { + TyTy::reset_cmp_autoderef_mode (); + return true; + } + + for (auto &impl_item : inherent_impl_fns) + { + bool is_trait_impl_block = impl_item.impl_block->has_trait_ref (); + if (!is_trait_impl_block) + continue; + + TyTy::FnType *fn = impl_item.ty; + rust_assert (fn->is_method ()); + + TyTy::BaseType *fn_self = fn->get_self_type (); + rust_debug ( + "dot-operator trait_impl_item fn_self={%s} can_eq receiver={%s}", + fn_self->debug_str ().c_str (), receiver.debug_str ().c_str ()); + if (fn_self->can_eq (&receiver, false)) + { + PathProbeCandidate::ImplItemCandidate c{impl_item.item, + impl_item.impl_block}; + auto try_result = MethodCandidate{ + PathProbeCandidate (PathProbeCandidate::CandidateType::IMPL_FUNC, + fn, impl_item.item->get_locus (), c), + adjustments}; + result.insert (std::move (try_result)); + found_possible_candidate = true; + } + } + if (found_possible_candidate) + { + TyTy::reset_cmp_autoderef_mode (); + return true; + } for (auto trait_item : trait_fns) { @@ -212,13 +258,19 @@ MethodResolver::select (const TyTy::BaseType &receiver) PathProbeCandidate::TraitItemCandidate c{trait_item.reference, trait_item.item_ref, nullptr}; - try_result = MethodCandidate{ + auto try_result = MethodCandidate{ PathProbeCandidate (PathProbeCandidate::CandidateType::TRAIT_FUNC, fn, trait_item.item->get_locus (), c), adjustments}; - return true; + result.insert (std::move (try_result)); + found_possible_candidate = true; } } + if (found_possible_candidate) + { + TyTy::reset_cmp_autoderef_mode (); + return true; + } for (const auto &predicate : predicate_items) { @@ -238,15 +290,17 @@ MethodResolver::select (const TyTy::BaseType &receiver) PathProbeCandidate::TraitItemCandidate c{trait_ref, trait_item, nullptr}; - try_result = MethodCandidate{ + auto try_result = MethodCandidate{ PathProbeCandidate (PathProbeCandidate::CandidateType::TRAIT_FUNC, fn->clone (), trait_item->get_locus (), c), adjustments}; - return true; + result.insert (std::move (try_result)); + found_possible_candidate = true; } } - return false; + TyTy::reset_cmp_autoderef_mode (); + return found_possible_candidate; } std::vector diff --git a/gcc/rust/typecheck/rust-hir-dot-operator.h b/gcc/rust/typecheck/rust-hir-dot-operator.h index 8341173a061..e14baf3f87d 100644 --- a/gcc/rust/typecheck/rust-hir-dot-operator.h +++ b/gcc/rust/typecheck/rust-hir-dot-operator.h @@ -35,6 +35,13 @@ struct MethodCandidate } bool is_error () const { return candidate.is_error (); } + + DefId get_defid () const { return candidate.get_defid (); } + + bool operator< (const MethodCandidate &c) const + { + return get_defid () < c.get_defid (); + } }; class MethodResolver : private TypeCheckBase, protected AutoderefCycle @@ -46,9 +53,10 @@ public: TyTy::FnType *fntype; }; - static MethodCandidate Probe (const TyTy::BaseType *receiver, - const HIR::PathIdentSegment &segment_name, - bool autoderef_flag = false); + static std::set + Probe (const TyTy::BaseType *receiver, + const HIR::PathIdentSegment &segment_name, + bool autoderef_flag = false); static std::vector get_predicate_items ( const HIR::PathIdentSegment &segment_name, const TyTy::BaseType &receiver, @@ -68,7 +76,7 @@ private: std::vector predicate_items; // mutable fields - MethodCandidate try_result; + std::set result; }; } // namespace Resolver diff --git a/gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h b/gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h index 3733f555cfb..6e2fe1b2286 100644 --- a/gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h +++ b/gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h @@ -93,8 +93,9 @@ public: HirId impl_type_id = impl->get_type ()->get_mappings ().get_hirid (); TyTy::BaseType *impl_type = nullptr; - bool ok = context->lookup_type (impl_type_id, &impl_type); - rust_assert (ok); + bool ok = query_type (impl_type_id, &impl_type); + if (!ok) + return; std::string impl_item_name; ok = ImplItemToName::resolve (impl_item, impl_item_name); diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc index 2f22c82f063..4e377d52a0f 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc @@ -1015,10 +1015,10 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr) context->insert_receiver (expr.get_mappings ().get_hirid (), receiver_tyty); - auto candidate + auto candidates = MethodResolver::Probe (receiver_tyty, expr.get_method_name ().get_segment ()); - if (candidate.is_error ()) + if (candidates.empty ()) { rust_error_at ( expr.get_method_name ().get_locus (), @@ -1027,6 +1027,19 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr) return; } + if (candidates.size () > 1) + { + RichLocation r (expr.get_method_name ().get_locus ()); + for (auto &c : candidates) + r.add_range (c.candidate.locus); + + rust_error_at ( + r, "multiple candidates found for method %<%s%>", + expr.get_method_name ().get_segment ().as_string ().c_str ()); + return; + } + + auto candidate = *candidates.begin (); rust_debug_loc (expr.get_method_name ().get_locus (), "resolved method to: {%u} {%s}", candidate.candidate.ty->get_ref (), @@ -1422,14 +1435,28 @@ TypeCheckExpr::resolve_operator_overload ( return false; auto segment = HIR::PathIdentSegment (associated_item_name); - auto candidate + auto candidates = MethodResolver::Probe (lhs, HIR::PathIdentSegment (associated_item_name)); - bool have_implementation_for_lang_item = !candidate.is_error (); + bool have_implementation_for_lang_item = candidates.size () > 0; if (!have_implementation_for_lang_item) return false; + if (candidates.size () > 1) + { + // mutliple candidates + RichLocation r (expr.get_locus ()); + for (auto &c : candidates) + r.add_range (c.candidate.locus); + + rust_error_at ( + r, "multiple candidates found for possible operator overload"); + + return false; + } + // Get the adjusted self + auto candidate = *candidates.begin (); Adjuster adj (lhs); TyTy::BaseType *adjusted_self = adj.adjust_type (candidate.adjustments); diff --git a/gcc/rust/typecheck/rust-tyty-cmp.h b/gcc/rust/typecheck/rust-tyty-cmp.h index d47cbb4369a..5dfd2d7184a 100644 --- a/gcc/rust/typecheck/rust-tyty-cmp.h +++ b/gcc/rust/typecheck/rust-tyty-cmp.h @@ -28,6 +28,10 @@ namespace Rust { namespace TyTy { +// we need to fix this properly by implementing the match for assembling +// candidates +extern bool autoderef_cmp_flag; + class BaseCmp : public TyConstVisitor { public: @@ -1244,6 +1248,9 @@ public: auto other_base_type = type.get_base (); bool mutability_ok = base->is_mutable () ? type.is_mutable () : true; + if (autoderef_cmp_flag) + mutability_ok = base->mutability () == type.mutability (); + if (!mutability_ok) { BaseCmp::visit (type); @@ -1289,9 +1296,10 @@ public: auto base_type = base->get_base (); auto other_base_type = type.get_base (); - // rust is permissive about mutablity here you can always go from mutable to - // immutable but not the otherway round bool mutability_ok = base->is_mutable () ? type.is_mutable () : true; + if (autoderef_cmp_flag) + mutability_ok = base->mutability () == type.mutability (); + if (!mutability_ok) { BaseCmp::visit (type); @@ -1370,7 +1378,7 @@ public: void visit (const ArrayType &) override { ok = true; } - void visit (const SliceType &) override { ok = true; } + void visit (const SliceType &) override { ok = !autoderef_cmp_flag; } void visit (const BoolType &) override { ok = true; } diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index e2f79971337..462c5bf91fd 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -32,6 +32,19 @@ namespace Rust { namespace TyTy { +bool autoderef_cmp_flag = false; + +void +set_cmp_autoderef_mode () +{ + autoderef_cmp_flag = true; +} +void +reset_cmp_autoderef_mode () +{ + autoderef_cmp_flag = false; +} + std::string TypeKindFormat::to_string (TypeKind kind) { diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index a033fcad6c9..b17f01f67ea 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -135,6 +135,11 @@ protected: std::vector specified_bounds; }; +extern void +set_cmp_autoderef_mode (); +extern void +reset_cmp_autoderef_mode (); + class TyVisitor; class TyConstVisitor; class BaseType : public TypeBoundsMappings diff --git a/gcc/testsuite/rust/compile/generics7.rs b/gcc/testsuite/rust/compile/generics7.rs index 2a41632e693..2789c30ee38 100644 --- a/gcc/testsuite/rust/compile/generics7.rs +++ b/gcc/testsuite/rust/compile/generics7.rs @@ -3,13 +3,13 @@ struct Foo { } impl Foo { - fn bar(self) -> isize { // { dg-error "duplicate definitions with name bar" } + fn bar(self) -> isize { self.a } } impl Foo { - fn bar(self) -> char { // { dg-error "duplicate definitions with name bar" } + fn bar(self) -> char { self.a } } @@ -23,4 +23,6 @@ impl Foo { fn main() { let a = Foo { a: 123 }; a.bar(); + // { dg-error "multiple candidates found for method .bar." "" { target *-*-* } .-1 } + // { dg-error "failed to type resolve expression" "" { target *-*-* } .-2 } } diff --git a/gcc/testsuite/rust/execute/torture/operator_overload_9.rs b/gcc/testsuite/rust/execute/torture/operator_overload_9.rs index fbb96a60d36..fd972e28ab3 100644 --- a/gcc/testsuite/rust/execute/torture/operator_overload_9.rs +++ b/gcc/testsuite/rust/execute/torture/operator_overload_9.rs @@ -1,4 +1,4 @@ -/* { dg-output "imm_deref\n123\n" } */ +/* { dg-output "mut_deref\n123\n" } */ extern "C" { fn printf(s: *const i8, ...); } From patchwork Tue Feb 21 12:01:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59977 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1828884wrn; Tue, 21 Feb 2023 04:17:24 -0800 (PST) X-Google-Smtp-Source: AK7set/SnssuaNvVjIVOrdo11eMu6YeRvCRDBol/E4quTIoW852Szr5tV8EO0FxDGadNl/dIXapf X-Received: by 2002:a17:906:aac6:b0:8b2:fa6d:45d5 with SMTP id kt6-20020a170906aac600b008b2fa6d45d5mr14699256ejb.71.1676981844596; Tue, 21 Feb 2023 04:17:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981844; cv=none; d=google.com; s=arc-20160816; b=ExNM9sJGy6bvZcuRAS/X13GsXrPplITcS8KF8BhmCYqENgMNT3y1UTo2PNrtND5nrA okgEqz6XMIzZyBnsib2wRidpxLj8EX5asy3/hhAtdSYVmaa58U6dl9Mx7j65Q5iyAmQZ v714QoENewpJo40SpHP2ZPKcDM8LamQSXUMdUis567Cs3YOV3ooyesiorTcnqqk6V9el 6NvbJjzHn2dwQ/nNyKHcx0bPyohtTfneJRlNNnSn047WNTNW8QHakIJtgzek2aFIIBKf VhYjdEBLfYaF/IR4zpa12Wl4jJnHO1/4kJEEs3HUbESUijPXgmTIYsDYaFV/KCarDbOR hB7g== 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=2Wf5brmIn2Hriw2LNJ4HRFXIl5pkjH3B9BtsPEVbJ4Y=; b=XxsKLXzJTjWEhicU2GCdd4ZBnPpTgM7asj3352XcVhe0jU2VX+eSBKle2itB5eqfg+ pZ+J5Y0lsDqQPQMENEMqAb88OBDbdV/3IM56h79NftEiDUXDIhCJEw6hubNlUo0p6k/h UP4ul9asvJIdn9C2C4VQhdNvDt3zuIRRTfJXNy65VBuIDaoMM1sCa9DpBJUYpq2wbD8d ltrtTyvtX/r2V9r4FfMTZbP5bYzvBZC1qOsBEdVGMT8y17jMJIBS7pHwRaM91ANm2Ovk 5NrdqvpZDTgfhqlhwM8U5cYecOyPQN7Bf3bgbYslZ9HlcnDg9BncloVbp652rCx09KEp msYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=KAGWwTc0; 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 fb7-20020a1709073a0700b008cd04d9ea72si8644172ejc.847.2023.02.21.04.17.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:17:24 -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=KAGWwTc0; 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 09F893AA8CBB for ; Tue, 21 Feb 2023 12:08:08 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id 73A1C383FE0E for ; Tue, 21 Feb 2023 12:03:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 73A1C383FE0E 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-x433.google.com with SMTP id p8so4289980wrt.12 for ; Tue, 21 Feb 2023 04:03:44 -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=2Wf5brmIn2Hriw2LNJ4HRFXIl5pkjH3B9BtsPEVbJ4Y=; b=KAGWwTc0T+Qj7CKivYuS8WASp/hZuB2aqKSnLn7fI9YwU6zKtbsr1pWXpd52OVZvWP YcYomugRKtfMvywdEslTeBBOzyAwzu9kPmUiakEs97Bgt1Zx1LdHOSB/LudkZzvevi/i VW4Y8HTcS0ufUiYgPWxTIbv77z4XGf76zpVJtwvYTdIGQxLGkzvkwIwXTIDGiLOPcsQO h7g2TKol3r1/RyndlVSfNq0oZvD15bM3zSpnrbqSOb+02ITIzw3+Hb3hVrRyCvFTAAPC NgLMWrhVVx/0by9sdCE930k7q7JTsu7eUgs8zOc9AzDvTwkfbUn9nIkM4saIjQyVQpM7 9brg== 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=2Wf5brmIn2Hriw2LNJ4HRFXIl5pkjH3B9BtsPEVbJ4Y=; b=MzxW82/n5Lpk8r2Qoy3ZV0ZLHZoQ4YF0k9hb9E66ayIh6imZIO1uI/vzu8lJraPyHP P5DIIUpkpR0/6at0n+yPEwDqj31L6Dgm7YuPC06J13jWe8YLOWzoYjHCKBQJRd8JF4g2 zlBn03RnUebQQ1bjcLs5UQVONtkOkUn3yhwLABn0CiLbWs8lKVjZrD6ioIT8wDaiBNYG GexqIIStbuzZ76HKP7VkQql9oTwohV7lQbrB9vBdcAi2vGiAvI7GxFsiwXQkqkc9waEM ZUhqySF1HivhIGvONq4zEivpkyHt02dVnjOaNFrOWW3hrD8SyF3NYnCAlM6Zsip6S9+D /iGA== X-Gm-Message-State: AO0yUKXS9AT8BhbukCFeS5VCF+Eq/uugYziuhHMwMX4hdB3c0ZuoSb8m Gdw++b1GNVQhOmVRl18vVoDmCNSf8n8E/WPrnw== X-Received: by 2002:adf:e445:0:b0:2c5:48ed:d258 with SMTP id t5-20020adfe445000000b002c548edd258mr3820798wrm.35.1676981023855; Tue, 21 Feb 2023 04:03:43 -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.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:43 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, David Faust Subject: [committed 025/103] gccrs: ast: dump: fix extra newline in block without tail Date: Tue, 21 Feb 2023 13:01:15 +0100 Message-Id: <20230221120230.596966-26-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.4 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?1758442914768358357?= X-GMAIL-MSGID: =?utf-8?q?1758442914768358357?= From: David Faust gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Fix block formatting. --- gcc/rust/ast/rust-ast-dump.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 7cbdfa21fcb..3b00c9fedb6 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -498,11 +498,11 @@ Dump::visit (BlockExpr &expr) { stream << indentation; expr.get_tail_expr ()->accept_vis (*this); - stream << " /* tail expr */"; + stream << " /* tail expr */\n"; } indentation.decrement (); - stream << "\n" << indentation << "}\n"; + stream << indentation << "}\n"; } void From patchwork Tue Feb 21 12:01:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59994 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1832784wrn; Tue, 21 Feb 2023 04:27:37 -0800 (PST) X-Google-Smtp-Source: AK7set/a2n4PpGd7CRf5UD2aNetXlixl675ql4eY+JZoxYdHo+r2K+ILcd3oqIgKZ10/Tv1OFqc4 X-Received: by 2002:a17:906:27c3:b0:885:2eb5:68a5 with SMTP id k3-20020a17090627c300b008852eb568a5mr10338144ejc.66.1676982457222; Tue, 21 Feb 2023 04:27:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982457; cv=none; d=google.com; s=arc-20160816; b=GDjtK+Q4UOVIc0ljsd8ASwO2cnl/okOKrW+oMHnPFQVr7g6MtNzwHbRDWqpRBdcGnw xQVeuO1kx2e5mapboE+Cpsv8mHcH/5z9IeGBCd7ljXdECbxi+5Q1f2Us3JnvtE4/jOi/ y6JyuPq9ifGr/oiXuFya1WKBT2Jj2s2Y10W6bYy7oiHGtwYiAI16nrUs9SHWTIoRluBI xHGPpI8Bvk4CdK1EnQwmB3WKRQWlSXK5uM/VbFK7ffsYzFxZ5kc8OvG1dhkB7O2OfLmB nROjXHCSNFerY06Bdk/Fi7TvmhAiOv0Q7msiobPKYT/Muk26ZfHu7oWb3RxXMc4bXKqZ 6qlg== 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=uwPUebrX1sEZQcVvMyvVXXl5jvFOsJN52ZRV+SL1CnQ=; b=jESuUsZ823+3QT6ymJkP7/h0PIOvCqnIYSOEC36HwUF/cg3n4U+YJxWxC4vTa7UYoL 39D47ePg8oxgy8Myq2IlyY5HyVr1q/cszd0j32M9tGoInQ6go3j2lUO2oXym7Dj2zAs9 5cktNkhKPCjhXTR+8faUMzC7cerLndQdDLSzjaWdNwDCPs0ilxK2GEsJB/ixqiU3Qir/ rrm/5JynaBW/Bgwyaa1NJNGIIdBr/W1oYSM9nH/W9Y5b91vWZMhbf4VNxbeWVOccLzBO PoGqrCmtYc4v8lwlJM0Kpg8t4Bgc9JfbK0tHVue3PtMUGVk9YedFTCQL1HyREHoQjPAk 6YUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=TOV3lF5e; 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 ui38-20020a170907c92600b008b17879ce7asi15663667ejc.914.2023.02.21.04.27.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:27:37 -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=TOV3lF5e; 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 A88DA38B1E1C for ; Tue, 21 Feb 2023 12:10:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 0D390383FDC6 for ; Tue, 21 Feb 2023 12:03:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0D390383FDC6 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-x333.google.com with SMTP id p18-20020a05600c359200b003dc57ea0dfeso3355602wmq.0 for ; Tue, 21 Feb 2023 04:03:46 -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=uwPUebrX1sEZQcVvMyvVXXl5jvFOsJN52ZRV+SL1CnQ=; b=TOV3lF5eNT/oIft2vgnKnmoYyXalBiVzyP2Fb1zJXyldYblCGF5qIX2LZ6o0XTktFD NPhLrH5iH9xTLCJhy605Ul02UrKIDU0rzjsBgnb43/tLtX6vid2V1r0eQnomrV+lPpr8 35OvvrnCDg05ZdVJXQD0Q8hC/nDuKc/VRgXTFknR/byIpixVw0109hcXa54Rwv8TybGy ktMlQKX2UfI2JpGzh6AysoKLOfJr1bds+noVAA7+MqL1C02FRjD6h9GdIpA5bm2DjznF vOZIvKoK1SsJdMmcmoE7yeTPN8l3nKhV9OrY6Ttry/jmbCosVx2yWEuJDCT2PLyyJ+ja Q3kQ== 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=uwPUebrX1sEZQcVvMyvVXXl5jvFOsJN52ZRV+SL1CnQ=; b=L+vuvntNobCWN2uBtJsCbUW7nYM3Bb+SKA7Cioo2YgXFlDyGDpGAVl6YeJjvoChcZV pEAC6LDRErFCOE0YIPEPio/+3R/HTQeVfomsOBh3Jzpz3uMZCeQjtSceBORr+EzrOWbT mv5n+1WknQC/0BGcuP+zogMHzvz2R+3fti+eIQqvsXw44M/Tb+0T/KMQW/96POQrjGSD XuHY8WqoAg60zjuoljdXNzjmRf5RA3ycR7R8zg9K08ZvT1hoThJkZjP5LP3jbnCvOmY3 g6DfgbHI8/0xwKAQjG42BsFpm+nAWXYxGU6DTqcYmhk/HSFnRPFYA6ZZ1u7YZlSwq0lQ iHyA== X-Gm-Message-State: AO0yUKVT9zO4hQfpEbh686Ycj9oxOylc6pgKdKWgGMxOdss/vPjt4q+u +J+x4SdTs2golqGg5Uz9csZbclMTlw33HU9+4w== X-Received: by 2002:a05:600c:448a:b0:3e1:97d:612e with SMTP id e10-20020a05600c448a00b003e1097d612emr8747107wmo.29.1676981024524; Tue, 21 Feb 2023 04:03:44 -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.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:44 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, David Faust Subject: [committed 026/103] gccrs: ast: dump: minor fixups to IfExpr formatting Date: Tue, 21 Feb 2023 13:01:16 +0100 Message-Id: <20230221120230.596966-27-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=-15.1 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?1758443556918056075?= X-GMAIL-MSGID: =?utf-8?q?1758443556918056075?= From: David Faust gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Fix IfExpr formatting. --- gcc/rust/ast/rust-ast-dump.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 3b00c9fedb6..1ba84b8efa1 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -570,6 +570,7 @@ Dump::visit (IfExpr &expr) { stream << "if "; expr.vis_if_condition (*this); + stream << " "; expr.vis_if_block (*this); } @@ -578,6 +579,7 @@ Dump::visit (IfExprConseqElse &expr) { stream << "if "; expr.vis_if_condition (*this); + stream << " "; expr.vis_if_block (*this); stream << indentation << "else "; expr.vis_else_block (*this); @@ -588,8 +590,10 @@ Dump::visit (IfExprConseqIf &expr) { stream << "if "; expr.vis_if_condition (*this); + stream << " "; expr.vis_if_block (*this); - stream << indentation << "else if "; + stream << indentation << "else "; + // The "if" part of the "else if" is printed by the next visitor expr.vis_conseq_if_expr (*this); } From patchwork Tue Feb 21 12:01:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59974 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1828213wrn; Tue, 21 Feb 2023 04:15:48 -0800 (PST) X-Google-Smtp-Source: AK7set/pFoUUyCyOVSo0vth9UDCTCJTgUmbyF0+5XkVFXsLAXaqsvIuP67gnEAK5dxFVgyR7hdcU X-Received: by 2002:aa7:da04:0:b0:4ab:5ce9:9f83 with SMTP id r4-20020aa7da04000000b004ab5ce99f83mr3938382eds.23.1676981748310; Tue, 21 Feb 2023 04:15:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981748; cv=none; d=google.com; s=arc-20160816; b=PsWvx4v4R5irJ+Ep5Em8D1Qu8t2pbF2uFa6M7L84WSOycTdpkQiiZN4/jYz3e91xjo IaHrZCs903H44gOpNtPQ0MFa2KtzE8fLpwd4VOuqaJ1ChZRgLBLWYofzox+bYH9YVAmD JT4Ws/pc6KsVWfDHyJqluvX+uQXHkeEcoIT6ZoR78V7zSi6Tw/Y+0fb/nKZw+OEv1cYd vnkNgXq1m7Vea1MjqC0unIk+I+6Kgh6vvq8XYSJnwpq++kyNN1OnQMfVh10ugXFWf6b0 v3KdZ+BmY2QEQ4pKGy9nF9368jAofYVzpOvBIrgg9NrU3KlOCBy2dRqqa94wUZ6EufKo AWYA== 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=9K7lfLyTafeqFOHlHDQCdciQa00C/3w0biaTALS9ap8=; b=a5XQKVov3YKGENmtUtAZgQdaM5W2qIluWe9nH+8wOBY4rTpIO2ykYEGzMDi/XUAYRX xoUqY6+NhE7046kew1uSuBrRbuXb1jqoBjCqzzASDWGuts6GpROxWZV4y0qxUetxFP/J sTmvs3Vm8AtxYjT4fT34h0UaXWv2+TK5PAGysrLQ3jUoeZ/tID6BtqKdTiaij3uDinnR LFqpjmbP8Z5Rwo3SMmqqpsVTFgSdc0oP+kRWk4mgn1bzewj74ja/8ik7y05jWC2X8cnA 99iZxlcxBC6YK1hF57GbtrPmMLBIzIajS8iLV9sgMPh5Dt47KmdfxyduxK9ogbEZf0Vo fgGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=QqnLr3jx; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id m3-20020a50ef03000000b004acb6009aa3si19343728eds.617.2023.02.21.04.15.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:15:48 -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=QqnLr3jx; 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 BA214395BC76 for ; Tue, 21 Feb 2023 12:07:41 +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 C56BF385B50A for ; Tue, 21 Feb 2023 12:03:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C56BF385B50A 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 o14so3388110wms.1 for ; Tue, 21 Feb 2023 04:03:46 -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=9K7lfLyTafeqFOHlHDQCdciQa00C/3w0biaTALS9ap8=; b=QqnLr3jxRdw8/P56cFa6c7346rI5VO8VFNv8rSahHwe4lR9N/RKd/X5N1EOHL3PBp+ UbK7WSEh/ri30sGknENMo4bfeSMNLg6Och4S6Wj5W6coz/vuswSbnw3v/Os22TEr5zy5 67AUXjpWTDl+1gIYyyxjEH9rWMlBLaXrN+6HYKzfVrA5CDvlg3xiztOy/bCQt9bWgD9n 55Hpp0ZFQb4hp+RwovfEes10DrrkbNHjiwX1gKMyVK5mzbIUHz/OQTl+Dc7oJCINB5jW L7Cnr4hedPz5cV97/233DyXBPARptCyl1UykXt2tyKuwKefFdy9OZc7mu/kJOgbUt3BB PDxA== 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=9K7lfLyTafeqFOHlHDQCdciQa00C/3w0biaTALS9ap8=; b=lsHa1IgjK/F2+3SQMsvk7gEPxi4uA9XM3opXozjjQsiwKfprLDbaGrcXxGH1x39P+U ECINnIxucXLC+8egvIt53KbOATmu9w8v4f2izSRQ9bPdRBBZgLqX2Oqw7fFYS+CB0JPp /DCYPMW98n5GKhzNiuazS/Oz/Gfq1xYrRFjBgEdGqnHJqzk2Vmb9t4iK5BfzDpOhJ/ho Y9NWQvCvy/W3ZEtGJWJqR1jOAVPrVv1d81k0Ve6kIzsnEPtUyCmbUONn2TaiE9lsmJs0 xYiPrrL/VcxcluEX8baynBtRFKnHca3AbCiO4w031ZJRlyqUa7YWYOl+aBTaxY1SWYxV +gTA== X-Gm-Message-State: AO0yUKVf59K/Rw+HV+fnZqqAE2yJ8DCDcaeeO5IbEDLT93zn3xGJI9oY aagOW+rxldJerSG/CYcpLiUU8Sv4f/V8dLM6TA== X-Received: by 2002:a05:600c:4508:b0:3da:2500:e702 with SMTP id t8-20020a05600c450800b003da2500e702mr3377312wmo.32.1676981025320; Tue, 21 Feb 2023 04:03:45 -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.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:44 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, David Faust Subject: [committed 027/103] gccrs: ast: dump: ComparisonExpr and LazyBooleanExpr Date: Tue, 21 Feb 2023 13:01:17 +0100 Message-Id: <20230221120230.596966-28-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.4 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?1758442814011175271?= X-GMAIL-MSGID: =?utf-8?q?1758442814011175271?= From: David Faust gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add dumps for ComparisonExpr and LazyBooleanExpr. --- gcc/rust/ast/rust-ast-dump.cc | 50 +++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 1ba84b8efa1..ddc43b33512 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -327,11 +327,57 @@ Dump::visit (ArithmeticOrLogicalExpr &expr) void Dump::visit (ComparisonExpr &expr) -{} +{ + auto op = ""; + switch (expr.get_expr_type ()) + { + case ComparisonOperator::EQUAL: + op = "=="; + break; + case ComparisonOperator::NOT_EQUAL: + op = "!="; + break; + + case ComparisonOperator::GREATER_THAN: + op = ">"; + break; + + case ComparisonOperator::LESS_THAN: + op = "<"; + break; + + case ComparisonOperator::GREATER_OR_EQUAL: + op = ">="; + break; + + case ComparisonOperator::LESS_OR_EQUAL: + op = "<="; + break; + } + + expr.get_left_expr ()->accept_vis (*this); + stream << " " << op << " "; + expr.get_right_expr ()->accept_vis (*this); +} void Dump::visit (LazyBooleanExpr &expr) -{} +{ + auto op = ""; + switch (expr.get_expr_type ()) + { + case LazyBooleanOperator::LOGICAL_AND: + op = "&&"; + break; + case LazyBooleanOperator::LOGICAL_OR: + op = "||"; + break; + } + + expr.get_left_expr ()->accept_vis (*this); + stream << " " << op << " "; + expr.get_right_expr ()->accept_vis (*this); +} void Dump::visit (TypeCastExpr &expr) From patchwork Tue Feb 21 12:01:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59998 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1833490wrn; Tue, 21 Feb 2023 04:29:41 -0800 (PST) X-Google-Smtp-Source: AK7set/8ufzxzMx0URVUDdLSmY8W/sCTd0VvfbriG0kAzrqgIroFuM6/VQvOHktvtrfKIoB0bDga X-Received: by 2002:a17:906:22ce:b0:8b1:bab0:aa3d with SMTP id q14-20020a17090622ce00b008b1bab0aa3dmr15235060eja.8.1676982580925; Tue, 21 Feb 2023 04:29:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982580; cv=none; d=google.com; s=arc-20160816; b=bYcV2WeIAXkTAh4mSoymaC6TAB8cmHSKUN/mdxPWumYoEvIvL2VZsqbEoC9QE3oQ2Z KHrM7diLbZHb2Q7XC5+WkbpSvTgf58UkauRDSD+AelScjPMcZ/Up8giW/leu5qK2LsmN jS3ArQTNx/65RCuftb0dQ1rMLiHEMHUIwW+VS59Hs3UAXWotalEbMDLIVS8HoiEEIbWf R2aZUsAM11RXyTlClsbIvgNLWrWp716gvVvGa0i70vbpt9qqfyjacok4kyvWcRk9gDBH Yeg94Z8aLmJHkDmW6h7Ma0q+k4Iep4fYQnMfpnh/NP4QKCFdNttU7e0ql//BpYXkwnF7 T7hQ== 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=X3fnMK/DzNtrqsGeeABjLKt6+sn0htuGaZiMaGUt0+Y=; b=dg641NpM/ZL8/Ptuk06dOSXH719Z+EbLPq3Y/QYZN6eVnriTwNKFQ/Y/oSL+yOy0CW Cd6dekKh71rcU00XpmSfcHwgQ9SIyrltbrpfkX+C8FC7OLJsgYzv23z1qTs76Cv+GOsw PPuv/eMmEvqfZ3rW0V6X8gDErNsS8IRQ8Wf/YKuP5/qwSOh9Uvk5P/7ibVCH6CcKP3kN mkutjzdrUp4SpKUG73m40D4WK/mHm7T3XyJppprQbSzdkSgEJzoTl5mUDtRpbn504z3+ VPQ/VCLMTRdenZFkw6eEK0z4vHYNwcrMT/FT1xbvetPI/Fb5yHCrqAh2UJIFXqoZGkyA 3Fpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=KPkD9FZX; 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 zy21-20020a17090734d500b008cd6f50c059si7421209ejb.669.2023.02.21.04.29.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:29:40 -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=KPkD9FZX; 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 67B8C382E20B for ; Tue, 21 Feb 2023 12:11:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id 969773844078 for ; Tue, 21 Feb 2023 12:03:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 969773844078 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-x334.google.com with SMTP id p3-20020a05600c358300b003e206711347so2928288wmq.0 for ; Tue, 21 Feb 2023 04:03:46 -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=X3fnMK/DzNtrqsGeeABjLKt6+sn0htuGaZiMaGUt0+Y=; b=KPkD9FZXmmQfDGCHgXXmaPEJCjjLSQHEUpSj3PLhJ6FBkMFw32liJlxZJBpLmKwBEo oCqHJe1OJdvfv3rI2m+aFadGy80HB0/YczpU1ZpuoG14eRjUiMuxrcICJV876/0r4/E5 OWIUsR7pTfOTv2y9xQvLwMkuFwbXIgWRDBgM5DQY52+F0fve7WqnAXB3Me2Co9Q2Xm/U mYOehQ0+zTdKE0f9ZMTRLlnRomC98RiqRzgsJHxCcRTzrHxO61X/bxvYW5AtgK4SKych H5lLG/sn/tBAbEiUIKezl51CjTu/9N5bzgJb53P+i1emvSWTrOisGjTtWuKzGhCC1uCk cgmQ== 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=X3fnMK/DzNtrqsGeeABjLKt6+sn0htuGaZiMaGUt0+Y=; b=UWFEu9tfCDEyTR+xoqsBigXJc7gcxYizxHSf7qGMfTdh7O1iup5gqSiIJfPcjVM4o5 JQC7BpJdgMg7dMuEBvd54JF5dKpf1dMG4gGdL439ELb5EvIIgbTyAgLZg3EVVclxdfw+ myJ5VjVvJ8/b1dL0lM9Q+l9KuvAFfYsga7bb5m2Uw7li9RRIqKn7qr6TVab8sBuQNcts +029XRyKCD94lH2QkEJCzL8sJkaFqJkli/AuniG/5GuLm5oh7JlyE2mvwfu0+FRwN6Z9 EEjEXzAJ2W9aRgLMq2+RZrCHV1w3O9fUwaFVbihHmd/aO5fdXbLte6ZC5G7QRXP/b8f4 /0Jw== X-Gm-Message-State: AO0yUKVqNDcrNoQXicoA1s0zj6VHLzFjZKbJfcRC0o27M61+vsbUrwYB Lzm6rMnxXHZYYsTRgeNPnKM3USHKOMhjAf9hZg== X-Received: by 2002:a05:600c:1d23:b0:3e7:f108:664c with SMTP id l35-20020a05600c1d2300b003e7f108664cmr1079967wms.40.1676981025992; Tue, 21 Feb 2023 04:03:45 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:45 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, David Faust Subject: [committed 028/103] gccrs: ast: dump: ArrayExpr Date: Tue, 21 Feb 2023 13:01:18 +0100 Message-Id: <20230221120230.596966-29-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=-15.0 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 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?1758443686969737373?= X-GMAIL-MSGID: =?utf-8?q?1758443686969737373?= From: David Faust gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add dump code for ArrayExpr. --- gcc/rust/ast/rust-ast-dump.cc | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index ddc43b33512..91e540a1ee8 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -449,19 +449,43 @@ Dump::visit (GroupedExpr &expr) void Dump::visit (ArrayElemsValues &elems) -{} +{ + auto &vals = elems.get_values (); + if (vals.size () >= 1) + { + vals[0]->accept_vis (*this); + for (size_t i = 1; i < vals.size (); i++) + { + stream << ", "; + vals[i]->accept_vis (*this); + } + } +} void Dump::visit (ArrayElemsCopied &elems) -{} +{ + elems.get_elem_to_copy ()->accept_vis (*this); + stream << "; "; + elems.get_num_copies ()->accept_vis (*this); +} void Dump::visit (ArrayExpr &expr) -{} +{ + stream << '['; + expr.get_array_elems ()->accept_vis (*this); + stream << ']'; +} void Dump::visit (ArrayIndexExpr &expr) -{} +{ + expr.get_array_expr ()->accept_vis (*this); + stream << '['; + expr.get_index_expr ()->accept_vis (*this); + stream << ']'; +} void Dump::visit (TupleExpr &expr) From patchwork Tue Feb 21 12:01:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59980 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1829894wrn; Tue, 21 Feb 2023 04:20:00 -0800 (PST) X-Google-Smtp-Source: AK7set8SLVObr9jfG8PPzCFJ/LGKdqa528fr3gnm+/ZWjd4ISdFW7JkWXiPz2cMHLEkM+OH+MvrY X-Received: by 2002:a05:6402:755:b0:4ad:6ca7:6134 with SMTP id p21-20020a056402075500b004ad6ca76134mr5376869edy.30.1676982000506; Tue, 21 Feb 2023 04:20:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982000; cv=none; d=google.com; s=arc-20160816; b=LIrtf9hLYu3V3rE/DH5YdYs+SPeyUf5N9KtwdeuFEnBg3ywmtxz3RhDN7c5M88BWvP RRb3fOONnf+RrYO16m7j9o/yMmDFEdB69spE/N5Rn7GCrRf2ibnm7RxStGlBb1alY4Hu ziCOwRwFTfXC1r04+psHNEyhoVBb6PWTKeQoEp2MxzH4rSIsWAaSxumynvSi7Di5saVh 1BdfqTT8xfC3yWfZqPV0I1rcsY1du/VNDNShnECkvGU/rIDlnGPuFv6Sm2SKtm//T1CV dNz3lkhDIPpH/JYS6krRFo9G/JNsFYg1EwUg7ALXouv6o/eICDD5AesVOfhkS0PXowAU 6WlA== 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=T0DYbXI1IPQ+wNckeL/Ao7Wjwpi9gOtXH9sqjOHGUWo=; b=vocWjdb4Gg/iHG10hZaDEm/kLZlkJaDbID77V/WTWvnwfBWyzoH225aksdnVTDEZO5 +kkasB0VlF45FWAixGuhbxuCMBHq+Q+UBVW0R9XjyhDr6IPbAy7oRF9Dw+KwZTsxrbPA HhIXzqroQBAV+rlKO8Y3q+QW1il8FxS1GyxNQRuEvMseDA8QRp1ruAzMkJyB0XUulQrf qaIMI64b+szz+a77U1tqKWBZgzKYpphGQ7QWyTMOIH2ar28mhQJtdHM774NN17tWi+XH 2TnZ9OQXDfvbYrR+jkkygKXed2NeQBFkKDCzE1PUsHlg7KtSJzObC6AmbES9DiC0jZ65 9CvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=AAsUsO16; 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 o2-20020a056402038200b004ad79746598si6953386edv.173.2023.02.21.04.20.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:20:00 -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=AAsUsO16; 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 9DEA238362D6 for ; Tue, 21 Feb 2023 12:08:49 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id 163873843883 for ; Tue, 21 Feb 2023 12:03:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 163873843883 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-x431.google.com with SMTP id z8so3883102wrm.8 for ; Tue, 21 Feb 2023 04:03:48 -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=T0DYbXI1IPQ+wNckeL/Ao7Wjwpi9gOtXH9sqjOHGUWo=; b=AAsUsO16x2hAFtpTum+N4L9DbWJ6TSqrTcQjXN+rk1r9stTSbfv4HdXmyr/yU3JtoQ J5+WIzVHT3/Cbbu7EpNGPIIOCJcCwrV6vjo8tzwQIUoMey5XHhSPUMlwXXowNnHZ9zAN aQ+qOlG6/Of10j+8pRqbutLzzox/UTrDIX+R57sgC/F6TcpmVeSdVTn4LRdxohQuSBnO yWGRCtUnqRhCM7C96bfNQtRAqc7MbzEq4N91TLYaXimIWjeKsoaEGfkXv4X4KwZpFbkZ apSF98MpsrTKFFb0uGBEO34FmhSye8tK6k7iAIIR7AySvYqRoWRBaI64k1CuW/htPQwe 0CTg== 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=T0DYbXI1IPQ+wNckeL/Ao7Wjwpi9gOtXH9sqjOHGUWo=; b=O5/rpH7stXXbeFFhsFs+UX7Iabv77wSB8wFkrbg/h3AorrV0VVb7Z1bEc82fJncqk4 PfkYBa0scbqdekofLjtPhPcxpLAiP0/Ec/juj6k7wnrL/8BpGa2uEsqXUf1sQemKeMLL 9xSVjNHjtf/P4sQmDEl8IHnHlNYsZSSAAHnOiC7yWeSSgevnS1HBqCsAhTmdTgHzR9MJ 4VB6yFMu0d4z+yNz7cAwDCgwdPtuifr4kHIDfUcV3ZxX2UAgJKqhgZE9WUKE3axEPd45 CPwVdGkzF4LsOdg4a+BU0BKZ91+VvJNePkG8mS/FftU9y2KF/FYYRp80ws4VB3n06CY2 BnQQ== X-Gm-Message-State: AO0yUKWCe+245hcS8LnprEyYM4Hxs0BfPjJAWH+8yYtfGiTQRdzj5n5p jrMWCn2u8AEHEEVurPCZWgl9q2dE3X9fF94xPg== X-Received: by 2002:a05:6000:1c5:b0:2c5:61ef:7b36 with SMTP id t5-20020a05600001c500b002c561ef7b36mr4502501wrx.67.1676981026721; Tue, 21 Feb 2023 04:03:46 -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.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:46 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, David Faust Subject: [committed 029/103] gccrs: ast: dump: various simple Exprs Date: Tue, 21 Feb 2023 13:01:19 +0100 Message-Id: <20230221120230.596966-30-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=-15.0 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?1758443078269415822?= X-GMAIL-MSGID: =?utf-8?q?1758443078269415822?= From: David Faust Adds dump for: - BorrowExpr - DereferenceExpr - ErrorPropagationExpr - NegationExpr - TypeCastExpr - GroupedExpr gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add dump for, BorrowExpr, DereferenceExpr, ErrorPropagationExpr, NegationExpr, TypeCastExpr and GroupedExpr. --- gcc/rust/ast/rust-ast-dump.cc | 45 ++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 91e540a1ee8..b9e08b59554 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -259,19 +259,44 @@ Dump::visit (MetaItemPathLit &meta_item) void Dump::visit (BorrowExpr &expr) -{} +{ + stream << '&'; + if (expr.get_is_double_borrow ()) + stream << '&'; + if (expr.get_is_mut ()) + stream << "mut "; + + expr.get_borrowed_expr ()->accept_vis (*this); +} void Dump::visit (DereferenceExpr &expr) -{} +{ + stream << '*'; + expr.get_dereferenced_expr ()->accept_vis (*this); +} void Dump::visit (ErrorPropagationExpr &expr) -{} +{ + expr.get_propagating_expr ()->accept_vis (*this); + stream << '?'; +} void Dump::visit (NegationExpr &expr) -{} +{ + switch (expr.get_expr_type ()) + { + case NegationOperator::NEGATE: + stream << '-'; + break; + case NegationOperator::NOT: + stream << '!'; + break; + } + expr.get_negated_expr ()->accept_vis (*this); +} void Dump::visit (ArithmeticOrLogicalExpr &expr) @@ -381,7 +406,11 @@ Dump::visit (LazyBooleanExpr &expr) void Dump::visit (TypeCastExpr &expr) -{} +{ + expr.get_casted_expr ()->accept_vis (*this); + stream << " as "; + expr.get_type_to_cast_to ()->accept_vis (*this); +} void Dump::visit (AssignmentExpr &expr) @@ -445,7 +474,11 @@ Dump::visit (CompoundAssignmentExpr &expr) void Dump::visit (GroupedExpr &expr) -{} +{ + stream << '('; + expr.get_expr_in_parens ()->accept_vis (*this); + stream << ')'; +} void Dump::visit (ArrayElemsValues &elems) From patchwork Tue Feb 21 12:01:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60003 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1834484wrn; Tue, 21 Feb 2023 04:31:52 -0800 (PST) X-Google-Smtp-Source: AK7set9ydCv4ditnOmdzW4/fZ+zDFMbh0V1mi8/iHFaC1CU9LsY6HhsW9MdCSG6rpxuqcTMubIea X-Received: by 2002:a17:906:70c5:b0:8b1:3d17:811e with SMTP id g5-20020a17090670c500b008b13d17811emr11041858ejk.12.1676982712707; Tue, 21 Feb 2023 04:31:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982712; cv=none; d=google.com; s=arc-20160816; b=b3ZecB9pi6gI2O8HNdIju3LHnCyK6r78KiyhS8NVuQsCbl/N1gFN//NgJIKTh7tTqh ZUIwTPo2sT9wQzL+S+XwMAVordzX2XzZEAyC8eLIZ+DJ37p5VSFNeoUUG204MYhHfTpA chisXjUaJ77PY1CXPDxiNEDeG0BRbTYBckNNGmKEn4o7wpQrSvJkkAn1CGjReS7Ubv3X CGNl/Prpx26wqYIvGgjqHEvT14H5B7fZa2sSsxK6NngnR/Gzt+fOjpuy4T+AB9IScwDc eUHCkp0txdopKU82BS5Ael+3q3x2sWprRLRwbu73tgRWISZRJM6HnfxyZEaL7/d5aVQ+ O/iw== 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=hOqfwE3wkTzoLZ4O/E/DEsRHNpWnm2k7Dz+yLnaoaTY=; b=bVadnmEFTd2mdkW/zbruh5gDOrUDc7C7eEecg31ezDdgU2zwVv1n1wt/o3Y7HrIPE+ d0WVg88evp6rJP1FR9VSwYDr6VksHVuQV/XAheM3LOOQgfG+x3hyQdxtjlpwuGBSmMNR dYwEJUUDs5i188HpzKknXqQvEg8ksOJdRjID/rc8lepnbR5gVy1j+XMby6aUmKuu3mXh 558YTyvTCmxidHo3MjI4eIZg4qaDieC4FktnH2MSj0tnG63S8Ar9CZ6jkZeV75GockZ6 1BA6LCuj/8hJWq8aSxt6wsYQhTBU9XzkMsv0sMEZxGfSgaC7bOndw7xvrSXiZhJoU72N wxPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=DjVRMe+l; 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 ft31-20020a170907801f00b008e0927211b1si1477517ejc.775.2023.02.21.04.31.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:31:52 -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=DjVRMe+l; 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 AAA8538D1BA0 for ; Tue, 21 Feb 2023 12:11:49 +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 13F77384FB6B for ; Tue, 21 Feb 2023 12:03:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 13F77384FB6B 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 t15so4267252wrz.7 for ; Tue, 21 Feb 2023 04:03:48 -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=hOqfwE3wkTzoLZ4O/E/DEsRHNpWnm2k7Dz+yLnaoaTY=; b=DjVRMe+lFzJRs8PclEZ9svHmnqiWIZZn6WrcOtegwohdKcvxop/uUw/68ynTx9j1MY ge0QmkDpEiIrKCngu4RbHqeGArp4a6KthYsSmdaZ36oFOe/Xa5bjx8Mvz9DD5jFGrOhq rwBOUByhfiXDeJT6M4/em7KHDolkaSU7Mkdhu5ZVms+T/F86SsEzhYl22h1xbYJEm/XJ ITFB/M0/TRRmrTJx5apeaPRJdD9qPh1XLsrDVaX3zWML50ZuQVU92qicyKviObo/Yj5J wXqQv1YGpudneEBFDMvEP2LjT+4mVSIldgO5jhxBA2ot+uirfnUxQQU/yehnD5pJqXIy Djvg== 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=hOqfwE3wkTzoLZ4O/E/DEsRHNpWnm2k7Dz+yLnaoaTY=; b=mh3KpaoPr2MHUCimlCso0BpeDbpcLmUdZsTSrnYdYBE/R3BnSrCzGPIdH2tSqer3Y3 1/WLMx9eejaeeUn7i2OQTeAuqoWS/5PHRk+LeGx6gxWSAK36knieD+iCNwVJbARYf35k gdooUPWXWPWDGqi3P4zQ6n87MsZ3p8RFn4awBTCNL4G9/utmlRT9EQkTRp8aaGyww4fz 6pvOvYyn/UEaAhvSTDQsJ9znLbAyNL1VdpQxnDKiOk4nLdG2DfQkupGFM4K6CTbdcXh/ 6bIVfyuAkmNe191scXv2EwCxwxVSsJ+2MQcioSR4cjOAeXmY3TgoL4IZZpq6aFMjJeMD kA6A== X-Gm-Message-State: AO0yUKUTXVCYJ5P6ULzn1jzFnclGS+mKkHxDPq8t9VOKKcguPNL4K3zG Kq8rXCWncUVxWAEpW8vMeFT9ldLueprV1oeA+g== X-Received: by 2002:a5d:5511:0:b0:2c3:e7d8:245c with SMTP id b17-20020a5d5511000000b002c3e7d8245cmr3052626wrv.13.1676981027409; Tue, 21 Feb 2023 04:03:47 -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.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:46 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, David Faust Subject: [committed 030/103] gccrs: ast: dump: RangeExprs Date: Tue, 21 Feb 2023 13:01:20 +0100 Message-Id: <20230221120230.596966-31-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=-15.0 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?1758443825065627356?= X-GMAIL-MSGID: =?utf-8?q?1758443825065627356?= From: David Faust gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add dump for RangeExprs. --- gcc/rust/ast/rust-ast-dump.cc | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index b9e08b59554..8caad987538 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -622,27 +622,46 @@ Dump::visit (BreakExpr &expr) void Dump::visit (RangeFromToExpr &expr) -{} +{ + expr.get_from_expr ()->accept_vis (*this); + stream << ".."; + expr.get_to_expr ()->accept_vis (*this); +} void Dump::visit (RangeFromExpr &expr) -{} +{ + expr.get_from_expr ()->accept_vis (*this); + stream << ".."; +} void Dump::visit (RangeToExpr &expr) -{} +{ + stream << ".."; + expr.get_to_expr ()->accept_vis (*this); +} void Dump::visit (RangeFullExpr &expr) -{} +{ + stream << ".."; +} void Dump::visit (RangeFromToInclExpr &expr) -{} +{ + expr.get_from_expr ()->accept_vis (*this); + stream << "..="; + expr.get_to_expr ()->accept_vis (*this); +} void Dump::visit (RangeToInclExpr &expr) -{} +{ + stream << "..="; + expr.get_to_expr ()->accept_vis (*this); +} void Dump::visit (ReturnExpr &expr) From patchwork Tue Feb 21 12:01:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59993 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1832685wrn; Tue, 21 Feb 2023 04:27:21 -0800 (PST) X-Google-Smtp-Source: AK7set/9ad3nGnst8H3LaKQ3WDftFULLt/RmwNDqyijK2Qp+Yj9kpraq5RKuqTYMzJur4Gn1rP91 X-Received: by 2002:a17:907:76ad:b0:8b1:749f:b2bc with SMTP id jw13-20020a17090776ad00b008b1749fb2bcmr13488194ejc.11.1676982441898; Tue, 21 Feb 2023 04:27:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982441; cv=none; d=google.com; s=arc-20160816; b=ExLYtXP2KSCCsUe4/hxhb1DdgD+vbW3mZX70QxQhLsQIRdP1SLnD1dImszP8aLgVzo Y/8PrwNNVr5yX+moghqopGQObguKrRVhzgAMa6TdYXSMJvNRZUv6kPVDlgExxYDee0ni U0VmrwgZ7VTWnrN8bpu3R1BXxeKqB0cXnm7eiuIq6CPwRZKLMm8rIfgpaCXJE03TCfB9 4X0yx+zCAQQ9Lxe3ZTIaOCERiJWnC2NrpihjED/OYZTN0Ax43hy5+TCRgvBGDivFhlxg nWdO03QTVL4NZUR4QImrBj2hSx3gPxo09Ez2qJuDTNI+T/FhuXJUJpuEC7J/pDTTYSXH JiPQ== 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=pf8ctTx7dyWfWEzGSCn3OZ8N1vvNrHRekpIg9uJGwGk=; b=GqtgywxCqyBEff06QU7EkLQ3+kzAwJRbifTaVv9Ij6bhrHp8DKI8Tmiiye1xnMkiPa 2XRrsDgiFgNZwP7whUxozcwgcNl2Jm5jU6Qj6W6gkmqsv+pH691+j4fRhN6wEgO9dxQY wwrCNLQT6E/smOtY6835HoEUvPtXaL6/7K8X4PT39XgUN+v2wzuxa/TGsfgsvulTJcsd G1gdRTtoho4FyyxIQQ1a9YGo+pghClqDS9LLi41InVmXldLec6rnimt3TS3s+yckgPn0 UYs0YmWxic0BoILoFgYLUVjpl8Ek4Sb7O3gjdkIq+uRbskK/WRc7pWhxcQYI4ne/M0q7 SwHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Ir2S3svT; 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 20-20020a17090600d400b008dd491949c6si2940335eji.978.2023.02.21.04.27.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:27:21 -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=Ir2S3svT; 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 90A7C383DB8B for ; Tue, 21 Feb 2023 12:10:43 +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 76C02383E2A0 for ; Tue, 21 Feb 2023 12:03:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 76C02383E2A0 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 c12so4162690wrw.1 for ; Tue, 21 Feb 2023 04:03:49 -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=pf8ctTx7dyWfWEzGSCn3OZ8N1vvNrHRekpIg9uJGwGk=; b=Ir2S3svTkhTFsRVC909/++CMp7PiAQ4VSJTPaan27/dcZYsBIXA7+gWRKr8j+9ongl iqOgJLYmAMoHQP+Ay5WaBICZs6Iz0EnozOk2zN3fPeVFPVl53SSJK3wDmyd1W9x/AY+n iix+ptXdaMNtfOWsd7K03ytRmwTPSyfPiYokN/orM5pF9G/gyLVrwuopCx/kCyP7UyO6 3ZAXGdRMv3MsAwUI95DwHfrFTQxI3WTRVuVYtjje+aD7zk+P5zhZcIcD5eimgXuqk3ta 4s/xugZnDnai4RVEzn4MF66vFWmXYJpfmdXLlArRaRZTt2jCWJFFs4JqL7UmjhreLOhB bDIA== 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=pf8ctTx7dyWfWEzGSCn3OZ8N1vvNrHRekpIg9uJGwGk=; b=wrg5sJwqmFuJSMDQLunil3FwyyMlCili1q819mnO3a/rv2yuPFFTEjXlYDG8y7sIsl ddKAEJeh/varkG8Qc1zH8tLbUCEhjKODYi0NBNY3w0nB4o2tFf+UYc4sh7a420Z7U6hN 0HmmGCgZFOpqppzWGVrGD1BdVm3w2v1ALt6ycWDKVgZS9pqv3kuaAts055sTVkMtpeYk aoCTrPx136lldIvxWfWakXrwHd4gLgAcmCswCZIH7oR37NsEKow2488S3+Qgr3Dl9O9t 4aXyUkOndFmd977jQS5a7VG3TrzUyfvjTHLcON3xH4vjIK5ULyJWUty+GF8R6bf10auL Z9Ng== X-Gm-Message-State: AO0yUKU8bXfr8cfdCXgK7y9EFBhcKQHgndPkwHGevfXvtSamxlRQJY0a u0Y15P4v3YfHDI5O4zk6kknoJAkBLzBJJD4nYw== X-Received: by 2002:adf:e308:0:b0:2c5:5687:5ed5 with SMTP id b8-20020adfe308000000b002c556875ed5mr4548967wrj.18.1676981028060; Tue, 21 Feb 2023 04:03:48 -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.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:47 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 031/103] gccrs: Refactor TraitResolver to not require a visitor Date: Tue, 21 Feb 2023 13:01:21 +0100 Message-Id: <20230221120230.596966-32-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=-15.0 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?1758443540565344082?= X-GMAIL-MSGID: =?utf-8?q?1758443540565344082?= From: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-hir-trait-resolve.cc (TraitResolver::TraitResolver): Do not nullptr init `resolved_trait_reference` anymore. (TraitResolver::resolve_path): Simplify function and rename to... (TraitResolver::resolve_path_to_trait): ...this. (TraitResolver::lookup_path): Use new interface. * typecheck/rust-hir-trait-resolve.h (class TraitResolver): Do not inherit `HIRFullVisitor` class anymore. --- gcc/rust/typecheck/rust-hir-trait-resolve.cc | 53 +++++++++----------- gcc/rust/typecheck/rust-hir-trait-resolve.h | 10 ++-- 2 files changed, 26 insertions(+), 37 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc index 22398b1fa8a..1b0bcaac79d 100644 --- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc +++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc @@ -91,33 +91,42 @@ TraitResolver::Lookup (HIR::TypePath &path) return resolver.lookup_path (path); } -TraitResolver::TraitResolver () - : TypeCheckBase (), resolved_trait_reference (nullptr) -{} +TraitResolver::TraitResolver () : TypeCheckBase () {} -TraitReference * -TraitResolver::resolve_path (HIR::TypePath &path) +bool +TraitResolver::resolve_path_to_trait (const HIR::TypePath &path, + HIR::Trait **resolved) const { NodeId ref; if (!resolver->lookup_resolved_type (path.get_mappings ().get_nodeid (), &ref)) { rust_error_at (path.get_locus (), "Failed to resolve path to node-id"); - return &TraitReference::error_node (); + return false; } HirId hir_node = UNKNOWN_HIRID; if (!mappings->lookup_node_to_hir (ref, &hir_node)) { rust_error_at (path.get_locus (), "Failed to resolve path to hir-id"); - return &TraitReference::error_node (); + return false; } HIR::Item *resolved_item = mappings->lookup_hir_item (hir_node); - rust_assert (resolved_item != nullptr); - resolved_item->accept_vis (*this); - rust_assert (resolved_trait_reference != nullptr); + rust_assert (resolved_item->get_item_kind () == HIR::Item::ItemKind::Trait); + *resolved = static_cast (resolved_item); + + return true; +} + +TraitReference * +TraitResolver::resolve_path (HIR::TypePath &path) +{ + HIR::Trait *resolved_trait_reference; + bool ok = resolve_path_to_trait (path, &resolved_trait_reference); + if (!ok) + return &TraitReference::error_node (); return resolve_trait (resolved_trait_reference); } @@ -237,26 +246,10 @@ TraitResolver::resolve_trait (HIR::Trait *trait_reference) TraitReference * TraitResolver::lookup_path (HIR::TypePath &path) { - NodeId ref; - if (!resolver->lookup_resolved_type (path.get_mappings ().get_nodeid (), - &ref)) - { - rust_error_at (path.get_locus (), "Failed to resolve path to node-id"); - return &TraitReference::error_node (); - } - - HirId hir_node = UNKNOWN_HIRID; - if (!mappings->lookup_node_to_hir (ref, &hir_node)) - { - rust_error_at (path.get_locus (), "Failed to resolve path to hir-id"); - return &TraitReference::error_node (); - } - - HIR::Item *resolved_item = mappings->lookup_hir_item (hir_node); - - rust_assert (resolved_item != nullptr); - resolved_item->accept_vis (*this); - rust_assert (resolved_trait_reference != nullptr); + HIR::Trait *resolved_trait_reference; + bool ok = resolve_path_to_trait (path, &resolved_trait_reference); + if (!ok) + return &TraitReference::error_node (); TraitReference *tref = &TraitReference::error_node (); if (context->lookup_trait_reference ( diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.h b/gcc/rust/typecheck/rust-hir-trait-resolve.h index 6d4b932e468..ca23d48c3dd 100644 --- a/gcc/rust/typecheck/rust-hir-trait-resolve.h +++ b/gcc/rust/typecheck/rust-hir-trait-resolve.h @@ -55,10 +55,8 @@ private: std::vector substitutions; }; -class TraitResolver : public TypeCheckBase, private HIR::HIRFullVisitorBase +class TraitResolver : public TypeCheckBase { - using HIR::HIRFullVisitorBase::visit; - public: static TraitReference *Resolve (HIR::TypePath &path); @@ -75,10 +73,8 @@ private: TraitReference *lookup_path (HIR::TypePath &path); - HIR::Trait *resolved_trait_reference; - -public: - void visit (HIR::Trait &trait) override { resolved_trait_reference = &trait; } + bool resolve_path_to_trait (const HIR::TypePath &path, + HIR::Trait **resolved) const; }; } // namespace Resolver From patchwork Tue Feb 21 12:01:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59979 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1829845wrn; Tue, 21 Feb 2023 04:19:52 -0800 (PST) X-Google-Smtp-Source: AK7set/B4SBtAAcTWLlGTBkOxFLeV50ia3WCpdJTluyObVJvYkBeq18PIWp2TOu5Ae8eNwH8yHXO X-Received: by 2002:a05:6402:3890:b0:4a3:43c1:843e with SMTP id fd16-20020a056402389000b004a343c1843emr4882117edb.18.1676981992290; Tue, 21 Feb 2023 04:19:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981992; cv=none; d=google.com; s=arc-20160816; b=KmlnpF8REfHSFIvzyxaqyFQ2tsl8hEi68XAoERKyyLcIVeX1wHOT3ZrCzk6hVDZlmc 3paVR7vG9PAtCURGz0ITC8VAwqy0UplxrEZmIIph+XdQOOn5XvPWZs9eKovoN256ayDi Gv+UiTpw6NVW8dkPLQcU4qyxFAR2aVPoYHaAbizY8Jdoi9WCiB2BPM0XG1sbr0C9Ax3/ sdfH4mHoLwkZ4h9CB1puytrlejFm6Tfjisc8lfPXRuyDSBRsPjD8SoH6+abCi+xwBWhY tMaC/VTL6K4GxOvYqrrmhsysEiA9pKdFLQAbfCP3gMjbOKz5DDGtpx2ciA7MulgDpu3I /ZZA== 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=slQAgBMvj8tODNXriziEsytCKWacvcjyFcx6cI9juKU=; b=pQcZ862U4JvEzoXEFb5zrN2c5RiYpmtseFHXrCLp8rCJB5FzM1S2raAiqvhcEbjT9i jFnEozK4qbv3zTPRMTSCjDeAr84+b+drXgJrCYMvUa7kL/UJwA4Qq6zt3NOOnplQCy35 41UB8N8dejrXVnZP6ZeF8zdFhIlwJqN9o0u65x7B8hAyQG2OCb/6knOjxaIzXMOG2IKP tImQGBp8qvb+FF8sH/RtaB1N3ET66txnkgcdrWeco3yRMKaBTo0ikMI8Qmc10hlcieKt BgzFD+/voo7LLwWjd+q91TYG5Xiz3YQUiX+t2UJ4n+iUkCEqJbN/F6lpb/iVmL/koR1C t02w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=OSbRP1u8; 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 u4-20020aa7d0c4000000b004aef6266c6bsi7024902edo.325.2023.02.21.04.19.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:19:52 -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=OSbRP1u8; 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 2DF97382999E for ; Tue, 21 Feb 2023 12:08:48 +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 5B033383E29A for ; Tue, 21 Feb 2023 12:03:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5B033383E29A 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 l1so3885566wry.10 for ; Tue, 21 Feb 2023 04:03:49 -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=slQAgBMvj8tODNXriziEsytCKWacvcjyFcx6cI9juKU=; b=OSbRP1u8kYyQ1D8U6apKacJH7miaxFyQycag6ERnyy47ye8qSXUB2EDzoDpjOo42BF wFqCSELXmTu8LwlDthM1VyNAvTf2Rg8AXh6kVOoOFYSAg9vF9fv+Z5JFolLNozfJdakG gayRjGv9GB6anMewlxMbEsjlWPD+y+J+R1gCVkeV4SFPpMS9XvzNfKwQi5wExSn6b6Y8 K6yGZ/2RQqBZgKhKNfItjAd9ewiO8uCCxFWcE6Q5ANoddr1ahuUEpR2nzrNSYg7IXV5y KR58aP4WWjZWEpg3NiCspPZ0VMSt0STalPmDRqq/2q7xjtWrXyBxHIZEoVVoSi4K0xa2 IF+A== 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=slQAgBMvj8tODNXriziEsytCKWacvcjyFcx6cI9juKU=; b=FuXsvr8qWC1dV5J4+9HO+WGbVbqf4VlBKuAdyVoZgNdzZJ5ocjwV4Q9x9uOsafF/zk EdpJHsAzEhbzNh4ve2ecUuimd8oJrqbdKwtcBuPA/D+tf6M1qOBwmoY1vr7I/hevKwED lIrsitUnx8iupiL4i40iGv5AfFtPhREBQbAPM6siOFBGNX6Cpi7rOL75hWcvxiO6G0yW SdQD+ZqnTNqD6V0/YIOP3BQfGiLcaqraehV9mHS9JKP6ZegMakP84PK193IJZXHJanpl dxBx7zmSMzogQhS1bHSQg6hSLBdWRybyQ/ghH5wph+ceEtih/RokNvQ1nzjLfuVyPdK8 Anfw== X-Gm-Message-State: AO0yUKW6KMxhHDQlyQ0rwPKLx6Ktp6vIq197gWGOFU1qx9dZlmU5rNKP TewznbrqAg0ZSV2Jc0AaxGw6P0Tj9zA45UWgUw== X-Received: by 2002:a05:6000:1f10:b0:2c5:512c:f499 with SMTP id bv16-20020a0560001f1000b002c5512cf499mr3279850wrb.27.1676981028702; Tue, 21 Feb 2023 04:03:48 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:48 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 032/103] gccrs: ast: dump TypeAlias Date: Tue, 21 Feb 2023 13:01:22 +0100 Message-Id: <20230221120230.596966-33-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.4 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?1758443069585571795?= X-GMAIL-MSGID: =?utf-8?q?1758443069585571795?= From: Jakub Dupak gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add code for dumping type aliases. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 8caad987538..fdcd97561bb 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -836,7 +836,6 @@ Dump::visit (Function &function) { emit_visibility (function.get_visibility ()); stream << "fn " << function.get_function_name (); - if (function.has_generics ()) emit_generic_params (function.get_generic_params ()); @@ -872,7 +871,24 @@ Dump::visit (Function &function) void Dump::visit (TypeAlias &type_alias) -{} +{ + // Syntax: + // Visibility? type IDENTIFIER GenericParams? WhereClause? = Type; + + // Note: Associated types are handled by `AST::TraitItemType`. + + if (type_alias.has_visibility ()) + emit_visibility (type_alias.get_visibility ()); + stream << "type " << type_alias.get_new_type_name (); + if (type_alias.has_generics ()) + emit_generic_params (type_alias.get_generic_params ()); + if (type_alias.has_where_clause ()) + { + } // FIXME: WhereClause + stream << " = "; + type_alias.get_type_aliased ()->accept_vis (*this); + stream << ";\n"; +} void Dump::visit (StructStruct &struct_item) From patchwork Tue Feb 21 12:01: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: 59996 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1833423wrn; Tue, 21 Feb 2023 04:29:27 -0800 (PST) X-Google-Smtp-Source: AK7set8TfNgbveaGUILhWqlKSUS1MgSsMeqvLqGbnkrBOqiqc30D5hDyeAk/RxQAZP1N2rRHHn0p X-Received: by 2002:a17:907:6d99:b0:8d7:153:1486 with SMTP id sb25-20020a1709076d9900b008d701531486mr5381026ejc.20.1676982567551; Tue, 21 Feb 2023 04:29:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982567; cv=none; d=google.com; s=arc-20160816; b=ADHC4n237y1SOfRcqto/wxHQ69UaTymn1U8kgtiqBUN6QqOwusqG7SyBXHcXMgNHjJ 27aSgyllKQvvKe8z+Qesz/C+wsliTLtz/QynU8wvu1yoNcNsVk3HKCzeCicQXJnnadW/ 66QsrrWOGz3R9d2vGe+s13mJjDU3Og1mhcRCN+STC3573Qso16+EY8zluuS/4GKZOsOg RXykGIeVAyS3a9gIFxnWhMEh2unOqYUars+yVHHwoVy00KiAS0zkNrfLgkP7vU+h2L8z txwNcosMWJoPrAqDZYhyY+7qt3U5v0b/OI3xvItx2vEV7K7HpTNw/CALhJyICONpSuhj Rb4w== 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=2kEV19E2Nn/fFi2EPMgG7Z9TklCsrbLhj0NdrpFT5u4=; b=QVBW+xxVXunL49TsSJ2AT1gky2BEXpcqASJ2feU9FfP9jZokIiOh+ustb4c4N0ucMJ aiiZMi23emtLnD04J0f3x5kEhYAj/VqiydLXcTDWC6hLRjCkRgGyZSXchWUED5ns3RfW aEmKHo9eQDiP9Chg9O/2BSzM3zm/8BNFVwTuW1XYXVpjjSf7w+y6Mqt3IKxFaCOpLviY xy8pRl1Xy9NDmOYdPIaMHVuzwJhm9Eh0pXfrkr8SJjjlaHMxxN9TAnYrmVUKEVVM98wz Pj0l8SyNcc2ro0H1JadndLYS6sXVmp/P4MB7ogpxOLEYKAlATWObzUUZO8/9e48qHos+ S+FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=E44wJ4qf; 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 ew6-20020a170907950600b008c9eb8758desi8636807ejc.915.2023.02.21.04.29.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:29:27 -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=E44wJ4qf; 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 1C793385B536 for ; Tue, 21 Feb 2023 12:11:15 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 22BDD383E2AE for ; Tue, 21 Feb 2023 12:03:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 22BDD383E2AE 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 r7so3991163wrz.6 for ; Tue, 21 Feb 2023 04:03:50 -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=2kEV19E2Nn/fFi2EPMgG7Z9TklCsrbLhj0NdrpFT5u4=; b=E44wJ4qf5ZuXm7EHmlMS+iDPOwR/b137BG0a9lXt6jZucvULhJ3gbJnRe/WGWYehbm 49ON/WSUude38YInImUlTpdOwSsJJsSoAW2l6uWIxvb4Toms4geYWKBIA/KmjjwETBMU iKKC0yVa2cJlJ33oYQ4yqn/Bj29WWJkI8SJZejtKahZkQdPI86w/F9UflmgZLsEDy+kU TeZJ0B67XJwp+fxN9Ngw+YvXwcQ62B+EFKNCsENVuT+02H/ERS2K3ryntqfAHfw36FSq yTbN6+MEmLYCHaM8Texe2U6/MhHelNNKyaaVtvRjXDrEd/bsjmpeAfA/oq9F21R3meUF kENw== 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=2kEV19E2Nn/fFi2EPMgG7Z9TklCsrbLhj0NdrpFT5u4=; b=BiECCGtEil1pR7ws9UZY1P/2hL1WL9K225gbCPCPsP67eUmPbQwf2X/E0N3Xp76agc ptiKakRjR4O6ybTQwOTzDT9x4flK14E63V15GGxNElvSjOCxuePhupm06p7OwIWLE1R3 Df/XbsprwJiYQoXQ/6V7SU0UO0WkRslgFEH23s+ahEwPky6TV4aaKOYqj3kNCosqVXT3 ymkMUCk3B1Way97QzKmDA9o0rnjdiJJvjjXF22r2KPRfxxJJrm0xysaYVCnF+L8Kfq/I BQxCNhaNlKL3T1CWJ+VS3Ot4L8sS+bwhdEMjqAA78AQYaBVpQQSU3ywMa0joJZQNvsRh +jAg== X-Gm-Message-State: AO0yUKXQu2KzoT/yUkuU6lV9CJBWU5DgYqHYXflrUhNHrAZDZyiwY63w bVumCWgOrsk9DR3yvEsIz5NfH2fmjpqaoHbUmA== X-Received: by 2002:a5d:47c9:0:b0:2bf:bf05:85ac with SMTP id o9-20020a5d47c9000000b002bfbf0585acmr2984720wrc.23.1676981029478; Tue, 21 Feb 2023 04:03:49 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:48 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 033/103] gccrs: Support outer attribute handling on trait items just like normal items Date: Tue, 21 Feb 2023 13:01:23 +0100 Message-Id: <20230221120230.596966-34-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=-15.0 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 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?1758443672838932658?= X-GMAIL-MSGID: =?utf-8?q?1758443672838932658?= From: Philip Herron gcc/rust/ChangeLog: * hir/rust-ast-lower-base.h (class ItemWrapper): New class. * hir/rust-ast-lower-base.cc (ASTLoweringBase::handle_outer_attributes): Use `ItemWrapper` class. (ASTLoweringBase::handle_doc_item_attribute): Likewise. (ASTLoweringBase::handle_lang_item_attribute): Likewise. * hir/rust-ast-lower-implitem.h: Check outer attributes on items. * hir/tree/rust-hir-item.h: Add `get_trait_locus` methods. * hir/tree/rust-hir.h: Likewise. * util/rust-hir-map.h: Add defId mappings and associated functions. * util/rust-hir-map.cc (Mappings::insert_defid_mapping): Implement insertion to said mappings. (Mappings::lookup_trait_item_defid): And looking up said mappings. --- gcc/rust/hir/rust-ast-lower-base.cc | 6 +++--- gcc/rust/hir/rust-ast-lower-base.h | 30 +++++++++++++++++++++++--- gcc/rust/hir/rust-ast-lower-implitem.h | 14 ++++++------ gcc/rust/hir/tree/rust-hir-item.h | 6 ++++++ gcc/rust/hir/tree/rust-hir.h | 4 +++- gcc/rust/util/rust-hir-map.cc | 24 +++++++++++++++++++++ gcc/rust/util/rust-hir-map.h | 3 +++ 7 files changed, 72 insertions(+), 15 deletions(-) diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc index a4bcfd6c4b4..098014ff92b 100644 --- a/gcc/rust/hir/rust-ast-lower-base.cc +++ b/gcc/rust/hir/rust-ast-lower-base.cc @@ -824,7 +824,7 @@ ASTLoweringBase::lower_qualifiers (const AST::FunctionQualifiers &qualifiers) } void -ASTLoweringBase::handle_outer_attributes (const HIR::Item &item) +ASTLoweringBase::handle_outer_attributes (const ItemWrapper &item) { for (const auto &attr : item.get_outer_attrs ()) { @@ -855,7 +855,7 @@ ASTLoweringBase::handle_outer_attributes (const HIR::Item &item) } void -ASTLoweringBase::handle_doc_item_attribute (const HIR::Item &item, +ASTLoweringBase::handle_doc_item_attribute (const ItemWrapper &item, const AST::Attribute &attr) { auto simple_doc_comment = attr.has_attr_input () @@ -878,7 +878,7 @@ ASTLoweringBase::handle_doc_item_attribute (const HIR::Item &item, } void -ASTLoweringBase::handle_lang_item_attribute (const HIR::Item &item, +ASTLoweringBase::handle_lang_item_attribute (const ItemWrapper &item, const AST::Attribute &attr) { auto &literal = static_cast (attr.get_attr_input ()); diff --git a/gcc/rust/hir/rust-ast-lower-base.h b/gcc/rust/hir/rust-ast-lower-base.h index f08e3185451..adcbc5d2f69 100644 --- a/gcc/rust/hir/rust-ast-lower-base.h +++ b/gcc/rust/hir/rust-ast-lower-base.h @@ -29,6 +29,30 @@ namespace Rust { namespace HIR { +// proxy class so we can do attribute checking on items and trait items +class ItemWrapper +{ +public: + ItemWrapper (const HIR::Item &item) + : mappings (item.get_mappings ()), locus (item.get_locus ()), + outer_attrs (item.get_outer_attrs ()) + {} + + ItemWrapper (const HIR::TraitItem &item) + : mappings (item.get_mappings ()), locus (item.get_trait_locus ()), + outer_attrs (item.get_outer_attrs ()) + {} + + const Analysis::NodeMapping &get_mappings () const { return mappings; } + Location get_locus () const { return locus; } + const AST::AttrVec &get_outer_attrs () const { return outer_attrs; } + +private: + const Analysis::NodeMapping &mappings; + Location locus; + const AST::AttrVec &outer_attrs; +}; + // base class to allow derivatives to overload as needed class ASTLoweringBase : public AST::ASTVisitor { @@ -264,12 +288,12 @@ protected: HIR::FunctionQualifiers lower_qualifiers (const AST::FunctionQualifiers &qualifiers); - void handle_outer_attributes (const HIR::Item &item); + void handle_outer_attributes (const ItemWrapper &item); - void handle_lang_item_attribute (const HIR::Item &item, + void handle_lang_item_attribute (const ItemWrapper &item, const AST::Attribute &attr); - void handle_doc_item_attribute (const HIR::Item &item, + void handle_doc_item_attribute (const ItemWrapper &item, const AST::Attribute &attr); bool is_known_attribute (const std::string &attribute_path) const; diff --git a/gcc/rust/hir/rust-ast-lower-implitem.h b/gcc/rust/hir/rust-ast-lower-implitem.h index 69436543825..709bb573046 100644 --- a/gcc/rust/hir/rust-ast-lower-implitem.h +++ b/gcc/rust/hir/rust-ast-lower-implitem.h @@ -305,16 +305,14 @@ public: if (resolver.translated != nullptr) { - // FIXME + auto id = resolver.translated->get_mappings ().get_hirid (); + auto defid = resolver.translated->get_mappings ().get_defid (); + auto locus = resolver.translated->get_trait_locus (); - // auto id = resolver.translated->get_mappings ().get_hirid (); - // auto defid = resolver.translated->get_mappings ().get_defid (); - // auto locus = resolver.translated->get_locus (); - - // resolver.handle_outer_attributes (*resolver.translated); + resolver.handle_outer_attributes (*resolver.translated); resolver.mappings->insert_hir_trait_item (resolver.translated); - // resolver.mappings->insert_location (id, locus); - // resolver.mappings->insert_defid_mapping (defid, resolver.item_cast); + resolver.mappings->insert_location (id, locus); + resolver.mappings->insert_defid_mapping (defid, resolver.translated); } return resolver.translated; diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h index 8d371e00b98..7f665159572 100644 --- a/gcc/rust/hir/tree/rust-hir-item.h +++ b/gcc/rust/hir/tree/rust-hir-item.h @@ -2394,6 +2394,8 @@ public: return outer_attrs; } + Location get_trait_locus () const override { return get_locus (); } + protected: // Clone function implementation as (not pure) virtual method TraitItemFunc *clone_trait_item_impl () const override @@ -2480,6 +2482,8 @@ public: return outer_attrs; } + Location get_trait_locus () const override { return get_locus (); } + protected: // Clone function implementation as (not pure) virtual method TraitItemConst *clone_trait_item_impl () const override @@ -2567,6 +2571,8 @@ public: return outer_attrs; } + Location get_trait_locus () const override { return get_locus (); } + protected: // Clone function implementation as (not pure) virtual method TraitItemType *clone_trait_item_impl () const override diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h index 2614ef85b29..aa305f1590c 100644 --- a/gcc/rust/hir/tree/rust-hir.h +++ b/gcc/rust/hir/tree/rust-hir.h @@ -796,7 +796,9 @@ public: virtual const std::string trait_identifier () const = 0; - const Analysis::NodeMapping get_mappings () const { return mappings; } + const Analysis::NodeMapping &get_mappings () const { return mappings; } + + virtual Location get_trait_locus () const = 0; virtual TraitItemKind get_item_kind () const = 0; diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index 7ea782ed4c4..4aeb7f5ae18 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -316,6 +316,7 @@ Mappings::insert_defid_mapping (DefId id, HIR::Item *item) rust_assert (lookup_defid (id) == nullptr); rust_assert (lookup_local_defid (crate_num, local_def_id) == nullptr); + rust_assert (lookup_trait_item_defid (id) == nullptr); defIdMappings[id] = item; insert_local_defid_mapping (crate_num, local_def_id, item); @@ -331,6 +332,29 @@ Mappings::lookup_defid (DefId id) return it->second; } +void +Mappings::insert_defid_mapping (DefId id, HIR::TraitItem *item) +{ + CrateNum crate_num = id.crateNum; + LocalDefId local_def_id = id.localDefId; + + rust_assert (lookup_defid (id) == nullptr); + rust_assert (lookup_local_defid (crate_num, local_def_id) == nullptr); + rust_assert (lookup_trait_item_defid (id) == nullptr); + + defIdTraitItemMappings[id] = item; +} + +HIR::TraitItem * +Mappings::lookup_trait_item_defid (DefId id) +{ + auto it = defIdTraitItemMappings.find (id); + if (it == defIdTraitItemMappings.end ()) + return nullptr; + + return it->second; +} + void Mappings::insert_hir_item (HIR::Item *item) { diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h index addd9efc3b0..13cae717031 100644 --- a/gcc/rust/util/rust-hir-map.h +++ b/gcc/rust/util/rust-hir-map.h @@ -104,6 +104,8 @@ public: void insert_defid_mapping (DefId id, HIR::Item *item); HIR::Item *lookup_defid (DefId id); + void insert_defid_mapping (DefId id, HIR::TraitItem *item); + HIR::TraitItem *lookup_trait_item_defid (DefId id); void insert_local_defid_mapping (CrateNum crateNum, LocalDefId id, HIR::Item *item); @@ -307,6 +309,7 @@ private: std::map ast_crate_mappings; std::map hir_crate_mappings; std::map defIdMappings; + std::map defIdTraitItemMappings; std::map> localDefIdMappings; std::map hirModuleMappings; From patchwork Tue Feb 21 12:01:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60011 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1835638wrn; Tue, 21 Feb 2023 04:34:11 -0800 (PST) X-Google-Smtp-Source: AK7set8Ulmg6W7U0auQDFqFc4lxHpMiXrKI3XDS1CaGmb99dPZzuH8NTGkq+OOh1iaAtnFmGWskv X-Received: by 2002:a17:907:d405:b0:8af:12d9:a4ac with SMTP id vi5-20020a170907d40500b008af12d9a4acmr10675393ejc.25.1676982851654; Tue, 21 Feb 2023 04:34:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982851; cv=none; d=google.com; s=arc-20160816; b=w/1xHwgOi+bEsdj3WTKoed2o6Dcq4yrg4y+bcfr277U+Mh7oURKLJbSbxCNk6Wu9Cp dDzV3i/C96JSDtyGdKEZSaicD1XtPaXf1iz9P5JEGspIXC1dM013ww3VkE2McEZGqL9I bVLk1gOZc1DV7oZpPaCwekrW/716QSn96kMGQt4vsvNePYbrfAaC7idiSmOiX60ndhYb vYcwfemjOwUI6Zvu4rJXsPtROnJKYMCrkSElSrJQZgh0YzsZ54HJjkUH1+I6HH21ZXO7 HxmtZqAOK2fZEw6iBOAe7RHYStulobmvQKQYA3rbdGylQUu+O7d5lSTDyXguDA7Z1FHg apOQ== 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=hyrW4gYeLWwwOBxOHyE+rSZZYnyLfq0C8muqnzvHhAg=; b=u8b6edb+zSasSbAt+hdI4FtwuM9feLIJHTX3lR5+ip0EZ/gKxOiD1T48un1rTjOy1v eiiMzJCnuG1Odh2YiIi2XNOvVVgH4PT1wuRmfXX3uSXfuEfvNTFiSdm/agu9CsF/TPK7 bCveJP3S9tln3bqZlZmshdeKvDIFOO1vuKc3tKKd3OyeIS5MTY4859ktGIAyo73dXOwu UE80gezmurSAn3PMcr7AMZWNkS8GUu1XLLFhguvQF78qyjTf06LalXa1tENrRLBJLGOG LN0ntpg2EXBqgt+gmdjrlUFfHy9KIuXZwosD18v7Qot9h5TkQVwZmcyDXO7+Zh0b/y7E q1IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b="ACbf//CA"; 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 ge9-20020a170907908900b008de4a641ff4si2702063ejb.412.2023.02.21.04.34.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:34:11 -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="ACbf//CA"; 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 4FB0C38BDBEE for ; Tue, 21 Feb 2023 12:12:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 AF60F383E2BF for ; Tue, 21 Feb 2023 12:03:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AF60F383E2BF 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 j2so3982252wrh.9 for ; Tue, 21 Feb 2023 04:03:50 -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=hyrW4gYeLWwwOBxOHyE+rSZZYnyLfq0C8muqnzvHhAg=; b=ACbf//CAh8VnJZWdzO7t6ZnQOrpqjBotOglYr2wbY9TZYhi9VNyCkfijBzHiqAMCpD 5ps0w9QbwFTXdGKvTCR0Wuk3+GVf1n9FFB44mwQjx5UX8Y7DclZs8vJHFoeXJC4/fh+R tpAyVy67ouwYTl2cnMnbktrZHTVNLJN9u+Y99EDgRgsDKey9/pMJdpvxD6mubE4/wm2i eyip49xGPS5JWdxTyO58evmtHRwy5MINxD4gE+4O2UWMYrz+dZCFmu+T6y5Ory4uT4pL f0u1aRHsYxeG8Ai8KjR/cWV5ABauyx/YpRY0TGsY6iq3e9HQcQ7NsrgV4YZWjmHpVfUH D1oQ== 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=hyrW4gYeLWwwOBxOHyE+rSZZYnyLfq0C8muqnzvHhAg=; b=IloLKTCUPghmghrdrH9F3dWdn8+w15Gc5T026CtXDhDyjVa5CvOwImchRUSCG3fIUH znJj4ysHTnQO1zb3DJcxiTleLA2xmFBDvBF3zDxnwseBiqUM/wyfUgYEL7q35wn4I5S9 8MVb3m4awj/v7S9iUYwfiCd/++L2ojw5Gnat7NPCgG90XDM5fCFLVN9nL7IyIixhpYxq cc6IewT4xl2od01o6j+ur4fl1mZJ+LPgoZGfBmT6FbzOx9y0WJrrqsQkozDiw+tGxtq+ I8fXH9JFkoGTdk0xEWdSDSkpP1/UxzkDD1dy2GbLyVhGNJ7Nj6Gg2nZCD9NeKyaFSHbQ J0Dg== X-Gm-Message-State: AO0yUKXOI7nqflWZVdTl8xoYRV1063ED8XwLrsVvwtPjPuvso1pP1OKq eHeIJVY3CsE7dRddYj43KMdlGxiOoSsQKBPIag== X-Received: by 2002:adf:e199:0:b0:2c5:4659:3e76 with SMTP id az25-20020adfe199000000b002c546593e76mr3680965wrb.18.1676981030129; Tue, 21 Feb 2023 04:03:50 -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.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:49 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 034/103] gccrs: dump: Emit visibility when dumping items Date: Tue, 21 Feb 2023 13:01:24 +0100 Message-Id: <20230221120230.596966-35-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=-15.0 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 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?1758442157789204990?= X-GMAIL-MSGID: =?utf-8?q?1758443970618516914?= From: Arthur Cohen gcc/rust/ChangeLog: * ast/rust-ast-dump.cc: Emit visibility when dumping items. --- gcc/rust/ast/rust-ast-dump.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index fdcd97561bb..b7557bdee0c 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -835,6 +835,7 @@ void Dump::visit (Function &function) { emit_visibility (function.get_visibility ()); + stream << "fn " << function.get_function_name (); if (function.has_generics ()) emit_generic_params (function.get_generic_params ()); From patchwork Tue Feb 21 12:01:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60002 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1834381wrn; Tue, 21 Feb 2023 04:31:37 -0800 (PST) X-Google-Smtp-Source: AK7set+LrCvOzyd2dnOTBmRXJFLpxUcXbW7KE2FGUi1x76ChDFFLMDuwFoax+DAloBnYLu/Ic5iA X-Received: by 2002:a05:6402:10d9:b0:4ac:bd35:d05b with SMTP id p25-20020a05640210d900b004acbd35d05bmr3922478edu.27.1676982697381; Tue, 21 Feb 2023 04:31:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982697; cv=none; d=google.com; s=arc-20160816; b=CBa7lqvVtpsMnN5ak4KC7ucpLz3DpR+UlQVXj79Wo0ODApWAOuxlX1WIf3oQkeCdnv Z0SXVvVNE8CriiAuujJU+cumFKlGsuVJhDdAgQNFdi0FYa5eYUSlfJhDMm5UcXVQ8iTv pxjCHFfuI+pPdv1m727NUfPCKhXg/utTBTJqorHPiNDllxRL9Y/hS/iZFZPtEc3LZABc x7nr6uM+GN/uRWIl0VU9IdKVFoA/nZJ5k6shmfLVrwdFNdiQJzEv0uTGT63QrbdNPRXu kWzgkpuOC43f7LKxSrsQJrstAosVwEa7/UWLlr7Hf3DCCvsPRzb0rG3JsNsP4SPBHBve eavw== 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=9RyVPYw0UdE+p1GAb/kq+6qEzPD+D/YtLlfHnIbSjfM=; b=RVdWH8brRAIFvcQTbIVc2URvzCrzECgaXbu12K+rHKWMyUWaSEXi2eiYQcEc1HpSYO KDiRMh023nFuGoqlWsIiuFKZk9U1uEd+H8MqIzns6lJpLIrcIc3CXTESDCA0IH/aFrsd i35Nxt6Pupkn8vUD67RWen/kMZAIkh3OvOe1hD57p94sCV7pbjhBh5LfHSkjCeO5veDz yiGdhZgkxcNw54ijaXWSyWDVjbgBp1chadLOdzlrJHlUS9q+WMhN359LBzCMBjRapFth q4nnr+WNNkmGDdXMbnOhZzq8FKP7SLR7JEm7Amcb1DiLxME9aMomQNcfhL0fdrq0Udhj 17YA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=e6VlhmSF; 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 p18-20020a05640210d200b004acd090f0basi8461509edu.373.2023.02.21.04.31.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:31:37 -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=e6VlhmSF; 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 D45FF3AA801A for ; Tue, 21 Feb 2023 12:11:45 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 710CD3844053 for ; Tue, 21 Feb 2023 12:03:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 710CD3844053 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 bo30so3602097wrb.0 for ; Tue, 21 Feb 2023 04:03:51 -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=9RyVPYw0UdE+p1GAb/kq+6qEzPD+D/YtLlfHnIbSjfM=; b=e6VlhmSFgbmr9Pph0bEOM+I91XvRYENqKsqyDd77rEiEtpTjkfbFpJTuRmrCRuXgxQ 4/48aQoXSweUVcGCMvCNz9BL/cc9tF5MzullJ5u3e2K0ckMFugjIvuQTr2gmiNBnVepC Gkb0GyioEp6V3F9ZIp+QFzHQ/FTC4jtP9JeiP9UWcVw9twsYBBPD0nzuGG5RzLkHjxV6 anJqAGK4z4OMQOiq+A7udWacMScGdTn8p3FP8+O211gwi1DmGZrZ4JCGX2D9tbOCduYO VZWTsEqnxXmwlEe3wGYp7xg2DKrj8oB3j7fgZz2MsOMr12kovn6b+qC9ON+wEJGe9C+I IRBQ== 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=9RyVPYw0UdE+p1GAb/kq+6qEzPD+D/YtLlfHnIbSjfM=; b=Yn7+uVGm+x70XPsyigHJdRX2nsN7thB520cg/EyWqEfNXRZdf2f1X9I0hE2l/YZdYQ pdxsw0dwcyzsN5Nc4SvYIhh9KdEQuJ8Imck9nSW0fzSNSPVY+RQvO9GBn7Bn298vG5li vCs8GvZrZ/94bZsXAiPBc/wDIsr/MsJ7p7W8gt0Rxb6ZdVYy4jM8HOeVmbk8eU67kFgu /zQHH0Hi6GUXA9UP9BTfsRdFaqBdVJES1mMwjeKo0W+IlJraegBw+Ue67lw9MW8mvH/u CQ/z7wCtfELl9SDwNSOXoBveLlsFi7K1+31hft/ih70GdbbOzjCcPKhanutOvADSjbkW aaoA== X-Gm-Message-State: AO0yUKUw77X7Szgh0pEDzFXiBlSQaE6QEoMpK0kLaAdO0UeX6ldF2O5O oB5Zdne9vnViyrrV7gXdTf9Un1q2oD0+/cvYiA== X-Received: by 2002:adf:f108:0:b0:2c5:561e:809b with SMTP id r8-20020adff108000000b002c5561e809bmr4365668wro.66.1676981030809; Tue, 21 Feb 2023 04:03:50 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:50 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 035/103] gccrs: dump: Dump items within modules Date: Tue, 21 Feb 2023 13:01:25 +0100 Message-Id: <20230221120230.596966-36-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.4 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?1758443808713199629?= X-GMAIL-MSGID: =?utf-8?q?1758443808713199629?= From: Arthur Cohen gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Dump items in modules properly. --- gcc/rust/ast/rust-ast-dump.cc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index b7557bdee0c..653c1d9ff03 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -809,7 +809,23 @@ Dump::visit (Method &method) void Dump::visit (Module &module) -{} +{ + indentation.increment (); + + stream << indentation; + emit_visibility (module.get_visibility ()); + stream << "mod" << module.get_name () << " {\n"; + + for (auto &item : module.get_items ()) + { + stream << indentation; + item->accept_vis (*this); + stream << '\n'; + } + + indentation.decrement (); + stream << indentation << "}\n"; +} void Dump::visit (ExternCrate &crate) From patchwork Tue Feb 21 12:01:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60015 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1836541wrn; Tue, 21 Feb 2023 04:36:16 -0800 (PST) X-Google-Smtp-Source: AK7set/XdytrdVx+LYJF9JQkFifjQw8GjYP8MeQiDBfz5nXEc9p8H4s8wmrZdqH/pzm9uNniZG7V X-Received: by 2002:a17:906:8614:b0:8b1:3304:7767 with SMTP id o20-20020a170906861400b008b133047767mr9481824ejx.67.1676982976463; Tue, 21 Feb 2023 04:36:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982976; cv=none; d=google.com; s=arc-20160816; b=ma2+2aGl9SVxtU92nYvHlSm4DP89uR1aLBcI9RoK7k0ISgyb+PQYXO82C8BlKJPUcf g0qop2yBI3MNSv6ePXaiGy9aQQ+t0z8uHYuIlmR6qw5T1s5tT0frGvvoyg9CXoJGBFol 6BKk4MfuxFFe6Fl0F9sZToG+9vFcDGWC4xLLceG6UJgZ7piXlpFV/6X0wPIx975//7Qw uHi04axuxErj1sXqEtRNFm9D/YoI3C9isI0yQfwZl16wUcd9OMJ14CKYNLmCNAOVrKyR 9Fy1ZEsPHjiPwTcBeJ+ZOCM6Ch5QCTUV/qIeht7EXkpzs4EJlWNz9q0C6O8E09ogIBgh wxJQ== 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=zeuPinrsY6MTpPq8oRqtzBS3YcWBmw72rZi2/cH+vmg=; b=JAoDYK/J8eafTSLyw0aVIn/1WI44H2hyqR2p29Iwo3LhbKe0RlcZhtcecAWoI6zxFt UHBR1WJ4eaW03A4o4RDLid2HNcU/oiHKdtgUlua95d7DgSGSHIcBCUyZJUTwP/nYfGj2 K2DzGtaM82LaHYywKtB1wcw/t6rUohpa8vuJQFTOg2UnuVXunJNjBlq1qsxHe+EYvlqX 7WFVFPOgdJCNZcfNS6qVxuVPpdtsOYCE93nUzLOokzv8waY8xbaq+0IxqaLbvSeTpF/4 D1zvcYNlhsX+jvXmhhpLN9qtVWuLNY/AWE9qBG1cJlmEfwn6+3222mAoU48AecszIRV9 Ga1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Z2ZAmnjF; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id fb22-20020a1709073a1600b008d17b125783si7183407ejc.835.2023.02.21.04.36.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:36:16 -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=Z2ZAmnjF; 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 30A78383FE26 for ; Tue, 21 Feb 2023 12:12:57 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 0AEF7383D99B for ; Tue, 21 Feb 2023 12:03:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0AEF7383D99B 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 t15so4267482wrz.7 for ; Tue, 21 Feb 2023 04:03:52 -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=zeuPinrsY6MTpPq8oRqtzBS3YcWBmw72rZi2/cH+vmg=; b=Z2ZAmnjFa1qRtL7XYJ67WOMJoyUxKvWkuJ7mj614iL1UMCegIBsE1nc6Pun2duIHC7 qA8wkNm5DXI+4HWsuNt3i/DS3g2A1QGWWJZ1umdz4jBuEecXnUVQrys8Db+/B+fzZCf4 fX2HQqgMB0ZJaufLIPuMGyuPDN5nJq4u1tr/lrZvqJA4+tOZjLW7VT85Ahi4YMdr4+Te npNJxF7e+Mvx0nBLcqhpJJOiiUIIJCCAYzn2dA/mzNGQM9q3HJV72eYHPH2kXkGB5ZIt heouH87bWDuhmf+0Tn85lTTBI7fVxZugpQrJ+tSNQ4BgWC7gXiteDeSIQOEzZ95nM6uV npFA== 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=zeuPinrsY6MTpPq8oRqtzBS3YcWBmw72rZi2/cH+vmg=; b=66ptoXWGPwqYOBMmJuTTDhoG6xO2mdin5jfLTtqpVIPAzV02fQH28g0RwtLgFabogJ dwkGZEeOcI6YQ8A3usSJAnZhX+n+urX2E/jrcXighK2NYjB7em/39LG69ZGuz1FA6M3/ 2nfb5eCm4YcJkjgxWHw5aWhNY9Ewg7dl2aVWUNB2x50PqYz7WGs1ZEP3GMCXXAGo+JTF +4F0yBasRfXuUBjLyVwt+q8KcVP9Zy/EeTzCj5rNbGrNuJV8gsKVnbFXg5IMo8Jh4S7u /RBKJKTxTq7fYLyVHs2UB+gf89D6OINDZsuzuJ0gIly8XHyvnCjXnUBzem3P5wHadgSU BDAA== X-Gm-Message-State: AO0yUKVDQan2mlPj4+USXpl16ri5uCcmot5u3HLdib+v/DFabJUhk/DN ihc7cebDCEqNeJr1LuC3fvVDBioe3486w9xsNg== X-Received: by 2002:adf:cd8c:0:b0:2c5:4f2d:d9b4 with SMTP id q12-20020adfcd8c000000b002c54f2dd9b4mr3182878wrj.58.1676981031659; Tue, 21 Feb 2023 04:03:51 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:51 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 036/103] gccrs: dump: Fix module dumping Date: Tue, 21 Feb 2023 13:01:26 +0100 Message-Id: <20230221120230.596966-37-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?1758444101325841469?= X-GMAIL-MSGID: =?utf-8?q?1758444101325841469?= From: Arthur Cohen gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Fix formatting when dumping modules. --- gcc/rust/ast/rust-ast-dump.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 653c1d9ff03..1e7a235932d 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -810,11 +810,10 @@ Dump::visit (Method &method) void Dump::visit (Module &module) { - indentation.increment (); - - stream << indentation; emit_visibility (module.get_visibility ()); - stream << "mod" << module.get_name () << " {\n"; + stream << "mod " << module.get_name () << " {\n"; + + indentation.increment (); for (auto &item : module.get_items ()) { @@ -824,6 +823,7 @@ Dump::visit (Module &module) } indentation.decrement (); + stream << indentation << "}\n"; } From patchwork Tue Feb 21 12:01:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59983 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1830658wrn; Tue, 21 Feb 2023 04:22:04 -0800 (PST) X-Google-Smtp-Source: AK7set+9KsTViczV96cbovsZJR+Phdxqwvx9y//BGxn6/QsoducfEDHBbcC2pIp2CfPce25PX3pW X-Received: by 2002:a17:906:53da:b0:8b1:fc1a:7d21 with SMTP id p26-20020a17090653da00b008b1fc1a7d21mr14388936ejo.5.1676982124036; Tue, 21 Feb 2023 04:22:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982124; cv=none; d=google.com; s=arc-20160816; b=zsumirpbI0i3GtT1fu/CeeKLj0Cff/oTLSlkn9JOmy3kerdgpNtA7zru8Ctz5+3WNB H6EOV1/r6hgD16IzjUxsh4oLyz+K/oXd7PeLfzB/gGu9qbhjUDYbOOcC6uoi42XnuWMC rPje6x5tTFhzEe576uLqTKqCRZ6/iiXWkDhrlxg6tBVbquqx1LrXlgifn6i5GlLPHBGf bgA5X8VSSlQxacDvLHVZ8YYRleNwe/LR3Jo/705C6uSk8CKIBuDNtykr4DZ8gYAOk7lH 9P/fDZnmLpBHVzxNhQ5b9SKo7NoHMNGtKPwpv589KRhxVo9FwUpIOMpkTkVYxD1XXXdk JamA== 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=8pKvx826FvWkNnIXJQaue1CkAv0xBqaasqMXDJHejzk=; b=Bz9qw22B5KYNK7obRDpqq1WsQuAqFjatJpNhRpZftIVjI+FUSssZUDypE5TwQ8KhFi OjXBsbqS3gVNGmJbibmItMoN6AWf+27b3tfhyAzuxVr7Emfwh1u1d8SYzw2l+1QINGQU qgeMuvB2wCceO83rBP71rlJNOMBaHK6NyxusyWzQUiBihOkocRbBTg3J0lEuAMvVHUuI ZgfjGv68L3ZUJsgUKJnARl7dzjDEdqsOwKQimODb2BZ+KCQtTWwF1kXlHsYstsB2cfva le/ADqF+jrVhJ6oK0MkG6nQNgO4CTBo8HISLctLCt4d4EPr1UiSo6XsBQ7qn87eOsV1c ku6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=HII4bawz; 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 30-20020a170906011e00b008b841f2288dsi16442001eje.429.2023.02.21.04.22.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:22:04 -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=HII4bawz; 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 CC440380E0EB for ; Tue, 21 Feb 2023 12:09:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 226AA3854803 for ; Tue, 21 Feb 2023 12:03:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 226AA3854803 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-x42e.google.com with SMTP id r7so3991305wrz.6 for ; Tue, 21 Feb 2023 04:03:53 -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=8pKvx826FvWkNnIXJQaue1CkAv0xBqaasqMXDJHejzk=; b=HII4bawzDnV7OEmOFlkdHMuj6HxJIari1LG6jqaD4QySzUdTX8mWiSR8oZrihggsuz VuE8ekg3PIzQEvBBYf+1kB6aE9ROAd+h3672gI0J6/iyqKtIohnUVqbTEis4SouxqMMz fLKWqC+ZlWpw824H84oEnDaklX54zZe5RYyDthq1WwmqCtx08PM50AYP/QubR7VxJvuq rcoURIQwioKS2vgSHGU8L69dj9kTyKcKPCRsklst21uZZL03Q6kK9Gbo1IsP2i0B9TLf 7kxgoUS0pYoe26BRZX/PmXz/DEIuU1ezPNOYWTaghlqUBSVn+H5VcIHXA46Kwy1c+M7g pqGg== 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=8pKvx826FvWkNnIXJQaue1CkAv0xBqaasqMXDJHejzk=; b=3egxORd/fetLT2TFkNB2r0ABL5lhZlI92psk1W4sbm66VZinJlDGMSAhXyfkbluDwC x5JVLch7CB8+74+P5uoZDdmQa+3/KnibEcUAPw8UlvGCrDVqNpu2G05lb2i28luEGk0P MTHsI1p8jSR3EoWyZlOmm52WMuaAnyGZfH49dHFFh3qogHZ9vgrG0eUSqrkdqEkSNxM0 dY/JTesHwz5td6Qax+7Fa44vNIn0ITRH/Fqa1Uw5RZKnbZ+q4D2NC60hXgeuSbAlRpUr bU1G0fGBt6AYmAvRG08O5MGcjM/57UdqvlULVaFlTcRFLOQoOLjwMQ36zl1sG4bO9MtZ rFbg== X-Gm-Message-State: AO0yUKVo+nGp5fDhX2vPH/aB8LOQwPmF22sUZ1eZ3q0yupphSxXYJfpw mUvZdTclOcjbjb6oJJBeCSUrYhAcdGcmK0T8cg== X-Received: by 2002:a5d:5104:0:b0:2c5:5455:96a1 with SMTP id s4-20020a5d5104000000b002c5545596a1mr5070512wrt.29.1676981032518; Tue, 21 Feb 2023 04:03:52 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:52 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 037/103] gccrs: ast: Module: unloaded module and inner attributes Date: Tue, 21 Feb 2023 13:01:27 +0100 Message-Id: <20230221120230.596966-38-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?1758443207450330652?= X-GMAIL-MSGID: =?utf-8?q?1758443207450330652?= From: Jakub Dupak gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Properly handle unloaded modules. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 41 +++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 1e7a235932d..a12c3922c47 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -810,21 +810,44 @@ Dump::visit (Method &method) void Dump::visit (Module &module) { - emit_visibility (module.get_visibility ()); - stream << "mod " << module.get_name () << " {\n"; + // Syntax: + // mod IDENTIFIER ; + // | mod IDENTIFIER { + // InnerAttribute* + // Item* + // } - indentation.increment (); + emit_visibility (module.get_visibility ()); + stream << "mod " << module.get_name (); - for (auto &item : module.get_items ()) + if (module.get_kind () == Module::UNLOADED) { - stream << indentation; - item->accept_vis (*this); - stream << '\n'; + stream << ";\n"; } + else /* Module::LOADED */ + { + stream << " {\n"; - indentation.decrement (); + indentation.increment (); - stream << indentation << "}\n"; + for (auto &item : module.get_inner_attrs ()) + { + stream << indentation; + emit_attrib (item); + stream << '\n'; + } + + for (auto &item : module.get_items ()) + { + stream << indentation; + item->accept_vis (*this); + stream << '\n'; + } + + indentation.decrement (); + + stream << indentation << "}\n"; + } } void From patchwork Tue Feb 21 12:01:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59984 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1830813wrn; Tue, 21 Feb 2023 04:22:28 -0800 (PST) X-Google-Smtp-Source: AK7set+kGTZ5kouaUd/6vrQJF32hwHgmS0H04SvviYmgTh8kGQm3aRcQ97QwdBDFInb5URjstXbl X-Received: by 2002:a17:906:c04d:b0:8a4:e2aa:6cd9 with SMTP id bm13-20020a170906c04d00b008a4e2aa6cd9mr12459920ejb.19.1676982148199; Tue, 21 Feb 2023 04:22:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982148; cv=none; d=google.com; s=arc-20160816; b=OuSHJ1nQuWgB5nyV4WqbuengQbvtvFccT5x8UQ+TaM3jqF03q+KpjuFcsD4dHTmAp1 j3yiMdHtCdpbf5aa5a30zDPb7vzAtG3XZVemWj4MPlJwWdb2YOmWZse37M7AALAzBhN/ hw6BIgterp4zutf6xYNCHLni75aGKX8Drzup+0z8xnAyFP4xfud3vAGzQFZ7UcmI+IID +bzRjC1+L3+hSfyP3rMl9nSZhMYlLgQOLP4hrvzrKLNBhs53AyRFCmLkwyu8k4S9ZPaP azed4U0fOrfJfhdmo50RPFOdq+qAkJJUjw8clQ7vu2ILt9e78rjrvfzu9gCmXzMMVpcA tTcA== 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=O8zwOMN0JVeRFxhdQL7TtArc9HsLUZ8u3Trm17NZxoc=; b=xAXT5ijYkA3llx6gGWXMNO0/duCT93gATFac/xZrlYPw5FgP4rpO1WiBxNKxLIJrLk 03EV0z1klbMo9d/w6yoe1t5Es7qnus+Gmu9bl0WhKy9LKbvvLXomV1ByVTO3vfdv+1z1 /8Ka4jeRRhsrJ+FpKSs5M1gXogAC5k4/ocmG/BU6DJq3a2/w6UilV3ON0sR7x02Xr7xv ryB1JOL6vluSIDWEvIwh9az1icO9e0ar3x6CiX74Fz9iPGV3hI0RM4cq/HnI50NP/Yn/ NehApYcm7afCBZqpCXw8dV2u/bwPdP2uTSwvExgSkKPM6XbA8ZVJsifORKD/f9kP2i82 kL8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=XMZBPYwz; 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 12-20020a170906010c00b008b17662c9dasi19794349eje.713.2023.02.21.04.22.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:22:28 -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=XMZBPYwz; 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 E1B08384D562 for ; Tue, 21 Feb 2023 12:09:26 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id D1DE5384F48B for ; Tue, 21 Feb 2023 12:03:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D1DE5384F48B 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-x433.google.com with SMTP id o4so4164560wrs.4 for ; Tue, 21 Feb 2023 04:03:53 -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=O8zwOMN0JVeRFxhdQL7TtArc9HsLUZ8u3Trm17NZxoc=; b=XMZBPYwzEEt/S2PgJsdaYseFAQFM8PHXKqaHkZtMIu3lpNZXLXY8iUj4XaxPdqZXIV aEDThZtEtBFv1Y9xVgnwCA+hv0Y2XliwAME5tIwfI6COV+pHgDYVA0GP3Y6EKwDtBQpU z46wG/oI41j8ABrbFp5X5ahV3iR7c4Cx+CYNRYKS7ig5rsDV5cEe+1bqlo3bRacC+F0d F+TyALA52z5bdijpqHKjCON/U5PXIsukAgzO8EaAqqATSjx9kAdiuPXoaaDkRhKDayGw L+wDVSoUvZ5TmdRGY/H9mVnoPwilZ/X6lRQTzp2U0Nf/WzYYB2pjminK3MIBxGCYkL9b Mhqw== 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=O8zwOMN0JVeRFxhdQL7TtArc9HsLUZ8u3Trm17NZxoc=; b=RfugntYCFl5Xc60Ygm754iDYvA7IjLSbrrEppl7IUr3pDflPMMjxMZolIkHrogr7FT RAQ27vhAkcPECE+dhGMTtvwd/B8p1gzyZfLwFjDPK/S1HrBuPLEXKM8J+URQNXjTx/Mz OzDjuCX8Q/JNsd+ey0H3HbOwGg39oOfVBuzVQd5wH7u1WtDEmdmYXGHE0Yw16LUHG4TO wwU8SGLYugKZvhyozhRTp7V5JPtZIcltz0L1CBanrf+RjZgDXHeygH15lB/jlGd+IVQq 2npOa3GFaGCtLVLOVLTGX4NSztQ4L3X0+DKNY+Nwc0W7FBqpw0EATKAzrYQyShCbdACG N+DA== X-Gm-Message-State: AO0yUKU4vsxY1buuO4yJumJo3G3LQhKFUH2HJS0A4l7QXkOJARaclbiE ulk5Qoi0FUCE7AZJnXiBQhAnfAaHVjbI+cIToA== X-Received: by 2002:a5d:6686:0:b0:2c5:58fd:a965 with SMTP id l6-20020a5d6686000000b002c558fda965mr2523691wru.35.1676981033231; Tue, 21 Feb 2023 04:03:53 -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.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:52 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 038/103] gccrs: dump: Dump macro rules definition Date: Tue, 21 Feb 2023 13:01:28 +0100 Message-Id: <20230221120230.596966-39-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.4 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?1758443233292816493?= X-GMAIL-MSGID: =?utf-8?q?1758443233292816493?= From: Arthur Cohen gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add missing visitors for macro definition dumping. (get_delimiters): New function. * ast/rust-ast-dump.h: Declare `get_delimiters` and add documentation. * ast/rust-macro.h: Add `get_token_tree` method. --- gcc/rust/ast/rust-ast-dump.cc | 126 +++++++++++++++++++++++++++++++--- gcc/rust/ast/rust-ast-dump.h | 16 +++-- gcc/rust/ast/rust-macro.h | 1 + 3 files changed, 131 insertions(+), 12 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index a12c3922c47..4817962f767 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -175,11 +175,27 @@ Dump::format_struct_field (StructField &field) void Dump::visit (Token &tok) -{} +{ + stream << tok.as_string (); +} void Dump::visit (DelimTokenTree &delim_tok_tree) -{} +{ + auto tokens = delim_tok_tree.to_token_stream (); + + indentation.increment (); + stream << '\n' << indentation; + + for (const auto &tok : tokens) + { + stream << ' '; + tok->accept_vis (*this); + } + + indentation.decrement (); + stream << '\n' << indentation; +} void Dump::visit (AttrInputMetaItemContainer &input) @@ -1308,22 +1324,116 @@ Dump::visit (ExternBlock &block) stream << "\n" << indentation << "}\n"; } -// rust-macro.h +static std::pair +get_delimiters (DelimType delim) +{ + auto start_delim = '\0'; + auto end_delim = '\0'; + + switch (delim) + { + case PARENS: + start_delim = '('; + end_delim = ')'; + break; + case SQUARE: + start_delim = '['; + end_delim = ']'; + break; + case CURLY: + start_delim = '{'; + end_delim = '}'; + break; + } + + return {start_delim, end_delim}; +} + void Dump::visit (MacroMatchFragment &match) -{} +{ + stream << '$' << match.get_ident () << ':' + << match.get_frag_spec ().as_string (); +} void -Dump::visit (MacroMatchRepetition &match) -{} +Dump::visit (MacroMatchRepetition &repetition) +{ + stream << "$("; + + for (auto &match : repetition.get_matches ()) + { + match->accept_vis (*this); + stream << ' '; + } + + auto op_char = '\0'; + switch (repetition.get_op ()) + { + case MacroMatchRepetition::ANY: + op_char = '*'; + break; + case MacroMatchRepetition::ONE_OR_MORE: + op_char = '+'; + break; + case MacroMatchRepetition::ZERO_OR_ONE: + op_char = '?'; + break; + case MacroMatchRepetition::NONE: + break; + } + + stream << ')'; + + if (repetition.has_sep ()) + stream << repetition.get_sep ()->as_string (); + + stream << op_char; +} void Dump::visit (MacroMatcher &matcher) -{} +{ + auto delimiters = get_delimiters (matcher.get_delim_type ()); + + stream << delimiters.first; + + for (auto &match : matcher.get_matches ()) + { + match->accept_vis (*this); + stream << ' '; + } + + stream << delimiters.second; +} void Dump::visit (MacroRulesDefinition &rules_def) -{} +{ + for (auto &outer_attr : rules_def.get_outer_attrs ()) + emit_attrib (outer_attr); + + stream << "macro_rules! " << rules_def.get_rule_name () << " {\n"; + + indentation.increment (); + + for (auto &rule : rules_def.get_rules ()) + { + stream << indentation; + + rule.get_matcher ().accept_vis (*this); + + stream << " => "; + + rule.get_transcriber ().get_token_tree ().accept_vis (*this); + + stream << ";\n"; + } + + indentation.decrement (); + + stream << "}\n"; +} void Dump::visit (MacroInvocation ¯o_invoc) diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h index 2da2736c95b..9fe8ee95493 100644 --- a/gcc/rust/ast/rust-ast-dump.h +++ b/gcc/rust/ast/rust-ast-dump.h @@ -72,7 +72,9 @@ private: std::ostream &stream; Indent indentation; - // Format together common items of functions: Parameters, return type, block + /** + * Format together common items of functions: Parameters, return type, block + */ void format_function_common (std::unique_ptr &return_type, std::unique_ptr &block); @@ -97,13 +99,19 @@ private: std::ostream &emit_indented_string (const std::string &value, const std::string &comment = ""); - // Emit formatted string for generic parameters. + /** + * Emit formatted string for generic parameters + */ void emit_generic_params (std::vector> ¶ms); - // Format a single field of a tuple. + /** + * Format a single field of a tuple + */ void format_tuple_field (TupleField &field); - // Format a single field of a struct. + /** + * Format a single field of a struct + */ void format_struct_field (StructField &field); // rust-ast.h diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h index 4f980b0b506..798bc974fbb 100644 --- a/gcc/rust/ast/rust-macro.h +++ b/gcc/rust/ast/rust-macro.h @@ -407,6 +407,7 @@ public: Location get_locus () const { return locus; } DelimTokenTree &get_token_tree () { return token_tree; } + const DelimTokenTree &get_token_tree () const { return token_tree; } }; // A macro rule? Matcher and transcriber pair? From patchwork Tue Feb 21 12:01:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60021 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1837515wrn; Tue, 21 Feb 2023 04:38:27 -0800 (PST) X-Google-Smtp-Source: AK7set/0JHNCzxM8F5HPFHp5xrzf5e2iJhIrCyXjVFYYAay1otsVxjxWoPNLz3OYbvNjG1+9FfK9 X-Received: by 2002:a05:6402:355:b0:4ae:e547:e563 with SMTP id r21-20020a056402035500b004aee547e563mr5761209edw.36.1676983107079; Tue, 21 Feb 2023 04:38:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983107; cv=none; d=google.com; s=arc-20160816; b=Fa6xK5GjiUn3654N+OG93wOuAkTT5BQAQmaK21E1MXKL6xx0ElRX1rF/7dKOuJCC1s AHheLMU6ddNXhMglPNa6APOvIUsFwJlrAFwFcnxgUuMZcNqbISHX/tLwtVvm5GArzhkV FSiFdiU7V7eI2DOyFIKVJdr7nSPMufChkLSsnbl0Ov5EgUEcv08nR4yd2RZ7BOXDMbjW /aVcnjbTOFbu/JCehoUPsxIA6MEHUpDkw4krZuS6OvIlzndDRqt7ib8u3CTtyADmg4KG tNqZ++2O8nCexhYvq1qQUhxa/36OtL/HObIUWtmMTmJfzR09wsBR2mbnaE4424GsOoCq 9NRw== 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=88inREnYvEbMuVb0RenaQ3Q8ZlW4nBvnKzDWMJtXKHs=; b=AzAn9fIj7xO24WK7Z6TYVHEv9SBqixm1xAu0E4gaWgavG0HNabjNtN4ZVIdPPewDxl ZVaLdtr++3ouXgwqv2jM2QO1ASubf65P9XFwW2Bd2OyHaLR0BPR+xYsMmDJIKCZpCsrv WYJ2E6O05iCZIWRtzv0rqx1Un/uhrgLBJY/XOfPw5zd245j0GbftX8bm9+cd1nOiYH7o fzHs00soEu8cuYeCzHPSo/fWxppLuPJpgiaACmvdAGtZgIQ/EpgCp8pLPmMsh4s4ayt/ iZRJFY1Dw9wCgIe82ItQNQdAeMNsVp1y50Mp4XVElhumH3D7923JYn3owZ780Azo28ir K2Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b="N4jPaJ/a"; 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 f13-20020aa7d84d000000b004acc81d5053si19615154eds.616.2023.02.21.04.38.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:38:27 -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="N4jPaJ/a"; 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 4ADD938323D3 for ; Tue, 21 Feb 2023 12:13:31 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 438C6385B50C for ; Tue, 21 Feb 2023 12:03:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 438C6385B50C 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-x430.google.com with SMTP id r7so3991373wrz.6 for ; Tue, 21 Feb 2023 04:03:55 -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=88inREnYvEbMuVb0RenaQ3Q8ZlW4nBvnKzDWMJtXKHs=; b=N4jPaJ/aD4/FPoA+w0JLttZnE7Mc1iKw//BO9nAui48UlRaudm/ifGrXO44vd1YTF8 vtC4NSYYWHT4dV8zky9u6sKil1zvVKAuKQPK9jpgHa5bHJfuLNq4cdLfDjJLQ/P4wpTV RX83/oMDBgq6wpVAhmScUsi7BidsD17DZ7zJCZ/u3PrDsLGXGx30SNNGjQEQgZ2d0gkv 3F4VvprwzJmbNnvZULzdm/2xG9yB75cR9Fleu6LMx/L0BlH6mJc3nwLXYqAcM/E8hiqG r17wkTcbReVrfDUq15+yjD4FCyPnlyqekjs+bWPzRfM0qZN1MWYoQKLeccY+QE2umDh5 sIdQ== 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=88inREnYvEbMuVb0RenaQ3Q8ZlW4nBvnKzDWMJtXKHs=; b=ADeRBs5VMO5VpbcUVT4br6DpOxwXUvMOHk/eEmWCwJ4j4dkXCV5WCfiCEOdgZUo8F+ CamEKrgshtuk5jr+uSCCk0+OLNF0l5MflbJOS1ZANkgb7+C9c9RpyhKdIyrHy986QDeK NBBObbubgobdbaTc81DDniRiZ6Z3Yrm2AwRjxsXXPR2URAqCSxEahrqFK8RXj/Ja6ZyC uP+DHWKn8hm96b4XLWe+V+GdLbmBYybjYlZcW6JLk7VJzar1cBRZ4BRE2sE8zZ5UVXPY qgTFIjVFnVIzes7vsBIHUH7tJ+Vsk3M+svnxJlDSqmof4EuBq7NDeF1DOMWQGv2e3Njj kKHA== X-Gm-Message-State: AO0yUKXSucwN1kWuBWlcqdirD8c8h4eqFuK8mpL/xKh3CissTc+q9b8C px7I29S046n+BP6v2uBr87MFvAuUDTTJJ847WQ== X-Received: by 2002:a5d:5387:0:b0:2c5:455b:4cd2 with SMTP id d7-20020a5d5387000000b002c5455b4cd2mr5103370wrv.57.1676981033833; Tue, 21 Feb 2023 04:03:53 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:53 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 039/103] gccrs: Add check for recursive trait cycles Date: Tue, 21 Feb 2023 13:01:29 +0100 Message-Id: <20230221120230.596966-40-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?1758444238011994955?= X-GMAIL-MSGID: =?utf-8?q?1758444238011994955?= From: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): Check if a trait query is currently in progress. * typecheck/rust-hir-type-check.h (class TraitQueryGuard): Add helpers around checking for trait queries and inserting them. gcc/testsuite/ChangeLog: * rust/compile/issue-1589.rs: New test. --- gcc/rust/typecheck/rust-hir-trait-resolve.cc | 12 +++++++- gcc/rust/typecheck/rust-hir-type-check.h | 29 ++++++++++++++++++++ gcc/testsuite/rust/compile/issue-1589.rs | 5 ++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/rust/compile/issue-1589.rs diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc index 1b0bcaac79d..2ec9b2ef83e 100644 --- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc +++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc @@ -141,6 +141,14 @@ TraitResolver::resolve_trait (HIR::Trait *trait_reference) return tref; } + DefId trait_id = trait_reference->get_mappings ().get_defid (); + if (context->trait_query_in_progress (trait_id)) + { + rust_error_at (trait_reference->get_locus (), "trait cycle detected"); + return &TraitReference::error_node (); + } + + TraitQueryGuard guard (trait_id); TyTy::BaseType *self = nullptr; std::vector substitutions; for (auto &generic_param : trait_reference->get_generic_params ()) @@ -201,8 +209,10 @@ TraitResolver::resolve_trait (HIR::Trait *trait_reference) HIR::TraitBound *b = static_cast (bound.get ()); - // FIXME this might be recursive we need a check for that auto predicate = get_predicate_from_bound (b->get_path ()); + if (predicate.is_error ()) + return &TraitReference::error_node (); + specified_bounds.push_back (predicate); super_traits.push_back (predicate.get ()); } diff --git a/gcc/rust/typecheck/rust-hir-type-check.h b/gcc/rust/typecheck/rust-hir-type-check.h index a1dd8052246..2b47c6738b5 100644 --- a/gcc/rust/typecheck/rust-hir-type-check.h +++ b/gcc/rust/typecheck/rust-hir-type-check.h @@ -381,6 +381,19 @@ public: return querys_in_progress.find (id) != querys_in_progress.end (); } + void insert_trait_query (DefId id) { trait_queries_in_progress.insert (id); } + + void trait_query_completed (DefId id) + { + trait_queries_in_progress.erase (id); + } + + bool trait_query_in_progress (DefId id) const + { + return trait_queries_in_progress.find (id) + != trait_queries_in_progress.end (); + } + private: TypeCheckContext (); @@ -418,6 +431,7 @@ private: // query context lookups std::set querys_in_progress; + std::set trait_queries_in_progress; }; class TypeResolution @@ -426,6 +440,21 @@ public: static void Resolve (HIR::Crate &crate); }; +class TraitQueryGuard +{ +public: + TraitQueryGuard (DefId id) : id (id), ctx (*TypeCheckContext::get ()) + { + ctx.insert_trait_query (id); + } + + ~TraitQueryGuard () { ctx.trait_query_completed (id); } + +private: + DefId id; + TypeCheckContext &ctx; +}; + } // namespace Resolver } // namespace Rust diff --git a/gcc/testsuite/rust/compile/issue-1589.rs b/gcc/testsuite/rust/compile/issue-1589.rs new file mode 100644 index 00000000000..79a5866e4af --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-1589.rs @@ -0,0 +1,5 @@ +pub trait A: B {} +// { dg-error "trait cycle detected" "" { target *-*-* } .-1 } + +pub trait B: A {} +// { dg-error "trait cycle detected" "" { target *-*-* } .-1 } From patchwork Tue Feb 21 12:01:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59987 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1831485wrn; Tue, 21 Feb 2023 04:24:15 -0800 (PST) X-Google-Smtp-Source: AK7set8NUIadJMW49ZF/4X/gzP1JvHPVBmytDlEWQnxQuqxNsmwIYpTWpx3IySTK/yydcor1UEKZ X-Received: by 2002:a50:fb06:0:b0:4ac:be42:5c66 with SMTP id d6-20020a50fb06000000b004acbe425c66mr4697962edq.11.1676982255807; Tue, 21 Feb 2023 04:24:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982255; cv=none; d=google.com; s=arc-20160816; b=XsSFLagaY9laEDvhkI0exN0olDDtfBdS6ixTtCEnMwquWvtOduzTSBBagjBgK2Aqyv NqGKKwIRx6NkQsU6UHVO6IEpOFFUE5bRsW8oBeCf0gCxhz3kyIwKhaho2FvIDsoLEVFJ tmfVu1YOHEb/8A1GH2xy2ia550QtabsrWweFfa1I3Q9TmieLerXLvV6WDTJZLSkd8qoX 3ZWBJXzZNg9LiSfiznWAmc+tn1UdELc2Gimsl78i1fu2PSY5H8qwExuQTSLmQ0XVCkOU 6ADM2ftFeOF5yRVuSrVJsRRm2x0y4QJzluCA77ZF5VdAohUQjvX3mSyU9F+qNBsMdOZ8 6VJA== 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=xEzckGszM+/tMO7iCyDUccsFnmL8QHKThigENVqmI3Q=; b=PsNaHqXSabcEJs7uOPZr5xX/4MVu2Gshl8o5JxQNWeGRSAxij6XtQVM+Wk6Rdi2ekz TFhXENCMN6IHRFAtwatMWazc7vNM6cV97HfhGVQ+LMBZwA1MqcOcoUQflY477ZOuxhwI yhQ9TT3C6CLf/C7aQcsSsYL37rQqIrxq193MVvbfskLSxshYAnGNC6ho1ss0CcjJFuAp JiSKBZtW8ExAhmCTUMAG5igJr916S28dj6rQfNIqyAE77Mc5lkvHy/APdFkKqnmR84Dr LNfwmX/xaVo3XryDCVbaKQFE1CfaEZm2Gw4cSFSZQq5UH88fJ0iPKKkJ/PCc0pj78zYr TM/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=cMJmXM4G; 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 v1-20020aa7d9c1000000b004ad7ceba692si15775974eds.20.2023.02.21.04.24.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:24:15 -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=cMJmXM4G; 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 715BA395B43E for ; Tue, 21 Feb 2023 12:09:53 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id A0631385480B for ; Tue, 21 Feb 2023 12:03:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A0631385480B 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-x435.google.com with SMTP id l25so3758199wrb.3 for ; Tue, 21 Feb 2023 04:03:56 -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=xEzckGszM+/tMO7iCyDUccsFnmL8QHKThigENVqmI3Q=; b=cMJmXM4GJnVdEV1XrzEOrdBkELeJgix0v6kZ1A7acU50WdxKbWuQmPEcOABY9S8Wgj 5vS/oITFS/dZmr2t+XgqZ2CtRJhpsmorq+rbyHJv1mf3Fpi6Lob4dct75mQsiFhTZZB8 ukEkSPL6LoUy+ZbV6PNYjiys/CK8fjcffoG6Yx7HMtNBfS1NcGwlRP6F2cGoPxW9B9oM MVNL8cTLJxDNN6jP90/r0IBHNA4CmzrD8C6JXfw/NnXNtKOCOngGmcaym+uShqWTPeZl m8uBUVU27AYHuwrmu6TkcaTihFeKuQEdqRokM4nwkc0HpDdGKq87G4etKEaiBpG6Vhwd AHzg== 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=xEzckGszM+/tMO7iCyDUccsFnmL8QHKThigENVqmI3Q=; b=AK/yU1Bq8qT6cduYXWL1ugER7xkLaoxJ5sNXBbavcd80siCkZ0P5jMUBCLsocGOVcV OgxIHkRLhk9wtoeB+4mR0BjmtaVQIyvWSsACJ7HxOHfcGUhnAUSp0Z4Z2RV38BdC7i5p nOj6NCnKuwgrRxCpl/9sEyzdLsmwGr9pZ8t+dLAmfB8jMZE3JuINGhGyZvFTnnmgps1s n6tPySb7YIO1V9LY3n504T8cNQDUST0XMhMtOPLUs4wZKzoY3LqnYfsOximcUvoz1jkU Y2FW3kvo27oaNsoRxZkCZSGa3LOlCedDkXV3i2CfTrTv67AYum3J3cJbViQIyZEyVWmQ 3/MA== X-Gm-Message-State: AO0yUKX4cMbqjjWLJGJBLqRRBZQe6fSvihC8/NdFVvPv3pYeFzxHYUgW uSXYzt9BmgNkSEn+RUDl0HtAuXq2+1oxjDQhag== X-Received: by 2002:adf:f883:0:b0:2c7:3f9:7053 with SMTP id u3-20020adff883000000b002c703f97053mr2065114wrp.52.1676981034950; Tue, 21 Feb 2023 04:03:54 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:54 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 040/103] gccrs: ast: Refactor ASTFragment -> Fragment class Date: Tue, 21 Feb 2023 13:01:30 +0100 Message-Id: <20230221120230.596966-41-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, 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?1758443345986274125?= X-GMAIL-MSGID: =?utf-8?q?1758443345986274125?= From: Arthur Cohen gcc/rust/ChangeLog: * Make-lang.in: Add `rust-ast-fragment.o` object file. * ast/rust-ast-fragment.cc: New file. * ast/rust-ast-fragment.h: New file. --- gcc/rust/Make-lang.in | 1 + gcc/rust/ast/rust-ast-fragment.cc | 168 ++++++++++++++++++++++++++++++ gcc/rust/ast/rust-ast-fragment.h | 104 ++++++++++++++++++ 3 files changed, 273 insertions(+) create mode 100644 gcc/rust/ast/rust-ast-fragment.cc create mode 100644 gcc/rust/ast/rust-ast-fragment.h diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index a906516bd33..c5960530d0a 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -74,6 +74,7 @@ GRS_OBJS = \ rust/rust-cfg-parser.o \ rust/rust-parse.o \ rust/rust-ast-full-test.o \ + rust/rust-ast-fragment.o \ rust/rust-ast-dump.o \ rust/rust-hir-dump.o \ rust/rust-session-manager.o \ diff --git a/gcc/rust/ast/rust-ast-fragment.cc b/gcc/rust/ast/rust-ast-fragment.cc new file mode 100644 index 00000000000..1a2dd99835a --- /dev/null +++ b/gcc/rust/ast/rust-ast-fragment.cc @@ -0,0 +1,168 @@ +// 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-ast-fragment.h" + +namespace Rust { +namespace AST { + +Fragment::Fragment (std::vector nodes, bool fragment_is_error) + : kind (fragment_is_error ? FragmentKind::Error : FragmentKind::Complete), + nodes (std::move (nodes)) +{ + if (fragment_is_error) + rust_assert (nodes.empty ()); +} + +Fragment::Fragment (Fragment const &other) : kind (other.get_kind ()) +{ + nodes.clear (); + nodes.reserve (other.nodes.size ()); + for (auto &n : other.nodes) + { + nodes.push_back (n); + } +} + +Fragment & +Fragment::operator= (Fragment const &other) +{ + nodes.clear (); + nodes.reserve (other.nodes.size ()); + kind = other.get_kind (); + for (auto &n : other.nodes) + { + nodes.push_back (n); + } + + return *this; +} + +Fragment +Fragment::create_error () +{ + return Fragment ({}, true); +} + +std::vector & +Fragment::get_nodes () +{ + return nodes; +} + +FragmentKind +Fragment::get_kind () const +{ + return kind; +} + +bool +Fragment::is_error () const +{ + return get_kind () == FragmentKind::Error; +} + +bool +Fragment::should_expand () const +{ + return !is_error (); +} + +bool +Fragment::is_expression_fragment () const +{ + return is_single_fragment_of_kind (SingleASTNode::NodeType::EXPRESSION); +} + +bool +Fragment::is_type_fragment () const +{ + return is_single_fragment_of_kind (SingleASTNode::NodeType::TYPE); +} + +std::unique_ptr +Fragment::take_expression_fragment () +{ + assert_single_fragment (SingleASTNode::NodeType::EXPRESSION); + return nodes[0].take_expr (); +} + +std::unique_ptr +Fragment::take_type_fragment () +{ + assert_single_fragment (SingleASTNode::NodeType::TYPE); + return nodes[0].take_type (); +} + +void +Fragment::accept_vis (ASTVisitor &vis) +{ + for (auto &node : nodes) + node.accept_vis (vis); +} + +bool +Fragment::is_single_fragment () const +{ + return nodes.size () == 1; +} + +bool +Fragment::is_single_fragment_of_kind (SingleASTNode::NodeType expected) const +{ + return is_single_fragment () && nodes[0].get_kind () == expected; +} + +void +Fragment::assert_single_fragment (SingleASTNode::NodeType expected) const +{ + static const std::map str_map = { + {SingleASTNode::NodeType::IMPL, "impl"}, + {SingleASTNode::NodeType::ITEM, "item"}, + {SingleASTNode::NodeType::TYPE, "type"}, + {SingleASTNode::NodeType::EXPRESSION, "expr"}, + {SingleASTNode::NodeType::STMT, "stmt"}, + {SingleASTNode::NodeType::EXTERN, "extern"}, + {SingleASTNode::NodeType::TRAIT, "trait"}, + {SingleASTNode::NodeType::TRAIT_IMPL, "trait impl"}, + }; + + auto actual = nodes[0].get_kind (); + auto fail = false; + + if (!is_single_fragment ()) + { + rust_error_at (Location (), "fragment is not single"); + fail = true; + } + + if (actual != expected) + { + rust_error_at ( + Location (), + "invalid fragment operation: expected %qs node, got %qs node", + str_map.find (expected)->second, + str_map.find (nodes[0].get_kind ())->second); + fail = true; + } + + rust_assert (!fail); +} + +} // namespace AST +} // namespace Rust diff --git a/gcc/rust/ast/rust-ast-fragment.h b/gcc/rust/ast/rust-ast-fragment.h new file mode 100644 index 00000000000..ee6ab0d8433 --- /dev/null +++ b/gcc/rust/ast/rust-ast-fragment.h @@ -0,0 +1,104 @@ +// 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_AST_FRAGMENT_H +#define RUST_AST_FRAGMENT_H + +#include "rust-ast.h" +#include "rust-system.h" + +namespace Rust { +namespace AST { + +enum class FragmentKind +{ + /** + * If an AST Fragment still contains unexpanded tokens - this should only be + * used in the case of builtin macros which need to be expanded eagerly. + */ + Unexpanded, + /** + * A completely expanded AST Fragment. This signifies that all + * `SingleASTNode`s in the `nodes` vector are valid. + * + * Note that this doesn't imply that the expansion is "done". One of the + * expanded nodes could very well be another macro invocation + */ + Complete, + /** + * An error fragment. + */ + Error, +}; + +/** + * An AST Fragment. Previously named `ASTFragment`. + * + * Basically, a "fragment" that can be incorporated into the AST, created as + * a result of macro expansion. Really annoying to work with due to the fact + * that macros can really expand to anything. As such, horrible representation + * at the moment. + */ +class Fragment +{ +public: + Fragment (std::vector nodes, bool fragment_is_error = false); + Fragment (Fragment const &other); + static Fragment create_error (); + + Fragment &operator= (Fragment const &other); + + FragmentKind get_kind () const; + std::vector &get_nodes (); + + bool is_error () const; + bool should_expand () const; + + bool is_expression_fragment () const; + bool is_type_fragment () const; + + std::unique_ptr take_expression_fragment (); + std::unique_ptr take_type_fragment (); + + void accept_vis (ASTVisitor &vis); + +private: + FragmentKind kind; + + /** + * Basic idea: essentially, a vector of tagged unions of different AST node + * types. Now, this could actually be stored without a tagged union if the + * different AST node types had a unified parent, but that would create + * issues with the diamond problem or significant performance penalties. So + * a tagged union had to be used instead. A vector is used to represent the + * ability for a macro to expand to two statements, for instance. + */ + std::vector nodes; + + /** + * We need to make a special case for Expression and Type fragments as only + * one Node will be extracted from the `nodes` vector + */ + bool is_single_fragment () const; + bool is_single_fragment_of_kind (SingleASTNode::NodeType expected) const; + void assert_single_fragment (SingleASTNode::NodeType expected) const; +}; +} // namespace AST +} // namespace Rust + +#endif // !RUST_AST_FRAGMENT_H From patchwork Tue Feb 21 12:01:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60025 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1838383wrn; Tue, 21 Feb 2023 04:40:39 -0800 (PST) X-Google-Smtp-Source: AK7set9b2H8zt+2yX0RoWpQAKy0PGBHy0TvE+70HpOa0acQ5aWqmFYoDxwFOauumsIRIIIByU/hL X-Received: by 2002:a17:907:98bc:b0:8b1:7b10:61d5 with SMTP id ju28-20020a17090798bc00b008b17b1061d5mr15395204ejc.33.1676983239334; Tue, 21 Feb 2023 04:40:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983239; cv=none; d=google.com; s=arc-20160816; b=ED4sw59Zo3HqDZwr2IClc7ydlHUSlqrI/y+KIJIRVdzSM4ofqYY+T3jQ/HlWef2VdF Ktmtzr9GVeDuUYVjL3xLAhrtojanxGnnlT4xmiEJW1j0cSC+vYOVqqes2Q/j/q7uG9XP shJgv+fonRqh/5l6/OgR7s29z6zTz9hl85kVkMqHtXnaztjaS5xUpH50DQNFOjUUnwVE UrIeQWFQ0BxlIe/6wcjni24Vwaa6iZLoDqwmBKlNhpBKNpNHcbzuD0zjlSLhTXjNxWRK Cm34c27HOusssuJYSc4NaAc7qR+CKHegeRjoR8eXC83wA8A+aE4/rouW+7TS2oSP8H2P lwVw== 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=+QPeXja+bzOj/3nJzTHzFzkaFHCfZRSyNHb0lgsAQ0k=; b=EUBR7l/GxKECYhMNgMNdnGO5noWf8noiFhblNhVxCsfbbKGZV6dDifPAxrs+U1RiGv iy256SILlZJlSRdT1pAilsI76ORNPUT8SAC+vV12bGEGPJo4JTrCwpSwP2ITwIu7undH N73/jyewfwI6Zmhs/8yZ6OQoINriViymmiyXI21zO+KSbmXWcGp+6nriCKXYUKYP26XW XNhuboJLd9hqRIIM1rtrihK4Tmx5GJMsDjf558Q8YdJWlZwEAOESpSr0t5qxTQcNRyVL qwX0QdugZOP66ZJU4Cx0VNUI/fJJwoC0x2liGFewtF47tzpDyHpnXJfm0XvK3asPyycj ZtqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=E06iUWT5; 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 uh10-20020a170906b38a00b008b31de1854csi13498410ejc.536.2023.02.21.04.40.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:40:39 -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=E06iUWT5; 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 5ABF0389096E for ; Tue, 21 Feb 2023 12:14:03 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id CAB75383D9BE for ; Tue, 21 Feb 2023 12:03:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CAB75383D9BE 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-x436.google.com with SMTP id j2so3982535wrh.9 for ; Tue, 21 Feb 2023 04:03:57 -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=+QPeXja+bzOj/3nJzTHzFzkaFHCfZRSyNHb0lgsAQ0k=; b=E06iUWT5egYIsF5PBQsF3FUj+dlHCseLfQk3QLdX+zGOaGBYhbOj47L8wHNNvhvO9r zo740QpNogNbY+oWjLIJmOO68QyQpAosJRr+AyrC4ehwEBP3A/QfFzwZbDdrMSeyk2pR r6zHaxevhR0sQhY3q5I9+EOXpGBV4rGh4sBc86Zq+Sb7WSLb32gRRLvD084i2m051bOh lvttVPWBj1cGI8EmcMNDjgM/oyo0l+g43i1Bxo8+rthS2JZtPl/d5h1fiBIty/ZzQFOY 0jC+iTv2+a+zpQhrC8fr+NSvo3qpSsw84G+gWabFWrqj0bQm7Engpneh6OMCL7tgzqLM QhIA== 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=+QPeXja+bzOj/3nJzTHzFzkaFHCfZRSyNHb0lgsAQ0k=; b=4zX3V8EiEOWiAJrHUbSl9V9Nrpv4TqDc2GUijohbmM7jA9Fjc5Qa2xLgANnyqF4W8h WsC9VXWdEbYep91nERCK885n4KCbtj/t4VGrTkeLl2zTwtHQCrPzDcrlGNSnW2CMwCcF eaP8RXxIxvGrUxdoRMEhGnPQnGV0vlSAobyZLytecAOEIrLnNSmbvhRKpGqX4xPfphNX M+gfL4z4hYyZXdsVi20lTyEE+s8WhpKIm3vXKKQizUxB4Z0BBHNnccW/x47m+eeKy7DP jxtgXOknXun7RnJL7lNU40wHF5jYlO/kPNkWLbauD4Q9sP1zjr7Q1+QjmtKE72XtdV69 zZeg== X-Gm-Message-State: AO0yUKV3OAZh8ttCFxQzl7ck1FglxxlJkxD5aC2MO/N1czUT6J8Zyreb Ekhw7XA4PpRql7Zy0y3py76T2mfviKZjE4MFSQ== X-Received: by 2002:a5d:62ce:0:b0:2c6:d913:58a9 with SMTP id o14-20020a5d62ce000000b002c6d91358a9mr3471152wrv.39.1676981036245; Tue, 21 Feb 2023 04:03:56 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:55 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 041/103] gccrs: rust: Replace uses of ASTFragment -> Fragment Date: Tue, 21 Feb 2023 13:01:31 +0100 Message-Id: <20230221120230.596966-42-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=ham 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?1758444377124639823?= X-GMAIL-MSGID: =?utf-8?q?1758444377124639823?= From: Arthur Cohen gcc/rust/ChangeLog: * ast/rust-ast.h (class ASTFragment): Remove old ASTFragment class. * ast/rust-macro.h (class MacroRulesDefinition): Use new Fragment API. * expand/rust-attribute-visitor.h: Likewise. * expand/rust-macro-builtins.cc (macro_end_token): Likewise. (MacroBuiltin::assert): Likewise. (MacroBuiltin::file): Likewise. (MacroBuiltin::column): Likewise. (MacroBuiltin::include_bytes): Likewise. (MacroBuiltin::include_str): Likewise. (MacroBuiltin::compile_error): Likewise. (MacroBuiltin::concat): Likewise. (MacroBuiltin::env): Likewise. (MacroBuiltin::cfg): Likewise. (MacroBuiltin::include): Likewise. (MacroBuiltin::line): Likewise. * expand/rust-macro-builtins.h: Likewise. * expand/rust-macro-expand.cc (MacroExpander::expand_decl_macro): Likewise. (MacroExpander::expand_invoc): Likewise. (MacroExpander::match_repetition): Likewise. (parse_many): Likewise. (transcribe_many_items): Likewise. (transcribe_many_ext): Likewise. (transcribe_many_trait_items): Likewise. (transcribe_many_impl_items): Likewise. (transcribe_many_trait_impl_items): Likewise. (transcribe_expression): Likewise. (transcribe_type): Likewise. (transcribe_on_delimiter): Likewise. (tokens_to_str): Likewise. * expand/rust-macro-expand.h (struct MacroExpander): Likewise. * util/rust-hir-map.cc (Mappings::insert_macro_def): Likewise. --- gcc/rust/ast/rust-ast.h | 132 ----------------------- gcc/rust/ast/rust-macro.h | 18 ++-- gcc/rust/expand/rust-attribute-visitor.h | 4 +- gcc/rust/expand/rust-macro-builtins.cc | 72 ++++++------- gcc/rust/expand/rust-macro-builtins.h | 40 ++++--- gcc/rust/expand/rust-macro-expand.cc | 42 ++++---- gcc/rust/expand/rust-macro-expand.h | 23 ++-- gcc/rust/util/rust-hir-map.cc | 4 +- 8 files changed, 100 insertions(+), 235 deletions(-) diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index ccabccd6aff..3d602b1a379 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -1858,138 +1858,6 @@ public: } }; -/* Basically, a "fragment" that can be incorporated into the AST, created as - * a result of macro expansion. Really annoying to work with due to the fact - * that macros can really expand to anything. As such, horrible representation - * at the moment. */ -class ASTFragment -{ -private: - /* basic idea: essentially, a vector of tagged unions of different AST node - * types. Now, this could actually be stored without a tagged union if the - * different AST node types had a unified parent, but that would create - * issues with the diamond problem or significant performance penalties. So - * a tagged union had to be used instead. A vector is used to represent the - * ability for a macro to expand to two statements, for instance. */ - - std::vector nodes; - bool fragment_is_error; - - /** - * We need to make a special case for Expression and Type fragments as only - * one Node will be extracted from the `nodes` vector - */ - - bool is_single_fragment () const { return nodes.size () == 1; } - - bool is_single_fragment_of_kind (SingleASTNode::NodeType expected) const - { - return is_single_fragment () && nodes[0].get_kind () == expected; - } - - void assert_single_fragment (SingleASTNode::NodeType expected) const - { - static const std::map str_map = { - {SingleASTNode::NodeType::IMPL, "impl"}, - {SingleASTNode::NodeType::ITEM, "item"}, - {SingleASTNode::NodeType::TYPE, "type"}, - {SingleASTNode::NodeType::EXPRESSION, "expr"}, - {SingleASTNode::NodeType::STMT, "stmt"}, - {SingleASTNode::NodeType::EXTERN, "extern"}, - {SingleASTNode::NodeType::TRAIT, "trait"}, - {SingleASTNode::NodeType::TRAIT_IMPL, "trait impl"}, - }; - - auto actual = nodes[0].get_kind (); - auto fail = false; - - if (!is_single_fragment ()) - { - rust_error_at (Location (), "fragment is not single"); - fail = true; - } - - if (actual != expected) - { - rust_error_at ( - Location (), - "invalid fragment operation: expected %qs node, got %qs node", - str_map.find (expected)->second, - str_map.find (nodes[0].get_kind ())->second); - fail = true; - } - - rust_assert (!fail); - } - -public: - ASTFragment (std::vector nodes, bool fragment_is_error = false) - : nodes (std::move (nodes)), fragment_is_error (fragment_is_error) - { - if (fragment_is_error) - rust_assert (nodes.empty ()); - } - - ASTFragment (ASTFragment const &other) - : fragment_is_error (other.fragment_is_error) - { - nodes.clear (); - nodes.reserve (other.nodes.size ()); - for (auto &n : other.nodes) - { - nodes.push_back (n); - } - } - - ASTFragment &operator= (ASTFragment const &other) - { - fragment_is_error = other.fragment_is_error; - nodes.clear (); - nodes.reserve (other.nodes.size ()); - for (auto &n : other.nodes) - { - nodes.push_back (n); - } - - return *this; - } - - static ASTFragment create_error () { return ASTFragment ({}, true); } - - std::vector &get_nodes () { return nodes; } - bool is_error () const { return fragment_is_error; } - - bool should_expand () const { return !is_error (); } - - bool is_expression_fragment () const - { - return is_single_fragment_of_kind (SingleASTNode::NodeType::EXPRESSION); - } - - bool is_type_fragment () const - { - return is_single_fragment_of_kind (SingleASTNode::NodeType::TYPE); - } - - std::unique_ptr take_expression_fragment () - { - assert_single_fragment (SingleASTNode::NodeType::EXPRESSION); - return nodes[0].take_expr (); - } - - std::unique_ptr take_type_fragment () - { - assert_single_fragment (SingleASTNode::NodeType::TYPE); - return nodes[0].take_type (); - } - - void accept_vis (ASTVisitor &vis) - { - for (auto &node : nodes) - node.accept_vis (vis); - } -}; - // A crate AST object - holds all the data for a single compilation unit struct Crate { diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h index 798bc974fbb..fc4b5b82fb5 100644 --- a/gcc/rust/ast/rust-macro.h +++ b/gcc/rust/ast/rust-macro.h @@ -21,6 +21,7 @@ #include "rust-system.h" #include "rust-ast.h" +#include "rust-ast-fragment.h" #include "rust-location.h" namespace Rust { @@ -456,8 +457,7 @@ class MacroRulesDefinition : public MacroItem std::vector rules; // inlined form Location locus; - std::function - associated_transcriber; + std::function associated_transcriber; // Since we can't compare std::functions, we need to use an extra boolean bool is_builtin_rule; @@ -468,10 +468,10 @@ class MacroRulesDefinition : public MacroItem * should make use of the actual rules. If the macro is builtin, then another * associated transcriber should be used */ - static ASTFragment dummy_builtin (Location, MacroInvocData &) + static Fragment dummy_builtin (Location, MacroInvocData &) { gcc_unreachable (); - return ASTFragment::create_error (); + return Fragment::create_error (); } /* NOTE: in rustc, macro definitions are considered (and parsed as) a type @@ -491,9 +491,9 @@ public: associated_transcriber (dummy_builtin), is_builtin_rule (false) {} - MacroRulesDefinition (Identifier builtin_name, DelimType delim_type, - std::function - associated_transcriber) + MacroRulesDefinition ( + Identifier builtin_name, DelimType delim_type, + std::function associated_transcriber) : outer_attrs (std::vector ()), rule_name (builtin_name), delim_type (delim_type), rules (std::vector ()), locus (Location ()), associated_transcriber (associated_transcriber), @@ -521,14 +521,14 @@ public: const std::vector &get_rules () const { return rules; } bool is_builtin () const { return is_builtin_rule; } - const std::function & + const std::function & get_builtin_transcriber () const { rust_assert (is_builtin ()); return associated_transcriber; } void set_builtin_transcriber ( - std::function transcriber) + std::function transcriber) { associated_transcriber = transcriber; is_builtin_rule = true; diff --git a/gcc/rust/expand/rust-attribute-visitor.h b/gcc/rust/expand/rust-attribute-visitor.h index 80f9d4b4ded..6b562bd49b1 100644 --- a/gcc/rust/expand/rust-attribute-visitor.h +++ b/gcc/rust/expand/rust-attribute-visitor.h @@ -56,11 +56,11 @@ public: * @return Either the expanded fragment or an empty errored-out fragment * indicating an expansion failure. */ - AST::ASTFragment expand_macro_fragment_recursive () + AST::Fragment expand_macro_fragment_recursive () { auto fragment = expander.take_expanded_fragment (*this); unsigned int original_depth = expander.expansion_depth; - auto final_fragment = AST::ASTFragment ({}, true); + auto final_fragment = AST::Fragment ({}, true); while (fragment.should_expand ()) { diff --git a/gcc/rust/expand/rust-macro-builtins.cc b/gcc/rust/expand/rust-macro-builtins.cc index a230ad9f2d8..2a8a3f752f4 100644 --- a/gcc/rust/expand/rust-macro-builtins.cc +++ b/gcc/rust/expand/rust-macro-builtins.cc @@ -66,7 +66,7 @@ macro_end_token (AST::DelimTokenTree &invoc_token_tree, /* Expand and extract an expression from the macro */ -static inline AST::ASTFragment +static inline AST::Fragment try_expand_macro_expression (AST::Expr *expr, MacroExpander *expander) { rust_assert (expander); @@ -264,25 +264,25 @@ load_file_bytes (const char *filename) } } // namespace -AST::ASTFragment +AST::Fragment MacroBuiltin::assert (Location invoc_locus, AST::MacroInvocData &invoc) { rust_debug ("assert!() called"); - return AST::ASTFragment::create_error (); + return AST::Fragment::create_error (); } -AST::ASTFragment +AST::Fragment MacroBuiltin::file (Location invoc_locus, AST::MacroInvocData &invoc) { auto current_file = Session::get_instance ().linemap->location_file (invoc_locus); auto file_str = AST::SingleASTNode (make_string (invoc_locus, current_file)); - return AST::ASTFragment ({file_str}); + return AST::Fragment ({file_str}); } -AST::ASTFragment +AST::Fragment MacroBuiltin::column (Location invoc_locus, AST::MacroInvocData &invoc) { auto current_column @@ -292,14 +292,14 @@ MacroBuiltin::column (Location invoc_locus, AST::MacroInvocData &invoc) new AST::LiteralExpr (std::to_string (current_column), AST::Literal::INT, PrimitiveCoreType::CORETYPE_U32, {}, invoc_locus))); - return AST::ASTFragment ({column_no}); + return AST::Fragment ({column_no}); } /* Expand builtin macro include_bytes!("filename"), which includes the contents of the given file as reference to a byte array. Yields an expression of type &'static [u8; N]. */ -AST::ASTFragment +AST::Fragment MacroBuiltin::include_bytes (Location invoc_locus, AST::MacroInvocData &invoc) { /* Get target filename from the macro invocation, which is treated as a path @@ -308,7 +308,7 @@ MacroBuiltin::include_bytes (Location invoc_locus, AST::MacroInvocData &invoc) = parse_single_string_literal (invoc.get_delim_tok_tree (), invoc_locus, invoc.get_expander ()); if (lit_expr == nullptr) - return AST::ASTFragment::create_error (); + return AST::Fragment::create_error (); std::string target_filename = source_relative_path (lit_expr->as_string (), invoc_locus); @@ -335,14 +335,14 @@ MacroBuiltin::include_bytes (Location invoc_locus, AST::MacroInvocData &invoc) new AST::BorrowExpr (std::move (array), false, false, {}, invoc_locus)); auto node = AST::SingleASTNode (std::move (borrow)); - return AST::ASTFragment ({node}); + return AST::Fragment ({node}); } /* Expand builtin macro include_str!("filename"), which includes the contents of the given file as a string. The file must be UTF-8 encoded. Yields an expression of type &'static str. */ -AST::ASTFragment +AST::Fragment MacroBuiltin::include_str (Location invoc_locus, AST::MacroInvocData &invoc) { /* Get target filename from the macro invocation, which is treated as a path @@ -351,7 +351,7 @@ MacroBuiltin::include_str (Location invoc_locus, AST::MacroInvocData &invoc) = parse_single_string_literal (invoc.get_delim_tok_tree (), invoc_locus, invoc.get_expander ()); if (lit_expr == nullptr) - return AST::ASTFragment::create_error (); + return AST::Fragment::create_error (); std::string target_filename = source_relative_path (lit_expr->as_string (), invoc_locus); @@ -362,30 +362,30 @@ MacroBuiltin::include_str (Location invoc_locus, AST::MacroInvocData &invoc) std::string str ((const char *) &bytes[0], bytes.size ()); auto node = AST::SingleASTNode (make_string (invoc_locus, str)); - return AST::ASTFragment ({node}); + return AST::Fragment ({node}); } /* Expand builtin macro compile_error!("error"), which forces a compile error during the compile time. */ -AST::ASTFragment +AST::Fragment MacroBuiltin::compile_error (Location invoc_locus, AST::MacroInvocData &invoc) { auto lit_expr = parse_single_string_literal (invoc.get_delim_tok_tree (), invoc_locus, invoc.get_expander ()); if (lit_expr == nullptr) - return AST::ASTFragment::create_error (); + return AST::Fragment::create_error (); std::string error_string = lit_expr->as_string (); rust_error_at (invoc_locus, "%s", error_string.c_str ()); - return AST::ASTFragment::create_error (); + return AST::Fragment::create_error (); } /* Expand builtin macro concat!(), which joins all the literal parameters into a string with no delimiter. */ -AST::ASTFragment +AST::Fragment MacroBuiltin::concat (Location invoc_locus, AST::MacroInvocData &invoc) { auto invoc_token_tree = invoc.get_delim_tok_tree (); @@ -427,16 +427,16 @@ MacroBuiltin::concat (Location invoc_locus, AST::MacroInvocData &invoc) parser.skip_token (last_token_id); if (has_error) - return AST::ASTFragment::create_error (); + return AST::Fragment::create_error (); auto node = AST::SingleASTNode (make_string (invoc_locus, str)); - return AST::ASTFragment ({node}); + return AST::Fragment ({node}); } /* Expand builtin macro env!(), which inspects an environment variable at compile time. */ -AST::ASTFragment +AST::Fragment MacroBuiltin::env (Location invoc_locus, AST::MacroInvocData &invoc) { auto invoc_token_tree = invoc.get_delim_tok_tree (); @@ -451,11 +451,11 @@ MacroBuiltin::env (Location invoc_locus, AST::MacroInvocData &invoc) auto expanded_expr = try_expand_many_expr (parser, invoc_locus, last_token_id, invoc.get_expander (), has_error); if (has_error) - return AST::ASTFragment::create_error (); + return AST::Fragment::create_error (); if (expanded_expr.size () < 1 || expanded_expr.size () > 2) { rust_error_at (invoc_locus, "env! takes 1 or 2 arguments"); - return AST::ASTFragment::create_error (); + return AST::Fragment::create_error (); } if (expanded_expr.size () > 0) { @@ -463,7 +463,7 @@ MacroBuiltin::env (Location invoc_locus, AST::MacroInvocData &invoc) = try_extract_string_literal_from_fragment (invoc_locus, expanded_expr[0]))) { - return AST::ASTFragment::create_error (); + return AST::Fragment::create_error (); } } if (expanded_expr.size () > 1) @@ -472,7 +472,7 @@ MacroBuiltin::env (Location invoc_locus, AST::MacroInvocData &invoc) = try_extract_string_literal_from_fragment (invoc_locus, expanded_expr[1]))) { - return AST::ASTFragment::create_error (); + return AST::Fragment::create_error (); } } @@ -487,14 +487,14 @@ MacroBuiltin::env (Location invoc_locus, AST::MacroInvocData &invoc) lit_expr->as_string ().c_str ()); else rust_error_at (invoc_locus, "%s", error_expr->as_string ().c_str ()); - return AST::ASTFragment::create_error (); + return AST::Fragment::create_error (); } auto node = AST::SingleASTNode (make_string (invoc_locus, env_value)); - return AST::ASTFragment ({node}); + return AST::Fragment ({node}); } -AST::ASTFragment +AST::Fragment MacroBuiltin::cfg (Location invoc_locus, AST::MacroInvocData &invoc) { // only parse if not already parsed @@ -519,7 +519,7 @@ MacroBuiltin::cfg (Location invoc_locus, AST::MacroInvocData &invoc) /* TODO: assuming that cfg! macros can only have one meta item inner, like cfg * attributes */ if (invoc.get_meta_items ().size () != 1) - return AST::ASTFragment::create_error (); + return AST::Fragment::create_error (); bool result = invoc.get_meta_items ()[0]->check_cfg_predicate ( Session::get_instance ()); @@ -527,13 +527,13 @@ MacroBuiltin::cfg (Location invoc_locus, AST::MacroInvocData &invoc) new AST::LiteralExpr (result ? "true" : "false", AST::Literal::BOOL, PrimitiveCoreType::CORETYPE_BOOL, {}, invoc_locus))); - return AST::ASTFragment ({literal_exp}); + return AST::Fragment ({literal_exp}); } /* Expand builtin macro include!(), which includes a source file at the current scope compile time. */ -AST::ASTFragment +AST::Fragment MacroBuiltin::include (Location invoc_locus, AST::MacroInvocData &invoc) { /* Get target filename from the macro invocation, which is treated as a path @@ -542,7 +542,7 @@ MacroBuiltin::include (Location invoc_locus, AST::MacroInvocData &invoc) = parse_single_string_literal (invoc.get_delim_tok_tree (), invoc_locus, invoc.get_expander ()); if (lit_expr == nullptr) - return AST::ASTFragment::create_error (); + return AST::Fragment::create_error (); std::string filename = source_relative_path (lit_expr->as_string (), invoc_locus); @@ -556,7 +556,7 @@ MacroBuiltin::include (Location invoc_locus, AST::MacroInvocData &invoc) { rust_error_at (lit_expr->get_locus (), "cannot open included file %qs: %m", target_filename); - return AST::ASTFragment::create_error (); + return AST::Fragment::create_error (); } rust_debug ("Attempting to parse included file %s", target_filename); @@ -574,7 +574,7 @@ MacroBuiltin::include (Location invoc_locus, AST::MacroInvocData &invoc) { // inform the user that the errors above are from a included file rust_inform (invoc_locus, "included from here"); - return AST::ASTFragment::create_error (); + return AST::Fragment::create_error (); } std::vector nodes{}; @@ -584,10 +584,10 @@ MacroBuiltin::include (Location invoc_locus, AST::MacroInvocData &invoc) nodes.push_back (node); } - return AST::ASTFragment (nodes); + return AST::Fragment (nodes); } -AST::ASTFragment +AST::Fragment MacroBuiltin::line (Location invoc_locus, AST::MacroInvocData &invoc) { auto current_line @@ -597,7 +597,7 @@ MacroBuiltin::line (Location invoc_locus, AST::MacroInvocData &invoc) new AST::LiteralExpr (std::to_string (current_line), AST::Literal::INT, PrimitiveCoreType::CORETYPE_U32, {}, invoc_locus))); - return AST::ASTFragment ({line_no}); + return AST::Fragment ({line_no}); } } // namespace Rust diff --git a/gcc/rust/expand/rust-macro-builtins.h b/gcc/rust/expand/rust-macro-builtins.h index f1ea545ed21..c65bd940189 100644 --- a/gcc/rust/expand/rust-macro-builtins.h +++ b/gcc/rust/expand/rust-macro-builtins.h @@ -20,6 +20,7 @@ #define RUST_MACRO_BUILTINS_H #include "rust-ast.h" +#include "rust-ast-fragment.h" #include "rust-location.h" /** @@ -61,6 +62,7 @@ /* If assert is defined as a macro this file will not parse, so undefine this before continuing. */ +// TODO: Rename all functions here `*_handler` #ifdef assert #undef assert #endif @@ -69,38 +71,34 @@ namespace Rust { class MacroBuiltin { public: - static AST::ASTFragment assert (Location invoc_locus, - AST::MacroInvocData &invoc); - - static AST::ASTFragment file (Location invoc_locus, - AST::MacroInvocData &invoc); + static AST::Fragment assert (Location invoc_locus, + AST::MacroInvocData &invoc); - static AST::ASTFragment column (Location invoc_locus, - AST::MacroInvocData &invoc); + static AST::Fragment file (Location invoc_locus, AST::MacroInvocData &invoc); - static AST::ASTFragment include_bytes (Location invoc_locus, - AST::MacroInvocData &invoc); + static AST::Fragment column (Location invoc_locus, + AST::MacroInvocData &invoc); - static AST::ASTFragment include_str (Location invoc_locus, - AST::MacroInvocData &invoc); + static AST::Fragment include_bytes (Location invoc_locus, + AST::MacroInvocData &invoc); - static AST::ASTFragment compile_error (Location invoc_locus, - AST::MacroInvocData &invoc); + static AST::Fragment include_str (Location invoc_locus, + AST::MacroInvocData &invoc); - static AST::ASTFragment concat (Location invoc_locus, - AST::MacroInvocData &invoc); + static AST::Fragment compile_error (Location invoc_locus, + AST::MacroInvocData &invoc); - static AST::ASTFragment env (Location invoc_locus, + static AST::Fragment concat (Location invoc_locus, AST::MacroInvocData &invoc); - static AST::ASTFragment cfg (Location invoc_locus, - AST::MacroInvocData &invoc); + static AST::Fragment env (Location invoc_locus, AST::MacroInvocData &invoc); - static AST::ASTFragment include (Location invoc_locus, - AST::MacroInvocData &invoc); + static AST::Fragment cfg (Location invoc_locus, AST::MacroInvocData &invoc); - static AST::ASTFragment line (Location invoc_locus, + static AST::Fragment include (Location invoc_locus, AST::MacroInvocData &invoc); + + static AST::Fragment line (Location invoc_locus, AST::MacroInvocData &invoc); }; } // namespace Rust diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc index d94cd118700..0684a28787f 100644 --- a/gcc/rust/expand/rust-macro-expand.cc +++ b/gcc/rust/expand/rust-macro-expand.cc @@ -26,7 +26,7 @@ #include "rust-early-name-resolver.h" namespace Rust { -AST::ASTFragment +AST::Fragment MacroExpander::expand_decl_macro (Location invoc_locus, AST::MacroInvocData &invoc, AST::MacroRulesDefinition &rules_def, @@ -103,7 +103,7 @@ MacroExpander::expand_decl_macro (Location invoc_locus, RichLocation r (invoc_locus); r.add_range (rules_def.get_locus ()); rust_error_at (r, "Failed to match any rule within macro"); - return AST::ASTFragment::create_error (); + return AST::Fragment::create_error (); } return transcribe_rule (*matched_rule, invoc_token_tree, matched_fragments, @@ -139,7 +139,7 @@ MacroExpander::expand_invoc (AST::MacroInvocation &invoc, bool has_semicolon) // - else is unreachable // - derive container macro - unreachable - auto fragment = AST::ASTFragment::create_error (); + auto fragment = AST::Fragment::create_error (); invoc_data.set_expander (this); // lookup the rules @@ -707,7 +707,7 @@ MacroExpander::match_repetition (Parser &parser, /** * Helper function to refactor calling a parsing function 0 or more times */ -static AST::ASTFragment +static AST::Fragment parse_many (Parser &parser, TokenId &delimiter, std::function parse_fn) { @@ -723,13 +723,13 @@ parse_many (Parser &parser, TokenId &delimiter, for (auto err : parser.get_errors ()) err.emit_error (); - return AST::ASTFragment::create_error (); + return AST::Fragment::create_error (); } nodes.emplace_back (std::move (node)); } - return AST::ASTFragment (std::move (nodes)); + return AST::Fragment (std::move (nodes)); } /** @@ -738,7 +738,7 @@ parse_many (Parser &parser, TokenId &delimiter, * @param parser Parser to extract items from * @param delimiter Id of the token on which parsing should stop */ -static AST::ASTFragment +static AST::Fragment transcribe_many_items (Parser &parser, TokenId &delimiter) { return parse_many (parser, delimiter, [&parser] () { @@ -753,7 +753,7 @@ transcribe_many_items (Parser &parser, TokenId &delimiter) * @param parser Parser to extract items from * @param delimiter Id of the token on which parsing should stop */ -static AST::ASTFragment +static AST::Fragment transcribe_many_ext (Parser &parser, TokenId &delimiter) { return parse_many (parser, delimiter, [&parser] () { @@ -768,7 +768,7 @@ transcribe_many_ext (Parser &parser, TokenId &delimiter) * @param parser Parser to extract items from * @param delimiter Id of the token on which parsing should stop */ -static AST::ASTFragment +static AST::Fragment transcribe_many_trait_items (Parser &parser, TokenId &delimiter) { @@ -784,7 +784,7 @@ transcribe_many_trait_items (Parser &parser, * @param parser Parser to extract items from * @param delimiter Id of the token on which parsing should stop */ -static AST::ASTFragment +static AST::Fragment transcribe_many_impl_items (Parser &parser, TokenId &delimiter) { return parse_many (parser, delimiter, [&parser] () { @@ -799,7 +799,7 @@ transcribe_many_impl_items (Parser &parser, TokenId &delimiter) * @param parser Parser to extract items from * @param delimiter Id of the token on which parsing should stop */ -static AST::ASTFragment +static AST::Fragment transcribe_many_trait_impl_items (Parser &parser, TokenId &delimiter) { @@ -815,7 +815,7 @@ transcribe_many_trait_impl_items (Parser &parser, * @param parser Parser to extract statements from * @param delimiter Id of the token on which parsing should stop */ -static AST::ASTFragment +static AST::Fragment transcribe_many_stmts (Parser &parser, TokenId &delimiter) { auto restrictions = ParseRestrictions (); @@ -835,12 +835,12 @@ transcribe_many_stmts (Parser &parser, TokenId &delimiter) * * @param parser Parser to extract statements from */ -static AST::ASTFragment +static AST::Fragment transcribe_expression (Parser &parser) { auto expr = parser.parse_expr (); - return AST::ASTFragment ({std::move (expr)}); + return AST::Fragment ({std::move (expr)}); } /** @@ -848,17 +848,17 @@ transcribe_expression (Parser &parser) * * @param parser Parser to extract statements from */ -static AST::ASTFragment +static AST::Fragment transcribe_type (Parser &parser) { auto type = parser.parse_type (true); for (auto err : parser.get_errors ()) err.emit_error (); - return AST::ASTFragment ({std::move (type)}); + return AST::Fragment ({std::move (type)}); } -static AST::ASTFragment +static AST::Fragment transcribe_on_delimiter (Parser &parser, bool semicolon, AST::DelimType delimiter, TokenId last_token_id) { @@ -868,7 +868,7 @@ transcribe_on_delimiter (Parser &parser, bool semicolon, return transcribe_expression (parser); } // namespace Rust -static AST::ASTFragment +static AST::Fragment transcribe_context (MacroExpander::ContextType ctx, Parser &parser, bool semicolon, AST::DelimType delimiter, TokenId last_token_id) @@ -929,7 +929,7 @@ tokens_to_str (std::vector> &tokens) return str; } -AST::ASTFragment +AST::Fragment MacroExpander::transcribe_rule ( AST::MacroRule &match_rule, AST::DelimTokenTree &invoc_token_tree, std::map &matched_fragments, @@ -951,7 +951,7 @@ MacroExpander::transcribe_rule ( rust_debug ("substituted tokens: %s", tokens_to_str (substituted_tokens).c_str ()); - // parse it to an ASTFragment + // parse it to an Fragment MacroInvocLexer lex (std::move (substituted_tokens)); Parser parser (lex); @@ -994,7 +994,7 @@ MacroExpander::transcribe_rule ( { for (auto &err : parser.get_errors ()) rust_error_at (err.locus, "%s", err.message.c_str ()); - return AST::ASTFragment::create_error (); + return AST::Fragment::create_error (); } // are all the tokens used? diff --git a/gcc/rust/expand/rust-macro-expand.h b/gcc/rust/expand/rust-macro-expand.h index 187d79f9a28..b0c0c23a0c3 100644 --- a/gcc/rust/expand/rust-macro-expand.h +++ b/gcc/rust/expand/rust-macro-expand.h @@ -230,7 +230,7 @@ struct MacroExpander MacroExpander (AST::Crate &crate, ExpansionCfg cfg, Session &session) : cfg (cfg), crate (crate), session (session), sub_stack (SubstitutionScope ()), - expanded_fragment (AST::ASTFragment::create_error ()), + expanded_fragment (AST::Fragment::create_error ()), resolver (Resolver::Resolver::get ()), mappings (Analysis::Mappings::get ()) {} @@ -246,10 +246,9 @@ struct MacroExpander void expand_invoc (AST::MacroInvocation &invoc, bool has_semicolon); // Expands a single declarative macro. - AST::ASTFragment expand_decl_macro (Location locus, - AST::MacroInvocData &invoc, - AST::MacroRulesDefinition &rules_def, - bool semicolon); + AST::Fragment expand_decl_macro (Location locus, AST::MacroInvocData &invoc, + AST::MacroRulesDefinition &rules_def, + bool semicolon); void expand_cfg_attrs (AST::AttrVec &attrs); bool fails_cfg (const AST::AttrVec &attr) const; @@ -260,7 +259,7 @@ struct MacroExpander bool try_match_rule (AST::MacroRule &match_rule, AST::DelimTokenTree &invoc_token_tree); - AST::ASTFragment transcribe_rule ( + AST::Fragment transcribe_rule ( AST::MacroRule &match_rule, AST::DelimTokenTree &invoc_token_tree, std::map &matched_fragments, bool semicolon, ContextType ctx); @@ -314,16 +313,16 @@ struct MacroExpander ContextType peek_context () { return context.back (); } - void set_expanded_fragment (AST::ASTFragment &&fragment) + void set_expanded_fragment (AST::Fragment &&fragment) { expanded_fragment = std::move (fragment); } - AST::ASTFragment take_expanded_fragment (AST::ASTVisitor &vis) + AST::Fragment take_expanded_fragment (AST::ASTVisitor &vis) { - AST::ASTFragment old_fragment = std::move (expanded_fragment); + AST::Fragment old_fragment = std::move (expanded_fragment); auto accumulator = std::vector (); - expanded_fragment = AST::ASTFragment::create_error (); + expanded_fragment = AST::Fragment::create_error (); auto early_name_resolver = Resolver::EarlyNameResolver (); for (auto &node : old_fragment.get_nodes ()) @@ -345,7 +344,7 @@ struct MacroExpander auto new_nodes = expanded_fragment.get_nodes (); std::move (new_nodes.begin (), new_nodes.end (), std::back_inserter (accumulator)); - expanded_fragment = AST::ASTFragment (accumulator); + expanded_fragment = AST::Fragment (accumulator); } expansion_depth--; } @@ -358,7 +357,7 @@ private: Session &session; SubstitutionScope sub_stack; std::vector context; - AST::ASTFragment expanded_fragment; + AST::Fragment expanded_fragment; public: Resolver::Resolver *resolver; diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index 4aeb7f5ae18..bee0682e9b4 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -840,8 +840,8 @@ Mappings::iterate_trait_items ( void Mappings::insert_macro_def (AST::MacroRulesDefinition *macro) { - static std::map> + static std::map< + std::string, std::function> builtin_macros = { {"assert", MacroBuiltin::assert}, {"file", MacroBuiltin::file}, From patchwork Tue Feb 21 12:01:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59992 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1832320wrn; Tue, 21 Feb 2023 04:26:27 -0800 (PST) X-Google-Smtp-Source: AK7set/3d0OhW5W1L6XLUYL2296EuQ5ZOXz1RhLL7e1WMvLG0gtL7UG48hWW7TRNcIYX/eRX+uHu X-Received: by 2002:a17:906:bfc5:b0:879:bff:55c with SMTP id us5-20020a170906bfc500b008790bff055cmr14080542ejb.1.1676982387850; Tue, 21 Feb 2023 04:26:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982387; cv=none; d=google.com; s=arc-20160816; b=CiGW7xcSRvC9EhzW6cSfEz7Nn27wvx6ABZQOTIFWBKXbEaagUsxtdm9E6dZvo38LtO nbpOeO77eek1JcNUF/Ejng85b4+THWq3WCZzwiBxCn80hfFR65VYTEjmGsDG3QYQhr/Z 16odhzkgnFIPGqmd0STum7+UbffILjuVZaLLVyCjgctZTLlVlZkVyEVin5AG6Z3CobcF WKtWnDnaDY1hUnbmhq/vwCijaeQNfwyYxFgYExRJGbfbWC3VTH5F7XxlCudARAXbN6pv ctOW8ZdwW2xRlCrpV4oTpJLhai3riuVi2B3UW69FYc3DRCtwa/JgwqEcu0ZiqtZ94+hb eN0g== 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=PReMTRp2tbf6gGkZGNgpfxe+TfV6I29DrgLnP3Mm9Po=; b=DZSpfxxUqhmfrLE0VikR/450YetZ13YVTotHEvPP1OC2vomEt0q1jDpmNyrK7rmreA VcdePT8QiKNx57VkQqloLevXN0m2FeebiLwQ7eEEiyYVkXjjBoEa/wdyvyOEpEN48eIO w5OeokFAqkmLGTRhsAajNfjm1sbmcyQ1c9MbRcxhYfGHKNQSJsNL3zryX4PIzXXW4NRs CMoSJztL+RBs0w9BmgVVwtY0Wxo+wBXLk+0Ke1HoeWcMcU0FhfmJsbM1Ngodn8Ztx2ey W1BlR4ffLAgEYscbc1j1TCL4QDMXumhdrIOIUwJwQv2ojXIGchPbXijCoGjHsXt4hf/v L3nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=bn03QUuz; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d19-20020aa7d693000000b004ad05b994c3si19057731edr.544.2023.02.21.04.26.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:26:27 -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=bn03QUuz; 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 D2C58393A426 for ; Tue, 21 Feb 2023 12:10:29 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id D83513839DFC for ; Tue, 21 Feb 2023 12:03:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D83513839DFC 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-x434.google.com with SMTP id t13so4089371wrv.13 for ; Tue, 21 Feb 2023 04:03:58 -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=PReMTRp2tbf6gGkZGNgpfxe+TfV6I29DrgLnP3Mm9Po=; b=bn03QUuzzAV0p5+d/EWhcooEpcMUtF7sFCC0l5AdBav/NFPGNmr0NTXgPHqcTuB4Az FQkW37bK22O/2C+YHUOuMbRdJnyoOSotRhf5/prTVMk9z53iF9KS9wN6pHgZqkZK7JED KcHlPuHYc/ZhPVFnyIAsAPEp9aRiQTJo03K0I1JpjCMObSkTVjXKOw4qWqj2F2GpH4zT lxVhfqf0IDq5cSKnt/x11tjRTzvwRoc9UhiC2PBw0neELHfDm5kyJRWpWNMn842TUdE7 8XTp5E2rQoYESEIW3VYEMzcM0IoVIKOOAKJTmKCTCA0hYrb5bFSzYFQGtj31vwOwFIzV /XMw== 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=PReMTRp2tbf6gGkZGNgpfxe+TfV6I29DrgLnP3Mm9Po=; b=jpmTXiFO2T58w6k5huQ9ackHUzmwO73ghEzYjFb1L/xVEtrHBtwDXEtT/YqetvVEwW arTFkOwlkpT1qnv0mD64RYPwNOkQc9FSt1Q97PRLagrON1ZuDofzLr7cvTtbrXGLl6/x SaNPICDe4bcvNIlTkPipillRm9Ljrpk1MLPcTXiG9nrhkRFZEjLo7M+mT975pa7WBGXw yYUVluOBBgZiKfMnRsYlWvMFT9pALmMIwNF1cljy3qSuZG6pR5dc+Knhkum5p8FYfoIO Ulki7pp1Tfvd7TOuv6L2V7+uKu/rD56eeBg8CtGnDuAwzKl/E6JmO/J0TQTbK/FiFGLt dU5g== X-Gm-Message-State: AO0yUKVn1A28MigvlHLM8H3BM49Bzv+WEAW0YATOUGH110cbsWYmruOI TOe0G5H5j5CjdDu0l95wHhnUOXBzmmcL2SnRbQ== X-Received: by 2002:adf:e301:0:b0:2c5:46d1:69e1 with SMTP id b1-20020adfe301000000b002c546d169e1mr4955390wrj.36.1676981037272; Tue, 21 Feb 2023 04:03:57 -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.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:56 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 042/103] gccrs: ast: Improve Fragment API Date: Tue, 21 Feb 2023 13:01:32 +0100 Message-Id: <20230221120230.596966-43-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.4 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?1758443484333993602?= X-GMAIL-MSGID: =?utf-8?q?1758443484333993602?= From: Arthur Cohen gcc/rust/ChangeLog: * ast/rust-ast-fragment.cc (Fragment::Fragment): Add better APIs. (Fragment::complete): New function. (Fragment::unexpanded): New function. * ast/rust-ast-fragment.h: Declare new APIs and add documentation. * expand/rust-attribute-visitor.h: Use new Fragment API. * expand/rust-macro-builtins.cc (MacroBuiltin::file): Likewise. (MacroBuiltin::column): Likewise. (MacroBuiltin::include_bytes): Likewise. (MacroBuiltin::include_str): Likewise. (MacroBuiltin::concat): Likewise. (MacroBuiltin::env): Likewise. (MacroBuiltin::cfg): Likewise. (MacroBuiltin::include): Likewise. (MacroBuiltin::line): Likewise. * expand/rust-macro-expand.cc (parse_many): Likewise. (transcribe_expression): Likewise. (transcribe_type): Likewise. * expand/rust-macro-expand.h (struct MacroExpander): Likewise. --- gcc/rust/ast/rust-ast-fragment.cc | 31 +++++++++++++----------- gcc/rust/ast/rust-ast-fragment.h | 18 ++++++++++++-- gcc/rust/expand/rust-attribute-visitor.h | 2 +- gcc/rust/expand/rust-macro-builtins.cc | 18 +++++++------- gcc/rust/expand/rust-macro-expand.cc | 6 ++--- gcc/rust/expand/rust-macro-expand.h | 2 +- 6 files changed, 47 insertions(+), 30 deletions(-) diff --git a/gcc/rust/ast/rust-ast-fragment.cc b/gcc/rust/ast/rust-ast-fragment.cc index 1a2dd99835a..c4916093fc6 100644 --- a/gcc/rust/ast/rust-ast-fragment.cc +++ b/gcc/rust/ast/rust-ast-fragment.cc @@ -21,22 +21,13 @@ namespace Rust { namespace AST { -Fragment::Fragment (std::vector nodes, bool fragment_is_error) - : kind (fragment_is_error ? FragmentKind::Error : FragmentKind::Complete), - nodes (std::move (nodes)) -{ - if (fragment_is_error) - rust_assert (nodes.empty ()); -} +Fragment::Fragment (FragmentKind kind, std::vector nodes) + : kind (kind), nodes (std::move (nodes)) +{} Fragment::Fragment (Fragment const &other) : kind (other.get_kind ()) { - nodes.clear (); - nodes.reserve (other.nodes.size ()); - for (auto &n : other.nodes) - { - nodes.push_back (n); - } + *this = other; } Fragment & @@ -56,7 +47,19 @@ Fragment::operator= (Fragment const &other) Fragment Fragment::create_error () { - return Fragment ({}, true); + return Fragment (FragmentKind::Error, {}); +} + +Fragment +Fragment::complete (std::vector nodes) +{ + return Fragment (FragmentKind::Complete, std::move (nodes)); +} + +Fragment +Fragment::unexpanded () +{ + return Fragment (FragmentKind::Unexpanded, {}); } std::vector & diff --git a/gcc/rust/ast/rust-ast-fragment.h b/gcc/rust/ast/rust-ast-fragment.h index ee6ab0d8433..3ef4ba16dce 100644 --- a/gcc/rust/ast/rust-ast-fragment.h +++ b/gcc/rust/ast/rust-ast-fragment.h @@ -57,11 +57,23 @@ enum class FragmentKind class Fragment { public: - Fragment (std::vector nodes, bool fragment_is_error = false); Fragment (Fragment const &other); + Fragment &operator= (Fragment const &other); + + /** + * Create an error fragment + */ static Fragment create_error (); - Fragment &operator= (Fragment const &other); + /** + * Create a complete AST fragment + */ + static Fragment complete (std::vector nodes); + + /** + * Create a fragment which contains unexpanded nodes + */ + static Fragment unexpanded (); FragmentKind get_kind () const; std::vector &get_nodes (); @@ -78,6 +90,8 @@ public: void accept_vis (ASTVisitor &vis); private: + Fragment (FragmentKind kind, std::vector nodes); + FragmentKind kind; /** diff --git a/gcc/rust/expand/rust-attribute-visitor.h b/gcc/rust/expand/rust-attribute-visitor.h index 6b562bd49b1..cbddc163da7 100644 --- a/gcc/rust/expand/rust-attribute-visitor.h +++ b/gcc/rust/expand/rust-attribute-visitor.h @@ -60,7 +60,7 @@ public: { auto fragment = expander.take_expanded_fragment (*this); unsigned int original_depth = expander.expansion_depth; - auto final_fragment = AST::Fragment ({}, true); + auto final_fragment = AST::Fragment::create_error (); while (fragment.should_expand ()) { diff --git a/gcc/rust/expand/rust-macro-builtins.cc b/gcc/rust/expand/rust-macro-builtins.cc index 2a8a3f752f4..a2129e84a46 100644 --- a/gcc/rust/expand/rust-macro-builtins.cc +++ b/gcc/rust/expand/rust-macro-builtins.cc @@ -279,7 +279,7 @@ MacroBuiltin::file (Location invoc_locus, AST::MacroInvocData &invoc) = Session::get_instance ().linemap->location_file (invoc_locus); auto file_str = AST::SingleASTNode (make_string (invoc_locus, current_file)); - return AST::Fragment ({file_str}); + return AST::Fragment::complete ({file_str}); } AST::Fragment @@ -292,7 +292,7 @@ MacroBuiltin::column (Location invoc_locus, AST::MacroInvocData &invoc) new AST::LiteralExpr (std::to_string (current_column), AST::Literal::INT, PrimitiveCoreType::CORETYPE_U32, {}, invoc_locus))); - return AST::Fragment ({column_no}); + return AST::Fragment::complete ({column_no}); } /* Expand builtin macro include_bytes!("filename"), which includes the contents @@ -335,7 +335,7 @@ MacroBuiltin::include_bytes (Location invoc_locus, AST::MacroInvocData &invoc) new AST::BorrowExpr (std::move (array), false, false, {}, invoc_locus)); auto node = AST::SingleASTNode (std::move (borrow)); - return AST::Fragment ({node}); + return AST::Fragment::complete ({node}); } /* Expand builtin macro include_str!("filename"), which includes the contents @@ -362,7 +362,7 @@ MacroBuiltin::include_str (Location invoc_locus, AST::MacroInvocData &invoc) std::string str ((const char *) &bytes[0], bytes.size ()); auto node = AST::SingleASTNode (make_string (invoc_locus, str)); - return AST::Fragment ({node}); + return AST::Fragment::complete ({node}); } /* Expand builtin macro compile_error!("error"), which forces a compile error @@ -430,7 +430,7 @@ MacroBuiltin::concat (Location invoc_locus, AST::MacroInvocData &invoc) return AST::Fragment::create_error (); auto node = AST::SingleASTNode (make_string (invoc_locus, str)); - return AST::Fragment ({node}); + return AST::Fragment::complete ({node}); } /* Expand builtin macro env!(), which inspects an environment variable at @@ -491,7 +491,7 @@ MacroBuiltin::env (Location invoc_locus, AST::MacroInvocData &invoc) } auto node = AST::SingleASTNode (make_string (invoc_locus, env_value)); - return AST::Fragment ({node}); + return AST::Fragment::complete ({node}); } AST::Fragment @@ -527,7 +527,7 @@ MacroBuiltin::cfg (Location invoc_locus, AST::MacroInvocData &invoc) new AST::LiteralExpr (result ? "true" : "false", AST::Literal::BOOL, PrimitiveCoreType::CORETYPE_BOOL, {}, invoc_locus))); - return AST::Fragment ({literal_exp}); + return AST::Fragment::complete ({literal_exp}); } /* Expand builtin macro include!(), which includes a source file at the current @@ -584,7 +584,7 @@ MacroBuiltin::include (Location invoc_locus, AST::MacroInvocData &invoc) nodes.push_back (node); } - return AST::Fragment (nodes); + return AST::Fragment::complete (nodes); } AST::Fragment @@ -597,7 +597,7 @@ MacroBuiltin::line (Location invoc_locus, AST::MacroInvocData &invoc) new AST::LiteralExpr (std::to_string (current_line), AST::Literal::INT, PrimitiveCoreType::CORETYPE_U32, {}, invoc_locus))); - return AST::Fragment ({line_no}); + return AST::Fragment::complete ({line_no}); } } // namespace Rust diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc index 0684a28787f..9c3523e0515 100644 --- a/gcc/rust/expand/rust-macro-expand.cc +++ b/gcc/rust/expand/rust-macro-expand.cc @@ -729,7 +729,7 @@ parse_many (Parser &parser, TokenId &delimiter, nodes.emplace_back (std::move (node)); } - return AST::Fragment (std::move (nodes)); + return AST::Fragment::complete (std::move (nodes)); } /** @@ -840,7 +840,7 @@ transcribe_expression (Parser &parser) { auto expr = parser.parse_expr (); - return AST::Fragment ({std::move (expr)}); + return AST::Fragment::complete ({std::move (expr)}); } /** @@ -855,7 +855,7 @@ transcribe_type (Parser &parser) for (auto err : parser.get_errors ()) err.emit_error (); - return AST::Fragment ({std::move (type)}); + return AST::Fragment::complete ({std::move (type)}); } static AST::Fragment diff --git a/gcc/rust/expand/rust-macro-expand.h b/gcc/rust/expand/rust-macro-expand.h index b0c0c23a0c3..bf761c1b199 100644 --- a/gcc/rust/expand/rust-macro-expand.h +++ b/gcc/rust/expand/rust-macro-expand.h @@ -344,7 +344,7 @@ struct MacroExpander auto new_nodes = expanded_fragment.get_nodes (); std::move (new_nodes.begin (), new_nodes.end (), std::back_inserter (accumulator)); - expanded_fragment = AST::Fragment (accumulator); + expanded_fragment = AST::Fragment::complete (accumulator); } expansion_depth--; } From patchwork Tue Feb 21 12:01:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59988 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1831579wrn; Tue, 21 Feb 2023 04:24:33 -0800 (PST) X-Google-Smtp-Source: AK7set+xIEMDJSIAIbznV58buHUYA5mGtOEW3S3g1kknL5YDBx+SZvxjrNStbkjjxC/jlbx2alZo X-Received: by 2002:a17:907:ea2:b0:8aa:f2f2:7543 with SMTP id ho34-20020a1709070ea200b008aaf2f27543mr17377402ejc.29.1676982273828; Tue, 21 Feb 2023 04:24:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982273; cv=none; d=google.com; s=arc-20160816; b=VHP+ifhO6dq+Z5vZJ9ql9T/GpMnupnG/Lj7ejxIn3nIktXaILw2qMn8JSXCkuIiHpY isfjdin1LMMos+NJuPr6ahICxdUCUebt1R+MsxzWkfm6T7IUf0Q4axPMIa4RZt/5OdFf 57YC+E3Cf0ObjzLeFImsOBl/cw74EZYk5WZGaWuVge2DfevbODJ4+6QuRzv//BpMkxFN DNtWYI7Gp7WdNy7gUwlN0RnkZh7WUNCkmcDcoqhMirRDIqXGxfINkz+hAk4apHGFVl73 eQnbONhq1BYck+7AGKiCI4tfJ4p5iptCsS4WlinuPAmhOJ5zFmM/O1UqySMRsmqb7dJa JkPQ== 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=8dW4H40ntCuCTMH5mJ9Wz48yqLw+vd7e/YsoIF/P540=; b=aPSCsz670QawMuiXnELZnPFYpMXaKpLK1msStT9wMv9rh20W90BsxI+s/yyS7TWs2H QV7MSozKGMc3EA6qmMWVCKA+1QcNmh7JcTku6TH2uvpPJnS5j579lOpYF+DEBbW7NohS I/w9QC01UhHcXQe50tCvkfpqdC4NECFklFcodtLo07qvj8RKFlKYyoq+9s8/R+WmavC9 5WA+6weeqZY2his53g7IwbYbvkpaOIui1okFLmvQLZK/miuetIyDfFEJUilCRQSRe37c naJ/aUxrSfzjmv6wCeb51WJXMozH43DnUFia5GT9I8WFLixz/SxGyBV+Re4dQwGfdGhx ZmFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=GY97Dg5Y; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 17-20020a170906015100b008cf961a7bdesi9477872ejh.598.2023.02.21.04.24.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:24:33 -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=GY97Dg5Y; 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 0A162384C917 for ; Tue, 21 Feb 2023 12:09:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id A78F2384DD00 for ; Tue, 21 Feb 2023 12:03:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A78F2384DD00 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-x429.google.com with SMTP id v3so4084756wrp.2 for ; Tue, 21 Feb 2023 04:03:59 -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=8dW4H40ntCuCTMH5mJ9Wz48yqLw+vd7e/YsoIF/P540=; b=GY97Dg5YRIRzDlxAu5fS/b2JEX53+bdObLWPYqcYdGnPV3Hn/h2trlmuA6jnr02BkA s0z7+uxmQetdZ9L+upBmVBEW269tmHDU2A9xf+iguKdUs4vWiDvG5a0JXA4NcdZ+enC1 dGMC8Sijs4zuBgzamLpLg/D8ZpPHKM5ezWHiFNImjmVFegrEm61n+mLiION7GCmEhAhE D/8tU6tWuhYxSYVOy49m4F4Sylm19wrw5cDLI74mDBSfZXCoyG2tKjrcgfbsgKlTkCY1 PdbWA4Gd0SjPmoOYJK9HWO+6Ui89WYVnpUUOLti79rYH+aYXK27zTb86OXzijuOyjwsY Kd6A== 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=8dW4H40ntCuCTMH5mJ9Wz48yqLw+vd7e/YsoIF/P540=; b=SlNnAcQWIZ2SrVXFfdhJtbMz4Bp1He3i325dG8wWmLj7D6DEOhwC1aXhjnBXUEA1Hy SvtgG6+0H9MJwvsfmTa/ZfXxX5Rcrivcf3gef0cSfDuXlsCzIcythnyPlKoSCFSfJzUq JxJxtIrxMfBAWxguk0cjyc5eTFu8NM7qgVd7goLhmzzRmThX89C6M5TRpQ6iMFnlWixC WnpkL2RGlsZmsS8jjEy/xL/OAU4NM2MZ3vgS6JxtM2OcskeetL/Td/U/pfBB70Z9JfkE uFl723hTp7slTwWNQveajLiq2qGRB1ke0VxznP8qyPKMudgc/NqMROD0KH48FeLPbFP0 Qe9Q== X-Gm-Message-State: AO0yUKWonPOg1IU/CIoMOflIQIv1HQ7OMAttxVdIuLzk0TMiODnu06bK FA7TSlFPjvwkqt1PGS/zOTNclKACt9uFZPdvGw== X-Received: by 2002:a05:6000:1210:b0:2c3:eafd:143d with SMTP id e16-20020a056000121000b002c3eafd143dmr4675964wrx.69.1676981038335; Tue, 21 Feb 2023 04:03:58 -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.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:57 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 043/103] gccrs: Add missing fn_once_output langitem Date: Tue, 21 Feb 2023 13:01:33 +0100 Message-Id: <20230221120230.596966-44-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?1758443364503285230?= X-GMAIL-MSGID: =?utf-8?q?1758443364503285230?= From: Philip Herron gcc/rust/ChangeLog: * util/rust-lang-item.h: Add handling for `fn_once_output`. --- gcc/rust/util/rust-lang-item.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gcc/rust/util/rust-lang-item.h b/gcc/rust/util/rust-lang-item.h index c7e0e5c811d..02eeaee60df 100644 --- a/gcc/rust/util/rust-lang-item.h +++ b/gcc/rust/util/rust-lang-item.h @@ -75,6 +75,7 @@ public: // functions FN_ONCE, + FN_ONCE_OUTPUT, UNKNOWN, }; @@ -225,6 +226,10 @@ public: { return ItemType::FN_ONCE; } + else if (item.compare ("fn_once_output") == 0) + { + return ItemType::FN_ONCE_OUTPUT; + } return ItemType::UNKNOWN; } @@ -305,6 +310,8 @@ public: return "const_slice_ptr"; case FN_ONCE: return "fn_once"; + case FN_ONCE_OUTPUT: + return "fn_once_output"; case UNKNOWN: return ""; From patchwork Tue Feb 21 12:01:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60008 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1835373wrn; Tue, 21 Feb 2023 04:33:40 -0800 (PST) X-Google-Smtp-Source: AK7set8gFF+z7zAce9HPlci49kgaPOZc3fTrrdkPKCPr62uQctzRy/H1NoOeuU+FOhoR3ZAjtHCu X-Received: by 2002:a17:907:206e:b0:8b1:3a8e:232 with SMTP id qp14-20020a170907206e00b008b13a8e0232mr10097857ejb.74.1676982820686; Tue, 21 Feb 2023 04:33:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982820; cv=none; d=google.com; s=arc-20160816; b=jnQH2xRkwNTM6dkrXzk8jgK5MjH7W/16KqJ26zCpHn2b0FNbm2TLEt/HWf7luVvv1W HBMMTOohvFkifoZ3w7T2bA8eeq6J5tclwrrhnfPETU9TXt2penhkzY1fnHAHVO0pfTVy cxDx/4RWiPBb78KdIyaKcwPGto5L3/aYfG7nuYoiCZ7iHlehnrn12Kj1YcHoGWL94Nt+ sVkXClt75+Dm3xcGndebCZYdAn+NeqwRTFpGUg9N8T9g4oU23i00rY+QkY8jx5mzZtcm smv4iar7q/mUdH0TZkqUTGa8tQJibFIYXqdorJSjUgsmrcjW06XDa6hpJxKSBFyzYekx izMw== 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=DoYCs20heEDNP+c0YOP3YG/OH5gok3wKhwKVubDOM1I=; b=hgs/Bk7QFygnGe9j9TZCv3EcKMm4EiCmQsFDXBWvbEz746UuyPVfP34Ru3Xih4B/mC vd6sG0LGikRKXqeyVl5DTutjBeWW7d0xdTNXvXIhUvGuEs2BdsKljlkDUWkCCRAUwyZ/ 9DUltMuVdggtLFzVarcGTurTmHpxk+QHJZryX4taPJ5cRRvPDHf+y0zH2ObtffPtEmG4 PPbzptZQSa10pY/eeW/21TZNCo226lJg/i4uH+B/o1ZhX4zUx+iVVTIypp8NcUIp50Wy JpEEKitk8j1Zm3RT7/LQ8zb0TnWO5+Inld0o6GnfBhkg/nXk99K/wxIh6bdPhK1lD9wg 1YKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=UKvCCnj2; 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 uo42-20020a170907cc2a00b008cf2b9f412bsi7902678ejc.743.2023.02.21.04.33.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:33:40 -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=UKvCCnj2; 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 D2CFD3902A75 for ; Tue, 21 Feb 2023 12:12:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id B57F33839047 for ; Tue, 21 Feb 2023 12:04:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B57F33839047 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-x42e.google.com with SMTP id l25so3758455wrb.3 for ; Tue, 21 Feb 2023 04:04:00 -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=DoYCs20heEDNP+c0YOP3YG/OH5gok3wKhwKVubDOM1I=; b=UKvCCnj2Kf9EkvdVBp/ioNoXeVW6fHPxkELPJQT3vZn0IAWYbw5J1EPRBeZ0CAEJ/k EkzDDnatY59e8sFBaWYotIxDHDH0dE938S92FIEG+nMHJWvL+1CTPHTRYjfHs2II7QQw 0A0s+aPmxCBXx3xJl9OnMdRlbH/ZlhJ1VKjbhpXFqCWXunmhnJhCcb/J5JmF5gzmWL3V bGq4Z2V/B3pdECyWW6afx4Owj47Qlt1gxai/Jy9RkQzLvq4QZhvzj/5gxPQq3/fy62BI xJEVZ3wPCEpghj3/rev7RYK8sfbN5ZoFveFNgkVD1/m+w2hhGpi+jNgxEPybKAKstKfZ fkGw== 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=DoYCs20heEDNP+c0YOP3YG/OH5gok3wKhwKVubDOM1I=; b=0mFPb7ALusESPp8d7PiZedWj+pWmkYcXDQERPsY1JOQl08oQ/k4FpS/KCbOSkqES4E I7J6Ct6nYAfhZLIAlw2VEm89zBuJaxSkU9hGTDbn6iWvTro0YHeVKi2MdFiNhJiYcRcb gALG54fVraeAVZcC49Zwh8us8Y89cyCjO/vkjMOcawVNGLbwRxDIJstTzW//Pvlz6VO4 TWGchV7CkwmD8hgAN86PIZ6BXUOns0zCgrdG+arssjcby5OnWwapY78lEvw/kSIsPdbA M2b6oFUn0Mi+VhMzJBUYBBVHLi/4fjGR32UI2ukJyzVB39SRiC1a8/fw7W3rhSXk5gJF QiSQ== X-Gm-Message-State: AO0yUKVW92FRp88iHR2LgTVNGR5oizUA8xh/tx0Im+4P584JOOGWSrBK sjv1FP81ryzTFK9KYtmt8AAmwlj5oF+AUTmatg== X-Received: by 2002:adf:e7cc:0:b0:2c5:9eaa:831 with SMTP id e12-20020adfe7cc000000b002c59eaa0831mr4934578wrn.69.1676981039483; Tue, 21 Feb 2023 04:03:59 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:58 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 044/103] gccrs: Refactor expression hir lowering into cc file Date: Tue, 21 Feb 2023 13:01:34 +0100 Message-Id: <20230221120230.596966-45-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, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_FILL_THIS_FORM_SHORT autolearn=ham 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?1758443937879379450?= X-GMAIL-MSGID: =?utf-8?q?1758443937879379450?= From: Philip Herron gcc/rust/ChangeLog: * Make-lang.in: Add new object file for expression lowering. * ast/rust-expr.h: Move implementation of expr lowering to source file. * backend/rust-compile-block.h: Likewise. * backend/rust-compile-expr.cc (CompileExpr::visit): Likewise. * backend/rust-compile-expr.h: Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise. * checks/errors/privacy/rust-privacy-reporter.h: Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise. * checks/errors/rust-const-checker.h: Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.h: Likewise. * hir/rust-ast-lower-base.h: Likewise. * hir/rust-ast-lower-expr.h (RUST_AST_LOWER_EXPR): Likewise. * hir/rust-ast-lower.cc (ASTLoweringBase::lower_closure_param): Likewise. * hir/rust-hir-dump.cc (Dump::visit): Likewise. * hir/rust-hir-dump.h: Likewise. * hir/tree/rust-hir-expr.h (class ClosureExpr): Likewise. (class ClosureExprInner): Likewise. (class ClosureExprInnerTyped): Likewise. * hir/tree/rust-hir-full-decls.h (class ClosureExprInner): Likewise. (class ClosureExprInnerTyped): Likewise. * hir/tree/rust-hir-full-test.cc (ClosureExprInnerTyped::as_string): Likewise. (ClosureExprInner::as_string): Likewise. (ClosureExprInner::accept_vis): Likewise. (ClosureExpr::accept_vis): Likewise. (ClosureExprInnerTyped::accept_vis): Likewise. * hir/tree/rust-hir-visitor.h: Likewise. * hir/tree/rust-hir.h (class Expr): Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. * typecheck/rust-hir-type-check-expr.h: Likewise. * hir/rust-ast-lower-expr.cc: New file. --- gcc/rust/Make-lang.in | 1 + gcc/rust/ast/rust-expr.h | 9 +- gcc/rust/backend/rust-compile-block.h | 6 +- gcc/rust/backend/rust-compile-expr.cc | 6 + gcc/rust/backend/rust-compile-expr.h | 3 +- .../errors/privacy/rust-privacy-reporter.cc | 8 +- .../errors/privacy/rust-privacy-reporter.h | 3 +- gcc/rust/checks/errors/rust-const-checker.cc | 6 +- gcc/rust/checks/errors/rust-const-checker.h | 3 +- gcc/rust/checks/errors/rust-unsafe-checker.cc | 6 +- gcc/rust/checks/errors/rust-unsafe-checker.h | 3 +- gcc/rust/hir/rust-ast-lower-base.h | 2 + gcc/rust/hir/rust-ast-lower-expr.cc | 810 ++++++++++++++++++ gcc/rust/hir/rust-ast-lower-expr.h | 746 +--------------- gcc/rust/hir/rust-ast-lower.cc | 23 + gcc/rust/hir/rust-hir-dump.cc | 6 +- gcc/rust/hir/rust-hir-dump.h | 3 +- gcc/rust/hir/tree/rust-hir-expr.h | 213 ++--- gcc/rust/hir/tree/rust-hir-full-decls.h | 2 - gcc/rust/hir/tree/rust-hir-full-test.cc | 37 +- gcc/rust/hir/tree/rust-hir-visitor.h | 9 +- gcc/rust/hir/tree/rust-hir.h | 1 + .../typecheck/rust-hir-type-check-expr.cc | 6 + gcc/rust/typecheck/rust-hir-type-check-expr.h | 3 +- 24 files changed, 1009 insertions(+), 906 deletions(-) create mode 100644 gcc/rust/hir/rust-ast-lower-expr.cc diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index c5960530d0a..2f4f409f54f 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -94,6 +94,7 @@ GRS_OBJS = \ rust/rust-ast-lower-base.o \ rust/rust-ast-lower-pattern.o \ rust/rust-ast-lower-item.o \ + rust/rust-ast-lower-expr.o \ rust/rust-early-name-resolver.o \ rust/rust-name-resolver.o \ rust/rust-ast-resolve.o \ diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index c764f9c4c66..c58fae5e564 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -2134,8 +2134,6 @@ struct ClosureParam private: std::vector outer_attrs; std::unique_ptr pattern; - - // bool has_type_given; std::unique_ptr type; Location locus; @@ -2202,19 +2200,19 @@ public: const std::vector &get_outer_attrs () const { return outer_attrs; } std::vector &get_outer_attrs () { return outer_attrs; } - // TODO: is this better? Or is a "vis_block" better? std::unique_ptr &get_pattern () { rust_assert (pattern != nullptr); return pattern; } - // TODO: is this better? Or is a "vis_block" better? std::unique_ptr &get_type () { rust_assert (has_type_given ()); return type; } + + Location get_locus () const { return locus; } }; // Base closure definition expression AST node - abstract @@ -2248,6 +2246,8 @@ public: { outer_attrs = std::move (new_attrs); } + + bool get_has_move () const { return has_move; } }; // Represents a non-type-specified closure expression AST node @@ -2307,7 +2307,6 @@ public: return closure_inner == nullptr; } - // TODO: is this better? Or is a "vis_block" better? std::unique_ptr &get_definition_expr () { rust_assert (closure_inner != nullptr); diff --git a/gcc/rust/backend/rust-compile-block.h b/gcc/rust/backend/rust-compile-block.h index bcb7e77fc6d..0ccf81f376b 100644 --- a/gcc/rust/backend/rust-compile-block.h +++ b/gcc/rust/backend/rust-compile-block.h @@ -57,8 +57,7 @@ public: // Empty visit for unused Expression HIR nodes. void visit (HIR::PathInExpression &) override {} void visit (HIR::QualifiedPathInExpression &) override {} - void visit (HIR::ClosureExprInner &) override {} - void visit (HIR::ClosureExprInnerTyped &) override {} + void visit (HIR::ClosureExpr &) override {} void visit (HIR::StructExprFieldIdentifier &) override {} void visit (HIR::StructExprFieldIdentifierValue &) override {} void visit (HIR::StructExprFieldIndexValue &) override {} @@ -146,8 +145,7 @@ public: // Empty visit for unused Expression HIR nodes. void visit (HIR::PathInExpression &) override {} void visit (HIR::QualifiedPathInExpression &) override {} - void visit (HIR::ClosureExprInner &) override {} - void visit (HIR::ClosureExprInnerTyped &) override {} + void visit (HIR::ClosureExpr &) override {} void visit (HIR::StructExprFieldIdentifier &) override {} void visit (HIR::StructExprFieldIdentifierValue &) override {} void visit (HIR::StructExprFieldIndexValue &) override {} diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index ddf914f6736..724a93a68bd 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -2803,5 +2803,11 @@ CompileExpr::visit (HIR::ArrayIndexExpr &expr) expr.get_locus ()); } +void +CompileExpr::visit (HIR::ClosureExpr &expr) +{ + gcc_unreachable (); +} + } // namespace Compile } // namespace Rust diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index 845511f9f43..7fc3f5e7f4d 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -67,10 +67,9 @@ public: void visit (HIR::RangeToExpr &expr) override; void visit (HIR::RangeFullExpr &expr) override; void visit (HIR::RangeFromToInclExpr &expr) override; + void visit (HIR::ClosureExpr &expr) override; // TODO - void visit (HIR::ClosureExprInner &) override {} - void visit (HIR::ClosureExprInnerTyped &) override {} void visit (HIR::ErrorPropagationExpr &) override {} void visit (HIR::RangeToInclExpr &) override {} void visit (HIR::ForLoopExpr &) override {} diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc index e5afe817801..a126e7b4462 100644 --- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc +++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc @@ -426,7 +426,7 @@ PrivacyReporter::visit (HIR::FieldAccessExpr &expr) } void -PrivacyReporter::visit (HIR::ClosureExprInner &expr) +PrivacyReporter::visit (HIR::ClosureExpr &expr) { // Not handled yet } @@ -442,12 +442,6 @@ PrivacyReporter::visit (HIR::BlockExpr &expr) last_expr->accept_vis (*this); } -void -PrivacyReporter::visit (HIR::ClosureExprInnerTyped &expr) -{ - // Not handled yet -} - void PrivacyReporter::visit (HIR::ContinueExpr &expr) {} diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.h b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.h index 98f7a9419b2..c9307787e9e 100644 --- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.h +++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.h @@ -83,8 +83,7 @@ types virtual void visit (HIR::QualifiedPathInExpression &expr); virtual void visit (HIR::PathInExpression &expr); - virtual void visit (HIR::ClosureExprInnerTyped &); - virtual void visit (HIR::ClosureExprInner &expr); + virtual void visit (HIR::ClosureExpr &expr); virtual void visit (HIR::StructExprStructFields &); virtual void visit (HIR::StructExprStruct &); virtual void visit (HIR::LiteralExpr &expr); diff --git a/gcc/rust/checks/errors/rust-const-checker.cc b/gcc/rust/checks/errors/rust-const-checker.cc index 2fa9614abf1..01dc2620767 100644 --- a/gcc/rust/checks/errors/rust-const-checker.cc +++ b/gcc/rust/checks/errors/rust-const-checker.cc @@ -382,7 +382,7 @@ ConstChecker::visit (FieldAccessExpr &expr) } void -ConstChecker::visit (ClosureExprInner &expr) +ConstChecker::visit (ClosureExpr &expr) {} void @@ -395,10 +395,6 @@ ConstChecker::visit (BlockExpr &expr) expr.get_final_expr ()->accept_vis (*this); } -void -ConstChecker::visit (ClosureExprInnerTyped &expr) -{} - void ConstChecker::visit (ContinueExpr &expr) {} diff --git a/gcc/rust/checks/errors/rust-const-checker.h b/gcc/rust/checks/errors/rust-const-checker.h index 13cf44b1273..238173874aa 100644 --- a/gcc/rust/checks/errors/rust-const-checker.h +++ b/gcc/rust/checks/errors/rust-const-checker.h @@ -111,9 +111,8 @@ private: virtual void visit (CallExpr &expr) override; virtual void visit (MethodCallExpr &expr) override; virtual void visit (FieldAccessExpr &expr) override; - virtual void visit (ClosureExprInner &expr) override; + virtual void visit (ClosureExpr &expr) override; virtual void visit (BlockExpr &expr) override; - virtual void visit (ClosureExprInnerTyped &expr) override; virtual void visit (ContinueExpr &expr) override; virtual void visit (BreakExpr &expr) override; virtual void visit (RangeFromToExpr &expr) override; diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.cc b/gcc/rust/checks/errors/rust-unsafe-checker.cc index bb85fa77dc7..02868794cbc 100644 --- a/gcc/rust/checks/errors/rust-unsafe-checker.cc +++ b/gcc/rust/checks/errors/rust-unsafe-checker.cc @@ -453,7 +453,7 @@ UnsafeChecker::visit (FieldAccessExpr &expr) } void -UnsafeChecker::visit (ClosureExprInner &expr) +UnsafeChecker::visit (ClosureExpr &expr) {} void @@ -466,10 +466,6 @@ UnsafeChecker::visit (BlockExpr &expr) expr.get_final_expr ()->accept_vis (*this); } -void -UnsafeChecker::visit (ClosureExprInnerTyped &expr) -{} - void UnsafeChecker::visit (ContinueExpr &expr) {} diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.h b/gcc/rust/checks/errors/rust-unsafe-checker.h index 39c3b229ccc..9df44db06a9 100644 --- a/gcc/rust/checks/errors/rust-unsafe-checker.h +++ b/gcc/rust/checks/errors/rust-unsafe-checker.h @@ -88,9 +88,8 @@ private: virtual void visit (CallExpr &expr) override; virtual void visit (MethodCallExpr &expr) override; virtual void visit (FieldAccessExpr &expr) override; - virtual void visit (ClosureExprInner &expr) override; + virtual void visit (ClosureExpr &expr) override; virtual void visit (BlockExpr &expr) override; - virtual void visit (ClosureExprInnerTyped &expr) override; virtual void visit (ContinueExpr &expr) override; virtual void visit (BreakExpr &expr) override; virtual void visit (RangeFromToExpr &expr) override; diff --git a/gcc/rust/hir/rust-ast-lower-base.h b/gcc/rust/hir/rust-ast-lower-base.h index adcbc5d2f69..1af44aa239f 100644 --- a/gcc/rust/hir/rust-ast-lower-base.h +++ b/gcc/rust/hir/rust-ast-lower-base.h @@ -313,6 +313,8 @@ protected: HIR::Literal lower_literal (const AST::Literal &literal); HIR::ExternBlock *lower_extern_block (AST::ExternBlock &extern_block); + + HIR::ClosureParam lower_closure_param (AST::ClosureParam ¶m); }; } // namespace HIR diff --git a/gcc/rust/hir/rust-ast-lower-expr.cc b/gcc/rust/hir/rust-ast-lower-expr.cc new file mode 100644 index 00000000000..df4ba9d2911 --- /dev/null +++ b/gcc/rust/hir/rust-ast-lower-expr.cc @@ -0,0 +1,810 @@ +// 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-ast-lower-expr.h" +#include "rust-ast-lower-base.h" +#include "rust-ast-lower-block.h" +#include "rust-ast-lower-struct-field-expr.h" +#include "rust-ast-lower-pattern.h" +#include "rust-ast-lower-type.h" + +namespace Rust { +namespace HIR { + +ASTLoweringExpr::ASTLoweringExpr () + : ASTLoweringBase (), translated (nullptr), translated_array_elems (nullptr), + terminated (false) +{} + +HIR::Expr * +ASTLoweringExpr::translate (AST::Expr *expr, bool *terminated) +{ + ASTLoweringExpr resolver; + expr->accept_vis (resolver); + if (resolver.translated == nullptr) + { + rust_fatal_error (expr->get_locus (), "Failed to lower expr: [%s]", + expr->as_string ().c_str ()); + return nullptr; + } + + resolver.mappings->insert_hir_expr (resolver.translated); + resolver.mappings->insert_location ( + resolver.translated->get_mappings ().get_hirid (), expr->get_locus ()); + + if (terminated != nullptr) + *terminated = resolver.terminated; + + return resolver.translated; +} + +void +ASTLoweringExpr::visit (AST::TupleIndexExpr &expr) +{ + HIR::Expr *tuple_expr + = ASTLoweringExpr::translate (expr.get_tuple_expr ().get (), &terminated); + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + translated + = new HIR::TupleIndexExpr (mapping, std::unique_ptr (tuple_expr), + expr.get_tuple_index (), expr.get_outer_attrs (), + expr.get_locus ()); +} + +void +ASTLoweringExpr::visit (AST::TupleExpr &expr) +{ + std::vector > tuple_elements; + for (auto &e : expr.get_tuple_elems ()) + { + HIR::Expr *t = ASTLoweringExpr::translate (e.get ()); + tuple_elements.push_back (std::unique_ptr (t)); + } + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + translated + = new HIR::TupleExpr (std::move (mapping), std::move (tuple_elements), + expr.get_inner_attrs (), expr.get_outer_attrs (), + expr.get_locus ()); +} + +void +ASTLoweringExpr::visit (AST::IfExpr &expr) +{ + translated = ASTLoweringIfBlock::translate (&expr, &terminated); +} + +void +ASTLoweringExpr::visit (AST::IfExprConseqElse &expr) +{ + translated = ASTLoweringIfBlock::translate (&expr, &terminated); +} + +void +ASTLoweringExpr::visit (AST::IfExprConseqIf &expr) +{ + translated = ASTLoweringIfBlock::translate (&expr, &terminated); +} + +void +ASTLoweringExpr::visit (AST::BlockExpr &expr) +{ + translated = ASTLoweringBlock::translate (&expr, &terminated); +} + +void +ASTLoweringExpr::visit (AST::UnsafeBlockExpr &expr) +{ + translated = ASTLoweringBlock::translate (&expr, &terminated); +} + +void +ASTLoweringExpr::visit (AST::PathInExpression &expr) +{ + translated = ASTLowerPathInExpression::translate (&expr); +} + +void +ASTLoweringExpr::visit (AST::QualifiedPathInExpression &expr) +{ + translated = ASTLowerQualPathInExpression::translate (&expr); +} + +void +ASTLoweringExpr::visit (AST::ReturnExpr &expr) +{ + terminated = true; + HIR::Expr *return_expr + = expr.has_returned_expr () + ? ASTLoweringExpr::translate (expr.get_returned_expr ().get ()) + : nullptr; + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + translated = new HIR::ReturnExpr (mapping, expr.get_locus (), + std::unique_ptr (return_expr)); +} + +void +ASTLoweringExpr::visit (AST::CallExpr &expr) +{ + HIR::Expr *func + = ASTLoweringExpr::translate (expr.get_function_expr ().get ()); + + auto const &in_params = expr.get_params (); + std::vector > params; + for (auto ¶m : in_params) + { + auto trans = ASTLoweringExpr::translate (param.get ()); + params.push_back (std::unique_ptr (trans)); + } + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping ( + crate_num, UNKNOWN_NODEID /* this can map back to the AST*/, + mappings->get_next_hir_id (crate_num), UNKNOWN_LOCAL_DEFID); + + translated = new HIR::CallExpr (mapping, std::unique_ptr (func), + std::move (params), expr.get_outer_attrs (), + expr.get_locus ()); +} + +void +ASTLoweringExpr::visit (AST::MethodCallExpr &expr) +{ + HIR::PathExprSegment method_path + = lower_path_expr_seg (expr.get_method_name ()); + + HIR::Expr *receiver + = ASTLoweringExpr::translate (expr.get_receiver_expr ().get ()); + + auto const &in_params = expr.get_params (); + std::vector > params; + for (auto ¶m : in_params) + { + auto trans = ASTLoweringExpr::translate (param.get ()); + params.push_back (std::unique_ptr (trans)); + } + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + translated + = new HIR::MethodCallExpr (mapping, std::unique_ptr (receiver), + method_path, std::move (params), + expr.get_outer_attrs (), expr.get_locus ()); +} + +void +ASTLoweringExpr::visit (AST::AssignmentExpr &expr) +{ + HIR::Expr *lhs = ASTLoweringExpr::translate (expr.get_left_expr ().get ()); + HIR::Expr *rhs = ASTLoweringExpr::translate (expr.get_right_expr ().get ()); + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + translated + = new HIR::AssignmentExpr (mapping, std::unique_ptr (lhs), + std::unique_ptr (rhs), + expr.get_locus ()); +} + +void +ASTLoweringExpr::visit (AST::IdentifierExpr &expr) +{ + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping1 (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + Analysis::NodeMapping mapping2 (mapping1); + + HIR::PathIdentSegment ident_seg (expr.get_ident ()); + HIR::PathExprSegment seg (mapping1, ident_seg, expr.get_locus (), + HIR::GenericArgs::create_empty ()); + translated = new HIR::PathInExpression (mapping2, {seg}, expr.get_locus (), + false, expr.get_outer_attrs ()); +} + +void +ASTLoweringExpr::visit (AST::ArrayExpr &expr) +{ + expr.get_array_elems ()->accept_vis (*this); + rust_assert (translated_array_elems != nullptr); + HIR::ArrayElems *elems = translated_array_elems; + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + translated + = new HIR::ArrayExpr (mapping, std::unique_ptr (elems), + expr.get_inner_attrs (), expr.get_outer_attrs (), + expr.get_locus ()); +} + +void +ASTLoweringExpr::visit (AST::ArrayIndexExpr &expr) +{ + HIR::Expr *array_expr + = ASTLoweringExpr::translate (expr.get_array_expr ().get ()); + HIR::Expr *array_index_expr + = ASTLoweringExpr::translate (expr.get_index_expr ().get ()); + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + translated + = new HIR::ArrayIndexExpr (mapping, std::unique_ptr (array_expr), + std::unique_ptr (array_index_expr), + expr.get_outer_attrs (), expr.get_locus ()); +} + +void +ASTLoweringExpr::visit (AST::ArrayElemsValues &elems) +{ + std::vector > elements; + for (auto &elem : elems.get_values ()) + { + HIR::Expr *translated_elem = ASTLoweringExpr::translate (elem.get ()); + elements.push_back (std::unique_ptr (translated_elem)); + } + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (mappings->get_current_crate (), + elems.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + translated_array_elems + = new HIR::ArrayElemsValues (mapping, std::move (elements)); +} + +void +ASTLoweringExpr::visit (AST::ArrayElemsCopied &elems) +{ + HIR::Expr *element + = ASTLoweringExpr::translate (elems.get_elem_to_copy ().get ()); + HIR::Expr *num_copies + = ASTLoweringExpr::translate (elems.get_num_copies ().get ()); + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (mappings->get_current_crate (), + elems.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + translated_array_elems + = new HIR::ArrayElemsCopied (mapping, std::unique_ptr (element), + std::unique_ptr (num_copies)); +} + +void +ASTLoweringExpr::visit (AST::LiteralExpr &expr) +{ + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + HIR::Literal l = lower_literal (expr.get_literal ()); + translated = new HIR::LiteralExpr (mapping, std::move (l), expr.get_locus (), + expr.get_outer_attrs ()); +} + +void +ASTLoweringExpr::visit (AST::ArithmeticOrLogicalExpr &expr) +{ + HIR::Expr *lhs = ASTLoweringExpr::translate (expr.get_left_expr ().get ()); + rust_assert (lhs != nullptr); + HIR::Expr *rhs = ASTLoweringExpr::translate (expr.get_right_expr ().get ()); + rust_assert (rhs != nullptr); + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + translated = new HIR::ArithmeticOrLogicalExpr ( + mapping, std::unique_ptr (lhs), std::unique_ptr (rhs), + expr.get_expr_type (), expr.get_locus ()); +} + +void +ASTLoweringExpr::visit (AST::ComparisonExpr &expr) +{ + HIR::Expr *lhs = ASTLoweringExpr::translate (expr.get_left_expr ().get ()); + rust_assert (lhs != nullptr); + HIR::Expr *rhs = ASTLoweringExpr::translate (expr.get_right_expr ().get ()); + rust_assert (rhs != nullptr); + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + translated + = new HIR::ComparisonExpr (mapping, std::unique_ptr (lhs), + std::unique_ptr (rhs), + expr.get_expr_type (), expr.get_locus ()); +} + +void +ASTLoweringExpr::visit (AST::LazyBooleanExpr &expr) +{ + HIR::Expr *lhs = ASTLoweringExpr::translate (expr.get_left_expr ().get ()); + rust_assert (lhs != nullptr); + HIR::Expr *rhs = ASTLoweringExpr::translate (expr.get_right_expr ().get ()); + rust_assert (rhs != nullptr); + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + translated + = new HIR::LazyBooleanExpr (mapping, std::unique_ptr (lhs), + std::unique_ptr (rhs), + expr.get_expr_type (), expr.get_locus ()); +} + +void +ASTLoweringExpr::visit (AST::NegationExpr &expr) +{ + HIR::Expr *negated_value + = ASTLoweringExpr::translate (expr.get_negated_expr ().get ()); + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + translated + = new HIR::NegationExpr (mapping, + std::unique_ptr (negated_value), + expr.get_expr_type (), expr.get_outer_attrs (), + expr.get_locus ()); +} + +void +ASTLoweringExpr::visit (AST::TypeCastExpr &expr) +{ + HIR::Expr *expr_to_cast_to + = ASTLoweringExpr::translate (expr.get_casted_expr ().get ()); + HIR::Type *type_to_cast_to + = lower_type_no_bounds (expr.get_type_to_cast_to ().get ()); + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + translated + = new HIR::TypeCastExpr (mapping, + std::unique_ptr (expr_to_cast_to), + std::unique_ptr (type_to_cast_to), + expr.get_locus ()); +} + +void +ASTLoweringExpr::visit (AST::CompoundAssignmentExpr &expr) +{ + ArithmeticOrLogicalOperator op; + switch (expr.get_expr_type ()) + { + case CompoundAssignmentOperator::ADD: + op = ArithmeticOrLogicalOperator::ADD; + break; + case CompoundAssignmentOperator::SUBTRACT: + op = ArithmeticOrLogicalOperator::SUBTRACT; + break; + case CompoundAssignmentOperator::MULTIPLY: + op = ArithmeticOrLogicalOperator::MULTIPLY; + break; + case CompoundAssignmentOperator::DIVIDE: + op = ArithmeticOrLogicalOperator::DIVIDE; + break; + case CompoundAssignmentOperator::MODULUS: + op = ArithmeticOrLogicalOperator::MODULUS; + break; + case CompoundAssignmentOperator::BITWISE_AND: + op = ArithmeticOrLogicalOperator::BITWISE_AND; + break; + case CompoundAssignmentOperator::BITWISE_OR: + op = ArithmeticOrLogicalOperator::BITWISE_OR; + break; + case CompoundAssignmentOperator::BITWISE_XOR: + op = ArithmeticOrLogicalOperator::BITWISE_XOR; + break; + case CompoundAssignmentOperator::LEFT_SHIFT: + op = ArithmeticOrLogicalOperator::LEFT_SHIFT; + break; + case CompoundAssignmentOperator::RIGHT_SHIFT: + op = ArithmeticOrLogicalOperator::RIGHT_SHIFT; + break; + default: + gcc_unreachable (); + } + + HIR::Expr *asignee_expr + = ASTLoweringExpr::translate (expr.get_left_expr ().get ()); + HIR::Expr *value = ASTLoweringExpr::translate (expr.get_right_expr ().get ()); + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + translated = new HIR::CompoundAssignmentExpr ( + mapping, std::unique_ptr (asignee_expr), + std::unique_ptr (value), op, expr.get_locus ()); +} + +void +ASTLoweringExpr::visit (AST::StructExprStruct &struct_expr) +{ + HIR::PathInExpression *path + = ASTLowerPathInExpression::translate (&struct_expr.get_struct_name ()); + HIR::PathInExpression copied_path (*path); + delete path; + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, struct_expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + translated = new HIR::StructExprStruct (mapping, copied_path, + struct_expr.get_inner_attrs (), + struct_expr.get_outer_attrs (), + struct_expr.get_locus ()); +} + +void +ASTLoweringExpr::visit (AST::StructExprStructFields &struct_expr) +{ + // bit of a hack for now + HIR::PathInExpression *path + = ASTLowerPathInExpression::translate (&struct_expr.get_struct_name ()); + HIR::PathInExpression copied_path (*path); + delete path; + + HIR::StructBase *base = nullptr; + if (struct_expr.has_struct_base ()) + { + HIR::Expr *translated_base = ASTLoweringExpr::translate ( + struct_expr.get_struct_base ().get_base_struct ().get ()); + base = new HIR::StructBase (std::unique_ptr (translated_base)); + } + + auto const &in_fields = struct_expr.get_fields (); + std::vector > fields; + for (auto &field : in_fields) + { + HIR::StructExprField *translated + = ASTLowerStructExprField::translate (field.get ()); + fields.push_back (std::unique_ptr (translated)); + } + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, struct_expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + translated + = new HIR::StructExprStructFields (mapping, copied_path, std::move (fields), + struct_expr.get_locus (), base, + struct_expr.get_inner_attrs (), + struct_expr.get_outer_attrs ()); +} + +void +ASTLoweringExpr::visit (AST::GroupedExpr &expr) +{ + HIR::Expr *paren_expr + = ASTLoweringExpr::translate (expr.get_expr_in_parens ().get ()); + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + translated + = new HIR::GroupedExpr (mapping, std::unique_ptr (paren_expr), + expr.get_inner_attrs (), expr.get_outer_attrs (), + expr.get_locus ()); +} + +void +ASTLoweringExpr::visit (AST::FieldAccessExpr &expr) +{ + HIR::Expr *receiver + = ASTLoweringExpr::translate (expr.get_receiver_expr ().get ()); + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + translated + = new HIR::FieldAccessExpr (mapping, std::unique_ptr (receiver), + expr.get_field_name (), expr.get_outer_attrs (), + expr.get_locus ()); +} + +void +ASTLoweringExpr::visit (AST::LoopExpr &expr) +{ + translated = ASTLoweringExprWithBlock::translate (&expr, &terminated); +} + +void +ASTLoweringExpr::visit (AST::WhileLoopExpr &expr) +{ + translated = ASTLoweringExprWithBlock::translate (&expr, &terminated); +} + +void +ASTLoweringExpr::visit (AST::ForLoopExpr &expr) +{ + translated = ASTLoweringExprWithBlock::translate (&expr, &terminated); +} + +void +ASTLoweringExpr::visit (AST::BreakExpr &expr) +{ + HIR::Lifetime break_label = lower_lifetime (expr.get_label ()); + HIR::Expr *break_expr + = expr.has_break_expr () + ? ASTLoweringExpr::translate (expr.get_break_expr ().get ()) + : nullptr; + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + translated + = new HIR::BreakExpr (mapping, expr.get_locus (), std ::move (break_label), + std::unique_ptr (break_expr), + expr.get_outer_attrs ()); +} + +void +ASTLoweringExpr::visit (AST::ContinueExpr &expr) +{ + HIR::Lifetime break_label = lower_lifetime (expr.get_label ()); + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + translated + = new HIR::ContinueExpr (mapping, expr.get_locus (), + std ::move (break_label), expr.get_outer_attrs ()); +} + +void +ASTLoweringExpr::visit (AST::BorrowExpr &expr) +{ + HIR::Expr *borrow_lvalue + = ASTLoweringExpr::translate (expr.get_borrowed_expr ().get ()); + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + HIR::BorrowExpr *borrow_expr + = new HIR::BorrowExpr (mapping, std::unique_ptr (borrow_lvalue), + expr.get_is_mut () ? Mutability::Mut + : Mutability::Imm, + expr.get_outer_attrs (), expr.get_locus ()); + + if (expr.get_is_double_borrow ()) + { + NodeId artifical_bouble_borrow_id = mappings->get_next_node_id (); + Analysis::NodeMapping mapping (crate_num, artifical_bouble_borrow_id, + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + borrow_expr + = new HIR::BorrowExpr (mapping, + std::unique_ptr (borrow_expr), + expr.get_is_mut () ? Mutability::Mut + : Mutability::Imm, + expr.get_outer_attrs (), expr.get_locus ()); + } + + translated = borrow_expr; +} + +void +ASTLoweringExpr::visit (AST::DereferenceExpr &expr) +{ + HIR::Expr *dref_lvalue + = ASTLoweringExpr::translate (expr.get_dereferenced_expr ().get ()); + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + translated + = new HIR::DereferenceExpr (mapping, + std::unique_ptr (dref_lvalue), + expr.get_outer_attrs (), expr.get_locus ()); +} + +void +ASTLoweringExpr::visit (AST::MatchExpr &expr) +{ + translated = ASTLoweringExprWithBlock::translate (&expr, &terminated); +} + +void +ASTLoweringExpr::visit (AST::RangeFromToExpr &expr) +{ + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + HIR::Expr *range_from + = ASTLoweringExpr::translate (expr.get_from_expr ().get ()); + HIR::Expr *range_to = ASTLoweringExpr::translate (expr.get_to_expr ().get ()); + + translated + = new HIR::RangeFromToExpr (mapping, + std::unique_ptr (range_from), + std::unique_ptr (range_to), + expr.get_locus ()); +} + +void +ASTLoweringExpr::visit (AST::RangeFromExpr &expr) +{ + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + HIR::Expr *range_from + = ASTLoweringExpr::translate (expr.get_from_expr ().get ()); + + translated + = new HIR::RangeFromExpr (mapping, std::unique_ptr (range_from), + expr.get_locus ()); +} + +void +ASTLoweringExpr::visit (AST::RangeToExpr &expr) +{ + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + HIR::Expr *range_to = ASTLoweringExpr::translate (expr.get_to_expr ().get ()); + + translated + = new HIR::RangeToExpr (mapping, std::unique_ptr (range_to), + expr.get_locus ()); +} + +void +ASTLoweringExpr::visit (AST::RangeFullExpr &expr) +{ + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + translated = new HIR::RangeFullExpr (mapping, expr.get_locus ()); +} + +void +ASTLoweringExpr::visit (AST::RangeFromToInclExpr &expr) +{ + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + HIR::Expr *range_from + = ASTLoweringExpr::translate (expr.get_from_expr ().get ()); + HIR::Expr *range_to = ASTLoweringExpr::translate (expr.get_to_expr ().get ()); + + translated + = new HIR::RangeFromToInclExpr (mapping, + std::unique_ptr (range_from), + std::unique_ptr (range_to), + expr.get_locus ()); +} + +void +ASTLoweringExpr::visit (AST::ClosureExprInner &expr) +{ + HIR::Expr *closure_expr + = ASTLoweringExpr::translate (expr.get_definition_expr ().get ()); + + std::vector closure_params; + for (auto ¶m : expr.get_params ()) + { + HIR::ClosureParam p = lower_closure_param (param); + closure_params.push_back (std::move (p)); + } + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + mappings->get_next_localdef_id (crate_num)); + + translated + = new HIR::ClosureExpr (mapping, std::move (closure_params), + nullptr /* closure_return_type */, + std::unique_ptr (closure_expr), + expr.get_has_move (), expr.get_outer_attrs (), + expr.get_locus ()); +} + +void +ASTLoweringExpr::visit (AST::ClosureExprInnerTyped &expr) +{ + HIR::Type *closure_return_type = nullptr; + HIR::Expr *closure_expr + = ASTLoweringExpr::translate (expr.get_definition_block ().get ()); + + std::vector closure_params; + for (auto ¶m : expr.get_params ()) + { + HIR::ClosureParam p = lower_closure_param (param); + closure_params.push_back (std::move (p)); + } + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings->get_next_hir_id (crate_num), + mappings->get_next_localdef_id (crate_num)); + + translated + = new HIR::ClosureExpr (mapping, std::move (closure_params), + std::unique_ptr (closure_return_type), + std::unique_ptr (closure_expr), + expr.get_has_move (), expr.get_outer_attrs (), + expr.get_locus ()); +} + +} // namespace HIR +} // namespace Rust diff --git a/gcc/rust/hir/rust-ast-lower-expr.h b/gcc/rust/hir/rust-ast-lower-expr.h index b0ab409646d..bea254de79d 100644 --- a/gcc/rust/hir/rust-ast-lower-expr.h +++ b/gcc/rust/hir/rust-ast-lower-expr.h @@ -19,11 +19,7 @@ #ifndef RUST_AST_LOWER_EXPR #define RUST_AST_LOWER_EXPR -#include "rust-diagnostics.h" #include "rust-ast-lower-base.h" -#include "rust-ast-lower-block.h" -#include "rust-ast-lower-struct-field-expr.h" -#include "rust-ast-lower-pattern.h" namespace Rust { namespace HIR { @@ -76,703 +72,55 @@ class ASTLoweringExpr : public ASTLoweringBase using Rust::HIR::ASTLoweringBase::visit; public: - static HIR::Expr *translate (AST::Expr *expr, bool *terminated = nullptr) - { - ASTLoweringExpr resolver; - expr->accept_vis (resolver); - if (resolver.translated == nullptr) - { - rust_fatal_error (expr->get_locus (), "Failed to lower expr: [%s]", - expr->as_string ().c_str ()); - return nullptr; - } - - resolver.mappings->insert_hir_expr (resolver.translated); - resolver.mappings->insert_location ( - resolver.translated->get_mappings ().get_hirid (), expr->get_locus ()); - - if (terminated != nullptr) - *terminated = resolver.terminated; - - return resolver.translated; - } - - void visit (AST::TupleIndexExpr &expr) override - { - HIR::Expr *tuple_expr - = ASTLoweringExpr::translate (expr.get_tuple_expr ().get (), &terminated); - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - translated - = new HIR::TupleIndexExpr (mapping, - std::unique_ptr (tuple_expr), - expr.get_tuple_index (), - expr.get_outer_attrs (), expr.get_locus ()); - } - - void visit (AST::TupleExpr &expr) override - { - std::vector > tuple_elements; - for (auto &e : expr.get_tuple_elems ()) - { - HIR::Expr *t = ASTLoweringExpr::translate (e.get ()); - tuple_elements.push_back (std::unique_ptr (t)); - } - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - translated - = new HIR::TupleExpr (std::move (mapping), std::move (tuple_elements), - expr.get_inner_attrs (), expr.get_outer_attrs (), - expr.get_locus ()); - } - - void visit (AST::IfExpr &expr) override - { - translated = ASTLoweringIfBlock::translate (&expr, &terminated); - } - - void visit (AST::IfExprConseqElse &expr) override - { - translated = ASTLoweringIfBlock::translate (&expr, &terminated); - } - - void visit (AST::IfExprConseqIf &expr) override - { - translated = ASTLoweringIfBlock::translate (&expr, &terminated); - } - - void visit (AST::BlockExpr &expr) override - { - translated = ASTLoweringBlock::translate (&expr, &terminated); - } - - void visit (AST::UnsafeBlockExpr &expr) override - { - translated = ASTLoweringBlock::translate (&expr, &terminated); - } - - void visit (AST::PathInExpression &expr) override - { - translated = ASTLowerPathInExpression::translate (&expr); - } - - void visit (AST::QualifiedPathInExpression &expr) override - { - translated = ASTLowerQualPathInExpression::translate (&expr); - } - - void visit (AST::ReturnExpr &expr) override - { - terminated = true; - HIR::Expr *return_expr - = expr.has_returned_expr () - ? ASTLoweringExpr::translate (expr.get_returned_expr ().get ()) - : nullptr; - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - translated = new HIR::ReturnExpr (mapping, expr.get_locus (), - std::unique_ptr (return_expr)); - } - - void visit (AST::CallExpr &expr) override - { - HIR::Expr *func - = ASTLoweringExpr::translate (expr.get_function_expr ().get ()); - - auto const &in_params = expr.get_params (); - std::vector > params; - for (auto ¶m : in_params) - { - auto trans = ASTLoweringExpr::translate (param.get ()); - params.push_back (std::unique_ptr (trans)); - } - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping ( - crate_num, UNKNOWN_NODEID /* this can map back to the AST*/, - mappings->get_next_hir_id (crate_num), UNKNOWN_LOCAL_DEFID); - - translated = new HIR::CallExpr (mapping, std::unique_ptr (func), - std::move (params), expr.get_outer_attrs (), - expr.get_locus ()); - } - - void visit (AST::MethodCallExpr &expr) override - { - HIR::PathExprSegment method_path - = lower_path_expr_seg (expr.get_method_name ()); - - HIR::Expr *receiver - = ASTLoweringExpr::translate (expr.get_receiver_expr ().get ()); - - auto const &in_params = expr.get_params (); - std::vector > params; - for (auto ¶m : in_params) - { - auto trans = ASTLoweringExpr::translate (param.get ()); - params.push_back (std::unique_ptr (trans)); - } - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - translated - = new HIR::MethodCallExpr (mapping, std::unique_ptr (receiver), - method_path, std::move (params), - expr.get_outer_attrs (), expr.get_locus ()); - } - - void visit (AST::AssignmentExpr &expr) override - { - HIR::Expr *lhs = ASTLoweringExpr::translate (expr.get_left_expr ().get ()); - HIR::Expr *rhs = ASTLoweringExpr::translate (expr.get_right_expr ().get ()); - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - translated - = new HIR::AssignmentExpr (mapping, std::unique_ptr (lhs), - std::unique_ptr (rhs), - expr.get_locus ()); - } - - void visit (AST::IdentifierExpr &expr) override - { - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping1 (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - Analysis::NodeMapping mapping2 (mapping1); - - HIR::PathIdentSegment ident_seg (expr.get_ident ()); - HIR::PathExprSegment seg (mapping1, ident_seg, expr.get_locus (), - HIR::GenericArgs::create_empty ()); - translated = new HIR::PathInExpression (mapping2, {seg}, expr.get_locus (), - false, expr.get_outer_attrs ()); - } - - void visit (AST::ArrayExpr &expr) override - { - expr.get_array_elems ()->accept_vis (*this); - rust_assert (translated_array_elems != nullptr); - HIR::ArrayElems *elems = translated_array_elems; - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - translated - = new HIR::ArrayExpr (mapping, std::unique_ptr (elems), - expr.get_inner_attrs (), expr.get_outer_attrs (), - expr.get_locus ()); - } - - void visit (AST::ArrayIndexExpr &expr) override - { - HIR::Expr *array_expr - = ASTLoweringExpr::translate (expr.get_array_expr ().get ()); - HIR::Expr *array_index_expr - = ASTLoweringExpr::translate (expr.get_index_expr ().get ()); - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - translated - = new HIR::ArrayIndexExpr (mapping, - std::unique_ptr (array_expr), - std::unique_ptr (array_index_expr), - expr.get_outer_attrs (), expr.get_locus ()); - } - - void visit (AST::ArrayElemsValues &elems) override - { - std::vector > elements; - for (auto &elem : elems.get_values ()) - { - HIR::Expr *translated_elem = ASTLoweringExpr::translate (elem.get ()); - elements.push_back (std::unique_ptr (translated_elem)); - } - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (mappings->get_current_crate (), - elems.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - translated_array_elems - = new HIR::ArrayElemsValues (mapping, std::move (elements)); - } - - void visit (AST::ArrayElemsCopied &elems) override - { - HIR::Expr *element - = ASTLoweringExpr::translate (elems.get_elem_to_copy ().get ()); - HIR::Expr *num_copies - = ASTLoweringExpr::translate (elems.get_num_copies ().get ()); - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (mappings->get_current_crate (), - elems.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - translated_array_elems - = new HIR::ArrayElemsCopied (mapping, - std::unique_ptr (element), - std::unique_ptr (num_copies)); - } - - void visit (AST::LiteralExpr &expr) override - { - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - HIR::Literal l = lower_literal (expr.get_literal ()); - translated - = new HIR::LiteralExpr (mapping, std::move (l), expr.get_locus (), - expr.get_outer_attrs ()); - } - - void visit (AST::ArithmeticOrLogicalExpr &expr) override - { - HIR::Expr *lhs = ASTLoweringExpr::translate (expr.get_left_expr ().get ()); - rust_assert (lhs != nullptr); - HIR::Expr *rhs = ASTLoweringExpr::translate (expr.get_right_expr ().get ()); - rust_assert (rhs != nullptr); - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - translated - = new HIR::ArithmeticOrLogicalExpr (mapping, - std::unique_ptr (lhs), - std::unique_ptr (rhs), - expr.get_expr_type (), - expr.get_locus ()); - } - - void visit (AST::ComparisonExpr &expr) override - { - HIR::Expr *lhs = ASTLoweringExpr::translate (expr.get_left_expr ().get ()); - rust_assert (lhs != nullptr); - HIR::Expr *rhs = ASTLoweringExpr::translate (expr.get_right_expr ().get ()); - rust_assert (rhs != nullptr); - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - translated - = new HIR::ComparisonExpr (mapping, std::unique_ptr (lhs), - std::unique_ptr (rhs), - expr.get_expr_type (), expr.get_locus ()); - } - - void visit (AST::LazyBooleanExpr &expr) override - { - HIR::Expr *lhs = ASTLoweringExpr::translate (expr.get_left_expr ().get ()); - rust_assert (lhs != nullptr); - HIR::Expr *rhs = ASTLoweringExpr::translate (expr.get_right_expr ().get ()); - rust_assert (rhs != nullptr); - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - translated - = new HIR::LazyBooleanExpr (mapping, std::unique_ptr (lhs), - std::unique_ptr (rhs), - expr.get_expr_type (), expr.get_locus ()); - } - - void visit (AST::NegationExpr &expr) override - { - HIR::Expr *negated_value - = ASTLoweringExpr::translate (expr.get_negated_expr ().get ()); - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - translated - = new HIR::NegationExpr (mapping, - std::unique_ptr (negated_value), - expr.get_expr_type (), expr.get_outer_attrs (), - expr.get_locus ()); - } - - void visit (AST::TypeCastExpr &expr) override - { - HIR::Expr *expr_to_cast_to - = ASTLoweringExpr::translate (expr.get_casted_expr ().get ()); - HIR::Type *type_to_cast_to - = lower_type_no_bounds (expr.get_type_to_cast_to ().get ()); - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - translated - = new HIR::TypeCastExpr (mapping, - std::unique_ptr (expr_to_cast_to), - std::unique_ptr (type_to_cast_to), - expr.get_locus ()); - } - - void visit (AST::CompoundAssignmentExpr &expr) override - { - ArithmeticOrLogicalOperator op; - switch (expr.get_expr_type ()) - { - case CompoundAssignmentOperator::ADD: - op = ArithmeticOrLogicalOperator::ADD; - break; - case CompoundAssignmentOperator::SUBTRACT: - op = ArithmeticOrLogicalOperator::SUBTRACT; - break; - case CompoundAssignmentOperator::MULTIPLY: - op = ArithmeticOrLogicalOperator::MULTIPLY; - break; - case CompoundAssignmentOperator::DIVIDE: - op = ArithmeticOrLogicalOperator::DIVIDE; - break; - case CompoundAssignmentOperator::MODULUS: - op = ArithmeticOrLogicalOperator::MODULUS; - break; - case CompoundAssignmentOperator::BITWISE_AND: - op = ArithmeticOrLogicalOperator::BITWISE_AND; - break; - case CompoundAssignmentOperator::BITWISE_OR: - op = ArithmeticOrLogicalOperator::BITWISE_OR; - break; - case CompoundAssignmentOperator::BITWISE_XOR: - op = ArithmeticOrLogicalOperator::BITWISE_XOR; - break; - case CompoundAssignmentOperator::LEFT_SHIFT: - op = ArithmeticOrLogicalOperator::LEFT_SHIFT; - break; - case CompoundAssignmentOperator::RIGHT_SHIFT: - op = ArithmeticOrLogicalOperator::RIGHT_SHIFT; - break; - default: - gcc_unreachable (); - } - - HIR::Expr *asignee_expr - = ASTLoweringExpr::translate (expr.get_left_expr ().get ()); - HIR::Expr *value - = ASTLoweringExpr::translate (expr.get_right_expr ().get ()); - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - translated = new HIR::CompoundAssignmentExpr ( - mapping, std::unique_ptr (asignee_expr), - std::unique_ptr (value), op, expr.get_locus ()); - } - - void visit (AST::StructExprStruct &struct_expr) override - { - HIR::PathInExpression *path - = ASTLowerPathInExpression::translate (&struct_expr.get_struct_name ()); - HIR::PathInExpression copied_path (*path); - delete path; - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, struct_expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - translated = new HIR::StructExprStruct (mapping, copied_path, - struct_expr.get_inner_attrs (), - struct_expr.get_outer_attrs (), - struct_expr.get_locus ()); - } - - void visit (AST::StructExprStructFields &struct_expr) override - { - // bit of a hack for now - HIR::PathInExpression *path - = ASTLowerPathInExpression::translate (&struct_expr.get_struct_name ()); - HIR::PathInExpression copied_path (*path); - delete path; - - HIR::StructBase *base = nullptr; - if (struct_expr.has_struct_base ()) - { - HIR::Expr *translated_base = ASTLoweringExpr::translate ( - struct_expr.get_struct_base ().get_base_struct ().get ()); - base - = new HIR::StructBase (std::unique_ptr (translated_base)); - } - - auto const &in_fields = struct_expr.get_fields (); - std::vector > fields; - for (auto &field : in_fields) - { - HIR::StructExprField *translated - = ASTLowerStructExprField::translate (field.get ()); - fields.push_back (std::unique_ptr (translated)); - } - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, struct_expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - translated = new HIR::StructExprStructFields ( - mapping, copied_path, std::move (fields), struct_expr.get_locus (), base, - struct_expr.get_inner_attrs (), struct_expr.get_outer_attrs ()); - } - - void visit (AST::GroupedExpr &expr) override - { - HIR::Expr *paren_expr - = ASTLoweringExpr::translate (expr.get_expr_in_parens ().get ()); - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - translated - = new HIR::GroupedExpr (mapping, std::unique_ptr (paren_expr), - expr.get_inner_attrs (), expr.get_outer_attrs (), - expr.get_locus ()); - } - - void visit (AST::FieldAccessExpr &expr) override - { - HIR::Expr *receiver - = ASTLoweringExpr::translate (expr.get_receiver_expr ().get ()); - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - translated - = new HIR::FieldAccessExpr (mapping, - std::unique_ptr (receiver), - expr.get_field_name (), - expr.get_outer_attrs (), expr.get_locus ()); - } - - void visit (AST::LoopExpr &expr) override - { - translated = ASTLoweringExprWithBlock::translate (&expr, &terminated); - } - - void visit (AST::WhileLoopExpr &expr) override - { - translated = ASTLoweringExprWithBlock::translate (&expr, &terminated); - } - - void visit (AST::ForLoopExpr &expr) override - { - translated = ASTLoweringExprWithBlock::translate (&expr, &terminated); - } - - void visit (AST::BreakExpr &expr) override - { - HIR::Lifetime break_label = lower_lifetime (expr.get_label ()); - HIR::Expr *break_expr - = expr.has_break_expr () - ? ASTLoweringExpr::translate (expr.get_break_expr ().get ()) - : nullptr; - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - translated = new HIR::BreakExpr (mapping, expr.get_locus (), - std ::move (break_label), - std::unique_ptr (break_expr), - expr.get_outer_attrs ()); - } - - void visit (AST::ContinueExpr &expr) override - { - HIR::Lifetime break_label = lower_lifetime (expr.get_label ()); - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - translated = new HIR::ContinueExpr (mapping, expr.get_locus (), - std ::move (break_label), - expr.get_outer_attrs ()); - } - - void visit (AST::BorrowExpr &expr) override - { - HIR::Expr *borrow_lvalue - = ASTLoweringExpr::translate (expr.get_borrowed_expr ().get ()); - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - HIR::BorrowExpr *borrow_expr - = new HIR::BorrowExpr (mapping, - std::unique_ptr (borrow_lvalue), - expr.get_is_mut () ? Mutability::Mut - : Mutability::Imm, - expr.get_outer_attrs (), expr.get_locus ()); - - if (expr.get_is_double_borrow ()) - { - NodeId artifical_bouble_borrow_id = mappings->get_next_node_id (); - Analysis::NodeMapping mapping (crate_num, artifical_bouble_borrow_id, - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - borrow_expr - = new HIR::BorrowExpr (mapping, - std::unique_ptr (borrow_expr), - expr.get_is_mut () ? Mutability::Mut - : Mutability::Imm, - expr.get_outer_attrs (), expr.get_locus ()); - } - - translated = borrow_expr; - } - - void visit (AST::DereferenceExpr &expr) override - { - HIR::Expr *dref_lvalue - = ASTLoweringExpr::translate (expr.get_dereferenced_expr ().get ()); - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - translated - = new HIR::DereferenceExpr (mapping, - std::unique_ptr (dref_lvalue), - expr.get_outer_attrs (), expr.get_locus ()); - } - - void visit (AST::MatchExpr &expr) override - { - translated = ASTLoweringExprWithBlock::translate (&expr, &terminated); - } - - void visit (AST::RangeFromToExpr &expr) override - { - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - HIR::Expr *range_from - = ASTLoweringExpr::translate (expr.get_from_expr ().get ()); - HIR::Expr *range_to - = ASTLoweringExpr::translate (expr.get_to_expr ().get ()); - - translated - = new HIR::RangeFromToExpr (mapping, - std::unique_ptr (range_from), - std::unique_ptr (range_to), - expr.get_locus ()); - } - - void visit (AST::RangeFromExpr &expr) override - { - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - HIR::Expr *range_from - = ASTLoweringExpr::translate (expr.get_from_expr ().get ()); - - translated - = new HIR::RangeFromExpr (mapping, - std::unique_ptr (range_from), - expr.get_locus ()); - } - - void visit (AST::RangeToExpr &expr) override - { - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - HIR::Expr *range_to - = ASTLoweringExpr::translate (expr.get_to_expr ().get ()); - - translated - = new HIR::RangeToExpr (mapping, std::unique_ptr (range_to), - expr.get_locus ()); - } - - void visit (AST::RangeFullExpr &expr) override - { - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - translated = new HIR::RangeFullExpr (mapping, expr.get_locus ()); - } - - void visit (AST::RangeFromToInclExpr &expr) override - { - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - HIR::Expr *range_from - = ASTLoweringExpr::translate (expr.get_from_expr ().get ()); - HIR::Expr *range_to - = ASTLoweringExpr::translate (expr.get_to_expr ().get ()); - - translated - = new HIR::RangeFromToInclExpr (mapping, - std::unique_ptr (range_from), - std::unique_ptr (range_to), - expr.get_locus ()); - } + static HIR::Expr *translate (AST::Expr *expr, bool *terminated = nullptr); + + void visit (AST::TupleIndexExpr &expr) override; + void visit (AST::TupleExpr &expr) override; + void visit (AST::IfExpr &expr) override; + void visit (AST::IfExprConseqElse &expr) override; + void visit (AST::IfExprConseqIf &expr) override; + void visit (AST::BlockExpr &expr) override; + void visit (AST::UnsafeBlockExpr &expr) override; + void visit (AST::PathInExpression &expr) override; + void visit (AST::QualifiedPathInExpression &expr) override; + void visit (AST::ReturnExpr &expr) override; + void visit (AST::CallExpr &expr) override; + void visit (AST::MethodCallExpr &expr) override; + void visit (AST::AssignmentExpr &expr) override; + void visit (AST::IdentifierExpr &expr) override; + void visit (AST::ArrayExpr &expr) override; + void visit (AST::ArrayIndexExpr &expr) override; + void visit (AST::ArrayElemsValues &elems) override; + void visit (AST::ArrayElemsCopied &elems) override; + void visit (AST::LiteralExpr &expr) override; + void visit (AST::ArithmeticOrLogicalExpr &expr) override; + void visit (AST::ComparisonExpr &expr) override; + void visit (AST::LazyBooleanExpr &expr) override; + void visit (AST::NegationExpr &expr) override; + void visit (AST::TypeCastExpr &expr) override; + void visit (AST::CompoundAssignmentExpr &expr) override; + void visit (AST::StructExprStruct &struct_expr) override; + void visit (AST::StructExprStructFields &struct_expr) override; + void visit (AST::GroupedExpr &expr) override; + void visit (AST::FieldAccessExpr &expr) override; + void visit (AST::LoopExpr &expr) override; + void visit (AST::WhileLoopExpr &expr) override; + void visit (AST::ForLoopExpr &expr) override; + void visit (AST::BreakExpr &expr) override; + void visit (AST::ContinueExpr &expr) override; + void visit (AST::BorrowExpr &expr) override; + void visit (AST::DereferenceExpr &expr) override; + void visit (AST::MatchExpr &expr) override; + void visit (AST::RangeFromToExpr &expr) override; + void visit (AST::RangeFromExpr &expr) override; + void visit (AST::RangeToExpr &expr) override; + void visit (AST::RangeFullExpr &expr) override; + void visit (AST::RangeFromToInclExpr &expr) override; + void visit (AST::ClosureExprInner &expr) override; + void visit (AST::ClosureExprInnerTyped &expr) override; private: - ASTLoweringExpr () - : ASTLoweringBase (), translated (nullptr), - translated_array_elems (nullptr), terminated (false) - {} + ASTLoweringExpr (); HIR::Expr *translated; HIR::ArrayElems *translated_array_elems; diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc index 4f1bfd1f0c1..fdf8abe3ed3 100644 --- a/gcc/rust/hir/rust-ast-lower.cc +++ b/gcc/rust/hir/rust-ast-lower.cc @@ -22,9 +22,12 @@ #include "rust-ast-lower-expr.h" #include "rust-ast-lower-block.h" #include "rust-ast-lower-type.h" +#include "rust-ast-lower-pattern.h" +#include "rust-ast-lower-struct-field-expr.h" namespace Rust { namespace HIR { +using HIR::ClosureParam; Visibility translate_visibility (const AST::Visibility &vis) @@ -473,5 +476,25 @@ ASTLowerQualPathInExpression::visit (AST::QualifiedPathInExpression &expr) expr.get_locus (), expr.get_outer_attrs ()); } + +ClosureParam +ASTLoweringBase::lower_closure_param (AST::ClosureParam ¶m) +{ + HIR::Pattern *param_pattern + = ASTLoweringPattern::translate (param.get_pattern ().get ()); + + HIR::Type *param_type + = param.has_type_given () + ? ASTLoweringType::translate (param.get_type ().get ()) + : nullptr; + + return HIR::ClosureParam (std::unique_ptr (param_pattern), + param.get_locus (), + param.has_type_given () + ? std::unique_ptr (param_type) + : nullptr, + param.get_outer_attrs ()); +} + } // namespace HIR } // namespace Rust diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc index 6bbd7ef3a7f..261a36daa05 100644 --- a/gcc/rust/hir/rust-hir-dump.cc +++ b/gcc/rust/hir/rust-hir-dump.cc @@ -197,7 +197,7 @@ void Dump::visit (FieldAccessExpr &) {} void -Dump::visit (ClosureExprInner &) +Dump::visit (ClosureExpr &) {} void Dump::visit (BlockExpr &block_expr) @@ -212,9 +212,7 @@ Dump::visit (BlockExpr &block_expr) stream << "]"; indent--; } -void -Dump::visit (ClosureExprInnerTyped &) -{} + void Dump::visit (ContinueExpr &) {} diff --git a/gcc/rust/hir/rust-hir-dump.h b/gcc/rust/hir/rust-hir-dump.h index ead8d774b03..8715a95ada8 100644 --- a/gcc/rust/hir/rust-hir-dump.h +++ b/gcc/rust/hir/rust-hir-dump.h @@ -78,9 +78,8 @@ private: virtual void visit (CallExpr &) override; virtual void visit (MethodCallExpr &) override; virtual void visit (FieldAccessExpr &) override; - virtual void visit (ClosureExprInner &) override; + virtual void visit (ClosureExpr &) override; virtual void visit (BlockExpr &) override; - virtual void visit (ClosureExprInnerTyped &) override; virtual void visit (ContinueExpr &) override; virtual void visit (BreakExpr &) override; virtual void visit (RangeFromToExpr &) override; diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h index 564d5215724..4c5caf17ac3 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -1985,21 +1985,22 @@ protected: struct ClosureParam { private: + std::vector outer_attrs; std::unique_ptr pattern; - - // bool has_type_given; std::unique_ptr type; - - // TODO: should this store location data? + Location locus; public: // Returns whether the type of the parameter has been given. bool has_type_given () const { return type != nullptr; } // Constructor for closure parameter - ClosureParam (std::unique_ptr param_pattern, - std::unique_ptr param_type = nullptr) - : pattern (std::move (param_pattern)), type (std::move (param_type)) + ClosureParam (std::unique_ptr param_pattern, Location locus, + std::unique_ptr param_type = nullptr, + std::vector outer_attrs = {}) + : outer_attrs (std::move (outer_attrs)), + pattern (std::move (param_pattern)), type (std::move (param_type)), + locus (locus) {} // Copy constructor required due to cloning as a result of unique_ptrs @@ -2007,6 +2008,8 @@ public: : pattern (other.pattern->clone_pattern ()) { // guard to protect from null pointer dereference + if (other.pattern != nullptr) + pattern = other.pattern->clone_pattern (); if (other.type != nullptr) type = other.type->clone_type (); } @@ -2016,8 +2019,17 @@ public: // Assignment operator must be overloaded to clone as well ClosureParam &operator= (ClosureParam const &other) { - pattern = other.pattern->clone_pattern (); - type = other.type->clone_type (); + outer_attrs = other.outer_attrs; + + // guard to protect from null pointer dereference + if (other.pattern != nullptr) + pattern = other.pattern->clone_pattern (); + else + pattern = nullptr; + if (other.type != nullptr) + type = other.type->clone_type (); + else + type = nullptr; return *this; } @@ -2026,31 +2038,79 @@ public: ClosureParam (ClosureParam &&other) = default; ClosureParam &operator= (ClosureParam &&other) = default; - // Returns whether closure parameter is in an error state. - bool is_error () const { return pattern == nullptr; } + std::string as_string () const; - // Creates an error state closure parameter. - static ClosureParam create_error () { return ClosureParam (nullptr); } + const std::vector &get_outer_attrs () const + { + return outer_attrs; + } + std::vector &get_outer_attrs () { return outer_attrs; } - std::string as_string () const; + std::unique_ptr &get_pattern () + { + rust_assert (pattern != nullptr); + return pattern; + } + + std::unique_ptr &get_type () + { + rust_assert (has_type_given ()); + return type; + } + + Location get_locus () const { return locus; } }; // Base closure definition expression HIR node - abstract class ClosureExpr : public ExprWithoutBlock { +private: bool has_move; std::vector params; Location locus; + std::unique_ptr return_type; + std::unique_ptr expr; -protected: +public: ClosureExpr (Analysis::NodeMapping mappings, - std::vector closure_params, bool has_move, + std::vector closure_params, + std::unique_ptr closure_return_type, + std::unique_ptr closure_expr, bool has_move, AST::AttrVec outer_attribs, Location locus) : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)), - has_move (has_move), params (std::move (closure_params)), locus (locus) + has_move (has_move), params (std::move (closure_params)), locus (locus), + return_type (std::move (closure_return_type)), + expr (std::move (closure_expr)) {} -public: + // Copy constructor requires cloning + ClosureExpr (ClosureExpr const &other) + : ExprWithoutBlock (other.get_mappings (), other.get_outer_attrs ()) + { + return_type + = other.has_return_type () ? other.return_type->clone_type () : nullptr; + expr = other.expr->clone_expr (); + params = other.params; + has_move = other.has_move; + } + + // Overload assignment operator to clone unique_ptrs + ClosureExpr &operator= (ClosureExpr const &other) + { + mappings = other.mappings; + return_type + = other.has_return_type () ? other.return_type->clone_type () : nullptr; + expr = other.expr->clone_expr (); + params = other.params; + has_move = other.has_move; + + return *this; + } + + // move constructors + ClosureExpr (ClosureExpr &&other) = default; + ClosureExpr &operator= (ClosureExpr &&other) = default; + std::string as_string () const override; Location get_locus () const override final { return locus; } @@ -2059,47 +2119,17 @@ public: { return ExprType::Closure; } -}; -// Represents a non-type-specified closure expression HIR node -class ClosureExprInner : public ClosureExpr -{ - std::unique_ptr closure_inner; + bool get_has_move () const { return has_move; } -public: - std::string as_string () const override; + bool has_return_type () const { return return_type != nullptr; } - // Constructor for a ClosureExprInner - ClosureExprInner (Analysis::NodeMapping mappings, - std::unique_ptr closure_inner_expr, - std::vector closure_params, Location locus, - bool is_move = false, - AST::AttrVec outer_attribs = AST::AttrVec ()) - : ClosureExpr (std::move (mappings), std::move (closure_params), is_move, - std::move (outer_attribs), locus), - closure_inner (std::move (closure_inner_expr)) - {} - - // Copy constructor must be defined to allow copying via cloning of unique_ptr - ClosureExprInner (ClosureExprInner const &other) - : ClosureExpr (other), closure_inner (other.closure_inner->clone_expr ()) - {} - - // Overload assignment operator to clone closure_inner - ClosureExprInner &operator= (ClosureExprInner const &other) + std::unique_ptr &get_return_type () { - ClosureExpr::operator= (other); - closure_inner = other.closure_inner->clone_expr (); - // params = other.params; - // has_move = other.has_move; - // outer_attrs = other.outer_attrs; - - return *this; - } - - // move constructors - ClosureExprInner (ClosureExprInner &&other) = default; - ClosureExprInner &operator= (ClosureExprInner &&other) = default; + rust_assert (has_return_type ()); + return return_type; + }; + std::unique_ptr &get_expr () { return expr; } void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; @@ -2107,16 +2137,16 @@ public: protected: /* Use covariance to implement clone function as returning this object rather * than base */ - ClosureExprInner *clone_expr_impl () const override + ClosureExpr *clone_expr_impl () const override { - return new ClosureExprInner (*this); + return new ClosureExpr (*this); } /* Use covariance to implement clone function as returning this object rather * than base */ - ClosureExprInner *clone_expr_without_block_impl () const override + ClosureExpr *clone_expr_without_block_impl () const override { - return new ClosureExprInner (*this); + return new ClosureExpr (*this); } }; @@ -2239,71 +2269,6 @@ protected: } }; -// Represents a type-specified closure expression HIR node -class ClosureExprInnerTyped : public ClosureExpr -{ - std::unique_ptr return_type; - std::unique_ptr - expr; // only used because may be polymorphic in future - -public: - std::string as_string () const override; - - // Constructor potentially with a move - ClosureExprInnerTyped (Analysis::NodeMapping mappings, - std::unique_ptr closure_return_type, - std::unique_ptr closure_expr, - std::vector closure_params, - Location locus, bool is_move = false, - AST::AttrVec outer_attribs = AST::AttrVec ()) - : ClosureExpr (std::move (mappings), std::move (closure_params), is_move, - std::move (outer_attribs), locus), - return_type (std::move (closure_return_type)), - expr (std::move (closure_expr)) - {} - - // Copy constructor requires cloning - ClosureExprInnerTyped (ClosureExprInnerTyped const &other) - : ClosureExpr (other), return_type (other.return_type->clone_type ()), - expr (other.expr->clone_block_expr ()) - {} - - // Overload assignment operator to clone unique_ptrs - ClosureExprInnerTyped &operator= (ClosureExprInnerTyped const &other) - { - ClosureExpr::operator= (other); - return_type = other.return_type->clone_type (); - expr = other.expr->clone_block_expr (); - // params = other.params; - // has_move = other.has_move; - // outer_attrs = other.outer_attrs; - - return *this; - } - - // move constructors - ClosureExprInnerTyped (ClosureExprInnerTyped &&other) = default; - ClosureExprInnerTyped &operator= (ClosureExprInnerTyped &&other) = default; - - void accept_vis (HIRFullVisitor &vis) override; - void accept_vis (HIRExpressionVisitor &vis) override; - -protected: - /* Use covariance to implement clone function as returning this object rather - * than base */ - ClosureExprInnerTyped *clone_expr_impl () const override - { - return new ClosureExprInnerTyped (*this); - } - - /* Use covariance to implement clone function as returning this object rather - * than base */ - ClosureExprInnerTyped *clone_expr_without_block_impl () const override - { - return new ClosureExprInnerTyped (*this); - } -}; - // HIR node representing continue expression within loops class ContinueExpr : public ExprWithoutBlock { diff --git a/gcc/rust/hir/tree/rust-hir-full-decls.h b/gcc/rust/hir/tree/rust-hir-full-decls.h index 3cb3ffeecee..70ee7538298 100644 --- a/gcc/rust/hir/tree/rust-hir-full-decls.h +++ b/gcc/rust/hir/tree/rust-hir-full-decls.h @@ -94,9 +94,7 @@ class MethodCallExpr; class FieldAccessExpr; struct ClosureParam; class ClosureExpr; -class ClosureExprInner; class BlockExpr; -class ClosureExprInnerTyped; class ContinueExpr; class BreakExpr; class RangeExpr; diff --git a/gcc/rust/hir/tree/rust-hir-full-test.cc b/gcc/rust/hir/tree/rust-hir-full-test.cc index 48af16a45e6..f6e27b9a35f 100644 --- a/gcc/rust/hir/tree/rust-hir-full-test.cc +++ b/gcc/rust/hir/tree/rust-hir-full-test.cc @@ -1133,15 +1133,8 @@ ClosureExpr::as_string () const } } - return str; -} - -std::string -ClosureExprInnerTyped::as_string () const -{ - std::string str = ClosureExpr::as_string (); - - str += "\n Return type: " + return_type->as_string (); + str += "\n Return type: " + + (has_return_type () ? return_type->as_string () : "none"); str += "\n Body: " + expr->as_string (); @@ -1515,16 +1508,6 @@ UnsafeBlockExpr::as_string () const return str + "\n" + indent_spaces (out) + "}\n" + expr->as_string (); } -std::string -ClosureExprInner::as_string () const -{ - std::string str = ClosureExpr::as_string (); - - str += "\n Expression: " + closure_inner->as_string (); - - return str; -} - std::string IfExpr::as_string () const { @@ -4038,7 +4021,7 @@ FieldAccessExpr::accept_vis (HIRFullVisitor &vis) } void -ClosureExprInner::accept_vis (HIRFullVisitor &vis) +ClosureExpr::accept_vis (HIRFullVisitor &vis) { vis.visit (*this); } @@ -4049,12 +4032,6 @@ BlockExpr::accept_vis (HIRFullVisitor &vis) vis.visit (*this); } -void -ClosureExprInnerTyped::accept_vis (HIRFullVisitor &vis) -{ - vis.visit (*this); -} - void ContinueExpr::accept_vis (HIRFullVisitor &vis) { @@ -4986,7 +4963,7 @@ IfExpr::accept_vis (HIRExpressionVisitor &vis) } void -ClosureExprInner::accept_vis (HIRExpressionVisitor &vis) +ClosureExpr::accept_vis (HIRExpressionVisitor &vis) { vis.visit (*this); } @@ -5075,12 +5052,6 @@ QualifiedPathInExpression::accept_vis (HIRPatternVisitor &vis) vis.visit (*this); } -void -ClosureExprInnerTyped::accept_vis (HIRExpressionVisitor &vis) -{ - vis.visit (*this); -} - void ExprStmtWithBlock::accept_vis (HIRStmtVisitor &vis) { diff --git a/gcc/rust/hir/tree/rust-hir-visitor.h b/gcc/rust/hir/tree/rust-hir-visitor.h index 187f0794ac1..ba6cad7614b 100644 --- a/gcc/rust/hir/tree/rust-hir-visitor.h +++ b/gcc/rust/hir/tree/rust-hir-visitor.h @@ -63,9 +63,8 @@ public: virtual void visit (CallExpr &expr) = 0; virtual void visit (MethodCallExpr &expr) = 0; virtual void visit (FieldAccessExpr &expr) = 0; - virtual void visit (ClosureExprInner &expr) = 0; virtual void visit (BlockExpr &expr) = 0; - virtual void visit (ClosureExprInnerTyped &expr) = 0; + virtual void visit (ClosureExpr &expr) = 0; virtual void visit (ContinueExpr &expr) = 0; virtual void visit (BreakExpr &expr) = 0; virtual void visit (RangeFromToExpr &expr) = 0; @@ -206,9 +205,8 @@ public: virtual void visit (CallExpr &) override {} virtual void visit (MethodCallExpr &) override {} virtual void visit (FieldAccessExpr &) override {} - virtual void visit (ClosureExprInner &) override {} + virtual void visit (ClosureExpr &) override {} virtual void visit (BlockExpr &) override {} - virtual void visit (ClosureExprInnerTyped &) override {} virtual void visit (ContinueExpr &) override {} virtual void visit (BreakExpr &) override {} virtual void visit (RangeFromToExpr &) override {} @@ -419,8 +417,7 @@ public: virtual void visit (HIR::QualifiedPathInExpression &expr) = 0; virtual void visit (HIR::PathInExpression &expr) = 0; - virtual void visit (ClosureExprInnerTyped &) = 0; - virtual void visit (ClosureExprInner &expr) = 0; + virtual void visit (ClosureExpr &) = 0; virtual void visit (StructExprStructFields &) = 0; virtual void visit (StructExprStruct &) = 0; virtual void visit (LiteralExpr &expr) = 0; diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h index aa305f1590c..314aafb32d3 100644 --- a/gcc/rust/hir/tree/rust-hir.h +++ b/gcc/rust/hir/tree/rust-hir.h @@ -238,6 +238,7 @@ class ExprWithoutBlock; // Base expression HIR node - abstract class Expr : public Node { +protected: AST::AttrVec outer_attrs; Analysis::NodeMapping mappings; diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc index 4e377d52a0f..6b8c63b77f6 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc @@ -1418,6 +1418,12 @@ TypeCheckExpr::visit (HIR::MatchExpr &expr) } } +void +TypeCheckExpr::visit (HIR::ClosureExpr &expr) +{ + gcc_unreachable (); +} + bool TypeCheckExpr::resolve_operator_overload ( Analysis::RustLangItem::ItemType lang_item_type, HIR::OperatorExprMeta expr, diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h index 8a37512ec6e..7f787fa9766 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.h +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h @@ -69,10 +69,9 @@ public: void visit (HIR::RangeFullExpr &expr) override; void visit (HIR::RangeFromToInclExpr &expr) override; void visit (HIR::WhileLoopExpr &expr) override; + void visit (HIR::ClosureExpr &expr) override; // TODO - void visit (HIR::ClosureExprInnerTyped &) override {} - void visit (HIR::ClosureExprInner &expr) override {} void visit (HIR::ErrorPropagationExpr &expr) override {} void visit (HIR::RangeToInclExpr &expr) override {} void visit (HIR::WhileLetLoopExpr &expr) override {} From patchwork Tue Feb 21 12:01:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59995 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1833273wrn; Tue, 21 Feb 2023 04:29:01 -0800 (PST) X-Google-Smtp-Source: AK7set8V7PNx2aQZ8pobCsK4aIUu+lodo6GYI6RDezmvWDEWvHF0ok78WgPniHRJsLKUsXjSz+hn X-Received: by 2002:a17:906:1c56:b0:877:ef84:c7de with SMTP id l22-20020a1709061c5600b00877ef84c7demr11553845ejg.61.1676982541125; Tue, 21 Feb 2023 04:29:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982541; cv=none; d=google.com; s=arc-20160816; b=p04XxwZuZAJnbj/NmVEvfrS66VE/t/RcU1bcrGfIEo7g7xr31Mzb9vK54bAbaYh5cv 4IC47Ncdu4LoAX8q0KjRcZaKADEGkXUcFmR5g6VnxGkE8IRMrVqwksmPazGv2iSEy8RK kOGGpUmJVEFuAIXuhchAU9HCbom6eMKCBlwsFhvkcOTH/oddeJWSxQjmk386XDWziMBX LRjqJgi4ax+LyRDxJqF2cgU4kqQDsq8pVjDjIatvjQRWVoKMjmiveQ8nN06W7xafwZG0 GwKuwJKSSnKrSrrDrDPV9IvXPV9Za5qETtCboOCpRDNR2c1u4rkbk9+SXQTA3O77ZKv2 LndA== 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=bfEEoTWgSuf+7mFnFkvC32aMhpMgIXo+rzbgt+hsUio=; b=y91LFamx5yIobuIeu1LU2OWKdABl2KEEEmA2IOpTKvyJiDhdfSWtoRlNd3PWFnq4SS kBxUbY+fvyUaCoBKzCIIne6UC8/tF2dFi21MmerK+B5QVT4oOkiZY2qSVzc1f0jqms94 5h8d/zlYdaNeYaPBkUYc/doTtKvTnArIIrMtVoXdcPJtQeSji3KauHFmZhSNfY0yxfr5 /cDs0E0quVEUYqXD+CvVxyhV7/yEdYmcBIj5CaD0pl3IFTmAyiZukJhst2t8MA1kzndk ZCaBFvCu6R3YkXWKRS+Y26eiPSxTFhI5XaNpK+3GjdsB2Lka5Wxxt2jmE//3BIbbm1cK Bwiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=GxGRrg26; 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 um4-20020a170907cb0400b008b1797df05fsi14294264ejc.391.2023.02.21.04.29.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:29:01 -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=GxGRrg26; 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 0E4F2391F6C8 for ; Tue, 21 Feb 2023 12:11:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id E73AA383E29E for ; Tue, 21 Feb 2023 12:04:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E73AA383E29E 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-x436.google.com with SMTP id c12so4163282wrw.1 for ; Tue, 21 Feb 2023 04:04:00 -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=bfEEoTWgSuf+7mFnFkvC32aMhpMgIXo+rzbgt+hsUio=; b=GxGRrg26BUS2G15Eff0cxlEdujwN08ALk/rmH5YQX9WTj2TYLdSj4YMDn/UzOJs63a 2qDI3axGfvalcUg4ALrvPxDMHpTb5f7ogq65Z0lVP6ScqQgNMxh+eZLNrhR7HrC3q4vO pkN8ol/ZsAQUgfTpUnQUnhOXg1GPlS3Or394ZPbaCCrrJJQI+uXI0dvmBE4YwLHXCRwq /ousIoQBEW+tVFkI6az8A3whCKDWKqVoUjUVpL3a9HS2MTeKxNTgStGOVzgGBEiglzHO Cduj6H4Ro9Bd+DmF/mZfq3ILgRiQoylk5shtba0A/zFrnYovECCQVwKOD6lyTClmQZKV 7cfQ== 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=bfEEoTWgSuf+7mFnFkvC32aMhpMgIXo+rzbgt+hsUio=; b=eH+YTYozoBz58qpNIay6b3/ddUjLOjFe4kG8i7MKnLY0ZV7Qz79Y5HTzFsWlcPGZ6T BAMPRHx5lTgFSASZ4PZgYmyYH7h/DoV3t8exbtd5wFcP++1PxuIDpf8x/Omaa3MPxK/T xtvE8XSGyBdtouB0KPv6VKj5uN320GP+LGEpzp95n0WXjSzVNRBhMPWmD7lmaOfuqpIU /vMG2qUolkhMT9qCcOn2kHowJetDC6JPu/6THY6Bp0jsb6h7ayt3GWfLLdG4Yy9C60Z6 PFcdov5FdmPPSpUV+g/YERKn43MmrkyUUVtO4IC0VxIvqNusLjusiiIKu+Y5eTu8eCfi u7qw== X-Gm-Message-State: AO0yUKXXWfpemKJLYeHhTzyHohKr4b7q9SNf8LGO0fGWSZMJ5uoOA1s0 MPEd1S15Udsp5t6GYZJ179l1SHHSGK/jpfRCrw== X-Received: by 2002:a5d:5306:0:b0:2c5:62c8:5f43 with SMTP id e6-20020a5d5306000000b002c562c85f43mr2205431wrv.29.1676981040168; Tue, 21 Feb 2023 04:04:00 -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.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:59 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 045/103] gccrs: Formatting cleanup in HIR lowering pattern Date: Tue, 21 Feb 2023 13:01:35 +0100 Message-Id: <20230221120230.596966-46-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=ham 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?1758443644764431783?= X-GMAIL-MSGID: =?utf-8?q?1758443644764431783?= From: Philip Herron gcc/rust/ChangeLog: * hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::ASTLoweringPattern): Improve formatting. (ASTLoweringPattern::translate): Likewise. * hir/rust-ast-lower-pattern.h: Likewise. * resolve/rust-ast-resolve-expr.h: Likewise. --- gcc/rust/hir/rust-ast-lower-pattern.cc | 18 ++++++++++ gcc/rust/hir/rust-ast-lower-pattern.h | 24 ++----------- gcc/rust/resolve/rust-ast-resolve-expr.h | 43 ------------------------ 3 files changed, 20 insertions(+), 65 deletions(-) diff --git a/gcc/rust/hir/rust-ast-lower-pattern.cc b/gcc/rust/hir/rust-ast-lower-pattern.cc index 37bee38fd83..30a188286c8 100644 --- a/gcc/rust/hir/rust-ast-lower-pattern.cc +++ b/gcc/rust/hir/rust-ast-lower-pattern.cc @@ -22,6 +22,24 @@ namespace Rust { namespace HIR { +ASTLoweringPattern::ASTLoweringPattern () : translated (nullptr) {} + +HIR::Pattern * +ASTLoweringPattern::translate (AST::Pattern *pattern) +{ + ASTLoweringPattern resolver; + pattern->accept_vis (resolver); + + rust_assert (resolver.translated != nullptr); + + resolver.mappings->insert_hir_pattern (resolver.translated); + resolver.mappings->insert_location ( + resolver.translated->get_pattern_mappings ().get_hirid (), + pattern->get_locus ()); + + return resolver.translated; +} + void ASTLoweringPattern::visit (AST::IdentifierPattern &pattern) { diff --git a/gcc/rust/hir/rust-ast-lower-pattern.h b/gcc/rust/hir/rust-ast-lower-pattern.h index f47699d15ea..8b191d56868 100644 --- a/gcc/rust/hir/rust-ast-lower-pattern.h +++ b/gcc/rust/hir/rust-ast-lower-pattern.h @@ -29,39 +29,19 @@ class ASTLoweringPattern : public ASTLoweringBase using Rust::HIR::ASTLoweringBase::visit; public: - static HIR::Pattern *translate (AST::Pattern *pattern) - { - ASTLoweringPattern resolver; - pattern->accept_vis (resolver); - - rust_assert (resolver.translated != nullptr); - - resolver.mappings->insert_hir_pattern (resolver.translated); - resolver.mappings->insert_location ( - resolver.translated->get_pattern_mappings ().get_hirid (), - pattern->get_locus ()); - - return resolver.translated; - } + static HIR::Pattern *translate (AST::Pattern *pattern); void visit (AST::IdentifierPattern &pattern) override; - void visit (AST::PathInExpression &pattern) override; - void visit (AST::StructPattern &pattern) override; - void visit (AST::TupleStructPattern &pattern) override; - void visit (AST::WildcardPattern &pattern) override; - void visit (AST::TuplePattern &pattern) override; - void visit (AST::LiteralPattern &pattern) override; - void visit (AST::RangePattern &pattern) override; private: - ASTLoweringPattern () : translated (nullptr) {} + ASTLoweringPattern (); HIR::Pattern *translated; }; diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.h b/gcc/rust/resolve/rust-ast-resolve-expr.h index 57beab700d7..60ae1720811 100644 --- a/gcc/rust/resolve/rust-ast-resolve-expr.h +++ b/gcc/rust/resolve/rust-ast-resolve-expr.h @@ -34,89 +34,46 @@ public: const CanonicalPath &canonical_prefix); void visit (AST::TupleIndexExpr &expr) override; - void visit (AST::TupleExpr &expr) override; - void visit (AST::PathInExpression &expr) override; - void visit (AST::QualifiedPathInExpression &expr) override; - void visit (AST::ReturnExpr &expr) override; - void visit (AST::CallExpr &expr) override; - void visit (AST::MethodCallExpr &expr) override; - void visit (AST::AssignmentExpr &expr) override; - void visit (AST::IdentifierExpr &expr) override; - void visit (AST::ArithmeticOrLogicalExpr &expr) override; - void visit (AST::CompoundAssignmentExpr &expr) override; - void visit (AST::ComparisonExpr &expr) override; - void visit (AST::LazyBooleanExpr &expr) override; - void visit (AST::NegationExpr &expr) override; - void visit (AST::TypeCastExpr &expr) override; - void visit (AST::IfExpr &expr) override; - void visit (AST::IfExprConseqElse &expr) override; - void visit (AST::IfExprConseqIf &expr) override; - void visit (AST::IfLetExpr &expr) override; - void visit (AST::BlockExpr &expr) override; - void visit (AST::UnsafeBlockExpr &expr) override; - void visit (AST::ArrayElemsValues &elems) override; - void visit (AST::ArrayExpr &expr) override; - void visit (AST::ArrayIndexExpr &expr) override; - void visit (AST::ArrayElemsCopied &elems) override; - - // this this an empty struct constructor like 'S {}' void visit (AST::StructExprStruct &struct_expr) override; - - // this this a struct constructor with fields void visit (AST::StructExprStructFields &struct_expr) override; - void visit (AST::GroupedExpr &expr) override; - void visit (AST::FieldAccessExpr &expr) override; - void visit (AST::LoopExpr &expr) override; - void visit (AST::BreakExpr &expr) override; - void visit (AST::WhileLoopExpr &expr) override; - void visit (AST::ForLoopExpr &expr) override; - void visit (AST::ContinueExpr &expr) override; - void visit (AST::BorrowExpr &expr) override; - void visit (AST::DereferenceExpr &expr) override; - void visit (AST::MatchExpr &expr) override; - void visit (AST::RangeFromToExpr &expr) override; - void visit (AST::RangeFromExpr &expr) override; - void visit (AST::RangeToExpr &expr) override; - void visit (AST::RangeFullExpr &expr) override; - void visit (AST::RangeFromToInclExpr &expr) override; private: From patchwork Tue Feb 21 12:01:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60010 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1835566wrn; Tue, 21 Feb 2023 04:34:04 -0800 (PST) X-Google-Smtp-Source: AK7set/SvuNodC/nVw+KNuJeUNmuQEsWZ0YHFrYo1JZg2Sx8ylUfAhAHly7IqZPZHjrwBqmpIo2d X-Received: by 2002:a17:907:2d22:b0:8b1:4516:238 with SMTP id gs34-20020a1709072d2200b008b145160238mr11846198ejc.26.1676982844257; Tue, 21 Feb 2023 04:34:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982844; cv=none; d=google.com; s=arc-20160816; b=c/2FjfpYzphDYsTRV+0fJOiBFpiUrBS0nAGRQMJI3fFKJYlw68XAqvKznDoHnnYvxh OrDtlgMqDaEr1w5PaJyA64A+tCbn/P36mAHFTYRTZiRhaug/hRTIFdSXYoCgYh6ZXJ/+ PXJ56JWLx0dGw4FokRftpI9gpGeNTme7dl62+vcm0KcYQiMoNXvuoPy+mfI1ftRQP6cd MhUDlr0W6DBbzRE1fh1EXLAAg3Sg5qvxffv9FFvbfowAyaFeOGVvKT+GElzHkwNYGx5O R4/UQg97FIFAst5DvSeWqhiS/VAWWIKwzZtC4p/2A39uuUacNPiYkdfJa+tS4Taphh1o BNTQ== 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=Mx4M+hOcIm/m8fLsqZd3LiXt4cjdnBO461A2GXm7wMU=; b=Ob5aRzq99kkACOh8awnUISx3VGmxoG86DA8cjmM+dNqqw7EgCnFvSSm9LB6uRefbEm blZRjzJpxPF+U5urEy3zzF0Yf0Bg745sceRWGHZnamXqCfDaF4roAKTA8e5du1zQTYqO 1ieISWSGJbdwljWw/rtVXxdxTHAyhpl0OohhUn7rjHVf+yEpvoTmz1keWnphnOUytPvK J63UpBwwDLaDRNBWkns1PRVWD4q90avViQrzQ9eI2G9UEDZfy9wVW077UX6BBvqIOaCT rAfi+FqSaSyYol60k9OfKhk6nHJPwBkBAy51Kcr8Dvz9u7eC6yU43Tt6rdlambobsgPp 44yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=QayNPtpN; 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 vs18-20020a170907139200b008cbf89a6787si7996556ejb.6.2023.02.21.04.34.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:34:04 -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=QayNPtpN; 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 C949A39192C2 for ; Tue, 21 Feb 2023 12:12:23 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 08CC6383FE01 for ; Tue, 21 Feb 2023 12:04:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 08CC6383FE01 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-x432.google.com with SMTP id bo30so3602647wrb.0 for ; Tue, 21 Feb 2023 04:04:02 -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=Mx4M+hOcIm/m8fLsqZd3LiXt4cjdnBO461A2GXm7wMU=; b=QayNPtpNaCSzCcAyz0BBiXlwyiD9ndNrAb+Lba5ODogKQb04xSKvqiyI62OpUNiJdy 1mWZTGZH8dTbOA4L0HCogbk5YKwdwPSJSmyuwLa8/ON/Y9TqH1XBqRQfgWy7jHj7/iqe rbrMgWxmubFSD+aQE28kID/XIWL3JTefydqdcvu6xM/eUdk3pCjxBea2Xw2krnChTJNO hrBshSFFsytyLziSIkilIwNic5gX66OxVYZBa/NyQPIHU0TWkcMFcVgGv0ZqJRvr/kwH GqwZVJTS50FtiA8eczBcjs2lQGb283KJBOWJYUmcDYfJiAYMYtmbUWHZs7mXQCygZH0R YNUA== 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=Mx4M+hOcIm/m8fLsqZd3LiXt4cjdnBO461A2GXm7wMU=; b=yuKY1QEXmSBvz8k+PClrnw0icu2V1jK45pWjACij7cB3AQo8JgmVJ/zi4LD3ZI/QHo NNpF/rjn1h7sy9XCrdy3Ab8VB9+7mNcMkdM6I3HQpjyV8djxgXdxw2u6eX2owWFKzUL0 JSGoDddnU4BRWgsD72vZfy0aLHjy6Cs46u0TbD6X4hgipb2+Cf4b5/CZFUKyqECsaVXN iC3zDlfhvIHkVUXrjANu2ZEwRcmF4410jZI/DIz+YjnB44i+MVgimXfiiEY2QZr0xFFv fa5lfZJgHQkIYoCariU+io66HZJyvilMBX2OMpirok7UE608VtijVF7YasaYj/EJ3QGR MCKA== X-Gm-Message-State: AO0yUKUqvY8efnA2DZ57Kl6BmbDduO14pcITXGUuwcr2flj+rsdXR9zs eYoBXuTZLSeaqBNw+tVFdMAq8jVbXmmrn4jR0g== X-Received: by 2002:a5d:59a9:0:b0:2bf:95d6:4789 with SMTP id p9-20020a5d59a9000000b002bf95d64789mr3973049wrr.2.1676981041483; Tue, 21 Feb 2023 04:04:01 -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.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:01 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 046/103] gccrs: Add name resolution for closures Date: Tue, 21 Feb 2023 13:01:36 +0100 Message-Id: <20230221120230.596966-47-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?1758443962914319803?= X-GMAIL-MSGID: =?utf-8?q?1758443962914319803?= From: Philip Herron gcc/rust/ChangeLog: * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Visit closure properly when name resolving. (ResolveExpr::resolve_closure_param): Implement closure name resolving. * resolve/rust-ast-resolve-expr.h: Declare visitors for closure types. --- gcc/rust/resolve/rust-ast-resolve-expr.cc | 58 +++++++++++++++++++++++ gcc/rust/resolve/rust-ast-resolve-expr.h | 5 ++ 2 files changed, 63 insertions(+) diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.cc b/gcc/rust/resolve/rust-ast-resolve-expr.cc index 40d4af09444..8ece5b63b6d 100644 --- a/gcc/rust/resolve/rust-ast-resolve-expr.cc +++ b/gcc/rust/resolve/rust-ast-resolve-expr.cc @@ -565,6 +565,64 @@ ResolveExpr::visit (AST::RangeFromToInclExpr &expr) ResolveExpr::go (expr.get_to_expr ().get (), prefix, canonical_prefix); } +void +ResolveExpr::visit (AST::ClosureExprInner &expr) +{ + NodeId scope_node_id = expr.get_node_id (); + resolver->get_name_scope ().push (scope_node_id); + resolver->get_type_scope ().push (scope_node_id); + resolver->get_label_scope ().push (scope_node_id); + resolver->push_new_name_rib (resolver->get_name_scope ().peek ()); + resolver->push_new_type_rib (resolver->get_type_scope ().peek ()); + resolver->push_new_label_rib (resolver->get_type_scope ().peek ()); + + for (auto &p : expr.get_params ()) + { + resolve_closure_param (p); + } + + ResolveExpr::go (expr.get_definition_expr ().get (), prefix, + canonical_prefix); + + resolver->get_name_scope ().pop (); + resolver->get_type_scope ().pop (); + resolver->get_label_scope ().pop (); +} + +void +ResolveExpr::visit (AST::ClosureExprInnerTyped &expr) +{ + NodeId scope_node_id = expr.get_node_id (); + resolver->get_name_scope ().push (scope_node_id); + resolver->get_type_scope ().push (scope_node_id); + resolver->get_label_scope ().push (scope_node_id); + resolver->push_new_name_rib (resolver->get_name_scope ().peek ()); + resolver->push_new_type_rib (resolver->get_type_scope ().peek ()); + resolver->push_new_label_rib (resolver->get_type_scope ().peek ()); + + for (auto &p : expr.get_params ()) + { + resolve_closure_param (p); + } + + ResolveType::go (expr.get_return_type ().get ()); + ResolveExpr::go (expr.get_definition_block ().get (), prefix, + canonical_prefix); + + resolver->get_name_scope ().pop (); + resolver->get_type_scope ().pop (); + resolver->get_label_scope ().pop (); +} + +void +ResolveExpr::resolve_closure_param (AST::ClosureParam ¶m) +{ + PatternDeclaration::go (param.get_pattern ().get ()); + + if (param.has_type_given ()) + ResolveType::go (param.get_type ().get ()); +} + ResolveExpr::ResolveExpr (const CanonicalPath &prefix, const CanonicalPath &canonical_prefix) : ResolverBase (), prefix (prefix), canonical_prefix (canonical_prefix) diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.h b/gcc/rust/resolve/rust-ast-resolve-expr.h index 60ae1720811..9e3e7750119 100644 --- a/gcc/rust/resolve/rust-ast-resolve-expr.h +++ b/gcc/rust/resolve/rust-ast-resolve-expr.h @@ -75,6 +75,11 @@ public: void visit (AST::RangeToExpr &expr) override; void visit (AST::RangeFullExpr &expr) override; void visit (AST::RangeFromToInclExpr &expr) override; + void visit (AST::ClosureExprInner &expr) override; + void visit (AST::ClosureExprInnerTyped &expr) override; + +protected: + void resolve_closure_param (AST::ClosureParam ¶m); private: ResolveExpr (const CanonicalPath &prefix, From patchwork Tue Feb 21 12:01:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60001 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1834169wrn; Tue, 21 Feb 2023 04:31:10 -0800 (PST) X-Google-Smtp-Source: AK7set/hBl+BF5GhTA4GhE9nf6AMeSeAOOlgEEClfKsxmIl1ZyTPxEXEhNrb30wO9Wnn3r2zQHZm X-Received: by 2002:a17:906:ad82:b0:8af:40b0:3dd1 with SMTP id la2-20020a170906ad8200b008af40b03dd1mr12013393ejb.27.1676982670366; Tue, 21 Feb 2023 04:31:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982670; cv=none; d=google.com; s=arc-20160816; b=nnTQzYz+9LGHnpSlqZTFlKGjh8J25e4FnxeNVr7koJEAXSH4zxU6DgnJ47W9R78zsf ARK34J6ScuYRMJp3UnLSWPEV1dysoXRM0mm0Loia/UzKEdkuiYKCTCYEBYt5oRukqYV7 T9WnFKV3fAk/zso8uU+XcroVsY30+J0cxULj1ZikSUwmK3+jm5aoetZMzb+qvzfCJEaZ TTPEZddUjWQGBRs7nc5lwlN0NqeU09b9xms8GcgtURKRexOALc5eM6JJ5xam84USviNm PiGXOZEMl7oSn2zh17YZVF1CCWFB8BiiAoIdxA1YNttT1YKLFKVR+0FicZY+tSLvOgJ/ d/sw== 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=G3ONC9PX2itSjLz0EzLRU32X9fcrVk/vu9ZHrzlAcDI=; b=ENqTHULBn1uN5qV6p8C3QtdGo1WzqyggeKa87o0ME/49Y+9nkL2+YW5pyVfu1mRQXG voEEYhH4DmgMq8eoLjfOlXJntJ9KBd8pQd3z17/xjFMZVjvBbuXDmJBm7b1WOV082XdJ S2/aM1TkHBSklUPOvncCk1BnjbU0cVDbAQMm9m51hfX4awmgzxQNUDLzIkLxQvuUqaxD be4EFWw+Yz1IhgRuTPoRa+J4CEIS2Ubj8KFzIzyAFZwfDq8VTGEa8txICaqM3RjQpn/Y 7wsXUwqqd9ydLCbZ3bc5vkHXVRU8NjqrfQg1d5KTDkdpaOc2edWEuPXc0RooS9On+zDE JIlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Xwun+jU0; 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 et19-20020a170907295300b008e41fc88f2bsi20132ejc.981.2023.02.21.04.31.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:31:10 -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=Xwun+jU0; 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 1AB7438B73E9 for ; Tue, 21 Feb 2023 12:11:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id E19CB384F4AA for ; Tue, 21 Feb 2023 12:04:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E19CB384F4AA 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-x42f.google.com with SMTP id c5so4849965wrr.5 for ; Tue, 21 Feb 2023 04:04:02 -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=G3ONC9PX2itSjLz0EzLRU32X9fcrVk/vu9ZHrzlAcDI=; b=Xwun+jU0ZunQTBL51ry3pF9atGRwZwhAx2lTvd1y4ZbaT9PPTK8yqBeSf0rGytZfds h//QiZCyTsL/os/lrLxTKT0SVyhdO5E3LGEvZmMZUvHltYqD13vgwNZWTrlAsEiRJBY+ TY6b98gA7NyG5GO9Tp6mW8IUQ4XytIttiYUcSGNh9pRXM43OvNtnRAW0ZFdA6mAVfqai RfkTq+YiW+xBOOz434Qk0ok5g4snpMyz+UYkFyqlx7JAKFdDp3M6eOMwwa+tlFfDotVQ gYR75VCji8pFB/I2pIv7h5eRv1fVxAfLR495WK0IbKGS+sfzbR5qBNUFriqOznDjOmHR 7Gcg== 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=G3ONC9PX2itSjLz0EzLRU32X9fcrVk/vu9ZHrzlAcDI=; b=E2bplYhwaygdknODxE05+riTw1trXD9Y7no8MR2DXf+Jn+FLEfkJKr4ADd7h+gMDOt /OZT3Xqg9xeMuAwd8ri0Iysw2qlKtq/9F8M1Re+aER9iRvD8cba7u7dZPyCtehj7saLy MDKNgCquoASkfhfUCZOigFUURfkrUA32xONZHCl1oXf2ixhsLEheLrJBbKpX534qnYRN LVkfaV+lrr6/7PTiU6TOgtvKBfzQElYHNtH+xRNTLBmCp2BVulAgGznQYAkifwfTQAlH KI7V+QN8uJpuan/ENM/fBJlzo3y2CjR4URxHbU5GUPJ54iT8f2KbToQdsMY6+1Y3gGc/ u24g== X-Gm-Message-State: AO0yUKWUKvtcfFNkHHPeuYPFESr3P1EnQp+s9nBKRU8ul5DOOe3Prqh7 OW++Y3oNWrMdjYVJ2GHdZlwZEzl3YzgH6CzNzQ== X-Received: by 2002:a05:6000:1cc:b0:2c6:6e35:440f with SMTP id t12-20020a05600001cc00b002c66e35440fmr4042090wrx.6.1676981042269; Tue, 21 Feb 2023 04:04:02 -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.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:01 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 047/103] gccrs: Refactor method call type checking Date: Tue, 21 Feb 2023 13:01:37 +0100 Message-Id: <20230221120230.596966-48-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=ham 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?1758443780694479456?= X-GMAIL-MSGID: =?utf-8?q?1758443780694479456?= From: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Simplify method call type checking by removing visitor and instead using one static cast. Use the new interface. * typecheck/rust-tyty-call.cc (TypeCheckMethodCallExpr::visit): Likewise. (TypeCheckMethodCallExpr::go): Likewise. (TypeCheckMethodCallExpr::check): Likewise. * typecheck/rust-tyty-call.h (class TypeCheckMethodCallExpr): Likewise. (class Argument): Likewise. --- .../typecheck/rust-hir-type-check-expr.cc | 3 +- gcc/rust/typecheck/rust-tyty-call.cc | 98 +++++++++++++------ gcc/rust/typecheck/rust-tyty-call.h | 79 +++++++-------- 3 files changed, 106 insertions(+), 74 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc index 6b8c63b77f6..9140b8b1305 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc @@ -1162,7 +1162,8 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr) rust_debug ("type-checking method_call: {%s}", lookup->debug_str ().c_str ()); TyTy::BaseType *function_ret_tyty - = TyTy::TypeCheckMethodCallExpr::go (lookup, expr, adjusted_self, context); + = TyTy::TypeCheckMethodCallExpr::go (static_cast (lookup), + expr, adjusted_self, context); if (function_ret_tyty == nullptr || function_ret_tyty->get_kind () == TyTy::TypeKind::ERROR) { diff --git a/gcc/rust/typecheck/rust-tyty-call.cc b/gcc/rust/typecheck/rust-tyty-call.cc index 96c6b93e5c2..0c9e9f488fd 100644 --- a/gcc/rust/typecheck/rust-tyty-call.cc +++ b/gcc/rust/typecheck/rust-tyty-call.cc @@ -216,29 +216,77 @@ TypeCheckCallExpr::visit (FnPtr &type) // method call checker -void -TypeCheckMethodCallExpr::visit (FnType &type) +TypeCheckMethodCallExpr::TypeCheckMethodCallExpr ( + Analysis::NodeMapping call_mappings, std::vector &args, + Location call_locus, Location receiver_locus, TyTy::BaseType *adjusted_self, + Resolver::TypeCheckContext *context) + : call_mappings (call_mappings), arguments (args), call_locus (call_locus), + receiver_locus (receiver_locus), adjusted_self (adjusted_self), + context (context), mappings (Analysis::Mappings::get ()) +{} + +BaseType * +TypeCheckMethodCallExpr::go (FnType *ref, HIR::MethodCallExpr &call, + TyTy::BaseType *adjusted_self, + Resolver::TypeCheckContext *context) +{ + std::vector args; + for (auto &arg : call.get_arguments ()) + { + BaseType *argument_expr_tyty + = Resolver::TypeCheckExpr::Resolve (arg.get ()); + if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR) + { + rust_error_at (arg->get_locus (), + "failed to resolve type for argument"); + return new ErrorType (ref->get_ref ()); + } + + Argument a (arg->get_mappings (), argument_expr_tyty, arg->get_locus ()); + args.push_back (std::move (a)); + } + + TypeCheckMethodCallExpr checker (call.get_mappings (), args, + call.get_locus (), + call.get_receiver ()->get_locus (), + adjusted_self, context); + return checker.check (*ref); +} + +BaseType * +TypeCheckMethodCallExpr::go (FnType *ref, Analysis::NodeMapping call_mappings, + std::vector &args, Location call_locus, + Location receiver_locus, + TyTy::BaseType *adjusted_self, + Resolver::TypeCheckContext *context) +{ + TypeCheckMethodCallExpr checker (call_mappings, args, call_locus, + receiver_locus, adjusted_self, context); + return checker.check (*ref); +} + +BaseType * +TypeCheckMethodCallExpr::check (FnType &type) { Resolver::TypeCheckBase::unify_site ( - call.get_mappings ().get_hirid (), TyWithLocation (type.get_self_type ()), - TyWithLocation (adjusted_self, call.get_receiver ()->get_locus ()), - call.get_locus ()); + call_mappings.get_hirid (), TyWithLocation (type.get_self_type ()), + TyWithLocation (adjusted_self, receiver_locus), call_locus); // +1 for the receiver self - size_t num_args_to_call = call.num_params () + 1; + size_t num_args_to_call = arguments.size () + 1; if (num_args_to_call != type.num_params ()) { - rust_error_at (call.get_locus (), + rust_error_at (call_locus, "unexpected number of arguments %lu expected %lu", - (unsigned long) call.num_params (), + (unsigned long) num_args_to_call, (unsigned long) type.num_params ()); - return; + return new ErrorType (type.get_ref ()); } size_t i = 1; - for (auto &argument : call.get_arguments ()) + for (auto &argument : arguments) { - Location arg_locus = argument->get_locus (); + Location arg_locus = argument.get_locus (); auto fnparam = type.param_at (i); HIR::Pattern *fn_param_pattern = fnparam.first; @@ -248,25 +296,15 @@ TypeCheckMethodCallExpr::visit (FnType &type) ? mappings->lookup_location (param_ty->get_ref ()) : fn_param_pattern->get_locus (); - auto argument_expr_tyty - = Resolver::TypeCheckExpr::Resolve (argument.get ()); - if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR) - { - rust_error_at ( - argument->get_locus (), - "failed to resolve type for argument expr in CallExpr"); - return; - } - - HirId coercion_side_id = argument->get_mappings ().get_hirid (); + auto argument_expr_tyty = argument.get_argument_type (); + HirId coercion_side_id = argument.get_mappings ().get_hirid (); auto resolved_argument_type = Resolver::TypeCheckBase::coercion_site ( coercion_side_id, TyWithLocation (param_ty, param_locus), - TyWithLocation (argument_expr_tyty, arg_locus), argument->get_locus ()); + TyWithLocation (argument_expr_tyty, arg_locus), arg_locus); if (resolved_argument_type->get_kind () == TyTy::TypeKind::ERROR) { - rust_error_at (argument->get_locus (), - "Type Resolution failure on parameter"); - return; + rust_error_at (arg_locus, "Type Resolution failure on parameter"); + return new ErrorType (type.get_ref ()); } i++; @@ -274,15 +312,15 @@ TypeCheckMethodCallExpr::visit (FnType &type) if (i != num_args_to_call) { - rust_error_at (call.get_locus (), + rust_error_at (call_locus, "unexpected number of arguments %lu expected %lu", - (unsigned long) i, (unsigned long) call.num_params ()); - return; + (unsigned long) i, (unsigned long) arguments.size ()); + return new ErrorType (type.get_ref ()); } type.monomorphize (); - resolved = type.get_return_type ()->monomorphized_clone (); + return type.get_return_type ()->monomorphized_clone (); } } // namespace TyTy diff --git a/gcc/rust/typecheck/rust-tyty-call.h b/gcc/rust/typecheck/rust-tyty-call.h index aa47328424e..4d1c81112d6 100644 --- a/gcc/rust/typecheck/rust-tyty-call.h +++ b/gcc/rust/typecheck/rust-tyty-call.h @@ -84,58 +84,51 @@ private: Analysis::Mappings *mappings; }; -class TypeCheckMethodCallExpr : private TyVisitor +class Argument { public: - // Resolve the Method parameters and return back the return type - static BaseType *go (BaseType *ref, HIR::MethodCallExpr &call, - TyTy::BaseType *adjusted_self, - Resolver::TypeCheckContext *context) - { - TypeCheckMethodCallExpr checker (call, adjusted_self, context); - ref->accept_vis (checker); - return checker.resolved; - } + Argument (Analysis::NodeMapping mapping, BaseType *argument_type, + Location locus) + : mapping (mapping), argument_type (argument_type), locus (locus) + {} - void visit (InferType &) override { gcc_unreachable (); } - void visit (TupleType &) override { gcc_unreachable (); } - void visit (ArrayType &) override { gcc_unreachable (); } - void visit (SliceType &) override { gcc_unreachable (); } - void visit (BoolType &) override { gcc_unreachable (); } - void visit (IntType &) override { gcc_unreachable (); } - void visit (UintType &) override { gcc_unreachable (); } - void visit (FloatType &) override { gcc_unreachable (); } - void visit (USizeType &) override { gcc_unreachable (); } - void visit (ISizeType &) override { gcc_unreachable (); } - void visit (ErrorType &) override { gcc_unreachable (); } - void visit (ADTType &) override { gcc_unreachable (); }; - void visit (CharType &) override { gcc_unreachable (); } - void visit (ReferenceType &) override { gcc_unreachable (); } - void visit (PointerType &) override { gcc_unreachable (); } - void visit (ParamType &) override { gcc_unreachable (); } - void visit (StrType &) override { gcc_unreachable (); } - void visit (NeverType &) override { gcc_unreachable (); } - void visit (PlaceholderType &) override { gcc_unreachable (); } - void visit (ProjectionType &) override { gcc_unreachable (); } - void visit (DynamicObjectType &) override { gcc_unreachable (); } + Location get_locus () const { return locus; } - // FIXME - void visit (FnPtr &type) override { gcc_unreachable (); } + BaseType *get_argument_type () { return argument_type; } - // call fns - void visit (FnType &type) override; - void visit (ClosureType &type) override { gcc_unreachable (); } + Analysis::NodeMapping get_mappings () const { return mapping; } private: - TypeCheckMethodCallExpr (HIR::MethodCallExpr &c, + Analysis::NodeMapping mapping; + BaseType *argument_type; + Location locus; +}; + +class TypeCheckMethodCallExpr +{ +public: + static BaseType *go (FnType *ref, HIR::MethodCallExpr &call, + TyTy::BaseType *adjusted_self, + Resolver::TypeCheckContext *context); + + static BaseType *go (FnType *ref, Analysis::NodeMapping call_mappings, + std::vector &args, Location call_locus, + Location receiver_locus, TyTy::BaseType *adjusted_self, + Resolver::TypeCheckContext *context); + +protected: + BaseType *check (FnType &type); + + TypeCheckMethodCallExpr (Analysis::NodeMapping call_mappings, + std::vector &args, Location call_locus, + Location receiver_locus, TyTy::BaseType *adjusted_self, - Resolver::TypeCheckContext *context) - : resolved (nullptr), call (c), adjusted_self (adjusted_self), - context (context), mappings (Analysis::Mappings::get ()) - {} + Resolver::TypeCheckContext *context); - BaseType *resolved; - HIR::MethodCallExpr &call; + Analysis::NodeMapping call_mappings; + std::vector &arguments; + Location call_locus; + Location receiver_locus; TyTy::BaseType *adjusted_self; Resolver::TypeCheckContext *context; Analysis::Mappings *mappings; From patchwork Tue Feb 21 12:01:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59991 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1832202wrn; Tue, 21 Feb 2023 04:26:10 -0800 (PST) X-Google-Smtp-Source: AK7set+c5DBCajUDqdzo4sFmdgjGJO7/lCb6bu+2Z2+yi8XSzgqW246oWgVYRYZ0jBQcP0UDuYnS X-Received: by 2002:a17:906:2b16:b0:8b1:5903:6a01 with SMTP id a22-20020a1709062b1600b008b159036a01mr17756835ejg.77.1676982369916; Tue, 21 Feb 2023 04:26:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982369; cv=none; d=google.com; s=arc-20160816; b=n50Z9FItN0J2S5E21UHOSOZzYxWS8CWYRuFeN37LejzAoepbif9459Zk9sVLD60Y8i tAUQQuiZY8XLS4Ih4YVmYER8P4Exs7XAEvBt0+GQavF/uDXfdljqvipR9skm3CqN2dFu 25apGp5M62Ay4ltRgCdVT1Ix8Zk0PPLvlzLjoZzS0AyFJfFWcO9rOqBe/Vn06RFcXxn2 O++A94W+FKlhEJ5hmz0pNfkF4oss8do2z4K7Xf60iiCzHjvLTkbEdNu1e85VnnYLGPHZ GKZlkXINSVEB/cqqySR6hgwKsaHX1cScOGCcbl6S1RbnOQYyFkuf5oW+c07W/8fsRM58 I7Ag== 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=i9xkM9ea5e6EmRQaVJzdKZ3ladU8rRb31u8pdwTtQPk=; b=zO1Ar2cG/WEzVssZ3l74vfyHTBqOUp28hlhftHE43cU8hS0EiBxDQgSgX0H2GYIq3y ebEzbuu6eaMkssTHeTYHfAS0L3p4LAeC/0fnNVBmNS7jiZ76mB0BiEm7WzS+tsJPYbNm avRdK/t0aZokWtkgEydwcdk5K36WWdsxwNwAAxIe6kOp+RidHc97/Ek2NdYeBfi/NQWU dI3ycf/Zb3CHTMHCH1gjtofyjPcArWRrYOZ+vy9mmFH3uI4QXHmLrb2YURqNIrVgqGDj OB0YoBt4fxLE2W4fVF1M9zw+T3JoOvqHigldYyZAv+YvBGUSVxhmvO27bZ8dcXg3CSYR SlBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Et42iL+N; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ad24-20020a170907259800b008dc1a5182desi3425935ejc.979.2023.02.21.04.26.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:26:09 -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=Et42iL+N; 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 880EA3890975 for ; Tue, 21 Feb 2023 12:10:24 +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 8887E383814A for ; Tue, 21 Feb 2023 12:04:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8887E383814A 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 c12so4163432wrw.1 for ; Tue, 21 Feb 2023 04:04:03 -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=i9xkM9ea5e6EmRQaVJzdKZ3ladU8rRb31u8pdwTtQPk=; b=Et42iL+NzAFCKDtzqoNF56x2YmgAzXeDJqYwGZ2sym5jUdXxZDWRKl+Fw4yZg6zJdL ZM1SYqr0gRU+Rg9yRMUtE7Ytp62IU5dLF+9LfyoDmXcUT/vmy4T63NLWp0pKog9K9/4U wWZc17bNWyIa/mI9T2pedE6nHlVrB4B1GAjZXMtaLkDUt4GcP+51aBm8EVsesaDKvPm1 9CWURKiwsMIPqLZK2nnkVipQZqGwjQZ0my4DaCr1/+As5vYYD7NlA4VM3EhdkkWUES/g k2jYOgV/fUC+W5hVA645Ncu6/I51Ls8lP1VvxcWj/Qk6A/SF5ob3FgabruGQBWIc7deB ZmpQ== 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=i9xkM9ea5e6EmRQaVJzdKZ3ladU8rRb31u8pdwTtQPk=; b=MUPQneQHnqeyN2pAxa/WOAhy66BTJdStzcvCrdpYp9xLz21IuTvpGw5dN4iTB69EWR aeHvmaHEN1Pp61jZhXJfuNN0sxQmSAImurBpXj95+TXH+hQUNvIVkyNRr0RIDzrkgyev 0hgUexKn1U2KB00jUbwurYe8lVh9HLtxZQ49bCa0DozrdbGbj/GQI4IQMqM9n/VTFDvb bRLtHxj4FhZogpjknrCEitVF1ypM7OutAZ0ozdaKr5qMKWnsvR7XEJ9FaXSrhyVTOqPC s5B7TL1MRT6nZAMtUh19PjF7dsl+q8mZaE9nK9tK1WUJv4r0rg8BlvBKy9LDGoQKchur YEfA== X-Gm-Message-State: AO0yUKWZEuiXG8N857oLRJ9iMa1Jd01MoyQ7hh2Xn1Fv/EhyciRH4Pw2 0AnZqqvmIVHFT4zmsKc5fB1mlen83AyxyjslvA== X-Received: by 2002:a5d:5486:0:b0:2be:c41:4758 with SMTP id h6-20020a5d5486000000b002be0c414758mr2396543wrv.38.1676981042894; Tue, 21 Feb 2023 04:04:02 -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.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:02 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 048/103] gccrs: Add closures to lints and error checking Date: Tue, 21 Feb 2023 13:01:38 +0100 Message-Id: <20230221120230.596966-49-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.4 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?1758443465831930586?= X-GMAIL-MSGID: =?utf-8?q?1758443465831930586?= From: Philip Herron gcc/rust/ChangeLog: * checks/errors/rust-const-checker.cc (ConstChecker::visit): Visit closures properly. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/lints/rust-lint-marklive.h: Likewise. --- gcc/rust/checks/errors/rust-const-checker.cc | 4 +++- gcc/rust/checks/errors/rust-unsafe-checker.cc | 4 +++- gcc/rust/checks/lints/rust-lint-marklive.h | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/gcc/rust/checks/errors/rust-const-checker.cc b/gcc/rust/checks/errors/rust-const-checker.cc index 01dc2620767..9161fa1ea2a 100644 --- a/gcc/rust/checks/errors/rust-const-checker.cc +++ b/gcc/rust/checks/errors/rust-const-checker.cc @@ -383,7 +383,9 @@ ConstChecker::visit (FieldAccessExpr &expr) void ConstChecker::visit (ClosureExpr &expr) -{} +{ + expr.get_expr ()->accept_vis (*this); +} void ConstChecker::visit (BlockExpr &expr) diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.cc b/gcc/rust/checks/errors/rust-unsafe-checker.cc index 02868794cbc..3d534743eeb 100644 --- a/gcc/rust/checks/errors/rust-unsafe-checker.cc +++ b/gcc/rust/checks/errors/rust-unsafe-checker.cc @@ -454,7 +454,9 @@ UnsafeChecker::visit (FieldAccessExpr &expr) void UnsafeChecker::visit (ClosureExpr &expr) -{} +{ + expr.get_expr ()->accept_vis (*this); +} void UnsafeChecker::visit (BlockExpr &expr) diff --git a/gcc/rust/checks/lints/rust-lint-marklive.h b/gcc/rust/checks/lints/rust-lint-marklive.h index 4caf18ce186..dcc625d0b9d 100644 --- a/gcc/rust/checks/lints/rust-lint-marklive.h +++ b/gcc/rust/checks/lints/rust-lint-marklive.h @@ -285,6 +285,11 @@ public: item->accept_vis (*this); } + void visit (HIR::ClosureExpr &expr) override + { + expr.get_expr ()->accept_vis (*this); + } + private: std::vector worklist; std::set liveSymbols; From patchwork Tue Feb 21 12:01:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60033 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1839475wrn; Tue, 21 Feb 2023 04:43:15 -0800 (PST) X-Google-Smtp-Source: AK7set+9+egUjj0VPbZsvRya/HvAPpLiSNaTHjT9Fo4nVAqe66eYYT5pHrCDbQCQw1I3iI2fgo9y X-Received: by 2002:a50:ee01:0:b0:4ae:eb0f:892e with SMTP id g1-20020a50ee01000000b004aeeb0f892emr4473625eds.20.1676983395135; Tue, 21 Feb 2023 04:43:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983395; cv=none; d=google.com; s=arc-20160816; b=UPKwyqaGIPA0eZPIkjSgjLybbVYdXSLtuGtYAZw4YsPfuckoPL7394UWXzvgeRPAdg XE4hiufdXkwk2eobPrKN222yUrA8HbbUak7rVx4/t8tV/N6WgWpkkH/1dLAKPkvTDtJG wIrup0Kqho3Dw7TyCN3cjnhi99Rybpnvt+NzEfYadgCgxavrUu0gzrTI5ol9LPY+7QoX C835gid+dSK5MW3/qOkZtgBSrAapiPPhNi1oc+4l6i5C4NvHNE44VZWmFwBQWI0cA77A b57AWSiJk7SkzoKxKzpkrGozW7+Vz4StA4/hCVQWIgf723Dlqy/eppmQr+0XqAn3Pekv v22A== 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=zRJlYgzUbLxQ9JVJ2IG7Wwl33z76X7RQGKYZNW1AbvI=; b=MwoQ9fCfF/Uyw1YtZxN1mTQwit2rHTueCWbdMgvyqNUdnWq/q17SRWi3rYIqtsOaVV j+hFHN1KXMKpbde502IPs3UrTMaxPZVw6subYMD1ZnzVnMA51gXZEoV/8WBjfn3pGg1i Mn6KpB+Ex2OrcWjaeKf6m68oppJ/Qlo2GIIg3jryjOXJxev5gjyJkCPS8TewcQyRZgYA HD+okY4EylFMIV1SL0cGUnhqvAt77rtviCuNuFp15saQNLqfcb01blKudaMx0/3lhg2u //2VSbt1g/cmREa7ekxQpORPZgcFvDMCzdzDKKaHGOAhzth8jzncLsZp9UN0jG7aLoXu EKjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=J9KopAI4; 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 h17-20020a50ed91000000b004acbbafc603si18544371edr.335.2023.02.21.04.43.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:43:15 -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=J9KopAI4; 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 A43B838F7BE9 for ; Tue, 21 Feb 2023 12:14:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 65447385B536 for ; Tue, 21 Feb 2023 12:04:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 65447385B536 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 r7so3991894wrz.6 for ; Tue, 21 Feb 2023 04:04:04 -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=zRJlYgzUbLxQ9JVJ2IG7Wwl33z76X7RQGKYZNW1AbvI=; b=J9KopAI4Mfn5MjA0tgrD1ju2OpglW+XXJXbaOahQAC6NnWWwOzBFj/9JU2UAkSS0ay dVRc1WKn3suKbEYwKRcRo1uW/aO3fg5Ny4wl3bxyrF8XSfknVXDpDEjwmBDotmp+aUkK KVXMqJB0fWV55G02h67t/ZG2930Xta6ukjL7II9rroDtqnrzxJ+bXTjpxNS61zQTXiF5 Vo7Jsc3LhjGFeD3wkrohQWOSuKGCd3lGmSOF8RpC079d1yMp0+Yq7GEuwqcuF9hJUIQZ gkaksxM38YwVCSGMhcHItIqT38u7ShoigJvRkDfPeda24lBgth7hgFiQafhLjglFK55l ueRg== 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=zRJlYgzUbLxQ9JVJ2IG7Wwl33z76X7RQGKYZNW1AbvI=; b=zBVIyFWfr5xf8yTM2Ljw2Ceq9y7LggNBJSo5qexMjhi7/KZ4ATknfxqrYS+0dkDC18 24jPQzVw9xA5MCsKaWomQDT8Nlgkqq7tW1lg13tcENxyqaMHW0tgLtMxWArBH6NclD9U CCB3zMLLBl37mzUEliMTGQTMoFmLcO8CCCJmBM498jDsUqLBT5yijvJmnf2InDvmJ82T BubYI+4XXK/65sRlOiScDZtGihAclvmHMQL9sy7gx1tbrv7jkdobya24X1Tv30+5LnJh SJ/owa48+5MjsVAx9Cp3h1HmmPkAkWltYpgVU4FP8Vc+huPMgZrYy48iQM3yPpgx5HB2 tgGA== X-Gm-Message-State: AO0yUKUgmnbA1d2UdeK119mpyOgvH/uA5aF1E+jHnqLC3Iw/0WQQqBWP uOH1uSDJIxLcozWumbKP46FpPpnMszVcgLgLIA== X-Received: by 2002:a5d:4ccf:0:b0:2c6:5972:cd13 with SMTP id c15-20020a5d4ccf000000b002c65972cd13mr4761569wrt.26.1676981043543; Tue, 21 Feb 2023 04:04:03 -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.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:03 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 049/103] gccrs: Initial Type resolution for closures Date: Tue, 21 Feb 2023 13:01:39 +0100 Message-Id: <20230221120230.596966-50-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=ham 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?1758444540451696021?= X-GMAIL-MSGID: =?utf-8?q?1758444540451696021?= From: Philip Herron gcc/rust/ChangeLog: * hir/tree/rust-hir-expr.h: Add `get_params` method. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Typecheck closure nodes. (TypeCheckExpr::resolve_fn_trait_call): New function. * typecheck/rust-hir-type-check-expr.h: Declare `resolve_fn_trait_call` and `resolve_possible_fn_trait_call_method_name`. * typecheck/rust-hir-type-check.h: Declare `get_context_type`. * typecheck/rust-tyctx.cc (TypeCheckContextItem::get_context_type): New function. * typecheck/rust-tyty-cmp.h: Visit closures properly. * typecheck/rust-tyty-rules.h: Likewise. * typecheck/rust-tyty.cc (BaseType::bounds_compatible): Add commented out assertin. (ClosureType::as_string): Implement it. (ClosureType::clone): Fix closure cloning. (ClosureType::setup_fn_once_output): New function. * typecheck/rust-tyty.h: Improve `ClosureType` class and declare `setup_fn_once_output`. --- gcc/rust/hir/tree/rust-hir-expr.h | 2 + .../typecheck/rust-hir-type-check-expr.cc | 308 +++++++++++++++++- gcc/rust/typecheck/rust-hir-type-check-expr.h | 7 + gcc/rust/typecheck/rust-hir-type-check.h | 2 + gcc/rust/typecheck/rust-tyctx.cc | 32 ++ gcc/rust/typecheck/rust-tyty-cmp.h | 23 ++ gcc/rust/typecheck/rust-tyty-rules.h | 40 ++- gcc/rust/typecheck/rust-tyty.cc | 58 +++- gcc/rust/typecheck/rust-tyty.h | 38 ++- 9 files changed, 479 insertions(+), 31 deletions(-) diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h index 4c5caf17ac3..227bacbe641 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -2131,6 +2131,8 @@ public: }; std::unique_ptr &get_expr () { return expr; } + std::vector &get_params () { return params; } + void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc index 9140b8b1305..85590630378 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc @@ -178,16 +178,6 @@ TypeCheckExpr::visit (HIR::CallExpr &expr) { TyTy::BaseType *function_tyty = TypeCheckExpr::Resolve (expr.get_fnexpr ()); - bool valid_tyty = function_tyty->get_kind () == TyTy::TypeKind::ADT - || function_tyty->get_kind () == TyTy::TypeKind::FNDEF - || function_tyty->get_kind () == TyTy::TypeKind::FNPTR; - if (!valid_tyty) - { - rust_error_at (expr.get_locus (), - "Failed to resolve expression of function call"); - return; - } - rust_debug_loc (expr.get_locus (), "resolved_call_expr to: {%s}", function_tyty->get_name ().c_str ()); @@ -214,6 +204,24 @@ TypeCheckExpr::visit (HIR::CallExpr &expr) rust_assert (adt->number_of_variants () == 1); variant = *adt->get_variants ().at (0); } + + infered + = TyTy::TypeCheckCallExpr::go (function_tyty, expr, variant, context); + return; + } + + bool resolved_fn_trait_call + = resolve_fn_trait_call (expr, function_tyty, &infered); + if (resolved_fn_trait_call) + return; + + bool valid_tyty = function_tyty->get_kind () == TyTy::TypeKind::FNDEF + || function_tyty->get_kind () == TyTy::TypeKind::FNPTR; + if (!valid_tyty) + { + rust_error_at (expr.get_locus (), + "Failed to resolve expression of function call"); + return; } infered = TyTy::TypeCheckCallExpr::go (function_tyty, expr, variant, context); @@ -1422,7 +1430,123 @@ TypeCheckExpr::visit (HIR::MatchExpr &expr) void TypeCheckExpr::visit (HIR::ClosureExpr &expr) { - gcc_unreachable (); + TypeCheckContextItem ¤t_context = context->peek_context (); + TyTy::FnType *current_context_fndecl = current_context.get_context_type (); + + HirId ref = expr.get_mappings ().get_hirid (); + DefId id = expr.get_mappings ().get_defid (); + RustIdent ident{current_context_fndecl->get_ident ().path, expr.get_locus ()}; + + // get from parent context + std::vector subst_refs + = current_context_fndecl->clone_substs (); + + std::vector parameter_types; + for (auto &p : expr.get_params ()) + { + if (p.has_type_given ()) + { + TyTy::BaseType *param_tyty + = TypeCheckType::Resolve (p.get_type ().get ()); + TyTy::TyVar param_ty (param_tyty->get_ref ()); + parameter_types.push_back (param_ty); + + TypeCheckPattern::Resolve (p.get_pattern ().get (), + param_ty.get_tyty ()); + } + else + { + TyTy::TyVar param_ty + = TyTy::TyVar::get_implicit_infer_var (p.get_locus ()); + parameter_types.push_back (param_ty); + + TypeCheckPattern::Resolve (p.get_pattern ().get (), + param_ty.get_tyty ()); + } + } + + // we generate an implicit hirid for the closure args + HirId implicit_args_id = mappings->get_next_hir_id (); + TyTy::TupleType *closure_args + = new TyTy::TupleType (implicit_args_id, expr.get_locus (), + parameter_types); + context->insert_implicit_type (closure_args); + + Location result_type_locus = expr.has_return_type () + ? expr.get_return_type ()->get_locus () + : expr.get_locus (); + TyTy::TyVar result_type + = expr.has_return_type () + ? TyTy::TyVar ( + TypeCheckType::Resolve (expr.get_return_type ().get ())->get_ref ()) + : TyTy::TyVar::get_implicit_infer_var (expr.get_locus ()); + + // resolve the block + Location closure_expr_locus = expr.get_expr ()->get_locus (); + TyTy::BaseType *closure_expr_ty + = TypeCheckExpr::Resolve (expr.get_expr ().get ()); + coercion_site (expr.get_mappings ().get_hirid (), + TyTy::TyWithLocation (result_type.get_tyty (), + result_type_locus), + TyTy::TyWithLocation (closure_expr_ty, closure_expr_locus), + expr.get_locus ()); + + // generate the closure type + infered = new TyTy::ClosureType (ref, id, ident, closure_args, result_type, + subst_refs); + + // FIXME + // all closures automatically inherit the appropriate fn trait. Lets just + // assume FnOnce for now. I think this is based on the return type of the + // closure + + Analysis::RustLangItem::ItemType lang_item_type + = Analysis::RustLangItem::ItemType::FN_ONCE; + DefId respective_lang_item_id = UNKNOWN_DEFID; + bool lang_item_defined + = mappings->lookup_lang_item (lang_item_type, &respective_lang_item_id); + if (!lang_item_defined) + { + // FIXME + // we need to have a unified way or error'ing when we are missing lang + // items that is useful + rust_fatal_error ( + expr.get_locus (), "unable to find lang item: %<%s%>", + Analysis::RustLangItem::ToString (lang_item_type).c_str ()); + } + rust_assert (lang_item_defined); + + // these lang items are always traits + HIR::Item *item = mappings->lookup_defid (respective_lang_item_id); + rust_assert (item->get_item_kind () == HIR::Item::ItemKind::Trait); + HIR::Trait *trait_item = static_cast (item); + + TraitReference *trait = TraitResolver::Resolve (*trait_item); + rust_assert (!trait->is_error ()); + + TyTy::TypeBoundPredicate predicate (*trait, expr.get_locus ()); + + // resolve the trait bound where the <(Args)> are the parameter tuple type + HIR::GenericArgs args = HIR::GenericArgs::create_empty (expr.get_locus ()); + + // lets generate an implicit Type so that it resolves to the implict tuple + // type we have created + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_mappings ().get_nodeid (), + implicit_args_id, UNKNOWN_LOCAL_DEFID); + HIR::TupleType *implicit_tuple + = new HIR::TupleType (mapping, + {} // we dont need to fill this out because it will + // auto resolve because the hir id's match + , + expr.get_locus ()); + args.get_type_args ().push_back (std::unique_ptr (implicit_tuple)); + + // apply the arguments + predicate.apply_generic_arguments (&args); + + // finally inherit the trait bound + infered->inherit_bounds ({predicate}); } bool @@ -1630,6 +1754,168 @@ TypeCheckExpr::resolve_operator_overload ( return true; } +HIR::PathIdentSegment +TypeCheckExpr::resolve_possible_fn_trait_call_method_name ( + const TyTy::BaseType &receiver) +{ + // Question + // do we need to probe possible bounds here? I think not, i think when we + // support Fn traits they are explicitly specified + + // FIXME + // the logic to map the FnTrait to their respective call trait-item is + // duplicated over in the backend/rust-compile-expr.cc + for (const auto &bound : receiver.get_specified_bounds ()) + { + bool found_fn = bound.get_name ().compare ("Fn") == 0; + bool found_fn_mut = bound.get_name ().compare ("FnMut") == 0; + bool found_fn_once = bound.get_name ().compare ("FnOnce") == 0; + + if (found_fn) + { + return HIR::PathIdentSegment ("call"); + } + else if (found_fn_mut) + { + return HIR::PathIdentSegment ("call_mut"); + } + else if (found_fn_once) + { + return HIR::PathIdentSegment ("call_once"); + } + } + + // nothing + return HIR::PathIdentSegment (""); +} + +bool +TypeCheckExpr::resolve_fn_trait_call (HIR::CallExpr &expr, + TyTy::BaseType *receiver_tyty, + TyTy::BaseType **result) +{ + // we turn this into a method call expr + HIR::PathIdentSegment method_name + = resolve_possible_fn_trait_call_method_name (*receiver_tyty); + if (method_name.is_error ()) + return false; + + auto candidates = MethodResolver::Probe (receiver_tyty, method_name); + if (candidates.empty ()) + return false; + + if (candidates.size () > 1) + { + RichLocation r (expr.get_locus ()); + for (auto &c : candidates) + r.add_range (c.candidate.locus); + + rust_error_at ( + r, "multiple candidates found for function trait method call %<%s%>", + method_name.as_string ().c_str ()); + return false; + } + + if (receiver_tyty->get_kind () == TyTy::TypeKind::CLOSURE) + { + const TyTy::ClosureType &closure + = static_cast (*receiver_tyty); + closure.setup_fn_once_output (); + } + + auto candidate = *candidates.begin (); + rust_debug_loc (expr.get_locus (), + "resolved call-expr to fn trait: {%u} {%s}", + candidate.candidate.ty->get_ref (), + candidate.candidate.ty->debug_str ().c_str ()); + + // Get the adjusted self + Adjuster adj (receiver_tyty); + TyTy::BaseType *adjusted_self = adj.adjust_type (candidate.adjustments); + + // store the adjustments for code-generation to know what to do which must be + // stored onto the receiver to so as we don't trigger duplicate deref mappings + // ICE when an argument is a method call + HirId autoderef_mappings_id = expr.get_mappings ().get_hirid (); + context->insert_autoderef_mappings (autoderef_mappings_id, + std::move (candidate.adjustments)); + context->insert_receiver (expr.get_mappings ().get_hirid (), receiver_tyty); + + PathProbeCandidate &resolved_candidate = candidate.candidate; + TyTy::BaseType *lookup_tyty = candidate.candidate.ty; + NodeId resolved_node_id + = resolved_candidate.is_impl_candidate () + ? resolved_candidate.item.impl.impl_item->get_impl_mappings () + .get_nodeid () + : resolved_candidate.item.trait.item_ref->get_mappings ().get_nodeid (); + + if (lookup_tyty->get_kind () != TyTy::TypeKind::FNDEF) + { + RichLocation r (expr.get_locus ()); + r.add_range (resolved_candidate.locus); + rust_error_at (r, "associated impl item is not a method"); + return false; + } + + TyTy::BaseType *lookup = lookup_tyty; + TyTy::FnType *fn = static_cast (lookup); + if (!fn->is_method ()) + { + RichLocation r (expr.get_locus ()); + r.add_range (resolved_candidate.locus); + rust_error_at (r, "associated function is not a method"); + return false; + } + + // fn traits only support tuple argument passing so we need to implicitly set + // this up to get the same type checking we get in the rest of the pipeline + + std::vector call_args; + for (auto &arg : expr.get_arguments ()) + { + TyTy::BaseType *a = TypeCheckExpr::Resolve (arg.get ()); + call_args.push_back (TyTy::TyVar (a->get_ref ())); + } + + // crate implicit tuple + HirId implicit_arg_id = mappings->get_next_hir_id (); + Analysis::NodeMapping mapping (mappings->get_current_crate (), UNKNOWN_NODEID, + implicit_arg_id, UNKNOWN_LOCAL_DEFID); + + TyTy::TupleType *tuple + = new TyTy::TupleType (implicit_arg_id, expr.get_locus (), call_args); + context->insert_implicit_type (implicit_arg_id, tuple); + + std::vector args; + TyTy::Argument a (mapping, tuple, + expr.get_locus () /*FIXME is there a better location*/); + args.push_back (std::move (a)); + + TyTy::BaseType *function_ret_tyty + = TyTy::TypeCheckMethodCallExpr::go (fn, expr.get_mappings (), args, + expr.get_locus (), expr.get_locus (), + adjusted_self, context); + if (function_ret_tyty == nullptr + || function_ret_tyty->get_kind () == TyTy::TypeKind::ERROR) + { + rust_error_at (expr.get_locus (), + "failed check fn trait call-expr MethodCallExpr"); + return false; + } + + // store the expected fntype + context->insert_operator_overload (expr.get_mappings ().get_hirid (), fn); + + // set up the resolved name on the path + resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (), + resolved_node_id); + + // return the result of the function back + *result = function_ret_tyty; + + return true; +} + bool TypeCheckExpr::validate_arithmetic_type ( const TyTy::BaseType *tyty, HIR::ArithmeticOrLogicalExpr::ExprType expr_type) diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h index 7f787fa9766..d800549dea2 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.h +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h @@ -103,6 +103,13 @@ protected: HIR::OperatorExprMeta expr, TyTy::BaseType *lhs, TyTy::BaseType *rhs); + bool resolve_fn_trait_call (HIR::CallExpr &expr, + TyTy::BaseType *function_tyty, + TyTy::BaseType **result); + + HIR::PathIdentSegment + resolve_possible_fn_trait_call_method_name (const TyTy::BaseType &receiver); + private: TypeCheckExpr (); diff --git a/gcc/rust/typecheck/rust-hir-type-check.h b/gcc/rust/typecheck/rust-hir-type-check.h index 2b47c6738b5..adec2f91961 100644 --- a/gcc/rust/typecheck/rust-hir-type-check.h +++ b/gcc/rust/typecheck/rust-hir-type-check.h @@ -70,6 +70,8 @@ public: return item.trait_item; } + TyTy::FnType *get_context_type (); + private: union Item { diff --git a/gcc/rust/typecheck/rust-tyctx.cc b/gcc/rust/typecheck/rust-tyctx.cc index a0b5c5e849e..886842b0623 100644 --- a/gcc/rust/typecheck/rust-tyctx.cc +++ b/gcc/rust/typecheck/rust-tyctx.cc @@ -154,5 +154,37 @@ TypeCheckContext::peek_context () return return_type_stack.back ().first; } +// TypeCheckContextItem + +TyTy::FnType * +TypeCheckContextItem::get_context_type () +{ + auto &context = *TypeCheckContext::get (); + + HirId reference = UNKNOWN_HIRID; + switch (get_type ()) + { + case ITEM: + reference = get_item ()->get_mappings ().get_hirid (); + break; + + case IMPL_ITEM: + reference = get_impl_item ().second->get_mappings ().get_hirid (); + break; + + case TRAIT_ITEM: + reference = get_trait_item ()->get_mappings ().get_hirid (); + break; + } + + rust_assert (reference != UNKNOWN_HIRID); + + TyTy::BaseType *lookup = nullptr; + bool ok = context.lookup_type (reference, &lookup); + rust_assert (ok); + rust_assert (lookup->get_kind () == TyTy::TypeKind::FNDEF); + return static_cast (lookup); +} + } // namespace Resolver } // namespace Rust diff --git a/gcc/rust/typecheck/rust-tyty-cmp.h b/gcc/rust/typecheck/rust-tyty-cmp.h index 5dfd2d7184a..293c8bfa641 100644 --- a/gcc/rust/typecheck/rust-tyty-cmp.h +++ b/gcc/rust/typecheck/rust-tyty-cmp.h @@ -871,6 +871,29 @@ public: ok = true; } + void visit (const ClosureType &type) override + { + if (base->get_def_id () != type.get_def_id ()) + { + BaseCmp::visit (type); + return; + } + + if (!base->get_parameters ().can_eq (&type.get_parameters (), false)) + { + BaseCmp::visit (type); + return; + } + + if (!base->get_result_type ().can_eq (&type.get_result_type (), false)) + { + BaseCmp::visit (type); + return; + } + + ok = true; + } + private: const BaseType *get_base () const override { return base; } const ClosureType *base; diff --git a/gcc/rust/typecheck/rust-tyty-rules.h b/gcc/rust/typecheck/rust-tyty-rules.h index 7ffffc1dd59..4b1fe4fd418 100644 --- a/gcc/rust/typecheck/rust-tyty-rules.h +++ b/gcc/rust/typecheck/rust-tyty-rules.h @@ -624,7 +624,45 @@ class ClosureRules : public BaseRules public: ClosureRules (ClosureType *base) : BaseRules (base), base (base) {} - // TODO + void visit (InferType &type) override + { + if (type.get_infer_kind () != InferType::InferTypeKind::GENERAL) + { + BaseRules::visit (type); + return; + } + + resolved = base->clone (); + resolved->set_ref (type.get_ref ()); + } + + void visit (ClosureType &type) override + { + if (base->get_def_id () != type.get_def_id ()) + { + BaseRules::visit (type); + return; + } + + TyTy::BaseType *args_res + = base->get_parameters ().unify (&type.get_parameters ()); + if (args_res == nullptr || args_res->get_kind () == TypeKind::ERROR) + { + BaseRules::visit (type); + return; + } + + TyTy::BaseType *res + = base->get_result_type ().unify (&type.get_result_type ()); + if (res == nullptr || res->get_kind () == TypeKind::ERROR) + { + BaseRules::visit (type); + return; + } + + resolved = base->clone (); + resolved->set_ref (type.get_ref ()); + } private: BaseType *get_base () override { return base; } diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index 462c5bf91fd..0d96c0f04fd 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -27,6 +27,7 @@ #include "rust-substitution-mapper.h" #include "rust-hir-trait-ref.h" #include "rust-hir-type-bounds.h" +#include "rust-hir-trait-resolve.h" #include "options.h" namespace Rust { @@ -200,6 +201,7 @@ BaseType::bounds_compatible (const BaseType &other, Location locus, rust_error_at (r, "bounds not satisfied for %s %<%s%> is not satisfied", other.get_name ().c_str (), missing_preds.c_str ()); + // rust_assert (!emit_error); } } @@ -1672,7 +1674,9 @@ ClosureType::accept_vis (TyConstVisitor &vis) const std::string ClosureType::as_string () const { - return "TODO"; + std::string params_buf = parameters->as_string (); + return "|" + params_buf + "| {" + result_type.get_tyty ()->as_string () + + "} {" + raw_bounds_as_string () + "}"; } BaseType * @@ -1699,8 +1703,10 @@ ClosureType::is_equal (const BaseType &other) const BaseType * ClosureType::clone () const { - return new ClosureType (get_ref (), get_ty_ref (), ident, id, parameter_types, - result_type, clone_substs (), get_combined_refs ()); + return new ClosureType (get_ref (), get_ty_ref (), ident, id, + (TyTy::TupleType *) parameters->clone (), result_type, + clone_substs (), get_combined_refs (), + specified_bounds); } BaseType * @@ -1716,6 +1722,52 @@ ClosureType::handle_substitions (SubstitutionArgumentMappings mappings) return nullptr; } +void +ClosureType::setup_fn_once_output () const +{ + // lookup the lang items + auto fn_once_lang_item = Analysis::RustLangItem::ItemType::FN_ONCE; + auto fn_once_output_lang_item + = Analysis::RustLangItem::ItemType::FN_ONCE_OUTPUT; + + DefId trait_id = UNKNOWN_DEFID; + bool trait_lang_item_defined + = mappings->lookup_lang_item (fn_once_lang_item, &trait_id); + rust_assert (trait_lang_item_defined); + + DefId trait_item_id = UNKNOWN_DEFID; + bool trait_item_lang_item_defined + = mappings->lookup_lang_item (fn_once_output_lang_item, &trait_item_id); + rust_assert (trait_item_lang_item_defined); + + // resolve to the trait + HIR::Item *item = mappings->lookup_defid (trait_id); + rust_assert (item->get_item_kind () == HIR::Item::ItemKind::Trait); + HIR::Trait *trait = static_cast (item); + + Resolver::TraitReference *trait_ref + = Resolver::TraitResolver::Resolve (*trait); + rust_assert (!trait_ref->is_error ()); + + // resolve to trait item + HIR::TraitItem *trait_item + = mappings->lookup_trait_item_defid (trait_item_id); + rust_assert (trait_item != nullptr); + rust_assert (trait_item->get_item_kind () + == HIR::TraitItem::TraitItemKind::TYPE); + std::string item_identifier = trait_item->trait_identifier (); + + // setup associated types #[lang = "fn_once_output"] + Resolver::TraitItemReference *item_reference = nullptr; + bool found = trait_ref->lookup_trait_item_by_type ( + item_identifier, Resolver::TraitItemReference::TraitItemType::TYPE, + &item_reference); + rust_assert (found); + + // setup + item_reference->associated_type_set (&get_result_type ()); +} + void ArrayType::accept_vis (TyVisitor &vis) { diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index b17f01f67ea..5eaec352567 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -1626,31 +1626,35 @@ class ClosureType : public BaseType, public SubstitutionRef { public: ClosureType (HirId ref, DefId id, RustIdent ident, - std::vector parameter_types, TyVar result_type, + TyTy::TupleType *parameters, TyVar result_type, std::vector subst_refs, - std::set refs = std::set ()) + std::set refs = std::set (), + std::vector specified_bounds + = std::vector ()) : BaseType (ref, ref, TypeKind::CLOSURE, ident, refs), SubstitutionRef (std::move (subst_refs), SubstitutionArgumentMappings::error ()), - parameter_types (std::move (parameter_types)), - result_type (std::move (result_type)), id (id) + parameters (parameters), result_type (std::move (result_type)), id (id) { LocalDefId local_def_id = id.localDefId; rust_assert (local_def_id != UNKNOWN_LOCAL_DEFID); + inherit_bounds (specified_bounds); } ClosureType (HirId ref, HirId ty_ref, RustIdent ident, DefId id, - std::vector parameter_types, TyVar result_type, + TyTy::TupleType *parameters, TyVar result_type, std::vector subst_refs, - std::set refs = std::set ()) + std::set refs = std::set (), + std::vector specified_bounds + = std::vector ()) : BaseType (ref, ty_ref, TypeKind::CLOSURE, ident, refs), SubstitutionRef (std::move (subst_refs), SubstitutionArgumentMappings::error ()), - parameter_types (std::move (parameter_types)), - result_type (std::move (result_type)), id (id) + parameters (parameters), result_type (std::move (result_type)), id (id) { LocalDefId local_def_id = id.localDefId; rust_assert (local_def_id != UNKNOWN_LOCAL_DEFID); + inherit_bounds (specified_bounds); } void accept_vis (TyVisitor &vis) override; @@ -1669,13 +1673,8 @@ public: bool is_concrete () const override final { - for (auto ¶m : parameter_types) - { - auto p = param.get_tyty (); - if (!p->is_concrete ()) - return false; - } - return result_type.get_tyty ()->is_concrete (); + return parameters->is_concrete () + && result_type.get_tyty ()->is_concrete (); } bool needs_generic_substitutions () const override final @@ -1693,8 +1692,15 @@ public: ClosureType * handle_substitions (SubstitutionArgumentMappings mappings) override final; + TyTy::TupleType &get_parameters () const { return *parameters; } + TyTy::BaseType &get_result_type () const { return *result_type.get_tyty (); } + + DefId get_def_id () const { return id; } + + void setup_fn_once_output () const; + private: - std::vector parameter_types; + TyTy::TupleType *parameters; TyVar result_type; DefId id; }; From patchwork Tue Feb 21 12:01:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60036 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1840341wrn; Tue, 21 Feb 2023 04:45:22 -0800 (PST) X-Google-Smtp-Source: AK7set+7s/E0g5bfJE6x51VY9XeTYLMUd1Ym38f+WkT8bD9e1mR7DI7pj/unEp88NY8c+n7zLNML X-Received: by 2002:a17:907:7f04:b0:8b1:3191:286f with SMTP id qf4-20020a1709077f0400b008b13191286fmr15429643ejc.25.1676983522208; Tue, 21 Feb 2023 04:45:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983522; cv=none; d=google.com; s=arc-20160816; b=Ab5sm0B5Ml2WBdsbXl9/AHlJGJKTFmKd4Afw/ns6da8j8tJ9Ulb5la0ZTKXRRH2SU5 ZDeo7phcfUxRpV3g3Sz0OQhwQfKHQIpIHhPV2gVV/yXoWopLvM7LXs25OmdM2c/EQ5vv +4cDgPJtiDNAmsvo8/p3T41tNzY+zfrbVUugBj/zVMcfT+9S9884Re54f5dXRlWI2mBu vzXS1BqBx0o1EYmh3RU6cpTJedtEw5FuqF2VFHY46+bD6/AP8eNQodYl4NT8MN7M/7Yr NsI3kn1Dcp24xCFewkk9DevaAMLOsA/3FtNq1xgCiexPzJ81EZVwsBlR2m/bEMVJeMCk setQ== 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=NpuVtdTrDL1+3kjR3aAHmX1YO5DQorK9CoTm1hn8Wxc=; b=U2PaA+6L2UMpeBedMZU/XyLoYqoGo/18W7t9+CnmLkKg997m0yqCvlSn9Kdq50v4Jn MOCvftjMhAXESmPuwffOs+7SCmaQQJwezUwY2Td9T22beLTIZj/r87sYyM4WzPpDeHu1 3aJo+1mcK2qtnWy+BOrh3BTOdjRXiimUChOgQchhP+dcJPeABbq1GiLY9FL9frpkmwpH F98WOZcmqHD/cvoFOuKwucD7pzV4XJc240L9fbQ+8lhYLVsZEhKJsQusgIHde37iCNml Bzh0HEF2T4wD+HmilZgU8DmoMdNOP59xH8oHswoP3TI+jOA0r7B9ugbqs24eXmNkl/gy SuBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=d2s6Yzaa; 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 f4-20020a1709063f4400b008b172e28307si18687027ejj.935.2023.02.21.04.45.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:45:22 -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=d2s6Yzaa; 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 86A6E3948491 for ; Tue, 21 Feb 2023 12:15:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 85CCA385B523 for ; Tue, 21 Feb 2023 12:04:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 85CCA385B523 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 c12so4163496wrw.1 for ; Tue, 21 Feb 2023 04:04:05 -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=NpuVtdTrDL1+3kjR3aAHmX1YO5DQorK9CoTm1hn8Wxc=; b=d2s6Yzaahm5RSJsj1ClJhUg26GOMu0pK6EcHq6tyGmftfBQC/Dn+NrBoJ5rDFhbr53 rkqqjc+WJWn24LDlxEInqSeJaVOy/9gGvYCln4J/J0k2R6rJ0qvlxeAYkVywF8TLsFHm LoCXcEmfOb2hh73q1N8biqXTHaNy1rP4t9rDs6K2CsarzgU/gqnDgw0H+9SLGffHmzEn foDhaW4hdgf0nBoRG58v6vR1PPMvw7A0tzH+nGpRvPD25VCa/3zfUOqGcJF58UohN4G7 GUZiJJEh98HC/dDAF/uQVry1M6yaj8cByGyaOOr/h+k+4h7Si6PZJevwIQSAh6sCgNkP 45ng== 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=NpuVtdTrDL1+3kjR3aAHmX1YO5DQorK9CoTm1hn8Wxc=; b=tmcKIE18lx6gwoCZF3ygKQ05Ad8Bu0R7g36eYomG4pQaeKlJK1WjCIbFSchLTxPa0R 9zm2k19v8k+dyd805PzpitsjJWpumHN1q4cCY1a16C0VeC5fWVPK88xUzSlmLjhxufy+ lUukY0k9w9+5G/5D44xSXA255KGiM+6wyS8TStiz8Fa/ZuU9y/QX6vjFHXDn0m9e5hF8 JyRO9e0N83ctFmryHZB+1t4/q+nnkgkw4ygEee2ea6xTG/4yYI0ikdGSxo8IyYdDJm60 sXiOm1ZAn5SXo6VGMBQ7sotAMqG5rkWbilRsragSSUfYcxRiAp00QtAy6L2EtNCkj6sJ eQCw== X-Gm-Message-State: AO0yUKWQxQplgzZPFA33cAGnnRj5EvGsIlo9CI73OKdViQNv1dXzV5Lp +jyEXihehnVz5AxPUdwUldXaj7Q+UezvEIpH5Q== X-Received: by 2002:adf:ef0c:0:b0:2c3:f6ff:292c with SMTP id e12-20020adfef0c000000b002c3f6ff292cmr3743056wro.55.1676981044052; Tue, 21 Feb 2023 04:04:04 -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.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:03 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 050/103] gccrs: Closure support at CallExpr Date: Tue, 21 Feb 2023 13:01:40 +0100 Message-Id: <20230221120230.596966-51-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.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=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?1758444673492336022?= X-GMAIL-MSGID: =?utf-8?q?1758444673492336022?= From: Philip Herron gcc/rust/ChangeLog: * backend/rust-compile-context.h: Add new functions: `insert_closure_decl` and `lookup_closure_decl`. * backend/rust-compile-expr.cc (CompileExpr::visit): Start compiling Closures properly. (CompileExpr::generate_closure_function): New function. (CompileExpr::generate_closure_fntype): Likewise. * backend/rust-compile-expr.h: Declare `generate_closure_function` and `generate_closure_fntype`. * backend/rust-compile-type.cc (TyTyResolveCompile::visit): Visit closure types properly. * backend/rust-mangle.cc (legacy_mangle_name): Add support for closures. * backend/rust-tree.h (RS_CLOSURE_FLAG): Add new tree macro. (RS_CLOSURE_TYPE_P): And checking for it on tree nodes. * typecheck/rust-tyty.cc (ClosureType::is_equal): Add implementation. gcc/testsuite/ChangeLog: * rust/execute/torture/closure1.rs: New test. --- gcc/rust/backend/rust-compile-context.h | 31 ++ gcc/rust/backend/rust-compile-expr.cc | 280 +++++++++++++++++- gcc/rust/backend/rust-compile-expr.h | 10 + gcc/rust/backend/rust-compile-type.cc | 10 +- gcc/rust/backend/rust-mangle.cc | 6 + gcc/rust/backend/rust-tree.h | 5 + gcc/rust/typecheck/rust-tyty.cc | 13 +- .../rust/execute/torture/closure1.rs | 18 ++ 8 files changed, 361 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/rust/execute/torture/closure1.rs diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h index 49f78e19b20..d2d3a53f182 100644 --- a/gcc/rust/backend/rust-compile-context.h +++ b/gcc/rust/backend/rust-compile-context.h @@ -147,6 +147,35 @@ public: mono_fns[dId].push_back ({ref, fn}); } + void insert_closure_decl (const TyTy::ClosureType *ref, tree fn) + { + auto dId = ref->get_def_id (); + auto it = mono_closure_fns.find (dId); + if (it == mono_closure_fns.end ()) + mono_closure_fns[dId] = {}; + + mono_closure_fns[dId].push_back ({ref, fn}); + } + + tree lookup_closure_decl (const TyTy::ClosureType *ref) + { + auto dId = ref->get_def_id (); + auto it = mono_closure_fns.find (dId); + if (it == mono_closure_fns.end ()) + return error_mark_node; + + for (auto &i : it->second) + { + const TyTy::ClosureType *t = i.first; + tree fn = i.second; + + if (ref->is_equal (*t)) + return fn; + } + + return error_mark_node; + } + bool lookup_function_decl (HirId id, tree *fn, DefId dId = UNKNOWN_DEFID, const TyTy::BaseType *ref = nullptr, const std::string &asm_name = std::string ()) @@ -343,6 +372,8 @@ private: std::vector loop_begin_labels; std::map>> mono_fns; + std::map>> + mono_closure_fns; std::map implicit_pattern_bindings; std::map main_variants; diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index 724a93a68bd..d2d9ae0a233 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -1589,9 +1589,7 @@ CompileExpr::visit (HIR::CallExpr &expr) } // must be a tuple constructor - bool is_fn = tyty->get_kind () == TyTy::TypeKind::FNDEF - || tyty->get_kind () == TyTy::TypeKind::FNPTR; - bool is_adt_ctor = !is_fn; + bool is_adt_ctor = tyty->get_kind () == TyTy::TypeKind::ADT; if (is_adt_ctor) { rust_assert (tyty->get_kind () == TyTy::TypeKind::ADT); @@ -1692,6 +1690,57 @@ CompileExpr::visit (HIR::CallExpr &expr) return true; }; + auto fn_address = CompileExpr::Compile (expr.get_fnexpr (), ctx); + + // is this a closure call? + if (RS_CLOSURE_TYPE_P (TREE_TYPE (fn_address))) + { + rust_assert (tyty->get_kind () == TyTy::TypeKind::CLOSURE); + TyTy::ClosureType *closure = static_cast (tyty); + + std::vector tuple_arg_vals; + for (auto &argument : expr.get_arguments ()) + { + auto rvalue = CompileExpr::Compile (argument.get (), ctx); + tuple_arg_vals.push_back (rvalue); + } + + tree tuple_args_tyty + = TyTyResolveCompile::compile (ctx, &closure->get_parameters ()); + tree tuple_args + = ctx->get_backend ()->constructor_expression (tuple_args_tyty, false, + tuple_arg_vals, -1, + expr.get_locus ()); + + // need to apply any autoderef's to the self argument + HirId autoderef_mappings_id = expr.get_mappings ().get_hirid (); + std::vector *adjustments = nullptr; + bool ok + = ctx->get_tyctx ()->lookup_autoderef_mappings (autoderef_mappings_id, + &adjustments); + rust_assert (ok); + + // apply adjustments for the fn call + tree self + = resolve_adjustements (*adjustments, fn_address, expr.get_locus ()); + + // args are always self, and the tuple of the args we are passing where + // self is the path of the call-expr in this case the fn_address + std::vector args; + args.push_back (self); + args.push_back (tuple_args); + + // get the fn call address + tree closure_call_site = ctx->lookup_closure_decl (closure); + tree closure_call_address + = address_expression (closure_call_site, expr.get_locus ()); + translated + = ctx->get_backend ()->call_expression (closure_call_address, args, + nullptr /* static chain ?*/, + expr.get_locus ()); + return; + } + bool is_varadic = false; if (tyty->get_kind () == TyTy::TypeKind::FNDEF) { @@ -1699,13 +1748,13 @@ CompileExpr::visit (HIR::CallExpr &expr) is_varadic = fn->is_varadic (); } - size_t required_num_args; + size_t required_num_args = expr.get_arguments ().size (); if (tyty->get_kind () == TyTy::TypeKind::FNDEF) { const TyTy::FnType *fn = static_cast (tyty); required_num_args = fn->num_params (); } - else + else if (tyty->get_kind () == TyTy::TypeKind::FNPTR) { const TyTy::FnPtr *fn = static_cast (tyty); required_num_args = fn->num_params (); @@ -1746,8 +1795,7 @@ CompileExpr::visit (HIR::CallExpr &expr) args.push_back (rvalue); } - // must be a call to a function - auto fn_address = CompileExpr::Compile (expr.get_fnexpr (), ctx); + // must be a regular call to a function translated = ctx->get_backend ()->call_expression (fn_address, args, nullptr, expr.get_locus ()); } @@ -2806,7 +2854,223 @@ CompileExpr::visit (HIR::ArrayIndexExpr &expr) void CompileExpr::visit (HIR::ClosureExpr &expr) { - gcc_unreachable (); + TyTy::BaseType *closure_expr_ty = nullptr; + if (!ctx->get_tyctx ()->lookup_type (expr.get_mappings ().get_hirid (), + &closure_expr_ty)) + { + rust_fatal_error (expr.get_locus (), + "did not resolve type for this ClosureExpr"); + return; + } + rust_assert (closure_expr_ty->get_kind () == TyTy::TypeKind::CLOSURE); + TyTy::ClosureType *closure_tyty + = static_cast (closure_expr_ty); + tree compiled_closure_tyty = TyTyResolveCompile::compile (ctx, closure_tyty); + + // generate closure function + generate_closure_function (expr, *closure_tyty, compiled_closure_tyty); + + // lets ignore state capture for now we need to instantiate the struct anyway + // then generate the function + + std::vector vals; + // TODO + // setup argument captures based on the mode? + + translated + = ctx->get_backend ()->constructor_expression (compiled_closure_tyty, false, + vals, -1, expr.get_locus ()); +} + +tree +CompileExpr::generate_closure_function (HIR::ClosureExpr &expr, + TyTy::ClosureType &closure_tyty, + tree compiled_closure_tyty) +{ + TyTy::FnType *fn_tyty = nullptr; + tree compiled_fn_type + = generate_closure_fntype (expr, closure_tyty, compiled_closure_tyty, + &fn_tyty); + if (compiled_fn_type == error_mark_node) + return error_mark_node; + + const Resolver::CanonicalPath &parent_canonical_path + = closure_tyty.get_ident ().path; + Resolver::CanonicalPath path = parent_canonical_path.append ( + Resolver::CanonicalPath::new_seg (UNKNOWN_NODEID, "{{closure}}")); + + std::string ir_symbol_name = path.get (); + std::string asm_name = ctx->mangle_item (&closure_tyty, path); + + unsigned int flags = 0; + tree fndecl + = ctx->get_backend ()->function (compiled_fn_type, ir_symbol_name, asm_name, + flags, expr.get_locus ()); + + // insert into the context + ctx->insert_function_decl (fn_tyty, fndecl); + ctx->insert_closure_decl (&closure_tyty, fndecl); + + // setup the parameters + std::vector param_vars; + + // closure self + Bvariable *self_param + = ctx->get_backend ()->parameter_variable (fndecl, "$closure", + compiled_closure_tyty, + expr.get_locus ()); + DECL_ARTIFICIAL (self_param->get_decl ()) = 1; + param_vars.push_back (self_param); + + // setup the implicit argument captures + // TODO + + // args tuple + tree args_type + = TyTyResolveCompile::compile (ctx, &closure_tyty.get_parameters ()); + Bvariable *args_param + = ctx->get_backend ()->parameter_variable (fndecl, "args", args_type, + expr.get_locus ()); + param_vars.push_back (args_param); + + // setup the implicit mappings for the arguments. Since argument passing to + // closure functions is done via passing a tuple but the closure body expects + // just normal arguments this means we need to destructure them similar to + // what we do in MatchExpr's. This means when we have a closure-param of a we + // actually setup the destructure to take from the args tuple + + tree args_param_expr = args_param->get_tree (expr.get_locus ()); + size_t i = 0; + for (auto &closure_param : expr.get_params ()) + { + tree compiled_param_var = ctx->get_backend ()->struct_field_expression ( + args_param_expr, i, closure_param.get_locus ()); + + const HIR::Pattern ¶m_pattern = *closure_param.get_pattern (); + ctx->insert_pattern_binding ( + param_pattern.get_pattern_mappings ().get_hirid (), compiled_param_var); + i++; + } + + if (!ctx->get_backend ()->function_set_parameters (fndecl, param_vars)) + return error_mark_node; + + // lookup locals + HIR::Expr *function_body = expr.get_expr ().get (); + auto body_mappings = function_body->get_mappings (); + Resolver::Rib *rib = nullptr; + bool ok + = ctx->get_resolver ()->find_name_rib (body_mappings.get_nodeid (), &rib); + rust_assert (ok); + + std::vector locals + = compile_locals_for_block (ctx, *rib, fndecl); + + tree enclosing_scope = NULL_TREE; + Location start_location = function_body->get_locus (); + Location end_location = function_body->get_locus (); + bool is_block_expr + = function_body->get_expression_type () == HIR::Expr::ExprType::Block; + if (is_block_expr) + { + HIR::BlockExpr *body = static_cast (function_body); + start_location = body->get_locus (); + end_location = body->get_end_locus (); + } + + tree code_block = ctx->get_backend ()->block (fndecl, enclosing_scope, locals, + start_location, end_location); + ctx->push_block (code_block); + + TyTy::BaseType *tyret = &closure_tyty.get_result_type (); + bool function_has_return = !closure_tyty.get_result_type ().is_unit (); + Bvariable *return_address = nullptr; + if (function_has_return) + { + tree return_type = TyTyResolveCompile::compile (ctx, tyret); + + bool address_is_taken = false; + tree ret_var_stmt = NULL_TREE; + + return_address = ctx->get_backend ()->temporary_variable ( + fndecl, code_block, return_type, NULL, address_is_taken, + expr.get_locus (), &ret_var_stmt); + + ctx->add_statement (ret_var_stmt); + } + + ctx->push_fn (fndecl, return_address); + + if (is_block_expr) + { + HIR::BlockExpr *body = static_cast (function_body); + compile_function_body (ctx, fndecl, *body, true); + } + else + { + tree value = CompileExpr::Compile (function_body, ctx); + tree return_expr + = ctx->get_backend ()->return_statement (fndecl, {value}, + function_body->get_locus ()); + ctx->add_statement (return_expr); + } + + tree bind_tree = ctx->pop_block (); + + gcc_assert (TREE_CODE (bind_tree) == BIND_EXPR); + DECL_SAVED_TREE (fndecl) = bind_tree; + + ctx->pop_fn (); + ctx->push_function (fndecl); + + return fndecl; +} + +tree +CompileExpr::generate_closure_fntype (HIR::ClosureExpr &expr, + const TyTy::ClosureType &closure_tyty, + tree compiled_closure_tyty, + TyTy::FnType **fn_tyty) +{ + // grab the specified_bound + rust_assert (closure_tyty.num_specified_bounds () == 1); + const TyTy::TypeBoundPredicate &predicate + = *closure_tyty.get_specified_bounds ().begin (); + + // ensure the fn_once_output associated type is set + closure_tyty.setup_fn_once_output (); + + // the function signature is based on the trait bound that the closure + // implements which is determined at the type resolution time + // + // https://github.com/rust-lang/rust/blob/7807a694c2f079fd3f395821bcc357eee8650071/library/core/src/ops/function.rs#L54-L71 + + TyTy::TypeBoundPredicateItem item = TyTy::TypeBoundPredicateItem::error (); + if (predicate.get_name ().compare ("FnOnce") == 0) + { + item = predicate.lookup_associated_item ("call_once"); + } + else if (predicate.get_name ().compare ("FnMut") == 0) + { + item = predicate.lookup_associated_item ("call_mut"); + } + else if (predicate.get_name ().compare ("Fn") == 0) + { + item = predicate.lookup_associated_item ("call"); + } + else + { + // FIXME error message? + gcc_unreachable (); + return error_mark_node; + } + + rust_assert (!item.is_error ()); + + TyTy::BaseType *item_tyty = item.get_tyty_for_receiver (&closure_tyty); + rust_assert (item_tyty->get_kind () == TyTy::TypeKind::FNDEF); + *fn_tyty = static_cast (item_tyty); + return TyTyResolveCompile::compile (ctx, item_tyty); } } // namespace Compile diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index 7fc3f5e7f4d..c734406e0da 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -142,6 +142,16 @@ protected: const TyTy::ArrayType &array_tyty, tree array_type, HIR::ArrayElemsCopied &elems); +protected: + tree generate_closure_function (HIR::ClosureExpr &expr, + TyTy::ClosureType &closure_tyty, + tree compiled_closure_tyty); + + tree generate_closure_fntype (HIR::ClosureExpr &expr, + const TyTy::ClosureType &closure_tyty, + tree compiled_closure_tyty, + TyTy::FnType **fn_tyty); + private: CompileExpr (Context *ctx); diff --git a/gcc/rust/backend/rust-compile-type.cc b/gcc/rust/backend/rust-compile-type.cc index fe1b7ce95e3..824cb3a56ef 100644 --- a/gcc/rust/backend/rust-compile-type.cc +++ b/gcc/rust/backend/rust-compile-type.cc @@ -97,9 +97,15 @@ TyTyResolveCompile::visit (const TyTy::InferType &) } void -TyTyResolveCompile::visit (const TyTy::ClosureType &) +TyTyResolveCompile::visit (const TyTy::ClosureType &type) { - gcc_unreachable (); + std::vector fields; + tree type_record = ctx->get_backend ()->struct_type (fields); + RS_CLOSURE_FLAG (type_record) = 1; + + std::string named_struct_str = type.get_ident ().path.get () + "{{closure}}"; + translated = ctx->get_backend ()->named_type (named_struct_str, type_record, + type.get_ident ().locus); } void diff --git a/gcc/rust/backend/rust-mangle.cc b/gcc/rust/backend/rust-mangle.cc index 4d202078a70..83aefa7997a 100644 --- a/gcc/rust/backend/rust-mangle.cc +++ b/gcc/rust/backend/rust-mangle.cc @@ -13,6 +13,8 @@ static const std::string kMangledRef = "$RF$"; static const std::string kMangledPtr = "$BP$"; static const std::string kMangledLeftSqParen = "$u5b$"; // [ static const std::string kMangledRightSqParen = "$u5d$"; // ] +static const std::string kMangledLeftBrace = "$u7b$"; // { +static const std::string kMangledRightBrace = "$u7d$"; // } static const std::string kQualPathBegin = "_" + kMangledSubstBegin; static const std::string kMangledComma = "$C$"; @@ -66,6 +68,10 @@ legacy_mangle_name (const std::string &name) m = kMangledLeftSqParen; else if (c == ']') m = kMangledRightSqParen; + else if (c == '{') + m = kMangledLeftBrace; + else if (c == '}') + m = kMangledRightBrace; else if (c == ',') m = kMangledComma; else if (c == ':') diff --git a/gcc/rust/backend/rust-tree.h b/gcc/rust/backend/rust-tree.h index 41dd012bd6d..284fd873c1c 100644 --- a/gcc/rust/backend/rust-tree.h +++ b/gcc/rust/backend/rust-tree.h @@ -82,6 +82,11 @@ #define SLICE_TYPE_P(TYPE) \ (TREE_CODE (TYPE) == RECORD_TYPE && TREE_LANG_FLAG_0 (TYPE)) +// lambda? +#define RS_CLOSURE_FLAG TREE_LANG_FLAG_1 +#define RS_CLOSURE_TYPE_P(TYPE) \ + (TREE_CODE (TYPE) == RECORD_TYPE && TREE_LANG_FLAG_1 (TYPE)) + /* Returns true if NODE is a pointer to member function type. */ #define TYPE_PTRMEMFUNC_P(NODE) \ (TREE_CODE (NODE) == RECORD_TYPE && TYPE_PTRMEMFUNC_FLAG (NODE)) diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index 0d96c0f04fd..bdb2d909b86 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -1696,8 +1696,17 @@ ClosureType::can_eq (const BaseType *other, bool emit_errors) const bool ClosureType::is_equal (const BaseType &other) const { - gcc_unreachable (); - return false; + if (other.get_kind () != TypeKind::CLOSURE) + return false; + + const ClosureType &other2 = static_cast (other); + if (get_def_id () != other2.get_def_id ()) + return false; + + if (!get_parameters ().is_equal (other2.get_parameters ())) + return false; + + return get_result_type ().is_equal (other2.get_result_type ()); } BaseType * diff --git a/gcc/testsuite/rust/execute/torture/closure1.rs b/gcc/testsuite/rust/execute/torture/closure1.rs new file mode 100644 index 00000000000..62afa78a038 --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/closure1.rs @@ -0,0 +1,18 @@ +extern "C" { + fn printf(s: *const i8, ...); +} + +#[lang = "fn_once"] +pub trait FnOnce { + #[lang = "fn_once_output"] + type Output; + + extern "rust-call" fn call_once(self, args: Args) -> Self::Output; +} + +fn main() -> i32 { + let closure_annotated = |i: i32| -> i32 { i + 1 }; + + let i = 1; + closure_annotated(i) - 2 +} From patchwork Tue Feb 21 12:01:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60013 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1836486wrn; Tue, 21 Feb 2023 04:36:08 -0800 (PST) X-Google-Smtp-Source: AK7set8F/y2ApuPe9JZgR5YoJ95wbyS7tuzHwTgZJCL7vIK4qpnv3vz77f9krr3sYTwaGLBoV5SA X-Received: by 2002:a05:6402:1383:b0:4af:59c0:d37d with SMTP id b3-20020a056402138300b004af59c0d37dmr354952edv.30.1676982968388; Tue, 21 Feb 2023 04:36:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982968; cv=none; d=google.com; s=arc-20160816; b=B5Kpfz50DLEdYPvV1QkywN3zGZL+g/xSJ9TPZFFnD53p/uxUsxEfgkLEsPUUNzlWWV ksZneIs5toYpSVrt5fTgVt+r06sUjbJ5Q9NbdSzi9Voaq/Ev/bnBIu9H64MW8bhNwSyx H1+tmOyjpIW07xc7SDyzUJkiqYrwv+iNBRweLCsEaCvZO27xp9w4nMFE2h8FpeVxURJE ro0Yynav0DC+/NL6PgX6q/Sm4fGCN/AjNV1e900ZH+S3yYa1xRTSxEhgDPDvwwuYvX6y LOQYd48h/7sqZtnh2b6gYhU757BjdhTWPFTsBtpKnYmy5sx0ZamZfwGj8t6mhPX1DWIH Pb9w== 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=cn21z6lBPZuI15CN1Av/jLF6sToO05XyZ1FrrIoqbYA=; b=lFDwLmm+rMfbdJ/db2kOi9fvd8ziAvh5BTmhg6otj5BqY7S4KYJxiRHmKb3tgn+E8W vwQGnutXSF6NxVp+f7q81HgSELLKFLritooI2O76fmAQ4mC1YNcTIxUCXOqe8eZyAn8P //wllHKd2sPgGSqYK3WDY2uRPbDUC5sb+Cu+2GJytcD6gxJ+mPd1v1/Dg8hQzFUAXY37 3Jrv+Xswat8dmvBO07OFAUMnoyzld3vLfesd3a5hgZkiXZvwikksWEB8P7M4b5A9ISAJ Ix3b7HY8n6TxHrmK6c80uGcUW74C6BrAubKQfwjRG64kIIaUXEADP63eTaicOzKSmYbb olgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=ew5I7TSe; 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 r18-20020aa7d592000000b004acbdaf456fsi20370591edq.291.2023.02.21.04.36.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:36:08 -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=ew5I7TSe; 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 885053837F22 for ; Tue, 21 Feb 2023 12:12:55 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 2960B383FDEE for ; Tue, 21 Feb 2023 12:04:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2960B383FDEE 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-x42f.google.com with SMTP id c12so4163533wrw.1 for ; Tue, 21 Feb 2023 04:04:06 -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=cn21z6lBPZuI15CN1Av/jLF6sToO05XyZ1FrrIoqbYA=; b=ew5I7TSeDbGa0prayJ4nMXpWO3/A5tCda1BtSPlIkJtEC/lqClMaflsEheypI7JBj5 ALpeWhcliW6RnfHcqwU7u3wRuHRQ8RDknZgjwBZNvpa6oqLHofNCGy4l9Xgwp2RLZS2t vhVfb33ZoQJKWDVhbADzoosxbHC/B8bN34gFzHRToNoYNsZgv1cFd2E0HjmNzKdSWw8N E19bQ8hXzON5Q05z9ozoBRte/PE9NWcxL9V31tvq2Ad52KGCzpMVC/2lG1DDYeUS5LJp A0VZzzonT2FquxBhcEFU0udd64rpos4PlIfNedVJynQFIJipoT7HI82X8Y9kQZHTi+oT G3qw== 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=cn21z6lBPZuI15CN1Av/jLF6sToO05XyZ1FrrIoqbYA=; b=nUHhyIuYFT0DK/6XOnBY2Pa2fThh8PDiJ/qEGoDI9ONHhcanqcVTnnUw0mMY4aWjHA WmAT7qwBulW6dtdG6Mf+1hfxi6xl8JMt7HiRkjFw57/5fGzMf3IcjMtz3t/OlpC0o93j TPEOUnKCmx3VOljTWp7B13HF7kMaxzYepiyqqQiNpnWP9palnb96Qcycjpo2bow/sxEJ DoZwK4v6ozbo0xePESzzEmV/VNQXWq1x0smtgKDp/CUuOG4qY3BZ8UfkjdOufaIbtIiv HKNsbAr3TbO01K4RvkVi/IZdudbRTQgJS6UCWrNnc1mn1iG4vR+CFvXfwv2/6BUiqZAA 5w5g== X-Gm-Message-State: AO0yUKWuzOz7S1CT+smmE2C921AN9F36lhSY7m0PpmNPydOfTMou1oKj nfYRhmPfgo4pMLZNbPuI8SUFhtBl8EYarsKkgg== X-Received: by 2002:a5d:6b83:0:b0:2c5:77de:426b with SMTP id n3-20020a5d6b83000000b002c577de426bmr3461385wrx.60.1676981044769; Tue, 21 Feb 2023 04:04:04 -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.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:04 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 051/103] gccrs: Add missing name resolution to Function type-path segments Date: Tue, 21 Feb 2023 13:01:41 +0100 Message-Id: <20230221120230.596966-52-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.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=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?1758444093221679462?= X-GMAIL-MSGID: =?utf-8?q?1758444093221679462?= From: Philip Herron gcc/rust/ChangeLog: * resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Add missing handling of function case. --- gcc/rust/resolve/rust-ast-resolve-type.cc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc b/gcc/rust/resolve/rust-ast-resolve-type.cc index d227b8b539a..e5c712aba07 100644 --- a/gcc/rust/resolve/rust-ast-resolve-type.cc +++ b/gcc/rust/resolve/rust-ast-resolve-type.cc @@ -149,7 +149,20 @@ ResolveRelativeTypePath::go (AST::TypePath &path, NodeId &resolved_node_id) break; case AST::TypePathSegment::SegmentType::FUNCTION: - gcc_unreachable (); + AST::TypePathSegmentFunction *fnseg + = static_cast (segment.get ()); + + AST::TypePathFunction &fn = fnseg->get_type_path_function (); + for (auto ¶m : fn.get_params ()) + { + ResolveType::go (param.get ()); + } + + if (fn.has_return_type ()) + { + ResolveType::go (fn.get_return_type ().get ()); + } + break; } From patchwork Tue Feb 21 12:01:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60020 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1837477wrn; Tue, 21 Feb 2023 04:38:20 -0800 (PST) X-Google-Smtp-Source: AK7set8Z0FN4KEwQhhSzUIMxSBZTxyzwI8kYKbagSteZQR7lyORpe7lXAq7Th1wVhe9KlUPcQSFS X-Received: by 2002:a17:906:24d3:b0:8c8:bd1:1d7e with SMTP id f19-20020a17090624d300b008c80bd11d7emr7969350ejb.18.1676983100688; Tue, 21 Feb 2023 04:38:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983100; cv=none; d=google.com; s=arc-20160816; b=tzndkCFh1EHQLrj9kMclgdLYEtDZxVgZ6l8j5i70P5VzBhqhItHcq8lhavl6zFoYOe 5xjIKrRB+UUqfjP8e52Z8FDcuGsRVXSlYGWJi0WdAhCAeGHViIayRdDomWz7tlRRqD3L MzShrecRlISlAE2pcIPKP5O6ocTj+7zq9qV0N1EacfqcHDlliQaWGfc9B672eYL7fOP9 4Zfo0YsedmoHsNjbpt2SrwDTYO2GJBzAd1r0nZ8th9MpUyVscMcaYMOFghFxtO4vg8tZ 5T0QRmJRsIzoMPFXJxioiaArEL2f2F9VkEXnd7tM4BMYUTg8hv4lWLypDVuVJTcDq1LZ UJ3A== 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=OKUjLOAKFbXHwJjqjnkbMGlApLgsGgSq0nNCpQ7jW8c=; b=tnKxq1NEEOEuiPzXUEmeQQkR/CPV2gjZf3lJ7cbYzxfeCM/jpqQEWutATKF1i5GrXS /qu2swDWd4+e3/IERIjL+duRDc7mvRqJpElRV1VzadZ3IfKEZ2O/aZ/Hm/8Na7AniDdE 5O7sreOpDJUk0w+CujLDGYxWDeS+4yKMNNhqwskcE91CDwDb1x/hrGC9B0Djn3onX7HO 1ahRQz3x1NX/JSLDsKaUGPoL7XCQJ6Mx3dTM34fuE84rtWrdEcrULCnMdvmPHpHLa0jc G0mfKxUss/j8chPlEUJxO2ox02acjSKXy9yuTRRgyLzflugl/LEdOCz5KWzSuCseOD85 wPHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=IWY5s0yQ; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 25-20020a17090601d900b008b17ac3edb8si16956033ejj.675.2023.02.21.04.38.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:38:20 -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=IWY5s0yQ; 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 4ABF839124BD for ; Tue, 21 Feb 2023 12:13:28 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 41AED383D99F for ; Tue, 21 Feb 2023 12:04:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 41AED383D99F 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-x430.google.com with SMTP id r7so3991999wrz.6 for ; Tue, 21 Feb 2023 04:04:06 -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=OKUjLOAKFbXHwJjqjnkbMGlApLgsGgSq0nNCpQ7jW8c=; b=IWY5s0yQeXG42ARJSO7RkHMDVBD8dA/8uK1uSdHDPXs6KgEfxkrwBC0kOQNxdnuAFq SsRvk8bNqJemx4x/ghqXuNSumvvYHCCEsHROA1ajPynhm67cxxSGX/jpxG987sq+79uN PeWGX88HXLbP7LQRlTPWjjfIPxkOSBNrZy8QVF/XiMsRbuo7rhZUe/QtTjjA9mwnYc/U 0OFofdxbjkRYRArhuX+NMa+Lf6y06GID+zq9/nsgg8kI96y0BtxUiTc15olAcORZSrHV 8Mqm+OseDypbXXH3flXnNOHW7zCFyL4lfdsBILurv52gA2Axsi51dz5Q/AR2ZX9vL3Fj /f+g== 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=OKUjLOAKFbXHwJjqjnkbMGlApLgsGgSq0nNCpQ7jW8c=; b=jJj8Sxe155/uH/DyE3zAdGQwmisazanfdlBamhCGhzsAOoEMZ3LC0XaUIAC4F3nNCR bcdMcnXao7tVZEXbNUHIRduJGlXbD5ivL8bn0WZj3PTzQ4jXVF0BQsNYdbQoQZOpAAcC fxKUkBGW+r0xZvXT0bjWQiFfLTtfx4lYfB+7jd6SwJG6R4jnYDpzDaNVMU4Xky68Qajz Rx2iNyt7UfzoqJRi4yv8FHQeJv6VU8ZVFFeUU0G/EogfX/1zTu/N1txhr5KwDsSgpgNZ nwl5zTEhqwe1Mwrq4KGGqKWvPzB47rZHeYV7Bl18zWcdE+xoMMve95OliXoq+l6JsAFn LU4A== X-Gm-Message-State: AO0yUKWxwuWbZvqbuYnO3TUvHB0fZ+8H5isVgzuzljcfo5L6DtPNEjTf ph16uC9kWbQPA8Ci2jJG5tczwFlX2c8+AK/PIA== X-Received: by 2002:adf:f450:0:b0:2bf:f4f7:be9c with SMTP id f16-20020adff450000000b002bff4f7be9cmr2329183wrp.14.1676981045511; Tue, 21 Feb 2023 04:04:05 -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.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:04 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 052/103] gccrs: Add missing hir lowering to function type-path segments Date: Tue, 21 Feb 2023 13:01:42 +0100 Message-Id: <20230221120230.596966-53-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.8 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 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?1758444231547974933?= X-GMAIL-MSGID: =?utf-8?q?1758444231547974933?= From: Philip Herron gcc/rust/ChangeLog: * Make-lang.in: Compile rust-ast-lower-type.cc. * ast/rust-path.h: Add `get_locus` method to `TypePathFunction`. * hir/rust-ast-lower-base.cc (ASTLowerTypePath::visit): Move implementation to rust-ast-lower-type.cc. (ASTLowerQualifiedPathInType::visit): Likewise. (ASTLoweringType::visit): Likewise. * hir/rust-ast-lower-type.h: Move implementations to source file. * hir/tree/rust-hir-path.h: Likewise. * hir/rust-ast-lower-type.cc: New file. --- gcc/rust/Make-lang.in | 1 + gcc/rust/ast/rust-path.h | 2 + gcc/rust/hir/rust-ast-lower-base.cc | 113 -------------- gcc/rust/hir/rust-ast-lower-type.cc | 232 ++++++++++++++++++++++++++++ gcc/rust/hir/rust-ast-lower-type.h | 63 +------- gcc/rust/hir/tree/rust-hir-path.h | 68 ++++---- 6 files changed, 269 insertions(+), 210 deletions(-) create mode 100644 gcc/rust/hir/rust-ast-lower-type.cc diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index 2f4f409f54f..dddc70a26ec 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -95,6 +95,7 @@ GRS_OBJS = \ rust/rust-ast-lower-pattern.o \ rust/rust-ast-lower-item.o \ rust/rust-ast-lower-expr.o \ + rust/rust-ast-lower-type.o \ rust/rust-early-name-resolver.o \ rust/rust-name-resolver.o \ rust/rust-ast-resolve.o \ diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h index 9683ad6ad68..b5c9c3aab3a 100644 --- a/gcc/rust/ast/rust-path.h +++ b/gcc/rust/ast/rust-path.h @@ -898,6 +898,8 @@ public: rust_assert (has_return_type ()); return return_type; } + + Location get_locus () const { return locus; } }; // Segment used in type path with a function argument diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc index 098014ff92b..f5402efe066 100644 --- a/gcc/rust/hir/rust-ast-lower-base.cc +++ b/gcc/rust/hir/rust-ast-lower-base.cc @@ -658,119 +658,6 @@ ASTLoweringBase::lower_self (AST::SelfParam &self) self.get_locus ()); } -void -ASTLowerTypePath::visit (AST::TypePathSegmentGeneric &segment) -{ - std::vector binding_args; // TODO - - std::string segment_name = segment.get_ident_segment ().as_string (); - bool has_separating_scope_resolution - = segment.get_separating_scope_resolution (); - - auto generic_args = lower_generic_args (segment.get_generic_args ()); - - auto crate_num = mappings->get_current_crate (); - auto hirid = mappings->get_next_hir_id (crate_num); - Analysis::NodeMapping mapping (crate_num, segment.get_node_id (), hirid, - UNKNOWN_LOCAL_DEFID); - - translated_segment - = new HIR::TypePathSegmentGeneric (std::move (mapping), segment_name, - has_separating_scope_resolution, - generic_args, segment.get_locus ()); -} - -void -ASTLowerQualifiedPathInType::visit (AST::QualifiedPathInType &path) -{ - auto crate_num = mappings->get_current_crate (); - auto hirid = mappings->get_next_hir_id (crate_num); - Analysis::NodeMapping qual_mappings ( - crate_num, path.get_qualified_path_type ().get_node_id (), hirid, - UNKNOWN_LOCAL_DEFID); - - HIR::Type *qual_type = ASTLoweringType::translate ( - path.get_qualified_path_type ().get_type ().get ()); - HIR::TypePath *qual_trait = ASTLowerTypePath::translate ( - path.get_qualified_path_type ().get_as_type_path ()); - - HIR::QualifiedPathType qual_path_type ( - qual_mappings, std::unique_ptr (qual_type), - std::unique_ptr (qual_trait), - path.get_qualified_path_type ().get_locus ()); - - translated_segment = nullptr; - path.get_associated_segment ()->accept_vis (*this); - if (translated_segment == nullptr) - { - rust_fatal_error (path.get_associated_segment ()->get_locus (), - "failed to translate AST TypePathSegment"); - return; - } - std::unique_ptr associated_segment (translated_segment); - - std::vector> translated_segments; - for (auto &seg : path.get_segments ()) - { - translated_segment = nullptr; - seg->accept_vis (*this); - if (translated_segment == nullptr) - { - rust_fatal_error (seg->get_locus (), - "failed to translte AST TypePathSegment"); - } - translated_segments.push_back ( - std::unique_ptr (translated_segment)); - } - - Analysis::NodeMapping mapping (crate_num, path.get_node_id (), hirid, - mappings->get_next_localdef_id (crate_num)); - translated = new HIR::QualifiedPathInType (std::move (mapping), - std::move (qual_path_type), - std::move (associated_segment), - std::move (translated_segments), - path.get_locus ()); -} - -void -ASTLoweringType::visit (AST::TraitObjectTypeOneBound &type) -{ - std::vector> bounds; - HIR::TypeParamBound *translated_bound - = ASTLoweringTypeBounds::translate (&type.get_trait_bound ()); - bounds.push_back (std::unique_ptr (translated_bound)); - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, type.get_node_id (), - mappings->get_next_hir_id (crate_num), - mappings->get_next_localdef_id (crate_num)); - - translated = new HIR::TraitObjectType (mapping, std::move (bounds), - type.get_locus (), type.is_dyn ()); -} - -void -ASTLoweringType::visit (AST::TraitObjectType &type) -{ - std::vector> bounds; - - for (auto &bound : type.get_type_param_bounds ()) - { - HIR::TypeParamBound *translated_bound - = ASTLoweringTypeBounds::translate (bound.get ()); - bounds.push_back ( - std::unique_ptr (translated_bound)); - } - - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, type.get_node_id (), - mappings->get_next_hir_id (crate_num), - mappings->get_next_localdef_id (crate_num)); - - translated = new HIR::TraitObjectType (mapping, std::move (bounds), - type.get_locus (), type.is_dyn ()); -} - HIR::Type * ASTLoweringBase::lower_type_no_bounds (AST::TypeNoBounds *type) { diff --git a/gcc/rust/hir/rust-ast-lower-type.cc b/gcc/rust/hir/rust-ast-lower-type.cc new file mode 100644 index 00000000000..92a14f4dacf --- /dev/null +++ b/gcc/rust/hir/rust-ast-lower-type.cc @@ -0,0 +1,232 @@ +// 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-ast-lower-type.h" + +namespace Rust { +namespace HIR { + +HIR::TypePath * +ASTLowerTypePath::translate (AST::TypePath &type) +{ + ASTLowerTypePath resolver; + type.accept_vis (resolver); + rust_assert (resolver.translated != nullptr); + return resolver.translated; +} + +void +ASTLowerTypePath::visit (AST::TypePathSegmentFunction &segment) +{ + auto crate_num = mappings->get_current_crate (); + auto hirid = mappings->get_next_hir_id (crate_num); + Analysis::NodeMapping mapping (crate_num, segment.get_node_id (), hirid, + UNKNOWN_LOCAL_DEFID); + + HIR::PathIdentSegment ident (segment.get_ident_segment ().as_string ()); + + AST::TypePathFunction &fn = segment.get_type_path_function (); + std::vector> inputs; + for (auto ¶m : fn.get_params ()) + { + HIR::Type *hir_type = ASTLoweringType::translate (param.get ()); + inputs.push_back (std::unique_ptr (hir_type)); + } + + HIR::Type *result_type + = fn.has_return_type () + ? ASTLoweringType::translate (fn.get_return_type ().get ()) + : nullptr; + + HIR::TypePathFunction function_path (std::move (inputs), + std::unique_ptr ( + result_type)); + + translated_segment = new HIR::TypePathSegmentFunction ( + mapping, std::move (ident), segment.get_separating_scope_resolution (), + std::move (function_path), segment.get_locus ()); +} + +void +ASTLowerTypePath::visit (AST::TypePathSegment &segment) +{ + auto crate_num = mappings->get_current_crate (); + auto hirid = mappings->get_next_hir_id (crate_num); + Analysis::NodeMapping mapping (crate_num, segment.get_node_id (), hirid, + UNKNOWN_LOCAL_DEFID); + + HIR::PathIdentSegment ident (segment.get_ident_segment ().as_string ()); + translated_segment + = new HIR::TypePathSegment (std::move (mapping), ident, + segment.get_separating_scope_resolution (), + segment.get_locus ()); +} + +void +ASTLowerTypePath::visit (AST::TypePathSegmentGeneric &segment) +{ + std::vector binding_args; // TODO + + std::string segment_name = segment.get_ident_segment ().as_string (); + bool has_separating_scope_resolution + = segment.get_separating_scope_resolution (); + + auto generic_args = lower_generic_args (segment.get_generic_args ()); + + auto crate_num = mappings->get_current_crate (); + auto hirid = mappings->get_next_hir_id (crate_num); + Analysis::NodeMapping mapping (crate_num, segment.get_node_id (), hirid, + UNKNOWN_LOCAL_DEFID); + + translated_segment + = new HIR::TypePathSegmentGeneric (std::move (mapping), segment_name, + has_separating_scope_resolution, + generic_args, segment.get_locus ()); +} + +void +ASTLowerTypePath::visit (AST::TypePath &path) +{ + std::vector> translated_segments; + + for (auto &seg : path.get_segments ()) + { + translated_segment = nullptr; + seg->accept_vis (*this); + if (translated_segment == nullptr) + { + rust_fatal_error (seg->get_locus (), + "failed to translate AST TypePathSegment"); + } + translated_segments.push_back ( + std::unique_ptr (translated_segment)); + } + + auto crate_num = mappings->get_current_crate (); + auto hirid = mappings->get_next_hir_id (crate_num); + Analysis::NodeMapping mapping (crate_num, path.get_node_id (), hirid, + mappings->get_next_localdef_id (crate_num)); + + translated + = new HIR::TypePath (std::move (mapping), std::move (translated_segments), + path.get_locus (), + path.has_opening_scope_resolution_op ()); +} + +HIR::QualifiedPathInType * +ASTLowerQualifiedPathInType::translate (AST::QualifiedPathInType &type) +{ + ASTLowerQualifiedPathInType resolver; + type.accept_vis (resolver); + rust_assert (resolver.translated != nullptr); + return resolver.translated; +} + +void +ASTLowerQualifiedPathInType::visit (AST::QualifiedPathInType &path) +{ + auto crate_num = mappings->get_current_crate (); + auto hirid = mappings->get_next_hir_id (crate_num); + Analysis::NodeMapping qual_mappings ( + crate_num, path.get_qualified_path_type ().get_node_id (), hirid, + UNKNOWN_LOCAL_DEFID); + + HIR::Type *qual_type = ASTLoweringType::translate ( + path.get_qualified_path_type ().get_type ().get ()); + HIR::TypePath *qual_trait = ASTLowerTypePath::translate ( + path.get_qualified_path_type ().get_as_type_path ()); + + HIR::QualifiedPathType qual_path_type ( + qual_mappings, std::unique_ptr (qual_type), + std::unique_ptr (qual_trait), + path.get_qualified_path_type ().get_locus ()); + + translated_segment = nullptr; + path.get_associated_segment ()->accept_vis (*this); + if (translated_segment == nullptr) + { + rust_fatal_error (path.get_associated_segment ()->get_locus (), + "failed to translate AST TypePathSegment"); + return; + } + std::unique_ptr associated_segment (translated_segment); + + std::vector> translated_segments; + for (auto &seg : path.get_segments ()) + { + translated_segment = nullptr; + seg->accept_vis (*this); + if (translated_segment == nullptr) + { + rust_fatal_error (seg->get_locus (), + "failed to translte AST TypePathSegment"); + } + translated_segments.push_back ( + std::unique_ptr (translated_segment)); + } + + Analysis::NodeMapping mapping (crate_num, path.get_node_id (), hirid, + mappings->get_next_localdef_id (crate_num)); + translated = new HIR::QualifiedPathInType (std::move (mapping), + std::move (qual_path_type), + std::move (associated_segment), + std::move (translated_segments), + path.get_locus ()); +} + +void +ASTLoweringType::visit (AST::TraitObjectTypeOneBound &type) +{ + std::vector> bounds; + HIR::TypeParamBound *translated_bound + = ASTLoweringTypeBounds::translate (&type.get_trait_bound ()); + bounds.push_back (std::unique_ptr (translated_bound)); + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, type.get_node_id (), + mappings->get_next_hir_id (crate_num), + mappings->get_next_localdef_id (crate_num)); + + translated = new HIR::TraitObjectType (mapping, std::move (bounds), + type.get_locus (), type.is_dyn ()); +} + +void +ASTLoweringType::visit (AST::TraitObjectType &type) +{ + std::vector> bounds; + + for (auto &bound : type.get_type_param_bounds ()) + { + HIR::TypeParamBound *translated_bound + = ASTLoweringTypeBounds::translate (bound.get ()); + bounds.push_back ( + std::unique_ptr (translated_bound)); + } + + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, type.get_node_id (), + mappings->get_next_hir_id (crate_num), + mappings->get_next_localdef_id (crate_num)); + + translated = new HIR::TraitObjectType (mapping, std::move (bounds), + type.get_locus (), type.is_dyn ()); +} + +} // namespace HIR +} // namespace Rust diff --git a/gcc/rust/hir/rust-ast-lower-type.h b/gcc/rust/hir/rust-ast-lower-type.h index 56442110e07..a0761023ce8 100644 --- a/gcc/rust/hir/rust-ast-lower-type.h +++ b/gcc/rust/hir/rust-ast-lower-type.h @@ -32,59 +32,12 @@ protected: using Rust::HIR::ASTLoweringBase::visit; public: - static HIR::TypePath *translate (AST::TypePath &type) - { - ASTLowerTypePath resolver; - type.accept_vis (resolver); - rust_assert (resolver.translated != nullptr); - return resolver.translated; - } - - void visit (AST::TypePathSegmentFunction &) override { gcc_unreachable (); } - - void visit (AST::TypePathSegment &segment) override - { - auto crate_num = mappings->get_current_crate (); - auto hirid = mappings->get_next_hir_id (crate_num); - Analysis::NodeMapping mapping (crate_num, segment.get_node_id (), hirid, - UNKNOWN_LOCAL_DEFID); - - HIR::PathIdentSegment ident (segment.get_ident_segment ().as_string ()); - translated_segment - = new HIR::TypePathSegment (std::move (mapping), ident, - segment.get_separating_scope_resolution (), - segment.get_locus ()); - } + static HIR::TypePath *translate (AST::TypePath &type); + void visit (AST::TypePathSegmentFunction &segment) override; + void visit (AST::TypePathSegment &segment) override; void visit (AST::TypePathSegmentGeneric &segment) override; - - void visit (AST::TypePath &path) override - { - std::vector> translated_segments; - - for (auto &seg : path.get_segments ()) - { - translated_segment = nullptr; - seg->accept_vis (*this); - if (translated_segment == nullptr) - { - rust_fatal_error (seg->get_locus (), - "failed to translate AST TypePathSegment"); - } - translated_segments.push_back ( - std::unique_ptr (translated_segment)); - } - - auto crate_num = mappings->get_current_crate (); - auto hirid = mappings->get_next_hir_id (crate_num); - Analysis::NodeMapping mapping (crate_num, path.get_node_id (), hirid, - mappings->get_next_localdef_id (crate_num)); - - translated - = new HIR::TypePath (std::move (mapping), std::move (translated_segments), - path.get_locus (), - path.has_opening_scope_resolution_op ()); - } + void visit (AST::TypePath &path) override; protected: HIR::TypePathSegment *translated_segment; @@ -98,13 +51,7 @@ class ASTLowerQualifiedPathInType : public ASTLowerTypePath using ASTLowerTypePath::visit; public: - static HIR::QualifiedPathInType *translate (AST::QualifiedPathInType &type) - { - ASTLowerQualifiedPathInType resolver; - type.accept_vis (resolver); - rust_assert (resolver.translated != nullptr); - return resolver.translated; - } + static HIR::QualifiedPathInType *translate (AST::QualifiedPathInType &type); void visit (AST::QualifiedPathInType &path) override; diff --git a/gcc/rust/hir/tree/rust-hir-path.h b/gcc/rust/hir/tree/rust-hir-path.h index 64df6f7fd02..fa8347b2cf8 100644 --- a/gcc/rust/hir/tree/rust-hir-path.h +++ b/gcc/rust/hir/tree/rust-hir-path.h @@ -529,24 +529,9 @@ protected: struct TypePathFunction { private: - // TODO: remove - /*bool has_inputs; - TypePathFnInputs inputs;*/ - // inlined from TypePathFnInputs std::vector > inputs; - - // bool has_type; std::unique_ptr return_type; - // FIXME: think of better way to mark as invalid than taking up storage - bool is_invalid; - - // TODO: should this have location info? - -protected: - // Constructor only used to create invalid type path functions. - TypePathFunction (bool is_invalid) : is_invalid (is_invalid) {} - public: // Returns whether the return type of the function has been specified. bool has_return_type () const { return return_type != nullptr; } @@ -554,31 +539,19 @@ public: // Returns whether the function has inputs. bool has_inputs () const { return !inputs.empty (); } - // Returns whether function is in an error state. - bool is_error () const { return is_invalid; } - - // Creates an error state function. - static TypePathFunction create_error () { return TypePathFunction (true); } - - // Constructor - TypePathFunction (std::vector > inputs, - Type *type = nullptr) - : inputs (std::move (inputs)), return_type (type), is_invalid (false) - {} - // FIXME: deprecated - // Constructor TypePathFunction (std::vector > inputs, - std::unique_ptr type = nullptr) - : inputs (std::move (inputs)), return_type (std::move (type)), - is_invalid (false) + std::unique_ptr type) + : inputs (std::move (inputs)), return_type (std::move (type)) {} // Copy constructor with clone TypePathFunction (TypePathFunction const &other) - : return_type (other.return_type->clone_type ()), - is_invalid (other.is_invalid) { + return_type = other.has_return_type () + ? other.get_return_type ()->clone_type () + : nullptr; + inputs.reserve (other.inputs.size ()); for (const auto &e : other.inputs) inputs.push_back (e->clone_type ()); @@ -589,8 +562,9 @@ public: // Overloaded assignment operator to clone type TypePathFunction &operator= (TypePathFunction const &other) { - return_type = other.return_type->clone_type (); - is_invalid = other.is_invalid; + return_type = other.has_return_type () + ? other.get_return_type ()->clone_type () + : nullptr; inputs.reserve (other.inputs.size ()); for (const auto &e : other.inputs) @@ -604,6 +578,23 @@ public: TypePathFunction &operator= (TypePathFunction &&other) = default; std::string as_string () const; + + const std::vector > &get_params () const + { + return inputs; + }; + std::vector > &get_params () { return inputs; }; + + const std::unique_ptr &get_return_type () const + { + rust_assert (has_return_type ()); + return return_type; + }; + std::unique_ptr &get_return_type () + { + rust_assert (has_return_type ()); + return return_type; + }; }; // Segment used in type path with a function argument @@ -638,10 +629,9 @@ public: void accept_vis (HIRFullVisitor &vis) override; - virtual SegmentType get_type () const override final - { - return SegmentType::FUNCTION; - } + SegmentType get_type () const override final { return SegmentType::FUNCTION; } + + TypePathFunction &get_function_path () { return function_path; } protected: // Use covariance to override base class method From patchwork Tue Feb 21 12:01:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59999 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1833561wrn; Tue, 21 Feb 2023 04:29:51 -0800 (PST) X-Google-Smtp-Source: AK7set8EpF9meEKHyTlTZxoNBZFrkFzbkf06JG8/RCh/M9pF9lsLKCJ04r/6+JIo2voDkKsaDYGf X-Received: by 2002:a17:906:304e:b0:8aa:be1a:c4bf with SMTP id d14-20020a170906304e00b008aabe1ac4bfmr10357368ejd.16.1676982591113; Tue, 21 Feb 2023 04:29:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982591; cv=none; d=google.com; s=arc-20160816; b=GX0bOeLax8d/9xphCg/wJIYRYqMSwnKTwEMqqwL6MoiuXnb27vD0v2KNYjz4ggMEf3 9K2TYcg1FA5+uPumP2q3oLWbqBBZkEyi8dUeJIqGlZfDgbAYxwtJNG8OXiHg5SpdS7QG mM2vrGbW163ymcQ+Cfu8+Hrkxbd5FZGZpUjAGLH/YaZKrs+2aY0tghl06Ou4Wi81gzDJ rTd6aZi6qhPK7/Zq1gdl50JtGchlIQtivZJT8g2QMOCfKHylBa0OgLqkf8F4xwF4FC0h 5ZZu2i0vRHMU6w6ELhq9XrYaWdDNSlxGceJf/oYmFe+hxUNiECS4ch5BILa/ryrA474Z 8zDQ== 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=RnXwxXJcMqT0unhfwV0db+jGuzoB00BPT1OUeIgVUSQ=; b=WhLcr8V+9uGaCOrTL+GDIuyPO4W07l5AOg/Z+ERQRM1FsJAoofPAyKNQzhobYeyLEZ VjFFxwXOnxXXoJre8qIfgjZdF5KGinLcGon0mBGae25LuJfeewD9K2ynDDWT0BPozajH XpuhsbHVLHV2OZxUlN6+/4PFhoZ9gWf9V2Frf2Qk9b0tJ7qVoKZ9Aq4Tg8MTqo6sy3va OH/LgbmJ5mYUE+pEhJewk/HVpuYQ55i63zZ2iTf9h0MMNl4lzObzeLsX2hJA2h8c7SE4 9PeNwJFTi+ycSAAekOs/VdV8WN5VrQD0NwFQczPrWzA+LMQT9Gc9wV3EjzD/BlgmGYYC 5LwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=MXUsdwHR; 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 fw37-20020a170907502500b008d21d51c307si7215733ejc.383.2023.02.21.04.29.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:29:51 -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=MXUsdwHR; 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 B3B953873BE0 for ; Tue, 21 Feb 2023 12:11:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id A8FF3384DD3C for ; Tue, 21 Feb 2023 12:04:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A8FF3384DD3C 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-x431.google.com with SMTP id r7so3992032wrz.6 for ; Tue, 21 Feb 2023 04:04:07 -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=RnXwxXJcMqT0unhfwV0db+jGuzoB00BPT1OUeIgVUSQ=; b=MXUsdwHRcVYGse3qbma1tj6PiJfuNnte6EUNITOXpXo/i3s8vISPcGPr6ZZlFlwnMa kM494z5yyG+184/hpoAOjAzqOFFYB0/dsYJ4IjpC0/7DBo33x+Q77Fj4Z8kqWeoVjMHk 2d9WoKh5K5i1NM0QYrK9o+GMt1wHyWBmdZyc9JMMWUkkYUj0bPCRCj0kr74iuGy0RjOK eZXSxjUDif1jDCJ9h/aqbWx+FY5hIUnQCAeL8YPXCGSlauNGskjpEsdzIDMJGlXGA9jc AENz9yAxNsUWd29xSFZWGQ/KvMqm8I7+gXInu46HP73WjoH70wdskxRSJi/jovvSc9ta Sa/g== 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=RnXwxXJcMqT0unhfwV0db+jGuzoB00BPT1OUeIgVUSQ=; b=Va+HSvtaLSn/JOJ5WLCWfiVrsp41XegG32iSuGLEqXm0XqOz3zR+AwJrLXPGZM9RVJ qcPXOE8XM5hiIB55sczpitG3rbBQXFldfJS++0C+Iw6ueoYO9EAHJ8FEfRmRiz4lojha DJUZ82CiRGt/FEqy3s2eJ5foR2ldNAEsvOFFwe/WXg0H6TEj7sTl9lvBvRxO3A09yaWE m6Smt3wZKHu0BCWWPrNFSMUs6k1woCRr+pPAwbCmYu4mCbiU4uY+MFo9zcRxAWa7j4Mn Lu1BOIDu9WE7dxnb7z/q6p5yqbBWDsSbnZvQv4xUMZBIZynFg1vvruzyDk48KB/Jl47f AI5w== X-Gm-Message-State: AO0yUKUPq8EisRfo8mo7e/XpF2YV35LAgCtpsAPYwFGmzN2CgFd6XQTw j+m68zGH4OFdmAf9NTqdKrgpLM2Dnu8eNGY2xw== X-Received: by 2002:a05:6000:c2:b0:2c5:55a1:c7fe with SMTP id q2-20020a05600000c200b002c555a1c7femr2971891wrx.8.1676981046245; Tue, 21 Feb 2023 04:04:06 -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.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:05 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 053/103] gccrs: Add missing type resolution for function type segments Date: Tue, 21 Feb 2023 13:01:43 +0100 Message-Id: <20230221120230.596966-54-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.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=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?1758443697437472252?= X-GMAIL-MSGID: =?utf-8?q?1758443697437472252?= From: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-tyty-bounds.cc (TypeCheckBase::get_predicate_from_bound): Add missing implementation. --- gcc/rust/typecheck/rust-tyty-bounds.cc | 69 +++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 7 deletions(-) diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc b/gcc/rust/typecheck/rust-tyty-bounds.cc index 1a2ed3b7422..20a81ada6c4 100644 --- a/gcc/rust/typecheck/rust-tyty-bounds.cc +++ b/gcc/rust/typecheck/rust-tyty-bounds.cc @@ -84,16 +84,71 @@ TypeCheckBase::get_predicate_from_bound (HIR::TypePath &type_path) = HIR::GenericArgs::create_empty (type_path.get_locus ()); auto &final_seg = type_path.get_final_segment (); - if (final_seg->is_generic_segment ()) + switch (final_seg->get_type ()) { - auto final_generic_seg - = static_cast (final_seg.get ()); - if (final_generic_seg->has_generic_args ()) - { - args = final_generic_seg->get_generic_args (); - } + case HIR::TypePathSegment::SegmentType::GENERIC: { + auto final_generic_seg + = static_cast (final_seg.get ()); + if (final_generic_seg->has_generic_args ()) + { + args = final_generic_seg->get_generic_args (); + } + } + break; + + case HIR::TypePathSegment::SegmentType::FUNCTION: { + auto final_function_seg + = static_cast (final_seg.get ()); + auto &fn = final_function_seg->get_function_path (); + + // we need to make implicit generic args which must be an implicit Tuple + auto crate_num = mappings->get_current_crate (); + HirId implicit_args_id = mappings->get_next_hir_id (); + Analysis::NodeMapping mapping (crate_num, + final_seg->get_mappings ().get_nodeid (), + implicit_args_id, UNKNOWN_LOCAL_DEFID); + + std::vector> params_copy; + for (auto &p : fn.get_params ()) + { + params_copy.push_back (p->clone_type ()); + } + + HIR::TupleType *implicit_tuple + = new HIR::TupleType (mapping, std::move (params_copy), + final_seg->get_locus ()); + + std::vector> inputs; + inputs.push_back (std::unique_ptr (implicit_tuple)); + + args = HIR::GenericArgs ({} /* lifetimes */, + std::move (inputs) /* type_args*/, + {} /* binding_args*/, {} /* const_args */, + final_seg->get_locus ()); + + // resolve the fn_once_output type + TyTy::BaseType *fn_once_output_ty + = fn.has_return_type () + ? TypeCheckType::Resolve (fn.get_return_type ().get ()) + : TyTy::TupleType::get_unit_type ( + final_seg->get_mappings ().get_hirid ()); + context->insert_implicit_type (final_seg->get_mappings ().get_hirid (), + fn_once_output_ty); + + // setup the associated type.. ?? + // fn_once_output_ty->debug (); + } + break; + + default: + /* nothing to do */ + break; } + // FIXME + // I think this should really be just be if the !args.is_empty() because + // someone might wrongly apply generic arguments where they should not and + // they will be missing error diagnostics if (predicate.requires_generic_args ()) { // this is applying generic arguments to a trait reference From patchwork Tue Feb 21 12:01:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60004 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1834556wrn; Tue, 21 Feb 2023 04:32:02 -0800 (PST) X-Google-Smtp-Source: AK7set+oBg7kxxOUctzYj7vYR8ZZYhwz37QtxFpJxHc6lyB3x95fdtvs7ZLBC6Vm5L5JRC+SLM3I X-Received: by 2002:a17:906:2993:b0:881:23a:aba5 with SMTP id x19-20020a170906299300b00881023aaba5mr10948478eje.11.1676982722483; Tue, 21 Feb 2023 04:32:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982722; cv=none; d=google.com; s=arc-20160816; b=RfwrmahzjAJQGw6/MILDfN301Cv3/RaJGEWOEhs8pLlhK8LCRwlRvf4MVEHU6Bz5xF 1ho5NJKLjSQb6DOrUBqAF87ZQTMi50O+sWzqBeHm6sct0B9oRT98Scu/FbcS1FGApDyC 6fsyT14BIXm7F9fDA8F6b+QZZHe+dLAOcKPSx70Gu3albrHrUnFeX575ePUyJbkJ+eMM gomAfYxse/tAXWOrMZ2SK57S3zQMiTHx6Qbnah6xLMOF9kaWFBnMTy6QDX2wSkSrkZDp AUx0iHnAH9xDdLjM07j+rKIL2B2nnYi6wiU85T9sCvFA1dNnb6Ge96ybokQDC4Ad6iRE 2FFg== 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=DyIW1+oDgSzhRnE28nbxqnk8ukPdAgXqz5DDTys8nMk=; b=aqjCU15gNh03Pk5Fjz8OcVK1d8KCbyHeSXa0m3HvWTHm21/sWCc8dxM5PaweHja061 RQbFMgR++K6WloIBv8wSITCyqaFHC7ad8I0E8o3DBNePec5FM8NfV1WXrlDH1oKlalhP akN6wJmlIb08OVCTv72VxYjxw5qzzz5SJRasnQDE9hDY5Wm1qYLxBvHKu/idOZrmI8X+ Lq9WpRYVS3U06ZipXwygFyGLWRGSHgDQSGaN/9r5qbr/mUkVXF0CXD15CWx+Bo29CbrK VyT4F0fv9di1cAWhR+Y5OXc6glurkGjVZWMaMOtubQwmmfVJKel3bJaiz/26fp8gj6/N esDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Ud25AQqg; 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 f4-20020a1709063f4400b008b1737316cdsi18227675ejj.720.2023.02.21.04.32.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:32:02 -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=Ud25AQqg; 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 228EE38883FC for ; Tue, 21 Feb 2023 12:11:52 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 95868383D98B for ; Tue, 21 Feb 2023 12:04:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 95868383D98B 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-x436.google.com with SMTP id z8so3884159wrm.8 for ; Tue, 21 Feb 2023 04:04:07 -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=DyIW1+oDgSzhRnE28nbxqnk8ukPdAgXqz5DDTys8nMk=; b=Ud25AQqgQELrw5eXsswMcECfu7QsI/hmeN1LYbXukfIXEktJAnfL/9yD2KOnTaq3pZ pdLHX1wh+8Vhai9Btb7jz4b29LKlH1WjbspQG0fyYVR0G2NZH+4yBfvzbrxbf+mYO2eI vRZJlNsdNWTcyKWX6/vZatiseIxclh7sWUqIYvQ1Hye49NOpvQKJrmv5ciXDn5JYGQf6 o2X2lxvyH+slWI78bCLSuVcBBPJFsmgjZtzgPI2YKk2WODs3nEKnzCKDyhT5c1Bedr6B lV3kQA6WZlj2odduVN/nq8spc7NmIwW03IkjIRY9orymagUIWOccov+TkzKOWQvwGM7I Ke8w== 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=DyIW1+oDgSzhRnE28nbxqnk8ukPdAgXqz5DDTys8nMk=; b=6k6Pbbksgan7YBc6uH8bKPaZC47PCstDQ98yvx1K3jJY+tChR09bAuGA+e0kO+b5gN 5dFs9wmSnswcB/1BeRCOEWYffaLsn1hkU04bsknxanKGGhEixVypxvGWFxYSRg9CJg8s jZvYtFSdCk8ncRJ1Uaso5gJC/oLGrsACO7YwG3LZSZMf7oi4lcVsfCaUrV1wKoZRgfVV o2bpo5pcUIRNoTL1AQitlFI0JpvpNAQTAY+Shv1q/mNov0O/Ln1AOuoLhyyV0C4x4moi KUHKNqf4G60FzPOneT8FCXABvVul52u2Js+vul80z5wQt08uV4U4TGjih7p+9Z7LXwzL rbHw== X-Gm-Message-State: AO0yUKWJK2ixScVyVUP1zr07vj2xHe5rJNKsBnwHSIaW3jyZUTDGqVVg fXRJcsRpiUdh5lPSp8xufZBN0PaYvia2OYCwqA== X-Received: by 2002:a5d:5306:0:b0:2c5:588f:c5c4 with SMTP id e6-20020a5d5306000000b002c5588fc5c4mr2804459wrv.37.1676981046911; Tue, 21 Feb 2023 04:04:06 -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.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:06 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 054/103] gccrs: Support Closure calls as generic trait bounds Date: Tue, 21 Feb 2023 13:01:44 +0100 Message-Id: <20230221120230.596966-55-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.3 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?1758443834933792209?= X-GMAIL-MSGID: =?utf-8?q?1758443834933792209?= From: Philip Herron gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): Refactor checking of closures. (CompileExpr::generate_possible_fn_trait_call): New function. * backend/rust-compile-expr.h: Declare `generate_possible_fn_trait_call`. gcc/testsuite/ChangeLog: * rust/execute/torture/closure2.rs: New test. --- gcc/rust/backend/rust-compile-expr.cc | 116 +++++++++++------- gcc/rust/backend/rust-compile-expr.h | 3 + .../rust/execute/torture/closure2.rs | 32 +++++ 3 files changed, 104 insertions(+), 47 deletions(-) create mode 100644 gcc/testsuite/rust/execute/torture/closure2.rs diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index d2d9ae0a233..8169ba02b84 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -1693,53 +1693,10 @@ CompileExpr::visit (HIR::CallExpr &expr) auto fn_address = CompileExpr::Compile (expr.get_fnexpr (), ctx); // is this a closure call? - if (RS_CLOSURE_TYPE_P (TREE_TYPE (fn_address))) - { - rust_assert (tyty->get_kind () == TyTy::TypeKind::CLOSURE); - TyTy::ClosureType *closure = static_cast (tyty); - - std::vector tuple_arg_vals; - for (auto &argument : expr.get_arguments ()) - { - auto rvalue = CompileExpr::Compile (argument.get (), ctx); - tuple_arg_vals.push_back (rvalue); - } - - tree tuple_args_tyty - = TyTyResolveCompile::compile (ctx, &closure->get_parameters ()); - tree tuple_args - = ctx->get_backend ()->constructor_expression (tuple_args_tyty, false, - tuple_arg_vals, -1, - expr.get_locus ()); - - // need to apply any autoderef's to the self argument - HirId autoderef_mappings_id = expr.get_mappings ().get_hirid (); - std::vector *adjustments = nullptr; - bool ok - = ctx->get_tyctx ()->lookup_autoderef_mappings (autoderef_mappings_id, - &adjustments); - rust_assert (ok); - - // apply adjustments for the fn call - tree self - = resolve_adjustements (*adjustments, fn_address, expr.get_locus ()); - - // args are always self, and the tuple of the args we are passing where - // self is the path of the call-expr in this case the fn_address - std::vector args; - args.push_back (self); - args.push_back (tuple_args); - - // get the fn call address - tree closure_call_site = ctx->lookup_closure_decl (closure); - tree closure_call_address - = address_expression (closure_call_site, expr.get_locus ()); - translated - = ctx->get_backend ()->call_expression (closure_call_address, args, - nullptr /* static chain ?*/, - expr.get_locus ()); - return; - } + bool possible_trait_call + = generate_possible_fn_trait_call (expr, fn_address, &translated); + if (possible_trait_call) + return; bool is_varadic = false; if (tyty->get_kind () == TyTy::TypeKind::FNDEF) @@ -3073,5 +3030,70 @@ CompileExpr::generate_closure_fntype (HIR::ClosureExpr &expr, return TyTyResolveCompile::compile (ctx, item_tyty); } +bool +CompileExpr::generate_possible_fn_trait_call (HIR::CallExpr &expr, + tree receiver, tree *result) +{ + TyTy::FnType *fn_sig = nullptr; + bool found_overload = ctx->get_tyctx ()->lookup_operator_overload ( + expr.get_mappings ().get_hirid (), &fn_sig); + if (!found_overload) + return false; + + auto id = fn_sig->get_ty_ref (); + auto dId = fn_sig->get_id (); + + tree function = error_mark_node; + bool found_closure = ctx->lookup_function_decl (id, &function, dId, fn_sig); + if (!found_closure) + { + // something went wrong we still return true as this was meant to be an fn + // trait call + *result = error_mark_node; + return true; + } + + // need to apply any autoderef's to the self argument + HirId autoderef_mappings_id = expr.get_mappings ().get_hirid (); + std::vector *adjustments = nullptr; + bool ok = ctx->get_tyctx ()->lookup_autoderef_mappings (autoderef_mappings_id, + &adjustments); + rust_assert (ok); + + // apply adjustments for the fn call + tree self = resolve_adjustements (*adjustments, receiver, expr.get_locus ()); + + // resolve the arguments + std::vector tuple_arg_vals; + for (auto &argument : expr.get_arguments ()) + { + auto rvalue = CompileExpr::Compile (argument.get (), ctx); + tuple_arg_vals.push_back (rvalue); + } + + // this is always the 2nd argument in the function signature + tree fnty = TREE_TYPE (function); + tree fn_arg_tys = TYPE_ARG_TYPES (fnty); + tree tuple_args_tyty_chain = TREE_CHAIN (fn_arg_tys); + tree tuple_args_tyty = TREE_VALUE (tuple_args_tyty_chain); + + tree tuple_args + = ctx->get_backend ()->constructor_expression (tuple_args_tyty, false, + tuple_arg_vals, -1, + expr.get_locus ()); + + // args are always self, and the tuple of the args we are passing where + // self is the path of the call-expr in this case the fn_address + std::vector args; + args.push_back (self); + args.push_back (tuple_args); + + tree call_address = address_expression (function, expr.get_locus ()); + *result = ctx->get_backend ()->call_expression (call_address, args, + nullptr /* static chain ?*/, + expr.get_locus ()); + return true; +} + } // namespace Compile } // namespace Rust diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index c734406e0da..150a7a4788a 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -152,6 +152,9 @@ protected: tree compiled_closure_tyty, TyTy::FnType **fn_tyty); + bool generate_possible_fn_trait_call (HIR::CallExpr &expr, tree receiver, + tree *result); + private: CompileExpr (Context *ctx); diff --git a/gcc/testsuite/rust/execute/torture/closure2.rs b/gcc/testsuite/rust/execute/torture/closure2.rs new file mode 100644 index 00000000000..45b3b5ce8b4 --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/closure2.rs @@ -0,0 +1,32 @@ +// { dg-output "3\n" } +extern "C" { + fn printf(s: *const i8, ...); +} + +#[lang = "fn_once"] +pub trait FnOnce { + #[lang = "fn_once_output"] + type Output; + + extern "rust-call" fn call_once(self, args: Args) -> Self::Output; +} + +fn f i32>(g: F) { + let call = g(1); + unsafe { + let a = "%i\n\0"; + let b = a as *const str; + let c = b as *const i8; + + printf(c, call); + } +} + +pub fn main() -> i32 { + let a = |i: i32| { + let b = i + 2; + b + }; + f(a); + 0 +} From patchwork Tue Feb 21 12:01:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60045 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1842227wrn; Tue, 21 Feb 2023 04:49:39 -0800 (PST) X-Google-Smtp-Source: AK7set/vAO2/RCUhEJpZiVKsMtVE8IvrRIWzaQ7qBA/7M5AIMGJLVQfDnsaoM7ykQWU+MhkwGQyB X-Received: by 2002:a17:907:7f27:b0:8d5:f77:284d with SMTP id qf39-20020a1709077f2700b008d50f77284dmr6792123ejc.21.1676983779530; Tue, 21 Feb 2023 04:49:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983779; cv=none; d=google.com; s=arc-20160816; b=TlGOrSnfm5NbTBR/NZTcxAHoDUlH8BPXzf2W5DFyK4vstO54YvYAAM/uegRv2BBgPL y7ikjkbVYhoUqWVo6xl0786qvBFDNBvFkys3wvAYVaTzRcIZyfkwzO3zKgsjXuOyVCZu FeYaMBkRqD+5sOZmTH98ZJX8bwHwVsFMjho+QWAVmm9Y25ZXEIJFiYjNQTTeNf7z9/eI pQ4r91w2U+iz4pzdcCuy/GRLysHHYchbpg00baJg0N0xoHlvujVeh6NoMSA9QjvCWXaX wgfLgd2wqXnNCYJ/WlXfAR9UiV2dPrNWikAWqj1BwNna2066yGYH+QKQYNG9uUCIrZs6 0t8w== 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=eQjqnCabeSQGQ4Q9UTx1rnkZ8Ka6kmB8wDytSJyo+3w=; b=NLLK1/u4e9/0Fo+mc8L8n7Z9H2khaJoCKZ4MofQzA/d/D9s6kBATY6HCoyGGaH8q6j 8BBaqHJL/nLW6cdm+Z6uvMTYcP0703FcgXmQTnik1fjRr9p5gFH+b371rMM1zqMxYWMp GKNJ52J5XPfZQi4e7+KvjZySH9NEX1T7j9S58wgHnOrVqFabSfZVzDsAuvs+mGDznRbf L5TuC+qUyCAIiIvWJV6n5iaDeknxEIihnK+byyGo+pFIQQAmljrjKnUVNis7KWZiQjno wkvULLyWqpWgMjYqKebKZUbLsPCw75B5qevgrwxvj9djsLU3xh5KmkHlYF43aHkKcyMU /HNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=CsJ3R3oL; 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 n2-20020a17090673c200b008b2ab95c90asi16752129ejl.707.2023.02.21.04.49.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:49:39 -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=CsJ3R3oL; 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 2BB0D396F9E0 for ; Tue, 21 Feb 2023 12:16:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id E9905383905A for ; Tue, 21 Feb 2023 12:04:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E9905383905A 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-x436.google.com with SMTP id c5so4850235wrr.5 for ; Tue, 21 Feb 2023 04:04:08 -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=eQjqnCabeSQGQ4Q9UTx1rnkZ8Ka6kmB8wDytSJyo+3w=; b=CsJ3R3oLpAuzo4/QAUFEhSX8SuacaEVyHcS1qaywHIAnnlLoG3K+I/kvt59hXj0X59 q1YZPfRng/RzDwseirTun0dIvQVzo7Bo47S4sRY3ctAU0cK1MFab6pdmx8idwI86xNxY qIkDREPH5csP6AdlqID3xlHnbTLjxr8fMMA5a1bQ+jmeCf0/6R965K+5C9hJ2u0r1z5u +fpLVmHjDd+uGiCk7j6clliecWF3E8vw/wiSl9N/n4j216miyFq9dCt4kWxmdOsk5PYB GAlunffNCGfwHaWqsXurjh5m/hKX+L6MerlcLfGsxamZKhWL+xTtglDv6EfAsD2pzA3r aoBw== 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=eQjqnCabeSQGQ4Q9UTx1rnkZ8Ka6kmB8wDytSJyo+3w=; b=MzmfvxTggq0kEwZZkTCaU2OKMDgqrLsga/G0lCQBFDYf02nHjh2gmrpiQLvrF+9TiC XnjaTznxrz8c9RhszIMAqMD1EvjFeX9hdBKcxbfKoJpSH64noBD62EDsVS2MdOpMuQAT 7kCvBuAXW5cGJ5TaFxdmMLEMCR/UxpyV94dDK23E1V+jdDj0CiAqykaejpNUoo40hA33 n8ooNT+GPkg26hRy67kuVLmuXbGr8zrJ/Qo1u22IkpjWfAv9BVRGlaKv35EBV9AFjKHz 2jk3xOLjhEITZEbgFJ8SmDKICAfisxU8vVc6DtoSfAY9IsB0eq1rIWfgHwSnXKxPHJwX Jajg== X-Gm-Message-State: AO0yUKVHvTi45xEm+iuD0ZUxzjphbzjxggZ4iz1lvfGcLVgf3sfvRU69 wXXCVkDXDG/s/rbHUxd/ShK3R9L4tqQMw8XPyg== X-Received: by 2002:adf:e184:0:b0:2c5:5ec7:43bc with SMTP id az4-20020adfe184000000b002c55ec743bcmr2422655wrb.18.1676981047586; Tue, 21 Feb 2023 04:04:07 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:07 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, YizhePKU Subject: [committed 055/103] gccrs: Implement the inline visitor Date: Tue, 21 Feb 2023 13:01:45 +0100 Message-Id: <20230221120230.596966-56-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.3 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 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?1758444943563319701?= X-GMAIL-MSGID: =?utf-8?q?1758444943563319701?= From: YizhePKU gcc/rust/ChangeLog: * util/rust-inline-visitor.h: New file. --- gcc/rust/util/rust-inline-visitor.h | 95 +++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 gcc/rust/util/rust-inline-visitor.h diff --git a/gcc/rust/util/rust-inline-visitor.h b/gcc/rust/util/rust-inline-visitor.h new file mode 100644 index 00000000000..18920d9f93a --- /dev/null +++ b/gcc/rust/util/rust-inline-visitor.h @@ -0,0 +1,95 @@ +// Copyright (C) 2021-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 +// . + +// An improved implementation of the inline visitor. +// Original idea from https://members.accu.org/index.php/articles/2021 + +#ifndef RUST_INLINE_VISITOR +#define RUST_INLINE_VISITOR + +#include +#include + +namespace Rust { + +// Wrapper for the target Visitor we're matching against. +// Consumes the final nullptr of the _args linked list. +template struct EmptyVisitor : TargetVisitor +{ + EmptyVisitor (std::nullptr_t ptr) {} + + using TargetVisitor::visit; +}; + +// Wrapper for a (possibly incomplete) Visitor. +template struct VisitorWrapper +{ + // Lambdas are stored in _args as a linked list and passed to the actual + // visitor when end_visitor() is called. + Args _args; + + // The actual visitor being created. + // Each visitor inherits from the last one and implements one more visit(). + template struct Visitor : BaseVisitor + { + F _f; + + Visitor (std::pair &&args) + : BaseVisitor (std::move (args.second)), _f (std::move (args.first)) + {} + + using BaseVisitor::visit; + virtual void visit (T &t) final override { _f (t); } + }; + + VisitorWrapper (Args &&args) : _args (std::move (args)) {} + + // Add another visit() method to the visitor. + // _args will be moved over, so don't keep the old wrapper around. + template + VisitorWrapper, std::pair> on (F &&f) + { + return VisitorWrapper, std::pair> ( + std::make_pair (std::move (f), std::move (_args))); + } + + // Returns the finished visitor. + // NOTE: The reference implementation has a bug that exposes this method even + // when BaseVisitor is still an abstract class. The C++11 standard states that + // "An abstract class shall not be used [...] as a function return type". GCC + // rejects the buggy code as expected, but Clang accepts the code as long as + // the method is not actually called. Maybe this is a bug in Clang? + template + typename std::enable_if::value, T>::type + end_visitor () + { + return T (std::move (_args)); + } +}; + +// The entry point. +template +VisitorWrapper, std::nullptr_t> +begin_visitor () +{ + return VisitorWrapper, std::nullptr_t> (nullptr); +} + +} // namespace Rust + +#endif From patchwork Tue Feb 21 12:01:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60040 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1841306wrn; Tue, 21 Feb 2023 04:47:30 -0800 (PST) X-Google-Smtp-Source: AK7set+MX2y1s/mRPc7IbrOFbytca/8Yv2BuEaMFuaB4uTjEkCcGxNpizGJ2laux+AaRfmk6xgYJ X-Received: by 2002:a17:907:170e:b0:8b1:3483:e3d5 with SMTP id le14-20020a170907170e00b008b13483e3d5mr10866262ejc.48.1676983650607; Tue, 21 Feb 2023 04:47:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983650; cv=none; d=google.com; s=arc-20160816; b=HsgFl1KfXDSsTIP1l0oVcsrQ78PqK8B2H3dCiZazhBvv5tcu6nK7BZ5CX8cq6Tgv9O ttjKsPgdjJdvJZYPxaelvjYpvfSN9ceGPzNf4DG87rz4SMT6s3gLvVqWlWsXJRnN7kEC lcYWfB/xeCWEzTLUNB9rqNV/b+elwSm4Rs9KGA9XPi4+/7wWIBFXoBhorS5vQZ6/ENEC jc62OkmiM5a5jo3Zx/4JIfEUrK/rct0ZZEsc3D4u8CSp9mWLMbHU+BxPWsuFjzo/laVB sD7tV5w5DlDVlEwxMoellJHerFUqqsMgJEjtpE4HMAJw3gxPY0fOnbYKJjjDZPTLW6jD 2z8w== 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=H8S5iJ6nYeL94/MXpPgn8/HOKjx3mdnN2kXX1+fFH+k=; b=vwdeOaO8xztmBxosZm8/hLwEkESItgFT9R+bIUkdgcQ+5agKF9DbT7qAkl9LwgfHeC kNBVzHPO5fPt6IMdYEOqzBrHq7EQdnWJmQXOQm/MOxTfLMOYq+ucnEfAXQFwgsd31tEm c0IymijS9k5woFX3Oj9bkvnL25xD47TrpovsAn/jKVSMThI4Wqkcmll6Nha2emsCzGSj 0NUPlJjx6KO+/nClv4+1wI8BI7c2bZla4Nf5BFL0XEuqc4Tji3ZnKw3WgixkT+MCqG8T wBWJQhP+5YOpSWkRXm32EK5Xpg0xrqUZIqbstcaQmmnLAhmYoGwS/YktIEV+oftNzs+n PPJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=YbpKofq6; 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 aa23-20020a170907355700b008d80f0b9713si4444836ejc.674.2023.02.21.04.47.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:47:30 -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=YbpKofq6; 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 955AF3922AD7 for ; Tue, 21 Feb 2023 12:15:44 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id BD4F43839DFA for ; Tue, 21 Feb 2023 12:04:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BD4F43839DFA 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-x435.google.com with SMTP id l25so3758891wrb.3 for ; Tue, 21 Feb 2023 04:04:08 -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=H8S5iJ6nYeL94/MXpPgn8/HOKjx3mdnN2kXX1+fFH+k=; b=YbpKofq6dtFXyQnCBhTODNblZPCNW+qjnCceACDcONJUQQMROY+Q7TPNBfarcffeoK OIkO+xZCWAOilTGbtxnIvSn+Nf4DPhHFs3+ZzD3aKHN489FzyFNPyL2gF3fNeqaN6gUB qb3n2vA5X8dzpf5zBre1gz4WgrjB8RyaA/mYEvOCsrZjlrURbes7pDnh56N1KcPsKsRp fFpHizI05ZKN/ISaxwPsCbWuZ4Lj8puGTxcCUx2NNMJZgwHDTvh71dJD9lJ8m8jbgeYD GBaB24dxe43J7gvtn1F4aeMkVoiW2pd6SvWPs5rt6UADbn5DyjQzhIzOci3nJskz8j/E YlLA== 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=H8S5iJ6nYeL94/MXpPgn8/HOKjx3mdnN2kXX1+fFH+k=; b=NCgJrDpY3Gzb1lbduhNSujKS29PXsBph2oZD6e7ZLfPT1dK3CxeH+A260Jp0UEF/nr E2bO+TMC34k4bd0ne0YUkAbttjWEY3P5udUGli9AVBd95SFt2yLcFzoF0Gu8RoHodhO3 yf0f7aovarWVjMfut2nzxdH0MyVUu0STZbBLoYoSkzqJCuGjPmNeWf2P8xxOxxXQwnLg M7dQerS7y9xNrwQQvxzZEkqHJ9QZDJWgdefGth7895J098xgmJq31kJuKgGZqeM8qmat //9mTFo/lBtqdAinELyTSMOI1sRq9CCDuMhkipy5hAWBxjn6rgb4ybEVuO+1pIhmW3oE 9c4g== X-Gm-Message-State: AO0yUKWYQiJFbxf6oVi4UVS3GSdM7qWk0UyPJiZdJRRW7PryedsgDCv9 Avu8ozJa1775IOvKK+3txGhHXYHUxaO2HVAJKQ== X-Received: by 2002:a05:6000:1a52:b0:2c7:6bf:16cc with SMTP id t18-20020a0560001a5200b002c706bf16ccmr966576wry.32.1676981048177; Tue, 21 Feb 2023 04:04:08 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:07 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Simon Cook Subject: [committed 056/103] gccrs: rust: Allow gccrs to build on x86_64-apple-darwin with clang/libc++ Date: Tue, 21 Feb 2023 13:01:46 +0100 Message-Id: <20230221120230.596966-57-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.3 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?1758444808481340288?= X-GMAIL-MSGID: =?utf-8?q?1758444808481340288?= From: Simon Cook gcc/rust/ChangeLog: * util/rust-inline-visitor.h: Remove some offending system includes. --- gcc/rust/util/rust-inline-visitor.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/gcc/rust/util/rust-inline-visitor.h b/gcc/rust/util/rust-inline-visitor.h index 18920d9f93a..105a67b8c5c 100644 --- a/gcc/rust/util/rust-inline-visitor.h +++ b/gcc/rust/util/rust-inline-visitor.h @@ -22,9 +22,6 @@ #ifndef RUST_INLINE_VISITOR #define RUST_INLINE_VISITOR -#include -#include - namespace Rust { // Wrapper for the target Visitor we're matching against. From patchwork Tue Feb 21 12:01:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60024 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1838331wrn; Tue, 21 Feb 2023 04:40:31 -0800 (PST) X-Google-Smtp-Source: AK7set/Af47aaGqmVJZvgEjVDZOddEAXoJGsqgtEeo2va14h2v3kvRFZsGB6PhXqHTs70laSDZbW X-Received: by 2002:a17:906:e24b:b0:8ae:11ca:81de with SMTP id gq11-20020a170906e24b00b008ae11ca81demr10016829ejb.34.1676983231226; Tue, 21 Feb 2023 04:40:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983231; cv=none; d=google.com; s=arc-20160816; b=ojrXbIi3ey7TKF2pVuxw74j9Kx6vMdlQX+YUms3BRO8g3ZRhdJc/OYQicaAg+4h7b4 GXQlaSzx3lT0ae0H97qLXZgRnvopxtRxfI9ABdPVeqZTZmAaimfny4jJdsjGSc06+rvC 38v1i9yTaZX3rk3mBfbaA90943ppNlCPiNeJwxJIH37QwamdY+8O/NkF9W+el1906t4r vMe2U3IBhL16bR3fPVuvuRTB2eXVRI0jiMp8ecAnoh8azSI5YNHay7nZn4e++CRldXEK O6TlIIS5AiJ+63ZBVUD1RCcMOZE3t2N7o2K2WvphHToyo8igec0yYYKTdiLndxo+9zfD JWnw== 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=WXs6UuL1L22/MMSudGfPsJiIDR8xhfHBtSBjD1AbHLU=; b=X/Fx/BfsQ5BXVQR11T+I0EqCoamXvuNpgA2ZwK+j+fl2p/PbNXnGeaWyUGjUmMP/o5 bzzeY/POSYMFTabvTQR8FM9iWa89lz7+EV717zZgjaIXSFBpKVLKQCIUunsCrKBhx82o RfsLiKDT3pPRoLGDjW8+Glg4h8SzB4XWqwqjA9wtMs3dJdzM9qJUjlavEOwP2p4/A+ei TeoEnPzyPF9lMF30HB1t68EHWOKhTjwFT/xaVP57vykrJ9A6NHVfg1jVgk71E18NHxdx sDCBzuu2DB3euNHqZm86n1oG/CcdJaiISXCX/AtdL9F6XBWT84rExOf22LYfFadIkeFB IbJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=OxRdBQYs; 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 we24-20020a170907235800b008b2ecb065b5si12674976ejb.368.2023.02.21.04.40.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:40:31 -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=OxRdBQYs; 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 B636339896DA for ; Tue, 21 Feb 2023 12:14:01 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 69B6938323C1 for ; Tue, 21 Feb 2023 12:04:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 69B6938323C1 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-x432.google.com with SMTP id 6so3758215wrb.11 for ; Tue, 21 Feb 2023 04:04:10 -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=WXs6UuL1L22/MMSudGfPsJiIDR8xhfHBtSBjD1AbHLU=; b=OxRdBQYsGlsQMFPgqF16h0o8Fbmcjxg+GvKfkIIhmqF7ZQXDZxZyrRd8Sf1/apVvTf r3rztz95hi02j1ScBcgaGMs1Dzsps+aLG0p88WDaKzq1ITnPIN4spB1mH1pjtFJLMnky JI8mwV0i3ySQVL2usv0MfTnED4iaXqBO1B5dUx83bbJVW5EIMP6Xgcu4JCRM9qALzxir WRO92sdxnnfnHo0OzYY+3nReqyG1mhbEGtPNE9mi+GfqTFQZxzvHDfnXJ71FLbUyigiS RpvoMMetP7Q5uQRw20QJbOnWZ0DaoixFK6zT5QOb6b9VbI0Bgtuq1MPrVbNBFtO8uUnA bO+g== 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=WXs6UuL1L22/MMSudGfPsJiIDR8xhfHBtSBjD1AbHLU=; b=SJvhm0GorlF9c8gnGu6NQQEfpfaUoJ3nBqw8eAx/UPyX9OtodUz+ClMzZqrDKCkyun 4LKeLNKkD/k5HTBkvl6W+CoGmF9ohHoQ3jKx/B3xYL+ZeuyMfXl8Ptg6T1hZwehDUlwC 8mIrVMF4ddB5GTkLOrrmv+Vm3ZqwUjzewGatRme+G58NOLtmIw0mXXriuAZA//kpv3PO Bqods0tH5NANuh5Dh2pt10oJ1LVFZc8kLP9bIMG5LS09SxexD4FfCtS5e7IShcQ7dEaG 1XbPVRUGBbvA5wB0U/9l5ePpBW+OAzpAG8GOU9ZpTemsoeXLuGXiaoD4pUKy48s+xaEh q4Kg== X-Gm-Message-State: AO0yUKXGu97hxrAWcYHsARBtBmJWGS1ApmBiqgR1C87QBDzk/otZIKL4 t8qWqULj4n7Q9VSuwvpauIKs4RUI/ktnO81zWg== X-Received: by 2002:a5d:4d09:0:b0:2c5:5048:8a6a with SMTP id z9-20020a5d4d09000000b002c550488a6amr4866117wrt.60.1676981048873; Tue, 21 Feb 2023 04:04:08 -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.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:08 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 057/103] gccrs: builtins: Rename all bang macro handlers Date: Tue, 21 Feb 2023 13:01:47 +0100 Message-Id: <20230221120230.596966-58-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.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=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?1758444368582448576?= X-GMAIL-MSGID: =?utf-8?q?1758444368582448576?= From: Arthur Cohen gcc/rust/ChangeLog: * expand/rust-macro-builtins.cc (MacroBuiltin::assert): Rename to... (MacroBuiltin::assert_handler): ..this. (MacroBuiltin::file): Rename to... (MacroBuiltin::file_handler): ..this. (MacroBuiltin::column): Rename to... (MacroBuiltin::column_handler): ..this. (MacroBuiltin::include_bytes): Rename to... (MacroBuiltin::include_bytes_handler): ..this. (MacroBuiltin::include_str): Rename to... (MacroBuiltin::include_str_handler): ..this. (MacroBuiltin::compile_error): Rename to... (MacroBuiltin::compile_error_handler): ..this. (MacroBuiltin::concat): Rename to... (MacroBuiltin::concat_handler): ..this. (MacroBuiltin::env): Rename to... (MacroBuiltin::env_handler): ..this. (MacroBuiltin::cfg): Rename to... (MacroBuiltin::cfg_handler): ..this. (MacroBuiltin::include): Rename to... (MacroBuiltin::include_handler): ..this. (MacroBuiltin::line): Rename to... (MacroBuiltin::line_handler): ..this. * expand/rust-macro-builtins.h: Rename all handlers. * util/rust-hir-map.cc (Mappings::insert_macro_def): Use new handler names. --- gcc/rust/expand/rust-macro-builtins.cc | 25 ++++++++------ gcc/rust/expand/rust-macro-builtins.h | 47 ++++++++++++-------------- gcc/rust/util/rust-hir-map.cc | 22 ++++++------ 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/gcc/rust/expand/rust-macro-builtins.cc b/gcc/rust/expand/rust-macro-builtins.cc index a2129e84a46..9bed3ddbe79 100644 --- a/gcc/rust/expand/rust-macro-builtins.cc +++ b/gcc/rust/expand/rust-macro-builtins.cc @@ -265,7 +265,7 @@ load_file_bytes (const char *filename) } // namespace AST::Fragment -MacroBuiltin::assert (Location invoc_locus, AST::MacroInvocData &invoc) +MacroBuiltin::assert_handler (Location invoc_locus, AST::MacroInvocData &invoc) { rust_debug ("assert!() called"); @@ -273,7 +273,7 @@ MacroBuiltin::assert (Location invoc_locus, AST::MacroInvocData &invoc) } AST::Fragment -MacroBuiltin::file (Location invoc_locus, AST::MacroInvocData &invoc) +MacroBuiltin::file_handler (Location invoc_locus, AST::MacroInvocData &invoc) { auto current_file = Session::get_instance ().linemap->location_file (invoc_locus); @@ -283,7 +283,7 @@ MacroBuiltin::file (Location invoc_locus, AST::MacroInvocData &invoc) } AST::Fragment -MacroBuiltin::column (Location invoc_locus, AST::MacroInvocData &invoc) +MacroBuiltin::column_handler (Location invoc_locus, AST::MacroInvocData &invoc) { auto current_column = Session::get_instance ().linemap->location_to_column (invoc_locus); @@ -300,7 +300,8 @@ MacroBuiltin::column (Location invoc_locus, AST::MacroInvocData &invoc) &'static [u8; N]. */ AST::Fragment -MacroBuiltin::include_bytes (Location invoc_locus, AST::MacroInvocData &invoc) +MacroBuiltin::include_bytes_handler (Location invoc_locus, + AST::MacroInvocData &invoc) { /* Get target filename from the macro invocation, which is treated as a path relative to the include!-ing file (currently being compiled). */ @@ -343,7 +344,8 @@ MacroBuiltin::include_bytes (Location invoc_locus, AST::MacroInvocData &invoc) expression of type &'static str. */ AST::Fragment -MacroBuiltin::include_str (Location invoc_locus, AST::MacroInvocData &invoc) +MacroBuiltin::include_str_handler (Location invoc_locus, + AST::MacroInvocData &invoc) { /* Get target filename from the macro invocation, which is treated as a path relative to the include!-ing file (currently being compiled). */ @@ -368,7 +370,8 @@ MacroBuiltin::include_str (Location invoc_locus, AST::MacroInvocData &invoc) /* Expand builtin macro compile_error!("error"), which forces a compile error during the compile time. */ AST::Fragment -MacroBuiltin::compile_error (Location invoc_locus, AST::MacroInvocData &invoc) +MacroBuiltin::compile_error_handler (Location invoc_locus, + AST::MacroInvocData &invoc) { auto lit_expr = parse_single_string_literal (invoc.get_delim_tok_tree (), invoc_locus, @@ -386,7 +389,7 @@ MacroBuiltin::compile_error (Location invoc_locus, AST::MacroInvocData &invoc) into a string with no delimiter. */ AST::Fragment -MacroBuiltin::concat (Location invoc_locus, AST::MacroInvocData &invoc) +MacroBuiltin::concat_handler (Location invoc_locus, AST::MacroInvocData &invoc) { auto invoc_token_tree = invoc.get_delim_tok_tree (); MacroInvocLexer lex (invoc_token_tree.to_token_stream ()); @@ -437,7 +440,7 @@ MacroBuiltin::concat (Location invoc_locus, AST::MacroInvocData &invoc) compile time. */ AST::Fragment -MacroBuiltin::env (Location invoc_locus, AST::MacroInvocData &invoc) +MacroBuiltin::env_handler (Location invoc_locus, AST::MacroInvocData &invoc) { auto invoc_token_tree = invoc.get_delim_tok_tree (); MacroInvocLexer lex (invoc_token_tree.to_token_stream ()); @@ -495,7 +498,7 @@ MacroBuiltin::env (Location invoc_locus, AST::MacroInvocData &invoc) } AST::Fragment -MacroBuiltin::cfg (Location invoc_locus, AST::MacroInvocData &invoc) +MacroBuiltin::cfg_handler (Location invoc_locus, AST::MacroInvocData &invoc) { // only parse if not already parsed if (!invoc.is_parsed ()) @@ -534,7 +537,7 @@ MacroBuiltin::cfg (Location invoc_locus, AST::MacroInvocData &invoc) scope compile time. */ AST::Fragment -MacroBuiltin::include (Location invoc_locus, AST::MacroInvocData &invoc) +MacroBuiltin::include_handler (Location invoc_locus, AST::MacroInvocData &invoc) { /* Get target filename from the macro invocation, which is treated as a path relative to the include!-ing file (currently being compiled). */ @@ -588,7 +591,7 @@ MacroBuiltin::include (Location invoc_locus, AST::MacroInvocData &invoc) } AST::Fragment -MacroBuiltin::line (Location invoc_locus, AST::MacroInvocData &invoc) +MacroBuiltin::line_handler (Location invoc_locus, AST::MacroInvocData &invoc) { auto current_line = Session::get_instance ().linemap->location_to_line (invoc_locus); diff --git a/gcc/rust/expand/rust-macro-builtins.h b/gcc/rust/expand/rust-macro-builtins.h index c65bd940189..6d7a0123ab3 100644 --- a/gcc/rust/expand/rust-macro-builtins.h +++ b/gcc/rust/expand/rust-macro-builtins.h @@ -60,45 +60,42 @@ * of the `Mappings` class. */ -/* If assert is defined as a macro this file will not parse, so undefine this - before continuing. */ -// TODO: Rename all functions here `*_handler` -#ifdef assert -#undef assert -#endif - namespace Rust { class MacroBuiltin { public: - static AST::Fragment assert (Location invoc_locus, - AST::MacroInvocData &invoc); + static AST::Fragment assert_handler (Location invoc_locus, + AST::MacroInvocData &invoc); - static AST::Fragment file (Location invoc_locus, AST::MacroInvocData &invoc); + static AST::Fragment file_handler (Location invoc_locus, + AST::MacroInvocData &invoc); - static AST::Fragment column (Location invoc_locus, - AST::MacroInvocData &invoc); + static AST::Fragment column_handler (Location invoc_locus, + AST::MacroInvocData &invoc); - static AST::Fragment include_bytes (Location invoc_locus, - AST::MacroInvocData &invoc); + static AST::Fragment include_bytes_handler (Location invoc_locus, + AST::MacroInvocData &invoc); - static AST::Fragment include_str (Location invoc_locus, - AST::MacroInvocData &invoc); + static AST::Fragment include_str_handler (Location invoc_locus, + AST::MacroInvocData &invoc); - static AST::Fragment compile_error (Location invoc_locus, - AST::MacroInvocData &invoc); + static AST::Fragment compile_error_handler (Location invoc_locus, + AST::MacroInvocData &invoc); - static AST::Fragment concat (Location invoc_locus, - AST::MacroInvocData &invoc); + static AST::Fragment concat_handler (Location invoc_locus, + AST::MacroInvocData &invoc); - static AST::Fragment env (Location invoc_locus, AST::MacroInvocData &invoc); + static AST::Fragment env_handler (Location invoc_locus, + AST::MacroInvocData &invoc); - static AST::Fragment cfg (Location invoc_locus, AST::MacroInvocData &invoc); + static AST::Fragment cfg_handler (Location invoc_locus, + AST::MacroInvocData &invoc); - static AST::Fragment include (Location invoc_locus, - AST::MacroInvocData &invoc); + static AST::Fragment include_handler (Location invoc_locus, + AST::MacroInvocData &invoc); - static AST::Fragment line (Location invoc_locus, AST::MacroInvocData &invoc); + static AST::Fragment line_handler (Location invoc_locus, + AST::MacroInvocData &invoc); }; } // namespace Rust diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index bee0682e9b4..1fc32038d19 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -843,17 +843,17 @@ Mappings::insert_macro_def (AST::MacroRulesDefinition *macro) static std::map< std::string, std::function> builtin_macros = { - {"assert", MacroBuiltin::assert}, - {"file", MacroBuiltin::file}, - {"line", MacroBuiltin::line}, - {"column", MacroBuiltin::column}, - {"include_bytes", MacroBuiltin::include_bytes}, - {"include_str", MacroBuiltin::include_str}, - {"compile_error", MacroBuiltin::compile_error}, - {"concat", MacroBuiltin::concat}, - {"env", MacroBuiltin::env}, - {"cfg", MacroBuiltin::cfg}, - {"include", MacroBuiltin::include}, + {"assert", MacroBuiltin::assert_handler}, + {"file", MacroBuiltin::file_handler}, + {"line", MacroBuiltin::line_handler}, + {"column", MacroBuiltin::column_handler}, + {"include_bytes", MacroBuiltin::include_bytes_handler}, + {"include_str", MacroBuiltin::include_str_handler}, + {"compile_error", MacroBuiltin::compile_error_handler}, + {"concat", MacroBuiltin::concat_handler}, + {"env", MacroBuiltin::env_handler}, + {"cfg", MacroBuiltin::cfg_handler}, + {"include", MacroBuiltin::include_handler}, }; auto outer_attrs = macro->get_outer_attrs (); From patchwork Tue Feb 21 12:01:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60012 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1836416wrn; Tue, 21 Feb 2023 04:35:57 -0800 (PST) X-Google-Smtp-Source: AK7set+KWfEUoLCFS+XwwRDqjQNPqWGomb9hWXyMHx6ATcDuYbq4EHDccWgAOvMsyFL3jEy+oWIG X-Received: by 2002:aa7:d515:0:b0:4ab:db9e:9682 with SMTP id y21-20020aa7d515000000b004abdb9e9682mr4520829edq.34.1676982957582; Tue, 21 Feb 2023 04:35:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982957; cv=none; d=google.com; s=arc-20160816; b=N9bKkDrFSqvov0/Q/zmfvlWN+fBdKYiPf5OuO8cIUN7wx6tCOtTRGUaKApouX7dzLS ys8MnOD+Br9zDqDNzjx0f35cbe4Xad3VNDq38vSLDbROPLbVyNcmAIB0EZ0bQMUoXFvd qxt80tKvmh7IxBFCNaoms5iuclSjQF3fl0Q9J1c9zYeKjGF31JIFSVrhtW9p/jG0hpc5 qgN2xi3AQeQrqvpQc7P7c2uaED+PWWlLVLQFDTmyM8vPHfWYN4vR1OpXW3AkE9j2mR8T ij+BiHJKM3eQ5T0PHn2BdOMVfC97u6EnomlbWoiuqe7VHdbNr8f/mBkpCKMEfYq0Ywt7 rPIA== 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=cS4jfXy0zd9Z4iDHTUS/X0Jl6KbAr7Z+iQWYT2shEVc=; b=D1f6gJF5t/omlGA1SGlPNl3njSgs/OGM7xzOPoaNiQvvcv8RVGPrJsxByG5k6M1I+o cJ1FXYJkUS5SetSF7DtNfdk22J60cmM6AEOcz0mH4yuWAZNXzoob1c0tg5+ECjQ1Ddi8 ttum2e5NmPMcjcqg8+9CAKHMssLGjJ6f2Cedg6Xbme0OQX16ADCmhhVj4oe0v14rMffq oKR/1t78eOfUls5mfb7WV5vgwkN1vOlsl/9W/pPA8m7PUmt9UuQB0Hu8dMogaOS35fA5 ggI1BPS8ilJwPJYwHijF2SlM+TF00DCPkgJFGcfQWimCWC8YYEZU0qag2UpmI/X9B98R 6LwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=D3GHJglk; 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 u24-20020a056402065800b004ace603c65csi3793506edx.247.2023.02.21.04.35.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:35:57 -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=D3GHJglk; 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 15A5C3932E03 for ; Tue, 21 Feb 2023 12:12:53 +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 1683638493E8 for ; Tue, 21 Feb 2023 12:04:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1683638493E8 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 t15so4268473wrz.7 for ; Tue, 21 Feb 2023 04:04:10 -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=cS4jfXy0zd9Z4iDHTUS/X0Jl6KbAr7Z+iQWYT2shEVc=; b=D3GHJglkZt4pN+lNvQgmKAzjnmyISuOyvQwdvNgeaBbj7f1QWwsgnNGzyfBVLhrfWl ydoj02vn19T5N7RgG1Ed1Ch3cLWe3mI0Y33ITO9v5u9WxQm0w15Ll7FYr3+MS26NZ3e1 3gO/tNVcsGCLbHiqCo4EQAUSzRnNeY/Ts5erS4J+oBUBC8xgS228kJ4k0xnuHmXI3FkY J3KRLFEA8wzK31mhSCwmpeomHm4479qkBn17ST1e+/0iy34AK68cCeSkyXj7g+pJntXq PbpACiMmFU3MyhGMgQ5svumljQiw4O+4VBfRWMXlDio4n1CuP59D4DP2NwFktY8b9EI4 qvAQ== 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=cS4jfXy0zd9Z4iDHTUS/X0Jl6KbAr7Z+iQWYT2shEVc=; b=FFcD/HbjOlJS5wPDnpKwLRWPIILt69vw9ODy22Ea6nurk5sCZsoTn0NtJey1z+sABp tJJEQqPJF4MvIXQf8lUYaJcTc7AdFIk/qUY9fPGEmNw4k2RBbqZhW/JwTBUAcxhyhQIu T1I5UAlK1/egPTy0m2ZnIUajVXdxiQO0VStfUOx3WVc7M3Goug5h1efrqnr1wJdb5d/Y MgSa3EJWsxqQj6XsBjdzT5DU+ZQhbyoNgkP6mC0xsLt895qHOnFlvit62JUTa32i4D21 AwCcT6RczfOit0sn9mwWA1hIThyOp+NYYoqKumAIovnXMEcmry9HlgFwApw9LEzXilOz usFA== X-Gm-Message-State: AO0yUKV8PbId2Cxd1NIVxJbW58BMnVwlU7Rgi5guYDTpq82nal5zlKtd zJoW0Fd/2yvKKAH/kOJZGwAIj3vJ7S7dbi8PSA== X-Received: by 2002:a5d:62c7:0:b0:2c5:55cf:b1ab with SMTP id o7-20020a5d62c7000000b002c555cfb1abmr2463146wrv.48.1676981049324; Tue, 21 Feb 2023 04:04:09 -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.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:09 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 058/103] gccrs: intrinsics: Add `sorry_handler` intrinsic handler Date: Tue, 21 Feb 2023 13:01:48 +0100 Message-Id: <20230221120230.596966-59-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.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 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?1758444082244810075?= X-GMAIL-MSGID: =?utf-8?q?1758444082244810075?= From: Arthur Cohen gcc/rust/ChangeLog: * backend/rust-compile-intrinsic.cc (sorry_handler): New intrinsic handler. gcc/testsuite/ChangeLog: * rust/compile/torture/intrinsics-3.rs: New test. --- gcc/rust/backend/rust-compile-intrinsic.cc | 10 ++++++++++ gcc/testsuite/rust/compile/torture/intrinsics-3.rs | 9 +++++++++ 2 files changed, 19 insertions(+) create mode 100644 gcc/testsuite/rust/compile/torture/intrinsics-3.rs diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc b/gcc/rust/backend/rust-compile-intrinsic.cc index a418b863210..2a2091ccc25 100644 --- a/gcc/rust/backend/rust-compile-intrinsic.cc +++ b/gcc/rust/backend/rust-compile-intrinsic.cc @@ -93,6 +93,15 @@ prefetch_write_data (Context *ctx, TyTy::FnType *fntype) return prefetch_data_handler (ctx, fntype, Prefetch::Write); } +static inline tree +sorry_handler (Context *ctx, TyTy::FnType *fntype) +{ + rust_sorry_at (fntype->get_locus (), "intrinsic %qs is not yet implemented", + fntype->get_identifier ().c_str ()); + + return error_mark_node; +} + static const std::map> generic_intrinsics = { @@ -107,6 +116,7 @@ static const std::map X-Patchwork-Id: 60019 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1837391wrn; Tue, 21 Feb 2023 04:38:08 -0800 (PST) X-Google-Smtp-Source: AK7set+uaQLFvCHQOonsq8UCBsTybkCB1E4vJ5x401p6IGpMyKjCwHODQ5+zP5wE6GdxLVM8isu1 X-Received: by 2002:a17:906:4fd2:b0:8d9:c3d:91d8 with SMTP id i18-20020a1709064fd200b008d90c3d91d8mr6237447ejw.31.1676983088357; Tue, 21 Feb 2023 04:38:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983088; cv=none; d=google.com; s=arc-20160816; b=RtVZuzqNhyLLPysP3zWP5u5cL/fL8rphCrwtnJwmD45zuZphP9t6Nefkbakk08SYY7 A24iitqd9tFKUkb7EDRrZKAN6MAy2uT3LcBT4y2HwBqKwBdS+oo114weRrLPt0GRo3gT mSQII5IwDNyG1SUkCht2kVqoE3+xYLZpRE4v9vNI5ka2WvoPMcLF/Jb0mp8osj+Hi2+M ftZuBTJ5wmHOWOCb1rA81Cqmnxl6/ia+VQNlphBAPh7Vbv0NHKL/S2XXVONpE25FuNnq uuzNzl/ZcK/44UvFtIEHvbCoUwDb1dTucvdT+UruoZr1b+llooiknhjpsn+BH2MpltGF uqYg== 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=xb1CCtsf/kMc5yfrZoQf4CdA00LJzqPiyDi4OxFeit8=; b=uQ+IfM8CHiJFSUXPmpo/Dyb8EiPIV/ZY2hFVWRpEdjDW85tgnNToE6Fyy7QcnAwiy2 wwpkyGLhAq9o4/HrXQLl+bTcN/X0QzxTfsfg1en7VpFvLl3StvItXwC9SeO9MlLi3WM5 rP/N/BX82pngVAsIjxf8cJ10TxugFcl0Y4peIzoIkmNhQ5QLbM3KTGKbsl8xvQ6PsI/u 6/d6+ctOhfQQdSFS9EfTVkl+1r3DsN0hH8F9h/ulTeR3BDrA3xDbdos0e6/hYzrq/Y7x /qkBvvnYkOfi/17/8+9Rfe++FNIAa6ZVHS0+NxFn4RdOsmOWYBvRLTdbhWyGCWKhC44E J7Vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=g5JaUl5Y; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 26-20020a170906029a00b008d17b125784si8399702ejf.30.2023.02.21.04.38.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:38:08 -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=g5JaUl5Y; 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 66D12397A1C6 for ; Tue, 21 Feb 2023 12:13:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id C4B203846902 for ; Tue, 21 Feb 2023 12:04:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C4B203846902 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-x431.google.com with SMTP id z8so3884423wrm.8 for ; Tue, 21 Feb 2023 04:04:11 -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=xb1CCtsf/kMc5yfrZoQf4CdA00LJzqPiyDi4OxFeit8=; b=g5JaUl5YN8jL+90q2a4XL5OpUZ3s2ygkRznLPYU931xFdkO1bluh7Go10btyCxmZRl kS1eiquVxM0FhHsr7W/urO9jUfpNZrW2a9BM8XKQr+xEwWzjB8eeFxloPcC1ofNMfYCK a/04vDr5tPgOvpa3ElNbXTgrHMYb5ENuiqH7B6xzbT3nBMVev/jHC1BEp9NYTMC9kBCD sQeFDIkpJkNfU+o1PWteuE8e5YJl72F75pnT5JTGDMCX+9DEGS+cpccZ32+UckJDoePe qj9q4QPheSX7JmBqdIFiz/tlPk8QHaS7GNswuWU4TzejcJGu25qUCAaf7Rex7SW1SyvY KKdw== 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=xb1CCtsf/kMc5yfrZoQf4CdA00LJzqPiyDi4OxFeit8=; b=AATNK9B2QVQvsT2cyRxJt5PDdd4+esWjuSOnjg4D3Zz/AVac3MXk4+F82XSfgm3NJ6 FxrZtVBQETEoEV/72pH9PYE3UyQ6XNzNi1msaGp3GXtA/bhbRHwiy+J0qy3QoDW0VAMh CFAp1ddEd3V5yDd9hL7sVzNRStSWPMp+HISyvzoMV0xJ74ufQQ3tMxvxo34iaV01EYP4 T2h1bKM2dl6oEi6NUOkFjA3SXWChOU54hlfMMzuKZZlZtTPG1pOwHhBAogCQ1oDBad44 CTjqrVFbgoqQN6LhD8k242bK6UpK1b0QYqeC8qaSxp2RBELjJ3D6MzaMYeZUUcZ7kArO fMWQ== X-Gm-Message-State: AO0yUKXDjh4eIgRB2aXp/CMzqpwboZxeMsFW02A3GK/+sw4Swr4VXN9y rFFJQ9dQiNKY4LU/fEFlksLix3aYCnNvGP+XrQ== X-Received: by 2002:a05:6000:1052:b0:2c5:582b:bad1 with SMTP id c18-20020a056000105200b002c5582bbad1mr4392313wrx.30.1676981050891; Tue, 21 Feb 2023 04:04:10 -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.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:10 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 059/103] gccrs: constexpr: Add `rust_sorry_at` in places relying on init values Date: Tue, 21 Feb 2023 13:01:49 +0100 Message-Id: <20230221120230.596966-60-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.3 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 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?1758444219071423574?= X-GMAIL-MSGID: =?utf-8?q?1758444219071423574?= From: Arthur Cohen gcc/rust/ChangeLog: * backend/rust-constexpr.cc (build_anon_member_initialization): Workaround uninitialized values. (build_data_member_initialization): Likewise. --- gcc/rust/backend/rust-constexpr.cc | 96 +++++++++++++++--------------- 1 file changed, 49 insertions(+), 47 deletions(-) diff --git a/gcc/rust/backend/rust-constexpr.cc b/gcc/rust/backend/rust-constexpr.cc index 8623816236c..23d940d04ce 100644 --- a/gcc/rust/backend/rust-constexpr.cc +++ b/gcc/rust/backend/rust-constexpr.cc @@ -3658,49 +3658,48 @@ eval_call_expression (const constexpr_ctx *ctx, tree t, bool lval, whose constructor we are processing. Add the initializer to the vector and return true to indicate success. */ -static bool -build_anon_member_initialization (tree member, tree init, - vec **vec_outer) -{ - /* MEMBER presents the relevant fields from the inside out, but we need - to build up the initializer from the outside in so that we can reuse - previously built CONSTRUCTORs if this is, say, the second field in an - anonymous struct. So we use a vec as a stack. */ - auto_vec fields; - do - { - fields.safe_push (TREE_OPERAND (member, 1)); - member = TREE_OPERAND (member, 0); - } - while (ANON_AGGR_TYPE_P (TREE_TYPE (member)) - && TREE_CODE (member) == COMPONENT_REF); - - /* VEC has the constructor elements vector for the context of FIELD. - If FIELD is an anonymous aggregate, we will push inside it. */ - vec **vec = vec_outer; - tree field; - while (field = fields.pop (), ANON_AGGR_TYPE_P (TREE_TYPE (field))) - { - tree ctor; - /* If there is already an outer constructor entry for the anonymous - aggregate FIELD, use it; otherwise, insert one. */ - if (vec_safe_is_empty (*vec) || (*vec)->last ().index != field) - { - ctor = build_constructor (TREE_TYPE (field), NULL); - CONSTRUCTOR_APPEND_ELT (*vec, field, ctor); - } - else - ctor = (*vec)->last ().value; - vec = &CONSTRUCTOR_ELTS (ctor); - } - - /* Now we're at the innermost field, the one that isn't an anonymous - aggregate. Add its initializer to the CONSTRUCTOR and we're done. */ - gcc_assert (fields.is_empty ()); - CONSTRUCTOR_APPEND_ELT (*vec, field, init); - - return true; -} +// static bool +// build_anon_member_initialization (tree member, tree init, +// vec **vec_outer) +// { +// /* MEMBER presents the relevant fields from the inside out, but we need +// to build up the initializer from the outside in so that we can reuse +// previously built CONSTRUCTORs if this is, say, the second field in an +// anonymous struct. So we use a vec as a stack. */ +// auto_vec fields; +// do +// { +// fields.safe_push (TREE_OPERAND (member, 1)); +// member = TREE_OPERAND (member, 0); +// } while (ANON_AGGR_TYPE_P (TREE_TYPE (member)) +// && TREE_CODE (member) == COMPONENT_REF); +// +// /* VEC has the constructor elements vector for the context of FIELD. +// If FIELD is an anonymous aggregate, we will push inside it. */ +// vec **vec = vec_outer; +// tree field; +// while (field = fields.pop (), ANON_AGGR_TYPE_P (TREE_TYPE (field))) +// { +// tree ctor; +// /* If there is already an outer constructor entry for the anonymous +// aggregate FIELD, use it; otherwise, insert one. */ +// if (vec_safe_is_empty (*vec) || (*vec)->last ().index != field) +// { +// ctor = build_constructor (TREE_TYPE (field), NULL); +// CONSTRUCTOR_APPEND_ELT (*vec, field, ctor); +// } +// else +// ctor = (*vec)->last ().value; +// vec = &CONSTRUCTOR_ELTS (ctor); +// } +// +// /* Now we're at the innermost field, the one that isn't an anonymous +// aggregate. Add its initializer to the CONSTRUCTOR and we're done. */ +// gcc_assert (fields.is_empty ()); +// CONSTRUCTOR_APPEND_ELT (*vec, field, init); +// +// return true; +// } ///* V is a vector of constructor elements built up for the base and member // initializers of a constructor for TYPE. They need to be in increasing @@ -3750,7 +3749,7 @@ build_anon_member_initialization (tree member, tree init, static bool build_data_member_initialization (tree t, vec **vec) { - tree member, init; + tree member; if (TREE_CODE (t) == CLEANUP_POINT_EXPR) t = TREE_OPERAND (t, 0); if (TREE_CODE (t) == EXPR_STMT) @@ -3835,7 +3834,8 @@ build_data_member_initialization (tree t, vec **vec) member = TREE_OPERAND (member, 1); else if (ANON_AGGR_TYPE_P (TREE_TYPE (aggr))) /* Initializing a member of an anonymous union. */ - return build_anon_member_initialization (member, init, vec); + rust_sorry_at (Location (), "cannot handle value initialization yet"); + // return build_anon_member_initialization (member, init, vec); else /* We're initializing a vtable pointer in a base. Leave it as COMPONENT_REF so we remember the path to get to the vfield. */ @@ -3845,9 +3845,11 @@ build_data_member_initialization (tree t, vec **vec) /* Value-initialization can produce multiple initializers for the same field; use the last one. */ if (!vec_safe_is_empty (*vec) && (*vec)->last ().index == member) - (*vec)->last ().value = init; + rust_sorry_at (Location (), "cannot handle value initialization yet"); + // (*vec)->last ().value = init; else - CONSTRUCTOR_APPEND_ELT (*vec, member, init); + rust_sorry_at (Location (), "cannot handle value initialization yet"); + // CONSTRUCTOR_APPEND_ELT (*vec, member, init); return true; } From patchwork Tue Feb 21 12:01:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60018 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1836674wrn; Tue, 21 Feb 2023 04:36:38 -0800 (PST) X-Google-Smtp-Source: AK7set+qYbsWa39pAqwRCIR+DqqzDHvVEX7eo1r/zdaC2j1vFnnPQ3vjdfvhwBv/bU44BvDja6bG X-Received: by 2002:a17:906:58c6:b0:8de:1eb6:d09c with SMTP id e6-20020a17090658c600b008de1eb6d09cmr2503677ejs.13.1676982998706; Tue, 21 Feb 2023 04:36:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982998; cv=none; d=google.com; s=arc-20160816; b=0msQYAvX8M4JtfRUcR5h1LXOQppkj6/LF0XIZb+/rSY+dLeULan7eaTzQg5mi6lp5C pQ2jMga5zVG/dlCC2iHW/ohQmjbeneVgUr5YOW9TMRo8uCszrQiwdJ55+noIHOidbkLA eZe6p5lNEXvATFXCUsld2XjO5JdcWAiRKnYZxMMicV96KkFesJnVTDlCMI6Ad8ai1HD3 noKByxcOWDWQ7W72S5ZOJ/Y4Ce5KoC/wq13K8IlwTW8lQpgqVXkGJyn+dn/8G82560j7 2rq07zlM5E+IAXa5x4PMOwDF1X6a5fJfV7+hTaHSNAHDw/wCJQ9KMiNrJ+fELuzdKcQU PKWA== 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=rloLSKS9lkl2psQzOflci4DtRK9bodiWEJkUGeWDtYg=; b=POVlOwV88mzjSn8OrDX1Pr40wx/NGBey9tBfrcFj2OYz+T/fAo7N3Tkdf16tKlQcW6 cp60R7nlXX3Q2UYY2UpFYDElVIMqzSLqaA0zSv2PgyzmM/xXjFQ66+yCeIubwlRfgf4R KhvGssjWAD7J89KpmqCij6u/HF0yB4cVwNRs0sIRfUIG797gpcpDkM5nkg1XEqWfDxvL gzNSGm/n+YKPlZ6V+lWlGY9yzdPwDRcejXTyMF4iMJTiWUVxnmH3Os0ATYL24r/7fpbK /KjjyM+CzV1yqXaKAUv6R2tdWOicx5ke5A/wjsCkq+RHYh6n1Y9rl53aAvWQXRBn96qu DZxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Te0qgIBJ; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ex17-20020a170907955100b008d2060ebc6esi6205587ejc.564.2023.02.21.04.36.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:36:38 -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=Te0qgIBJ; 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 624C1391284B for ; Tue, 21 Feb 2023 12:13:03 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 91B35383FDC3 for ; Tue, 21 Feb 2023 12:04:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 91B35383FDC3 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-x435.google.com with SMTP id t13so4090141wrv.13 for ; Tue, 21 Feb 2023 04:04:12 -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=rloLSKS9lkl2psQzOflci4DtRK9bodiWEJkUGeWDtYg=; b=Te0qgIBJhFm38yvlYMi3MNgr2QThNgLmvRuOLITdDXYYil3eLt9ilkKGSFr0Qibzx2 6gTVnke9dPDOdIbvdqYYTFvuPfu8R4AD8T7HjZ7FtKMcO+gqZfH3ME1EnaToEMyowvfA EXbAIT9ubtKX2spA9hNWtERhDWB0gIb3DXw5qTu3bk2sUhpK1gT+jhY9lwtJ1Z0RK/+v GfDLEBS3u91DpCZNUFFix+FNnBezFj9HMYL1z2kf4td5Jf/3TsNgHLlE+Pj1loklOg+b iFm7DWLBUtOy/QVCFFv6dTaUTPy1b26aqtzpQVDMJZpn2FZpPfW5UYG5Rz34z8G4y5ul BaJg== 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=rloLSKS9lkl2psQzOflci4DtRK9bodiWEJkUGeWDtYg=; b=wGt8QYIB/0ZBCDOI0fcRQnNIQX/B1bWnjArjr5ZX1fsBMT7UWC6fXRylh1aM/yf9zK Mtx1NfI+oqISd9rZZkdmu/Xwl08rXIlNFEvhuFP4XfEwI7fAeYBUGs3hvY5Ad7SX3Yoi zObNdHUQb/78rtxb9YOPpCgHOdnYVk3Ah4YHkptQ4UkdmSOLl63K9iGqLFBucdSwxfRL STq8LLsgMtCr13cwHKtkreAmo/SzHGCX/U1jHJyychuY9j6sW2E8ut4lSbbEVaxZ46uK 0//Zfc6l4ON/MgD+tSXeJmVoQUokdC4sW18lRdvVYNhdvz+NpS1mCDto8QeSy5ueiYx6 nhMw== X-Gm-Message-State: AO0yUKUrLzCcRdjkcdSjit1LkTvHaHn7Z28pl0pYqxoIBRdH7hk4frag yNPOe9oJ/8C35PoarCpFGPzrfgCOZxjlM3qiRA== X-Received: by 2002:a5d:5c0d:0:b0:2c5:67e3:808d with SMTP id cc13-20020a5d5c0d000000b002c567e3808dmr2745512wrb.35.1676981051903; Tue, 21 Feb 2023 04:04:11 -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.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:11 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 060/103] gccrs: intrinsics: Add early implementation for atomic_store_{seqcst, relaxed, release} Date: Tue, 21 Feb 2023 13:01:50 +0100 Message-Id: <20230221120230.596966-61-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.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 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?1758444124855333937?= X-GMAIL-MSGID: =?utf-8?q?1758444124855333937?= From: Arthur Cohen gcc/rust/ChangeLog: * backend/rust-builtins.cc (BuiltinsContext::setup_atomic_fns): New function. (BuiltinsContext::setup): Call `setup_atomic_fns`. * backend/rust-builtins.h: Declare `setup_atomic_fns`. * backend/rust-compile-intrinsic.cc (atomic_store_handler_inner): New function. (atomic_store_handler): New handler. (make_unsigned_long_tree): Add helper around making unsigned long trees. (prefetch_data_handler): Use `make_unsigned_long_tree`. (build_atomic_builtin_name): New function. gcc/testsuite/ChangeLog: * rust/compile/torture/intrinsics-4.rs: New test. * rust/compile/torture/intrinsics-5.rs: New test. * rust/execute/torture/atomic_store.rs: New test. --- gcc/rust/backend/rust-builtins.cc | 36 ++++ gcc/rust/backend/rust-builtins.h | 2 +- gcc/rust/backend/rust-compile-intrinsic.cc | 165 +++++++++++++++--- .../rust/compile/torture/intrinsics-4.rs | 20 +++ .../rust/compile/torture/intrinsics-5.rs | 35 ++++ .../rust/execute/torture/atomic_store.rs | 32 ++++ 6 files changed, 268 insertions(+), 22 deletions(-) create mode 100644 gcc/testsuite/rust/compile/torture/intrinsics-4.rs create mode 100644 gcc/testsuite/rust/compile/torture/intrinsics-5.rs create mode 100644 gcc/testsuite/rust/execute/torture/atomic_store.rs diff --git a/gcc/rust/backend/rust-builtins.cc b/gcc/rust/backend/rust-builtins.cc index d6f8cb6f495..64e06e1a240 100644 --- a/gcc/rust/backend/rust-builtins.cc +++ b/gcc/rust/backend/rust-builtins.cc @@ -68,11 +68,47 @@ BuiltinsContext::setup_math_fns () math_function_type_f32, builtin_const); } +void +BuiltinsContext::setup_atomic_fns () +{ + define_builtin ("atomic_store", BUILT_IN_ATOMIC_STORE, "__atomic_store", NULL, + build_function_type_list (void_type_node, size_type_node, + build_pointer_type (void_type_node), + const_ptr_type_node, + integer_type_node, NULL_TREE), + 0); + define_builtin ("atomic_store_n", BUILT_IN_ATOMIC_STORE_N, "__atomic_store_n", + NULL, + build_varargs_function_type_list (void_type_node, NULL_TREE), + 0); + define_builtin ("atomic_store_1", BUILT_IN_ATOMIC_STORE_1, "__atomic_store_1", + NULL, + build_varargs_function_type_list (void_type_node, NULL_TREE), + 0); + define_builtin ("atomic_store_2", BUILT_IN_ATOMIC_STORE_2, "__atomic_store_2", + NULL, + build_varargs_function_type_list (void_type_node, NULL_TREE), + 0); + define_builtin ("atomic_store_4", BUILT_IN_ATOMIC_STORE_4, "__atomic_store_4", + NULL, + build_varargs_function_type_list (void_type_node, NULL_TREE), + 0); + define_builtin ("atomic_store_8", BUILT_IN_ATOMIC_STORE_8, "__atomic_store_8", + NULL, + build_varargs_function_type_list (void_type_node, NULL_TREE), + 0); + define_builtin ("atomic_store_16", BUILT_IN_ATOMIC_STORE_16, + "__atomic_store_16", NULL, + build_varargs_function_type_list (void_type_node, NULL_TREE), + 0); +} + void BuiltinsContext::setup () { setup_math_fns (); setup_overflow_fns (); + setup_atomic_fns (); define_builtin ("unreachable", BUILT_IN_UNREACHABLE, "__builtin_unreachable", NULL, build_function_type (void_type_node, void_list_node), diff --git a/gcc/rust/backend/rust-builtins.h b/gcc/rust/backend/rust-builtins.h index e421fa43755..c2825107faf 100644 --- a/gcc/rust/backend/rust-builtins.h +++ b/gcc/rust/backend/rust-builtins.h @@ -86,8 +86,8 @@ private: BuiltinsContext (); void setup_overflow_fns (); - void setup_math_fns (); + void setup_atomic_fns (); void setup (); diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc b/gcc/rust/backend/rust-compile-intrinsic.cc index 2a2091ccc25..7c592dabb38 100644 --- a/gcc/rust/backend/rust-compile-intrinsic.cc +++ b/gcc/rust/backend/rust-compile-intrinsic.cc @@ -93,6 +93,17 @@ prefetch_write_data (Context *ctx, TyTy::FnType *fntype) return prefetch_data_handler (ctx, fntype, Prefetch::Write); } +static tree +atomic_store_handler_inner (Context *ctx, TyTy::FnType *fntype, int ordering); + +static inline std::function +atomic_store_handler (int ordering) +{ + return [ordering] (Context *ctx, TyTy::FnType *fntype) { + return atomic_store_handler_inner (ctx, fntype, ordering); + }; +} + static inline tree sorry_handler (Context *ctx, TyTy::FnType *fntype) { @@ -105,18 +116,22 @@ sorry_handler (Context *ctx, TyTy::FnType *fntype) static const std::map> generic_intrinsics = { - {"offset", &offset_handler}, - {"size_of", &sizeof_handler}, - {"transmute", &transmute_handler}, - {"rotate_left", &rotate_left_handler}, - {"rotate_right", &rotate_right_handler}, - {"wrapping_add", &wrapping_add_handler}, - {"wrapping_sub", &wrapping_sub_handler}, - {"wrapping_mul", &wrapping_mul_handler}, - {"copy_nonoverlapping", ©_nonoverlapping_handler}, - {"prefetch_read_data", &prefetch_read_data}, - {"prefetch_write_data", &prefetch_write_data}, - {"atomic_load", &sorry_handler}, + {"offset", offset_handler}, + {"size_of", sizeof_handler}, + {"transmute", transmute_handler}, + {"rotate_left", rotate_left_handler}, + {"rotate_right", rotate_right_handler}, + {"wrapping_add", wrapping_add_handler}, + {"wrapping_sub", wrapping_sub_handler}, + {"wrapping_mul", wrapping_mul_handler}, + {"copy_nonoverlapping", copy_nonoverlapping_handler}, + {"prefetch_read_data", prefetch_read_data}, + {"prefetch_write_data", prefetch_write_data}, + {"atomic_load", sorry_handler}, + {"atomic_store_seqcst", atomic_store_handler (__ATOMIC_SEQ_CST)}, + {"atomic_store_release", atomic_store_handler (__ATOMIC_RELEASE)}, + {"atomic_store_relaxed", atomic_store_handler (__ATOMIC_RELAXED)}, + {"atomic_store_unordered", atomic_store_handler (__ATOMIC_RELAXED)}, }; Intrinsics::Intrinsics (Context *ctx) : ctx (ctx) {} @@ -551,6 +566,16 @@ copy_nonoverlapping_handler (Context *ctx, TyTy::FnType *fntype) return fndecl; } +static tree +make_unsigned_long_tree (Context *ctx, unsigned long value) +{ + mpz_t mpz_value; + mpz_init_set_ui (mpz_value, value); + + return ctx->get_backend ()->integer_constant_expression (integer_type_node, + mpz_value); +} + static tree prefetch_data_handler (Context *ctx, TyTy::FnType *fntype, Prefetch kind) { @@ -576,16 +601,8 @@ prefetch_data_handler (Context *ctx, TyTy::FnType *fntype, Prefetch kind) auto addr = ctx->get_backend ()->var_expression (args[0], Location ()); auto locality = ctx->get_backend ()->var_expression (args[1], Location ()); + auto rw_flag = make_unsigned_long_tree (ctx, kind == Prefetch::Write ? 1 : 0); - mpz_t zero; - mpz_t one; - mpz_init_set_ui (zero, 0); - mpz_init_set_ui (one, 1); - - auto rw_flag_value = kind == Prefetch::Write ? one : zero; - auto rw_flag - = ctx->get_backend ()->integer_constant_expression (integer_type_node, - rw_flag_value); auto prefetch_raw = NULL_TREE; auto ok = BuiltinsContext::get ().lookup_simple_builtin ("prefetch", &prefetch_raw); @@ -597,6 +614,9 @@ prefetch_data_handler (Context *ctx, TyTy::FnType *fntype, Prefetch kind) = ctx->get_backend ()->call_expression (prefetch, {addr, rw_flag, locality}, nullptr, Location ()); + TREE_READONLY (prefetch_call) = 0; + TREE_SIDE_EFFECTS (prefetch_call) = 1; + ctx->add_statement (prefetch_call); finalize_intrinsic_block (ctx, fndecl); @@ -604,5 +624,108 @@ prefetch_data_handler (Context *ctx, TyTy::FnType *fntype, Prefetch kind) return fndecl; } +static std::string +build_atomic_builtin_name (Location locus, tree operand_type) +{ + static const std::map allowed_types = { + {"i8", "1"}, {"i16", "2"}, {"i32", "4"}, {"i64", "8"}, + {"i128", "16"}, {"isize", "8"}, {"u8", "1"}, {"u16", "2"}, + {"u32", "4"}, {"u64", "8"}, {"u128", "16"}, {"usize", "8"}, + }; + + // TODO: Can we maybe get the generic version (atomic_store_n) to work... This + // would be so much better + + std::string result = "atomic_store_"; + + auto type_name = std::string (TYPE_NAME_STRING (operand_type)); + if (type_name == "usize" || type_name == "isize") + { + rust_sorry_at ( + locus, "atomics are not yet available for size types (usize, isize)"); + return ""; + } + + // FIXME: Can we have a better looking name here? + // Instead of `::::`? + // Maybe instead of giving the tree node, pass the resolved Tyty before it + // gets compiled? + // + // Or should we perform this check somwhere else in the compiler? + auto type_size_str = allowed_types.find (type_name); + if (type_size_str == allowed_types.end ()) + { + rust_error_at (locus, + "atomic intrinsics are only available for basic integer " + "types: got type %qs", + type_name.c_str ()); + return ""; + } + + result += type_size_str->second; + + return result; +} + +static tree +atomic_store_handler_inner (Context *ctx, TyTy::FnType *fntype, int ordering) +{ + rust_assert (fntype->get_params ().size () == 2); + rust_assert (fntype->get_num_substitutions () == 1); + + tree lookup = NULL_TREE; + if (check_for_cached_intrinsic (ctx, fntype, &lookup)) + return lookup; + + auto fndecl = compile_intrinsic_function (ctx, fntype); + + // Most intrinsic functions are pure but not the atomic ones + TREE_READONLY (fndecl) = 0; + TREE_SIDE_EFFECTS (fndecl) = 1; + + // setup the params + std::vector param_vars; + std::vector types; + compile_fn_params (ctx, fntype, fndecl, ¶m_vars, &types); + + auto ok = ctx->get_backend ()->function_set_parameters (fndecl, param_vars); + rust_assert (ok); + + enter_intrinsic_block (ctx, fndecl); + + auto dst = ctx->get_backend ()->var_expression (param_vars[0], Location ()); + TREE_READONLY (dst) = 0; + + auto value = ctx->get_backend ()->var_expression (param_vars[1], Location ()); + auto memorder = make_unsigned_long_tree (ctx, ordering); + + auto builtin_name + = build_atomic_builtin_name (fntype->get_locus (), TREE_TYPE (types[0])); + if (builtin_name.empty ()) + return error_mark_node; + + tree atomic_store_raw = nullptr; + BuiltinsContext::get ().lookup_simple_builtin (builtin_name, + &atomic_store_raw); + rust_assert (atomic_store_raw); + + auto atomic_store + = build_fold_addr_expr_loc (Location ().gcc_location (), atomic_store_raw); + + auto store_call + = ctx->get_backend ()->call_expression (atomic_store, + {dst, value, memorder}, nullptr, + Location ()); + + TREE_READONLY (store_call) = 0; + TREE_SIDE_EFFECTS (store_call) = 1; + + ctx->add_statement (store_call); + + finalize_intrinsic_block (ctx, fndecl); + + return fndecl; +} + } // namespace Compile } // namespace Rust diff --git a/gcc/testsuite/rust/compile/torture/intrinsics-4.rs b/gcc/testsuite/rust/compile/torture/intrinsics-4.rs new file mode 100644 index 00000000000..243d4460089 --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/intrinsics-4.rs @@ -0,0 +1,20 @@ +trait Copy {} + +extern "rust-intrinsic" { + pub fn atomic_store_seqcst(dst: *mut T, val: T); + pub fn atomic_store_release(dst: *mut T, val: T); + pub fn atomic_store_relaxed(dst: *mut T, val: T); + // pub fn atomic_store_unordered(dst: *mut T, val: T); +} + +fn main() { + let mut dst = 15; + let new_value = 14; + + unsafe { + atomic_store_seqcst(&mut dst, new_value); + atomic_store_release(&mut dst, new_value); + atomic_store_relaxed(&mut dst, new_value); + // atomic_store_unordered(&mut dst, new_value); + } +} diff --git a/gcc/testsuite/rust/compile/torture/intrinsics-5.rs b/gcc/testsuite/rust/compile/torture/intrinsics-5.rs new file mode 100644 index 00000000000..e0087720cc4 --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/intrinsics-5.rs @@ -0,0 +1,35 @@ +trait Copy {} + +extern "rust-intrinsic" { + pub fn atomic_store_seqcst(dst: *mut T, value: T); + // { dg-error "atomic intrinsics are only available for basic integer types: got type .intrinsics_5::VeryLargeType." "" { target *-*-* } .-1 } + // { dg-error "atomic intrinsics are only available for basic integer types: got type .bool." "" { target *-*-* } .-2 } +} + +struct VeryLargeType { + a0: i128, + a1: i128, + a2: i128, + a3: i128, +} + +impl VeryLargeType { + pub fn new(value: i128) -> VeryLargeType { + VeryLargeType { + a0: value, + a1: 0, + a2: 0, + a3: 0, + } + } +} + +fn main() { + let mut dst = VeryLargeType::new(0); + let mut b = false; + + unsafe { + atomic_store_seqcst(&mut dst, VeryLargeType::new(1)); + atomic_store_seqcst(&mut b, true); + } +} diff --git a/gcc/testsuite/rust/execute/torture/atomic_store.rs b/gcc/testsuite/rust/execute/torture/atomic_store.rs new file mode 100644 index 00000000000..9f248b4f823 --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/atomic_store.rs @@ -0,0 +1,32 @@ +trait Copy {} + +extern "rust-intrinsic" { + pub fn atomic_store_seqcst(dst: *mut T, val: T); + pub fn atomic_store_release(dst: *mut T, val: T); + pub fn atomic_store_relaxed(dst: *mut T, val: T); + pub fn atomic_store_unordered(dst: *mut T, val: T); +} + +fn main() -> i32 { + let mut dst = 15; + let one; + let two; + let three; + let four; + + unsafe { + atomic_store_seqcst(&mut dst, 1); + one = dst; + + atomic_store_release(&mut dst, 2); + two = dst; + + atomic_store_relaxed(&mut dst, 3); + three = dst; + + atomic_store_unordered(&mut dst, 4); + four = dst; + } + + (four + three + two + one) - 10 +} From patchwork Tue Feb 21 12:01:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60009 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1835546wrn; Tue, 21 Feb 2023 04:34:02 -0800 (PST) X-Google-Smtp-Source: AK7set8lXtQf48PI8SJVHUoomLi1FwjBFGMHcd0IhI4La36GgHCgLrn/sFfXWXQDUpRiXm8q2H/l X-Received: by 2002:a17:907:3201:b0:888:a32d:b50 with SMTP id xg1-20020a170907320100b00888a32d0b50mr18189318ejb.40.1676982842172; Tue, 21 Feb 2023 04:34:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982842; cv=none; d=google.com; s=arc-20160816; b=OIAdso0TuqM3QmDxSBE9dJayT+zDfyIZ2mBZR8RnQelbDGC03B33OPYxWh8PyiDZZa PBmqIawGM7n4xulRyWH7Bc9XpyQ6B2IirkCfOnAcP2Q4NPMeEoe59YBcgWOyXBrj7Gqv egcUXNbbQzDd6MmNPLr57ByNRfESKFMOFHiPEVd3WBx70DzlIM/w9QJH9H1/WYx0FVm1 8GhYDeALBLpWO1kP978Vk5PyoU3E03UBYv/59hL8qrq3MGRb5Vg8kt/H80vEZtMYWvLu IZN7hcI7W3CesO0WzBV9UgHNEkDj8kpuYs/1fVtN6ijpeYpc5zrdlx9wwQAy1uF2PLEn 6P5Q== 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=u7X/OfhZtknKt9FIFWe3Qg0++vyap5e/JC7aYw+rSVA=; b=Jik7hV0Svmc8KtbQX+gq2IUJ9Xa1hGkszxBcWFWBT2BQQSHBTbrWDvhiU+th3vHSSe 4328de3/fU8MSJrWybMjKx06M9VTJaujKKKaWYC5I7oR8QLK4U5ZOymv98cjtrD9Q+8w dXJJbKeWR313+O4M4/vIWm+7Z5DBxly/Uc7LqmHv1i8RIg/l2omXe8qoJZLhmnDNygRJ SlzayP7iiSTIENjEBG6erBpJWg7Ek2DhP1vpnDdBK6lgnL7XeexTcCfXz9a+xv5HxFF6 NuC4dYgF4A9YiBjWHBk15ADPph3UeObhW4wYp8NidWzo6Z/62PAwTCHdFABWd1ljGuhM ogMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=IWugtZc2; 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 f25-20020a170906739900b008b17cc2e38asi18939677ejl.582.2023.02.21.04.34.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:34:02 -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=IWugtZc2; 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 5AA0B383FB88 for ; Tue, 21 Feb 2023 12:12:23 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id E69743838152 for ; Tue, 21 Feb 2023 12:04:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E69743838152 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-x430.google.com with SMTP id z8so3884509wrm.8 for ; Tue, 21 Feb 2023 04:04:13 -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=u7X/OfhZtknKt9FIFWe3Qg0++vyap5e/JC7aYw+rSVA=; b=IWugtZc2IJHJ72JgYFHqtdAAtZiOhZkQUqufRQIMStepnxV6aO2Ub9yUUMiwLJsiMf A5Qpg9CBXQAcqdjC//wnAmjYRTh1RTA4050l8w13vMOz1h3lXC49XTYtQwvLbwgDsita jjjgOILZrKX0fYulrfbK+i+PNBsiuG0mSoD2AmE9HGGJ6VkOjGwUBXsBtQ8yV2DsHb8x cfJ26119OQBCGs19mARepx0cjRsZ8zxh1LtvnwQ++iaDD+phuRt4WfNas8YElQMOAVfS 17nmSvqB4fvBq3yNVvAz1ARigmA4nX5UsdQJH8q+N/sF2whWHfa95CJh9eqYetRRbYXM JmAQ== 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=u7X/OfhZtknKt9FIFWe3Qg0++vyap5e/JC7aYw+rSVA=; b=CzLoxVRQSsIbZYu92wI0WaOak6JOgMyInBQWmNs2owopr6ZrvT35/3z1X3WVX19tPD i4bRRv1fLkd7W8MFbpjq3A3aNoun6HpEQQnXSrRbHWzQXOXWK0Yf0kmKSPcWrv7vqq4C ZUAH5eyQwNNucz08DcBsuW2bgrZNpbnib8BqXOKkkX+TRNR7CGLbEIZ3zJRmh0BuHgEO rAZv/DbHe80b918kY6TgMDkuRjwhgPPTUVmddfk91HwA8DG7UCgHZVrLc9ra2/0r2fWD 6mleTV9UJG554vnI3RaVlm3T3cBLXtZ9CyLzpDZMZREMXZnsOIeLyxzXNDC2rhm47xoS WkWg== X-Gm-Message-State: AO0yUKUUK1lU7nvYssdhL79EBGMwfCEL0KNSN0B3GrXlCh6vSBPALeCq aE1qTeJMbZBq0y08s14TTWBxUQSdnLnxPCxeIw== X-Received: by 2002:a5d:5945:0:b0:2c5:5c00:b917 with SMTP id e5-20020a5d5945000000b002c55c00b917mr2323189wri.0.1676981052561; Tue, 21 Feb 2023 04:04:12 -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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:12 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 061/103] gccrs: intrinsics: Add unchecked operation intrinsics Date: Tue, 21 Feb 2023 13:01:51 +0100 Message-Id: <20230221120230.596966-62-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.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 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?1758443960626760221?= X-GMAIL-MSGID: =?utf-8?q?1758443960626760221?= From: Arthur Cohen gcc/rust/ChangeLog: * backend/rust-compile-intrinsic.cc (is_basic_integer_type): New function. (unchecked_op_inner): New handler. (unchecked_op_handler): New handler. gcc/testsuite/ChangeLog: * rust/compile/torture/intrinsics-6.rs: New test. * rust/compile/torture/intrinsics-7.rs: New test. --- gcc/rust/backend/rust-compile-intrinsic.cc | 80 +++++++++++++++++++ .../rust/compile/torture/intrinsics-6.rs | 21 +++++ .../rust/compile/torture/intrinsics-7.rs | 10 +++ 3 files changed, 111 insertions(+) create mode 100644 gcc/testsuite/rust/compile/torture/intrinsics-6.rs create mode 100644 gcc/testsuite/rust/compile/torture/intrinsics-7.rs diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc b/gcc/rust/backend/rust-compile-intrinsic.cc index 7c592dabb38..46ea5b3f795 100644 --- a/gcc/rust/backend/rust-compile-intrinsic.cc +++ b/gcc/rust/backend/rust-compile-intrinsic.cc @@ -34,6 +34,22 @@ namespace Rust { namespace Compile { +static bool +is_basic_integer_type (TyTy::BaseType *type) +{ + switch (type->get_kind ()) + { + case TyTy::INT: + case TyTy::UINT: + case TyTy::USIZE: + case TyTy::ISIZE: + return true; + default: + return false; + break; + } +} + static tree offset_handler (Context *ctx, TyTy::FnType *fntype); static tree @@ -104,6 +120,17 @@ atomic_store_handler (int ordering) }; } +static inline tree +unchecked_op_inner (Context *ctx, TyTy::FnType *fntype, tree_code op); + +const static std::function +unchecked_op_handler (tree_code op) +{ + return [op] (Context *ctx, TyTy::FnType *fntype) { + return unchecked_op_inner (ctx, fntype, op); + }; +} + static inline tree sorry_handler (Context *ctx, TyTy::FnType *fntype) { @@ -132,6 +159,13 @@ static const std::mapadd_statement (store_call); + finalize_intrinsic_block (ctx, fndecl); + + return fndecl; +} + +static inline tree +unchecked_op_inner (Context *ctx, TyTy::FnType *fntype, tree_code op) +{ + rust_assert (fntype->get_params ().size () == 2); + rust_assert (fntype->get_num_substitutions () == 1); + + tree lookup = NULL_TREE; + if (check_for_cached_intrinsic (ctx, fntype, &lookup)) + return lookup; + + auto fndecl = compile_intrinsic_function (ctx, fntype); + + // setup the params + std::vector param_vars; + compile_fn_params (ctx, fntype, fndecl, ¶m_vars); + + if (!ctx->get_backend ()->function_set_parameters (fndecl, param_vars)) + return error_mark_node; + + enter_intrinsic_block (ctx, fndecl); + + // BUILTIN unchecked_ BODY BEGIN + + auto x = ctx->get_backend ()->var_expression (param_vars[0], Location ()); + auto y = ctx->get_backend ()->var_expression (param_vars[1], Location ()); + + auto *monomorphized_type + = fntype->get_substs ().at (0).get_param_ty ()->resolve (); + if (!is_basic_integer_type (monomorphized_type)) + rust_error_at (fntype->get_locus (), + "unchecked operation intrinsics can only be used with " + "basic integer types (got %qs)", + monomorphized_type->get_name ().c_str ()); + + auto expr = build2 (op, TREE_TYPE (x), x, y); + auto return_statement + = ctx->get_backend ()->return_statement (fndecl, {expr}, Location ()); + + ctx->add_statement (return_statement); + + // BUILTIN unchecked_ BODY END finalize_intrinsic_block (ctx, fndecl); diff --git a/gcc/testsuite/rust/compile/torture/intrinsics-6.rs b/gcc/testsuite/rust/compile/torture/intrinsics-6.rs new file mode 100644 index 00000000000..143b62a2b27 --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/intrinsics-6.rs @@ -0,0 +1,21 @@ +extern "rust-intrinsic" { + pub fn unchecked_add(x: T, y: T) -> T; + pub fn unchecked_sub(x: T, y: T) -> T; + pub fn unchecked_mul(x: T, y: T) -> T; + pub fn unchecked_div(x: T, y: T) -> T; + pub fn unchecked_rem(x: T, y: T) -> T; + pub fn unchecked_shl(x: T, y: T) -> T; + pub fn unchecked_shr(x: T, y: T) -> T; +} + +fn main() -> i32 { + let zero0 = unsafe { (1 + 5) - unchecked_add(1, 5) }; + let zero1 = unsafe { (1 - 5) - unchecked_sub(1, 5) }; + let zero2 = unsafe { (1 * 5) - unchecked_mul(1, 5) }; + let zero3 = unsafe { (1 / 5) - unchecked_div(1, 5) }; + let zero4 = unsafe { (1 % 5) - unchecked_rem(1, 5) }; + let zero5 = unsafe { (1 << 5) - unchecked_shl(1, 5) }; + let zero6 = unsafe { (1 >> 5) - unchecked_shr(1, 5) }; + + zero0 + zero1 + zero2 + zero3 + zero4 + zero5 + zero6 +} diff --git a/gcc/testsuite/rust/compile/torture/intrinsics-7.rs b/gcc/testsuite/rust/compile/torture/intrinsics-7.rs new file mode 100644 index 00000000000..8e8c5fe0cdf --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/intrinsics-7.rs @@ -0,0 +1,10 @@ +extern "rust-intrinsic" { + pub fn unchecked_add(x: T, y: T) -> T; + // { dg-error "unchecked operation intrinsics can only be used with basic integer types .got .NotAdd.." "" { target *-*-* } .-1 } +} + +fn main() { + struct NotAdd; + + unsafe { unchecked_add(NotAdd, NotAdd) }; +} From patchwork Tue Feb 21 12:01:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60050 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1843483wrn; Tue, 21 Feb 2023 04:52:30 -0800 (PST) X-Google-Smtp-Source: AK7set/Q/KB+QOvS8Cvk7Zm9c5wSrdp0VADUBNzB3YW1gT/KoAxjHPRAIyGwgZ5Xsx+SOCL4NFAB X-Received: by 2002:a05:6402:799:b0:4ac:bf55:e943 with SMTP id d25-20020a056402079900b004acbf55e943mr5388419edy.34.1676983950771; Tue, 21 Feb 2023 04:52:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983950; cv=none; d=google.com; s=arc-20160816; b=agqKgH3+58/iucZ7gJOEfM1K20MzgBFKpiOWeMST2qRW4P6oYo6l1K4vFHhStVdr2H FiVEsjpJtgS2uf+P93j0YIjksPnXAYCLeVtM5W1unhw7K+0YNqzj/xhjo2ThB/XWwmkR 4GyanGGMT88tSJiiwCJHwqGhigQBeOhCEV4+wr4ZgQhLnVEeVCsiTGm9mdgPIGKD8fwt l7THjrfa+6Na0X1f6BPepHTXrOBG4VspeHN7Qpm5GFP85Tr0QrWNDGNCF0ybhaOuqa9z b3i2JY2oEDwqPzapwtdvKkTo8x06NDFFNQoeHceh7HrTE6+CTd6d1Lm6Ik++IHkMnmdG ZDcg== 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=rFq0pn8FQeq3f3KVEDXQ7ZU0b3akL46rDfTt6VT0s+E=; b=apsSHSI1+f468xFsUBiUH2CvH3pq+hkRMWcWKuwtQYufRh6Ppt/sJPyZ1TmUktcrrY EgG6YAmmc8aMhSNlT8rccd9M0Ls37skCzviEy4E1z6EGbM54E8543X+zBq8Miljp5uE8 ++lkjdgxUpT8yBl7K+N+fUe8NuKFoCc4AnpyG2Apjv6EP4VCulsPqKhiy1Z4S88MaTAV K4ckD57lnWca/oq0tmWwxloveKZdkJM/ukWbWRgwOiQFQ15pjPhpxyiFQH0ugkYQgYD6 9RGo4VhNKoLp5/NEiUNtRvhfG+dEHXxr3U0TNNUEg3A7BOFqpHDTsB3f90hWB7IRtAbP mCEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=IDXVW2i4; 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 e12-20020a50ec8c000000b004acc6c6ecc0si2962365edr.228.2023.02.21.04.52.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:52:30 -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=IDXVW2i4; 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 11BBE39730D5 for ; Tue, 21 Feb 2023 12:17:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id 0DA0C383E281 for ; Tue, 21 Feb 2023 12:04:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0DA0C383E281 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-x434.google.com with SMTP id l25so3759207wrb.3 for ; Tue, 21 Feb 2023 04:04:14 -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=rFq0pn8FQeq3f3KVEDXQ7ZU0b3akL46rDfTt6VT0s+E=; b=IDXVW2i4XwCuYiAjoCQ3pcAKUCeAyVbz3Sw6l7p3PFP+cidAm23QhK/Fqb/3i5owNJ KqX/6X65v3JT4PFk6HRLYtBWTVY3rK04xryaUEdJU3MW+jlly+xjxMn/e8J4DcWu5Qpb 1lvPqd2SXY5B2913hPHYP9dgXwF8KN0rQ0K0kk3cBivVHJh1YharTSeTnXOrOqRzNDMQ UuOE1mlOMRGiqhQxm7Xo+eT1FFw7MrkmWg/yNe6tFxOkMhv3YcsOfbVog1k2W7QbXhht a9osYgqPImdWG1UEGw1L7nkCb1LoJHDC6cNneP+QLkBEabv0yicV2+wy9341ZFePSU9W yy3w== 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=rFq0pn8FQeq3f3KVEDXQ7ZU0b3akL46rDfTt6VT0s+E=; b=KkCFtNaZtUXLtSwdt/uOvAbYb6MJMeshiTRGd/Y5f/KsetA99XnRBw4F+8GqxG0kl5 tBoncBdaGNE3afPJLgqrleIr6sK/NKZ1ohnhjs7CSBhnatFzNsHUb/U8GlPWeo5ly6HB 4qNCfmKoa4RVpudcBafATj2xYhEnRr+eSfWbQoBPmcIl96f5b1m75IC4tp6z2E81D5zH HUISpp272f+BwTLri3R982nYfiDAFg+bT+MqmfsCsl8vFuW7ioPsdhz2UGKcfm6dSh3Y 1Q1ODP9fTbzGFHP7X5QwozW5Sr+qZgd3/n49Y23cGSLVMGmNpuSHgE+TS/rSgk8Tdj76 fWHQ== X-Gm-Message-State: AO0yUKXdxgwvbn2qW+jxh03Fyn0LBNHcUIgkK7jyoXi3/321IMtUdQ+w kzyeTd9W020Tz2FP+UhzVWhbAjDmAfiDppg+sg== X-Received: by 2002:a5d:53c5:0:b0:2c5:581d:5a1d with SMTP id a5-20020a5d53c5000000b002c5581d5a1dmr4068874wrw.43.1676981053397; Tue, 21 Feb 2023 04:04:13 -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.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:13 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 062/103] gccrs: intrinsics: Use lambdas for wrapping_ intrinsics Date: Tue, 21 Feb 2023 13:01:52 +0100 Message-Id: <20230221120230.596966-63-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.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=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?1758445123105845356?= X-GMAIL-MSGID: =?utf-8?q?1758445123105845356?= From: Arthur Cohen gcc/rust/ChangeLog: * backend/rust-compile-intrinsic.cc (wrapping_op_handler): Refactor to return an `std::function`. (wrapping_op_handler_inner): Rename. (wrapping_add_handler): Remove function. (wrapping_sub_handler): Likewise. (wrapping_mul_handler): Likewise. --- gcc/rust/backend/rust-compile-intrinsic.cc | 29 ++++++++-------------- 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc b/gcc/rust/backend/rust-compile-intrinsic.cc index 46ea5b3f795..142a2173672 100644 --- a/gcc/rust/backend/rust-compile-intrinsic.cc +++ b/gcc/rust/backend/rust-compile-intrinsic.cc @@ -59,7 +59,7 @@ transmute_handler (Context *ctx, TyTy::FnType *fntype); static tree rotate_handler (Context *ctx, TyTy::FnType *fntype, tree_code op); static tree -wrapping_op_handler (Context *ctx, TyTy::FnType *fntype, tree_code op); +wrapping_op_handler_inner (Context *ctx, TyTy::FnType *fntype, tree_code op); static tree copy_nonoverlapping_handler (Context *ctx, TyTy::FnType *fntype); @@ -83,21 +83,14 @@ rotate_right_handler (Context *ctx, TyTy::FnType *fntype) return rotate_handler (ctx, fntype, RROTATE_EXPR); } -static inline tree -wrapping_add_handler (Context *ctx, TyTy::FnType *fntype) -{ - return wrapping_op_handler (ctx, fntype, PLUS_EXPR); -} -static inline tree -wrapping_sub_handler (Context *ctx, TyTy::FnType *fntype) -{ - return wrapping_op_handler (ctx, fntype, MINUS_EXPR); -} -static inline tree -wrapping_mul_handler (Context *ctx, TyTy::FnType *fntype) +const static std::function +wrapping_op_handler (tree_code op) { - return wrapping_op_handler (ctx, fntype, MULT_EXPR); + return [op] (Context *ctx, TyTy::FnType *fntype) { + return wrapping_op_handler_inner (ctx, fntype, op); + }; } + static inline tree prefetch_read_data (Context *ctx, TyTy::FnType *fntype) { @@ -148,9 +141,9 @@ static const std::map(lhs: T, rhs: T) -> T; */ static tree -wrapping_op_handler (Context *ctx, TyTy::FnType *fntype, tree_code op) +wrapping_op_handler_inner (Context *ctx, TyTy::FnType *fntype, tree_code op) { // wrapping_ intrinsics have two parameter rust_assert (fntype->get_params ().size () == 2); From patchwork Tue Feb 21 12:01:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60022 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1837647wrn; Tue, 21 Feb 2023 04:38:49 -0800 (PST) X-Google-Smtp-Source: AK7set/BYL8Q6Dhl490MiAaqH9sw7bCW40WSsIqxWy2nOMBnhk//OXXVIQOpfx9X3HIkSTecY2oD X-Received: by 2002:aa7:db56:0:b0:4ad:a70c:e010 with SMTP id n22-20020aa7db56000000b004ada70ce010mr5540239edt.41.1676983129843; Tue, 21 Feb 2023 04:38:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983129; cv=none; d=google.com; s=arc-20160816; b=Urnl7hN0UuG3A8t0K3xdhcwl3el8Qa9/jtV8G8o429y9Zp+Ar7K6mu4kDuhuWQ/GQy Tsd4Qg3MB3UfIsK2rr4VyU8W6un2OzSlkOwrHgpM8a4bNwjWKqdrcXUuSBSeohNTtVer TeMCfA7rNUHBc/SStw+QV6fmsHgVP60WlJWOXWHXoywd8ng8sXiXw7WWzMTcu/tsd6Jl rlHBr7IsWiYx1r282qNIpoPOZHTeQRdVWEY/w5NgZWANgDKEgOk+Gl7OYfY+Y68ON+DJ 9P2ZlzkvlACU7uC1z5Sj6d3CTb8jfYDB59bhIcnEnHMGf6wwnq/7mMjkV3rGT/3RKCBa r8+A== 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=y4Ixa1KGj7wRHLUrMUNq040LE267nvqwm94j+ZxQG/A=; b=NzwSo6cyt7tB5XzcXqx5AyZB1qAgeq3ZETm1K+BQHSx/KhYKx9AfuLoGiKA/deO8Ia GoB1jBnoswv2m+jxBv9TqU0AXOz2G6o9h6FXX3wzYdHehzWGs6sSa0zn+BKOaI2usMxT rh2EBeY0IEqXodjeoQ2S+lOKmn48/HlaU1YvVqXJXrSVPWjR4zURNDxUjkDNpILUnZ1f ScuzgtE7Do3v5mxASGXzticbTC2fs/N7WSQsvEqvpVhDL31sQgarBOZN+3Aqr0GURnB8 Mggz8qnPtBojzMUi6zvIxZcVsBJQPGKLYMhkjNeXn7iSrr9uvr+/eCf6GgYpZxOcX9jB El6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b="WPE/F7L2"; 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 l13-20020aa7c30d000000b004ace0fce45asi18250259edq.509.2023.02.21.04.38.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:38:49 -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="WPE/F7L2"; 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 DDDCE38E8177 for ; Tue, 21 Feb 2023 12:13:36 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 6D26A3836E9B for ; Tue, 21 Feb 2023 12:04:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6D26A3836E9B 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-x435.google.com with SMTP id r7so3992476wrz.6 for ; Tue, 21 Feb 2023 04:04:15 -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=y4Ixa1KGj7wRHLUrMUNq040LE267nvqwm94j+ZxQG/A=; b=WPE/F7L2Bmm1m38Xrx7lQJWiBLovglHyBqrDSXx3QcywZWwp78AXm9ci5NYL3dlH+g RJkW13VvT6SuRUsB6HgAoDOYMxNwFgeUulYdK2JcESqANWDWSpKXES8+eBBIzHDeYbVp fUtqsjlaqQ3HQqQx40o+WLqXWSLZVOyxBS4wxkWkaaCH0tmRNK4ZOEMpR4lCHAfusiwx +Ow9RJ5nt6dp6tBukhL7xWTH4a/9vYE5D81+5Jdgq4lPSjC5WeOWJFLcPL6aXP4Br6+e Dh5tqBzO7cXqzOohxJUzvoA2tR8SKpIBNINgM8ePI2ADmdsXmjAqe3ZhsuHBsFb7YKjH +IKw== 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=y4Ixa1KGj7wRHLUrMUNq040LE267nvqwm94j+ZxQG/A=; b=TD57b9ned6gBOa/tdu+RWzKigUEC0WZnp8w3SytFDFEYYrhZsK+EJ+ou/JAk/hDmRl bPyi1OrkVic0+qztTeN75iqVw/NmtxKt9Rz2KfcKMBq10TEzU5KYprDfNTicZMycZouP XpJmg9a5NiKRODITIT4mMyM56yKldlfeVEtE01yUzRMh6TzSWZuil5coECQKBGJPcBAF OxwhyHknXm7JkaMyM184V8ANfLVv9GBB6Cr84yjJQMcERjTdZmUt1gLnapzfdZaB8az5 TBMrmRLQkQeoufnIh0Z/IhxSOwQ5q/nZ/bLoq2wV77a1YbJe4Jt4W0C7isWtU2C74vsw +zkQ== X-Gm-Message-State: AO0yUKV8sD6NmRVOBPR07/UD/BawDpHqoZOcAIkTX9iQrHC2+zoFTjmc awhs+Zt+fKdQDtiG3mhrLh8QRIFbLzxr3vzagw== X-Received: by 2002:adf:e805:0:b0:2c6:e670:8867 with SMTP id o5-20020adfe805000000b002c6e6708867mr4219103wrm.0.1676981054036; Tue, 21 Feb 2023 04:04:14 -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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:13 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 063/103] gccrs: intrinsics: Cleanup error handling around atomic_store_* Date: Tue, 21 Feb 2023 13:01:53 +0100 Message-Id: <20230221120230.596966-64-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.3 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?1758444262444569752?= X-GMAIL-MSGID: =?utf-8?q?1758444262444569752?= From: Arthur Cohen gcc/rust/ChangeLog: * backend/rust-compile-intrinsic.cc (check_for_basic_integer_type): New function. (build_atomic_builtin_name): Use HIR Type instead of `tree`. (atomic_store_handler_inner): Cleanup error handling. (unchecked_op_inner): Likewise. gcc/testsuite/ChangeLog: * rust/compile/torture/intrinsics-5.rs: Fix error message. --- gcc/rust/backend/rust-compile-intrinsic.cc | 50 +++++++++++-------- .../rust/compile/torture/intrinsics-5.rs | 4 +- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc b/gcc/rust/backend/rust-compile-intrinsic.cc index 142a2173672..b0c6015bee2 100644 --- a/gcc/rust/backend/rust-compile-intrinsic.cc +++ b/gcc/rust/backend/rust-compile-intrinsic.cc @@ -50,6 +50,22 @@ is_basic_integer_type (TyTy::BaseType *type) } } +static bool +check_for_basic_integer_type (const std::string &intrinsic_str, Location locus, + TyTy::BaseType *type) +{ + auto is_basic_integer = is_basic_integer_type (type); + if (!is_basic_integer) + { + rust_error_at ( + locus, + "%s intrinsics can only be used with basic integer types (got %qs)", + intrinsic_str.c_str (), type->get_name ().c_str ()); + } + + return is_basic_integer; +} + static tree offset_handler (Context *ctx, TyTy::FnType *fntype); static tree @@ -652,7 +668,7 @@ prefetch_data_handler (Context *ctx, TyTy::FnType *fntype, Prefetch kind) } static std::string -build_atomic_builtin_name (Location locus, tree operand_type) +build_atomic_builtin_name (Location locus, TyTy::BaseType *operand_type) { static const std::map allowed_types = { {"i8", "1"}, {"i16", "2"}, {"i32", "4"}, {"i64", "8"}, @@ -665,7 +681,7 @@ build_atomic_builtin_name (Location locus, tree operand_type) std::string result = "atomic_store_"; - auto type_name = std::string (TYPE_NAME_STRING (operand_type)); + auto type_name = operand_type->get_name (); if (type_name == "usize" || type_name == "isize") { rust_sorry_at ( @@ -673,21 +689,10 @@ build_atomic_builtin_name (Location locus, tree operand_type) return ""; } - // FIXME: Can we have a better looking name here? - // Instead of `::::`? - // Maybe instead of giving the tree node, pass the resolved Tyty before it - // gets compiled? - // - // Or should we perform this check somwhere else in the compiler? auto type_size_str = allowed_types.find (type_name); - if (type_size_str == allowed_types.end ()) - { - rust_error_at (locus, - "atomic intrinsics are only available for basic integer " - "types: got type %qs", - type_name.c_str ()); - return ""; - } + + if (!check_for_basic_integer_type ("atomic", locus, operand_type)) + return ""; result += type_size_str->second; @@ -726,8 +731,11 @@ atomic_store_handler_inner (Context *ctx, TyTy::FnType *fntype, int ordering) auto value = ctx->get_backend ()->var_expression (param_vars[1], Location ()); auto memorder = make_unsigned_long_tree (ctx, ordering); + auto monomorphized_type + = fntype->get_substs ()[0].get_param_ty ()->resolve (); + auto builtin_name - = build_atomic_builtin_name (fntype->get_locus (), TREE_TYPE (types[0])); + = build_atomic_builtin_name (fntype->get_locus (), monomorphized_type); if (builtin_name.empty ()) return error_mark_node; @@ -781,11 +789,9 @@ unchecked_op_inner (Context *ctx, TyTy::FnType *fntype, tree_code op) auto *monomorphized_type = fntype->get_substs ().at (0).get_param_ty ()->resolve (); - if (!is_basic_integer_type (monomorphized_type)) - rust_error_at (fntype->get_locus (), - "unchecked operation intrinsics can only be used with " - "basic integer types (got %qs)", - monomorphized_type->get_name ().c_str ()); + + check_for_basic_integer_type ("unchecked operation", fntype->get_locus (), + monomorphized_type); auto expr = build2 (op, TREE_TYPE (x), x, y); auto return_statement diff --git a/gcc/testsuite/rust/compile/torture/intrinsics-5.rs b/gcc/testsuite/rust/compile/torture/intrinsics-5.rs index e0087720cc4..7fd84dcd635 100644 --- a/gcc/testsuite/rust/compile/torture/intrinsics-5.rs +++ b/gcc/testsuite/rust/compile/torture/intrinsics-5.rs @@ -2,8 +2,8 @@ trait Copy {} extern "rust-intrinsic" { pub fn atomic_store_seqcst(dst: *mut T, value: T); - // { dg-error "atomic intrinsics are only available for basic integer types: got type .intrinsics_5::VeryLargeType." "" { target *-*-* } .-1 } - // { dg-error "atomic intrinsics are only available for basic integer types: got type .bool." "" { target *-*-* } .-2 } + // { dg-error "atomic intrinsics can only be used with basic integer types .got .VeryLargeType.." "" { target *-*-* } .-1 } + // { dg-error "atomic intrinsics can only be used with basic integer types .got .bool.." "" { target *-*-* } .-2 } } struct VeryLargeType { From patchwork Tue Feb 21 12:01: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: 60035 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1840286wrn; Tue, 21 Feb 2023 04:45:13 -0800 (PST) X-Google-Smtp-Source: AK7set9GcJVTuWBrwPPbpkIBdJkbvZhFhWTCeMfDhl67a4JxNJb7xzXqNebDjdj2WCxwtoGcAnNS X-Received: by 2002:a17:907:8c89:b0:8b1:779c:a8ac with SMTP id td9-20020a1709078c8900b008b1779ca8acmr17210477ejc.13.1676983513750; Tue, 21 Feb 2023 04:45:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983513; cv=none; d=google.com; s=arc-20160816; b=jYSbh0yX5a2Ietv4FNzosPwvj/EWaNXOH4VNfXs0APQegQ5pZGGgJZ8OwiKM7Ms7MB jmCMtCEt4p6sMTWTFrol61L/u0lmN1vDabptvqpE/D0ReThTj5Sz4gJwLi2wnV4LoWZS q6jtWp/6/Yl79GGDWoowPZaEBUC5L+EFRCKJYhO0YsC0a/n4mZg40Gq9+XDS9Bj3mwMv R5971C2Cpo9Yi5Z75MjhgB/KP8QUjDEXYyOJKczMSaYUst7ekhs3I8NFlhGyWXiFVBq9 aC18AAydZfX9ynXfcsGQ4F0MQfUF9IoPOXpqPUm4X11t4mxaLEeA4Q0TySOYVvcds87o 1Y4Q== 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=nYzQRgOHmXTgQjDWfcMLGmNVMNqbdUIYDJHuTupsqS0=; b=h/grDEWEi1U0gUMEwd9Wa/ms2YQHXCHZmzmfzkbtONx2pqQAtKO3mOIRoLDiHYls/r RLY8s3AQek9rr1Ut6qVN7XYabT70XAjD/v3TVhWTFqprJXWKD1sl9RwWmlZ2gqPDjE58 hVpqcVHkPtjC11FY4ONn/lHfH5zyGJX42AUHquTgOHxEtdmVRXerCfYPtlFU80+Kv+6c GViTjpKIL6pN0pSfCF/IiyTM0aHlFVeYkBJhVmUt8ersD39k2W4TytMJNmKjiStarCG9 GD0UPGkHyxBqPVL/bLMm1fLOIzNV9qG8jAAUPZpT2d0crG39F1bRBRsBTumUZwf/ySMq YIdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=FccjDFOk; 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 u17-20020a170906109100b008b17f6b8c98si18887744eju.994.2023.02.21.04.45.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:45:13 -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=FccjDFOk; 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 AA3413A20B96 for ; Tue, 21 Feb 2023 12:15:10 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 9781238323CE for ; Tue, 21 Feb 2023 12:04:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9781238323CE 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-x436.google.com with SMTP id c12so4164082wrw.1 for ; Tue, 21 Feb 2023 04:04:15 -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=nYzQRgOHmXTgQjDWfcMLGmNVMNqbdUIYDJHuTupsqS0=; b=FccjDFOksXoFL0JDMz56Rfx/cJ7AgK+J1hFZebOCpWQK71CDGzad1or8qjeuhFR8w/ E7vY8JtDN6zhLT1j4rTgxuGbQhidMP4zmyUrtBja/9VwWCCy1YSWh1Gifg+1S+DglRmD z9nQYS7tz1FmyJgTh6l0QI8AwwvM/wNnjp1d4EJ35j1LFgugma4jjJ69luoeD1PPOvbI UDokzF7sOzdSXtRbULmQeiw+9ZOt4yuM26Ta2F+yH0hd4UhXgDgvmy75XDHDiP5i147p DzBnU4fWnwlpsEDoIirT2MlvbLsVCG4nB0I271O+6OtEE1FS7DhL65mGnSQZLuaZwwDZ 5Xhg== 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=nYzQRgOHmXTgQjDWfcMLGmNVMNqbdUIYDJHuTupsqS0=; b=qiA07Zk6XtrjK3dBsH11ELWqbimytfjyxTWG9OAHSzfz/IAC5e4HdXzzPllkFyrem/ EjKBnapQzugo6gN7xOSEWh59oCck/NugRbcL/D4MVlrtKFLhePRtjhzH/seR+k+vLxLS fXhh6MGxQfyxE21NZx7EfnPPcqw3xTxrXUDn0BPsneigl8ilnu2/TlTGo1WMj1s8nrZW f81dwnwXi56H/R3sVs/U8gFBEqZCaCjXSOwgvPg5EsjCovwIW4FTHYYWJnDosxrFOkM7 of+/U/iwulcwoNQvJ6FlL+THMPU33nzUPebFwZjUTB6x/vBmT1TMR68rbhpUIAHljY8H IL4w== X-Gm-Message-State: AO0yUKWXzv9FYz/aDTRTKaRFm9jI1/GXo12/9puspW5kO0FS8JamLNja gGDxZm9mYt0dnu+Sv6ueai7w+qe5ivQBmUnFPw== X-Received: by 2002:a5d:4805:0:b0:2c5:4e3c:d390 with SMTP id l5-20020a5d4805000000b002c54e3cd390mr4166390wrq.62.1676981054887; Tue, 21 Feb 2023 04:04:14 -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.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:14 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 064/103] gccrs: intrinsics: Implement atomic_load intrinsics Date: Tue, 21 Feb 2023 13:01:54 +0100 Message-Id: <20230221120230.596966-65-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.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 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?1758444665280763054?= X-GMAIL-MSGID: =?utf-8?q?1758444665280763054?= From: Arthur Cohen gcc/rust/ChangeLog: * backend/rust-builtins.cc (BuiltinsContext::setup_atomic_fns): Declare atomic load intrinsics. * backend/rust-compile-intrinsic.cc (atomic_load_handler_inner): New handler. (atomic_load_handler): Likewise. (unchecked_op_handler): Remove `static` function qualifier. (build_atomic_builtin_name): Handle load intrinsics. (atomic_store_handler_inner): New handler. gcc/testsuite/ChangeLog: * rust/compile/torture/intrinsics-3.rs: * rust/execute/torture/atomic_load.rs: New test. --- gcc/rust/backend/rust-builtins.cc | 56 ++++++------ gcc/rust/backend/rust-compile-intrinsic.cc | 88 +++++++++++++++++-- .../rust/compile/torture/intrinsics-3.rs | 2 - .../rust/execute/torture/atomic_load.rs | 31 +++++++ 4 files changed, 144 insertions(+), 33 deletions(-) create mode 100644 gcc/testsuite/rust/execute/torture/atomic_load.rs diff --git a/gcc/rust/backend/rust-builtins.cc b/gcc/rust/backend/rust-builtins.cc index 64e06e1a240..66b3becc47a 100644 --- a/gcc/rust/backend/rust-builtins.cc +++ b/gcc/rust/backend/rust-builtins.cc @@ -71,36 +71,42 @@ BuiltinsContext::setup_math_fns () void BuiltinsContext::setup_atomic_fns () { - define_builtin ("atomic_store", BUILT_IN_ATOMIC_STORE, "__atomic_store", NULL, - build_function_type_list (void_type_node, size_type_node, - build_pointer_type (void_type_node), - const_ptr_type_node, - integer_type_node, NULL_TREE), - 0); - define_builtin ("atomic_store_n", BUILT_IN_ATOMIC_STORE_N, "__atomic_store_n", - NULL, - build_varargs_function_type_list (void_type_node, NULL_TREE), - 0); + auto atomic_store_type + = build_varargs_function_type_list (void_type_node, NULL_TREE); + auto atomic_load_type = [] (tree ret_type_node) { + return build_function_type_list (ret_type_node, + ptr_type_node, // const_ptr_type_node? + integer_type_node, NULL_TREE); + }; + + // FIXME: These should be the definition for the generic version of the + // atomic_store builtins, but I cannot get them to work properly. Revisit + // later. define_builtin ("atomic_store", BUILT_IN_ATOMIC_STORE, + // "__atomic_store", NULL, + // atomic_store_type, 0); + // define_builtin ("atomic_store_n", BUILT_IN_ATOMIC_STORE_N, + // "__atomic_store_n", + // NULL, atomic_store_type, 0); + define_builtin ("atomic_store_1", BUILT_IN_ATOMIC_STORE_1, "__atomic_store_1", - NULL, - build_varargs_function_type_list (void_type_node, NULL_TREE), - 0); + NULL, atomic_store_type, 0); define_builtin ("atomic_store_2", BUILT_IN_ATOMIC_STORE_2, "__atomic_store_2", - NULL, - build_varargs_function_type_list (void_type_node, NULL_TREE), - 0); + NULL, atomic_store_type, 0); define_builtin ("atomic_store_4", BUILT_IN_ATOMIC_STORE_4, "__atomic_store_4", - NULL, - build_varargs_function_type_list (void_type_node, NULL_TREE), - 0); + NULL, atomic_store_type, 0); define_builtin ("atomic_store_8", BUILT_IN_ATOMIC_STORE_8, "__atomic_store_8", - NULL, - build_varargs_function_type_list (void_type_node, NULL_TREE), - 0); + NULL, atomic_store_type, 0); define_builtin ("atomic_store_16", BUILT_IN_ATOMIC_STORE_16, - "__atomic_store_16", NULL, - build_varargs_function_type_list (void_type_node, NULL_TREE), - 0); + "__atomic_store_16", NULL, atomic_store_type, 0); + + define_builtin ("atomic_load_1", BUILT_IN_ATOMIC_LOAD_1, "__atomic_load_1", + NULL, atomic_load_type (integer_type_node), 0); + define_builtin ("atomic_load_2", BUILT_IN_ATOMIC_LOAD_2, "__atomic_load_2", + NULL, atomic_load_type (integer_type_node), 0); + define_builtin ("atomic_load_4", BUILT_IN_ATOMIC_LOAD_4, "__atomic_load_4", + NULL, atomic_load_type (integer_type_node), 0); + define_builtin ("atomic_load_8", BUILT_IN_ATOMIC_LOAD_8, "__atomic_load_8", + NULL, atomic_load_type (integer_type_node), 0); } void diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc b/gcc/rust/backend/rust-compile-intrinsic.cc index b0c6015bee2..55222116366 100644 --- a/gcc/rust/backend/rust-compile-intrinsic.cc +++ b/gcc/rust/backend/rust-compile-intrinsic.cc @@ -120,6 +120,8 @@ prefetch_write_data (Context *ctx, TyTy::FnType *fntype) static tree atomic_store_handler_inner (Context *ctx, TyTy::FnType *fntype, int ordering); +static tree +atomic_load_handler_inner (Context *ctx, TyTy::FnType *fntype, int ordering); static inline std::function atomic_store_handler (int ordering) @@ -129,6 +131,14 @@ atomic_store_handler (int ordering) }; } +static inline std::function +atomic_load_handler (int ordering) +{ + return [ordering] (Context *ctx, TyTy::FnType *fntype) { + return atomic_load_handler_inner (ctx, fntype, ordering); + }; +} + static inline tree unchecked_op_inner (Context *ctx, TyTy::FnType *fntype, tree_code op); @@ -140,7 +150,7 @@ unchecked_op_handler (tree_code op) }; } -static inline tree +inline tree sorry_handler (Context *ctx, TyTy::FnType *fntype) { rust_sorry_at (fntype->get_locus (), "intrinsic %qs is not yet implemented", @@ -163,11 +173,14 @@ static const std::map allowed_types = { {"i8", "1"}, {"i16", "2"}, {"i32", "4"}, {"i64", "8"}, @@ -679,7 +693,7 @@ build_atomic_builtin_name (Location locus, TyTy::BaseType *operand_type) // TODO: Can we maybe get the generic version (atomic_store_n) to work... This // would be so much better - std::string result = "atomic_store_"; + std::string result = prefix; auto type_name = operand_type->get_name (); if (type_name == "usize" || type_name == "isize") @@ -735,7 +749,8 @@ atomic_store_handler_inner (Context *ctx, TyTy::FnType *fntype, int ordering) = fntype->get_substs ()[0].get_param_ty ()->resolve (); auto builtin_name - = build_atomic_builtin_name (fntype->get_locus (), monomorphized_type); + = build_atomic_builtin_name ("atomic_store_", fntype->get_locus (), + monomorphized_type); if (builtin_name.empty ()) return error_mark_node; @@ -751,7 +766,6 @@ atomic_store_handler_inner (Context *ctx, TyTy::FnType *fntype, int ordering) = ctx->get_backend ()->call_expression (atomic_store, {dst, value, memorder}, nullptr, Location ()); - TREE_READONLY (store_call) = 0; TREE_SIDE_EFFECTS (store_call) = 1; @@ -761,6 +775,68 @@ atomic_store_handler_inner (Context *ctx, TyTy::FnType *fntype, int ordering) return fndecl; } +static tree +atomic_load_handler_inner (Context *ctx, TyTy::FnType *fntype, int ordering) +{ + rust_assert (fntype->get_params ().size () == 1); + rust_assert (fntype->get_num_substitutions () == 1); + + tree lookup = NULL_TREE; + if (check_for_cached_intrinsic (ctx, fntype, &lookup)) + return lookup; + + auto fndecl = compile_intrinsic_function (ctx, fntype); + + // Most intrinsic functions are pure but not the atomic ones + // FIXME: Is atomic_load_* pure? Feels like it shouldn't so + TREE_READONLY (fndecl) = 0; + TREE_SIDE_EFFECTS (fndecl) = 1; + + // setup the params + std::vector param_vars; + std::vector types; + compile_fn_params (ctx, fntype, fndecl, ¶m_vars, &types); + + auto ok = ctx->get_backend ()->function_set_parameters (fndecl, param_vars); + rust_assert (ok); + + enter_intrinsic_block (ctx, fndecl); + + auto src = ctx->get_backend ()->var_expression (param_vars[0], Location ()); + auto memorder = make_unsigned_long_tree (ctx, ordering); + + auto monomorphized_type + = fntype->get_substs ()[0].get_param_ty ()->resolve (); + + auto builtin_name + = build_atomic_builtin_name ("atomic_load_", fntype->get_locus (), + monomorphized_type); + if (builtin_name.empty ()) + return error_mark_node; + + tree atomic_load_raw = nullptr; + BuiltinsContext::get ().lookup_simple_builtin (builtin_name, + &atomic_load_raw); + rust_assert (atomic_load_raw); + + auto atomic_load + = build_fold_addr_expr_loc (Location ().gcc_location (), atomic_load_raw); + + auto load_call + = ctx->get_backend ()->call_expression (atomic_load, {src, memorder}, + nullptr, Location ()); + auto return_statement + = ctx->get_backend ()->return_statement (fndecl, {load_call}, Location ()); + + TREE_READONLY (load_call) = 0; + TREE_SIDE_EFFECTS (load_call) = 1; + + ctx->add_statement (return_statement); + finalize_intrinsic_block (ctx, fndecl); + + return fndecl; +} + static inline tree unchecked_op_inner (Context *ctx, TyTy::FnType *fntype, tree_code op) { diff --git a/gcc/testsuite/rust/compile/torture/intrinsics-3.rs b/gcc/testsuite/rust/compile/torture/intrinsics-3.rs index 1acb3533c08..5c131bd8aa2 100644 --- a/gcc/testsuite/rust/compile/torture/intrinsics-3.rs +++ b/gcc/testsuite/rust/compile/torture/intrinsics-3.rs @@ -1,9 +1,7 @@ extern "rust-intrinsic" { fn not_an_intrinsic(); - fn atomic_load(); // { dg-message "sorry, unimplemented: intrinsic .atomic_load. is not yet implemented" } } fn main() { unsafe { not_an_intrinsic() }; // { dg-error "unknown builtin intrinsic: not_an_intrinsic" } - unsafe { atomic_load() }; } diff --git a/gcc/testsuite/rust/execute/torture/atomic_load.rs b/gcc/testsuite/rust/execute/torture/atomic_load.rs new file mode 100644 index 00000000000..28ed8ae78f1 --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/atomic_load.rs @@ -0,0 +1,31 @@ +trait Copy {} + +extern "rust-intrinsic" { + pub fn atomic_load_seqcst(src: *const T) -> T; + pub fn atomic_load_acquire(src: *const T) -> T; + pub fn atomic_load_relaxed(src: *const T) -> T; + pub fn atomic_load_unordered(src: *const T) -> T; +} + +fn main() -> i32 { + let one; + let two; + let three; + let four; + + unsafe { + let mut src = 1; + one = atomic_load_seqcst(&src); + + src = 2; + two = atomic_load_acquire(&src); + + src = 3; + three = atomic_load_relaxed(&src); + + src = 4; + four = atomic_load_unordered(&src); + } + + (four + three + two + one) - 10 +} From patchwork Tue Feb 21 12:01:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60032 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1839409wrn; Tue, 21 Feb 2023 04:43:05 -0800 (PST) X-Google-Smtp-Source: AK7set/HoL3JEUFGbt9Txdfc0D7AkJM9eEShsnwx9R2ywKn64JQeqBo9TgEEbjcUwdM536GFwbfa X-Received: by 2002:a17:907:888b:b0:878:6519:c740 with SMTP id rp11-20020a170907888b00b008786519c740mr16111610ejc.44.1676983385652; Tue, 21 Feb 2023 04:43:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983385; cv=none; d=google.com; s=arc-20160816; b=z1YDO7wccrbBTjS6xfj9vaIwhWk4nyzuj+C2pdWaG6nL3qfulJ4Y0lbh3JN3sdQv3K k+bRs4AE3s7FJ+8BUQsqtwmPVgRJtHGIvfFSqfRA1NTI/9zjloQLOuojArQCk5inImDa HXmsE9L0Qortv9ksr1HM6y6QoJ5Ge37aJMnOOzCk8hXNztQqp+vRAP8QNLJwk5ME+8D2 S57ljsxcBNTPHPW1+bJqvpOfzQDx1s4aUMZJ3j8FBmgpC3eU5+qR+I2wFz89C+08yBiA NAZ8hVBspkmyXl7c1RYnk2AWaXn+1geqpgv4DpI3olUtavQ5/I/0U24MGLVhZrLZqdKx cXqQ== 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=W1xmgehrU8TuQqqCih7THK1rfPPB+3RmditxusaMbCs=; b=gsZi8TtniGz66w1/h5E++8wf/HFS4wZoIq4OUGy4lICW0Wing1VZwfcTec/Hwk5KH2 6pwJLl1532WHdPsrwe3Ci73k8EAG67j4JWWAVjcByE5CQCDTThMscPtCw8Ay8OBg7S11 oyKxeKt5dSZLYcfDJ0zBGobJja6+TrxGOofziBaxgcYs7Xh70DhQoUVOPUjkJe8ESEqo tvLj82i6EffcT0FuujhzBu0TLIY0o5255pcll+/1+m6capfmtmaSpvvB5YxsNIWFrnwB oPgE99nfV3WS8AauykJSXAWrVLU2k33bz8PiizbcnY9sAxM7ouUjPDSpvlm5vqXYcAeJ W3Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=KMOLu21R; 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 zz14-20020a170907350e00b008da033ef977si4071882ejb.731.2023.02.21.04.43.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:43:05 -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=KMOLu21R; 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 B5E32383FE1B for ; Tue, 21 Feb 2023 12:14:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 B9DF738323E6 for ; Tue, 21 Feb 2023 12:04:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B9DF738323E6 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 r7so3992592wrz.6 for ; Tue, 21 Feb 2023 04:04:16 -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=W1xmgehrU8TuQqqCih7THK1rfPPB+3RmditxusaMbCs=; b=KMOLu21R3rCTRHso2OiTEYDNNI9KWq0+DvGRV8QXFSzNzK1PSQigRUeCmCX2FHtmTz hG60IPBn1xVPdWJiFlkFn7dweWMhGNlAkJNWAbYe+iV3LYMgJY2575ZPgSwTXWAU0hMd b1cAl2A4GNiz0W46rbk9clR99yb9R58LeWu24TzzWquYpUiUf3/eq3GeAz/g/qJlop47 Mjvaqt8IxxTLCubkk2G++VgTtImCPsgnFVKQy+h888EOTKfeUNq87Mvqzx1vsx1QzDH9 eAoCWBEZmNzUtl9ZTQ229rSv4xRojx3F565PjC39CKgfheRu7H6lEcJOnstQgYJkpmO3 UAsw== 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=W1xmgehrU8TuQqqCih7THK1rfPPB+3RmditxusaMbCs=; b=DITJWV+WcVjerDMEQdTOrXVaZ6MC7wHLQ/Q/l5HIr1qgWHQQ1/7j46BFrq9kCKu9CU N8ACdYC8gmFwYjQz5W7qaKtBw1oBLPrCPTcRrPoHb7w+s2CCUAX5S/cNhmrLPDJEDVko +LBTP8SIZcPIHk+6OHggb3cEVL4pt9gnZF+X7Sg4mgLpGxP8TqmttQRRw+cIca+w6jTV 6C61k1Qt56taRj7zSkpZbgc55Tf9mz340F11oWPLkSSQCp3Z/5ValR+1mB8WqhzvysIX lTI2f8vJsFKFNLiygG7EoTXqoq98dHLYfdfWQaXzeI6dRMNjOumuo4lGaEzmxG/tOgdM O5Dw== X-Gm-Message-State: AO0yUKXuMdMo9zz3ycLUCIptid3Yfh50H6g6ZxrZI5hDIszBRbr8Biln bTXM/WXS+0L4OXZGWiSyE0eldOVNN/Ozbxodpg== X-Received: by 2002:a05:6000:114e:b0:2c4:9d7:c7da with SMTP id d14-20020a056000114e00b002c409d7c7damr3305029wrx.65.1676981055849; Tue, 21 Feb 2023 04:04:15 -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.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:15 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 065/103] gccrs: ast: visitor pattern -> overload syntax compatibility layer Date: Tue, 21 Feb 2023 13:01:55 +0100 Message-Id: <20230221120230.596966-66-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.3 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 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?1758444531013473088?= X-GMAIL-MSGID: =?utf-8?q?1758444531013473088?= From: Jakub Dupak gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add new visit function for overloading. * ast/rust-ast-dump.h: Add documentation for layer. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 7 +++++++ gcc/rust/ast/rust-ast-dump.h | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 4817962f767..9771f432ea0 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -62,6 +62,13 @@ Dump::go (AST::Item &item) item.accept_vis (*this); } +template +void +Dump::visit (std::unique_ptr &node) +{ + node->accept_vis (*this); +} + void Dump::format_function_param (FunctionParam ¶m) { diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h index 9fe8ee95493..7cd922e0ac9 100644 --- a/gcc/rust/ast/rust-ast-dump.h +++ b/gcc/rust/ast/rust-ast-dump.h @@ -72,6 +72,14 @@ private: std::ostream &stream; Indent indentation; + /** + * Compatibility layer for using the visitor pattern on polymorphic classes + * with a unified overload syntax. This allows us to call `visit` both on + * types implementing `accept_vis` method and for classes for which the + * `visit` method is directly implemented. + */ + template void visit (std::unique_ptr &node); + /** * Format together common items of functions: Parameters, return type, block */ From patchwork Tue Feb 21 12:01:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60027 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1838724wrn; Tue, 21 Feb 2023 04:41:26 -0800 (PST) X-Google-Smtp-Source: AK7set+rVFaHTCssMmgSf8M8bwBRPjT3/Y7oKEZYYZbK7nn2dkAD3Y6OUBkIfJiXgcX4EbPpAhXc X-Received: by 2002:a05:6402:4d7:b0:4aa:a4e6:249b with SMTP id n23-20020a05640204d700b004aaa4e6249bmr3827339edw.7.1676983286540; Tue, 21 Feb 2023 04:41:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983286; cv=none; d=google.com; s=arc-20160816; b=E1mRWKz/fcm6WxjiZOVSVgpZLubI/7jpZRjmkzBvaXjeocXFEsKUkVnihCq3Tryf8c YG8Xvrc4eBmvBAzinLJG/TMRp+ND021gGtp0dlsYexSbJyL/jAcy1cV3cUA4e0IMzkzk 0dmyL+/EiUZ1zHNbdxfUM6ggwPcGs+acx4bEUhfN2NCi8E9PLLU5tBrUnVQD0iFsmZep u3b2+y9sOJ26BoB9tglUjEDvWKBS8jC4UfT1eo5s2l6AjXjhsqO83s0nijj118K6SuTU l53eeY5uwAEgbQDvDC6SEIsXF2FIBMel1yC/4/LChz6B9axPcnejUIOah77bcrZ92ofO xUmA== 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=VINjvqRB1H0DsHj26Sspz8KviPA7rHIBhZ6kyuYQi2w=; b=J3ln1ly7R15ah4ALJ23DK+SSMa4AAgyJIsmqMmvfrzwDziv81zLtKsXP6RTwPILMBI NqSHFMGZoI7JmqIXNxIGRmm25WJH1JfCA3rTzlA1+h0J7pZC8dzthh1x3XpqNIetYTGe RAT2+UEf2jWiGZ6wQ/jbgJNlIWea+dYfmI2fED5aMqW2t/E/LDA+xBSpEviVm0oabIEr jRJrU/dX1lA8VIe+rPmKVUzwgTjyb9Fm32OY1pe00lXO2D6oQElmBf/J3ltWwl4fl1eZ iApDQ7hE5djjfpjcwVqjs8OLg+kyvwkp9zBL1DUcQeUUzI0KwjoUbJICAvvdsjXOYDBI ID2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b="VO8Wnc/W"; 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 h7-20020a50ed87000000b004ac8e6409a1si9190627edr.91.2023.02.21.04.41.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:41:26 -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="VO8Wnc/W"; 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 144C638CB1A8 for ; Tue, 21 Feb 2023 12:14:16 +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 1513938323EC for ; Tue, 21 Feb 2023 12:04:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1513938323EC 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 l1so3887062wry.10 for ; Tue, 21 Feb 2023 04:04:18 -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=VINjvqRB1H0DsHj26Sspz8KviPA7rHIBhZ6kyuYQi2w=; b=VO8Wnc/WvRFGBOzA9K7b4XCrYcLdgGLva+YbxUHi7yXylZwBJZ9AMrEjWYcL3tdWXv Ulf2f14hWiLgm4je5tPPGB7pfCiYpqcTLiobwlxVDj8OiYavv89sP0k+cj6YkpTdiiiq ekFFLsmRms21AVXyGg82tmgl09WlO4GuJ1W/dPM/OTcfwEtqXqxuEqfZdirE08XiEi2d UdIXnEKkOgIXDkPegiqnJBkNAvyYEKrYLO1syLBrliAsCZPePFRQRZvq43ZKZSe1HKP4 n+PJA/f75d2UYmiAEf5nmHjFyYIkrQdoRHgKn5TT+y9lVQ6bn3B07ywdH4pRmLDJ6ssl IEPQ== 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=VINjvqRB1H0DsHj26Sspz8KviPA7rHIBhZ6kyuYQi2w=; b=Jgk52PRiCZrbScGFe0Qt0eQSXblpUEf3HjPg6Rfo8ePbZVmWPPxQmu8NnKqAPEloL0 UIkNwkYk1cxQKH3HXQbvysq6rCA3bcECNMqCVSUYjDmQCecCVj0PJ+V8xyGE6dXX7pQ2 sPnlf69aDCI23gteoGtcYi3qBVb9UxQuYp6STUVbtXQDQalLj8yQUYRLtvG3GuXi8AQ2 s5WdDEiAndjp2smig7sSIkrny/Xgbz1bmB2YBV6TiEFSPTt2MNoSYJ09+9RumuNylMEV bLTHq4DezNPWvjJhmwrMVYxfOLRSwpKZF0GuvWuX8EDI0l/TJt+Nl9dXX+vGEjyZUtpc VJzQ== X-Gm-Message-State: AO0yUKUkpruyrCUACwTvUC0V+FgeEHI07BZC/Xi34xTfhVkjsXDJ7jcs HCm/jOeC7sRh1g7eeR5IGL5Fug7vMcN+y05JaA== X-Received: by 2002:a05:6000:1146:b0:2c5:8c04:efbf with SMTP id d6-20020a056000114600b002c58c04efbfmr2542145wrx.13.1676981057210; Tue, 21 Feb 2023 04:04:17 -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.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:16 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 066/103] gccrs: ast: transform helper methods to visits and add methods to simplify repeated patterns Date: Tue, 21 Feb 2023 13:01:56 +0100 Message-Id: <20230221120230.596966-67-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.3 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?1758444426820362410?= X-GMAIL-MSGID: =?utf-8?q?1758444426820362410?= From: Jakub Dupak gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::go): Use new API. (Dump::format_function_param): Refactor. (Dump::visit_items_joined_by_separator): New function. (Dump::emit_attrib): Refactor. (Dump::visit_as_line): New function. (Dump::visit_items_as_lines): Likewise. (Dump::visit_items_as_block): Likewise. (Dump::visit): Use new API. (Dump::emit_visibility): Likewise. (Dump::emit_indented_string): Likewise. (Dump::emit_generic_params): Likewise. (Dump::format_tuple_field): Likewise. (Dump::format_struct_field): Likewise. (Dump::format_function_common): Likewise. (Dump::visit_function_common): Likewise. * ast/rust-ast-dump.h: Declare new functions and add documentation. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 559 ++++++++++++---------------------- gcc/rust/ast/rust-ast-dump.h | 63 ++-- 2 files changed, 235 insertions(+), 387 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 9771f432ea0..191e328b134 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -48,12 +48,7 @@ Dump::Dump (std::ostream &stream) : stream (stream), indentation (Indent ()) {} void Dump::go (AST::Crate &crate) { - for (auto &item : crate.items) - { - stream << indentation; - item->accept_vis (*this); - stream << '\n'; - } + visit_items_as_lines (crate.items, ""); } void @@ -69,28 +64,75 @@ Dump::visit (std::unique_ptr &node) node->accept_vis (*this); } +template void -Dump::format_function_param (FunctionParam ¶m) +Dump::visit_items_joined_by_separator (T &collection, + const std::string &separator, + size_t start_offset, size_t end_offset) { - param.get_pattern ()->accept_vis (*this); - stream << ": "; - param.get_type ()->accept_vis (*this); + if (collection.size () > start_offset) + { + visit (collection.at (start_offset)); + auto size = collection.size () - end_offset; + for (size_t i = start_offset + 1; i < size; i++) + { + stream << separator; + visit (collection.at (i)); + } + } } +template void -Dump::emit_attrib (const Attribute &attrib) +Dump::visit_as_line (T &item, const std::string &trailing) { - stream << "#["; + stream << indentation; + visit (item); + stream << trailing << '\n'; +} - for (size_t i = 0; i < attrib.get_path ().get_segments ().size (); i++) +template +void +Dump::visit_items_as_lines (T &collection, const std::string &trailing) +{ + for (auto &item : collection) + visit_as_line (item, trailing); +} + +template +void +Dump::visit_items_as_block (T &collection, const std::string &line_trailing, + char left_brace, char right_brace) +{ + if (collection.empty ()) { - const auto &seg = attrib.get_path ().get_segments ().at (i); - bool has_next = (i + 1) < attrib.get_path ().get_segments ().size (); + stream << left_brace << right_brace << '\n'; + } + else + { + stream << left_brace << '\n'; + + indentation.increment (); + visit_items_as_lines (collection, line_trailing); + indentation.decrement (); - stream << seg.get_segment_name (); - if (has_next) - stream << "::"; + stream << indentation << right_brace << '\n'; } +} + +void +Dump::visit (FunctionParam ¶m) +{ + visit (param.get_pattern ()); + stream << ": "; + visit (param.get_type ()); +} + +void +Dump::visit (const Attribute &attrib) +{ + stream << "#["; + visit_items_joined_by_separator (attrib.get_path ().get_segments (), "::"); if (attrib.has_attr_input ()) { @@ -116,7 +158,13 @@ Dump::emit_attrib (const Attribute &attrib) } void -Dump::emit_visibility (const Visibility &vis) +Dump::visit (const SimplePathSegment &segment) +{ + stream << segment.get_segment_name (); +} + +void +Dump::visit (const Visibility &vis) { switch (vis.get_vis_type ()) { @@ -140,44 +188,36 @@ Dump::emit_visibility (const Visibility &vis) } } -std::ostream & -Dump::emit_indented_string (const std::string &value, - const std::string &comment) +void +Dump::visit (NamedFunctionParam ¶m) { - return stream << indentation << value << comment; + stream << param.get_name () << ": "; + visit (param.get_type ()); } void -Dump::emit_generic_params (std::vector> ¶ms) +Dump::visit (std::vector> ¶ms) { stream << "<"; - for (size_t i = 0; i < params.size (); i++) - { - auto ¶m = params.at (i); - param->accept_vis (*this); - - bool has_next = (i + 1) < params.size (); - if (has_next) - stream << ", "; - } + visit_items_joined_by_separator (params, ", "); stream << ">"; } void -Dump::format_tuple_field (TupleField &field) +Dump::visit (TupleField &field) { // TODO: do we need to emit outer attrs here? - emit_visibility (field.get_visibility ()); - field.get_field_type ()->accept_vis (*this); + visit (field.get_visibility ()); + visit (field.get_field_type ()); } void -Dump::format_struct_field (StructField &field) +Dump::visit (StructField &field) { // TODO: do we need to emit outer attrs here? - emit_visibility (field.get_visibility ()); + visit (field.get_visibility ()); stream << field.get_field_name () << ": "; - field.get_field_type ()->accept_vis (*this); + visit (field.get_field_type ()); } void @@ -189,16 +229,11 @@ Dump::visit (Token &tok) void Dump::visit (DelimTokenTree &delim_tok_tree) { - auto tokens = delim_tok_tree.to_token_stream (); - indentation.increment (); stream << '\n' << indentation; - for (const auto &tok : tokens) - { - stream << ' '; - tok->accept_vis (*this); - } + auto tokens = delim_tok_tree.to_token_stream (); + visit_items_joined_by_separator (tokens, " "); indentation.decrement (); stream << '\n' << indentation; @@ -289,20 +324,20 @@ Dump::visit (BorrowExpr &expr) if (expr.get_is_mut ()) stream << "mut "; - expr.get_borrowed_expr ()->accept_vis (*this); + visit (expr.get_borrowed_expr ()); } void Dump::visit (DereferenceExpr &expr) { stream << '*'; - expr.get_dereferenced_expr ()->accept_vis (*this); + visit (expr.get_dereferenced_expr ()); } void Dump::visit (ErrorPropagationExpr &expr) { - expr.get_propagating_expr ()->accept_vis (*this); + visit (expr.get_propagating_expr ()); stream << '?'; } @@ -318,7 +353,7 @@ Dump::visit (NegationExpr &expr) stream << '!'; break; } - expr.get_negated_expr ()->accept_vis (*this); + visit (expr.get_negated_expr ()); } void @@ -368,9 +403,9 @@ Dump::visit (ArithmeticOrLogicalExpr &expr) break; } - expr.get_left_expr ()->accept_vis (*this); + visit (expr.get_left_expr ()); stream << " " << op << " "; - expr.get_right_expr ()->accept_vis (*this); + visit (expr.get_right_expr ()); } void @@ -403,9 +438,9 @@ Dump::visit (ComparisonExpr &expr) break; } - expr.get_left_expr ()->accept_vis (*this); + visit (expr.get_left_expr ()); stream << " " << op << " "; - expr.get_right_expr ()->accept_vis (*this); + visit (expr.get_right_expr ()); } void @@ -422,17 +457,17 @@ Dump::visit (LazyBooleanExpr &expr) break; } - expr.get_left_expr ()->accept_vis (*this); + visit (expr.get_left_expr ()); stream << " " << op << " "; - expr.get_right_expr ()->accept_vis (*this); + visit (expr.get_right_expr ()); } void Dump::visit (TypeCastExpr &expr) { - expr.get_casted_expr ()->accept_vis (*this); + visit (expr.get_casted_expr ()); stream << " as "; - expr.get_type_to_cast_to ()->accept_vis (*this); + visit (expr.get_type_to_cast_to ()); } void @@ -490,56 +525,47 @@ Dump::visit (CompoundAssignmentExpr &expr) break; } - expr.get_left_expr ()->accept_vis (*this); + visit (expr.get_left_expr ()); stream << " " << op << "= "; - expr.get_right_expr ()->accept_vis (*this); + visit (expr.get_right_expr ()); } void Dump::visit (GroupedExpr &expr) { stream << '('; - expr.get_expr_in_parens ()->accept_vis (*this); + visit (expr.get_expr_in_parens ()); stream << ')'; } void Dump::visit (ArrayElemsValues &elems) { - auto &vals = elems.get_values (); - if (vals.size () >= 1) - { - vals[0]->accept_vis (*this); - for (size_t i = 1; i < vals.size (); i++) - { - stream << ", "; - vals[i]->accept_vis (*this); - } - } + visit_items_joined_by_separator (elems.get_values (), ", "); } void Dump::visit (ArrayElemsCopied &elems) { - elems.get_elem_to_copy ()->accept_vis (*this); + visit (elems.get_elem_to_copy ()); stream << "; "; - elems.get_num_copies ()->accept_vis (*this); + visit (elems.get_num_copies ()); } void Dump::visit (ArrayExpr &expr) { stream << '['; - expr.get_array_elems ()->accept_vis (*this); + visit (expr.get_array_elems ()); stream << ']'; } void Dump::visit (ArrayIndexExpr &expr) { - expr.get_array_expr ()->accept_vis (*this); + visit (expr.get_array_expr ()); stream << '['; - expr.get_index_expr ()->accept_vis (*this); + visit (expr.get_index_expr ()); stream << ']'; } @@ -578,21 +604,15 @@ Dump::visit (StructExprStructBase &expr) void Dump::visit (CallExpr &expr) { - expr.get_function_expr ()->accept_vis (*this); - stream << '('; + visit (expr.get_function_expr ()); + stream << '(' << '\n'; indentation.increment (); - for (auto &arg : expr.get_params ()) - { - stream << '\n' << indentation; - arg->accept_vis (*this); - stream << ','; - } + visit_items_as_lines (expr.get_params (), ","); indentation.decrement (); - - stream << '\n' << indentation << ')'; + stream << indentation << ')'; } void @@ -613,19 +633,10 @@ Dump::visit (BlockExpr &expr) stream << "{\n"; indentation.increment (); - for (auto &stmt : expr.get_statements ()) - { - stream << indentation; - stmt->accept_vis (*this); - stream << "; /* stmt */\n"; - } + visit_items_as_lines (expr.get_statements (), "; /* stmt */"); if (expr.has_tail_expr ()) - { - stream << indentation; - expr.get_tail_expr ()->accept_vis (*this); - stream << " /* tail expr */\n"; - } + visit_as_line (expr.get_tail_expr (), " /* tail expr */\n"); indentation.decrement (); stream << indentation << "}\n"; @@ -646,15 +657,15 @@ Dump::visit (BreakExpr &expr) void Dump::visit (RangeFromToExpr &expr) { - expr.get_from_expr ()->accept_vis (*this); + visit (expr.get_from_expr ()); stream << ".."; - expr.get_to_expr ()->accept_vis (*this); + visit (expr.get_to_expr ()); } void Dump::visit (RangeFromExpr &expr) { - expr.get_from_expr ()->accept_vis (*this); + visit (expr.get_from_expr ()); stream << ".."; } @@ -662,7 +673,7 @@ void Dump::visit (RangeToExpr &expr) { stream << ".."; - expr.get_to_expr ()->accept_vis (*this); + visit (expr.get_to_expr ()); } void @@ -674,16 +685,16 @@ Dump::visit (RangeFullExpr &expr) void Dump::visit (RangeFromToInclExpr &expr) { - expr.get_from_expr ()->accept_vis (*this); + visit (expr.get_from_expr ()); stream << "..="; - expr.get_to_expr ()->accept_vis (*this); + visit (expr.get_to_expr ()); } void Dump::visit (RangeToInclExpr &expr) { stream << "..="; - expr.get_to_expr ()->accept_vis (*this); + visit (expr.get_to_expr ()); } void @@ -714,32 +725,32 @@ void Dump::visit (IfExpr &expr) { stream << "if "; - expr.vis_if_condition (*this); + visit (expr.get_condition_expr ()); stream << " "; - expr.vis_if_block (*this); + visit (expr.get_if_block ()); } void Dump::visit (IfExprConseqElse &expr) { stream << "if "; - expr.vis_if_condition (*this); + visit (expr.get_condition_expr ()); stream << " "; - expr.vis_if_block (*this); + visit (expr.get_if_block ()); stream << indentation << "else "; - expr.vis_else_block (*this); + visit (expr.get_else_block ()); } void Dump::visit (IfExprConseqIf &expr) { stream << "if "; - expr.vis_if_condition (*this); + visit (expr.get_condition_expr ()); stream << " "; - expr.vis_if_block (*this); + visit (expr.get_if_block ()); stream << indentation << "else "; // The "if" part of the "else if" is printed by the next visitor - expr.vis_conseq_if_expr (*this); + visit (expr.get_conseq_if_expr ()); } void @@ -782,7 +793,7 @@ Dump::visit (TypeParam ¶m) if (param.has_type ()) { stream << " = "; - param.get_type ()->accept_vis (*this); + visit (param.get_type ()); } } @@ -799,25 +810,18 @@ Dump::visit (Method &method) { // FIXME: Do we really need to dump the indentation here? stream << indentation; - emit_visibility (method.get_visibility ()); + visit (method.get_visibility ()); stream << "fn " << method.get_method_name () << '('; - auto &self = method.get_self_param (); - stream << self.as_string (); - - auto ¶ms = method.get_function_params (); - for (auto ¶m : params) - { - stream << ", "; - format_function_param (param); - } + stream << method.get_self_param ().as_string () << ", "; + visit_items_joined_by_separator (method.get_function_params (), ", "); stream << ") "; if (method.has_return_type ()) { stream << "-> "; - method.get_return_type ()->accept_vis (*this); + visit (method.get_return_type ()); stream << " "; } @@ -825,7 +829,7 @@ Dump::visit (Method &method) if (!block) stream << ';'; else - block->accept_vis (*this); + visit (block); stream << '\n'; } @@ -840,7 +844,7 @@ Dump::visit (Module &module) // Item* // } - emit_visibility (module.get_visibility ()); + visit (module.get_visibility ()); stream << "mod " << module.get_name (); if (module.get_kind () == Module::UNLOADED) @@ -853,19 +857,8 @@ Dump::visit (Module &module) indentation.increment (); - for (auto &item : module.get_inner_attrs ()) - { - stream << indentation; - emit_attrib (item); - stream << '\n'; - } - - for (auto &item : module.get_items ()) - { - stream << indentation; - item->accept_vis (*this); - stream << '\n'; - } + visit_items_as_lines (module.get_inner_attrs ()); + visit_items_as_lines (module.get_items ()); indentation.decrement (); @@ -896,30 +889,20 @@ Dump::visit (UseDeclaration &use_decl) void Dump::visit (Function &function) { - emit_visibility (function.get_visibility ()); + visit (function.get_visibility ()); stream << "fn " << function.get_function_name (); if (function.has_generics ()) - emit_generic_params (function.get_generic_params ()); + visit (function.get_generic_params ()); stream << '('; - auto ¶ms = function.get_function_params (); - if (params.size () >= 1) - { - format_function_param (params[0]); - for (size_t i = 1; i < params.size (); i++) - { - stream << ", "; - format_function_param (params[i]); - } - } - + visit_items_joined_by_separator (function.get_function_params ()); stream << ") "; if (function.has_return_type ()) { stream << "-> "; - function.get_return_type ()->accept_vis (*this); + visit (function.get_return_type ()); stream << " "; } @@ -927,7 +910,7 @@ Dump::visit (Function &function) if (!block) stream << ';'; else - block->accept_vis (*this); + visit (block); stream << '\n'; } @@ -941,15 +924,15 @@ Dump::visit (TypeAlias &type_alias) // Note: Associated types are handled by `AST::TraitItemType`. if (type_alias.has_visibility ()) - emit_visibility (type_alias.get_visibility ()); + visit (type_alias.get_visibility ()); stream << "type " << type_alias.get_new_type_name (); if (type_alias.has_generics ()) - emit_generic_params (type_alias.get_generic_params ()); + visit (type_alias.get_generic_params ()); if (type_alias.has_where_clause ()) { } // FIXME: WhereClause stream << " = "; - type_alias.get_type_aliased ()->accept_vis (*this); + visit (type_alias.get_type_aliased ()); stream << ";\n"; } @@ -958,26 +941,11 @@ Dump::visit (StructStruct &struct_item) { stream << "struct " << struct_item.get_identifier (); if (struct_item.has_generics ()) - emit_generic_params (struct_item.get_generic_params ()); + visit (struct_item.get_generic_params ()); // FIXME: where-clause - stream << " {"; - - auto &fields = struct_item.get_fields (); - - indentation.increment (); - for (auto &field : fields) - { - stream << '\n' << indentation; - format_struct_field (field); - stream << ','; - } - indentation.decrement (); - - if (fields.size () > 0) - stream << '\n' << indentation; - stream << "}\n"; + visit_items_as_block (struct_item.get_fields (), ","); } void @@ -985,22 +953,12 @@ Dump::visit (TupleStruct &tuple_struct) { stream << "struct " << tuple_struct.get_identifier (); if (tuple_struct.has_generics ()) - emit_generic_params (tuple_struct.get_generic_params ()); + visit (tuple_struct.get_generic_params ()); // FIXME: where-clause stream << '('; - - auto &fields = tuple_struct.get_fields (); - if (fields.size () >= 1) - { - format_tuple_field (fields[0]); - for (size_t i = 1; i < fields.size (); i++) - { - stream << ", "; - format_tuple_field (fields[i]); - } - } + visit_items_joined_by_separator (tuple_struct.get_fields (), ", "); stream << ");\n"; } @@ -1014,45 +972,22 @@ void Dump::visit (EnumItemTuple &item) { stream << item.get_identifier () << '('; - auto &fields = item.get_tuple_fields (); - if (fields.size () >= 1) - { - format_tuple_field (fields[0]); - for (size_t i = 1; i < fields.size (); i++) - { - stream << ", "; - format_tuple_field (fields[i]); - } - } + visit_items_joined_by_separator (item.get_tuple_fields (), ", "); stream << ')'; } void Dump::visit (EnumItemStruct &item) { - stream << item.get_identifier () << " {"; - - auto &fields = item.get_struct_fields (); - - indentation.increment (); - for (auto &field : fields) - { - stream << '\n' << indentation; - format_struct_field (field); - stream << ','; - } - indentation.decrement (); - - if (fields.size () > 0) - stream << '\n' << indentation; - stream << '}'; + stream << item.get_identifier (); + visit_items_as_block (item.get_struct_fields (), ","); } void Dump::visit (EnumItemDiscriminant &item) { stream << item.get_identifier () << " = "; - item.get_expr ()->accept_vis (*this); + visit (item.get_expr ()); } void @@ -1060,26 +995,11 @@ Dump::visit (Enum &enum_item) { stream << "enum " << enum_item.get_identifier (); if (enum_item.has_generics ()) - emit_generic_params (enum_item.get_generic_params ()); + visit (enum_item.get_generic_params ()); // FIXME: where-clause - stream << " {"; - auto &variants = enum_item.get_variants (); - if (variants.size () >= 1) - { - stream << '\n'; - indentation.increment (); - for (auto &var : variants) - { - stream << indentation; - var->accept_vis (*this); - stream << ",\n"; - } - indentation.decrement (); - } - - stream << "}\n"; + visit_items_as_block (enum_item.get_variants (), ","); } void @@ -1087,21 +1007,11 @@ Dump::visit (Union &union_item) { stream << "union " << union_item.get_identifier (); if (union_item.has_generics ()) - emit_generic_params (union_item.get_generic_params ()); + visit (union_item.get_generic_params ()); // FIXME: where-clause - stream << " {"; - indentation.increment (); - for (auto &field : union_item.get_variants ()) - { - stream << '\n' << indentation; - format_struct_field (field); - stream << ','; - } - indentation.decrement (); - - stream << '\n' << indentation << "}\n"; + visit_items_as_block (union_item.get_variants (), ","); } void @@ -1113,14 +1023,14 @@ Dump::visit (StaticItem &static_item) {} void -Dump::format_function_common (std::unique_ptr &return_type, - std::unique_ptr &block) +Dump::visit_function_common (std::unique_ptr &return_type, + std::unique_ptr &block) { // FIXME: This should format the ` fn ( [args] )` as well if (return_type) { stream << "-> "; - return_type->accept_vis (*this); + visit (return_type); } if (block) @@ -1128,7 +1038,7 @@ Dump::format_function_common (std::unique_ptr &return_type, if (return_type) { stream << ' '; - block->accept_vis (*this); + visit (block); } } else @@ -1141,16 +1051,11 @@ Dump::visit (TraitItemFunc &item) auto func = item.get_trait_function_decl (); stream << indentation << "fn " << func.get_identifier () << '('; - auto ¶ms = func.get_function_params (); - for (auto ¶m : params) - { - stream << ", "; - format_function_param (param); - } + visit_items_joined_by_separator (func.get_function_params ()); stream << ") "; - format_function_common (func.get_return_type (), item.get_definition ()); + visit_function_common (func.get_return_type (), item.get_definition ()); } void @@ -1165,26 +1070,20 @@ Dump::visit (TraitItemMethod &item) // emit_visibility (method.get_visibility ()); stream << "fn " << method.get_identifier () << '('; - auto &self = method.get_self_param (); - stream << self.as_string (); + stream << method.get_self_param ().as_string () << ", "; - auto ¶ms = method.get_function_params (); - for (auto ¶m : params) - { - stream << ", "; - format_function_param (param); - } + visit_items_joined_by_separator (method.get_function_params (), ", "); stream << ") "; - format_function_common (method.get_return_type (), item.get_definition ()); + visit_function_common (method.get_return_type (), item.get_definition ()); } void Dump::visit (TraitItemConst &item) { stream << indentation << "const " << item.get_identifier () << ": "; - item.get_type ()->accept_vis (*this); + visit (item.get_type ()); stream << ";\n"; } @@ -1199,40 +1098,24 @@ Dump::visit (Trait &trait) { for (const auto &attr : trait.get_outer_attrs ()) { - emit_attrib (attr); + visit (attr); stream << "\n" << indentation; } - emit_visibility (trait.get_visibility ()); + visit (trait.get_visibility ()); stream << "trait " << trait.get_identifier (); - // Traits actually have an implicit Self thrown at the start so we must expect - // the number of generic params to be > 1 + // Traits actually have an implicit Self thrown at the start, so we must + // expect the number of generic params to be > 1 if (trait.get_generic_params ().size () > 1) { stream << "<"; - for (size_t i = 1; i < trait.get_generic_params ().size (); i++) - { - auto ¶m = trait.get_generic_params ().at (i); - param->accept_vis (*this); - - bool has_next = (i + 1) < trait.get_generic_params ().size (); - if (has_next) - stream << ", "; - } + visit_items_joined_by_separator (trait.get_generic_params (), ", ", 1); stream << ">"; } - stream << " {\n"; - - indentation.increment (); - - for (auto &item : trait.get_trait_items ()) - item->accept_vis (*this); - - indentation.decrement (); - stream << "\n}\n"; + visit_items_as_block (trait.get_trait_items (), ""); } void @@ -1242,28 +1125,21 @@ Dump::visit (InherentImpl &impl) // FIXME: Handle generics - impl.get_type ()->accept_vis (*this); + visit (impl.get_type ()); // FIXME: Handle where-clause // FIXME: Handle inner attributes - stream << " {\n"; - indentation.increment (); - - for (auto &item : impl.get_impl_items ()) - item->accept_vis (*this); - - indentation.decrement (); - stream << "\n}\n"; + visit_items_as_block (impl.get_impl_items (), ""); } void Dump::visit (TraitImpl &impl) { stream << "impl "; - impl.get_trait_path ().accept_vis (*this); + visit (impl.get_trait_path ()); stream << " for "; - impl.get_type ()->accept_vis (*this); + visit (impl.get_type ()); stream << " {\n"; indentation.increment (); @@ -1271,7 +1147,7 @@ Dump::visit (TraitImpl &impl) for (auto &item : impl.get_impl_items ()) { stream << indentation; - item->accept_vis (*this); + visit (item); } indentation.decrement (); @@ -1285,27 +1161,17 @@ Dump::visit (ExternalStaticItem &item) void Dump::visit (ExternalFunctionItem &function) { - emit_visibility (function.get_visibility ()); + visit (function.get_visibility ()); stream << "fn " << function.get_identifier () << '('; - for (size_t i = 0; i < function.get_function_params ().size (); i++) - { - auto ¶m = function.get_function_params ().at (i); - bool has_next = (i + 1) < function.get_function_params ().size (); - - stream << param.get_name () << ": "; - param.get_type ()->accept_vis (*this); - - if (has_next) - stream << ", "; - } + visit_items_joined_by_separator (function.get_function_params ()); stream << ')'; if (function.has_return_type ()) { stream << "-> "; - function.get_return_type ()->accept_vis (*this); + visit (function.get_return_type ()); } } @@ -1317,18 +1183,7 @@ Dump::visit (ExternBlock &block) if (block.has_abi ()) stream << "\"" << block.get_abi () << "\" "; - stream << "{\n"; - indentation.increment (); - - for (auto &item : block.get_extern_items ()) - { - stream << indentation; - item->accept_vis (*this); - stream << ";\n"; - } - - indentation.decrement (); - stream << "\n" << indentation << "}\n"; + visit_items_as_block (block.get_extern_items (), ";"); } static std::pair @@ -1368,11 +1223,7 @@ Dump::visit (MacroMatchRepetition &repetition) { stream << "$("; - for (auto &match : repetition.get_matches ()) - { - match->accept_vis (*this); - stream << ' '; - } + visit_items_joined_by_separator (repetition.get_matches (), " "); auto op_char = '\0'; switch (repetition.get_op ()) @@ -1405,41 +1256,29 @@ Dump::visit (MacroMatcher &matcher) stream << delimiters.first; - for (auto &match : matcher.get_matches ()) - { - match->accept_vis (*this); - stream << ' '; - } + visit_items_joined_by_separator (matcher.get_matches (), " "); stream << delimiters.second; } +void +Dump::visit (MacroRule &rule) +{ + visit (rule.get_matcher ()); + stream << " => "; + visit (rule.get_transcriber ().get_token_tree ()); + stream << ";"; +} + void Dump::visit (MacroRulesDefinition &rules_def) { for (auto &outer_attr : rules_def.get_outer_attrs ()) - emit_attrib (outer_attr); - - stream << "macro_rules! " << rules_def.get_rule_name () << " {\n"; - - indentation.increment (); + visit (outer_attr); - for (auto &rule : rules_def.get_rules ()) - { - stream << indentation; - - rule.get_matcher ().accept_vis (*this); - - stream << " => "; - - rule.get_transcriber ().get_token_tree ().accept_vis (*this); - - stream << ";\n"; - } - - indentation.decrement (); + stream << "macro_rules! " << rules_def.get_rule_name (); - stream << "}\n"; + visit_items_as_block (rules_def.get_rules (), ";"); } void @@ -1572,31 +1411,31 @@ Dump::visit (LetStmt &stmt) stream << "let "; auto &pattern = stmt.get_pattern (); if (pattern) - pattern->accept_vis (*this); + visit (pattern); if (stmt.has_type ()) { stream << ": "; - stmt.get_type ()->accept_vis (*this); + visit (stmt.get_type ()); } if (stmt.has_init_expr ()) { stream << " = "; - stmt.get_init_expr ()->accept_vis (*this); + visit (stmt.get_init_expr ()); } } void Dump::visit (ExprStmtWithoutBlock &stmt) { - stmt.get_expr ()->accept_vis (*this); + visit (stmt.get_expr ()); } void Dump::visit (ExprStmtWithBlock &stmt) { - stmt.get_expr ()->accept_vis (*this); + visit (stmt.get_expr ()); } // rust-type.h @@ -1639,19 +1478,19 @@ Dump::visit (RawPointerType &type) void Dump::visit (ReferenceType &type) { - type.get_type_referenced ()->accept_vis (*this); + visit (type.get_type_referenced ()); } void Dump::visit (ArrayType &type) { - type.get_elem_type ()->accept_vis (*this); + visit (type.get_elem_type ()); } void Dump::visit (SliceType &type) { - type.get_elem_type ()->accept_vis (*this); + visit (type.get_elem_type ()); } void diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h index 7cd922e0ac9..7a8058b195e 100644 --- a/gcc/rust/ast/rust-ast-dump.h +++ b/gcc/rust/ast/rust-ast-dump.h @@ -81,46 +81,55 @@ private: template void visit (std::unique_ptr &node); /** - * Format together common items of functions: Parameters, return type, block + * Visit all items in given collection, placing the separator in between but + * not at the end. + * Start and end offset allow to visit only a "slice" from the collection. */ - void format_function_common (std::unique_ptr &return_type, - std::unique_ptr &block); + template + void visit_items_joined_by_separator (T &collection, + const std::string &separator = "", + size_t start_offset = 0, + size_t end_offset = 0); /** - * Format a function's definition parameter + * Visit item placing indentation before and trailing string + end of line + * after. */ - void format_function_param (FunctionParam ¶m); + template + void visit_as_line (T &item, const std::string &trailing = ""); /** - * Emit an attribute + * Visit each item in a collection "as line". + * + * @see visit_as_line */ - void emit_attrib (const Attribute &attrib); + template + void visit_items_as_lines (T &collection, const std::string &trailing = ""); /** - * Emit an item's visibility + * Visit each item in collection as lines inside a block delimited by braces + * with increased indentation. Also includes special handling for empty + * collection to print only the delimiters with no new line inside. */ - void emit_visibility (const Visibility &vis); + template + void visit_items_as_block (T &collection, const std::string &line_trailing, + char left_brace = '{', char right_brace = '}'); /** - * Emit an indented string with an optional extra comment + * Visit common items of functions: Parameters, return type, block */ - std::ostream &emit_indented_string (const std::string &value, - const std::string &comment = ""); - - /** - * Emit formatted string for generic parameters - */ - void emit_generic_params (std::vector> ¶ms); - - /** - * Format a single field of a tuple - */ - void format_tuple_field (TupleField &field); - - /** - * Format a single field of a struct - */ - void format_struct_field (StructField &field); + void visit_function_common (std::unique_ptr &return_type, + std::unique_ptr &block); + + void visit (FunctionParam ¶m); + void visit (const Attribute &attrib); + void visit (const Visibility &vis); + void visit (std::vector> ¶ms); + void visit (TupleField &field); + void visit (StructField &field); + void visit (const SimplePathSegment &segment); + void visit (NamedFunctionParam ¶m); + void visit (MacroRule &rule); // rust-ast.h void visit (Token &tok); From patchwork Tue Feb 21 12:01: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: 60054 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1844350wrn; Tue, 21 Feb 2023 04:54:27 -0800 (PST) X-Google-Smtp-Source: AK7set+IEEeYeFjqVl0eBIEQYcQFeVUEEDGQuFs8N6lg1R+TyLSBO0jrL38fuJJicJiUWxoz7QlC X-Received: by 2002:aa7:d647:0:b0:4ab:4289:e9f8 with SMTP id v7-20020aa7d647000000b004ab4289e9f8mr2895932edr.3.1676984067828; Tue, 21 Feb 2023 04:54:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984067; cv=none; d=google.com; s=arc-20160816; b=hm2HHrQHQk/xn4IssoTEoIFO04SQ1fANi345cT0I50I/vAw1uKM82gu/b3vJc8X6Nf FIaoFLpg0s3wFOPGEIcrZu/kGw16dKJpUI/Xl/ynOELcJFuJZcAizqAAiI+j2jUfcJ19 e4A6a6bzbkCbdQLQEkdkAl3wwOukSDV8B4Iu3jv9nCYr+ehzlPN1GTo21JNvnRJqj3Zb 7ZhB4C7RbDTpehS8PkA9u/2w35ZUmeZl2+PTlt7GJJ9YaX4OajHE0gr6wWysIOY3AoLb pbS7yKtmdLPznV6IeUmbAWXQGGNQkZpr1Kvdnc9QPC1/3VAGt9/nLZURvpM/OnyCVgmg 6Kaw== 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=gaLVuN1YavFfnLN4s9PtvKeadkoquklPIThye7oU5FQ=; b=XJ19GIzX8r0pvO+HIk3z4yHXmyoRftupTgFjFza2p7OdKVVzxxvBlZr/dGhkeXVW80 0KgZWKC9YubK2gi/m1Y28fJWVB+I3wSOx05JVDvGAGc4R8nrwI0I8vEZnVFKnxxEqAiA MJRu9yk1stMaepQdeLL8VtpXoFfCTUrnSxGXgVyJy9VTmiTX+qGN3CLibhg/Hox31WYm l2Em2mGQwSgurFAN3myRJWSOhKgAF6h+1rBEKhUjvXsDt3xehqrzqPxy8GjU/R6OIe/J GFDFJA0a3ckEddrSMYVxa9ZkS/1geAxP5Ja76e8uUZu0hdkx8x8E89FBGmXN7MrUU1e0 7kNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=b724jekW; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id c17-20020a056402121100b004ab4c4532b4si3977257edw.148.2023.02.21.04.54.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:54:27 -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=b724jekW; 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 733EF39087CC for ; Tue, 21 Feb 2023 12:18:44 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 D58BC384692F for ; Tue, 21 Feb 2023 12:04:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D58BC384692F 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 bo30so3603614wrb.0 for ; Tue, 21 Feb 2023 04:04:18 -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=gaLVuN1YavFfnLN4s9PtvKeadkoquklPIThye7oU5FQ=; b=b724jekWZ//1iVh14MzYTml97MQt5TqmodZPSvI2MhKGIojLrAV8NRqtB1uJZWYThm DHDETXT+aMJ+TP44LSoBM+zGuGnXG+6G0uX822eRkFLcwjYP6OTTTg31c3hJKiHSbPJI FT6oCao0a9jp93uQRsEMdric3m68zGkD/azcVS5QDTVhqzTsh8lCKZZu5RAr8HR4mE2t 4D/42v/ebhJY/O1Lb0bGTNtMWZ6pn/oteQY5wTFkAyLj/mW3QF2zHPXmCDKKAfQoznYi YZ5qDQqvbFx9bemc0iQpvsQhSxkYV+gOjawU4p+Fq8S05P2rfksGHevGsSp0so/4fOCr inJQ== 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=gaLVuN1YavFfnLN4s9PtvKeadkoquklPIThye7oU5FQ=; b=Are8zQxIUtBqfwkJQt+OeN/dUjIDHU0S0t1rL9vRpNQtHHYzNeipTWcYmZeVyB7Rj0 JJEHfoe7ggat7T8g8Pa+c0711A3LDCHA83rP/o0cdSaQHkHHa6KtIBz2HWHRl4OGcHj4 6gWDdRmiXkRhUaeujLUxNW6pbJufVaoTwdjklqfI7IJM71M5dqkdOCUm3aC6AxmZ1rHQ IXalEoeJr7oa8wT/9oodA/GLcIyNOJ+c4WWsPEyro2wcdqA1u0p+28PUOiP7iHFTLMSd ykFs9P/3dXAgp+2dic6beqa9ZiL19ohSv6IdwryWQvqJZWkcVkJtC8pOoKq3qDtTgqhH QHEw== X-Gm-Message-State: AO0yUKXVHzG1EAZH0Y9VJtt5KMH+tK4cpiDXM7vYuRx50HIFNZcj8oUY 6Wx4xwuJxk0IwxlT8hReL4bHTsvxhg9hxp1Fyw== X-Received: by 2002:adf:cf06:0:b0:2bf:d285:b787 with SMTP id o6-20020adfcf06000000b002bfd285b787mr3490301wrj.56.1676981058259; Tue, 21 Feb 2023 04:04:18 -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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:17 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 067/103] gccrs: ast: refer correctly to arguments in docs-strings Date: Tue, 21 Feb 2023 13:01:57 +0100 Message-Id: <20230221120230.596966-68-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.3 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?1758445246037362481?= X-GMAIL-MSGID: =?utf-8?q?1758445246037362481?= From: Jakub Dupak gcc/rust/ChangeLog: * ast/rust-ast-dump.h: Fix documentation. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h index 7a8058b195e..13c92123ea9 100644 --- a/gcc/rust/ast/rust-ast-dump.h +++ b/gcc/rust/ast/rust-ast-dump.h @@ -81,7 +81,7 @@ private: template void visit (std::unique_ptr &node); /** - * Visit all items in given collection, placing the separator in between but + * Visit all items in given @collection, placing the separator in between but * not at the end. * Start and end offset allow to visit only a "slice" from the collection. */ @@ -99,7 +99,7 @@ private: void visit_as_line (T &item, const std::string &trailing = ""); /** - * Visit each item in a collection "as line". + * Visit each item in @collection "as line". * * @see visit_as_line */ @@ -107,7 +107,7 @@ private: void visit_items_as_lines (T &collection, const std::string &trailing = ""); /** - * Visit each item in collection as lines inside a block delimited by braces + * Visit each item in @collection as lines inside a block delimited by braces * with increased indentation. Also includes special handling for empty * collection to print only the delimiters with no new line inside. */ From patchwork Tue Feb 21 12:01:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60039 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1841250wrn; Tue, 21 Feb 2023 04:47:22 -0800 (PST) X-Google-Smtp-Source: AK7set+tAQ8oNbmSIrWfTyPvviFzAp4tviZ8tFYOBA/egy5Elny5GThenJb/3Adl0cup5YwBsCTG X-Received: by 2002:a17:907:2da2:b0:889:33ca:70c6 with SMTP id gt34-20020a1709072da200b0088933ca70c6mr19472434ejc.2.1676983642732; Tue, 21 Feb 2023 04:47:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983642; cv=none; d=google.com; s=arc-20160816; b=G15zc3xOdvtpEj/dB6ILtA9urZk+OE9UcOwKkIp+WrTNnwpNrlCfisAICRkvme4+Ta /j5Kan58BWFy/gJve4pZ364UiiXt0veQqKJCahpLBNrj4lufOB4aGUlfFM3Uy8rKFOCq Az+x0BIHh8RROSEnO/WjYEHZaVGQF6d9J6JlzirO0U1HR3omnmZu57DqmO5pNvq3nye/ 3VpuCMY/D1yCzy4kS8yoZ2VPNU580pGGUguHjQlKfO/yUfS4sut3GH0BgspidyiQGs9F XZEfuAvsFAwKHvG/F+FHsXUdHNKeuWf2Ao7zpJShdRSMJgZR8deXPEVPzpvzJp+qpP/E lELw== 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=JPkBa+BNYndGOynndtqfRq+B1aNIjnVFvgpJGhbl9nI=; b=bEaOk2jd1GNoiv0pQciYd1rQ9O3sSDkZgPb71Z7G+rGXA3nRla9y/5DFaL2dnTjryk q4dUy6hjt0xHcfXh7s5RKTo8CpM/15Z/y49mEFByfqRrIXG3/GZVqvwsfHLnCwIIfeCp 6+qEVsaBZoXIRbO/dT3dY6Jn0CQ8bQOtwGnKW6VW7vdq2/9o81yiz3hsPqlbJCq+YHFE ee6b0DMnzzwAquBKpaxnsI7rtmH91IP7rL4WeVJwoOOEN2SeFWOeACRIkvpKniHGyKaJ ESvWGoQ3jP2SRlbKgaZ+Gq4BWLq+eZ+TZ9UkyMPORasyFlQjq0ci72OMFy0adej1MHgj ph/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Xvz0eroK; 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 ge16-20020a170907909000b008caedbfc3b0si9271164ejb.755.2023.02.21.04.47.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:47:22 -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=Xvz0eroK; 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 B61B43853379 for ; Tue, 21 Feb 2023 12:15:42 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 340C4384F4AE for ; Tue, 21 Feb 2023 12:04:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 340C4384F4AE 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 o4so4165990wrs.4 for ; Tue, 21 Feb 2023 04:04:20 -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=JPkBa+BNYndGOynndtqfRq+B1aNIjnVFvgpJGhbl9nI=; b=Xvz0eroKyhDk+kmqYiHbPGhgCLlgbQESfIXGWE1ZTsyeYJ6Yp0P0CRgQ4BQPqdGNaR /V/TQVeYRNQFLOOKF+PUV1O5JO1N3pEmbRf9igotl7+msNI2d8GUZA41FwmFGjWtQcsy CWAwc2WWDQX/4DMaepTi5YdeXe/cohke1lPqbIRuoB5+3dLvZMmcYH3ZYtKwvxIOhSwU XB902a4P9v1VCO1S6Y434y+Vz/Z7BKv4z9WuSF6mDMphxH7xq2jn4rmSXuhbYg7/YoAW g0e88NK75xmdomdVqG8lm0x5lY4kdb5V22LTl3hvWuhUVoFwyZ8p96rgoHR2m4cKHqzO dIPg== 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=JPkBa+BNYndGOynndtqfRq+B1aNIjnVFvgpJGhbl9nI=; b=IGvm+IjhA/n6njc+FGl7lj6/HprZRQxCp9R7BVFordtJz9pRR9JjJNUIArWE6hKx5p hvckrQPOHdUQjJCnxpmmjyjulNs9pGrD6hSw6XcAvxh3HGQAvQYWFKjqExJ87n35UvXO XU4H0xo9Ivub+RKROPBHhwpWK/33q9Jsk/R6igBEewyj6hH0i7EMIkWHvc93PrXnuTiD t783efRfjhTPeI1NeqBd1qpoQ32k/MU7sx66qXICRbCgg8cy1XXfF1lBgtIBA0r/bdsF 1k2k5/2ta7kZKs20zI9k0wetoWRgsvzheEQ9LIbaHzcayno+hzmCCu9uomJXA7Rbrhi/ hLtg== X-Gm-Message-State: AO0yUKVgv205HWHMBXbru9ZliQQgjsSdEucsQjfePPv3APliQAZs+8Si LlPlNrWB2qTH0kjPtHDEuQ5m+zd10CDMmePdYw== X-Received: by 2002:a5d:4ccf:0:b0:2c6:5972:cd13 with SMTP id c15-20020a5d4ccf000000b002c65972cd13mr4762336wrt.26.1676981059438; Tue, 21 Feb 2023 04:04:19 -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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:18 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 068/103] gccrs: ast: Dump unit struct Date: Tue, 21 Feb 2023 13:01:58 +0100 Message-Id: <20230221120230.596966-69-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.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=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?1758444800482243089?= X-GMAIL-MSGID: =?utf-8?q?1758444800482243089?= From: Jakub Dupak gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add handling for unit structures. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 191e328b134..df42481c248 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -945,7 +945,10 @@ Dump::visit (StructStruct &struct_item) // FIXME: where-clause - visit_items_as_block (struct_item.get_fields (), ","); + if (struct_item.is_unit_struct ()) + stream << ";\n"; + else + visit_items_as_block (struct_item.get_fields (), ","); } void From patchwork Tue Feb 21 12:01:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60056 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1845187wrn; Tue, 21 Feb 2023 04:56:26 -0800 (PST) X-Google-Smtp-Source: AK7set+NdGKhZDTxbp6Z1+hB8gh3LJASFDp8nukkFZgbi9poIh5q1J13PHCFJcKkqyRbaQsZQXjq X-Received: by 2002:a17:907:a42a:b0:8b1:730b:a296 with SMTP id sg42-20020a170907a42a00b008b1730ba296mr21568103ejc.15.1676984186151; Tue, 21 Feb 2023 04:56:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984186; cv=none; d=google.com; s=arc-20160816; b=qSmU8H/IV0JOwDpSfcBxrdygsDVJaruS6J7ovF79cKYbWuLkKaKrv8QY8aURfKuWpM OOmf/2bIUogLoEhoykU+osQ+fSeKtlQhw09koHAED7mkHJct2hnoFU2YKqL8SzL2M8wo skaaDsZX912Jq+FwgsKMW2c0sXdCC0GEYzzHOVGp+hwD8cxiH7JCVPSMBU7hVWpiX9iO /pZF9Ci+yRRBtTIoD3ENVc2kqXXc9A2aQl2ULhD+ntH+LPlqtfHMmuLEt8ssKQPM/SRu OG0D+XWDiGvVcKMk+9R3UyXm3zQ14IHOng8x+sY8gE5YbFybi6loL7bqd+5y8jsG2Enr lqUg== 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=2FSqGpQictYqql6UW0VVozec41h7KkoljpT/l0GbZFI=; b=zadlIaahJt3MC8FT7KVXQboOMbPEH31UYbGS476L52LxJ/Uhx5q+FaYAU5EL8R52Uq o5ugim7RKNzP00FcPcWnycKHzpJGLAvvllAoVJIonOHlc6r5FznhmebH6nbQ0H31b+bE FVZyUp15yi3p/sc2Cl8STRsxPXtmow8jXlMTV/I5jHsnkrnpnUSdPEfWofEXv5irta90 T50ZrN2lSqUsZGlIO1ja7ndA1s6hD0TO7c8BpJ8i2nKhRwTFK9r7gNhJlbx8nhz7IW1C hNF2t+qAigdnA56MEXeoGPYt4XrwHbEVuJR2WB2YPHb/LjQKKTo5+hlLgkbb60LGu4PT Iw4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=IstCGMkA; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id q9-20020a056402032900b0049f1f3402f4si6417439edw.87.2023.02.21.04.56.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:56:26 -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=IstCGMkA; 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 46ACB39730E0 for ; Tue, 21 Feb 2023 12:19:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 55C1B3881D2B for ; Tue, 21 Feb 2023 12:04:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 55C1B3881D2B 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-x42e.google.com with SMTP id 6so3758922wrb.11 for ; Tue, 21 Feb 2023 04:04:21 -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=2FSqGpQictYqql6UW0VVozec41h7KkoljpT/l0GbZFI=; b=IstCGMkA2c3JDaFgCrRjc3gvTHi08Fl/+WaRHxg45jXZmoOFyIVCWn8yMpuXshKse+ cyZHO+DT6rrsetT4RDhtm1f204emuEY7o2Ex1ozqoPdd6Sn5axyikjHVKAdF0icfO46P SXA7vFSSla2OVGPkP+nkya2+2T6T2FQIB5g3VhAW/YzoCGWHMx9RWVXWMa+mSfcOhVUN cmBACKGBKA5mZLFKE49inJ+hmWKAA7uCAA6IJ7CVWu3Uv+AuUPwjFp8b7a8eUGyl1iZg TJyuR9FYOzNWvBJwLp1UezPU9X1LX6viEMxVOtVo5xA5vGmuXsu8i8pP//xbfOD+ft/w Yz3A== 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=2FSqGpQictYqql6UW0VVozec41h7KkoljpT/l0GbZFI=; b=3USivIwNSn8F+de6uyYsntokXZC32sVWEGmYGYjbrihS7w0+/QdYe5SeO4p2RiRf2j dlc9XUEj2dn0ZGQyxQDomKkOEenvBlNFlw1/j366ip/UWjK4CIwBTi1HBfXUYNq3Qgyl EQ79rD+Ct+djN+d7XVIsI0yMzyIl0PSaFtgWguHQELTLQdnoANaMoMjfuIy9nAWyGiFj xznpVL0AbTwcE5j2eU1qTV1ebDuLw0H8Qhh1La/hxOD2MNjjzPjUZz9V9aJJctLmHB89 AHKRYITvtuHaNPoS3X0gPfMskW3UOXW19FAaHvQsjxgNCMYdyouOEWXLBN4CauLCPeqt 0JpA== X-Gm-Message-State: AO0yUKUMFmETwVLSrk3ANIeUPAHswUMU2icz6H75p7ilsoyadLHyj5Hp j2ARHYh4jFIqCp6PpcWnfCw6iLWPDwo5PX4zBw== X-Received: by 2002:a5d:53c5:0:b0:2c5:581d:5a1d with SMTP id a5-20020a5d53c5000000b002c5581d5a1dmr4069238wrw.43.1676981060528; Tue, 21 Feb 2023 04:04:20 -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.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:19 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Raiki Tamura Subject: [committed 069/103] gccrs: add lang item "phantom_data" Date: Tue, 21 Feb 2023 13:01:59 +0100 Message-Id: <20230221120230.596966-70-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.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=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?1758445369705620841?= X-GMAIL-MSGID: =?utf-8?q?1758445369705620841?= From: Raiki Tamura gcc/rust/ChangeLog: * util/rust-lang-item.h: Add handling for `phantom_data` lang item. gcc/testsuite/ChangeLog: * rust/compile/torture/phantom_data.rs: New test. --- gcc/rust/util/rust-lang-item.h | 9 +++++++++ gcc/testsuite/rust/compile/torture/phantom_data.rs | 11 +++++++++++ 2 files changed, 20 insertions(+) create mode 100644 gcc/testsuite/rust/compile/torture/phantom_data.rs diff --git a/gcc/rust/util/rust-lang-item.h b/gcc/rust/util/rust-lang-item.h index 02eeaee60df..ea0c91aa5f2 100644 --- a/gcc/rust/util/rust-lang-item.h +++ b/gcc/rust/util/rust-lang-item.h @@ -73,6 +73,9 @@ public: MUT_PTR, CONST_SLICE_PTR, + // https://github.com/rust-lang/rust/blob/master/library/core/src/marker.rs + PHANTOM_DATA, + // functions FN_ONCE, FN_ONCE_OUTPUT, @@ -222,6 +225,10 @@ public: { return ItemType::CONST_SLICE_PTR; } + else if (item.compare ("phantom_data") == 0) + { + return ItemType::PHANTOM_DATA; + } else if (item.compare ("fn_once") == 0) { return ItemType::FN_ONCE; @@ -308,6 +315,8 @@ public: return "mut_ptr"; case CONST_SLICE_PTR: return "const_slice_ptr"; + case PHANTOM_DATA: + return "phantom_data"; case FN_ONCE: return "fn_once"; case FN_ONCE_OUTPUT: diff --git a/gcc/testsuite/rust/compile/torture/phantom_data.rs b/gcc/testsuite/rust/compile/torture/phantom_data.rs new file mode 100644 index 00000000000..89e76aeb5eb --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/phantom_data.rs @@ -0,0 +1,11 @@ +// { dg-options "-w" } +#[lang = "phantom_data"] +struct PhantomData; + +trait Hash { + fn hash(&self, state: &mut H); +} + +impl Hash for PhantomData { + fn hash(&self, state: &mut H) {} +} From patchwork Tue Feb 21 12:02:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60034 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1839620wrn; Tue, 21 Feb 2023 04:43:37 -0800 (PST) X-Google-Smtp-Source: AK7set8dGfuLFGSpIgLFqUULGoh8KdWOSPmc0a/xUwYQf88qoy+aKkf1oJwFHqqZBvwDAZdQP4Hv X-Received: by 2002:a17:907:c689:b0:8b1:23cf:13dc with SMTP id ue9-20020a170907c68900b008b123cf13dcmr13345822ejc.16.1676983417523; Tue, 21 Feb 2023 04:43:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983417; cv=none; d=google.com; s=arc-20160816; b=H1APj6blVJ8PfemMBg1cZolfGuf+I4+kB+qZuzmY7tMEgPsF773nRBXcFXZWdlJEZC jLJ32m7F7qsdRHb7HvSAROqUFcadOFK8NXfOI5yzho0xceHRXVP7Ll+QvVZxINekTHWB VvVqDY2QEFOkchNkhsZ1u+W+L7GyzYdLG8AoQ7Dx0gU2Kel/FoAfTtK70YGUNeGYNs06 SHrGb/GkZcAkinqnb3gCSaMOKTUTRjllk2Y5x2EJoJFnOnXrAh4oTY/QLvhFH/g9gJ33 Qx9SE0It4zwC7qJTM/0BP+hMpEuJDiUjveqGLzE7Pz+mRdlJ9VCOidyJ6r4EPbb7bNmk XGXg== 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=LoBWNt2H423ffTCV+quVu51FTvLZC+vkHJ/9OLOj3J4=; b=Do1sOZftZtJCnFOPLkKy1TtBeR+VoVYQ7jzjaCSr5CX1NMUodZiUMsij30bAi8VS/d sdwLTUFzW+R1dtJxCUjbQUn+bBg2ge6nyprfiiXgm6WWnKFK5MFsUZp/SpEbSyKvI6SY 498ctEp9sV60LDT8fyA4LWihHBm/9B29RIqaCyo/NJQYo8PnF6Zz+XvtSwbiAckyXsEy OFTExV6ZD/LjLG6nwkdaoNqYVVeC1jgHY4k4np/iWV+it3TEd5B/3Wpoqp1/k0qaU5Ul qSARwrlaz1f8EotJO+AznGdxY0nzWU0KemQQ8fnZm5pTg37uaHqpiFLgcw67iybbTMCN EhDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=T7WIADgg; 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 18-20020a170906209200b008dc4d55dda4si5372475ejq.705.2023.02.21.04.43.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:43:37 -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=T7WIADgg; 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 705BF38DC344 for ; Tue, 21 Feb 2023 12:14:47 +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 1CC96388211C for ; Tue, 21 Feb 2023 12:04:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1CC96388211C 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 l25so3759664wrb.3 for ; Tue, 21 Feb 2023 04:04:22 -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=LoBWNt2H423ffTCV+quVu51FTvLZC+vkHJ/9OLOj3J4=; b=T7WIADggMD+SNs+g/HkviHoWfwGcLJ1bV0NvB+GFHElmj4sm3haYYdwRYSmVBiw1o+ gIFE+t21xCJaFwLVnZspydpGZuzESNXQjkhMBNroexas4Vyjaun7aU4WdlMRI8je/Gdk BWXpyX0bS573ECIhtg3AxF5EYwUhqA9jEE5qzgPjcmnBvxY5hdPPAJXJKeIzkum4DeHF FfXNd/rDXxewX4eA0KFZP6CTCG0XVEBHegqXGPVmtsdJFrC5HOWROpCnaGonTLUturmf wf0IzECS11NpjiTfsbstxB3g7wesYhiFtJ4pY+M8IUPO5JUQybP0V+U9rbJbGGJY/bCd Cz0A== 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=LoBWNt2H423ffTCV+quVu51FTvLZC+vkHJ/9OLOj3J4=; b=CPigckgS0u+lXtMUGRVLXqSgiqAl1PWE0iUqjoIFIhTh+uW914BzG11jaqVaC9Bv1X P0Lg6fxU3uLLwATZxBO0MUFej+vk6lhS4cR6sTdjplLAlQH7zJ8Q59x1ac7uxlVGAU/B v3+WetHGyrtKNbMVD3796Fa5MaLfm3gHhuXyRgboJlAfkHmOCzRuBkTtByTcx+ETzOO8 eAhTs9k2m6F9chC+Do4Hld6+8MVDdX62gG6RiaFod4gjZSMzyYgGktAKGF7Hu5e7jTrG mJ42gwnlhxCWnxAPe/ge38b3VYf3ILda7gJv0bVPSJDZ9swoCW7aLeQ8SjqIsH5f9+eT U7OQ== X-Gm-Message-State: AO0yUKX/Tg0on2kkYaRVi4MFQGsm2kbqjMh1XdruWorVTIBpBsBQF41V sNNZa4DErCvVeuxSUkk0FVNbRrzmytwNa8AEvg== X-Received: by 2002:a5d:6501:0:b0:2c5:5701:8d03 with SMTP id x1-20020a5d6501000000b002c557018d03mr4270174wru.13.1676981061421; Tue, 21 Feb 2023 04:04:21 -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.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:20 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Dave Subject: [committed 070/103] gccrs: add Location to AST::Visibility Date: Tue, 21 Feb 2023 13:02:00 +0100 Message-Id: <20230221120230.596966-71-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.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=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?1758444564289734841?= X-GMAIL-MSGID: =?utf-8?q?1758444564289734841?= From: Dave gcc/rust/ChangeLog: * ast/rust-item.h: Add location member. * hir/rust-ast-lower.cc (translate_visibility): Pass location argument. * hir/tree/rust-hir-item.h: Fix constructor to accept Location argument. --- gcc/rust/ast/rust-item.h | 19 +++++++++++++------ gcc/rust/hir/rust-ast-lower.cc | 3 ++- gcc/rust/hir/tree/rust-hir-item.h | 6 ++++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index d66dd615319..17d11e4de38 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -625,13 +625,15 @@ private: VisType vis_type; // Only assigned if vis_type is IN_PATH SimplePath in_path; + Location locus; // should this store location info? public: // Creates a Visibility - TODO make constructor protected or private? - Visibility (VisType vis_type, SimplePath in_path) - : vis_type (vis_type), in_path (std::move (in_path)) + Visibility (VisType vis_type, SimplePath in_path, + Location locus = Location ()) + : vis_type (vis_type), in_path (std::move (in_path)), locus (locus) {} VisType get_vis_type () const { return vis_type; } @@ -648,6 +650,8 @@ public: // Returns whether visibility is public or not. bool is_public () const { return vis_type != PRIV && !is_error (); } + Location get_locus () const { return locus; } + // Creates an error visibility. static Visibility create_error () { @@ -672,21 +676,24 @@ public: static Visibility create_crate (Location crate_tok_location) { return Visibility (PUB_CRATE, - SimplePath::from_str ("crate", crate_tok_location)); + SimplePath::from_str ("crate", crate_tok_location), + crate_tok_location); } // Creates a public visibility with self-relative paths static Visibility create_self (Location self_tok_location) { return Visibility (PUB_SELF, - SimplePath::from_str ("self", self_tok_location)); + SimplePath::from_str ("self", self_tok_location), + self_tok_location); } // Creates a public visibility with parent module-relative paths static Visibility create_super (Location super_tok_location) { return Visibility (PUB_SUPER, - SimplePath::from_str ("super", super_tok_location)); + SimplePath::from_str ("super", super_tok_location), + super_tok_location); } // Creates a private visibility @@ -698,7 +705,7 @@ public: // Creates a public visibility with a given path or whatever. static Visibility create_in_path (SimplePath in_path) { - return Visibility (PUB_IN_PATH, std::move (in_path)); + return Visibility (PUB_IN_PATH, std::move (in_path), in_path.get_locus ()); } std::string as_string () const; diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc index fdf8abe3ed3..2e25be75a5a 100644 --- a/gcc/rust/hir/rust-ast-lower.cc +++ b/gcc/rust/hir/rust-ast-lower.cc @@ -50,7 +50,8 @@ translate_visibility (const AST::Visibility &vis) case AST::Visibility::PUB_SUPER: case AST::Visibility::PUB_IN_PATH: return Visibility (Visibility::VisType::RESTRICTED, - ASTLoweringSimplePath::translate (vis.get_path ())); + ASTLoweringSimplePath::translate (vis.get_path ()), + vis.get_locus ()); break; } diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h index 7f665159572..f7bf1f879c8 100644 --- a/gcc/rust/hir/tree/rust-hir-item.h +++ b/gcc/rust/hir/tree/rust-hir-item.h @@ -571,13 +571,15 @@ public: private: VisType vis_type; HIR::SimplePath path; + Location locus; // should this store location info? public: Visibility (VisType vis_type, - HIR::SimplePath path = HIR::SimplePath::create_empty ()) - : vis_type (vis_type), path (std::move (path)) + HIR::SimplePath path = HIR::SimplePath::create_empty (), + Location locus = Location ()) + : vis_type (vis_type), path (std::move (path)), locus (locus) {} // Returns whether visibility is in an error state. From patchwork Tue Feb 21 12:02:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60060 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1846050wrn; Tue, 21 Feb 2023 04:58:23 -0800 (PST) X-Google-Smtp-Source: AK7set+XaTw7UiklEhou9k12dIqINDXORYJXgGB7m5FMChWXf7u1LPTzK6RIhqjpI4A96LuoWGCO X-Received: by 2002:a17:906:1689:b0:8af:2fa1:5ae5 with SMTP id s9-20020a170906168900b008af2fa15ae5mr11706856ejd.53.1676984302871; Tue, 21 Feb 2023 04:58:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984302; cv=none; d=google.com; s=arc-20160816; b=x2FnrrjMaDkyVZ7Ea8QRIwwTPm6s87F82Ky6K4MOxHGWb1CM4VEGYON5sc7K+fWnu2 Rb1Z+WX27dSxaPAaVsypw/fEsIPyE2G0fAwGLeLWIWxN/HhPNRBRSEEaLi5XiNduWWqi QbqgNrfExrWKYpYOfbjlxf98Grtx9iEYCqm4xSlJtxW6s7/Q3rz9x1U0cFslbVLHD151 EAeVu/TEsb3KjbGQ8ilGqgGSm6ltlszkqULTP59dNxs1DayBcaNn3BeYSnLAp+emcaM4 orlgX2toOKGSHjiMrgyKAaP+S8dXjKthN97mjKg9AGn00LHRAyuIHkeNpYVpIENPal5g bqpg== 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=d/AqaGysgxq4MidozOILvtZvF8LJOjPiVhDS6pfLOmI=; b=h0lMnA85+AKVmcjVERVGo8mPxdbbEBAPbq3EDN8mWqpyuBkl7ELXwwDRpDDJzheekC U3WkQHN7OEHknbugdyNYW4SErLU/8WU10x06HEMz1RieGoFGtLZvGMe8eDM3A0Y0tDdN i/BMCaG7STbHAM45YRxwPeZ+wVakValiaCmh+xB8lDixTAsS2tCRf86jh25wKqcG2dnB flPw+B4cQN+Jm0KSjIcUiSfDOLsJDF1je4ZynJQWSt0kfWLlujgPV+d0cGFhjM5j7tmt Y4B7iV/W3MSfT6xvXsoT0yFzz0PL5KQaQiMwt9rWeaZrbdkoiQX/assPaUKYLVEPf3/r kfog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=AIiH2Pqi; 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 fe8-20020a1709072a4800b008d68d018141si4596069ejc.402.2023.02.21.04.58.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:58:22 -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=AIiH2Pqi; 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 6F5623940CDF for ; Tue, 21 Feb 2023 12:20:26 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id 7405738323F8 for ; Tue, 21 Feb 2023 12:04:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7405738323F8 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-x433.google.com with SMTP id p8so4292006wrt.12 for ; Tue, 21 Feb 2023 04:04:23 -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=d/AqaGysgxq4MidozOILvtZvF8LJOjPiVhDS6pfLOmI=; b=AIiH2PqiR7JQ9iPUUOtiB/wInjn/jUqlXcfugP5BB1cYL+441vImCpqM5AfSEsSJ2P vVYxA3IEBGqbL40DvAo/O3mrFpbE+QBhP1kgJVPD/w/fE7o1T44lXOHwlw//yHzrwKa1 U0PNzC5HKSuzhwoIHcoJQg+H3KqFN2dgl6kAD/dls6qYYhBOAFflJ9H+jflaVzYya+N9 TrOx2ICsN/6cb5AU8EUroEA/TRE22lMjpGMS20DS/9so4EjhyNr590cVQFWBc/jiVwNI 1eggqcqcr6e4IQNXQEOwcHaZpty5um3O9FZOxWLuI+X+aN7dbUH/4brWQfRd3KQxTGS5 8Dyw== 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=d/AqaGysgxq4MidozOILvtZvF8LJOjPiVhDS6pfLOmI=; b=aGXi+eYSJ2np2XBwPk6+03ATATG3rywlu7HI7z61nV+E6qasvvfBb30J3ytk2Mp+4G 1BS/w2WPKpZaldT+JJlmN05ceTDn+wn43FW0mYIgOW+xpdu7ImJnqkuxcAYZIxVnrdUB RY/GWhIlfK1dzAdQsjnpUvuUddUP+APOwq0DaKOt0xprevLYI8+fL556TA6UbxQBFoMo FuFvd+dTc9qnRp1d0fPa9nv0sLg9KwOUeclwip0/5YhZ8NPWFho0xmzzJWRwUNjCER50 eWxFDjvsTq9MiT1j7sCeign/Svi/VNX36H1PulgbxzExHgnx4pP0z+8EwdHNoPKONpya r/Vg== X-Gm-Message-State: AO0yUKV1jaLwqaG//AOBysiDGS4gwW92EM2EiH4FWaNx2mw7JqIBeotB zoF88nwmbUsvnef3X1OmDsZMdNQIoST3ckA8LQ== X-Received: by 2002:a5d:500f:0:b0:2c5:58b9:d76e with SMTP id e15-20020a5d500f000000b002c558b9d76emr4365242wrt.40.1676981062101; Tue, 21 Feb 2023 04:04:22 -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.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:21 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 071/103] gccrs: typecheck: Fix overzealous `delete` call Date: Tue, 21 Feb 2023 13:02:01 +0100 Message-Id: <20230221120230.596966-72-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?1758445492398527399?= X-GMAIL-MSGID: =?utf-8?q?1758445492398527399?= From: Arthur Cohen gcc/rust/ChangeLog: * typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Fix extra call to `delete`. --- gcc/rust/typecheck/rust-tyty-call.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/gcc/rust/typecheck/rust-tyty-call.cc b/gcc/rust/typecheck/rust-tyty-call.cc index 0c9e9f488fd..d520b595e43 100644 --- a/gcc/rust/typecheck/rust-tyty-call.cc +++ b/gcc/rust/typecheck/rust-tyty-call.cc @@ -68,7 +68,6 @@ TypeCheckCallExpr::visit (ADTType &type) return; } - delete res; i++; } From patchwork Tue Feb 21 12:02:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60038 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1840523wrn; Tue, 21 Feb 2023 04:45:49 -0800 (PST) X-Google-Smtp-Source: AK7set9tt4HGlfI61XUTpI27JN9QDFEfzCAfghY900/oM0hx29fmFlC6hLllCJvOfk8aZ8jfPrN7 X-Received: by 2002:a17:907:c927:b0:8b2:7150:dd03 with SMTP id ui39-20020a170907c92700b008b27150dd03mr12445922ejc.35.1676983549232; Tue, 21 Feb 2023 04:45:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983549; cv=none; d=google.com; s=arc-20160816; b=G/iL14Nc1/U2eWFOkfVvQYi4dmmal3iO0Nuq+SlJCOY+Fz+M2ZL97Zx8z1Mmxgkb8C sWNAsEQ+4aaxl9/ZvKE5/hcO+J4HBOefi2HzrM85Ii+QujQ0nZIueqHJr3FXNmML8pU+ ZD5Xahcdwq6pnSWOQC8HEH7pbGaRqJB3BfLVgxAzF4F3U9rzaEaHqYe0xvqEiD+qepkt pRmlhpVg/tiP/OBl+cJ7zX0+81pj+0q6xGVxFoZwx51uJMGJiUcfhDv8C27+ftuy6GKK VF6OtoKI+Va3yUU3Q1wdBJLEPw/zc64/aktWKSqudrkTG9PHGBRccpDFXemrbsbeVRx2 80Fg== 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=bbTFlyVGb4/Tv1FCbgCtCDXG3KrMOnEdeqrM2eVcyng=; b=EZQHyMPkra9FWJYMDtsJwtiRhsgcK0wpXjkcNlE3addEDqgBuMxTnybxTVx33CjM42 gH1OqeNMEZK+/FZhMZ5RPERC5UNqC5bU+oA0ISKMLpb6X1Uf4qppVgcUJY6dnSa+MQzL F4y95beV7rZk0JLV0Ef/ZGTT7POWdCn+tDJzvvHlztrXg+zMggmPaRRviDa8Ziyl7RCi m6cUocfvBtvV2USn5bFm7wRo6oel/FisPeS9dhyqRmgbja4bhFXennrIusu/hG4T0OjQ vQ7aXyeioGGErX1+URYg3Y8e1n15e4spFKG5Wa1O9OwFas+vJy4VXRTGWahlgqAjSqQL EO3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=ESp7OeQW; 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 30-20020a170906029e00b008b123fe4f19si22876662ejf.984.2023.02.21.04.45.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:45:49 -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=ESp7OeQW; 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 C65C938ED07F for ; Tue, 21 Feb 2023 12:15:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 755F738323FC for ; Tue, 21 Feb 2023 12:04:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 755F738323FC 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-x429.google.com with SMTP id v3so4086080wrp.2 for ; Tue, 21 Feb 2023 04:04:23 -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=bbTFlyVGb4/Tv1FCbgCtCDXG3KrMOnEdeqrM2eVcyng=; b=ESp7OeQWZyZgS91Kx+rzcuPWZ6ywB1dDjYsjgBcIY4+OTUmFuCl6/TKDCfqG3ILwuL jfOyxcmlA/tZOJ8hpc5Cjduygsj6h2FVweUZLNaDl4EyomwwyYIFdb5CgxlcVrbCT+H/ rRjZBihmK3SeZmWEkli3q9ScKK/WFIpTiFnYBL7V9/pyNw0XZv4SAvprDKvSuAntl/GC T/TusU3DuG5sgbGy1ZbSo9bJ4d90olVyoPQg4BPpkSSiNsHJ6z555PfLWmXeTAQLPVGY L3EfrQL8xY0sS1zZ7faDwXrMdZUA1hKpj7FiO6fVTg5VByCGoZRKcxjbYRgwpMXa9gHB YUzQ== 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=bbTFlyVGb4/Tv1FCbgCtCDXG3KrMOnEdeqrM2eVcyng=; b=aza9C2IOeIYXTjYROdFkKdIBwgbVDWvjf9OvXd04gMNskMSEehQDr6o8q7wDMYBCIk 5Mla1Y+19hhVa1L/cexp3jIxaDQu3yfWWl5c6mfsXKUNke+qiTXp8JTu9hLaYIqKS/np lZfZ5tqbxGb412EwKomoFkWZhKZrArJ0omo2ax/7d3GuNzBuwbuSFb/CsjAxHDsShjBa gkXDj/arZP3Qpwjnn9bM3hnhcB43+ViCln6QUgNXvyOKwrH+bVoVR54U0N2nrizoQzcb +4oLOy5fU++CcKsf2GCgdYz13W+vCcRWoNwUnur2JbR6WNbD2hh3rbo7fM+RMwyQmsWM unzA== X-Gm-Message-State: AO0yUKXzbAPeyBa+MRVJhmPz1Rt5wrpA1LWHO9s/d73F4jZw128IorJA 661XYtn67MoHEBQpBlza7YaIZCQqUT1o7uM6VA== X-Received: by 2002:a5d:6092:0:b0:2bf:ee65:b0b0 with SMTP id w18-20020a5d6092000000b002bfee65b0b0mr5388189wrt.41.1676981062819; Tue, 21 Feb 2023 04:04:22 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:22 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 072/103] gccrs: ast: add visit overload for references Date: Tue, 21 Feb 2023 13:02:02 +0100 Message-Id: <20230221120230.596966-73-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.3 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?1758444702192433779?= X-GMAIL-MSGID: =?utf-8?q?1758444702192433779?= From: Jakub Dupak This is currently needed for lifetimes to use the existing infrastructure. gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add new reference visitor wrapper. * ast/rust-ast-dump.h: Declare it. * ast/rust-item.h: Add mutable visibility getters. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 15 +++++++++++---- gcc/rust/ast/rust-ast-dump.h | 11 ++++++++--- gcc/rust/ast/rust-item.h | 4 ++++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index df42481c248..16c4a79dc6e 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -64,6 +64,13 @@ Dump::visit (std::unique_ptr &node) node->accept_vis (*this); } +template +void +Dump::visit (T &node) +{ + node.accept_vis (*this); +} + template void Dump::visit_items_joined_by_separator (T &collection, @@ -129,7 +136,7 @@ Dump::visit (FunctionParam ¶m) } void -Dump::visit (const Attribute &attrib) +Dump::visit (Attribute &attrib) { stream << "#["; visit_items_joined_by_separator (attrib.get_path ().get_segments (), "::"); @@ -158,13 +165,13 @@ Dump::visit (const Attribute &attrib) } void -Dump::visit (const SimplePathSegment &segment) +Dump::visit (SimplePathSegment &segment) { stream << segment.get_segment_name (); } void -Dump::visit (const Visibility &vis) +Dump::visit (Visibility &vis) { switch (vis.get_vis_type ()) { @@ -1099,7 +1106,7 @@ Dump::visit (TraitItemType &item) void Dump::visit (Trait &trait) { - for (const auto &attr : trait.get_outer_attrs ()) + for (auto &attr : trait.get_outer_attrs ()) { visit (attr); stream << "\n" << indentation; diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h index 13c92123ea9..57419b75347 100644 --- a/gcc/rust/ast/rust-ast-dump.h +++ b/gcc/rust/ast/rust-ast-dump.h @@ -80,6 +80,11 @@ private: */ template void visit (std::unique_ptr &node); + /** + * @see visit> + */ + template void visit (T &node); + /** * Visit all items in given @collection, placing the separator in between but * not at the end. @@ -122,12 +127,12 @@ private: std::unique_ptr &block); void visit (FunctionParam ¶m); - void visit (const Attribute &attrib); - void visit (const Visibility &vis); + void visit (Attribute &attrib); + void visit (Visibility &vis); void visit (std::vector> ¶ms); void visit (TupleField &field); void visit (StructField &field); - void visit (const SimplePathSegment &segment); + void visit (SimplePathSegment &segment); void visit (NamedFunctionParam ¶m); void visit (MacroRule &rule); diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 17d11e4de38..4e237f2e21e 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -908,6 +908,7 @@ public: FunctionQualifiers get_qualifiers () { return qualifiers; } + Visibility &get_visibility () { return vis; } const Visibility &get_visibility () const { return vis; } protected: @@ -1982,6 +1983,7 @@ public: return field_type; } + Visibility &get_visibility () { return visibility; } const Visibility &get_visibility () const { return visibility; } NodeId get_node_id () const { return node_id; } @@ -2116,6 +2118,7 @@ public: NodeId get_node_id () const { return node_id; } + Visibility &get_visibility () { return visibility; } const Visibility &get_visibility () const { return visibility; } Location get_locus () const { return locus; } @@ -4157,6 +4160,7 @@ public: Location get_locus () const { return locus; } + Visibility &get_visibility () { return visibility; } const Visibility &get_visibility () const { return visibility; } ExternalFunctionItem ( From patchwork Tue Feb 21 12:02:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60023 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1838237wrn; Tue, 21 Feb 2023 04:40:18 -0800 (PST) X-Google-Smtp-Source: AK7set+4wBt6kmr5E4NFSH5Kz72yGlODNfbRToudk3ENb6XmMYFShkPB3zcpNICXDTY5J/aamCJy X-Received: by 2002:a17:906:f8cf:b0:8b1:78b8:4208 with SMTP id lh15-20020a170906f8cf00b008b178b84208mr13727494ejb.1.1676983218705; Tue, 21 Feb 2023 04:40:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983218; cv=none; d=google.com; s=arc-20160816; b=zDjZlWCkdcp5MM0tAxdnkovfgetVlmuATz0JbasncUyx2nuEu84b3swImBt7lCbO4M o0m3VzmXvj+vr32Ro0d2OWc/QY+GMy6TQiM8p+9DB+eRkSPVqXgs9trqLDEX/oZCIjYv SGcV2sWQX1TUuKnn1x6EjTr4EdZ/AtJ2llxXGZJvHgIzmK3BBoPvgA6iM5obj5XbjbVG aSmsxSfdOmrQOOnYLIwxUcSyr/htatC/LyHgxzYN9aelH/xsKwZNs9efNi4DDBKrf8Ti gt2t5lxuQyEOmv24h8/FmLxWycpiw3nKp/uPa7IMjpp3d6csJnxPXu8KWVhoEUrqGpCu JKww== 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=BjAHtJds/dYXJHqzSlCFG7powDL7LnfaotJl7XWauHQ=; b=zLczB8U1RvsAczb4qR6sU7oeVhMXD+NrdzaQ98qwhL1pAE+XTCTIN6kuHfBacx9W2s xuTUA55NVxfgaNS3xye7t/cJYthDWzuLfEFvZN9KBhAH9crxTqZZtkqEHp5gOmCxw2av zRW6lBiRa+RoDbwxnmgUfGYY263wigqPlKrlB3KAd8rl6Avlc/8R/ZczIBeBftqReK1u /VVPnXup/T/zbz/dKX0MJxXx9J93MAWun9PWbVRIFkfL/CBndnLitj/Lq+cGcymot4s+ Fq8mh2esUh4hJm63ZcPoZHGUvAYmeDMpHPY1tOcTbPoBsCk+mNtOLL83mZpME2nefixU wIdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=QmdA0XRi; 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 z7-20020a17090674c700b008d2e6df3b6dsi8653653ejl.712.2023.02.21.04.40.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:40:18 -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=QmdA0XRi; 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 C55653995BD6 for ; Tue, 21 Feb 2023 12:13:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 285883881D00 for ; Tue, 21 Feb 2023 12:04:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 285883881D00 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-x42f.google.com with SMTP id c12so4164565wrw.1 for ; Tue, 21 Feb 2023 04:04:24 -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=BjAHtJds/dYXJHqzSlCFG7powDL7LnfaotJl7XWauHQ=; b=QmdA0XRisWXTUx4ygAp47xADIyE/L1xy3voPJjah9U8d8wh370oBneKfvfI4WX0FCV k3hvFG+rJRXw2l3bzeduoYzp7x3r8A0IXCohNTjzxAOTyM+q+ttfliqH7zJeujBfLFBH kwLZF1PXdNuIJHqMg9lsTaNcLxNtBlAxmSyxNAGjwhy7sXxRcEVAeq29ds4sc1JIJsey 6WSgC4DpZoYWQ+evfNdrSwODgD3DH+vyhlFRDskctBi2nNKirtN1WKNrgBSWvG2O5QLD pAfe5eayyRmVmMqJOT/JTwTTajHLO4gP4I0rqAUc/KMdDfl3TqxhlN9qwnPY+2i/CJ8+ xVVg== 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=BjAHtJds/dYXJHqzSlCFG7powDL7LnfaotJl7XWauHQ=; b=SwXUkRS3Sxq2+jo1kbGD/ign6P5K3xGz+SskSGrJajhO69/WYR9MrKWYzbHchL/0Yu kwcjxfsCYm80utkzKwNX+0sh4L9W2h1yXVn4+hQxKlJQh54pipjEutP38zMPhdrpUisj LoABKHJmrYN89tnRf9kMN+k4vF4aqiqSvkpDuJpYnENIP5utf/BRooOr5JhWgnUkeTmH dhyq7c1x/jSdnY1Uq6SjtNJaDfbpO+kLidSmxNXSsZ5UtvKhlZC1dhCIddgpl/gsZVTg GSHu88fyfCdJ4j2jCQcuy73H7Dxo5CU2fZxtBj+bTPDb3igGeVtfgcPQrGFltuFRNODu rjQQ== X-Gm-Message-State: AO0yUKWFNi39ioLvGC43qzt9iZjmsXJaW/Aa69G45LZXwpXHZvU9tf0b oH8bW+Mnty82nYZsI8O35A9HBEcW8VFIdaHGcw== X-Received: by 2002:a05:6000:c1:b0:2c5:5308:859c with SMTP id q1-20020a05600000c100b002c55308859cmr2351680wrx.18.1676981063456; Tue, 21 Feb 2023 04:04:23 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:23 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 073/103] gccrs: ast: Dump where clause and recursively needed nodes Date: Tue, 21 Feb 2023 13:02:03 +0100 Message-Id: <20230221120230.596966-74-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?1758444355713773659?= X-GMAIL-MSGID: =?utf-8?q?1758444355713773659?= From: Jakub Dupak This is currently needed for lifetimes to use the existing infrastructure. gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add missing visitors. * ast/rust-ast-dump.h: Likewise. * ast/rust-ast.h: Add `get_lifetime_bounds` method. * ast/rust-item.h: Add missing getter for lifetimes. * ast/rust-type.h: Likewise. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 140 +++++++++++++++++++++++++++++----- gcc/rust/ast/rust-ast-dump.h | 2 + gcc/rust/ast/rust-ast.h | 2 + gcc/rust/ast/rust-item.h | 2 + gcc/rust/ast/rust-type.h | 2 + 5 files changed, 131 insertions(+), 17 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 16c4a79dc6e..e5e051a46d8 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -227,6 +227,28 @@ Dump::visit (StructField &field) visit (field.get_field_type ()); } +// TODO is this unique by type? +void +Dump::visit (std::vector &for_lifetimes) +{ + // ForLifetimes : + // for GenericParams + // + // GenericParams : + // < > + // | < (GenericParam ,)* GenericParam ,? > + // + // GenericParam : + // OuterAttribute* ( LifetimeParam | TypeParam | ConstParam ) + // + // LifetimeParam : + // LIFETIME_OR_LABEL ( : LifetimeBounds )? + + stream << "for <"; + visit_items_joined_by_separator (for_lifetimes, " + "); + stream << "> "; +} + void Dump::visit (Token &tok) { @@ -258,11 +280,35 @@ Dump::visit (IdentifierExpr &ident_expr) void Dump::visit (Lifetime &lifetime) -{} +{ + // Syntax: + // Lifetime : + // LIFETIME_OR_LABEL + // | 'static + // | '_ + stream << lifetime.as_string (); +} void Dump::visit (LifetimeParam &lifetime_param) -{} +{ + // Syntax: + // LIFETIME_OR_LABEL ( : LifetimeBounds )? + // LifetimeBounds : + // ( Lifetime + )* Lifetime? + + // TODO what to do with outer attr? They are not mentioned in the reference. + + auto lifetime = lifetime_param.get_lifetime (); + visit (lifetime); + + if (lifetime_param.has_lifetime_bounds ()) + { + stream << ": "; + visit_items_joined_by_separator (lifetime_param.get_lifetime_bounds (), + " + "); + } +} void Dump::visit (ConstGenericParam &lifetime_param) @@ -804,13 +850,52 @@ Dump::visit (TypeParam ¶m) } } +void +Dump::visit (WhereClause &rule) +{ + // Syntax: + // where ( WhereClauseItem , )* WhereClauseItem ? + // WhereClauseItem : + // LifetimeWhereClauseItem + // | TypeBoundWhereClauseItem + + stream << " where\n"; + indentation.increment (); + visit_items_as_lines (rule.get_items (), ","); + indentation.decrement (); +} + void Dump::visit (LifetimeWhereClauseItem &item) -{} +{ + // Syntax: + // Lifetime : LifetimeBounds + // LifetimeBounds : + // ( Lifetime + )* Lifetime? + + visit (item.get_lifetime ()); + stream << ": "; + visit_items_joined_by_separator (item.get_lifetime_bounds (), " + "); +} void Dump::visit (TypeBoundWhereClauseItem &item) -{} +{ + // Syntax: + // ForLifetimes? Type : TypeParamBounds? + // TypeParamBounds : + // TypeParamBound ( + TypeParamBound )* +? + // TypeParamBound : + // Lifetime | TraitBound + + if (item.has_for_lifetimes ()) + visit (item.get_for_lifetimes ()); + + visit (item.get_type ()); + stream << ": "; + + visit_items_joined_by_separator (item.get_type_param_bounds (), " + "); +} void Dump::visit (Method &method) @@ -896,6 +981,12 @@ Dump::visit (UseDeclaration &use_decl) void Dump::visit (Function &function) { + // Syntax: + // FunctionQualifiers fn IDENTIFIER GenericParams? + // ( FunctionParameters? ) + // FunctionReturnType? WhereClause? + // ( BlockExpression | ; ) + visit (function.get_visibility ()); stream << "fn " << function.get_function_name (); @@ -913,6 +1004,9 @@ Dump::visit (Function &function) stream << " "; } + if (function.has_where_clause ()) + visit (function.get_where_clause ()); + auto &block = function.get_definition (); if (!block) stream << ';'; @@ -936,8 +1030,7 @@ Dump::visit (TypeAlias &type_alias) if (type_alias.has_generics ()) visit (type_alias.get_generic_params ()); if (type_alias.has_where_clause ()) - { - } // FIXME: WhereClause + visit (type_alias.get_where_clause ()); stream << " = "; visit (type_alias.get_type_aliased ()); stream << ";\n"; @@ -949,9 +1042,8 @@ Dump::visit (StructStruct &struct_item) stream << "struct " << struct_item.get_identifier (); if (struct_item.has_generics ()) visit (struct_item.get_generic_params ()); - - // FIXME: where-clause - + if (struct_item.has_where_clause ()) + visit (struct_item.get_where_clause ()); if (struct_item.is_unit_struct ()) stream << ";\n"; else @@ -964,8 +1056,8 @@ Dump::visit (TupleStruct &tuple_struct) stream << "struct " << tuple_struct.get_identifier (); if (tuple_struct.has_generics ()) visit (tuple_struct.get_generic_params ()); - - // FIXME: where-clause + if (tuple_struct.has_where_clause ()) + visit (tuple_struct.get_where_clause ()); stream << '('; visit_items_joined_by_separator (tuple_struct.get_fields (), ", "); @@ -1006,8 +1098,8 @@ Dump::visit (Enum &enum_item) stream << "enum " << enum_item.get_identifier (); if (enum_item.has_generics ()) visit (enum_item.get_generic_params ()); - - // FIXME: where-clause + if (enum_item.has_where_clause ()) + visit (enum_item.get_where_clause ()); visit_items_as_block (enum_item.get_variants (), ","); } @@ -1018,8 +1110,8 @@ Dump::visit (Union &union_item) stream << "union " << union_item.get_identifier (); if (union_item.has_generics ()) visit (union_item.get_generic_params ()); - - // FIXME: where-clause + if (union_item.has_where_clause ()) + visit (union_item.get_where_clause ()); visit_items_as_block (union_item.get_variants (), ","); } @@ -1137,7 +1229,9 @@ Dump::visit (InherentImpl &impl) visit (impl.get_type ()); - // FIXME: Handle where-clause + if (impl.has_where_clause ()) + visit (impl.get_where_clause ()); + // FIXME: Handle inner attributes visit_items_as_block (impl.get_impl_items (), ""); @@ -1451,7 +1545,19 @@ Dump::visit (ExprStmtWithBlock &stmt) // rust-type.h void Dump::visit (TraitBound &bound) -{} +{ + // Syntax: + // ?? ForLifetimes? TypePath + // | ( ?? ForLifetimes? TypePath ) + + if (bound.has_opening_question_mark ()) + stream << "? "; + + if (bound.has_for_lifetimes ()) + visit (bound.get_for_lifetimes ()); + + visit (bound.get_type_path ()); +} void Dump::visit (ImplTraitType &type) diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h index 57419b75347..2bd3b31d09a 100644 --- a/gcc/rust/ast/rust-ast-dump.h +++ b/gcc/rust/ast/rust-ast-dump.h @@ -135,6 +135,8 @@ private: void visit (SimplePathSegment &segment); void visit (NamedFunctionParam ¶m); void visit (MacroRule &rule); + void visit (WhereClause &rule); + void visit (std::vector &for_lifetimes); // rust-ast.h void visit (Token &tok); diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 3d602b1a379..aa86f2f9826 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -1310,6 +1310,8 @@ public: // Returns whether the lifetime param has any lifetime bounds. bool has_lifetime_bounds () const { return !lifetime_bounds.empty (); } + std::vector &get_lifetime_bounds () { return lifetime_bounds; } + // Returns whether the lifetime param has an outer attribute. bool has_outer_attribute () const { return !outer_attr.is_empty (); } diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 4e237f2e21e..96201d668de 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -236,6 +236,8 @@ public: // Returns whether the item has ForLifetimes bool has_for_lifetimes () const { return !for_lifetimes.empty (); } + std::vector &get_for_lifetimes () { return for_lifetimes; } + // Returns whether the item has type param bounds bool has_type_param_bounds () const { return !type_param_bounds.empty (); } diff --git a/gcc/rust/ast/rust-type.h b/gcc/rust/ast/rust-type.h index 0b91cafbfd1..05a78956b57 100644 --- a/gcc/rust/ast/rust-type.h +++ b/gcc/rust/ast/rust-type.h @@ -46,6 +46,8 @@ public: // Returns whether trait bound has "for" lifetimes bool has_for_lifetimes () const { return !for_lifetimes.empty (); } + std::vector &get_for_lifetimes () { return for_lifetimes; } + TraitBound (TypePath type_path, Location locus, bool in_parens = false, bool opening_question_mark = false, std::vector for_lifetimes From patchwork Tue Feb 21 12:02:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60064 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1846869wrn; Tue, 21 Feb 2023 05:00:13 -0800 (PST) X-Google-Smtp-Source: AK7set/wl216a3StUtvKMsWtbNDOXetK+e/UhUYwScYHWgNc1KPzHS2Mnn0ka+tqDytHlQViTiGt X-Received: by 2002:a05:6402:8d4:b0:4ad:a70c:e001 with SMTP id d20-20020a05640208d400b004ada70ce001mr3526771edz.21.1676984413416; Tue, 21 Feb 2023 05:00:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984413; cv=none; d=google.com; s=arc-20160816; b=W+3XSPNUKWoU4cCVFtBXPaH+C7gHzAhrVscBzbfmpeagi0eiN0xIqsKJ+7wIPOxT+q J89lnmkx5a/9/KgF0WdWPKY0SPYb1h9UC8hGxcg79PCFMVBWQmA5aWvqUMT9aDhEBH1V Vsxw6gOg5+baI+ZImEgLX7pk059kbkzy//LyrIvBFddA0XLDcP1IlNfbapdJYbQK8r4R LPfpik8+KozinnKGc0ptpdsok18+EvVse7hBoz7sEWSnh3Sj168/iz8vSL3sFFBRnozH rqD6fc3jGnnMMrFRqFlpLt3b9Ul+NenQALB7/S/HHFKGGLtKka3YBL3dZBg0g2JxEDYa yhng== 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=QF83OxrRWk1AKyEJS60vF2ZB2PDNOhaYtv6g19mPX1o=; b=V3WMOoeouuoRhh3hwBkkSHLX24MT57uikriUHgTcmZFdQ+mmNO+tnWiGp1i6qgPhPj dfZiDAM6LQkccDDNvgMbVJq8k2tVGF/pMl1mSWmZDpXmSnSASQoljfk+BOM7YDJtNdv7 FDI8PTwp0XyoyhqeZsEYkp4/de9BsLhMdl+RPwp+flNSAlCzYAfsAd8uCKVEA3ETW9Sq QGBzDU/8TTesJ5/pQmp/sU2rp229QGpM5dH23aGrdRWrKsQJFQzY5uXoZUbGrtEOm8IQ bSQVGml17EXUuwzyAlmtdGK5/c7MGkCffnY87bbNPwD3dou+pE8JXulwizYBZdXzDA// 31FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=AjXIFdss; 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 u4-20020aa7d0c4000000b004aef6266c6bsi7117194edo.325.2023.02.21.05.00.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 05:00:13 -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=AjXIFdss; 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 B75DC38DDF29 for ; Tue, 21 Feb 2023 12:21:04 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 11F153836EBD for ; Tue, 21 Feb 2023 12:04:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 11F153836EBD 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-x436.google.com with SMTP id z8so3885206wrm.8 for ; Tue, 21 Feb 2023 04:04:25 -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=QF83OxrRWk1AKyEJS60vF2ZB2PDNOhaYtv6g19mPX1o=; b=AjXIFdssUfKp52wLRj5I5kIK+8GmfhaCEt/63R9jadeWL2AoBxKUH7OSQJlQKdOQfU /eMyvSdQFRjykHG9skcMGshHQ4eb7OXhclRZF/mh3/289vcb/oMNIGTZSVFnXV5/1HWX xigirIm/hDoM13n3fJTSOCjKmJAcuJnoPKrbZYS9JwCcQTF5snNLJ0AeXi670u3ORjVF 1YSbjDchIFpE7MU+DJhAYLyj2VhNcAwGa2BKjBF2hLRRDTVtlJIa0Xh7DgxRhj3QwcMZ JedKMOQ54mI0sCKN8JSE/JEy2l8c8OiuGgUa82h4X51EeD7asnpJkeHjwwCWuzeTdOhx J6Qw== 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=QF83OxrRWk1AKyEJS60vF2ZB2PDNOhaYtv6g19mPX1o=; b=XcApfU5SlNGZuQ6n+GU7bMucKjPI9IA8EdPFYvT0Fs21jwQtWIXG78NhuOSZo+ROIR zNiK9Wv0Y8v63iLF7Yb8+lR33aK4Odl6o9oTo/wI3RftyGxWSUZkb1gF81VGiGadt3XY I1pB37Wu76QH2ivK+z37acAGqcbGwcN5fVIut7RFnYWK6QUI5T+XHoO4S4K54iPENZrY ymiEhTs7coLawf4PJxNle/bgviHp1VYNRwFEwSDy+ReLihDZUNPpsbYFIPxTdq/QXM0I SByV8v/ha23P4CoHQk+QbseLuRSF/BPC6OYgxB0s/8+9HuZS4dcSATF9qANOoOlhwTmV hIwA== X-Gm-Message-State: AO0yUKWX75B17Cfarf1xFqauFg6NFWeMvqX6oQc5JbzH0G0DRmIy9SHg yqTSjRuleGAEHiTdaiz3tLSrpBGS7oLuY6QuPA== X-Received: by 2002:a5d:5489:0:b0:2c6:d392:5579 with SMTP id h9-20020a5d5489000000b002c6d3925579mr3096116wrv.16.1676981064474; Tue, 21 Feb 2023 04:04:24 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:23 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 074/103] gccrs: ast: Dump slice type Date: Tue, 21 Feb 2023 13:02:04 +0100 Message-Id: <20230221120230.596966-75-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?1758445608525719627?= X-GMAIL-MSGID: =?utf-8?q?1758445608525719627?= From: Jakub Dupak gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add missing slice visitor. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index e5e051a46d8..b017c6ea592 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1606,7 +1606,12 @@ Dump::visit (ArrayType &type) void Dump::visit (SliceType &type) { + // Syntax: + // [ Type ] + + stream << '['; visit (type.get_elem_type ()); + stream << ']'; } void From patchwork Tue Feb 21 12:02:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60042 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1841515wrn; Tue, 21 Feb 2023 04:47:58 -0800 (PST) X-Google-Smtp-Source: AK7set/cFtecDihj7+tmtd+VFnhPN3AeqP6srDEnJfTDN4W7wge+7xEjQAfSFoQ6GAMnHZq5VnU0 X-Received: by 2002:aa7:d615:0:b0:4af:59c0:d303 with SMTP id c21-20020aa7d615000000b004af59c0d303mr363312edr.26.1676983677915; Tue, 21 Feb 2023 04:47:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983677; cv=none; d=google.com; s=arc-20160816; b=vfVEKTQTpJUDMHzTQ/BTK4VK4HAl8l4DVMTdlgfOY4Hcf7N130IPPlxE2r0R3bYwfG sANJE/qLHw7sOFEF99IVAbq//3VB8ZUfjyr7oEvYtq0G7mk51TAyG3QF0uAbfblY+wQA dqwS7yRGX5Tg1Rki0oXq9gtGoIHbm1VmQJckQxB+uGpXId9NTUBuPKy0JD4vWnHVCSe3 7lBIbb2CXpgCIfNhwylRRfd+7DrkuDuUdH0Wt2w8wWvPxQZkKCI5Ah1UgKUlZqI2wmzN 9qbCbuzBdoQ0RtRCY08M1Wh7E6oR2hOuGb8ArE6PiZ3copC7MiDuQWqn1awcxYBOwCY6 ywVA== 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=qPwKG1dft3w8VI1Iipv7tGcsWBo3Z5xgOHXhl2kP86Y=; b=X6wweef1ENQkssOvppoWvwzl+0ofJe5RSppZ2kis3mWcaRhJXH2jmgZwZRH67Igxsz IDMrtCmSWCWjMLf+ddRz1pLWIlz2r81v3XXLncWQaY1n1XRToWy7qM6tchpFhhbGZldI c202t0Adtl4Ji2PpWsK17ihIquV0L0gD8Sy6bj9rL+ZrE6AB/H7Vrxl0Mf29OjMXEYWI tCZK7I1UHvWGxiktGNfREOLkbSkR/ynBAilY2T4QHgJutt9TZMVRsPoVxE62cEUe6XzU NqVn/a7wgZFrq00dxDxP3G8EATvRpUT6vMP7omCkQwq6Lx3PXY3qKVhtxje/ReKtmRGU icaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=LnYazIRV; 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 m7-20020aa7d347000000b004aac89c74a9si4173024edr.630.2023.02.21.04.47.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:47:57 -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=LnYazIRV; 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 3DC7D392CBE4 for ; Tue, 21 Feb 2023 12:15:51 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 0C24B384FB41 for ; Tue, 21 Feb 2023 12:04:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0C24B384FB41 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-x42f.google.com with SMTP id l1so3887462wry.10 for ; Tue, 21 Feb 2023 04:04:26 -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=qPwKG1dft3w8VI1Iipv7tGcsWBo3Z5xgOHXhl2kP86Y=; b=LnYazIRVrhjREPhCy5UysqGYNTRyBFiF1xvv+bY4PJHfxPekcZiWEyPab0GdaEndOY qw226I6l5LUuIZimXkPDDqzcta23KXumZOpv8pjmESMIJMsatIDZhgE8BnzApABf+ABK f5/JEHYe3Hyx4gBh3LoZ+Rhk/MNrvQdcKeoR38Mj+q0GcMQsFBglDaWqd/KX2rCdizCV O0AW1xh2vTjievOjtEZg4r17Olz9HcLprV3+nKS+8Xo+rjH6urqIw0tDT+99mMJLRNix 8rPcGNs225ExN3qmJmAW/52EmAr2YSThPIPSRIngj6GnCTBTtxScHDIFo2uC054Wo9Jo DrMg== 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=qPwKG1dft3w8VI1Iipv7tGcsWBo3Z5xgOHXhl2kP86Y=; b=M+9IRXcKoomVK73UVc7Qte2INobxp9qKC6Swc9eX1TlRh13J/02NSGlHkSESRLSkvF OOFelrcNC89TSLQ3j2sh7BXgQ8ajCRXyB/FyU5ohKV0/OVGOAoh7P2s4EWw8bxzL5WCT /+8u1QKlEbmdXq9uFMTNh9I0HNHzdh5fDzFfK5Q9t54o5lB3ZDNyoB2K4cDrR07zQnBe YWwkclD2CsDKJPp+PLPUIUNgPkodjedgj3FyIsTkyK7U3nXyi8r9QVShE/6XLZJPIcnJ 7IpE8OGmzfcr+hVqohNjqmjXP8Vwu8gzR3t+nUo0rTPLCqeJjQRsI64i4dPm79ULe/bs A/pw== X-Gm-Message-State: AO0yUKXOLyQfVkQYPREVPdWtAywHhrFeyglPIa9BOI5NreMqfTrm2ZhZ Ac2KB5ph89UJ5pDkQ0hi0jLw/Epe1VMoCw+fQQ== X-Received: by 2002:a5d:58ce:0:b0:2c5:56f7:51eb with SMTP id o14-20020a5d58ce000000b002c556f751ebmr3545722wrf.63.1676981065375; Tue, 21 Feb 2023 04:04:25 -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.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:24 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 075/103] gccrs: ast: Dump array type Date: Tue, 21 Feb 2023 13:02:05 +0100 Message-Id: <20230221120230.596966-76-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?1758444836799272853?= X-GMAIL-MSGID: =?utf-8?q?1758444836799272853?= From: Jakub Dupak gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add missing array visitor Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index b017c6ea592..9f73d0565ac 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1600,7 +1600,14 @@ Dump::visit (ReferenceType &type) void Dump::visit (ArrayType &type) { + // Syntax: + // [ Type ; Expression ] + + stream << '['; visit (type.get_elem_type ()); + stream << "; "; + visit(type.get_size_expr()); + stream << ']'; } void From patchwork Tue Feb 21 12:02:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60031 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1839321wrn; Tue, 21 Feb 2023 04:42:53 -0800 (PST) X-Google-Smtp-Source: AK7set9wljGmoe4hJ5IxNkGlgc5eUC4yEK8/sye1pkdqR/lkPuuGWCIiEkIgvC3ljWWCM6kuR/9y X-Received: by 2002:a50:ec94:0:b0:4ab:2504:c7ff with SMTP id e20-20020a50ec94000000b004ab2504c7ffmr5563501edr.23.1676983373746; Tue, 21 Feb 2023 04:42:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983373; cv=none; d=google.com; s=arc-20160816; b=sVv0fZ3HOgWGxSNovKI5p9JQlii8QN7kltPnlI8QwCwkTjQCVhVMXTiTB6vcShk0bm IGDFPIhmSqKokdNgG1KCSfyV4Vd+ggayAalGcjHRIyYn2Nemkdg2fKfdzMz/rnJg0olY o234DnwgdnTpnmblW98nZCaMwXbo/K41LQrKzAuaz9RzvC69BgdOjTm5CBlDzOen1gok UkzjRMXUuedo8fXyNs78lGLRlK28LhxLxx6O9MphLOExHUr+QYjhEvRcfL0QGTN0ADRo ba1AZTKlwoCE32Blu/5PyZs2tU3kPZbzm3zVXPoWJ3YyPxlkfqzWvvYJAaIoqdgGh5tE 1TNA== 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=b4l4lMg+R/elc2tKtPjjaADgQ8YpFK0wm0cOTUenBgw=; b=E2iIeHyKSuRcQNDEH6qTTsTOgTMtn6kNjAUTKCzbOh0TFzDlPZ/hZ4aSGHl8DKW7J/ xOt0F4/u7oIWJ9geL2IRPs/Okvm+tDWGMNZdKzqtG6jElL/ajzOBjyHMV4VDdJEJcJDF QTLmChFhM5ag1ExAxYiaOXTo+TWHgftTKojT3UUBKLY5Y1wDVAQwbZ6DSDh5l2r+JO0h +n+h8MwVbnLl+dX+BT5yg3TjT5KVHcRzD5kbJEGmWEW8C+NgZjf1JYjFn8ruBZ10vKo+ 0sRp+/Mxk7tIZYCwZL3RUp35gGC8uoKyDAgDEx5fMeJPNKnnrC9pb2wncmi4l3HRcqrL t7PA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=a1dKDhPm; 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 o11-20020aa7d3cb000000b004acc4ee372bsi3189799edr.475.2023.02.21.04.42.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:42:53 -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=a1dKDhPm; 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 2403F39E7B53 for ; Tue, 21 Feb 2023 12:14:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 AE3C63846934 for ; Tue, 21 Feb 2023 12:04:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AE3C63846934 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 bo30so3604029wrb.0 for ; Tue, 21 Feb 2023 04:04:26 -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=b4l4lMg+R/elc2tKtPjjaADgQ8YpFK0wm0cOTUenBgw=; b=a1dKDhPmQ76T4qe9Rt7MkoCH1VVIJvsbDkn5jFr46GDjLdfH2lnfkr+zNtYYvfnGAU fuwRiHK9eCK29vs7FwEpK5vKYIwyjOFB/k9FuwY4P3h9uS4U8SMfpj0W3OKcU9YK6u9C BkvyU3lsWwCy5+7k43/e7o92aC3yD1cP4E8hL0U/7+M7HeB4NkaJMF4jsgXPpA9e9iSV i7rTG/konDWRKuOzbO/MFckgUJvPkA1WES5bYhhrfjHo481KUCoM/sN5xfte/pbvv/Mm +aQ8UznwKuZfxOkQkxuVHQjnpzRHGcskajCNyAK6/JlurG5iIjBgaVg7LxOtoOyoEqUW Y5EQ== 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=b4l4lMg+R/elc2tKtPjjaADgQ8YpFK0wm0cOTUenBgw=; b=3pr4IJ+1E5ab3Ph0TWS0uDNMbU7HVjlg9smK5nrM39eJkO8BaCbFF01qrwKDDZJ5VU z3r8UB3BCFKL05SKVDiZivZKjQY8v2N/vVsE6A5pCHDIB9Yf++o7br+RQxUnFpzn0iwU hESTVt73ReMvt0AzIWP4io544eFg2NRJxNTNkglqJKu+cTo7mFfeCnrtpeUWk2LftSYf F4efMo3xDxNsV3MCunux+F5kaxSfyaLqiHBkjmvt0voDHMjCzAqfycGijYJ6WepeAOwO 8nGXnyF3vy7BiqDMi5TAE1zDaUQ1ZEvHJp2HgN9V6eagEpDwn6Z225mpCVp/nm6Xtt95 OQeA== X-Gm-Message-State: AO0yUKVfygi0dq1RRXDQydHPLr5yAXNtND3aJ9sPGAuvLucwK9nVh978 If0fm38MCOmr+ZdzPBab87qaoDSljpfpmw0EXw== X-Received: by 2002:a5d:6089:0:b0:2c5:5936:16db with SMTP id w9-20020a5d6089000000b002c5593616dbmr3922014wrt.42.1676981066064; Tue, 21 Feb 2023 04:04:26 -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.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:25 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 076/103] gccrs: ast: Dump raw pointer type Date: Tue, 21 Feb 2023 13:02:06 +0100 Message-Id: <20230221120230.596966-77-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=ham 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?1758444518064098745?= X-GMAIL-MSGID: =?utf-8?q?1758444518064098745?= From: Jakub Dupak gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add missing RawPointer visitor. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 200 +++++++++++++++++++--------------- 1 file changed, 112 insertions(+), 88 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 9f73d0565ac..e6d6e070709 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -269,7 +269,7 @@ Dump::visit (DelimTokenTree &delim_tok_tree) } void -Dump::visit (AttrInputMetaItemContainer &input) +Dump::visit (AttrInputMetaItemContainer &) {} void @@ -311,7 +311,7 @@ Dump::visit (LifetimeParam &lifetime_param) } void -Dump::visit (ConstGenericParam &lifetime_param) +Dump::visit (ConstGenericParam &) {} // rust-path.h @@ -322,15 +322,15 @@ Dump::visit (PathInExpression &path) } void -Dump::visit (TypePathSegment &segment) +Dump::visit (TypePathSegment &) {} void -Dump::visit (TypePathSegmentGeneric &segment) +Dump::visit (TypePathSegmentGeneric &) {} void -Dump::visit (TypePathSegmentFunction &segment) +Dump::visit (TypePathSegmentFunction &) {} void @@ -346,7 +346,7 @@ Dump::visit (QualifiedPathInExpression &path) } void -Dump::visit (QualifiedPathInType &path) +Dump::visit (QualifiedPathInType &) {} // rust-expr.h @@ -357,15 +357,15 @@ Dump::visit (LiteralExpr &expr) } void -Dump::visit (AttrInputLiteral &attr_input) +Dump::visit (AttrInputLiteral &) {} void -Dump::visit (MetaItemLitExpr &meta_item) +Dump::visit (MetaItemLitExpr &) {} void -Dump::visit (MetaItemPathLit &meta_item) +Dump::visit (MetaItemPathLit &) {} void @@ -623,35 +623,35 @@ Dump::visit (ArrayIndexExpr &expr) } void -Dump::visit (TupleExpr &expr) +Dump::visit (TupleExpr &) {} void -Dump::visit (TupleIndexExpr &expr) +Dump::visit (TupleIndexExpr &) {} void -Dump::visit (StructExprStruct &expr) +Dump::visit (StructExprStruct &) {} void -Dump::visit (StructExprFieldIdentifier &field) +Dump::visit (StructExprFieldIdentifier &) {} void -Dump::visit (StructExprFieldIdentifierValue &field) +Dump::visit (StructExprFieldIdentifierValue &) {} void -Dump::visit (StructExprFieldIndexValue &field) +Dump::visit (StructExprFieldIndexValue &) {} void -Dump::visit (StructExprStructFields &expr) +Dump::visit (StructExprStructFields &) {} void -Dump::visit (StructExprStructBase &expr) +Dump::visit (StructExprStructBase &) {} void @@ -669,15 +669,15 @@ Dump::visit (CallExpr &expr) } void -Dump::visit (MethodCallExpr &expr) +Dump::visit (MethodCallExpr &) {} void -Dump::visit (FieldAccessExpr &expr) +Dump::visit (FieldAccessExpr &) {} void -Dump::visit (ClosureExprInner &expr) +Dump::visit (ClosureExprInner &) {} void @@ -696,15 +696,15 @@ Dump::visit (BlockExpr &expr) } void -Dump::visit (ClosureExprInnerTyped &expr) +Dump::visit (ClosureExprInnerTyped &) {} void -Dump::visit (ContinueExpr &expr) +Dump::visit (ContinueExpr &) {} void -Dump::visit (BreakExpr &expr) +Dump::visit (BreakExpr &) {} void @@ -730,7 +730,7 @@ Dump::visit (RangeToExpr &expr) } void -Dump::visit (RangeFullExpr &expr) +Dump::visit (RangeFullExpr &) { stream << ".."; } @@ -751,27 +751,27 @@ Dump::visit (RangeToInclExpr &expr) } void -Dump::visit (ReturnExpr &expr) +Dump::visit (ReturnExpr &) {} void -Dump::visit (UnsafeBlockExpr &expr) +Dump::visit (UnsafeBlockExpr &) {} void -Dump::visit (LoopExpr &expr) +Dump::visit (LoopExpr &) {} void -Dump::visit (WhileLoopExpr &expr) +Dump::visit (WhileLoopExpr &) {} void -Dump::visit (WhileLetLoopExpr &expr) +Dump::visit (WhileLetLoopExpr &) {} void -Dump::visit (ForLoopExpr &expr) +Dump::visit (ForLoopExpr &) {} void @@ -807,35 +807,35 @@ Dump::visit (IfExprConseqIf &expr) } void -Dump::visit (IfExprConseqIfLet &expr) +Dump::visit (IfExprConseqIfLet &) {} void -Dump::visit (IfLetExpr &expr) +Dump::visit (IfLetExpr &) {} void -Dump::visit (IfLetExprConseqElse &expr) +Dump::visit (IfLetExprConseqElse &) {} void -Dump::visit (IfLetExprConseqIf &expr) +Dump::visit (IfLetExprConseqIf &) {} void -Dump::visit (IfLetExprConseqIfLet &expr) +Dump::visit (IfLetExprConseqIfLet &) {} void -Dump::visit (MatchExpr &expr) +Dump::visit (MatchExpr &) {} void -Dump::visit (AwaitExpr &expr) +Dump::visit (AwaitExpr &) {} void -Dump::visit (AsyncBlockExpr &expr) +Dump::visit (AsyncBlockExpr &) {} // rust-item.h @@ -959,23 +959,23 @@ Dump::visit (Module &module) } void -Dump::visit (ExternCrate &crate) +Dump::visit (ExternCrate &) {} void -Dump::visit (UseTreeGlob &use_tree) +Dump::visit (UseTreeGlob &) {} void -Dump::visit (UseTreeList &use_tree) +Dump::visit (UseTreeList &) {} void -Dump::visit (UseTreeRebind &use_tree) +Dump::visit (UseTreeRebind &) {} void -Dump::visit (UseDeclaration &use_decl) +Dump::visit (UseDeclaration &) {} void @@ -1117,11 +1117,11 @@ Dump::visit (Union &union_item) } void -Dump::visit (ConstantItem &const_item) +Dump::visit (ConstantItem &) {} void -Dump::visit (StaticItem &static_item) +Dump::visit (StaticItem &) {} void @@ -1259,7 +1259,7 @@ Dump::visit (TraitImpl &impl) } void -Dump::visit (ExternalStaticItem &item) +Dump::visit (ExternalStaticItem &) {} void @@ -1386,36 +1386,36 @@ Dump::visit (MacroRulesDefinition &rules_def) } void -Dump::visit (MacroInvocation ¯o_invoc) +Dump::visit (MacroInvocation &) {} void -Dump::visit (MetaItemPath &meta_item) +Dump::visit (MetaItemPath &) {} void -Dump::visit (MetaItemSeq &meta_item) +Dump::visit (MetaItemSeq &) {} void -Dump::visit (MetaWord &meta_item) +Dump::visit (MetaWord &) {} void -Dump::visit (MetaNameValueStr &meta_item) +Dump::visit (MetaNameValueStr &) {} void -Dump::visit (MetaListPaths &meta_item) +Dump::visit (MetaListPaths &) {} void -Dump::visit (MetaListNameValueStr &meta_item) +Dump::visit (MetaListNameValueStr &) {} // rust-pattern.h void -Dump::visit (LiteralPattern &pattern) +Dump::visit (LiteralPattern &) {} void @@ -1425,88 +1425,88 @@ Dump::visit (IdentifierPattern &pattern) } void -Dump::visit (WildcardPattern &pattern) +Dump::visit (WildcardPattern &) {} -// void Dump::visit(RangePatternBound& bound){} +// void Dump::visit(RangePatternBound& ){} void -Dump::visit (RangePatternBoundLiteral &bound) +Dump::visit (RangePatternBoundLiteral &) {} void -Dump::visit (RangePatternBoundPath &bound) +Dump::visit (RangePatternBoundPath &) {} void -Dump::visit (RangePatternBoundQualPath &bound) +Dump::visit (RangePatternBoundQualPath &) {} void -Dump::visit (RangePattern &pattern) +Dump::visit (RangePattern &) {} void -Dump::visit (ReferencePattern &pattern) +Dump::visit (ReferencePattern &) {} -// void Dump::visit(StructPatternField& field){} +// void Dump::visit(StructPatternField& ){} void -Dump::visit (StructPatternFieldTuplePat &field) +Dump::visit (StructPatternFieldTuplePat &) {} void -Dump::visit (StructPatternFieldIdentPat &field) +Dump::visit (StructPatternFieldIdentPat &) {} void -Dump::visit (StructPatternFieldIdent &field) +Dump::visit (StructPatternFieldIdent &) {} void -Dump::visit (StructPattern &pattern) +Dump::visit (StructPattern &) {} -// void Dump::visit(TupleStructItems& tuple_items){} +// void Dump::visit(TupleStructItems& ){} void -Dump::visit (TupleStructItemsNoRange &tuple_items) +Dump::visit (TupleStructItemsNoRange &) {} void -Dump::visit (TupleStructItemsRange &tuple_items) +Dump::visit (TupleStructItemsRange &) {} void -Dump::visit (TupleStructPattern &pattern) +Dump::visit (TupleStructPattern &) {} -// void Dump::visit(TuplePatternItems& tuple_items){} +// void Dump::visit(TuplePatternItems& ){} void -Dump::visit (TuplePatternItemsMultiple &tuple_items) +Dump::visit (TuplePatternItemsMultiple &) {} void -Dump::visit (TuplePatternItemsRanged &tuple_items) +Dump::visit (TuplePatternItemsRanged &) {} void -Dump::visit (TuplePattern &pattern) +Dump::visit (TuplePattern &) {} void -Dump::visit (GroupedPattern &pattern) +Dump::visit (GroupedPattern &) {} void -Dump::visit (SlicePattern &pattern) +Dump::visit (SlicePattern &) {} // rust-stmt.h void -Dump::visit (EmptyStmt &stmt) +Dump::visit (EmptyStmt &) {} void @@ -1560,40 +1560,64 @@ Dump::visit (TraitBound &bound) } void -Dump::visit (ImplTraitType &type) +Dump::visit (ImplTraitType &) {} void -Dump::visit (TraitObjectType &type) +Dump::visit (TraitObjectType &) {} void -Dump::visit (ParenthesisedType &type) +Dump::visit (ParenthesisedType &) {} void -Dump::visit (ImplTraitTypeOneBound &type) +Dump::visit (ImplTraitTypeOneBound &) {} void -Dump::visit (TraitObjectTypeOneBound &type) +Dump::visit (TraitObjectTypeOneBound &) {} void -Dump::visit (TupleType &type) +Dump::visit (TupleType &) {} void -Dump::visit (NeverType &type) +Dump::visit (NeverType &) {} void Dump::visit (RawPointerType &type) -{} +{ + // Syntax: + // * ( mut | const ) TypeNoBounds + + if (type.get_pointer_type () == RawPointerType::MUT) + stream << "*mut "; + else /* RawPointerType::CONST */ + stream << "*const "; + + visit (type.get_type_pointed_to ()); +} void Dump::visit (ReferenceType &type) { + // Syntax: + // & Lifetime? mut? TypeNoBounds + + stream << '&'; + + if (type.has_lifetime ()) + { + visit (type.get_lifetime ()); + stream << ' '; + } + + if (type.get_has_mut ()) + stream << "mut "; + visit (type.get_type_referenced ()); } @@ -1606,7 +1630,7 @@ Dump::visit (ArrayType &type) stream << '['; visit (type.get_elem_type ()); stream << "; "; - visit(type.get_size_expr()); + visit (type.get_size_expr ()); stream << ']'; } @@ -1622,13 +1646,13 @@ Dump::visit (SliceType &type) } void -Dump::visit (InferredType &type) +Dump::visit (InferredType &) { stream << "_"; } void -Dump::visit (BareFunctionType &type) +Dump::visit (BareFunctionType &) {} } // namespace AST From patchwork Tue Feb 21 12:02:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60046 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1842382wrn; Tue, 21 Feb 2023 04:50:03 -0800 (PST) X-Google-Smtp-Source: AK7set/AQ8cUyhWHM3kinGZ3Wrjt23rPQBDrgAGSJVaaSI1b1rLxbwu0Hn8HrrvvQXB5nW2Hn2Z5 X-Received: by 2002:aa7:c306:0:b0:4ab:15d9:2dae with SMTP id l6-20020aa7c306000000b004ab15d92daemr5426045edq.14.1676983803298; Tue, 21 Feb 2023 04:50:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983803; cv=none; d=google.com; s=arc-20160816; b=NCLlTY6QiRfdonIwKnqQL4R7ViEbCqw4nxLX6AeFUUJtipKM/SMyxpfNonu8IO9YPC GYwheLM620YjZrXw3JAJqmd8/vbwuQyGM35/OGdd4CWHXN5P1eja2KtT60J94fViJnOn 0TUd1ReYEjbjY/BxCytLzSl4hr3rNt4cYv3KYk5IfBcvQlonnntWcq1OJnovfbOdzNpH VzcLJSykQufUbP9ZgdqeuFLMvd9w6lg19GmgpOyiTsVGAqDwVCbCm3npMyGjCTCyUdy1 RFMAca59/2oV8AkAOHM8gsAlYhod6oxoZrrYFZAiYyBwz8WZxHkQBftM71552cY0K9by LwMQ== 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=L6eAtmwzk72vX5Jk6XCvWsL8z4TEucBYbHfJ50Qccy0=; b=LMaftNo2qNzT/0GYfjNX5KhikoISwfKbIP+wJxiXyAnldznPRsbsLtLuohTTMvMEBu y7RJtc6/w6IBPENvDcUsQ/IxY5PHRpGYnzZr1R6806cvK6TulsHiwHwhXmTogu594pvG IB2goTfdwUFiLaILHItdOHUaQcWUPFA+rtlFdH5X//1eok6wjGf/glo03+vmSsdpbd8b 9/QdET6wPLGY+TfUAglseQFrqhKeTXMY3P2OUbm+ETkxyl/7xXSssP/2WC37TQJAzuZy eWXgVTEleM1zdVafTulyqzIWMYsaFUUSvbg1SacBEIlm0wYLirNmJKU37hRyRjhMQAYd LA0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=EB+6njac; 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 m3-20020aa7c2c3000000b004acbe85e42csi18994022edp.414.2023.02.21.04.50.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:50:03 -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=EB+6njac; 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 23A1C3894756 for ; Tue, 21 Feb 2023 12:16:51 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 40885383907A for ; Tue, 21 Feb 2023 12:04:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 40885383907A 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-x42f.google.com with SMTP id c5so4851331wrr.5 for ; Tue, 21 Feb 2023 04:04:27 -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=L6eAtmwzk72vX5Jk6XCvWsL8z4TEucBYbHfJ50Qccy0=; b=EB+6njacdB8nOmLFwt0N7JLtfLUi8DBrs/VwkvICob1IfcPzYyP3241FXuO4B2DLJr bASABH3qvIis8YTE8X75Kft7tluqtIpHcEjDlGw2TZaksYrQtpnwII57npaNgDUGvb8C 6guP7d4M4XfqRBv3CH4YEJhsbfyvuFyv57d0isLUwlgG4JJ6JyBoO5xHBHsrcBUk8jNF NqgvwLlbb6+PdsgzTb/kdtAIEqv67RMYd8gSIdBrSUCWJlu/YrNUd5zmcHatwCAy5tJi pnwWmVrtkz0BLOUILLn5WUfnGtDoXNI3vCZg+XZZARM4neSDV1Ng/W0qSe+9dAiPQeeH DeUw== 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=L6eAtmwzk72vX5Jk6XCvWsL8z4TEucBYbHfJ50Qccy0=; b=IyhFX9jSGIkFFjDVIU9v+A8xqggqfaoqwfKvmP4SAU6R/wQmAbx54ARZSB7b/Naxek jjaieq8tWtPZO1Qd965C5BlEna+3AqGVWCw3jnn8fK6MKXhkw31MHCgt0J08eb/gKhkx yrPxRAWeaewkEV/UdEZ1P8eGJQPGsvB+/7Ktv32BIj3c2NJUm5iB3Xy0fqhEODNFCPj9 puSZrasPFxINEoNtqsngVvDyjcBR9LBcQxbnRJEtQLCmDjCXKO6Y7DgJaL9ax6kd7BJg HDjJkx6UOUwFPtk5yAomWcSTlxzurKDwJ7NqVDn20AE2ldy941e7Rt7DFFcB00cFeZjO jfFA== X-Gm-Message-State: AO0yUKWCsEjT0/ytdLQt4HsQB5Koptla3PBRHyIoJN/9lkovHEELmlDa oqTkRw0/uHus/qe8lWr83IPEKIlXGnG7WhJTMg== X-Received: by 2002:adf:f450:0:b0:2bf:f4f7:be9c with SMTP id f16-20020adff450000000b002bff4f7be9cmr2330103wrp.14.1676981066665; Tue, 21 Feb 2023 04:04:26 -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.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:26 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 077/103] gccrs: ast: Dump never type Date: Tue, 21 Feb 2023 13:02:07 +0100 Message-Id: <20230221120230.596966-78-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.3 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?1758444968348173852?= X-GMAIL-MSGID: =?utf-8?q?1758444968348173852?= From: Jakub Dupak gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add missing never type visitor. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index e6d6e070709..3af4895269c 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1585,7 +1585,12 @@ Dump::visit (TupleType &) void Dump::visit (NeverType &) -{} +{ + // Syntax: + // ! + + stream << '!'; +} void Dump::visit (RawPointerType &type) From patchwork Tue Feb 21 12:02:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60066 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1847260wrn; Tue, 21 Feb 2023 05:00:56 -0800 (PST) X-Google-Smtp-Source: AK7set9X7wKR1BJB5piu+mbPAailH8NONzBEJbacM5DmuX4CsQSs9G5SA6lWfAEi5IzAStr3KH+I X-Received: by 2002:a17:906:d9cc:b0:8b1:304e:58a3 with SMTP id qk12-20020a170906d9cc00b008b1304e58a3mr11868543ejb.52.1676984456242; Tue, 21 Feb 2023 05:00:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984456; cv=none; d=google.com; s=arc-20160816; b=Df9Sg0jKz3ewM6lJl0AgAppj85n1Xmz/gSR/psgWEtcrNEo7VVKU3d/1zynn5uZUgA 1peDM+VfuucKrU3P4T5QBCfItSprcKEtBInBOeVdmx7odVUkYLGyJ2KFQ9/InCTh1kRu nl48TSquTqkQp4zJeStojIwskJ6ziNWBU4OFT9F6GQNDAwL2InQLOSeouRCgs+lkrYv/ XX2MLZ8SLeNfBt9ZhUctKPe/QTdTLwaA8dW1rSw5jYiLAAlEcupAaesPAJVTxRabjwPR CtkgNyES1PYf47/oBvdnp61n7evTUXPn8mfXuVMe9uzCqOh0K3iWXmzisuFAT2af3i+b vcSw== 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=WuI/LEae02cBMx2WrS3g0oXFB34DinFX7QBsPq6e16g=; b=vVRFZtQ5omxw3+wVoUSZ9YNlH6ZqPcBo4hU+4IpIVEMl1qu1UUiAEQMc2jaVMcGnei tMUBF2ciSsJmMpqRhLhmg+wF6/UCwM1//9QTJ5naiZVXjrqKjHZvXvHiatNx3gZfYWnY aaMkTPjdHjVQgKx4HHNRvpvnLy+GZNL2A6jSolrFV7+JIaZvTNsXuI3nEO6HDfI67rXr DVlTpklZL49E+XYK78NtScTCCPeKOhZW6JLa9kbE6cC0hTL8WW3v3TW33vvqZUnidml7 pzPpdHxgaYk6XwvMUIsP0vfEKlc+EE4X9a7k18nLGRqM7hT4/e9hBeAf89nIlYRZxtBd MtkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=PtNnwgKZ; 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 19-20020a17090602d300b008b17ac3edb4si17894507ejk.894.2023.02.21.05.00.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 05:00:56 -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=PtNnwgKZ; 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 EAEF23892B88 for ; Tue, 21 Feb 2023 12:21:36 +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 042DB3882F35 for ; Tue, 21 Feb 2023 12:04:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 042DB3882F35 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 t15so4269396wrz.7 for ; Tue, 21 Feb 2023 04:04:27 -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=WuI/LEae02cBMx2WrS3g0oXFB34DinFX7QBsPq6e16g=; b=PtNnwgKZr2zmjPWDk/5e0VN9+eWvmUYqApCGpWPVNOwiuLGutKNahTXEoTghCqWC2U NIRS+rAYQ4AFs4MBQEtJD/VUPbxBHWV89yBLOrHEMzZyyUlt4wJ+YxkPxvwRKsTjGHgh 1VwfW0QRwFhFagQgm037HVnNs9ZqpVTvdxto3zRzNOJZz4mTcAfavalOGq8lHh9kp2CV BbdBrILaImAoGTr0Qej052scE58ortdiIshIY3wrI75Gh7I8HhIGzXSXmxPZCM25etzw gA0nZEWON4lrYiLyHN+d8IFuiEILNa0zG/kPw0snI7KPwX8YobIw/2xYIdY4kxrfuVzX bERg== 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=WuI/LEae02cBMx2WrS3g0oXFB34DinFX7QBsPq6e16g=; b=elJT2bvl7Bi76oETEMjjiGZZMvkbBQnf4onxkySOc9TFMyZyCY/NtKULUKr9pAsTP/ YBs2g08cumvlU6s6fWCo/NPXVdTP6qxgT9nFhQOu53uto5lm7+ytMyITSFMzQvmAtjjy uXF0zkLM1sfC4RhsqUmhhtpGTCAgiEm3EEnzEKITfswVj9CfQdQkeGsF0q6iaWAI4sNi Xm4ZzWUPdtOOZpX335W9FWfUK51vX1qoyhGDo455+//y8jEBRRsSVUS+73657GiezUr+ nVVdEYT+yrXmMU9Lq08lNYwYxbNRxTqgdBSqAdazDCsftVKxDnmRCbN2W3nM+l+A8sfV 9SLg== X-Gm-Message-State: AO0yUKWbNOOuUh3GQAt0JaNNvRxveVqtekkQz2mGVGZiL/c7qTFNqut1 XMRkSLQADlqp/MDcxsgj3HWMxWYdfoL4S3Ts4A== X-Received: by 2002:a5d:474a:0:b0:2c5:52b7:8436 with SMTP id o10-20020a5d474a000000b002c552b78436mr4488467wrs.21.1676981067350; Tue, 21 Feb 2023 04:04: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.04.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:26 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 078/103] gccrs: ast: Dump tuple type Date: Tue, 21 Feb 2023 13:02:08 +0100 Message-Id: <20230221120230.596966-79-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=ham 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?1758445653421983042?= X-GMAIL-MSGID: =?utf-8?q?1758445653421983042?= From: Jakub Dupak gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add missing tuple type visitor. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 3af4895269c..9393f957aa2 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1580,16 +1580,24 @@ Dump::visit (TraitObjectTypeOneBound &) {} void -Dump::visit (TupleType &) -{} +Dump::visit (TupleType &type) +{ + // Syntax: + // ( ) + // | ( ( Type , )+ Type? ) + + stream << '('; + visit_items_joined_by_separator (type.get_elems (), ", "); + stream << ')'; +} void Dump::visit (NeverType &) { - // Syntax: - // ! + // Syntax: + // ! - stream << '!'; + stream << '!'; } void From patchwork Tue Feb 21 12:02:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60049 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1843396wrn; Tue, 21 Feb 2023 04:52:19 -0800 (PST) X-Google-Smtp-Source: AK7set983ZgIi18RrKi3/IiQRil2UJnaw2zkj9PSGNykCjaH9UA5xXcRqT6tM+A4G02HxtKJVU79 X-Received: by 2002:a17:906:35d5:b0:8b1:e791:faef with SMTP id p21-20020a17090635d500b008b1e791faefmr13068558ejb.67.1676983939157; Tue, 21 Feb 2023 04:52:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983939; cv=none; d=google.com; s=arc-20160816; b=VW9OVw3Q8fP2Qdk7cWFj3snNVCiQLoyXywdtHvZQMnRDYrnat9Y3PyRLpvdf7lAQaJ 4PVEf4dJZmwW3cKc0pMMwMr/UKADQkfHXnShBUXLeE80UHJ6WbXxmCIOu0R3R0N/rfGw OA49KlIIP1QxHPcOZN8/VnrqYG1QdvHNwfuFC0WuIQmSaCuF6TKPwhMGBnrjhpt4bWIJ YxAYuD02nfXWLDX+vsR+HRFGXBMf5y/ArUOlZ+ZD4Wyxr4d7IDGuqs/keoG+sJbWGg+b sCXq3NhKmHj0H2kP5Id9Rq4GyiAh8lZn1KQCNFWfyjchGC9R43OErUzKqS6EEu3rBgVK p4aQ== 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=fyKICt+4TiK9BChXFRyg7ODWF5w2yKwl7iEPs1xHLCk=; b=UJf2bJArdbK8zG0QKfWYQmtUlO/c0Snw1GCA8gc2yJspdrWO7/tt60gFcVAIxFgIQ7 8Ji2t2JAcTDhxVcFBWuTZVZJ4+NaS8JRCRAA/sBJpEDf99HRIlvBJwr3dN3/XuSVNnjL 3GgTC7rP8PwIJw0WbPHSlpb+O7rgXd5IAUMVxoUmt827MAdHSAPnrHgmfJn24GfUEYfX nd8HW4zkbBaPV42jmbJVOO/aeoMrHDyf5u4R06Bt5mkSDd6sbcmDJzMC/lQblvDeHwWS Z/evZoXtW5OUXOTW3I1tVfH8wus2ypUxlxZ1qO40i+3gBFWVcu22EEXUC7aUKR/zxCOw a5rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Mbjm1N91; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id um36-20020a170907cb2400b008777da65fc8si18139097ejc.781.2023.02.21.04.52.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:52:19 -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=Mbjm1N91; 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 8CE04396E01E for ; Tue, 21 Feb 2023 12:17:48 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id A689C38493CD for ; Tue, 21 Feb 2023 12:04:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A689C38493CD 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-x436.google.com with SMTP id c5so4851414wrr.5 for ; Tue, 21 Feb 2023 04:04: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=fyKICt+4TiK9BChXFRyg7ODWF5w2yKwl7iEPs1xHLCk=; b=Mbjm1N91br4u9D7D2GzemLlDIBnpfIq4eJO9a76WhokJdXwWcav4OYYKwuvu+TuFe5 fuKaOf6H5YfPYlF7rPBlUtcVPZE5zA4UH5cUAGpglQMY5VWtYVbkf+7lzyW36bgGvDja 9kUcpNMMl80iVyjnc7TssZxMog2uGtxRXYYQg8Fo4ooKWyMEFI5uV1UY41xlB9paASMU KJkXFg2iJBOBKXOEgjdnscUJ8ENmnv8f9plfA09jgvIQm85qh6wug/Ks3AOXgt0uEZ1v FhJ2xDqCBMFjdYYH+77AZP+IWL8GxUZ2AC+NJwVAn+zQ+MxOE+5VpY+rvtCXrsDaFXBy /Wcg== 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=fyKICt+4TiK9BChXFRyg7ODWF5w2yKwl7iEPs1xHLCk=; b=yIq+tlIsJxDwj/LedZRgpSeYQk9+oIyYvTiz17neZuXI/v5OF05gKrCVqKnqNQwQHH OEm2l6EdjXz+0Ri7M4zcj6QYx2tlJ7TUWtr+jmL8xDcRo7VsyY0NYDojuPRQfdlzw4X8 1XqJyNlaBw8HRZZgVPeUpQ4wpajm+CXpbxup9XXL43bAs9OLy9MQQ/7/rqVzsgc5IUtA E5BoBvvsm4y62ExuHM13JJhV6zAeHZ55yg7Y7AV1mPt29ibWvPP5+nUZGcfhR0eU/NVv MuKkrWNJLkuINFZpwzvHPCC4Gh1mb4EeSgvKMesC5pAhoTggpDpHK7XKKJGOWTFPtQU6 Ju1A== X-Gm-Message-State: AO0yUKWgNgB0sWN37Ad6+RrrwhoVNzz6ZHV75xn7ToPiQMKrAIydSvZy MGpu6z7BSreQQRRdH7Q+pHntcL/nWkPMitz10Q== X-Received: by 2002:a5d:654f:0:b0:2c5:4b93:ee44 with SMTP id z15-20020a5d654f000000b002c54b93ee44mr4582028wrv.60.1676981067986; Tue, 21 Feb 2023 04:04: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.04.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:27 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 079/103] gccrs: ast: Dump inferred type Date: Tue, 21 Feb 2023 13:02:09 +0100 Message-Id: <20230221120230.596966-80-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.3 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?1758445111086774252?= X-GMAIL-MSGID: =?utf-8?q?1758445111086774252?= From: Jakub Dupak gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add missing visitor. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 9393f957aa2..a37d5addbc4 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1661,6 +1661,9 @@ Dump::visit (SliceType &type) void Dump::visit (InferredType &) { + // Syntax: + // _ + stream << "_"; } From patchwork Tue Feb 21 12:02:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60043 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1842181wrn; Tue, 21 Feb 2023 04:49:32 -0800 (PST) X-Google-Smtp-Source: AK7set/PKu1z4DwflaJtswGUkebP2ciHp1cZH+/5CH+4m31T8U32povAr0uFkHmIvbrW5JXoZxIX X-Received: by 2002:a17:906:da0d:b0:8af:1a8c:eaa0 with SMTP id fi13-20020a170906da0d00b008af1a8ceaa0mr11195853ejb.75.1676983772510; Tue, 21 Feb 2023 04:49:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983772; cv=none; d=google.com; s=arc-20160816; b=NiXc31tdmmeS5dxon93ju29FsSFuq+egilgj5y1yZMNEceTak5aBWfzZMGGgmDZBGu 2P1sEX4gskd7xQeahnDuUuiPfSlH6Jbv4OGTMzo+DcFd55twqKPpPPAw7toRynrsODxt uxozfky5IDkzspRjVAWtjK60oSti8Gvt2mWvwlX8TN1S9t5m2AYB0TXLhbWUJWTDOPZK dAGiUVx/BZNeA9jyf0IXTKXC//H0koGQmllKbtNPcbOaTCI4DNlqdgorRFglWTksOoPc 5ev9nJA55OfROOCfHv9Ab6h6n6CUaW/5bqHHVs7gJBN+wb7uAFG+nkQWZC6aOPmqGS+d cY2g== 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=/oYp8jF2uc87zQ4BIwzSVGsJWwZZH6ku80iNX1kdNpQ=; b=QnqNHoHWwEDOCOE64R/sCp39pI/sekBPG9iOr+XPJsahkwyHwCsjdwJp4wlVjfdeEa ZVQaqqHkYL0WV+6K3I9ekFbYyr5SCQ6afdBICijppOir3+Pa5Ms59NVCt3hfMEbNsd1a 8TnG0XlBB2zLKjvGdtkfoMYN8f7B1qSkFM/I9uhgGhklS9PKAciJxqSW+fPoPelpBG3S mGCZMbosPVh9pPNgCA2a9g9PJz7a8dKmZ6GKXAgsG7rThkQ9/CilteDrepw8gvlBmH0N BdOT/cBhNlLLce+A95+wk0/mGquaOq1Ac5AKsWDnh6JBtqAB2TPJ9ZO7myMvk733FcJr HxQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=giQwnrqf; 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 15-20020a170906018f00b008ddf3c182fdsi3133124ejb.185.2023.02.21.04.49.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:49:32 -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=giQwnrqf; 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 A60013839063 for ; Tue, 21 Feb 2023 12:16:36 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 4BF69384FB48 for ; Tue, 21 Feb 2023 12:04:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4BF69384FB48 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 c12so4164844wrw.1 for ; Tue, 21 Feb 2023 04:04: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=/oYp8jF2uc87zQ4BIwzSVGsJWwZZH6ku80iNX1kdNpQ=; b=giQwnrqfvzvXr4kxMaVNHGwFuqrZpaIn5aVPiv+VRsnPmfmtnSA5Y5JEFmif+/QUzA 0JKt880IWcs41jfHFvZCcPhfI1IYUZ23K/qN/bDSouSuyICmHrtFYBPFZSopK2xQatar w9PKvPERDzIf+T4wEPob2yE9YlL2/FCWoj7lLULbHkCi3ap3qtb/iLeyhKSHCnFCAPrV 02xlX6QQKcyen0GXoe+NH0GJR7dJfd1vliyL012SYMKX7W3t4hKlb3k/1TKH6LQzI9Mo rip9Zin04y8G6915u+KIkW5RaTbwXoC+5vGldXeLYFjuXhbiXTNr2aBsF/UcMIJKWjPw hVfQ== 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=/oYp8jF2uc87zQ4BIwzSVGsJWwZZH6ku80iNX1kdNpQ=; b=JYTmkZq5e20w2BseL1WSX/8hK3T3sqKjXaLHXSrjBsTswd8YCexxPeKpw0PDPCsZoB MKvGTeTNXLr6gq4dL0SLT7GYs//VuJRWQ+Srj3Ieam2LKyuppwmHbtwnp1QXVlitdba2 h7PUyA3Z0NKC5XLaBqPg/NRbt6QzjBJZgVN/SzofM8BX++TusQfCrLWHzXonduutI41i cgIKWvz/HnOWmwEwqdYtnOA7YW0GNPIyjUKmNjxsvKzfSjWYFWeuqV6ZTW4A66yKYyY8 R3ngENTyg80+twIXysAHLZ8gGdPINZmxq+TwLP0H+XBJrl3jiGTxVAEvSlJimFm464Ks gocw== X-Gm-Message-State: AO0yUKWdvI7UBFmzf43njnM+1cHVPSmyqRwC4tqcy5mtzIvwCPQ2pn+W wRkAbHDAlDFRa98cyXv/C4A+VOUPBOpdnH/jXQ== X-Received: by 2002:a05:6000:1205:b0:2c7:454:cee3 with SMTP id e5-20020a056000120500b002c70454cee3mr1692700wrx.7.1676981068653; Tue, 21 Feb 2023 04:04:28 -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.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:28 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 080/103] gccrs: ast: Dump bare function type Date: Tue, 21 Feb 2023 13:02:10 +0100 Message-Id: <20230221120230.596966-81-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.3 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?1758444936163941067?= X-GMAIL-MSGID: =?utf-8?q?1758444936163941067?= From: Jakub Dupak + Return FunctionQualifiers as ref to work in ast dump gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add missing visitor. * ast/rust-ast-dump.h: Add missing getter declaration. * ast/rust-ast-full-test.cc (BareFunctionType::as_string): Fix bare function string representation. * ast/rust-type.h (class BareFunctionType): Declare said getter. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 94 +++++++++++++++++++++++++++++- gcc/rust/ast/rust-ast-dump.h | 2 + gcc/rust/ast/rust-ast-full-test.cc | 2 +- gcc/rust/ast/rust-type.h | 22 +++++-- 4 files changed, 111 insertions(+), 9 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index a37d5addbc4..5dae38ccef9 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -249,6 +249,56 @@ Dump::visit (std::vector &for_lifetimes) stream << "> "; } +void +Dump::visit (FunctionQualifiers &qualifiers) +{ + // Syntax: + // `const`? `async`? `unsafe`? (`extern` Abi?)? + // unsafe? (extern Abi?)? + + switch (qualifiers.get_const_status ()) + { + case NONE: + break; + case CONST_FN: + stream << "const "; + break; + case ASYNC_FN: + stream << "async "; + break; + } + + if (qualifiers.is_unsafe ()) + stream << "unsafe "; + if (qualifiers.is_extern ()) + { + stream << "extern "; + if (qualifiers.has_abi ()) + stream << "\"" << qualifiers.get_extern_abi () << "\" "; + } +} // namespace AST + +void +Dump::visit (MaybeNamedParam ¶m) +{ + // Syntax: + // OuterAttribute* ( ( IDENTIFIER | _ ) : )? Type + + visit_items_joined_by_separator (param.get_outer_attrs (), " "); + switch (param.get_param_kind ()) + { + case MaybeNamedParam::UNNAMED: + break; + case MaybeNamedParam::IDENTIFIER: + stream << " " << param.get_name () << ": "; + break; + case MaybeNamedParam::WILDCARD: + stream << " _: "; + break; + } + visit (param.get_type ()); +} + void Dump::visit (Token &tok) { @@ -1668,8 +1718,48 @@ Dump::visit (InferredType &) } void -Dump::visit (BareFunctionType &) -{} +Dump::visit (BareFunctionType &type) +{ + // Syntax: + // ForLifetimes? FunctionTypeQualifiers fn + // ( FunctionParametersMaybeNamedVariadic? ) BareFunctionReturnType? + // + // BareFunctionReturnType: + // -> TypeNoBounds + // + // FunctionParametersMaybeNamedVariadic : + // MaybeNamedFunctionParameters | MaybeNamedFunctionParametersVariadic + // + // MaybeNamedFunctionParameters : + // MaybeNamedParam ( , MaybeNamedParam )* ,? + // + // MaybeNamedFunctionParametersVariadic : + // ( MaybeNamedParam , )* MaybeNamedParam , OuterAttribute* ... + + if (type.has_for_lifetimes ()) + visit (type.get_for_lifetimes ()); + + visit (type.get_function_qualifiers ()); + + stream << "fn ("; + + visit_items_joined_by_separator (type.get_function_params (), ", "); + + if (type.is_variadic ()) + { + stream << ", "; + visit_items_joined_by_separator (type.get_variadic_attr (), " "); + stream << "..."; + } + + stream << ')'; + + if (type.has_return_type ()) + { + stream << " -> "; + visit (type.get_return_type ()); + } +} } // namespace AST } // namespace Rust diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h index 2bd3b31d09a..6c2f13c8c01 100644 --- a/gcc/rust/ast/rust-ast-dump.h +++ b/gcc/rust/ast/rust-ast-dump.h @@ -137,6 +137,8 @@ private: void visit (MacroRule &rule); void visit (WhereClause &rule); void visit (std::vector &for_lifetimes); + void visit (FunctionQualifiers &qualifiers); + void visit (MaybeNamedParam ¶m); // rust-ast.h void visit (Token &tok); diff --git a/gcc/rust/ast/rust-ast-full-test.cc b/gcc/rust/ast/rust-ast-full-test.cc index a4e059f1c0c..4f593dcbd49 100644 --- a/gcc/rust/ast/rust-ast-full-test.cc +++ b/gcc/rust/ast/rust-ast-full-test.cc @@ -3071,7 +3071,7 @@ BareFunctionType::as_string () const } str += "\n Is variadic: "; - if (is_variadic) + if (_is_variadic) str += "true"; else str += "false"; diff --git a/gcc/rust/ast/rust-type.h b/gcc/rust/ast/rust-type.h index 05a78956b57..efe59bd6f79 100644 --- a/gcc/rust/ast/rust-type.h +++ b/gcc/rust/ast/rust-type.h @@ -835,7 +835,7 @@ public: }; /* A function pointer type - can be created via coercion from function items and - * non- capturing closures. */ + * non-capturing closures. */ class BareFunctionType : public TypeNoBounds { // bool has_for_lifetimes; @@ -844,7 +844,7 @@ class BareFunctionType : public TypeNoBounds FunctionQualifiers function_qualifiers; std::vector params; - bool is_variadic; + bool _is_variadic; std::vector variadic_attrs; // bool has_return_type; @@ -860,6 +860,16 @@ public: // Whether the function has ForLifetimes. bool has_for_lifetimes () const { return !for_lifetimes.empty (); } + std::vector &get_for_lifetimes () { return for_lifetimes; } + + bool is_variadic () const { return _is_variadic; } + + std::vector &get_variadic_attr () { return variadic_attrs; }; + const std::vector &get_variadic_attr () const + { + return variadic_attrs; + }; + BareFunctionType (std::vector lifetime_params, FunctionQualifiers qualifiers, std::vector named_params, bool is_variadic, @@ -867,7 +877,7 @@ public: std::unique_ptr type, Location locus) : for_lifetimes (std::move (lifetime_params)), function_qualifiers (std::move (qualifiers)), - params (std::move (named_params)), is_variadic (is_variadic), + params (std::move (named_params)), _is_variadic (is_variadic), variadic_attrs (std::move (variadic_attrs)), return_type (std::move (type)), locus (locus) { @@ -879,7 +889,7 @@ public: BareFunctionType (BareFunctionType const &other) : for_lifetimes (other.for_lifetimes), function_qualifiers (other.function_qualifiers), params (other.params), - is_variadic (other.is_variadic), variadic_attrs (other.variadic_attrs), + _is_variadic (other._is_variadic), variadic_attrs (other.variadic_attrs), locus (other.locus) { // guard to prevent null dereference @@ -893,7 +903,7 @@ public: for_lifetimes = other.for_lifetimes; function_qualifiers = other.function_qualifiers; params = other.params; - is_variadic = other.is_variadic; + _is_variadic = other._is_variadic; variadic_attrs = other.variadic_attrs; locus = other.locus; @@ -930,7 +940,7 @@ public: return return_type; } - FunctionQualifiers get_function_qualifiers () { return function_qualifiers; } + FunctionQualifiers &get_function_qualifiers () { return function_qualifiers; } protected: /* Use covariance to implement clone function as returning this object rather From patchwork Tue Feb 21 12:02:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60068 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1848105wrn; Tue, 21 Feb 2023 05:02:03 -0800 (PST) X-Google-Smtp-Source: AK7set8RGowc55G+w/f+LCYGQiAdUG9o3QZmCv/PDUVyLk7b9wGDeGHEq350J3ZqlKMAssydtRK1 X-Received: by 2002:a17:906:aca:b0:8b1:7841:9f28 with SMTP id z10-20020a1709060aca00b008b178419f28mr15605019ejf.55.1676984523604; Tue, 21 Feb 2023 05:02:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984523; cv=none; d=google.com; s=arc-20160816; b=OHFbMPr6oFPkRI8TPJwo2t6udUZuLKU1tbTT/NbsVkf5bBVD2unGbERnFC2E/ju6sI pWmoWSxe2IgO51VbYPiCg5YpFEAgV1uWa72bIW4HVHTe1qGgyylqX8Jj4ajtgCMsUjfE wfnjfTbrP9SNHx0Y2L7fYlOsS3IkzGMfv3Xf9zUSebgcydZws0mHKUKgntjFhT6+wdK2 g4XBrEnijxYgsjrSwAI6hhV5kOACLPqpkwZx26NfztGi2e4aPGM/yYM7s32GcFV4FGVB XmwSYh8FdI+t+wHP++J3cc3UcAPSRfFNtQB4e8GS8M1F86MJx5wnwUuxffXZL4uzWiws 4qFg== 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=qdCYpkb54/RnBEDqNm47/juLUw1FDchgfwQ1zLU/Tuc=; b=ajlNyeOBQS7IqDAJhCYnajYBq9W40tX6qOPRggLJHkBsSRmajFE39L9A1rmjfsUMp+ Zi0N2ZcSa3GCUxumx6BWmkBsaobtCCgc/jG/Hq1aMH8IW99i00Ay3QW6r9V9AkkMQSTK aVJj7Xnjh1aJOjZOwS4ZTGh/cAF1xURzs/t2isW10Cy0EapnzAXw7cGNEqWAuDWioPz2 UTPTB4rPZ4qOe396IBwZO8p/jOkGc9AGRt8PJkGe4xXoJ4KTp0RDaT6nceRPusObWIon 20NjMtpsKaqIY+HVctJ93tp1jLHfjIiPG8xtCD3FmbVWfIKYUf7f/0qNTg8Ka4ibyg/y /5bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Av1TGpmP; 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 z14-20020a17090674ce00b008c72577b130si11221667ejl.636.2023.02.21.05.02.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 05:02:03 -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=Av1TGpmP; 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 F068E3A1BCD5 for ; Tue, 21 Feb 2023 12:22:08 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id DA079384FB66 for ; Tue, 21 Feb 2023 12:04:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DA079384FB66 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-x436.google.com with SMTP id o4so4166424wrs.4 for ; Tue, 21 Feb 2023 04:04: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=qdCYpkb54/RnBEDqNm47/juLUw1FDchgfwQ1zLU/Tuc=; b=Av1TGpmPEtqVwy9CWBjJN4H8caN3z1M9dNSGKAMYbLpp8tSLIPtUHiaoKAV18V0AaW QIP5nEzbIi1f9cuwNXUFTI6t4WYx7JSlWErpU7NFH2Ofw4iFR2Rhuac5V0f3tOC4/2S9 CiW3pktYWz56vCERtijMCWi9rD72YC7Ime8KgmdxRn0rZI1aau5ORiwlONXS6kYqQWU/ 1Y2AbPuBiD7+IJF+zKsn1zLhiMrBJ3xKWE4xEj1EPMMrTFelWBjpkQhInlNOKNm2MqPT lDfARCEjswOsV057IvUL6gUVq88EIHaFdx4SK72q3i8Qx4e+GG/e/Hntt/4hUd93eNhn 8lNA== 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=qdCYpkb54/RnBEDqNm47/juLUw1FDchgfwQ1zLU/Tuc=; b=02oq/qpOr25V8C+9dlrlA0ZoIp9d+tgLzh/Ppyo1hIqLSY0NjpS1QcXv3YTFSo57L7 W6KDcTCBN5L5C683TGO1tHsheJZHak+BZkae5kLlWIhbH/YeZtTKudfe2hDjOH1XXFmJ onSWFp/Dfek2m2WdxvtrLIPn5MveiFOQXaWFBe7O5qTWHPguWIVbL+qkohcne5Yyd4VW tMWGPQ52jYAC4KXDVvqSwpOu92UyeYst/mKYITtZQy5dUAA9UMthKO5gUDP0W0fHMvlA 6dbSV2MybucD4rqBWf4xtR35yOD6Dsf3zGBIn5lLTm9iZruAxjHNauRL1SaqB6xN+BRJ y7fw== X-Gm-Message-State: AO0yUKUx0Id6/fywSBw32cPPIwAdSV+/kxVAScHZNfqEttHsyhZ+GkOT Eyu3nILzBtJHKdMmvFatNGk/o67TSCTMEvgx8Q== X-Received: by 2002:a5d:5651:0:b0:2c3:f78f:518f with SMTP id j17-20020a5d5651000000b002c3f78f518fmr4035915wrw.39.1676981069274; Tue, 21 Feb 2023 04:04:29 -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.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:28 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 081/103] gccrs: ast: Dump impl trait type one bound Date: Tue, 21 Feb 2023 13:02:11 +0100 Message-Id: <20230221120230.596966-82-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=ham 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?1758445723717179275?= X-GMAIL-MSGID: =?utf-8?q?1758445723717179275?= From: Jakub Dupak gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add missing visitor. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 5dae38ccef9..2f01c72460d 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1622,8 +1622,14 @@ Dump::visit (ParenthesisedType &) {} void -Dump::visit (ImplTraitTypeOneBound &) -{} +Dump::visit (ImplTraitTypeOneBound &type) +{ + // Syntax: + // impl TraitBound + + stream << "impl "; + visit (type.get_trait_bound()); +} void Dump::visit (TraitObjectTypeOneBound &) From patchwork Tue Feb 21 12:02:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60037 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1840427wrn; Tue, 21 Feb 2023 04:45:35 -0800 (PST) X-Google-Smtp-Source: AK7set+EdRI87pbdxlu7xt9cWzaz56HKFIMsJlc2b76ZM5k4Ot5/SrHZvr+d9BEqZbzMRvtMVQFS X-Received: by 2002:aa7:df96:0:b0:49d:a60f:7827 with SMTP id b22-20020aa7df96000000b0049da60f7827mr5737683edy.6.1676983535311; Tue, 21 Feb 2023 04:45:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983535; cv=none; d=google.com; s=arc-20160816; b=BqZErrcz74u37dNWvq9ALEzRAg1RngzSh4GszewJkVgxAB3OjKhSjP/oNW4g6g25j9 iO0Z2S4CvvLD3+b73Qdv9KoWeXvLyXHjEt9kMUg78M2VcJ7UgWrQ6RJPMoCUJsx5i693 x1/Vg07M3ro2F3kR+0AN/WagdGg1AlL+SVJqGZvTepEGapgm8aUOZjYmdMLwA/rduap1 AvGYhYo/CdnEBQjglOo1zj0nAYeBbHwgyADhNgmXKXiMuf+py0xsIl8s2iWiDlvfK0SO cgM8BDNR514M74qVt/HbCh5mKmzzrDLtgdVn32ykv2i+NXi1DzQ6R5vK1W5f1j4DgAD6 Xe8g== 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=VOk2Xu6mBSLrtumJymSQAz7FVVO2sV3sj4WhdTfRGLQ=; b=DKQBIGRQMNqYMfY68yuyUBoGEBH9F2ol6/XP07Ka/00COtCfrn41LGEoFM0tr72mxk LdULYN9csS5bP9tuilMHHlt4/otIafuzkk7GY9Dlyx1jgNQJ1QH4T61QAJFJq2tdzkSc iyO2Zlj6bYrTL7VEv9plfGjt9XUDJiltQcse/S5ehFIXkBinDAH7FyFZoaadR7+UyAA3 TOV0D3/aM5oP7TVxq5D8RQc9FsbE/n2w+zBZfzBTa0SEfNcfSM46RwLHwgmXKFPfHuDW wF9bqCCg7AIhLR6hU7xZ1k7KruSE0E2zcPFyl8y3+JJPfwOeuFEzL3Mkx7rb4UM/jgyz xn8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=ej27rcQp; 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 ca27-20020aa7cd7b000000b004acd0b5ba4dsi5298802edb.67.2023.02.21.04.45.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:45:35 -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=ej27rcQp; 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 A81463A22E69 for ; Tue, 21 Feb 2023 12:15:15 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id 79B9C3836EAD for ; Tue, 21 Feb 2023 12:04:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 79B9C3836EAD 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-x431.google.com with SMTP id j2so3984311wrh.9 for ; Tue, 21 Feb 2023 04:04:30 -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=VOk2Xu6mBSLrtumJymSQAz7FVVO2sV3sj4WhdTfRGLQ=; b=ej27rcQphzQQ/1uBuyWD88pT+atZfLp0EJ1FusCD9bQ/oPeNtCcGDsZl83Bni4MXZS JZ/Rzz0SWZqt20cCaeafFZ+jehie213xW/t9135j6Ws1UDhBxjbDFFRCYY5WQnGjVGC0 absRAywTau99EAiKYJX9rjL1Slc8SuCR80uoBrvEhruQqgucTj1s0xjgvwxbsssUtXHE azxJzR8L8X34QnSqotdwgxj0nX6jYwxyqZqmMXDckG4ETsNRv8XWkIrFPgiilM4Dg6KD F0tbCTVMRZ4xntWQnnY1G0iOFmtrFYga37rLDMX6dTDNAZWLtQ2/b8k3xuG5HF+Mhcxr U1zw== 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=VOk2Xu6mBSLrtumJymSQAz7FVVO2sV3sj4WhdTfRGLQ=; b=Nl9/YORX03LFrGwQtDof9zQPtmcd2M3CdLx9K8DyiHEFA3PODPWhLH4UUDSM8mFxXM f7b3a+jRCaNPDKbFsHCePp8DPhHavCrI0DVuTjYiqUWi3hypNsoS9hHwOIsm8/zf0HZd a3FjznZGHmNpJRinOjvDLUh1Z6/RkYgLcuNdI7bKUPEItQ8QDuKfM0AHcntKoDP92h1J qKJEL727D8lkCzmu98AnAcjOhtjeuXuotzN2Z23eA797XT2aJ2nxM4RBzK5HSobMe1JP WFW++RGlGh4oZs5apxqHq17TBL56F/Z080ETwFHJREZ08o8KPBPhj0AVrk0aLEH3nzB0 rv4Q== X-Gm-Message-State: AO0yUKXoDQgM9Uc8SLDe+d4S/uM8t29iLnkK2LT2BZ4n0QWRSjr78Zy6 LmrOm93TM+W8zttgprp+IhooVdI+itY41QyMmQ== X-Received: by 2002:adf:f303:0:b0:2c5:5f9e:b0 with SMTP id i3-20020adff303000000b002c55f9e00b0mr2395558wro.8.1676981069864; Tue, 21 Feb 2023 04:04:29 -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.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:29 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 082/103] gccrs: ast: Dump impl trait type Date: Tue, 21 Feb 2023 13:02:12 +0100 Message-Id: <20230221120230.596966-83-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.3 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?1758444687801442332?= X-GMAIL-MSGID: =?utf-8?q?1758444687801442332?= From: Jakub Dupak gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add missing visitor. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 2f01c72460d..1d593d4b749 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1610,8 +1610,16 @@ Dump::visit (TraitBound &bound) } void -Dump::visit (ImplTraitType &) -{} +Dump::visit (ImplTraitType &type) +{ + // Syntax: + // impl TypeParamBounds + // TypeParamBounds : + // TypeParamBound ( + TypeParamBound )* +? + + stream << "impl "; + visit_items_joined_by_separator(type.get_type_param_bounds (), " + "); +} void Dump::visit (TraitObjectType &) From patchwork Tue Feb 21 12:02:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60041 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1841401wrn; Tue, 21 Feb 2023 04:47:43 -0800 (PST) X-Google-Smtp-Source: AK7set8jyFn0QojUmryYKJCoRir8ztdiOap8o5vCI07hF1KFxsKSzLoHedJRVRCZDorwIIql9fZs X-Received: by 2002:aa7:d957:0:b0:4ad:316:b4d9 with SMTP id l23-20020aa7d957000000b004ad0316b4d9mr4828603eds.15.1676983663479; Tue, 21 Feb 2023 04:47:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983663; cv=none; d=google.com; s=arc-20160816; b=VtwKYNELhOmCV5LIuaA8f9u2hfmYLs3siFwptwBcjnri2WP+Ul3kgCdWYjM0FlfmjA ppyVnyJAFSEJz8xqeSsFPIh7S+fxAcBRBrw5t+Omdcb4FKxlf6FcKp7Cwj8WGmMhRQiB NnRHwKQ3u/yi+NLZkNY8dSmS1aSxmrScFAXYYcSJTyA16tEYA5auas2n+0zpoPR2uyI4 4psuZzMkY4zaTRlsxfBOpFDzC4cmmbFVbpLOQVy6pphR3d5RMsn8MqYvmJu6cC8qLGB9 +c975hddi/nMqt1qhxK/966n3JFLNv39Wzx15AwUVpBK2y3O27pbgKPULhS4PiSJ38Ip DSkw== 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=h/qxXb9N6bCVFSsK37WzwVzLis52VTRBgIBGk8Rh1AI=; b=SaK0XqPbQVgj0VetORDcMftj0vrNGu5w4i6b1vnOnT5nGGLenndVA6fXvQUhQApITG txueAFW/W1evAN/8D6nFPrV+ZKJXx5nwi/yN2ineYLFxzX5QmRPLp707W233qeZmpMPu dZ7iI4nP45Q8h9L2PPNZIZGn4QeLsgEI9C5mp2fnw0ekFlpJus/y925tBPWsO6Z6g855 aMdbmFAoRclS5TTFLgu1UqSBMMasRE27SKHgBq1qPDxFOR5RxObEsBAnE0+jMCTgPxE2 BkFzslb2h5saC0CUYha8lfr9X6j/CSsR/8nj0WUwahlRSio2I/o4jNoh8WOpnMALppuJ yKtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b="R2pp5/BR"; 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 o25-20020a056402039900b004acb480f45dsi3598515edv.263.2023.02.21.04.47.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:47:43 -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="R2pp5/BR"; 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 AE6C2392EA9F for ; Tue, 21 Feb 2023 12:15:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id 26AFA382E6A2 for ; Tue, 21 Feb 2023 12:04:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 26AFA382E6A2 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-x433.google.com with SMTP id p8so4292458wrt.12 for ; Tue, 21 Feb 2023 04:04:31 -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=h/qxXb9N6bCVFSsK37WzwVzLis52VTRBgIBGk8Rh1AI=; b=R2pp5/BR5fKno7bEWSPPVxh9r2CJUU7GGR/YvZOWvQwHdj6s1IfRastGwBWUwf9AjH cr+MCqZ689hrKNbgA3yXzVT4lJX7ctZoQdUt4Dl//x7k86STbDfV3j5m8GoMk1YxQHfQ y+YNRLRf1Wlt+f7JtiVPq2orAVTbejDcf5eVmMm4rc1h0ZKPEOJXxJj0TyG6yGMYDuac J0mR4gunDa1iEkCjKAxRYwFsD3Ron8VXjG8PGNBcBxzXjChYQl57BUd4JR57LRJJ/5oP MnmXdECy5MPXnYqQewG7o7LZrfCXhI1UiyEhqCgHchvT/AJ1hfS54S/KGOYwyK+e+r4u 5bbw== 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=h/qxXb9N6bCVFSsK37WzwVzLis52VTRBgIBGk8Rh1AI=; b=EfZh7AzaUcgW45Mboqj/bUGI0qx4hM66j1XubeLKGwohaA/VkvVey3+eYFyAnEjsba TeLfXkICZWlQu9iG7Ic64nShA7LF9dCg6PRpY0fDAFuwlX9MfwU4XEhgnRzq93J+l00B N49exUjozOTnfdBoe9xwRsSSQW9ApWdkjVtexXz0UVGURKKfQEHVS0nfAxiy43ABk/32 qna6cHL4e6KP5cH6ITOFLX+kkS7BgHUcf+sbMncKrKeGI8LImZcroacp5fQsFU0Na+cm tYVzxFPmZyZSvxwXpjVcJC05Qrrm8yGhgYIblYpoHVwZSsJkKYf4FV6jPgne2t8BOI/3 D7jQ== X-Gm-Message-State: AO0yUKUYOny8AGAhrvoXY+RAiqa56pi0eocO3Ar+5bDC9poJCapXtlQX g73fTin/j/rre+9VrMrH5r/QzyJukmL7BjaLAA== X-Received: by 2002:adf:de04:0:b0:2c5:56f7:51f0 with SMTP id b4-20020adfde04000000b002c556f751f0mr2459058wrm.49.1676981070463; Tue, 21 Feb 2023 04:04:30 -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.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:30 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 083/103] gccrs: ast: Dump trait object type Date: Tue, 21 Feb 2023 13:02:13 +0100 Message-Id: <20230221120230.596966-84-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=ham 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?1758444822030500640?= X-GMAIL-MSGID: =?utf-8?q?1758444822030500640?= From: Jakub Dupak gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add missing visitor. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 1d593d4b749..0ae57fdb744 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1618,12 +1618,21 @@ Dump::visit (ImplTraitType &type) // TypeParamBound ( + TypeParamBound )* +? stream << "impl "; - visit_items_joined_by_separator(type.get_type_param_bounds (), " + "); + visit_items_joined_by_separator (type.get_type_param_bounds (), " + "); } void -Dump::visit (TraitObjectType &) -{} +Dump::visit (TraitObjectType &type) +{ + // Syntax: + // dyn? TypeParamBounds + // TypeParamBounds : + // TypeParamBound ( + TypeParamBound )* +? + + if (type.is_dyn ()) + stream << "dyn "; + visit_items_joined_by_separator (type.get_type_param_bounds (), " + "); +} void Dump::visit (ParenthesisedType &) @@ -1636,7 +1645,7 @@ Dump::visit (ImplTraitTypeOneBound &type) // impl TraitBound stream << "impl "; - visit (type.get_trait_bound()); + visit (type.get_trait_bound ()); } void From patchwork Tue Feb 21 12:02:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60053 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1844282wrn; Tue, 21 Feb 2023 04:54:19 -0800 (PST) X-Google-Smtp-Source: AK7set9gJmSghi+pghf1wsBE7a6oGpHwa/TyI7NmOQUdox8LgLj476v9xG5fnvDbJ/oGQOJvbaCw X-Received: by 2002:a17:906:e13:b0:8b1:2614:fbf2 with SMTP id l19-20020a1709060e1300b008b12614fbf2mr11017916eji.70.1676984059408; Tue, 21 Feb 2023 04:54:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984059; cv=none; d=google.com; s=arc-20160816; b=tcRlSLO91/VgHeUieryeB/iA1QpqeS+/PMYkX58pyKDSAI3aDay8EKzSO14mzsrHmM DwaFphjN2ZqDX+T6GAmyIvxtUaMPv7R/UALyooEjqZm+rSaFn70VESUcRHd0k3XBIFWT qtsGVq0IalRrt5/826GhxZVUdiVxH7NpVNKHY4Q/52Ja5Ek8zK+q8cZL9yOcuS+ECSoW IUKvCeYjzxSJxngyiCN9cEzHxcUmKxZuQwS5YWrKndi37cogB7HpNgDbI0JKdJ4XEfBB 0paOJ2NFOuiwlYTwRrpijhkx5HjybAdi93nH4Z0uLtu/5sk7siQvCUEOParl/n0GO2OZ rVNA== 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=FbkBr8HUI03AQU6DkJSzu7FnPK+Fx3xW1Ff+amG6vdI=; b=N1fT30tSRZwmTSFtz7fKdgnIV19FkrcPwoDMVeCbgaCMW2SHRAY/3Vxj+Esdhgy/Zv gH2xo/wo8DQ6syuexcquW+gDtDlNqFlhorGuKKVNNxZ3XmCayBH841I3bL5vBw8YggLX xlJB+NSrtN8WeIYluw3HLGz9oHu/DqLUQ3bAimscS7sbgiGKVmmwEgvD6vejMzqN+MNq I58akBhzcncVh7OAjIb1CIbZzZDtTH0v6p78XXNSEDtuH57jH0CXvW8ieA84GfZd0QRx 9EXcnO7qlh0pzptnsnRZJOhk+/grBVzz9I1GWgehua8r/mGMtWNiindH7uzTgc6PR3LF OUOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=ZfDVzQTX; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id v18-20020aa7cd52000000b004acdd3b83d2si18312006edw.14.2023.02.21.04.54.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:54:19 -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=ZfDVzQTX; 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 5AD8C395BC7D for ; Tue, 21 Feb 2023 12:18:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id BEED13851405 for ; Tue, 21 Feb 2023 12:04:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BEED13851405 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-x430.google.com with SMTP id t13so4091190wrv.13 for ; Tue, 21 Feb 2023 04:04:31 -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=FbkBr8HUI03AQU6DkJSzu7FnPK+Fx3xW1Ff+amG6vdI=; b=ZfDVzQTXezWAVpzFIA2Jpcm/I5uk1D/xD2cCPAAsF86SaYy2gb3pVJGCM7fJOsfKRx qKyeRghPyFcMI/EP0jTOQwzqdyhi+JMp1qANrF8hZgP8YiT+/Rpwsntp+F4ncJbKMPek d2wJLs68okXXkRwhpRxt6EksWMekR+++oOXWyfHd3jj6XKUi93i8SN9ClfS6ShLQN+0L ssmlVCDQ1vOke1FhTyFRC4pT7eIOhUXDeCbvhXDF3QoDfZU0/mX4Np78PvbpQmPEXKZO w6KSPvccUF9V8ITVBI1LzWNYFpoXjeIa2JluDQFH9scZ9P61v83xA8QwxxgrUC0KrXhI /Z3A== 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=FbkBr8HUI03AQU6DkJSzu7FnPK+Fx3xW1Ff+amG6vdI=; b=a3EBoi911mwWl5CcTgtLyL80582/frvigXKTAeFuyR0xN8G1q8/G/zDO+drBRFPivm 7jFLVeeWGQ4miOLlOR2IoDmusER6MbDJmnzySnlXiUyt0GqiPhd5DSVs1oOiU3sICQMv KRTedQTyDbVPm/KsG0SnlQkmqNlu+UiKBtMOpRDOCff40P8163hMua74yWkptryXaDlY pUBQjmVclfhu6zkOnXVRJFlprgQlHyjLG1pKfII69cInpN4+OItWCQM1+KmDUUubKx3Y Gpn4UFpCZcowgTg4tf5YlVOnTCun7xspdJeZ5DfmMDTJX1p9cMdaWyey4eI1vYfbd/hM 3bXg== X-Gm-Message-State: AO0yUKU+/xMPESFzQNbS7aCPWxv9N3RfGHR9eUK0pA20jJ+RjQb+oR1x XgjSkLVPUKUucLDwJG/lIlsI0YwbQEbVj2Ymbg== X-Received: by 2002:a5d:6acd:0:b0:2c5:7c55:501b with SMTP id u13-20020a5d6acd000000b002c57c55501bmr3698170wrw.26.1676981071130; Tue, 21 Feb 2023 04:04:31 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:30 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 084/103] gccrs: ast: Dump parenthesised type Date: Tue, 21 Feb 2023 13:02:14 +0100 Message-Id: <20230221120230.596966-85-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.3 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?1758445237505201274?= X-GMAIL-MSGID: =?utf-8?q?1758445237505201274?= From: Jakub Dupak gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add missing visitor. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 0ae57fdb744..8e06bf38a6a 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1635,8 +1635,15 @@ Dump::visit (TraitObjectType &type) } void -Dump::visit (ParenthesisedType &) -{} +Dump::visit (ParenthesisedType &type) +{ + // Syntax: + // ( Type ) + + stream << "("; + visit (type.get_type_in_parens ()); + stream << ")"; +} void Dump::visit (ImplTraitTypeOneBound &type) From patchwork Tue Feb 21 12:02:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60044 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1842209wrn; Tue, 21 Feb 2023 04:49:36 -0800 (PST) X-Google-Smtp-Source: AK7set+A5BtPalEKUmaS+4Ty94bo/jU2UOuN0yiMau97K+sN0bK0J+80MSXJCXiGRFAM/qukG5Iw X-Received: by 2002:aa7:d6c1:0:b0:4ac:b2c8:aeac with SMTP id x1-20020aa7d6c1000000b004acb2c8aeacmr4881219edr.40.1676983776521; Tue, 21 Feb 2023 04:49:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983776; cv=none; d=google.com; s=arc-20160816; b=TGEjUJHy/Q+RQGoo01ee6hZKc4/5Z1NJgH58Ujftg1xWsRyLWxNhxuqtA99Cp5nexl 76iEdd4hzZG11Fvugk+V/lauCnDgoJe6N03w9ywJAOVUdDwkR11gQ+ctrtgshgLj4krX h+eX0gG+8f3Hl+TjOGS56kImCMYcwWAT7IjyoHD4CQcMdUpC7euQvHddDCDZNtUd44Z9 SrpFQ50d25IZYoVAEj/avamndpf74V4KedP53K2VPnFVu5wbiqT3X8tz1L5AQgYFpuqg zodW0ZwFmg6GQjic120T4tIYKk7kacba87heCPTKgKFnS3p/1Vrd1Yr8KyGU1Ixm/qzB mDAw== 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=7n4qdLuOaMxwsGF1Vz5HNRRVSSn5HYSuES4ZbSs1CNI=; b=obfiizdZBsvYRJiZwDDMOsmI0iddKWzrFKDQ5sPd51mHrn4M4N9d9UdDi1rt81EGfV o88nmGVDUi7p4x7z3ZLF2h5fi4/ky7uHnmQ8t5u4hB9H40+coWZ+DL9leHgDJfdHGPRw 8vTDSar4zzcDNL2GvaTyYAcpQAZ0oZYcRBbQefPVSrR53n0RL3rWoWwVVxJ9bw3zJ80J trlKqDHF6QT8+yT5XsIHBrs79BycikJZPGx54Nnf/apGnc96iZ4Gkd6+vjluhkbMCVnX LMMZ5zq51Ard+md5YUAXwsSUmPAaZE/vHQ+seef+75YybxbWeSqfQKVX9+/GCmx5QM+G oRGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b="PT+EY/Pi"; 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 x7-20020aa7d387000000b004ab4bb74439si1288690edq.411.2023.02.21.04.49.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:49:36 -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="PT+EY/Pi"; 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 CE8BC396F9CC for ; Tue, 21 Feb 2023 12:16:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 664BC3884526 for ; Tue, 21 Feb 2023 12:04:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 664BC3884526 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-x436.google.com with SMTP id j2so3984420wrh.9 for ; Tue, 21 Feb 2023 04:04:32 -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=7n4qdLuOaMxwsGF1Vz5HNRRVSSn5HYSuES4ZbSs1CNI=; b=PT+EY/PiV/WpxR5+awUH2Dl4nh5K9FJ/cmYDstA6iLs7wDKxC8TNKcn58aGfxA7H5b K3HscjvRfNUoRHdSZclqjlvaB+SKdYi49aG9NWcub01QLwXhFPl5uGKdS1osuI8ZPPN5 7RXm/2kZ2WX/x+VlNST+4EZgJ8NRbH4RodiaNDaE8pZvQdEycceDIeyLeM+f4dtToKGC BeMQiJSUgsfVkFE8i+pX1BFjLqnBJ5JllUhJsfP47EJwbTnjMWiDrOsdt3BcuwuXEBOL CZwEHxrn6NbwBItwdDDnt+JrVTAIkvVjjvVNHZDOEeZK5E4b9U9jytjLDQQZ2cebpHlo +xAA== 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=7n4qdLuOaMxwsGF1Vz5HNRRVSSn5HYSuES4ZbSs1CNI=; b=51bdsuO2sv1yO0HWSM0TY2jJyRlwYGiixPoPCQ/7QzYijlTQ1MS4Jx3ReUkNVhYn1E gqL8uImXmxWxFyetUR7FARv1d/Kwm+gMqpBSTa+cANjXygFBShMHnb4naByslB73C9vk pZgoiu/YPnqujrwG7bT26sq3WRWAYgKNnjDaJQnBYsxNUhGSYiLAmrPQbyHMzxeIjQYL MPeRTkr/Kdv+PSpkyE/pbV8COHF+96+fFCmyHjExxyS66//iAEM0hhJwXSlj7xgwct8y 0u1eEEJ/0cVgeN2/gLBdq6mCJEvN8QtbEJrmgFcKueiJrMJt4nuh+jC5wNSHxyVBa/0D Jzig== X-Gm-Message-State: AO0yUKUMUlRNCYjIgsimsRrNSWZvY85RbJCYlncGlpO/HdCntABX3HD4 y8p2udMWTqZuTMJADVArs1ZbSwc6EVUFDlcMig== X-Received: by 2002:a5d:678a:0:b0:2c5:594d:d9f7 with SMTP id v10-20020a5d678a000000b002c5594dd9f7mr4076921wru.63.1676981071770; Tue, 21 Feb 2023 04:04:31 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:31 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 085/103] gccrs: ast: Dump trait object type one bound Date: Tue, 21 Feb 2023 13:02:15 +0100 Message-Id: <20230221120230.596966-86-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.3 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?1758444940474010275?= X-GMAIL-MSGID: =?utf-8?q?1758444940474010275?= From: Jakub Dupak gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add missing visitor. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 8e06bf38a6a..7d62571b778 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1656,8 +1656,15 @@ Dump::visit (ImplTraitTypeOneBound &type) } void -Dump::visit (TraitObjectTypeOneBound &) -{} +Dump::visit (TraitObjectTypeOneBound &type) +{ + // Syntax: + // dyn? TraitBound + + if (type.is_dyn ()) + stream << "dyn "; + visit(type.get_trait_bound()); +} void Dump::visit (TupleType &type) From patchwork Tue Feb 21 12:02:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60057 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1845226wrn; Tue, 21 Feb 2023 04:56:31 -0800 (PST) X-Google-Smtp-Source: AK7set9QG/vzFogkjoSSl2MbEPD/WLdF6YUV72KuQsDDSNyawPc/08MEkYhCVIi3X99f7I89d7Al X-Received: by 2002:a05:6402:1012:b0:4ac:c12b:8ef1 with SMTP id c18-20020a056402101200b004acc12b8ef1mr5408175edu.17.1676984191381; Tue, 21 Feb 2023 04:56:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984191; cv=none; d=google.com; s=arc-20160816; b=UU8m7HSTTqFom5/cI+nBiKdDDkaix7BRPYGYtP16io4yH8YJaj/92AtrjbEIst1bXl tB6COmgdO9Jceoqaf0EoNjQITSrCwc1MVHMlx9VvfotS4/UsiofevBxvKWknx6a+aun0 Lmq1+4ZGGNYh0XrBgUlcaSfaRheMfAvH3LesvFOwynSgB8Q1VTafGRct4bAlhfcwS0Yo v+aUjpEdztz/JB3EWBfsLj3Nze7gu7XFttVjEx3vqNJwQA89TM3TmVW5h9PvhbFiiN4k MYDlMGX9WtVvtoeNgSTUFEqN7UnrKwksbp39K/tJvxPp0mob3F63ILJKXcuZrsdjrwb7 M47Q== 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=3rXwqVcU6PweinMQaeTHlbgL76U7nK1bDRHb738wDlU=; b=CxOD7NSORlNCzCqqQzfpoiKhIeBim8rJ+hqLDRRZMoa5Hzd5CU4RJZI1sMZDYbVvU5 /ZCCL3ff8hz1fxkwsCAAMhn9OU6gmSeSvU1YUyOLIhjRxlpYRbIXNnsEwyF79gErhJPw acmojrC54yRt++vDi+2nH/9cLSptZJG+vfCFn0fwRUJc+I2FGQq+QeBZhSMnodPH4emP 2AhrLWd7mr9bnV3T6pxNNxj5Med6ck+0XRk2u/nzO2QlxRuyn4yg/Wl47VgcjOLkwzBk PJNVYE0aDW5mRffWuVzCejKlGxRxlk05O22TvLUmN8DxZDnaYc5rrVtxjJJjqRzOT5ah JMpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=DbQ795Uv; 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 v14-20020aa7cd4e000000b004ab498f69c4si9452578edw.242.2023.02.21.04.56.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:56:31 -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=DbQ795Uv; 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 BF6A3383FDDA for ; Tue, 21 Feb 2023 12:19:36 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id E62C9382CD6A for ; Tue, 21 Feb 2023 12:04:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E62C9382CD6A 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-x32d.google.com with SMTP id m14-20020a7bce0e000000b003e00c739ce4so2889696wmc.5 for ; Tue, 21 Feb 2023 04:04:33 -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=3rXwqVcU6PweinMQaeTHlbgL76U7nK1bDRHb738wDlU=; b=DbQ795UvI/gfLjUAUB36HXtc5zCvYFUCQX5GS6UhmiVbeu5rcFIC7izZC0+RvJlJh5 Mts8f72iCYLrClRj7kKzVcAVypRUg7Qb/u2Wy/O/MCNi9KhUBRI2swnJ34qX17nZANgO YiyAnqGVXIYJED9HFInmrbj/2komgtqZeM4LKiUqsdeT04cF/SRDR/lImFmXR09lSKBX kTrfNT2x3fBEii9yzfB4FkRw2Yj1ajhdOIax3pdvCpsm3XWTdqm3liSLZlpCH1m+YGuY n/Va8e7GoneAtFO+eNbhav/yBcsbP6TMihkWZVJ5dJNlLVlG2w1bMqnB5nYTdo5io4F9 Qqzw== 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=3rXwqVcU6PweinMQaeTHlbgL76U7nK1bDRHb738wDlU=; b=QfnOfVgpyCOGB2ZDMwTfpvL/hk1kpS+TP8vSmSlR8CDe/k5L8a0g31pbq+aZUGOsaS rv8Vx00Wrfq72q4hPv9ziDeUSAL9lDkmbABueqTxy7da1I+cR73R1WJIqD0uUtiCoVwM bRtDEktwSfXpVEAtE8I5zutNHIE54SFeM/CJU4bxgITCB8mO2dHdEF9GoUNZ8fSO7ghH kTYkBZ3/PFQ5UeaJ5QSbKQqVQTKYfDAdKSMKZDYwPW4Kbr2oFZpamcPxS8iXCR+mvpUZ nRQvJ2Ay0nyRd1mcQ4j87Fwb7hJI4d08UjjhQ8w3wEeqrcTKWheffY5//1+J05gxZtyl l/dQ== X-Gm-Message-State: AO0yUKXrZQnbF2h6L2c8NpJUmJ/uJa6Ua49meafM9JzU+CQh6+FVGhG7 wNT8fL5LVB7VL7be8GuwIri9+LroDgJNR7uG3Q== X-Received: by 2002:a05:600c:2e93:b0:3e1:f8af:8ef1 with SMTP id p19-20020a05600c2e9300b003e1f8af8ef1mr2762643wmn.22.1676981072505; Tue, 21 Feb 2023 04:04:32 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:32 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 086/103] gccrs: ast: Dump type param type Date: Tue, 21 Feb 2023 13:02:16 +0100 Message-Id: <20230221120230.596966-87-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.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 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?1758445375136935371?= X-GMAIL-MSGID: =?utf-8?q?1758445375136935371?= From: Jakub Dupak gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add missing visitor. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 7d62571b778..216f0a43dc3 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -892,7 +892,19 @@ Dump::visit (AsyncBlockExpr &) void Dump::visit (TypeParam ¶m) { + // Syntax: + // IDENTIFIER( : TypeParamBounds? )? ( = Type )? + // TypeParamBounds : + // TypeParamBound ( + TypeParamBound )* +? + + // FIXME this outputs things like "Ambiguous: String" - this comes from + // Token::str stream << param.get_type_representation (); + if (param.has_type_param_bounds ()) + { + stream << ": "; + visit_items_joined_by_separator (param.get_type_param_bounds (), " + "); + } if (param.has_type ()) { stream << " = "; @@ -1663,7 +1675,7 @@ Dump::visit (TraitObjectTypeOneBound &type) if (type.is_dyn ()) stream << "dyn "; - visit(type.get_trait_bound()); + visit (type.get_trait_bound ()); } void From patchwork Tue Feb 21 12:02:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60071 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1848883wrn; Tue, 21 Feb 2023 05:03:12 -0800 (PST) X-Google-Smtp-Source: AK7set9mgdmHX78hrZFnOGhJBSt3odXaF9ZH41pKkQfYAx3B+S5vOBu6/IePOfqMe6WROUZJbvCK X-Received: by 2002:a17:906:f4f:b0:8b1:2d35:2264 with SMTP id h15-20020a1709060f4f00b008b12d352264mr13911820ejj.73.1676984592722; Tue, 21 Feb 2023 05:03:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984592; cv=none; d=google.com; s=arc-20160816; b=Tp3nVfpUD4TZJZZ8TRPFvmli5jYr1xJFpf1SgtLVtvqYwGi4NaIpJ6tHjpl1BrKoW7 MwzQS0OuCjF+F4sQ7v859coDn2JZg1LL/+Rv3EOQAkmSn6xks6sorNwFDK3P6o/EDfMf va2i/qWojLsDLaqkOPVsxNAOEjLX32gShiA9fL5awRPB8g0bLpm5s7tXguCoEOvCZFRV jFyZpaZPWXZjBWdngFLaBKODVtCS2DM/HhfSRL28PGuKQd6bl53wCugygQ9bXw3yssHE mf3PqG7i2XyXyH8w+iErpRf6nqP3/FejP5jGSqYuJ0AWrn/00ehn8LczvaQdSMHUDoRV LI4g== 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=80461fre8+hQ0zMopblsV380dH0N+AStk+XMfdir8cY=; b=bKXaJmUKTvmqMH45FS2haMsdV4pl1mp+9iSxjMcPPrX6IMXf4uhMtqsBELL+PkN1sa GZ0RhLTKRxnbAY61dizWB7JQgWVbFjJWoLgTDqnakj37TceFgKi7ejYyYpIS+lTc48ab Od7Xm+lHcz/PNo0QpwbSLjaI/nsus6IDj+LEnrPZt+5sYC0zE0ytosUM/ZKfJNqVYPCd I/Hv/W6Py7OwnvqsqfqrU494qZrXsnRuWKf2Rzzs9di6NuxdpMxc1fXtZVBCmKJIjtXs fvMPEgDlALIMnhLNLjavHg1P4SAhvF1pQzGV3zaz90wg/NVF5OvNbOngF3ZbCtzIER9k O+KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Ab23yKxH; 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 cm3-20020a170907938300b008cf2b9f412csi6432870ejc.67.2023.02.21.05.03.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 05:03:12 -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=Ab23yKxH; 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 34A8F3902A51 for ; Tue, 21 Feb 2023 12:22:43 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id CBEAF382CD63 for ; Tue, 21 Feb 2023 12:04:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CBEAF382CD63 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-x430.google.com with SMTP id z8so3885694wrm.8 for ; Tue, 21 Feb 2023 04:04:33 -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=80461fre8+hQ0zMopblsV380dH0N+AStk+XMfdir8cY=; b=Ab23yKxHbZ+wd7dUuVAYJgm8UQA5Fm909Cyj5qth6UFHyDJfvGViDLD7X3FiPCsL2D gjwtyd9b2miICMxGIv5RomNgY3uuNfy1Wz5vriXngXsIQbu8QhrhQsOaiBzmlB+Hy5fY stPawowJnbOTck8NqwDzSoh0TzztMmiOpcVk0cbY3Exql0P1Y5D8Yp0OUQ/xd4RWon6v hlg0ZT61yJ6Nw0FUs3Jme+lePueyx04RqudNTPBpc+O28TNpOd0yR59dx0cIUkajtwN3 L9MtVN3J5eaKW6ogXVgdfMch3+DitRFOyrQPesHLaU3L90rgmUzA5vHujNIaVyvga8VG QY7w== 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=80461fre8+hQ0zMopblsV380dH0N+AStk+XMfdir8cY=; b=MWq6suAV/B7E3cLm0Ymy9zQnXb9y4DFCzAs6bD1WhUnEefi6SNe7H8NxIakJHOdDn1 sMZikiSi5L74Qu7K/K8i5oP61+7/2NEl9MtpwZFiI4HZmIncZc4hzaIWN+bHurvBRPrX fOZANeXfEi37gFZwvkvRBwmbe8AzmGnvoN3eNm2Iw+yc/4qd+WWraDe3AKGu/eNgFEFk d5F+8nkzrsDH/S9tJ7FczGYz73su09X5VaEQE64yoRE/nJHWZK7JRpAuxMu7pMT3CegJ y1yvFdfFVsL9Q1Y+pzChVkFEGz5ORnM61zO6OqmWD5JtLX9baq0LsaITPgfmNgpR3iOA XcSg== X-Gm-Message-State: AO0yUKVy+HtuuIJ72f73Db8xHSMTaHW+s9IZdbeEcLJ0eBUsZ+Y99Hz+ VKbap/UUuQ/DT2u+jwM1lRSp3qRC/qyGqKeiTQ== X-Received: by 2002:adf:fdce:0:b0:2c5:5ff8:6b01 with SMTP id i14-20020adffdce000000b002c55ff86b01mr4996763wrs.1.1676981073168; Tue, 21 Feb 2023 04:04:33 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:32 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 087/103] gccrs: ast: Dump generic parameters Date: Tue, 21 Feb 2023 13:02:17 +0100 Message-Id: <20230221120230.596966-88-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.3 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?1758445796327637854?= X-GMAIL-MSGID: =?utf-8?q?1758445796327637854?= From: Jakub Dupak gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add missing visitor. * ast/rust-ast-dump.h: Likewise. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 129 +++++++++++++++++++++++++++++++--- gcc/rust/ast/rust-ast-dump.h | 3 + 2 files changed, 123 insertions(+), 9 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 216f0a43dc3..03a57d416c4 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -372,21 +372,134 @@ Dump::visit (PathInExpression &path) } void -Dump::visit (TypePathSegment &) -{} +Dump::visit (TypePathSegment &segment) +{ + // Syntax: + // PathIdentSegment + + stream << segment.get_ident_segment ().as_string (); +} void -Dump::visit (TypePathSegmentGeneric &) -{} +Dump::visit (TypePathSegmentGeneric &segment) +{ + // Syntax: + // PathIdentSegment `::`? (GenericArgs)? + // GenericArgs : + // `<` `>` + // | `<` ( GenericArg `,` )* GenericArg `,`? `>` + + stream << segment.get_ident_segment ().as_string (); + + if (segment.get_separating_scope_resolution ()) + stream << "::"; + + stream << "<"; + + { + // Here we join 3 lists (each possibly empty) with a separator. + + auto &lifetime_args = segment.get_generic_args ().get_lifetime_args (); + auto &generic_args = segment.get_generic_args ().get_generic_args (); + auto &binding_args = segment.get_generic_args ().get_binding_args (); + + visit_items_joined_by_separator (lifetime_args, ", "); + if (!lifetime_args.empty () + && (!generic_args.empty () || !binding_args.empty ())) + { + // Insert separator if some items have been already emitted and some + // more are to be emitted from any of the following collections. + stream << ", "; + } + visit_items_joined_by_separator (generic_args, ", "); + if (!generic_args.empty () && !binding_args.empty ()) + { + // Insert separator if some item vas emitted from the previous + // collection and more are to be emitted from the last. + stream << ", "; + } + visit_items_joined_by_separator (binding_args, ", "); + } + + stream << ">"; +} void -Dump::visit (TypePathSegmentFunction &) -{} +Dump::visit (GenericArgsBinding &binding) +{ + // Syntax: + // IDENTIFIER `=` Type + + stream << binding.get_identifier () << " << "; + visit (binding.get_type ()); +} + +void +Dump::visit (GenericArg &arg) +{ + // `GenericArg` implements `accept_vis` but it is not useful for this case as + // it ignores unresolved cases (`Kind::Either`). + + switch (arg.get_kind ()) + { + case GenericArg::Kind::Const: + visit (arg.get_expression ()); + break; + case GenericArg::Kind::Type: + visit (arg.get_type ()); + break; + case GenericArg::Kind::Either: + stream << arg.get_path (); + break; + case GenericArg::Kind::Error: + gcc_unreachable (); + } +} // namespace AST + +void +Dump::visit (TypePathSegmentFunction &segment) +{ + // Syntax: + // PathIdentSegment `::`? (TypePathFn)? + + stream << segment.get_ident_segment ().as_string (); + + if (segment.get_separating_scope_resolution ()) + stream << "::"; + + if (!segment.is_ident_only ()) + visit (segment.get_type_path_function ()); +} + +void +Dump::visit (TypePathFunction &type_path_fn) +{ + // Syntax: + // `(` TypePathFnInputs? `)` (`->` Type)? + // TypePathFnInputs : + // Type (`,` Type)* `,`? + + stream << '('; + if (type_path_fn.has_inputs ()) + visit_items_joined_by_separator (type_path_fn.get_params (), ", "); + stream << ')'; + + if (type_path_fn.has_return_type ()) + { + stream << "->"; + visit (type_path_fn.get_return_type ()); + } +} void Dump::visit (TypePath &path) { - stream << path.as_string (); + // Syntax: + // `::`? TypePathSegment (`::` TypePathSegment)* + + if (path.has_opening_scope_resolution_op ()) + stream << "::"; + visit_items_joined_by_separator (path.get_segments (), "::"); } void @@ -897,8 +1010,6 @@ Dump::visit (TypeParam ¶m) // TypeParamBounds : // TypeParamBound ( + TypeParamBound )* +? - // FIXME this outputs things like "Ambiguous: String" - this comes from - // Token::str stream << param.get_type_representation (); if (param.has_type_param_bounds ()) { diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h index 6c2f13c8c01..4bc322cda98 100644 --- a/gcc/rust/ast/rust-ast-dump.h +++ b/gcc/rust/ast/rust-ast-dump.h @@ -139,6 +139,9 @@ private: void visit (std::vector &for_lifetimes); void visit (FunctionQualifiers &qualifiers); void visit (MaybeNamedParam ¶m); + void visit (TypePathFunction &type_path_fn); + void visit (GenericArgsBinding &binding); + void visit (GenericArg &arg); // rust-ast.h void visit (Token &tok); From patchwork Tue Feb 21 12:02:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60074 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1849383wrn; Tue, 21 Feb 2023 05:03:57 -0800 (PST) X-Google-Smtp-Source: AK7set/MNyeZGh16Baoez3sCPMbo/gESO0++56UwgwxoQbuPBfu82HjvV/QmZqo76I9mq+pBI3HQ X-Received: by 2002:aa7:c317:0:b0:4ac:b6b2:1233 with SMTP id l23-20020aa7c317000000b004acb6b21233mr4729358edq.30.1676984636986; Tue, 21 Feb 2023 05:03:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984636; cv=none; d=google.com; s=arc-20160816; b=XEHdxQMWXqjtbRgnrw0XJ9xmTUvW9ZlzfoI8EzhgaklX9jvNoG4phP1cJVlzsnsHdv 7BtIFhW+t1rYZ1XwSxxWYc15TZAMFiM7QR0cn8/8gstwou5s5YMBQI+Ibm1HKPjrOdKZ ZiLQMB2LDXvW+SKBXdIWwXs8aPTOeG7QErc8SieSjGzNikBW6sWJ2Rqj4yj1sIVFsbUt Q85Wd5E5zVrVDc2mpWu2EJcGi6LhDzuPRTIk/2+sgD36iNqrSfsJV8zHlAuwwtuX3Du7 +uLZB3PtyzulHMN1fgWqLEXzdaI5HSDjGHQulu4EqzKUS5ASBPngtfPbdoX+85wifikM Snkg== 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=XVJh6RdfPKwdhNeKpADf0ZoOlbV4+FDBVthHSaPMMcU=; b=rqUjCDXdwK2dds4rjgju1+xFrVTeVGdk39pNESS023UBtVE0DkXH4pYLYmCL3VpB7a khj2FrkoAkFSgqd2Xub5344UHnaW2Ci0j91nQ+fqDH5bcliZV+B/P9qgUvlduhoiOFRf 5Hv5ulbjXqDQ+RVArBs7JijGbVHOOw6E9bjzmZk0gsDVtN7CL0Kr9ITUY/rGSAbObhC9 hd32Wxopg7hDuhHruyGLu1UacpK39k+xX7waG0I6DEHBZgZ067f9SH1InQI7dSgm55ip jvlKoPkXSYFEF75W1i40fXVaT9sZReEYFc8E2RnzFvsvBuTbPw0pbG4mxAGBDFHfnKbI KKyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=CFBdUGKh; 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 p12-20020aa7d30c000000b004ad1256d8e3si9791096edq.51.2023.02.21.05.03.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 05:03:56 -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=CFBdUGKh; 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 B95CA382FDB9 for ; Tue, 21 Feb 2023 12:23:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id 2C7D3385559E for ; Tue, 21 Feb 2023 12:04:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2C7D3385559E 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-x434.google.com with SMTP id t13so4091323wrv.13 for ; Tue, 21 Feb 2023 04:04:34 -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=XVJh6RdfPKwdhNeKpADf0ZoOlbV4+FDBVthHSaPMMcU=; b=CFBdUGKhf16w3Y2KBX0VSAnBe6uQi3rPp+dsYOAwFi5/CApSeLrc0seznnFetPmLEd oy+7QY3oaXIJgnikdryw8Y56lr02KRBxZvcSaqDyxJe71L36rgGE8HxLqsU1OSecP3fd SbcZx3mPvg3alkiQEIgef1/6YirwC1wkUZR4ZbG33c+w6l9kadrxIl7psFKqkTG8Wc+t X2JaTc/mWK8vMq7MZFb79pieUUX7tEG3owipPKdErUYhn0syo8mP46bagNrypLrPSZ8E gH4rg1Yq3sHWwXKlrNwQrmWj7hLi44w3CBahRe5PDmy2aKpAFha5mH1KNXJVw5pdhG+H G6aw== 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=XVJh6RdfPKwdhNeKpADf0ZoOlbV4+FDBVthHSaPMMcU=; b=SyVrTjkycBerPG/hlNsO21CF6+Cmj6Jl6aNGEYLBUTk5HomLzPCLXkatBYu8lkm39D wDfJSedvUgXkPR78+jJ1Dij25lTyYzjz6YBOB+XIEQZLkappXuBVsvdzNPD0Dg1AaSzk N+tAxigN7Lbt+1A2AP4S+RZzvOEDXRP+D2zfWUoq+3gkmNYCnrxbuTELMYTSCqOZSSwX 7WTH7+LedUPW9czHyKTEkWObaq99j2QdBZqnqzWTCX4KxMQQOnxsV9BtFZ0jCSHgbSvB 9W96HmUJx56xkQfEuM8eZ7JXUebNV/4HHNCD+1FP47Gfp0kxLUsPN0Zdse1pngYdA6zT XdVQ== X-Gm-Message-State: AO0yUKUGrpajeLTA/cZ4E9wqkFjhb3jnLGSwabV0aKTUMYHFrb2TVbj9 d3tztwTe2PPOkjxdrBND8wqGWoD/8R6Nn/sGSQ== X-Received: by 2002:a5d:4cce:0:b0:2c5:5d18:ae1c with SMTP id c14-20020a5d4cce000000b002c55d18ae1cmr3288610wrt.31.1676981073935; Tue, 21 Feb 2023 04:04:33 -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.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:33 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 088/103] gccrs: ast: Remove unused include in rust-ast-dump.cc Date: Tue, 21 Feb 2023 13:02:18 +0100 Message-Id: <20230221120230.596966-89-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.3 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?1758445842939982598?= X-GMAIL-MSGID: =?utf-8?q?1758445842939982598?= From: Jakub Dupak gcc/rust/ChangeLog: * ast/rust-ast-dump.cc: Remove unused include. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 03a57d416c4..477805f19f3 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -17,7 +17,6 @@ // . #include "rust-ast-dump.h" -#include "rust-diagnostics.h" namespace Rust { namespace AST { From patchwork Tue Feb 21 12:02:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60059 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1845979wrn; Tue, 21 Feb 2023 04:58:08 -0800 (PST) X-Google-Smtp-Source: AK7set+FV7yGbmyqCN7zvdcc7AcvYnOUduo+dcvb55RXCdWSSno0MVoMmWUIQbepmqqdg11ZQlLy X-Received: by 2002:a17:907:2083:b0:8c7:f906:7fa8 with SMTP id pv3-20020a170907208300b008c7f9067fa8mr9276336ejb.38.1676984287954; Tue, 21 Feb 2023 04:58:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984287; cv=none; d=google.com; s=arc-20160816; b=NQiNQ/VhY+02vLRp1ivyJ0CuLWiz+HKDKQSCDw6fN6mfnXHrlUjZfOkp53XCwWCz86 rDAyaSxpkB/WLE1h6C7XNj7TDA7zoh+aOcZpXYxXw6r12hBhzLAbHhbLMBQ34XTrD9KL fPrX5FpYUWrvPTmbVWFm2aa+JuMHK/ES51gVTC8VFU/FMl3+2wPMDQYYj/aULhpbgQGy 9VaJ5qLeftLce8VUNJQwBT0kZTK69ZOc2bWDY8OmWr3ubI6jcGkYuFxQWe/1PD9MnSjj /jW2A/vhGNITGg1WbkY+gCE7pUQcfSnQcok5N97WwUu2x4dK3SvOt7iT9UrsFUvbVGMD 5jdQ== 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=uNF69TeQfZwK3+gJXrdNYVOhitZxnMt9bvlsdADDK9Q=; b=EA3IcAy1dRrIHthERQIm+RIUa1y+Zp+LQXEK7i1wcLgj5eSd/pFy7GE2ybbZqDaHQl YQkGrsBybvIvTSsGq2eB7Iqfh+qbNoyUCj7SyXFtNNWegbJ4I6hiTvPw13sKNkoC0mkn jGw2nmRjEZfvn7tv8WxvEDplAMvDMbXRr4mDG69HVZ2jMCbBDgrwHn9qzdUrAG7CZxsR e8vjk0nE3Nra/uvag86OYfYuIaWENzmxKFy3ag6nKQKGo3vDJsl4t2O9FW9slQMnj2KA 0t+U6ppg2SDDPiA75ICjIhy+iM1qptDhng2155F51aXtI63S6BSQaBBbT6Q3bFLQ1Gx/ dWkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=VEZ5M+Qi; 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 ay6-20020a170907900600b008cab1ae71e4si7977175ejc.818.2023.02.21.04.58.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:58:07 -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=VEZ5M+Qi; 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 EDAD73844741 for ; Tue, 21 Feb 2023 12:20:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 30A5138560A6 for ; Tue, 21 Feb 2023 12:04:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 30A5138560A6 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-x432.google.com with SMTP id bo30so3604485wrb.0 for ; Tue, 21 Feb 2023 04:04:35 -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=uNF69TeQfZwK3+gJXrdNYVOhitZxnMt9bvlsdADDK9Q=; b=VEZ5M+Qig76cDY8TwLg3hLTrk1d4/9xzCPjZtxcl0Wxq1q1woAKRw1LVvXfaaqhb+q 5RkUgu6BO9bJ0V4rY6qnvtBaKG/k6jvooDGzuXy7TWgQJiKYG3K4DoIudb1t+KCMG+gF 1eR8rxaEZcVYgnAbT8VRaH/yYt2ivCsHruQl5TtRQ3ofeU32sLevZvJAUethogn9F2a1 ZV2ewyiEnYWXW+M8EdChHnw1MGgX7IsyIuQQsEWYJHuJKov5WMjzpzrBfIbIBZmT4dht HdfxgEoCEzaTS2CkUdzbHJONMaO6gWYrVuBFANPhKokCeNGkyf1iSx+mEnidF+cLVgxS sKgw== 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=uNF69TeQfZwK3+gJXrdNYVOhitZxnMt9bvlsdADDK9Q=; b=8N++Mu7o46wwEWYWNypJpSChYX7CpSiFI2uTQ1zDWxwpMUGMQJxjBKdcjq9swxb+TE knIGqCnTMxJ0wXgkEQYNR9mpoD3BTCOwKwP0p91QOgS1uxV0GN3+M6M9kP4RnxvSxEN9 kt3hQymkN8vgwvNYckNLQXBNWfEWGwnS5PeFfNBFAgS4YWXKI3G2TA4+UOYpZQplcV8Y cnZLJtEdFU3luhp7gyfj/yDGDmEe0W2LR4+zXcgsDhqQaAmzRKxDyy2VV90GyUEZ7NFg x45YNuUePud9g5CQ6R42THKg0D9azpKRnHC36gzwjnHpa1JKGY5lUfxENJZqfHPMWyBt xSdA== X-Gm-Message-State: AO0yUKWk/Eb9jsnfD2O0VaH2I1tFjy3IPuUCFY55WmUbBPAFuufG7ENW zs6FXliBaGETgjzxlb/OmCuUpq1Rr3e2ukuEiw== X-Received: by 2002:a5d:5912:0:b0:2c5:58aa:35cb with SMTP id v18-20020a5d5912000000b002c558aa35cbmr4409639wrd.47.1676981074607; Tue, 21 Feb 2023 04:04:34 -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.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:34 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 089/103] gccrs: ast: Dump remove /* stmp */ comment to not clutter the dump Date: Tue, 21 Feb 2023 13:02:19 +0100 Message-Id: <20230221120230.596966-90-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=ham 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?1758445476533379174?= X-GMAIL-MSGID: =?utf-8?q?1758445476533379174?= From: Jakub Dupak gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Remove extraneous string when dumping statements. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 477805f19f3..9ec847c4f88 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -848,7 +848,7 @@ Dump::visit (BlockExpr &expr) stream << "{\n"; indentation.increment (); - visit_items_as_lines (expr.get_statements (), "; /* stmt */"); + visit_items_as_lines (expr.get_statements (), ";"); if (expr.has_tail_expr ()) visit_as_line (expr.get_tail_expr (), " /* tail expr */\n"); @@ -1205,7 +1205,6 @@ Dump::visit (TypeAlias &type_alias) visit (type_alias.get_where_clause ()); stream << " = "; visit (type_alias.get_type_aliased ()); - stream << ";\n"; } void From patchwork Tue Feb 21 12:02:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60047 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1843004wrn; Tue, 21 Feb 2023 04:51:28 -0800 (PST) X-Google-Smtp-Source: AK7set8ix5xxzgSLdfoSYEXeaeJH0VIm3dbf3giMFK/t/oHe9KYS/4Xcbgi+1XctamhuG9s7Jl7t X-Received: by 2002:a17:907:ea2:b0:888:b764:54e5 with SMTP id ho34-20020a1709070ea200b00888b76454e5mr14975839ejc.71.1676983888341; Tue, 21 Feb 2023 04:51:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983888; cv=none; d=google.com; s=arc-20160816; b=VeDvwT16Gsp2nKTMM93zRLn4xbpqTqUPFMM53wlXpaxiczKAvIdolf8DqyLIyTCjpz LWQgF+R8goozGDrafmDECgU1iOLlcfR7aP2wDjpSvRkiEb5j6nuUM/M/gZss3QEgOg8y enR4D/s1JjK7tAZyr6kHiZpO0VWiGRp6N9LLWaoU/qyn0xorDgjTONwJK1W8wvN0hhY1 I4EikchY6/s5lb1UOF+F/BNIuNDX5eDmeypTUDhHwSSHbCdZVACXeiVSIqagXlYrIA9e qtyijzSYFm/l1vBEhGDgA/VfcXVpl4l8c4QvIwlRLP3R8ZL/SLuJpoVlLJ8pd+LrgDQG TGNg== 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=RSRHZ03BQ36Dt52wUxwJi3sQlRkWpPDw6hAvKXoCZyc=; b=mRT1nhTYnirRAvAIigoKtR6x4a7XFqyzQeZcuAnwoPPa3aRwu8M3ntVPeUgkiNseMU juCZdKht8JdGuAXxdvikH4yT5pH6kIZseSbRK+uwvMNuwU+kd1346WIojb1x2GK7K2Tw OnfchLc5GoHyWaQDD/m/VBDDS4c0BihFAPrFm8NGxP6ZjHn6m3NfHFQI56PejyUNqop/ UnC339lwpyojJtI70bnQU+IoUvF4Se/ezkp1eymZ9LR4rxcWa6ZePlyONCgDjCvQTJKz Gc8KFL76dBCQRQa1TY/V4I5MwMQez6mPx/X0oot6ofBU/aACHg+++tvTOZQlYU+c/3TB y3Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=BJHLZjXX; 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 12-20020a17090600cc00b008dcebb5a0fasi3529588eji.944.2023.02.21.04.51.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:51:28 -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=BJHLZjXX; 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 D2B0E38E814B for ; Tue, 21 Feb 2023 12:17:25 +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 DCC4B38323DE for ; Tue, 21 Feb 2023 12:04:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DCC4B38323DE 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 z8so3885795wrm.8 for ; Tue, 21 Feb 2023 04:04:35 -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=RSRHZ03BQ36Dt52wUxwJi3sQlRkWpPDw6hAvKXoCZyc=; b=BJHLZjXX+Eu1KagaPGGQTh3N1kr9GP3jTQwmgViHbnnZfPSdg70OpxYdzAG03EiMQY 8X7so19NEYvIxnlq/ZIHfgGgdCml7LraAYhrHmEnZ+qZXD7AVBvUm0yfxCpLeD6wnfFT d4kgXe25R96wI1GXKrf7HIcI3XKmslFNtlaoxKcx6xSlEVEUQj8cV3ejoT9nFf/xHZNa Pdnn8R/lfwrzx6eYvmcY/JI5HNwr/kf9YL6m3RectXh2XDFu2IyugzmOxqcnWv4iBogf 4j6AOy8yGX4Mv8lV9w42EDVCqJwjHGvp0uvKgN5dyHKpGzzm3VoMK2nLHGv4Nyu6WVs/ 9naA== 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=RSRHZ03BQ36Dt52wUxwJi3sQlRkWpPDw6hAvKXoCZyc=; b=KxO+hWfpKn/dpJho9qBw+hn+gCQZlQOr/3wREvMqn7z4HbZXd/3YxoPK3WrzPH6QhR jQLOtug5sOlKQCL3AyLr1+6AMVP77hQwNdF/p09DfFqlrU/ugdE2KRX0eeRvztLyA0Qa DpEfWu8l0nc7NytB/lepbKAUnT5PpIiu8r67LQZcSs50OTd9qYnG+HIFMWN04VF56Gzb g83cr/11j7O9eUIGKks6CMwzulG98vYj0uChkTW3JvvtEhPgYoHrTmJdenGcnv8Am56L 7vj8BXTqOwRNNABOZUAHSWZ2IrxeI4ofUFNyfM7ez8gepd/jNK+ec0by1jAtKEZn7RTs xNVQ== X-Gm-Message-State: AO0yUKV6+iQy2d+ID5/wH21xbCP0LVcplLFjeXDiQAT8tViUlqTWhzry iPE3kiU1PqdVv4GBgRT/y8OlikhW8xg1wSx7Ug== X-Received: by 2002:a5d:4149:0:b0:2c4:695:d644 with SMTP id c9-20020a5d4149000000b002c40695d644mr4043107wrq.9.1676981075301; Tue, 21 Feb 2023 04:04:35 -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.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:34 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 090/103] gccrs: ast: Dump no comma after self in fn params if it is the last one Date: Tue, 21 Feb 2023 13:02:20 +0100 Message-Id: <20230221120230.596966-91-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=ham 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?1758445057347181250?= X-GMAIL-MSGID: =?utf-8?q?1758445057347181250?= From: Jakub Dupak gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Fix dumping of fn params. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 9ec847c4f88..131e23ea180 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1077,8 +1077,12 @@ Dump::visit (Method &method) visit (method.get_visibility ()); stream << "fn " << method.get_method_name () << '('; - stream << method.get_self_param ().as_string () << ", "; - visit_items_joined_by_separator (method.get_function_params (), ", "); + stream << method.get_self_param ().as_string (); + if (!method.get_function_params ().empty ()) + { + stream << ", "; + visit_items_joined_by_separator (method.get_function_params (), ", "); + } stream << ") "; @@ -1343,9 +1347,13 @@ Dump::visit (TraitItemMethod &item) // emit_visibility (method.get_visibility ()); stream << "fn " << method.get_identifier () << '('; - stream << method.get_self_param ().as_string () << ", "; + stream << method.get_self_param ().as_string (); - visit_items_joined_by_separator (method.get_function_params (), ", "); + if (!method.get_function_params ().empty ()) + { + stream << ", "; + visit_items_joined_by_separator (method.get_function_params (), ", "); + } stream << ") "; From patchwork Tue Feb 21 12:02:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60062 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1846530wrn; Tue, 21 Feb 2023 04:59:29 -0800 (PST) X-Google-Smtp-Source: AK7set/UYzEt7hNEzGfuL1L7oghoc4pRRabLFlE9A1xIBOGP8sC4UFqfibaYKjp4Z9ZpNolEcWBL X-Received: by 2002:a17:907:7628:b0:8b1:7daf:6285 with SMTP id jy8-20020a170907762800b008b17daf6285mr14180006ejc.35.1676984369575; Tue, 21 Feb 2023 04:59:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984369; cv=none; d=google.com; s=arc-20160816; b=OMlvhKB2Qub4ZsW81fAoYC+2AemOHNRR6vS8y5l35PZGlo2OuPks/HlDpJlBNW8aEI npI3x2XEwKmuDiOz3hRsc+0B3CTjrTj8KqXV3mMZKAvuS3PI3Ac/618z22Ykw1sGHO2M EM/XmYE77JJgaF8ofAofSXBDvxSNvsvQ8GadiO2CUnGU0421LWHfd8gNQnLAQlOZ2IGX g+4GFikvFjCRBdgXk0+Ze0cgBrnfUn559dBWXP5dXkaK/RzOoZCpz491rcY5IOoqbHOv IQWhrd9ZgQplZI0rrTlmTw9HspgL3zvWC7y5n0yXjziVNVUNFP4NjCYWO9poMtDOIDHp dnpw== 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=NCRIyJ3oqIvHXngAtHm1nMT8c70CGNL0Rd3wv/jq6L0=; b=XrIXNs5bgVaFOZzH6ArxtlKpMmNZ/o6m/ern2KVfsjGLKbov8hTfIb7xp6xet8Nh9f 4Snw9e5HuI7FjxDJF6FKpcosKa7JHIAuvJiRohhn+d+zBe5Raz7MJuEFPv/9Akkl7lLy HzwWcWNm+0Z6iKD9u7bYLW/pb4HjkexdrUh//yIC9TL81Ou7qFcKLzIMEXFsa6iEEIR0 0JYQXAJ7hLg1V66awNeiZgh4b/GEJMumDZ8CrpB8IUO4IPI9tMo1G3THKBJXsDlXXypz wiejzLCLFaG6ha2Xuhmv9p+hGqhGWZu+rX2iWoJp2rBOlTbQzEF02ctA5y+r3fTNFd2i kpXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=hBc5Q22q; 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 cm3-20020a170907938300b008cf2b9f412csi6425075ejc.67.2023.02.21.04.59.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:59:29 -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=hBc5Q22q; 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 2BC763886C53 for ; Tue, 21 Feb 2023 12:20:53 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 9BBAC3844765 for ; Tue, 21 Feb 2023 12:04:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9BBAC3844765 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 t15so4269890wrz.7 for ; Tue, 21 Feb 2023 04:04:36 -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=NCRIyJ3oqIvHXngAtHm1nMT8c70CGNL0Rd3wv/jq6L0=; b=hBc5Q22qorEz/qCHyMec+yUsViKI43PHNLsvpdtaRi3f7iXSHd3FU/CQGG+UkIEDTs Bf9loDXCSqz3k4UxKxd/2w/BBO3vVKdIpH2TB5vaEZTXm7vi+O0WZSZrlh/UCzI4Odg1 ZkkSYKUJ9KnpyvrHo4cURtMGW3NaXxqRNf8OkhcaP+rW+APF7m+xxD/3vKlEgwMQiN+G sUm3+PY5Mw05j8SwOJVgIuYbykjt27asis08X77iBApIYpZ7d6/yDR9XJ+81NjcTJ3yg jjwClo4YuJIcK6XA4SgdLrBihBCJcUG6uvTrv3FP5Nxrhd3GbF78m3Of1649P9N4i5xN 7flA== 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=NCRIyJ3oqIvHXngAtHm1nMT8c70CGNL0Rd3wv/jq6L0=; b=ogh6ORfhNj+dZzb2ke8vht2tbmoIu3EzUfcJR/bSek02myyITsiTeQTGKi2Y8dKbDw LHO5ZDRdI43Acsrt2cuHlmZuigd7YjPmOj0CynHqHh8NnImm9dU5ueusNGgDTb6xgVUO l93TKf6NiI2cEYHHml056ZjOLlB/7rralmGrPbQI2GIQ21wL5OHD9We7JJnj0mkuPrAC S7FXEhSZDYuUjXy3MFDWO7SYa5QrLqzlISxZqQznqGzvk25Nnr5SnBzixadpk6mswbb8 bXBJxAbeKK3+kstJTgmXIeOCtpraa1DHYvZvoCzJjo82niOQe4WivqMddMTzlhaZFZ22 s+Rg== X-Gm-Message-State: AO0yUKW0L+UH2DH/+pNEV2ITSiDkAn05Fo2jS+LswgHd/ODFpNXfy1jH C41jFG6BQXs3dc9DlvlQpIG1i9IGgb8xq8krKg== X-Received: by 2002:a5d:522e:0:b0:2c3:db9e:4b06 with SMTP id i14-20020a5d522e000000b002c3db9e4b06mr4944863wra.45.1676981075971; Tue, 21 Feb 2023 04:04:35 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:35 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Dave Subject: [committed 091/103] gccrs: Remove default location. Add visibility location to create_* functions Date: Tue, 21 Feb 2023 13:02:21 +0100 Message-Id: <20230221120230.596966-92-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.3 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?1758445562080392789?= X-GMAIL-MSGID: =?utf-8?q?1758445562080392789?= From: Dave gcc/rust/ChangeLog: * ast/rust-item.h: Remoe default location for Visibility class. * parse/rust-parse-impl.h (Parser::parse_visibility): Pass proper location when instantiating visibilities. --- gcc/rust/ast/rust-item.h | 33 ++++++++++++++++++-------------- gcc/rust/parse/rust-parse-impl.h | 11 ++++++----- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 96201d668de..7ea7b86562f 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -633,8 +633,7 @@ private: public: // Creates a Visibility - TODO make constructor protected or private? - Visibility (VisType vis_type, SimplePath in_path, - Location locus = Location ()) + Visibility (VisType vis_type, SimplePath in_path, Location locus) : vis_type (vis_type), in_path (std::move (in_path)), locus (locus) {} @@ -654,10 +653,11 @@ public: Location get_locus () const { return locus; } + // empty? // Creates an error visibility. static Visibility create_error () { - return Visibility (PUB_IN_PATH, SimplePath::create_empty ()); + return Visibility (PUB_IN_PATH, SimplePath::create_empty (), Location ()); } // Unique pointer custom clone function @@ -669,45 +669,50 @@ public: * is one idea but may be too resource-intensive. */ // Creates a public visibility with no further features/arguments. - static Visibility create_public () + // empty? + static Visibility create_public (Location pub_vis_location) { - return Visibility (PUB, SimplePath::create_empty ()); + return Visibility (PUB, SimplePath::create_empty (), pub_vis_location); } // Creates a public visibility with crate-relative paths - static Visibility create_crate (Location crate_tok_location) + static Visibility create_crate (Location crate_tok_location, + Location crate_vis_location) { return Visibility (PUB_CRATE, SimplePath::from_str ("crate", crate_tok_location), - crate_tok_location); + crate_vis_location); } // Creates a public visibility with self-relative paths - static Visibility create_self (Location self_tok_location) + static Visibility create_self (Location self_tok_location, + Location self_vis_location) { return Visibility (PUB_SELF, SimplePath::from_str ("self", self_tok_location), - self_tok_location); + self_vis_location); } // Creates a public visibility with parent module-relative paths - static Visibility create_super (Location super_tok_location) + static Visibility create_super (Location super_tok_location, + Location super_vis_location) { return Visibility (PUB_SUPER, SimplePath::from_str ("super", super_tok_location), - super_tok_location); + super_vis_location); } // Creates a private visibility static Visibility create_private () { - return Visibility (PRIV, SimplePath::create_empty ()); + return Visibility (PRIV, SimplePath::create_empty (), Location ()); } // Creates a public visibility with a given path or whatever. - static Visibility create_in_path (SimplePath in_path) + static Visibility create_in_path (SimplePath in_path, + Location in_path_vis_location) { - return Visibility (PUB_IN_PATH, std::move (in_path), in_path.get_locus ()); + return Visibility (PUB_IN_PATH, std::move (in_path), in_path_vis_location); } std::string as_string () const; diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index a4a912f8c1d..ee0282bdab3 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -2137,12 +2137,13 @@ Parser::parse_visibility () return AST::Visibility::create_private (); } + auto vis_loc = lexer.peek_token ()->get_locus (); lexer.skip_token (); // create simple pub visibility if no parentheses if (lexer.peek_token ()->get_id () != LEFT_PAREN) { - return AST::Visibility::create_public (); + return AST::Visibility::create_public (vis_loc); // or whatever } @@ -2158,19 +2159,19 @@ Parser::parse_visibility () skip_token (RIGHT_PAREN); - return AST::Visibility::create_crate (path_loc); + return AST::Visibility::create_crate (path_loc, vis_loc); case SELF: lexer.skip_token (); skip_token (RIGHT_PAREN); - return AST::Visibility::create_self (path_loc); + return AST::Visibility::create_self (path_loc, vis_loc); case SUPER: lexer.skip_token (); skip_token (RIGHT_PAREN); - return AST::Visibility::create_super (path_loc); + return AST::Visibility::create_super (path_loc, vis_loc); case IN: { lexer.skip_token (); @@ -2188,7 +2189,7 @@ Parser::parse_visibility () skip_token (RIGHT_PAREN); - return AST::Visibility::create_in_path (std::move (path)); + return AST::Visibility::create_in_path (std::move (path), vis_loc); } default: add_error (Error (t->get_locus (), "unexpected token %qs in visibility", From patchwork Tue Feb 21 12:02:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60077 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1849772wrn; Tue, 21 Feb 2023 05:04:40 -0800 (PST) X-Google-Smtp-Source: AK7set8Tw3uMm5I+4oQU9dx0dU5ueDH84QBQASDXZORUypECpno6hz46ozNdp0RbPZBr/fLGjLqM X-Received: by 2002:a17:906:1cd7:b0:88d:d76d:8527 with SMTP id i23-20020a1709061cd700b0088dd76d8527mr14451035ejh.47.1676984680251; Tue, 21 Feb 2023 05:04:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984680; cv=none; d=google.com; s=arc-20160816; b=kSc766Dp0iYZ7aVhwgbkzccF2rAFQkmpEVrAFq3U7AQYus8C6mrv/fsWesNmA1wXa8 A4mhaqYO3DzLonjS1oyNn4QulwJ9bNejGqYTi8C2whf1oOP2HXppN5BVuN5xzEJ9Budt O7zjubwLdjMKrTvSIsOmZDlz9qUWePR/vG0Oe54RogIjcnEvAPl4R1zdEpSf77OAnons soGlsx4hStCWlAI4apXK2ZKSjvCf9+enaP4RuMz6KnQC4gz/3Q/QcXqFSk046AZAwsOb zmmLCO1h5WGwm9PUfcLcxqJzSJkLdsm0EjRDH+FBFBMJHWLR7BY6L50jga5IAQj9GYMp yO7w== 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=IxHBAILdar9Cv3XQf/HDDc7bXPwJFtHB6rG28jATgZQ=; b=AhBKEk+trEFIHQPG5DcZDAbLAd02BWrkqw47aMrb75VxOMFE+QbZqsYtxTTYs1PNDw HW/lfKOkzxCE1xN86Thx6NoMchudQxmEPEpPlTFHW+RvqwTpXa6MJFSRpCdavA9crcYj 6LYIax26FRdOIVzN/MlCCWIgYLuRSiaj6CwN7UcsVaV37BzZrAScBo6s2i6sVXBt+aSI S8Udu34DPFkACMUJyb87xV3LLQlnvpS4mfI9DHRjqbpb6zgpzeGYS8RSRVnmA551g7nb 7oCpFtqXpcYjrl+xK1mQnXQA+ZvVbcWazb0uT+x4tgrDZ21oNWvPVogaH3dFezVb+UbI F6zA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=YbTTHaKA; 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 mq23-20020a170907831700b008cc4457c731si8346716ejc.900.2023.02.21.05.04.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 05:04:40 -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=YbTTHaKA; 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 1C5F33831483 for ; Tue, 21 Feb 2023 12:24:01 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 92516382CD64 for ; Tue, 21 Feb 2023 12:04:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 92516382CD64 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-x430.google.com with SMTP id j2so3984687wrh.9 for ; Tue, 21 Feb 2023 04:04:37 -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=IxHBAILdar9Cv3XQf/HDDc7bXPwJFtHB6rG28jATgZQ=; b=YbTTHaKAuxGNxfZp7RSvb/8IBuqrAPnXV9bMNZsNM5Z0VSkyFLZm7Rncyk0H7nffHz VQFnSBNmq79DlxzHj/0vcw0SghvLR6xdpJspGwjauNJKoMDaAj08SLkrvjUCWdbhUHlk nCWhRJa03UKxUxpI1TsnlO9ywiW8GEs7d3xy/aXwF+VFVYZgV1F/w2k1wTA6/e7PU9Sh Lu4MZYm2ebCzlFzSPqNoRhs/KH6gygVWPJOTZc4Cq7jGSgXt501SJzOUkhyEmEuwOeBw OTDrexRaQr6qmku9kvhzekS5IB/fSc9EciwnjbCppf+bO08Ezgy3CjkaQmjaIdYnhk2x dJwg== 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=IxHBAILdar9Cv3XQf/HDDc7bXPwJFtHB6rG28jATgZQ=; b=3clf27giOfRdSlOuUBXxgB9zuCa5sdiZcBp1OGjZQSouoVBHgVj16rSdj8N9i4tzim neoYKFBg0/0j/5z+h0fuC3oE8/P3c6qx5ujXtpotrh6iezWjnRiZbr8WH93igLffkHyt 4SQZ1skqqtwVZE7noi3rVmLGKeT9oqreO58Gq2qjAiT10ulUcEdmpTDxPZbhP2jFlySV pUmdX4QTOo/1nnqP/V8xMStJ4lmI6IRpCl0fmIXO/HsoegLgcrzWITug+cmGhHY5V+gv VVZnBq1726x2+AjpcAVbiLBdWG8U9Ta6fhzR8E3Ng7jWtfkJXqdeD8/Q2WhjLxjqSjjG /x/Q== X-Gm-Message-State: AO0yUKXe+7/OOZwRv8YIiVFth3FmCwffWaApAyh6SCV2OOe97IXcAfg5 gwg/6v0+jLbeQajuIeR8SGemz0P3oIw7ISLRww== X-Received: by 2002:adf:f348:0:b0:298:4baf:ac8a with SMTP id e8-20020adff348000000b002984bafac8amr2757565wrp.44.1676981076841; Tue, 21 Feb 2023 04:04:36 -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:36 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Raiki Tamura Subject: [committed 092/103] gccrs: Improve lexer dump Date: Tue, 21 Feb 2023 13:02:22 +0100 Message-Id: <20230221120230.596966-93-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.3 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?1758445888180253278?= X-GMAIL-MSGID: =?utf-8?q?1758445888180253278?= From: Raiki Tamura gcc/rust/ChangeLog: * lex/rust-lex.cc (Lexer::Lexer): Add `dump_lex` boolean flag. (Lexer::skip_token): Dump tokens if flag is enabled. (Lexer::dump_and_skip): New function. * lex/rust-lex.h: Include optional.h and declare functions. * parse/rust-parse-impl.h (Parser::debug_dump_lex_output): Remove old unused function. * parse/rust-parse.h: Likewise. * rust-session-manager.cc (Session::compile_crate): Pass lexer dump option to lexer. (Session::dump_lex): New function. * util/rust-optional.h: Add missing constructor. Signed-off-by: Raiki Tamura --- gcc/rust/lex/rust-lex.cc | 47 ++++++++++++++++++++++++++++++-- gcc/rust/lex/rust-lex.h | 12 ++++++-- gcc/rust/parse/rust-parse-impl.h | 41 ---------------------------- gcc/rust/parse/rust-parse.h | 2 -- gcc/rust/rust-session-manager.cc | 41 ++++++++++++---------------- gcc/rust/util/rust-optional.h | 1 + 6 files changed, 72 insertions(+), 72 deletions(-) diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc index 3467a3160ed..53c7aecd25b 100644 --- a/gcc/rust/lex/rust-lex.cc +++ b/gcc/rust/lex/rust-lex.cc @@ -118,13 +118,15 @@ is_non_decimal_int_literal_separator (char character) Lexer::Lexer (const std::string &input) : input (RAIIFile::create_error ()), current_line (1), current_column (1), - line_map (nullptr), raw_input_source (new BufferInputSource (input, 0)), + line_map (nullptr), dump_lex_out (Optional::none ()), + raw_input_source (new BufferInputSource (input, 0)), input_queue{*raw_input_source}, token_queue (TokenSource (this)) {} -Lexer::Lexer (const char *filename, RAIIFile file_input, Linemap *linemap) +Lexer::Lexer (const char *filename, RAIIFile file_input, Linemap *linemap, + Optional dump_lex_opt) : input (std::move (file_input)), current_line (1), current_column (1), - line_map (linemap), + line_map (linemap), dump_lex_out (dump_lex_opt), raw_input_source (new FileInputSource (input.get_raw ())), input_queue{*raw_input_source}, token_queue (TokenSource (this)) { @@ -186,6 +188,45 @@ Lexer::skip_input () skip_input (0); } +void +Lexer::skip_token (int n) +{ + // dump tokens if dump-lex option is enabled + if (dump_lex_out.is_some ()) + dump_and_skip (n); + else + token_queue.skip (n); +} + +void +Lexer::dump_and_skip (int n) +{ + std::ofstream &out = dump_lex_out.get (); + bool found_eof = false; + const_TokenPtr tok; + for (int i = 0; i < n + 1; i++) + { + if (!found_eof) + { + tok = peek_token (); + found_eof |= tok->get_id () == Rust::END_OF_FILE; + + Location loc = tok->get_locus (); + + out << "token_id_to_str (); + out << (tok->has_str () ? (std::string (", text=") + tok->get_str () + + std::string (", typehint=") + + std::string (tok->get_type_hint_str ())) + : "") + << " "; + out << get_line_map ()->to_string (loc) << " "; + } + + token_queue.skip (0); + } +} + void Lexer::replace_current_token (TokenPtr replacement) { diff --git a/gcc/rust/lex/rust-lex.h b/gcc/rust/lex/rust-lex.h index 6e8c5999f51..a170e91f2cc 100644 --- a/gcc/rust/lex/rust-lex.h +++ b/gcc/rust/lex/rust-lex.h @@ -22,6 +22,7 @@ #include "rust-linemap.h" #include "rust-buffered-queue.h" #include "rust-token.h" +#include "rust-optional.h" namespace Rust { // Simple wrapper for FILE* that simplifies destruction. @@ -139,7 +140,9 @@ private: public: // Construct lexer with input file and filename provided - Lexer (const char *filename, RAIIFile input, Linemap *linemap); + Lexer (const char *filename, RAIIFile input, Linemap *linemap, + Optional dump_lex_opt + = Optional::none ()); // Lex the contents of a string instead of a file Lexer (const std::string &input); @@ -161,10 +164,13 @@ public: const_TokenPtr peek_token () { return peek_token (0); } // Advances current token to n + 1 tokens ahead of current position. - void skip_token (int n) { token_queue.skip (n); } + void skip_token (int n); // Skips the current token. void skip_token () { skip_token (0); } + // Dumps and advances by n + 1 tokens. + void dump_and_skip (int n); + // Replaces the current token with a specified token. void replace_current_token (TokenPtr replacement); // FIXME: don't use anymore @@ -197,6 +203,8 @@ private: * allocating new linemap */ static const int max_column_hint = 80; + Optional dump_lex_out; + // Input source wrapper thing. class InputSource { diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index ee0282bdab3..cbd40efcc9b 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -14897,47 +14897,6 @@ Parser::done_end () return (t->get_id () == RIGHT_CURLY || t->get_id () == END_OF_FILE); } -// Dumps lexer output to stderr. -template -void -Parser::debug_dump_lex_output (std::ostream &out) -{ - /* TODO: a better implementation of "lexer dump" (as in dump what was - * actually tokenised) would actually be to "write" a token to a file every - * time skip_token() here was called. This would reflect the parser - * modifications to the token stream, such as fixing the template angle - * brackets. */ - - const_TokenPtr tok = lexer.peek_token (); - - while (true) - { - if (tok->get_id () == Rust::END_OF_FILE) - break; - - bool has_text = tok->get_id () == Rust::IDENTIFIER - || tok->get_id () == Rust::INT_LITERAL - || tok->get_id () == Rust::FLOAT_LITERAL - || tok->get_id () == Rust::STRING_LITERAL - || tok->get_id () == Rust::CHAR_LITERAL - || tok->get_id () == Rust::BYTE_STRING_LITERAL - || tok->get_id () == Rust::BYTE_CHAR_LITERAL; - - Location loc = tok->get_locus (); - - out << "token_id_to_str (); - out << has_text ? (std::string (", text=") + tok->get_str () - + std::string (", typehint=") - + std::string (tok->get_type_hint_str ())) - : ""; - out << lexer.get_line_map ()->to_string (loc); - - lexer.skip_token (); - tok = lexer.peek_token (); - } -} - // Parses crate and dumps AST to stderr, recursively. template void diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index e4c5a2c5c9f..8449181b12f 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -671,8 +671,6 @@ public: // Main entry point for parser. std::unique_ptr parse_crate (); - // Dumps all lexer output. - void debug_dump_lex_output (std::ostream &out); void debug_dump_ast_output (AST::Crate &crate, std::ostream &out); // Returns whether any parsing errors have occurred. diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc index 6f51bd2e5a1..732aabe1f26 100644 --- a/gcc/rust/rust-session-manager.cc +++ b/gcc/rust/rust-session-manager.cc @@ -455,7 +455,22 @@ Session::compile_crate (const char *filename) // parse file here /* create lexer and parser - these are file-specific and so aren't instance * variables */ - Lexer lex (filename, std::move (file_wrap), linemap); + Optional dump_lex_opt = Optional::none (); + std::ofstream dump_lex_stream; + if (options.dump_option_enabled (CompileOptions::LEXER_DUMP)) + { + dump_lex_stream.open (kLexDumpFile); + if (dump_lex_stream.fail ()) + { + rust_error_at (Linemap::unknown_location (), + "cannot open %s:%m; ignored", kLexDumpFile); + } + auto stream = Optional::some (dump_lex_stream); + dump_lex_opt = std::move (stream); + } + + Lexer lex (filename, std::move (file_wrap), linemap, dump_lex_opt); + Parser parser (lex); // generate crate from parser @@ -464,11 +479,7 @@ Session::compile_crate (const char *filename) // handle crate name handle_crate_name (*ast_crate.get ()); - // dump options - if (options.dump_option_enabled (CompileOptions::LEXER_DUMP)) - { - dump_lex (parser); - } + // dump options except lexer dump if (options.dump_option_enabled (CompileOptions::PARSER_AST_DUMP)) { dump_ast (parser, *ast_crate.get ()); @@ -835,24 +846,6 @@ Session::expansion (AST::Crate &crate) rust_debug ("finished expansion"); } -void -Session::dump_lex (Parser &parser) const -{ - std::ofstream out; - out.open (kLexDumpFile); - if (out.fail ()) - { - rust_error_at (Linemap::unknown_location (), "cannot open %s:%m; ignored", - kLexDumpFile); - return; - } - - // TODO: rewrite lexer dump or something so that it allows for the crate - // to already be parsed - parser.debug_dump_lex_output (out); - out.close (); -} - void Session::dump_ast (Parser &parser, AST::Crate &crate) const { diff --git a/gcc/rust/util/rust-optional.h b/gcc/rust/util/rust-optional.h index eba3a7886ac..d7349820b38 100644 --- a/gcc/rust/util/rust-optional.h +++ b/gcc/rust/util/rust-optional.h @@ -194,6 +194,7 @@ private: public: Optional (const Optional &other) = default; Optional (Optional &&other) = default; + Optional &operator= (Optional &&other) = default; static Optional some (T &value) { 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; From patchwork Tue Feb 21 12:02:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60055 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1844966wrn; Tue, 21 Feb 2023 04:55:53 -0800 (PST) X-Google-Smtp-Source: AK7set+mWIgLrMoyeb9H6vyBlbgQZkMc2rAp9dhnBbiqQl7fcjS/Mvc/a+W5Eo69rrDwLF6lvnv7 X-Received: by 2002:a17:906:5f89:b0:8c3:3439:24d9 with SMTP id a9-20020a1709065f8900b008c3343924d9mr9891360eju.24.1676984153713; Tue, 21 Feb 2023 04:55:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984153; cv=none; d=google.com; s=arc-20160816; b=vUA6eGT/bxDbrb5UqKReZSM4vicC9vswW9SEM3n4tsCoYJLaBsUPDfPC/iA0ZAdwdu V2RfYiDQrQTP/WX91oyBNwXs5CQaVFKKVHO94mnuWTIea/4YXlWXKict/iJr1ys4tsAQ SYT/uJcZzOIABZ+ya6AK1YfNVYe3fiY1OvLokysd8vKHaCVlC/UW/VZuuYxuxh6plhzl y7q6gmgWYSe7KaufUVy5OUEPnCwQG0yHexqYTC9SsfOr/SuH9Ft28ABU0PWSSsAt4s0+ UKlU/lokbpS3FoTPiygoFWkklDGUKFB6/jYjnLxi2GFLVBiZJdnur+Im01VF7mX0SNbH cS+w== 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=Kp+VIu1sDQvy8rqukJh4bdeRFz4pteYD8JPYipkguGs=; b=E/w2uyBFak+FoniRADtciRvVlKdSYnMta7CiBMSIbsNglrT8olBw3HyncphIXLC5Sv +9g/UksVPoUqUR2h7sgznWGrFi0qg78kc6/5CVNU7ViKuHbnl0wqflEhh8TXc0T8mjDh 6t1GOJxdR8+TxnDxe9P5baRHVMAvnuqP0K5QkmLHjYDSe2NTcSVx45EVDfPPO/LgW79V QIbXfDRVJ7zyhfeEcoZFRfHdmLXktLRNdBxZYeMmjpicNBgMsRBNMrOtkAAP41C1l4mz xehml8IRIn1KF1ImFRLHdmHmmh1PAde7MnVg3KAzSLv78b7PxTG+87Zw2QR4CqI1ijUB H6EQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=BheY2WLo; 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 bf21-20020a170906c51500b008bc108463e1si11357343ejb.98.2023.02.21.04.55.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:55:53 -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=BheY2WLo; 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 DFAB33A1E6ED for ; Tue, 21 Feb 2023 12:19:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 3F8253888C49 for ; Tue, 21 Feb 2023 12:04:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3F8253888C49 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-x42e.google.com with SMTP id j2so3984792wrh.9 for ; Tue, 21 Feb 2023 04:04:39 -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=Kp+VIu1sDQvy8rqukJh4bdeRFz4pteYD8JPYipkguGs=; b=BheY2WLozBKYLaCeagrk/z8ICLwC79tEER7NQ0AEOgt69+YFTwX9cMm47QmI2BEdwA XEAmUDLRJzfTp3S2jpiLSzTOiUzmowiWQVsV416zovtTKe9TKYw55v+e4wXlyC2sbYYK 3SNeJv81PP02jUaMuvWIlmGGe6c33owa07pI/o5y1ndoeW2+vTu6WNer0rgPN249fuc7 m/977DuLD90Efnvm68SMAoCKB+0FttUyJ4rEr0OuoeU4/VjdXSdiFW5vZ2SzlsnMV2OQ +EKabl5TCUibuxLiMv58BwVGvwLpr8QIFeqbEASwfwDMBkN9rrQh5iQnrb9Kmc7zaRLq lqSw== 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=Kp+VIu1sDQvy8rqukJh4bdeRFz4pteYD8JPYipkguGs=; b=C7gNd2saKjbimKo9rn2lhzlC+joCYvEjEOkuAbF03GHPx/pDzLQ99ocCxDTdYMd/d7 aFqhHLisFDxUYqYua65zw+ykRgR0PqhSDhgPONOeYP4zNOHCbrDYb4aZJ3hA1tC5AWIy iKjeZtSxxJ64OGOOx20w9eqy7kUEyBHR4kCggzOzOaUMiJmbqHN+YHNqK6yTxtbKXK5b Z2xsqYyfH6C8lsVrkZXF4iNRTP1lhSM/j2pbVyhcE7Z0iCmFgrpGNgtSNI292MjcyklK BZV/RJBpXTF9zUYcEE+Kp6pu8ZHRXk6Bie8i21GGAjlcheTVcXhndVD2NU7PrW6mIf/V 0xDw== X-Gm-Message-State: AO0yUKWRxU9q59O5LOuwMX5SJinV9MpcosD4U8gJAW/sJr2wHuibzMXh bwZDr0bICke91rFqjZ1S+bdyZ2U9SksdCa8low== X-Received: by 2002:a5d:444d:0:b0:2c5:4c32:92cb with SMTP id x13-20020a5d444d000000b002c54c3292cbmr2423346wrr.54.1676981078320; Tue, 21 Feb 2023 04:04:38 -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.37 (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 094/103] gccrs: Refactor name resolver to take a Rib::ItemType Date: Tue, 21 Feb 2023 13:02:24 +0100 Message-Id: <20230221120230.596966-95-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?1758445335886300310?= X-GMAIL-MSGID: =?utf-8?q?1758445335886300310?= From: Philip Herron This allows us to track the type of declaration that is stored within a Rib. gcc/rust/ChangeLog: * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Add Rib argument. (ResolveExpr::resolve_closure_param): Likewise. * resolve/rust-ast-resolve-implitem.h: Likewise. * resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit): Likewise. (ResolveItem::visit): Likewise. * resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::visit): Likewise. * resolve/rust-ast-resolve-pattern.h: Likewise. * resolve/rust-ast-resolve-stmt.h: Likewise. * resolve/rust-ast-resolve-toplevel.h: Likewise. * resolve/rust-ast-resolve-type.h: Likewise. * resolve/rust-name-resolver.cc (Rib::lookup_decl_type): Likewise. (Scope::insert): Likewise. (Resolver::insert_builtin_types): Likewise. * resolve/rust-name-resolver.h: Likewise. --- gcc/rust/resolve/rust-ast-resolve-expr.cc | 14 +++++------ gcc/rust/resolve/rust-ast-resolve-implitem.h | 12 ++++++++-- gcc/rust/resolve/rust-ast-resolve-item.cc | 19 ++++++++------- gcc/rust/resolve/rust-ast-resolve-pattern.cc | 2 +- gcc/rust/resolve/rust-ast-resolve-pattern.h | 12 ++++++---- gcc/rust/resolve/rust-ast-resolve-stmt.h | 19 ++++++++++----- gcc/rust/resolve/rust-ast-resolve-toplevel.h | 21 ++++++++++++---- gcc/rust/resolve/rust-ast-resolve-type.h | 2 +- gcc/rust/resolve/rust-name-resolver.cc | 23 ++++++++++++++---- gcc/rust/resolve/rust-name-resolver.h | 25 +++++++++++++++++++- 10 files changed, 108 insertions(+), 41 deletions(-) diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.cc b/gcc/rust/resolve/rust-ast-resolve-expr.cc index 8ece5b63b6d..293c63f5628 100644 --- a/gcc/rust/resolve/rust-ast-resolve-expr.cc +++ b/gcc/rust/resolve/rust-ast-resolve-expr.cc @@ -209,7 +209,7 @@ ResolveExpr::visit (AST::IfLetExpr &expr) for (auto &pattern : expr.get_patterns ()) { - PatternDeclaration::go (pattern.get ()); + PatternDeclaration::go (pattern.get (), Rib::ItemType::Var); } ResolveExpr::go (expr.get_if_block ().get (), prefix, canonical_prefix); @@ -343,7 +343,7 @@ ResolveExpr::visit (AST::LoopExpr &expr) auto label_lifetime_node_id = label.get_lifetime ().get_node_id (); resolver->get_label_scope ().insert ( CanonicalPath::new_seg (expr.get_node_id (), label_name), - label_lifetime_node_id, label.get_locus (), false, + label_lifetime_node_id, label.get_locus (), false, Rib::ItemType::Label, [&] (const CanonicalPath &, NodeId, Location locus) -> void { rust_error_at (label.get_locus (), "label redefined multiple times"); rust_error_at (locus, "was defined here"); @@ -400,7 +400,7 @@ ResolveExpr::visit (AST::WhileLoopExpr &expr) auto label_lifetime_node_id = label.get_lifetime ().get_node_id (); resolver->get_label_scope ().insert ( CanonicalPath::new_seg (label.get_node_id (), label_name), - label_lifetime_node_id, label.get_locus (), false, + label_lifetime_node_id, label.get_locus (), false, Rib::ItemType::Label, [&] (const CanonicalPath &, NodeId, Location locus) -> void { rust_error_at (label.get_locus (), "label redefined multiple times"); rust_error_at (locus, "was defined here"); @@ -429,7 +429,7 @@ ResolveExpr::visit (AST::ForLoopExpr &expr) auto label_lifetime_node_id = label.get_lifetime ().get_node_id (); resolver->get_label_scope ().insert ( CanonicalPath::new_seg (label.get_node_id (), label_name), - label_lifetime_node_id, label.get_locus (), false, + label_lifetime_node_id, label.get_locus (), false, Rib::ItemType::Label, [&] (const CanonicalPath &, NodeId, Location locus) -> void { rust_error_at (label.get_locus (), "label redefined multiple times"); rust_error_at (locus, "was defined here"); @@ -446,7 +446,7 @@ ResolveExpr::visit (AST::ForLoopExpr &expr) resolver->push_new_label_rib (resolver->get_type_scope ().peek ()); // resolve the expression - PatternDeclaration::go (expr.get_pattern ().get ()); + PatternDeclaration::go (expr.get_pattern ().get (), Rib::ItemType::Var); ResolveExpr::go (expr.get_iterator_expr ().get (), prefix, canonical_prefix); ResolveExpr::go (expr.get_loop_block ().get (), prefix, canonical_prefix); @@ -520,7 +520,7 @@ ResolveExpr::visit (AST::MatchExpr &expr) // insert any possible new patterns for (auto &pattern : arm.get_patterns ()) { - PatternDeclaration::go (pattern.get ()); + PatternDeclaration::go (pattern.get (), Rib::ItemType::Var); } // resolve the body @@ -617,7 +617,7 @@ ResolveExpr::visit (AST::ClosureExprInnerTyped &expr) void ResolveExpr::resolve_closure_param (AST::ClosureParam ¶m) { - PatternDeclaration::go (param.get_pattern ().get ()); + PatternDeclaration::go (param.get_pattern ().get (), Rib::ItemType::Param); if (param.has_type_given ()) ResolveType::go (param.get_type ().get ()); diff --git a/gcc/rust/resolve/rust-ast-resolve-implitem.h b/gcc/rust/resolve/rust-ast-resolve-implitem.h index 52e025672bd..9cad8aa41a5 100644 --- a/gcc/rust/resolve/rust-ast-resolve-implitem.h +++ b/gcc/rust/resolve/rust-ast-resolve-implitem.h @@ -56,7 +56,7 @@ public: auto path = prefix.append (decl); resolver->get_type_scope ().insert ( - path, type.get_node_id (), type.get_locus (), false, + path, type.get_node_id (), type.get_locus (), false, Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (type.get_locus ()); r.add_range (locus); @@ -72,6 +72,7 @@ public: resolver->get_name_scope ().insert ( path, constant.get_node_id (), constant.get_locus (), false, + Rib::ItemType::Const, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (constant.get_locus ()); r.add_range (locus); @@ -87,6 +88,7 @@ public: resolver->get_name_scope ().insert ( path, function.get_node_id (), function.get_locus (), false, + Rib::ItemType::Function, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (function.get_locus ()); r.add_range (locus); @@ -102,6 +104,7 @@ public: resolver->get_name_scope ().insert ( path, method.get_node_id (), method.get_locus (), false, + Rib::ItemType::Function, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (method.get_locus ()); r.add_range (locus); @@ -141,6 +144,7 @@ public: resolver->get_name_scope ().insert ( path, function.get_node_id (), function.get_locus (), false, + Rib::ItemType::Function, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (function.get_locus ()); r.add_range (locus); @@ -159,6 +163,7 @@ public: resolver->get_name_scope ().insert ( path, method.get_node_id (), method.get_locus (), false, + Rib::ItemType::Function, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (method.get_locus ()); r.add_range (locus); @@ -177,6 +182,7 @@ public: resolver->get_name_scope ().insert ( path, constant.get_node_id (), constant.get_locus (), false, + Rib::ItemType::Const, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (constant.get_locus ()); r.add_range (locus); @@ -194,7 +200,7 @@ public: auto cpath = canonical_prefix.append (decl); resolver->get_type_scope ().insert ( - path, type.get_node_id (), type.get_locus (), false, + path, type.get_node_id (), type.get_locus (), false, Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (type.get_locus ()); r.add_range (locus); @@ -233,6 +239,7 @@ public: resolver->get_name_scope ().insert ( path, function.get_node_id (), function.get_locus (), false, + Rib::ItemType::Function, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (function.get_locus ()); r.add_range (locus); @@ -251,6 +258,7 @@ public: resolver->get_name_scope ().insert ( path, item.get_node_id (), item.get_locus (), false, + Rib::ItemType::Static, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (item.get_locus ()); r.add_range (locus); diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc index 193e6834334..0be9a02a6f6 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.cc +++ b/gcc/rust/resolve/rust-ast-resolve-item.cc @@ -82,7 +82,8 @@ ResolveTraitItems::visit (AST::TraitItemFunc &func) for (auto ¶m : function.get_function_params ()) { ResolveType::go (param.get_type ().get ()); - PatternDeclaration::go (param.get_pattern ().get ()); + PatternDeclaration::go (param.get_pattern ().get (), + Rib::ItemType::Param); } if (function.has_where_clause ()) @@ -138,14 +139,15 @@ ResolveTraitItems::visit (AST::TraitItemMethod &func) AST::TypePath self_type_path (std::move (segments), self_param.get_locus ()); ResolveType::go (&self_type_path); - PatternDeclaration::go (&self_pattern); + PatternDeclaration::go (&self_pattern, Rib::ItemType::Param); // we make a new scope so the names of parameters are resolved and shadowed // correctly for (auto ¶m : function.get_function_params ()) { ResolveType::go (param.get_type ().get ()); - PatternDeclaration::go (param.get_pattern ().get ()); + PatternDeclaration::go (param.get_pattern ().get (), + Rib::ItemType::Param); } if (function.has_where_clause ()) @@ -499,10 +501,8 @@ ResolveItem::visit (AST::Function &function) for (auto ¶m : function.get_function_params ()) { ResolveType::go (param.get_type ().get ()); - PatternDeclaration::go (param.get_pattern ().get ()); - - // the mutability checker needs to verify for immutable decls the number - // of assignments are <1. This marks an implicit assignment + PatternDeclaration::go (param.get_pattern ().get (), + Rib::ItemType::Param); } // resolve the function body @@ -631,14 +631,15 @@ ResolveItem::visit (AST::Method &method) AST::TypePath self_type_path (std::move (segments), self_param.get_locus ()); ResolveType::go (&self_type_path); - PatternDeclaration::go (&self_pattern); + PatternDeclaration::go (&self_pattern, Rib::ItemType::Param); // we make a new scope so the names of parameters are resolved and shadowed // correctly for (auto ¶m : method.get_function_params ()) { ResolveType::go (param.get_type ().get ()); - PatternDeclaration::go (param.get_pattern ().get ()); + PatternDeclaration::go (param.get_pattern ().get (), + Rib::ItemType::Param); } // resolve any where clause items diff --git a/gcc/rust/resolve/rust-ast-resolve-pattern.cc b/gcc/rust/resolve/rust-ast-resolve-pattern.cc index 483d1908822..10f4fd8a61b 100644 --- a/gcc/rust/resolve/rust-ast-resolve-pattern.cc +++ b/gcc/rust/resolve/rust-ast-resolve-pattern.cc @@ -49,7 +49,7 @@ PatternDeclaration::visit (AST::TupleStructPattern &pattern) for (auto &inner_pattern : items_no_range.get_patterns ()) { - PatternDeclaration::go (inner_pattern.get ()); + PatternDeclaration::go (inner_pattern.get (), type); } } break; diff --git a/gcc/rust/resolve/rust-ast-resolve-pattern.h b/gcc/rust/resolve/rust-ast-resolve-pattern.h index ea99c63b1ca..5f2b7293cf2 100644 --- a/gcc/rust/resolve/rust-ast-resolve-pattern.h +++ b/gcc/rust/resolve/rust-ast-resolve-pattern.h @@ -55,9 +55,9 @@ class PatternDeclaration : public ResolverBase using Rust::Resolver::ResolverBase::visit; public: - static void go (AST::Pattern *pattern) + static void go (AST::Pattern *pattern, Rib::ItemType type) { - PatternDeclaration resolver; + PatternDeclaration resolver (type); pattern->accept_vis (resolver); }; @@ -67,14 +67,14 @@ public: // as new refs to this decl will match back here so it is ok to overwrite resolver->get_name_scope ().insert ( CanonicalPath::new_seg (pattern.get_node_id (), pattern.get_ident ()), - pattern.get_node_id (), pattern.get_locus ()); + pattern.get_node_id (), pattern.get_locus (), type); } void visit (AST::WildcardPattern &pattern) override { resolver->get_name_scope ().insert ( CanonicalPath::new_seg (pattern.get_node_id (), "_"), - pattern.get_node_id (), pattern.get_locus ()); + pattern.get_node_id (), pattern.get_locus (), type); } // cases in a match expression @@ -89,7 +89,9 @@ public: void visit (AST::RangePattern &pattern) override; private: - PatternDeclaration () : ResolverBase () {} + PatternDeclaration (Rib::ItemType type) : ResolverBase (), type (type) {} + + Rib::ItemType type; }; } // namespace Resolver diff --git a/gcc/rust/resolve/rust-ast-resolve-stmt.h b/gcc/rust/resolve/rust-ast-resolve-stmt.h index be93b008996..28c547f410b 100644 --- a/gcc/rust/resolve/rust-ast-resolve-stmt.h +++ b/gcc/rust/resolve/rust-ast-resolve-stmt.h @@ -64,6 +64,7 @@ public: resolver->get_name_scope ().insert ( path, constant.get_node_id (), constant.get_locus (), false, + Rib::ItemType::Const, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (constant.get_locus ()); r.add_range (locus); @@ -82,7 +83,7 @@ public: canonical_prefix); } - PatternDeclaration::go (stmt.get_pattern ().get ()); + PatternDeclaration::go (stmt.get_pattern ().get (), Rib::ItemType::Var); if (stmt.has_type ()) ResolveType::go (stmt.get_type ().get ()); } @@ -97,6 +98,7 @@ public: resolver->get_type_scope ().insert ( path, struct_decl.get_node_id (), struct_decl.get_locus (), false, + Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (struct_decl.get_locus ()); r.add_range (locus); @@ -128,6 +130,7 @@ public: resolver->get_type_scope ().insert ( path, enum_decl.get_node_id (), enum_decl.get_locus (), false, + Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (enum_decl.get_locus ()); r.add_range (locus); @@ -158,7 +161,7 @@ public: mappings->insert_canonical_path (item.get_node_id (), cpath); resolver->get_type_scope ().insert ( - path, item.get_node_id (), item.get_locus (), false, + path, item.get_node_id (), item.get_locus (), false, Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (item.get_locus ()); r.add_range (locus); @@ -177,7 +180,7 @@ public: mappings->insert_canonical_path (item.get_node_id (), cpath); resolver->get_type_scope ().insert ( - path, item.get_node_id (), item.get_locus (), false, + path, item.get_node_id (), item.get_locus (), false, Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (item.get_locus ()); r.add_range (locus); @@ -202,7 +205,7 @@ public: mappings->insert_canonical_path (item.get_node_id (), cpath); resolver->get_type_scope ().insert ( - path, item.get_node_id (), item.get_locus (), false, + path, item.get_node_id (), item.get_locus (), false, Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (item.get_locus ()); r.add_range (locus); @@ -227,7 +230,7 @@ public: mappings->insert_canonical_path (item.get_node_id (), cpath); resolver->get_type_scope ().insert ( - path, item.get_node_id (), item.get_locus (), false, + path, item.get_node_id (), item.get_locus (), false, Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (item.get_locus ()); r.add_range (locus); @@ -247,6 +250,7 @@ public: resolver->get_type_scope ().insert ( path, struct_decl.get_node_id (), struct_decl.get_locus (), false, + Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (struct_decl.get_locus ()); r.add_range (locus); @@ -283,6 +287,7 @@ public: resolver->get_type_scope ().insert ( path, union_decl.get_node_id (), union_decl.get_locus (), false, + Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (union_decl.get_locus ()); r.add_range (locus); @@ -317,6 +322,7 @@ public: resolver->get_name_scope ().insert ( path, function.get_node_id (), function.get_locus (), false, + Rib::ItemType::Function, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (function.get_locus ()); r.add_range (locus); @@ -343,7 +349,8 @@ public: for (auto ¶m : function.get_function_params ()) { ResolveType::go (param.get_type ().get ()); - PatternDeclaration::go (param.get_pattern ().get ()); + PatternDeclaration::go (param.get_pattern ().get (), + Rib::ItemType::Param); } // resolve the function body diff --git a/gcc/rust/resolve/rust-ast-resolve-toplevel.h b/gcc/rust/resolve/rust-ast-resolve-toplevel.h index 4cc51011777..d751318ee54 100644 --- a/gcc/rust/resolve/rust-ast-resolve-toplevel.h +++ b/gcc/rust/resolve/rust-ast-resolve-toplevel.h @@ -57,6 +57,7 @@ public: resolver->get_name_scope ().insert ( path, module.get_node_id (), module.get_locus (), false, + Rib::ItemType::Module, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (module.get_locus ()); r.add_range (locus); @@ -85,6 +86,7 @@ public: resolver->get_type_scope ().insert ( path, alias.get_node_id (), alias.get_locus (), false, + Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (alias.get_locus ()); r.add_range (locus); @@ -105,6 +107,7 @@ public: resolver->get_type_scope ().insert ( path, struct_decl.get_node_id (), struct_decl.get_locus (), false, + Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (struct_decl.get_locus ()); r.add_range (locus); @@ -125,6 +128,7 @@ public: resolver->get_type_scope ().insert ( path, enum_decl.get_node_id (), enum_decl.get_locus (), false, + Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (enum_decl.get_locus ()); r.add_range (locus); @@ -147,7 +151,7 @@ public: auto cpath = canonical_prefix.append (decl); resolver->get_type_scope ().insert ( - path, item.get_node_id (), item.get_locus (), false, + path, item.get_node_id (), item.get_locus (), false, Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (item.get_locus ()); r.add_range (locus); @@ -165,7 +169,7 @@ public: auto cpath = canonical_prefix.append (decl); resolver->get_type_scope ().insert ( - path, item.get_node_id (), item.get_locus (), false, + path, item.get_node_id (), item.get_locus (), false, Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (item.get_locus ()); r.add_range (locus); @@ -183,7 +187,7 @@ public: auto cpath = canonical_prefix.append (decl); resolver->get_type_scope ().insert ( - path, item.get_node_id (), item.get_locus (), false, + path, item.get_node_id (), item.get_locus (), false, Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (item.get_locus ()); r.add_range (locus); @@ -201,7 +205,7 @@ public: auto cpath = canonical_prefix.append (decl); resolver->get_type_scope ().insert ( - path, item.get_node_id (), item.get_locus (), false, + path, item.get_node_id (), item.get_locus (), false, Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (item.get_locus ()); r.add_range (locus); @@ -220,6 +224,7 @@ public: resolver->get_type_scope ().insert ( path, struct_decl.get_node_id (), struct_decl.get_locus (), false, + Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (struct_decl.get_locus ()); r.add_range (locus); @@ -240,6 +245,7 @@ public: resolver->get_type_scope ().insert ( path, union_decl.get_node_id (), union_decl.get_locus (), false, + Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (union_decl.get_locus ()); r.add_range (locus); @@ -259,7 +265,7 @@ public: auto cpath = canonical_prefix.append (decl); resolver->get_name_scope ().insert ( - path, var.get_node_id (), var.get_locus (), false, + path, var.get_node_id (), var.get_locus (), false, Rib::ItemType::Static, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (var.get_locus ()); r.add_range (locus); @@ -280,6 +286,7 @@ public: resolver->get_name_scope ().insert ( path, constant.get_node_id (), constant.get_locus (), false, + Rib::ItemType::Const, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (constant.get_locus ()); r.add_range (locus); @@ -300,6 +307,7 @@ public: resolver->get_name_scope ().insert ( path, function.get_node_id (), function.get_locus (), false, + Rib::ItemType::Function, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (function.get_locus ()); r.add_range (locus); @@ -343,6 +351,7 @@ public: resolver->get_name_scope ().insert ( impl_prefix, impl_block.get_node_id (), impl_block.get_locus (), false, + Rib::ItemType::TraitImpl, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (impl_block.get_locus ()); r.add_range (locus); @@ -362,6 +371,7 @@ public: resolver->get_type_scope ().insert ( path, trait.get_node_id (), trait.get_locus (), false, + Rib::ItemType::Trait, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (trait.get_locus ()); r.add_range (locus); @@ -437,6 +447,7 @@ public: resolver->get_type_scope ().insert ( decl, resolved_crate, extern_crate.get_locus (), false, + Rib::ItemType::ExternCrate, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (extern_crate.get_locus ()); r.add_range (locus); diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h b/gcc/rust/resolve/rust-ast-resolve-type.h index 424233fa3df..bb1178362fb 100644 --- a/gcc/rust/resolve/rust-ast-resolve-type.h +++ b/gcc/rust/resolve/rust-ast-resolve-type.h @@ -177,7 +177,7 @@ public: auto seg = CanonicalPath::new_seg (param.get_node_id (), param.get_type_representation ()); resolver->get_type_scope ().insert ( - seg, param.get_node_id (), param.get_locus (), false, + seg, param.get_node_id (), param.get_locus (), false, Rib::ItemType::Type, [&] (const CanonicalPath &, NodeId, Location locus) -> void { rust_error_at (param.get_locus (), "generic param redefined multiple times"); diff --git a/gcc/rust/resolve/rust-name-resolver.cc b/gcc/rust/resolve/rust-name-resolver.cc index cc1ec2b9dc7..cf3028ef271 100644 --- a/gcc/rust/resolve/rust-name-resolver.cc +++ b/gcc/rust/resolve/rust-name-resolver.cc @@ -29,7 +29,7 @@ Rib::Rib (CrateNum crateNum, NodeId node_id) void Rib::insert_name ( const CanonicalPath &path, NodeId id, Location locus, bool shadow, - + ItemType type, std::function dup_cb) { auto it = path_mappings.find (path); @@ -49,6 +49,7 @@ Rib::insert_name ( reverse_path_mappings.insert ({id, path}); decls_within_rib.insert ({id, locus}); references[id] = {}; + decl_type_mappings.insert ({id, type}); } bool @@ -105,6 +106,17 @@ Rib::decl_was_declared_here (NodeId def) const return false; } +bool +Rib::lookup_decl_type (NodeId def, ItemType *type) const +{ + auto it = decl_type_mappings.find (def); + if (it == decl_type_mappings.end ()) + return false; + + *type = it->second; + return true; +} + void Rib::debug () const { @@ -128,15 +140,17 @@ Scope::Scope (CrateNum crate_num) : crate_num (crate_num) {} void Scope::insert ( const CanonicalPath &ident, NodeId id, Location locus, bool shadow, + Rib::ItemType type, std::function dup_cb) { - peek ()->insert_name (ident, id, locus, shadow, dup_cb); + peek ()->insert_name (ident, id, locus, shadow, type, dup_cb); } void -Scope::insert (const CanonicalPath &ident, NodeId id, Location locus) +Scope::insert (const CanonicalPath &ident, NodeId id, Location locus, + Rib::ItemType type) { - peek ()->insert_name (ident, id, locus, true, + peek ()->insert_name (ident, id, locus, true, type, [] (const CanonicalPath &, NodeId, Location) -> void { }); } @@ -321,6 +335,7 @@ Resolver::insert_builtin_types (Rib *r) builtin->as_string ()); r->insert_name (builtin_path, builtin->get_node_id (), Linemap::predeclared_location (), false, + Rib::ItemType::Type, [] (const CanonicalPath &, NodeId, Location) -> void {}); } } diff --git a/gcc/rust/resolve/rust-name-resolver.h b/gcc/rust/resolve/rust-name-resolver.h index d2f740e0315..54d59544b1d 100644 --- a/gcc/rust/resolve/rust-name-resolver.h +++ b/gcc/rust/resolve/rust-name-resolver.h @@ -30,6 +30,24 @@ namespace Resolver { class Rib { public: + enum ItemType + { + Var, + Param, + Function, + Type, + Module, + Static, + Const, + Trait, + Impl, + TraitImpl, + ExternCrate, + MacroDecl, + Label, + Unknown + }; + // FIXME // Rust uses local_def_ids assigned by def_collector on the AST. Consider // moving to a local-def-id @@ -38,6 +56,7 @@ public: // this takes the relative paths of items within a compilation unit for lookup void insert_name ( const CanonicalPath &path, NodeId id, Location locus, bool shadow, + ItemType type, std::function dup_cb); bool lookup_canonical_path (const NodeId &id, CanonicalPath *ident); @@ -46,6 +65,7 @@ public: void append_reference_for_def (NodeId def, NodeId ref); bool have_references_for_node (NodeId def) const; bool decl_was_declared_here (NodeId def) const; + bool lookup_decl_type (NodeId def, ItemType *type) const; void debug () const; std::string debug_str () const; @@ -60,6 +80,7 @@ private: std::map reverse_path_mappings; std::map decls_within_rib; std::map> references; + std::map decl_type_mappings; }; class Scope @@ -69,9 +90,11 @@ public: void insert (const CanonicalPath &ident, NodeId id, Location locus, bool shadow, + Rib::ItemType type, std::function dup_cb); - void insert (const CanonicalPath &ident, NodeId id, Location locus); + void insert (const CanonicalPath &ident, NodeId id, Location locus, + Rib::ItemType type = Rib::ItemType::Unknown); bool lookup (const CanonicalPath &ident, NodeId *id); void iterate (std::function cb); From patchwork Tue Feb 21 12:02:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60051 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1843985wrn; Tue, 21 Feb 2023 04:53:38 -0800 (PST) X-Google-Smtp-Source: AK7set/SgLRFyQx9X3PNbkHoPJbWKtc6O72AhihoT2dv+BovLrYE4DRvhjEQejduE8no1ww8Y+eQ X-Received: by 2002:a05:6402:215:b0:4aa:9fc2:216 with SMTP id t21-20020a056402021500b004aa9fc20216mr5074317edv.9.1676984018092; Tue, 21 Feb 2023 04:53:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984018; cv=none; d=google.com; s=arc-20160816; b=pvNfCht7Vv7jjFdwVp64TmFlakPZ+L13HmnbpGj7TcD4yNNIUrSgwmCauM3KUJ/qg6 eBUAabSoR0Yuzdtu+fmaWgMHptpr7Bmi2KOFSoIVVu+T9FalC6sHmOFFu0CsFpdSajf8 5plzsWC7eIbZ6n8JIsQSw1RWIAzQ7lqBLWJZRsUSFXsZ7ACtLZHG+dFqX+Kfc7FyoGJa G4kiL/tbnxeLK5AP9Pdah8kf6CM07iykpZCqACzieKloT70Cnc0Tel9hFFgy5xvQLQTg GXH9VHQXUIYSo2f9/GBVee3C8zi+/dNXUGi44ZDAn1aS/2yv7AWCA84E6pp+4QOorsnN 9pDA== 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=DYtrhUnhoey2Jh6lTnVuch7YxTpbWRR7E1O7oWil0JM=; b=xxXDKJEen7y5yc+XO/o3y+h5Zy87MO2cDSpXHJ+9OGJuZfmfmNkcZg3uouSjoRAPWE zF4swh0qcrUFtY4HNCG/7w+MO7F2gXdlsZ55r0+PCW2d3YNWeFGBkKk4xtHryfN52PaJ ZfnwGqHABVvPC9B9UFTv5MRhfO0MC1NORvaX+EP/BzXTujneWULqG7wD8QSPdwM8QjT/ Ecf6ACHWSGV41n45rixnjsmjaQzSj8MWfKhgeAIWq0FqxT2urTfoEED7Sx9uTmM/Gc+o VilbmYcNi04udwecAZ0Mtga9OcwGaJZU359Onh46Id0V3uP/wYfg+LHkbcLCqAuHVN9a a/Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=DGwrdBQK; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id q9-20020aa7d449000000b004ad7c1ef7c7si15661437edr.506.2023.02.21.04.53.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:53:38 -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=DGwrdBQK; 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 8B4E2395A01C for ; Tue, 21 Feb 2023 12:18:22 +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 8B3E43888C52 for ; Tue, 21 Feb 2023 12:04:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8B3E43888C52 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 t15so4270088wrz.7 for ; Tue, 21 Feb 2023 04:04:39 -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=DYtrhUnhoey2Jh6lTnVuch7YxTpbWRR7E1O7oWil0JM=; b=DGwrdBQKSIwMYMVTnGUNftjnav4vEmzHWUph9FI8bX4b740dXn0MIK0i6YtD7VcoMd qfVTdtyEGx5t6RT7K+nfRIG1P5XiELDoq7RdM8t3bSMxh1NWbTVr/qEi4nEt9/yRBX9M bj7cMml3eggBIOFo++e6Ncgz6PGDvf59Wm9fjrYsRXPErCGVyo01N58JkZYoAj0ORDvk Gw8zUz6IlAUN+LXwlualOg0oevE0VTxEUxNoiNbaMboioHihQWNlhsk34rPZHY1J/oD/ sWsc9FTyVN3YbTymJGx8W45nitXllsMZl0GssQbjEybHibuGKCZHupdoShsGcLPd6ZJS 7uSQ== 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=DYtrhUnhoey2Jh6lTnVuch7YxTpbWRR7E1O7oWil0JM=; b=w9csHLzfI0M+1rDRsQLebUZ9Mf1idAGXwiHUYHlmreBiChHh/jiAdUjrwRuNhipYZ2 9qhancfwMA7dtnvyg1jEuke1TVbduWaXhtphtkzhYECPGJRTpXI32iUfzzsouGNfv7pw i7bHnqTvwuBtDf5pd05OcKnJUqk6A/DVWSuICzOZrb/ecGep3tMT2o7Io+xb5tEoLpUP jwiMqcEGNcuMn8uF6gegkQwKT5CSk8e6El6oPcxl+uSucPOlU57nufc4D1Qzc4YbX0Ur 8myeu195dbSCm4SwMexu+FmvuN5wkCVJPoSnsMNroQhWVRyc5damqK1Vsx7uiH0KUVE7 JROw== X-Gm-Message-State: AO0yUKWHte1p4HYJi7DGSnuHkGOOP2v9qlITe1emp9TjmPSDc+/snO6w vZy0ZREk/mpbsMchcgyBlz0OqSs7LWWPhQC7FA== X-Received: by 2002:a5d:4f08:0:b0:2c5:5870:b589 with SMTP id c8-20020a5d4f08000000b002c55870b589mr4131831wru.14.1676981078866; Tue, 21 Feb 2023 04:04:38 -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.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:38 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 095/103] gccrs: Add closure binding's tracking to name resolution Date: Tue, 21 Feb 2023 13:02:25 +0100 Message-Id: <20230221120230.596966-96-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.3 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?1758445193805956577?= X-GMAIL-MSGID: =?utf-8?q?1758445193805956577?= From: Philip Herron When we have a closure block referencing variables in a parent function, we must track what these are. We do this by having a context of closures so if we have a variable reference and its declared in a rib whose node id is less than the node id of the closure's node id we know it must be a captured variable. We also need to iterate all possible closure contexts as we might be in the case of a nested closure. Addresses #195 gcc/rust/ChangeLog: * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Use proper closure contexts. * resolve/rust-name-resolver.cc (Scope::lookup_decl_type): New function. (Scope::lookup_rib_for_decl): Likewise. (Resolver::insert_resolved_name): Insert captured items. (Resolver::push_closure_context): New function. (Resolver::pop_closure_context): Likewise. (Resolver::insert_captured_item): Likewise. (Resolver::decl_needs_capture): Likewise. (Resolver::get_captures): Likewise. * resolve/rust-name-resolver.h: Declare new functions. --- gcc/rust/resolve/rust-ast-resolve-expr.cc | 9 ++ gcc/rust/resolve/rust-name-resolver.cc | 133 ++++++++++++++++++++++ gcc/rust/resolve/rust-name-resolver.h | 17 +++ 3 files changed, 159 insertions(+) diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.cc b/gcc/rust/resolve/rust-ast-resolve-expr.cc index 293c63f5628..536c828beb4 100644 --- a/gcc/rust/resolve/rust-ast-resolve-expr.cc +++ b/gcc/rust/resolve/rust-ast-resolve-expr.cc @@ -581,9 +581,13 @@ ResolveExpr::visit (AST::ClosureExprInner &expr) resolve_closure_param (p); } + resolver->push_closure_context (expr.get_node_id ()); + ResolveExpr::go (expr.get_definition_expr ().get (), prefix, canonical_prefix); + resolver->pop_closure_context (); + resolver->get_name_scope ().pop (); resolver->get_type_scope ().pop (); resolver->get_label_scope ().pop (); @@ -606,9 +610,14 @@ ResolveExpr::visit (AST::ClosureExprInnerTyped &expr) } ResolveType::go (expr.get_return_type ().get ()); + + resolver->push_closure_context (expr.get_node_id ()); + ResolveExpr::go (expr.get_definition_block ().get (), prefix, canonical_prefix); + resolver->pop_closure_context (); + resolver->get_name_scope ().pop (); resolver->get_type_scope ().pop (); resolver->get_label_scope ().pop (); diff --git a/gcc/rust/resolve/rust-name-resolver.cc b/gcc/rust/resolve/rust-name-resolver.cc index cf3028ef271..b8ed3538f74 100644 --- a/gcc/rust/resolve/rust-name-resolver.cc +++ b/gcc/rust/resolve/rust-name-resolver.cc @@ -169,6 +169,39 @@ Scope::lookup (const CanonicalPath &ident, NodeId *id) return lookup != UNKNOWN_NODEID; } +bool +Scope::lookup_decl_type (NodeId id, Rib::ItemType *type) +{ + bool found = false; + iterate ([&] (const Rib *r) -> bool { + if (r->decl_was_declared_here (id)) + { + bool ok = r->lookup_decl_type (id, type); + rust_assert (ok); + found = true; + return false; + } + return true; + }); + return found; +} + +bool +Scope::lookup_rib_for_decl (NodeId id, const Rib **rib) +{ + bool found = false; + iterate ([&] (const Rib *r) -> bool { + if (r->decl_was_declared_here (id)) + { + *rib = r; + found = true; + return false; + } + return true; + }); + return found; +} + void Scope::iterate (std::function cb) { @@ -435,6 +468,7 @@ Resolver::insert_resolved_name (NodeId refId, NodeId defId) { resolved_names[refId] = defId; get_name_scope ().append_reference_for_def (refId, defId); + insert_captured_item (defId); } bool @@ -531,5 +565,104 @@ Resolver::lookup_resolved_misc (NodeId refId, NodeId *defId) return true; } +void +Resolver::push_closure_context (NodeId closure_expr_id) +{ + auto it = closures_capture_mappings.find (closure_expr_id); + rust_assert (it == closures_capture_mappings.end ()); + + closures_capture_mappings.insert ({closure_expr_id, {}}); + closure_context.push_back (closure_expr_id); +} + +void +Resolver::pop_closure_context () +{ + rust_assert (!closure_context.empty ()); + closure_context.pop_back (); +} + +void +Resolver::insert_captured_item (NodeId id) +{ + // nothing to do unless we are in a closure context + if (closure_context.empty ()) + return; + + // check that this is a VAR_DECL? + Scope &name_scope = get_name_scope (); + Rib::ItemType type = Rib::ItemType::Unknown; + bool found = name_scope.lookup_decl_type (id, &type); + if (!found) + return; + + // RIB Function { let a, let b } id = 1; + // RIB Closure { let c } id = 2; + // RIB IfStmt { } id = 3; + // RIB ... { ... } id = 4 + // + // if we have a resolved_node_id of 'a' and the current rib is '3' we know + // this is binding exists in a rib with id < the closure rib id, other wise + // its just a normal binding and we don't care + // + // Problem the node id's dont work like this because the inner most items are + // created first so this means the root will have a larger id and a simple + // less than or greater than check wont work for more complex scoping cases + // but we can use our current rib context to figure this out by checking if + // the rib id the decl we care about exists prior to the rib for the closure + // id + + const Rib *r = nullptr; + bool ok = name_scope.lookup_rib_for_decl (id, &r); + rust_assert (ok); + NodeId decl_rib_node_id = r->get_node_id (); + + // iterate the closure context and add in the mapping for all to handle the + // case of nested closures + for (auto &closure_expr_id : closure_context) + { + if (!decl_needs_capture (decl_rib_node_id, closure_expr_id, name_scope)) + continue; + + // is this a valid binding to take + bool is_var_decl_p = type == Rib::ItemType::Var; + if (!is_var_decl_p) + { + // FIXME is this an error case? + return; + } + + // append it to the context info + auto it = closures_capture_mappings.find (closure_expr_id); + rust_assert (it != closures_capture_mappings.end ()); + + it->second.insert (id); + } +} + +bool +Resolver::decl_needs_capture (NodeId decl_rib_node_id, + NodeId closure_rib_node_id, const Scope &scope) +{ + for (const auto &rib : scope.get_context ()) + { + bool rib_is_closure = rib->get_node_id () == closure_rib_node_id; + bool rib_is_decl = rib->get_node_id () == decl_rib_node_id; + if (rib_is_closure) + return false; + else if (rib_is_decl) + return true; + } + return false; +} + +const std::set & +Resolver::get_captures (NodeId id) const +{ + auto it = closures_capture_mappings.find (id); + rust_assert (it != closures_capture_mappings.end ()); + return it->second; +} + } // namespace Resolver } // namespace Rust diff --git a/gcc/rust/resolve/rust-name-resolver.h b/gcc/rust/resolve/rust-name-resolver.h index 54d59544b1d..f38cbb941bf 100644 --- a/gcc/rust/resolve/rust-name-resolver.h +++ b/gcc/rust/resolve/rust-name-resolver.h @@ -96,6 +96,8 @@ public: void insert (const CanonicalPath &ident, NodeId id, Location locus, Rib::ItemType type = Rib::ItemType::Unknown); bool lookup (const CanonicalPath &ident, NodeId *id); + bool lookup_decl_type (NodeId id, Rib::ItemType *type); + bool lookup_rib_for_decl (NodeId id, const Rib **rib); void iterate (std::function cb); void iterate (std::function cb) const; @@ -109,6 +111,8 @@ public: CrateNum get_crate_num () const { return crate_num; } + const std::vector &get_context () const { return stack; }; + private: CrateNum crate_num; std::vector stack; @@ -191,6 +195,15 @@ public: return current_module_stack.at (current_module_stack.size () - 2); } + void push_closure_context (NodeId closure_expr_id); + void pop_closure_context (); + void insert_captured_item (NodeId id); + const std::set &get_captures (NodeId id) const; + +protected: + bool decl_needs_capture (NodeId decl_rib_node_id, NodeId closure_rib_node_id, + const Scope &scope); + private: Resolver (); @@ -234,6 +247,10 @@ private: // keep track of the current module scope ids std::vector current_module_stack; + + // captured variables mappings + std::vector closure_context; + std::map> closures_capture_mappings; }; } // namespace Resolver From patchwork Tue Feb 21 12:02:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60079 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1850140wrn; Tue, 21 Feb 2023 05:05:14 -0800 (PST) X-Google-Smtp-Source: AK7set9LfKzlZKDxidEIEtoPYtQpc9UI8Oz7Xf2i6Mt+CpfRAOi1YVKcn/jCAU5+8pGJb+3IRzNY X-Received: by 2002:a17:907:a42a:b0:8b1:730b:a296 with SMTP id sg42-20020a170907a42a00b008b1730ba296mr21611074ejc.15.1676984714688; Tue, 21 Feb 2023 05:05:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984714; cv=none; d=google.com; s=arc-20160816; b=bMkoHKRi04Khu9tNLjUiWnuElCBcVCVbL8dvql7YdZaqhFMwkZJZnXnglY7EYhEIDb FBluByasahhGuyA7KNhpO7g6V0UyzjXo8DEux+Wwku+3LVzyfK9QRGWKx0SAuBCjlf1k /GZBQVxThQP7MaRIB5G3aBmgi0MgCNOInVtPajmv2tzntIzUz/62md40sFsjN4KMs3U6 YNeZPwwOugzaN/IOHE4q4S/D7m+LnBzq4TLcPxxtEcyBfI6mTeW2PTUMRR7pvtATrHmV s0/3v6HcGOweNwcR9T+o/caHegjy/wUMNrL81PFOLB+PrzFpVpTGpiLAanw6b3nOGHC9 gSAA== 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=DgbXq+dw7HduszADPLrrkky7+8q8tWS0noGuvtJu09I=; b=Z63CATceZDwMQI26PVjxYk0WrKJy47gGwMVgaxLLQZxUpnscLPrjYaUvzw2NQ+6d+F zjBCZxEqOw8Lch0kg6oHS+dxrYglM4OamBD51d2CSarQNFFDKNuk1WKWbLo9x6ZzsF4+ MbuqlaDioVbSc0zLQgjIjZjKwOB+ThlFp56EwNTqA46e+WA3NNUlYCrVCdxPgtEP+R1S PtigiXDL/swlxCb0zL3NdNwJRbxiPJMOhl9PeKDjSZ7usssOJMNuwVWc6FuLMJ2XThmH AgGugimy/0GGBV4j3Esm/Rlbg0+hvTrRcfulnqkzG206Cns2FhAv2txgdguZnLtJez/J VAAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=JBzvBzUJ; 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 qn20-20020a170907871400b008c0f56c2b50si10067209ejc.421.2023.02.21.05.05.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 05:05:14 -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=JBzvBzUJ; 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 B7950381BB82 for ; Tue, 21 Feb 2023 12:24:32 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 2C45F3888C55 for ; Tue, 21 Feb 2023 12:04:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2C45F3888C55 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-x430.google.com with SMTP id r7so3993912wrz.6 for ; Tue, 21 Feb 2023 04:04:40 -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=DgbXq+dw7HduszADPLrrkky7+8q8tWS0noGuvtJu09I=; b=JBzvBzUJL7V7p2winSgkFNLluFypgceGh/paFPATjtv2Dfk48HiNQUipgVJ6Tl8gTH d5RoZsMK2iO4t9mFx2+BcJjVWrOeN9OwmPrqWQynhOKmZz62h9GfChYMxJb/6NQAQ+uQ zLv5/RL1HIu6kqrqpSzwtiVhSvUWZrDNYRPHVZbzKax4P0OWYTIYnbrLrr/v9UyLueyh whH6TNPMd9VQBW+Uy57gMExo6szxcTZ8VL/Zybt6wP8+CqyoCSPfUWs+rJZ4y+l/Ewdv Nq77R6pOqerH+jRga9yh+PDiBjlrD/VpJtPsWiSxySiyUnUHLKzt6GBIhLcPqqpBd5/s XLbA== 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=DgbXq+dw7HduszADPLrrkky7+8q8tWS0noGuvtJu09I=; b=H0Lwryc53DzeTRiyJl/UckOkEPUvqGpYFQYAMlhQx+PxBzXk8BqBTkn+KAzFOQbv3L phA5asagPecvbk22pAnxg+VFEKZc1RbAtPZTrXuGvL39Fh84oJ8PR9Ud3iTfV5ZqGhD8 IzgLbS4+1BiXxwEip9mo6Nd5nIJP/XTToMN+Tid2QQ4t41unBlklLHNq83taqrhqjxfQ rMwJrLbx04lTu7pYghWroFGR104KYxmWHNlC3DZxoTu4RXv63i8w7EHxMuCuOD8J9qXT ERUiEeqssz1rdUWFhhpFVTGCF0AEg+6Q/fUG+LUwf/ZFyTPw7yfX3BMjeyfkXNBODseu tSkw== X-Gm-Message-State: AO0yUKWlWSZW9nI3no1HxnS8QtVCrl9O8OjGYCGgvFAExac6y71Hw238 ZIbdS9NC+3CZfXEwo/TW5I650356rK3zencxGA== X-Received: by 2002:adf:ef47:0:b0:2c5:9ed8:7c74 with SMTP id c7-20020adfef47000000b002c59ed87c74mr3685318wrp.19.1676981079537; Tue, 21 Feb 2023 04:04:39 -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.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:39 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 096/103] gccrs: Add capture tracking to the type info for closures Date: Tue, 21 Feb 2023 13:02:26 +0100 Message-Id: <20230221120230.596966-97-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?1758445924157455177?= X-GMAIL-MSGID: =?utf-8?q?1758445924157455177?= From: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Pass captures properly to `TyTy::ClosureType` constructor. * typecheck/rust-tyty.cc (ClosureType::as_string): Fix string representation. (ClosureType::clone): Pass `captures` argument. * typecheck/rust-tyty.h: Add `captures` field. --- gcc/rust/typecheck/rust-hir-type-check-expr.cc | 4 +++- gcc/rust/typecheck/rust-tyty.cc | 5 ++--- gcc/rust/typecheck/rust-tyty.h | 11 +++++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc index 85590630378..0b0db3296a0 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc @@ -1492,8 +1492,10 @@ TypeCheckExpr::visit (HIR::ClosureExpr &expr) expr.get_locus ()); // generate the closure type + NodeId closure_node_id = expr.get_mappings ().get_nodeid (); + const std::set &captures = resolver->get_captures (closure_node_id); infered = new TyTy::ClosureType (ref, id, ident, closure_args, result_type, - subst_refs); + subst_refs, captures); // FIXME // all closures automatically inherit the appropriate fn trait. Lets just diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index bdb2d909b86..71f0de1bbab 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -1675,8 +1675,7 @@ std::string ClosureType::as_string () const { std::string params_buf = parameters->as_string (); - return "|" + params_buf + "| {" + result_type.get_tyty ()->as_string () - + "} {" + raw_bounds_as_string () + "}"; + return "|" + params_buf + "| {" + result_type.get_tyty ()->as_string () + "}"; } BaseType * @@ -1714,7 +1713,7 @@ ClosureType::clone () const { return new ClosureType (get_ref (), get_ty_ref (), ident, id, (TyTy::TupleType *) parameters->clone (), result_type, - clone_substs (), get_combined_refs (), + clone_substs (), captures, get_combined_refs (), specified_bounds); } diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index 5eaec352567..b9a1fdfa5c7 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -1628,13 +1628,15 @@ public: ClosureType (HirId ref, DefId id, RustIdent ident, TyTy::TupleType *parameters, TyVar result_type, std::vector subst_refs, + std::set captures, std::set refs = std::set (), std::vector specified_bounds = std::vector ()) : BaseType (ref, ref, TypeKind::CLOSURE, ident, refs), SubstitutionRef (std::move (subst_refs), SubstitutionArgumentMappings::error ()), - parameters (parameters), result_type (std::move (result_type)), id (id) + parameters (parameters), result_type (std::move (result_type)), id (id), + captures (captures) { LocalDefId local_def_id = id.localDefId; rust_assert (local_def_id != UNKNOWN_LOCAL_DEFID); @@ -1644,13 +1646,15 @@ public: ClosureType (HirId ref, HirId ty_ref, RustIdent ident, DefId id, TyTy::TupleType *parameters, TyVar result_type, std::vector subst_refs, + std::set captures, std::set refs = std::set (), std::vector specified_bounds = std::vector ()) : BaseType (ref, ty_ref, TypeKind::CLOSURE, ident, refs), SubstitutionRef (std::move (subst_refs), SubstitutionArgumentMappings::error ()), - parameters (parameters), result_type (std::move (result_type)), id (id) + parameters (parameters), result_type (std::move (result_type)), id (id), + captures (captures) { LocalDefId local_def_id = id.localDefId; rust_assert (local_def_id != UNKNOWN_LOCAL_DEFID); @@ -1699,10 +1703,13 @@ public: void setup_fn_once_output () const; + const std::set &get_captures () const { return captures; } + private: TyTy::TupleType *parameters; TyVar result_type; DefId id; + std::set captures; }; class ArrayType : public BaseType From patchwork Tue Feb 21 12:02:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60052 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1844273wrn; Tue, 21 Feb 2023 04:54:18 -0800 (PST) X-Google-Smtp-Source: AK7set/eCjy3zTljB+bW0sUEplhxT5KtLGRl4ZCS01+CR3fcIhAh5cccg8PpWDNcyNHf0Jw0Th7u X-Received: by 2002:a05:6402:789:b0:4ac:b602:3fa4 with SMTP id d9-20020a056402078900b004acb6023fa4mr4579343edy.17.1676984058418; Tue, 21 Feb 2023 04:54:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984058; cv=none; d=google.com; s=arc-20160816; b=Bp7S/ocqzOdNtXC9z1R3umbjoMY5yMRY6BaoMVxnP+X7vqUgsedJw1DNkUddhwqBtP /ViPkj4o6wo17PQAmLJzdl5wkU4qtgXqFUYZBN9kojpyTK/Bb/uC4pSouw8L85bb6t2l PxaAuJslGeClOX/esLs+qBoiM9EfLy2/JeOzTvKU7ci4VxswbCxeJXTPdobDSCb5sTqb gOaasN9pZYkxydRIlgxBd84nNckYtGbZJtcRSgV4Go4xruIEv8NIFOFNewv7oKrrpGTp rNWGwl2OLcy2xZ87gd3sojb3rztlOR3bGuPHAF4i6iKCVquCuIDGcznYh8/oC5DvZkTT s1qA== 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=z9AvgW17NvT7ot9Owzmvx1hcTo625u6Y6O6ERkvImTk=; b=O0EO2MjjTOPGWczfKqi0BCAZX73GErpYmrXSXaIaU7Ncd+dm1X6dhY4wySvhU8cUDN XfaPuG+oIiBXdl/M9DWI2AOBAWp4q2tevnKPCI+V/g3xT6rrMmeC+NKxgUGaAxZiEZpO DQv0IYq5ijpn3hErnHRbbEwcq8NQ6OKfh+wrDXNp5SJ8ng7Dk9Z9+vHOGj+xpenCLbOC W7ZQEA9Jv6GJVw5NBKZKyf1ftyIEInZbubAfcPUyM6Tyxm4ABHIVYwmWtfsFTXoPNvwr G+q11Nqo2ftNyVWkmiVF6+CYvOynQs2S/yN/091MJ+o8/l0gAi/b3Lgq9KSRTifV+MDi Cggw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b="H/710H0S"; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id z11-20020aa7c64b000000b004ad119f4af3si3346847edr.412.2023.02.21.04.54.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:54:18 -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="H/710H0S"; 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 DBA3F3894C1F for ; Tue, 21 Feb 2023 12:18:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id C7A1D3841832 for ; Tue, 21 Feb 2023 12:04:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C7A1D3841832 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-x435.google.com with SMTP id t13so4091690wrv.13 for ; Tue, 21 Feb 2023 04:04:40 -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=z9AvgW17NvT7ot9Owzmvx1hcTo625u6Y6O6ERkvImTk=; b=H/710H0SXK3sof9diqlPxisO04ZdOoeamBacGC8dWNoS2LX7kV4cvm9CuDAIeJkX/H v7jE752tIK7g+AqS9x/v2SFStt+A90Q3xpc0Zpi0RemQ0OEsza4pITCz1zKcGUDGgK3i GfYi0JdXPbesVSWjVHzCGuZW29cMsyjD4C3DYbPppI9HAVhQqL19k4rsFTZu/oCJqiJM ZIAMALVzZBgJ14FXkrY9ntui2BjKO0B20Uq8CX9k5k6kL+rGzKP3TdC+o5fUApJWA92Q euP5sE6TZdF7YGdqhNaRoxdN4xBLw1M3SE1JZssqsSoYRqVbRYVfQtEb6fc2xKr4phlu kZoQ== 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=z9AvgW17NvT7ot9Owzmvx1hcTo625u6Y6O6ERkvImTk=; b=4V8sd3DoBPLQaTP9dvOKRA0AuBDJSFfmW5/eCxvjyTnwmu/35eaJo2ply8Hp/VSPbC W5pTRjfdu39fCJ4TaKc6VE0kz5V3QciTkXRXSZ4/GDR3Mll7zGYh1h5w+Eyc9TSLuVjJ gONqOnSP8P3MXYkS1kQG04IdGJ/FdvRIS8YLuzhojGjXlptjJ7aDt4UVf+qAGYh+pkTB Msfgsv+M36Xed3RsfX0Z9geBcmgqFz6hqu7ftit3g5jH8edlW57OMQyLSIXNe8SrVN8h VwAJT5qX/JUwM2RYyJqXnMWGHPKWDvUDUH0OBeHqpGzQy+pvLzRHZ1ZFkGhFYLXLG/1+ DWmA== X-Gm-Message-State: AO0yUKU/bA9jr6k2kupre32eHVrg9dLLTvvCicVX9YxhKuKPZ+tx3sSG FwqR33Ebt8W0a+TmGHub3X9Kth8Q86EUCQfQNQ== X-Received: by 2002:a5d:4851:0:b0:2c5:9cb8:d314 with SMTP id n17-20020a5d4851000000b002c59cb8d314mr3499811wrs.56.1676981080156; Tue, 21 Feb 2023 04:04:40 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:39 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 097/103] gccrs: Add initial support for argument capture of closures Date: Tue, 21 Feb 2023 13:02:27 +0100 Message-Id: <20230221120230.596966-98-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.3 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?1758445236341290043?= X-GMAIL-MSGID: =?utf-8?q?1758445236341290043?= From: Philip Herron When we have a closure expression that captures a parent function's variable we must setup the closure data to contain this. Ignoring moveability and mutability requires for now, this patch creates the closure structure with fields for each of the captured variables. When it comes to compilation of the closure expression in order to support nested closures we must setup a context of implicit mappings so that for all path resolution we hit this implicit closure mappings lookups code before any lookup_var_decl as this decl will not exist so the order here is important during path resolution which is a similar problem to match expression destructuring. Fixes #195 gcc/rust/ChangeLog: * backend/rust-compile-context.cc (Context::push_closure_context): New function. (Context::pop_closure_context): Likewise. (Context::insert_closure_binding): Likewise. (Context::lookup_closure_binding): Likewise. * backend/rust-compile-context.h: Declare new functions and closure mappings. * backend/rust-compile-expr.cc (CompileExpr::visit): Visit captures properly. (CompileExpr::generate_closure_function): Compile captures properly. * backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve): Check for closure bindings. * backend/rust-compile-type.cc (TyTyResolveCompile::visit): Compile capture list's types as well. gcc/testsuite/ChangeLog: * rust/execute/torture/closure3.rs: New test. --- gcc/rust/backend/rust-compile-context.cc | 47 +++++++++++++++++ gcc/rust/backend/rust-compile-context.h | 9 ++++ gcc/rust/backend/rust-compile-expr.cc | 50 +++++++++++++++++-- gcc/rust/backend/rust-compile-resolve-path.cc | 8 +++ gcc/rust/backend/rust-compile-type.cc | 31 +++++++++++- .../rust/execute/torture/closure3.rs | 33 ++++++++++++ 6 files changed, 172 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/rust/execute/torture/closure3.rs diff --git a/gcc/rust/backend/rust-compile-context.cc b/gcc/rust/backend/rust-compile-context.cc index b989741fe4b..018897e39b2 100644 --- a/gcc/rust/backend/rust-compile-context.cc +++ b/gcc/rust/backend/rust-compile-context.cc @@ -142,5 +142,52 @@ Context::type_hasher (tree type) return hstate.end (); } +void +Context::push_closure_context (HirId id) +{ + auto it = closure_bindings.find (id); + rust_assert (it == closure_bindings.end ()); + + closure_bindings.insert ({id, {}}); + closure_scope_bindings.push_back (id); +} + +void +Context::pop_closure_context () +{ + rust_assert (!closure_scope_bindings.empty ()); + + HirId ref = closure_scope_bindings.back (); + closure_scope_bindings.pop_back (); + closure_bindings.erase (ref); +} + +void +Context::insert_closure_binding (HirId id, tree expr) +{ + rust_assert (!closure_scope_bindings.empty ()); + + HirId ref = closure_scope_bindings.back (); + closure_bindings[ref].insert ({id, expr}); +} + +bool +Context::lookup_closure_binding (HirId id, tree *expr) +{ + if (closure_scope_bindings.empty ()) + return false; + + HirId ref = closure_scope_bindings.back (); + auto it = closure_bindings.find (ref); + rust_assert (it != closure_bindings.end ()); + + auto iy = it->second.find (id); + if (iy == it->second.end ()) + return false; + + *expr = iy->second; + return true; +} + } // namespace Compile } // namespace Rust diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h index d2d3a53f182..8e8fac80d59 100644 --- a/gcc/rust/backend/rust-compile-context.h +++ b/gcc/rust/backend/rust-compile-context.h @@ -345,6 +345,11 @@ public: return mangler.mangle_item (ty, path); } + void push_closure_context (HirId id); + void pop_closure_context (); + void insert_closure_binding (HirId id, tree expr); + bool lookup_closure_binding (HirId id, tree *expr); + std::vector &get_type_decls () { return type_decls; } std::vector<::Bvariable *> &get_var_decls () { return var_decls; } std::vector &get_const_decls () { return const_decls; } @@ -377,6 +382,10 @@ private: std::map implicit_pattern_bindings; std::map main_variants; + // closure bindings + std::vector closure_scope_bindings; + std::map> closure_bindings; + // To GCC middle-end std::vector type_decls; std::vector<::Bvariable *> var_decls; diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index 8169ba02b84..436fc924a13 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -2829,10 +2829,25 @@ CompileExpr::visit (HIR::ClosureExpr &expr) // lets ignore state capture for now we need to instantiate the struct anyway // then generate the function - std::vector vals; - // TODO - // setup argument captures based on the mode? + for (const auto &capture : closure_tyty->get_captures ()) + { + // lookup the HirId + HirId ref = UNKNOWN_HIRID; + bool ok = ctx->get_mappings ()->lookup_node_to_hir (capture, &ref); + rust_assert (ok); + + // lookup the var decl + Bvariable *var = nullptr; + bool found = ctx->lookup_var_decl (ref, &var); + rust_assert (found); + + // FIXME + // this should bes based on the closure move-ability + tree var_expr = var->get_tree (expr.get_locus ()); + tree val = address_expression (var_expr, expr.get_locus ()); + vals.push_back (val); + } translated = ctx->get_backend ()->constructor_expression (compiled_closure_tyty, false, @@ -2879,8 +2894,29 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr, DECL_ARTIFICIAL (self_param->get_decl ()) = 1; param_vars.push_back (self_param); + // push a new context + ctx->push_closure_context (expr.get_mappings ().get_hirid ()); + // setup the implicit argument captures - // TODO + size_t idx = 0; + for (const auto &capture : closure_tyty.get_captures ()) + { + // lookup the HirId + HirId ref = UNKNOWN_HIRID; + bool ok = ctx->get_mappings ()->lookup_node_to_hir (capture, &ref); + rust_assert (ok); + + // get the assessor + tree binding = ctx->get_backend ()->struct_field_expression ( + self_param->get_tree (expr.get_locus ()), idx, expr.get_locus ()); + tree indirection = indirect_expression (binding, expr.get_locus ()); + + // insert bindings + ctx->insert_closure_binding (ref, indirection); + + // continue + idx++; + } // args tuple tree args_type @@ -2910,7 +2946,10 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr, } if (!ctx->get_backend ()->function_set_parameters (fndecl, param_vars)) - return error_mark_node; + { + ctx->pop_closure_context (); + return error_mark_node; + } // lookup locals HIR::Expr *function_body = expr.get_expr ().get (); @@ -2977,6 +3016,7 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr, gcc_assert (TREE_CODE (bind_tree) == BIND_EXPR); DECL_SAVED_TREE (fndecl) = bind_tree; + ctx->pop_closure_context (); ctx->pop_fn (); ctx->push_function (fndecl); diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc index ab8e628c75c..8857df2f3a5 100644 --- a/gcc/rust/backend/rust-compile-resolve-path.cc +++ b/gcc/rust/backend/rust-compile-resolve-path.cc @@ -121,6 +121,14 @@ ResolvePathRef::resolve (const HIR::PathIdentSegment &final_segment, return constant_expr; } + // maybe closure binding + tree closure_binding = error_mark_node; + if (ctx->lookup_closure_binding (ref, &closure_binding)) + { + TREE_USED (closure_binding) = 1; + return closure_binding; + } + // this might be a variable reference or a function reference Bvariable *var = nullptr; if (ctx->lookup_var_decl (ref, &var)) diff --git a/gcc/rust/backend/rust-compile-type.cc b/gcc/rust/backend/rust-compile-type.cc index 824cb3a56ef..c8e1d3b4036 100644 --- a/gcc/rust/backend/rust-compile-type.cc +++ b/gcc/rust/backend/rust-compile-type.cc @@ -19,6 +19,7 @@ #include "rust-compile-type.h" #include "rust-compile-expr.h" #include "rust-constexpr.h" +#include "rust-gcc.h" #include "tree.h" @@ -99,11 +100,39 @@ TyTyResolveCompile::visit (const TyTy::InferType &) void TyTyResolveCompile::visit (const TyTy::ClosureType &type) { + auto mappings = ctx->get_mappings (); + std::vector fields; + + size_t i = 0; + for (const auto &capture : type.get_captures ()) + { + // lookup the HirId + HirId ref = UNKNOWN_HIRID; + bool ok = mappings->lookup_node_to_hir (capture, &ref); + rust_assert (ok); + + // lookup the var decl type + TyTy::BaseType *lookup = nullptr; + bool found = ctx->get_tyctx ()->lookup_type (ref, &lookup); + rust_assert (found); + + // FIXME get the var pattern name + std::string mappings_name = "capture_" + std::to_string (i); + + // FIXME + // this should be based on the closure move-ability + tree decl_type = TyTyResolveCompile::compile (ctx, lookup); + tree capture_type = build_reference_type (decl_type); + fields.push_back (Backend::typed_identifier (mappings_name, capture_type, + type.get_ident ().locus)); + } + tree type_record = ctx->get_backend ()->struct_type (fields); RS_CLOSURE_FLAG (type_record) = 1; - std::string named_struct_str = type.get_ident ().path.get () + "{{closure}}"; + std::string named_struct_str + = type.get_ident ().path.get () + "::{{closure}}"; translated = ctx->get_backend ()->named_type (named_struct_str, type_record, type.get_ident ().locus); } diff --git a/gcc/testsuite/rust/execute/torture/closure3.rs b/gcc/testsuite/rust/execute/torture/closure3.rs new file mode 100644 index 00000000000..62cf3a082cf --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/closure3.rs @@ -0,0 +1,33 @@ +// { dg-output "3\n" } +extern "C" { + fn printf(s: *const i8, ...); +} + +#[lang = "fn_once"] +pub trait FnOnce { + #[lang = "fn_once_output"] + type Output; + + extern "rust-call" fn call_once(self, args: Args) -> Self::Output; +} + +fn f i32>(g: F) { + let call = g(1); + unsafe { + let a = "%i\n\0"; + let b = a as *const str; + let c = b as *const i8; + + printf(c, call); + } +} + +pub fn main() -> i32 { + let capture = 2; + let a = |i: i32| { + let b = i + capture; + b + }; + f(a); + 0 +} From patchwork Tue Feb 21 12:02:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60080 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1850665wrn; Tue, 21 Feb 2023 05:06:03 -0800 (PST) X-Google-Smtp-Source: AK7set8CaSfeH4PyKKFwXoxicj/r6fU84N0+OT/y6albDtOBNxVH9qfm+cqH2tfH5YZjIjq8XbpA X-Received: by 2002:a17:906:f1c9:b0:877:7113:71f3 with SMTP id gx9-20020a170906f1c900b00877711371f3mr10270909ejb.25.1676984763080; Tue, 21 Feb 2023 05:06:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984763; cv=none; d=google.com; s=arc-20160816; b=LOQilUIb9NhNty9Gudncgm+ENePcDrsfGPX+rkY4XsL00RAsy5jwC65cUgXGUGFz2r oHhQUMh0EdzwW89JkSvJLOQfO3lHpWpLAiEkxXe414XdsyvZuiZreP835lBZYV/CEKh1 NNDgzfFVKDGNxdZe859dOiWPEXBlCszMGpoXUDjGeUccHcHBF7NTskC9eAp+2HF3d6pY pHMWk4OQK4zwpFtZlRXLTN9rher4BsI7hDwB3lt9cXx6coMmzbxhRKTMuVd1f5BJo2QT bVqYFMMRcB/YipIjObTeeofgQPh0mhQ9iKTsbO039h3HhvTLjvSxwzBVfU9GZAvaO915 L5lA== 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=vSNpzZvOilzKYGsnAcxKb5BlI9LPoMsUF3u+FaUOnzY=; b=Qr13hSeqkEoHdo9i09t6oWTEFMf3pTKzHxi82X2xgSKuXtwJfPjUE+K/S0pY41a4Cx h7NqycotFSHnafUEGZWHLqLZJXlPj3dSXJhPrIkCQIdd5cluhHrRbvbFm+dshBtaFHc5 TUKBjrXVqNHwBVLzE+YTjjBVd8T6EsJRcQLow8m11VaEosFDgSbZ3GAw/YKmd+7ubT7K +i8sgiynuoY4AP8bJxkeXN3LiK9KvpVfOuDuBeXaFJTcvdp+xcRPXIPYXSLlggXq7kQ/ kSFo6Il6yp+dVi+DuNeomVUn4YwvHkEDlkoEe3kDE5tQnr7Yo2IUhjPwhvbI3a7gQKAD f/1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=WcNkBANs; 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 y20-20020a170906519400b008b7eed5fa1bsi13624530ejk.737.2023.02.21.05.06.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 05:06:03 -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=WcNkBANs; 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 AA0A4389F86F for ; Tue, 21 Feb 2023 12:25:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 727DD382E695 for ; Tue, 21 Feb 2023 12:04:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 727DD382E695 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-x42e.google.com with SMTP id t13so4091731wrv.13 for ; Tue, 21 Feb 2023 04:04:41 -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=vSNpzZvOilzKYGsnAcxKb5BlI9LPoMsUF3u+FaUOnzY=; b=WcNkBANsIk8weDdyOyWqyK6jti0OKsy2hSCbA+bU/uYMIxaGaKK5r6R/BcsPrApWEk N0IUQR3g2eApaQiSjTIEyb3dSJDDPpHWSkRqDexPVm++c23pcrtYWYaZhyFwF5MwgjZJ YgbLavybtn0+f5kx8BqOlPr+od6bltjBxd6D5bL1bKOo1c07NHeOIzqxFbXXdEQGq/u7 3mqfw1bHAL9HkpqoGh3P1lc3tdsBy7bbrF4H76p59K070d3M15OEUEzQfzYEHu3BbWyR qnWEHNRYyclSPPk/V/5V5RViU2iVGNW1n5R9aVHG8qMdGmRZO6qSQ0lH40CMi9OSztrH U2iQ== 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=vSNpzZvOilzKYGsnAcxKb5BlI9LPoMsUF3u+FaUOnzY=; b=U4jxGBEtfSoGl6JZfPQq+nrNxhAgHFlIOMEveq5cAnsGufHXOHVLv0hDXF6Q6/xqon ST7IhaCmTINvGqk3ohztjJOsWb7JfGtGllfNu08l+Si0OhciTxXg9cDckQLS4FADnKxR K+1LZgMU5N7mwPnkuaNl1lh/PSak/i1HlPa/3egBHENHttcCqlFUtXawRufL3683BYmo IPGBMFJf8gNqTlRFW5hi062KcXU3Gv5apDejeb7ZJ5Wm9Gm/5HAi4EanBa6nqRVq0xk7 MZlb6i3TCP4cM5EPqn7cj1mrpNPnwzI5zQEVHt3LycvaHi1PrJ6LrXUPQfbAxb7OmYtu SLuw== X-Gm-Message-State: AO0yUKV1BF5EsHsUlS/DIsUkuPGtGXxiSwAohZyPYIIzHygF/kwjc3ij RzejAtTLogXiEYotw5BZmbtNIrgIrVCHLvQCzQ== X-Received: by 2002:adf:fb49:0:b0:2c6:6e35:4414 with SMTP id c9-20020adffb49000000b002c66e354414mr4289681wrs.6.1676981080786; Tue, 21 Feb 2023 04:04:40 -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.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:40 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 098/103] gccrs: Fix undefined behaviour issues on macos Date: Tue, 21 Feb 2023 13:02:28 +0100 Message-Id: <20230221120230.596966-99-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.3 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?1758445975164739384?= X-GMAIL-MSGID: =?utf-8?q?1758445975164739384?= From: Philip Herron This adds missing copy constructors to HIR::PathExprSegment which were wrongly defaulting to empty vectors when apply specified generic arguments to method calls. gcc/rust/ChangeLog: * hir/tree/rust-hir-expr.h: Add const `get_method_name`. * hir/tree/rust-hir-full-decls.h (struct GenericArgs): Move from `struct`... (class GenericArgs): ...to `class`. * hir/tree/rust-hir-path.h (struct GenericArgs): Likewise. (class GenericArgs): Clear `type_args` in copy constructor. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Reorder debug print. * typecheck/rust-tyty.h: Add default constructors for `SubstitutionArgumentMappings`. --- gcc/rust/hir/tree/rust-hir-expr.h | 3 +- gcc/rust/hir/tree/rust-hir-full-decls.h | 2 +- gcc/rust/hir/tree/rust-hir-path.h | 37 ++++++++++++++----- .../typecheck/rust-hir-type-check-expr.cc | 5 ++- gcc/rust/typecheck/rust-tyty.h | 4 ++ 5 files changed, 38 insertions(+), 13 deletions(-) diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h index 227bacbe641..cc884420bef 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -1872,7 +1872,8 @@ public: std::unique_ptr &get_receiver () { return receiver; } - PathExprSegment get_method_name () const { return method_name; }; + PathExprSegment &get_method_name () { return method_name; }; + const PathExprSegment &get_method_name () const { return method_name; }; size_t num_params () const { return params.size (); } diff --git a/gcc/rust/hir/tree/rust-hir-full-decls.h b/gcc/rust/hir/tree/rust-hir-full-decls.h index 70ee7538298..7870a5497ed 100644 --- a/gcc/rust/hir/tree/rust-hir-full-decls.h +++ b/gcc/rust/hir/tree/rust-hir-full-decls.h @@ -43,7 +43,7 @@ class PathExpr; // rust-path.h class PathIdentSegment; struct GenericArgsBinding; -struct GenericArgs; +class GenericArgs; class PathExprSegment; class PathPattern; class PathInExpression; diff --git a/gcc/rust/hir/tree/rust-hir-path.h b/gcc/rust/hir/tree/rust-hir-path.h index fa8347b2cf8..17eedb8d741 100644 --- a/gcc/rust/hir/tree/rust-hir-path.h +++ b/gcc/rust/hir/tree/rust-hir-path.h @@ -140,8 +140,7 @@ private: Location locus; }; -// Generic arguments allowed in each path expression segment - inline? -struct GenericArgs +class GenericArgs { std::vector lifetime_args; std::vector > type_args; @@ -172,6 +171,7 @@ public: : lifetime_args (other.lifetime_args), binding_args (other.binding_args), const_args (other.const_args), locus (other.locus) { + type_args.clear (); type_args.reserve (other.type_args.size ()); for (const auto &e : other.type_args) @@ -188,6 +188,7 @@ public: const_args = other.const_args; locus = other.locus; + type_args.clear (); type_args.reserve (other.type_args.size ()); for (const auto &e : other.type_args) type_args.push_back (e->clone_type ()); @@ -235,26 +236,44 @@ private: Location locus; public: - // Returns true if there are any generic arguments - bool has_generic_args () const { return generic_args.has_generic_args (); } - - // Constructor for segment (from IdentSegment and GenericArgs) PathExprSegment (Analysis::NodeMapping mappings, - PathIdentSegment segment_name, Location locus = Location (), - GenericArgs generic_args = GenericArgs::create_empty ()) + PathIdentSegment segment_name, Location locus, + GenericArgs generic_args) : mappings (std::move (mappings)), segment_name (std::move (segment_name)), generic_args (std::move (generic_args)), locus (locus) {} + PathExprSegment (PathExprSegment const &other) + : mappings (other.mappings), segment_name (other.segment_name), + generic_args (other.generic_args), locus (other.locus) + {} + + PathExprSegment &operator= (PathExprSegment const &other) + { + mappings = other.mappings; + segment_name = other.segment_name; + generic_args = other.generic_args; + locus = other.locus; + + return *this; + } + + // move constructors + PathExprSegment (PathExprSegment &&other) = default; + PathExprSegment &operator= (PathExprSegment &&other) = default; + std::string as_string () const; Location get_locus () const { return locus; } - PathIdentSegment get_segment () const { return segment_name; } + PathIdentSegment &get_segment () { return segment_name; } + const PathIdentSegment &get_segment () const { return segment_name; } GenericArgs &get_generic_args () { return generic_args; } const Analysis::NodeMapping &get_mappings () const { return mappings; } + + bool has_generic_args () const { return generic_args.has_generic_args (); } }; // HIR node representing a pattern that involves a "path" - abstract base class diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc index 0b0db3296a0..5c43cc8c7b4 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc @@ -1149,10 +1149,11 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr) // apply any remaining generic arguments if (expr.get_method_name ().has_generic_args ()) { - rust_debug_loc (expr.get_method_name ().get_generic_args ().get_locus (), + HIR::GenericArgs &args = expr.get_method_name ().get_generic_args (); + rust_debug_loc (args.get_locus (), "applying generic arguments to method_call: {%s}", lookup->debug_str ().c_str ()); - HIR::GenericArgs &args = expr.get_method_name ().get_generic_args (); + lookup = SubstMapper::Resolve (lookup, expr.get_method_name ().get_locus (), &args); diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index b9a1fdfa5c7..0fd664c8d46 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -699,6 +699,10 @@ public: return *this; } + SubstitutionArgumentMappings (SubstitutionArgumentMappings &&other) = default; + SubstitutionArgumentMappings &operator= (SubstitutionArgumentMappings &&other) + = default; + static SubstitutionArgumentMappings error () { return SubstitutionArgumentMappings ({}, Location (), nullptr, false); From patchwork Tue Feb 21 12:02:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60065 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1847033wrn; Tue, 21 Feb 2023 05:00:34 -0800 (PST) X-Google-Smtp-Source: AK7set/6Txugggw/k7y3QCa51AfyBO7LoxuZe0IY55gsuCE+ldKcgOXGP8YDZ4o2XdTL6bXaA9z2 X-Received: by 2002:a05:6402:51:b0:4af:5968:bcbc with SMTP id f17-20020a056402005100b004af5968bcbcmr805872edu.28.1676984434288; Tue, 21 Feb 2023 05:00:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984434; cv=none; d=google.com; s=arc-20160816; b=KGXc6zJtVmD66cUSfuGoEK9Kmg2BvG9dom05FYdPbPTW+USeSCq/rR13rqMIz1KV87 A0H3YySZR1e98U6NW2BU0UXNjtDXWcZb8PFuIc6Uw84HEuar+zIX3TkhvsNWkwyCrxou DqFg8Zca1xlrMAOc1W3HIqqQGqXpAW6PEzDWXcqUWau0PYXCTmN3j50a7d/7ni+jJLxv ErMYFXo2HPdx15wlluSrHi1W5zmr8CEEWLn5f4LzuLiWxFk3lGYxZMjBKMTWVU9hy4zO nZZk7wH1E4LIbsy12PIwQt5KgXGLzCt3jSyWvgm/cjkiiTc84y21rvWyiFleKXpt+uZR H6ew== 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=btPqZn/2MjkCOOQi3xvqC9JuoeuiSEbiS/7KwLwEqAw=; b=TB5iNgN2lYXypUyODMbqTkih+UsrBFtZ4VI2kBk3n9dzHDYohWwIA7uGKrij/jVvrI tt92dqlc9g2iqiibonK8inkaqr8yt9lr55pHFgdwHeSoSyTFKhkq7PUQ4X2dhLnzZ02D AvSuVCXJWeoRCY+NM6Php3sI9kqXU4e9WFAHRvWWGy5U7rGpqLKP6iBx/zApAMI58H3m RpZrBrpa5NnSxs1f1rb1AVgStm8DUnuTl/gGJ6f/j1pXcFhwaLWdjaYjFKOWfHjDZnEi gBqlTBWRnIvbW6uPM1AhbPV/0zci+PHI3j0dqCJq87sLclzgp0qHK5n7KZ61kf+bFZio qpdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Tuj6ZXkC; 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 g13-20020a50ee0d000000b004ab4cfc203dsi329738eds.380.2023.02.21.05.00.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 05:00:34 -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=Tuj6ZXkC; 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 CD597398DE7B for ; Tue, 21 Feb 2023 12:21:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 0C54C3885C03 for ; Tue, 21 Feb 2023 12:04:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0C54C3885C03 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-x42f.google.com with SMTP id l1so3888408wry.10 for ; Tue, 21 Feb 2023 04:04:42 -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=btPqZn/2MjkCOOQi3xvqC9JuoeuiSEbiS/7KwLwEqAw=; b=Tuj6ZXkCN7SLJSKZcDi8ADnu/E5349Q85U//1KouEp9nXgmFvXUlSagr3qNlFgikh0 R1Te0hoK2lxnXNfiCFOUGmR1bQ7GJInGmrk5FhjAghew4289858J9NXJebMd7fBm3s1n 07ajdk2wosJ3aKsCpNrHdk2881b9JG7ABMkF1JHbeSXyixVKGucIyqS2f2MOfoCNgFXy iaNmQTwXzm8bJNtaKTYtO2L9K+5LYgYY1Dd3gbqT5kqfbSUctO81poCzGe9XoUFI/CpE iZNSQs2CQaaauWb9/ZTYZPh0bOfXaN95h817wYk8W9ANNXATLkj7/e4hFJOzGypdGR7j Z8Sw== 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=btPqZn/2MjkCOOQi3xvqC9JuoeuiSEbiS/7KwLwEqAw=; b=vPjL0Vx1XOQ55XtPs0fb8QaMzNk0pBqXx8xNP98PG1h7g+8VKAeHzpbVHAmEDVJMXW vYjhPUnZJOLWxVjQ24FTHpIjR4lxKNFgYQJGNmpsItthmilxJRNTYeqjfhe+MFcuD3E/ nJ7yPWhaQqf8dlALtJZoOGa4aMZ1uL15ExJWDNFR/qvGqXGruiphq32Pc6Wp2ygOj5rW A3SoJIFPwbgoTH4keyR6I9Njs0Di8rmU5wkaw5XqhKnYs1MiPDtwRmgQa+YOTsDnMIIU 4xqokIWLBmw/z4c50Przn1aXYAwvhUVdcPZc+sAnJDl/FLY4EVA7iP9RqAlvLnFnfCjY Xqog== X-Gm-Message-State: AO0yUKWsH/48MDDyQ7QhJUUl2VhTPa7sIeug8pdjP2JKvNZU3b5iAbE3 d2zxJaWdmpd6Sz2rXK2/Frelc+3mV4VJs/ztIA== X-Received: by 2002:adf:d08f:0:b0:2c6:e87f:f19 with SMTP id y15-20020adfd08f000000b002c6e87f0f19mr3641852wrh.57.1676981081439; Tue, 21 Feb 2023 04:04:41 -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.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:41 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 099/103] gccrs: Skip this debug test case which is failing on the latest mac-os devtools and its only for debug info Date: Tue, 21 Feb 2023 13:02:29 +0100 Message-Id: <20230221120230.596966-100-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?1758445630120388390?= X-GMAIL-MSGID: =?utf-8?q?1758445630120388390?= From: Philip Herron gcc/testsuite/ChangeLog: * rust/debug/chartype.rs: Skip testcases on Darwin architectures. --- gcc/testsuite/rust/debug/chartype.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/gcc/testsuite/rust/debug/chartype.rs b/gcc/testsuite/rust/debug/chartype.rs index 69e7ab0b17f..3300925d4e0 100644 --- a/gcc/testsuite/rust/debug/chartype.rs +++ b/gcc/testsuite/rust/debug/chartype.rs @@ -1,10 +1,11 @@ -// 'char' should use DW_ATE_UTF -fn main () { - let c = 'x'; // { dg-do compile } -// Use -w to avoid warnings about the unused variables -// DW_ATE_UTF entered in DWARF 4. +// { dg-skip-if "see https://github.com/Rust-GCC/gccrs/pull/1632" { *-*-darwin* } } // { dg-options "-w -gdwarf-4 -dA" } -// DW_ATE_UTF = 0x10 -// { dg-final { scan-assembler "0x10\[ \t]\[^\n\r]* DW_AT_encoding" } } */ +// 'char' should use DW_ATE_UTF +fn main() { + let c = 'x'; + // Use -w to avoid warnings about the unused variables + // DW_ATE_UTF entered in DWARF 4. + // DW_ATE_UTF = 0x10 + // { dg-final { scan-assembler "0x10\[ \t]\[^\n\r]* DW_AT_encoding" } } */ } From patchwork Tue Feb 21 12:02:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60061 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1846243wrn; Tue, 21 Feb 2023 04:58:46 -0800 (PST) X-Google-Smtp-Source: AK7set+uI8iSGNk1sn+V4Zi9Ra4KUjZ0TWIzrDfErjleUpyTpsgh++NMiEPM0UruvvIR+nfZxBSO X-Received: by 2002:a17:906:81ce:b0:888:6294:a1fa with SMTP id e14-20020a17090681ce00b008886294a1famr14478236ejx.14.1676984326293; Tue, 21 Feb 2023 04:58:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984326; cv=none; d=google.com; s=arc-20160816; b=RnTFjWGocxNayNK0T7w3oLTUY+rePrcIs403el/aSN9VK9Mj8ULMeD7EB2Zc4v1PwG NPSas9PlQtBrIB4GBpA9pN7+NgU8E+xPF81MFBqAuAeAMjOxwb5jzYfK0VttjClja+Sp 92hHCB3WNLAg8qmbtBtRyGhYTKxEcA6vVV+khKwMRm5qQGI60Op8Tsk524bHejZl8uBv gSkvTdE8boA89yp9jImpRmtORX9DmQ2PxnDJzU6qGcyU9nMNbjDfoQUSqR5Vq65GkY9E mRb8Pa0c/GGI4KVL/CM8UDxNahFyvyGEBEicu9QaeIZZdUl3WuOXLS/DLb/Vw/Ep3L9A RwWg== 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=Nd5wpyvFm9PX5M7bVKGxlEFLVOWCCXxnBB0ZN5+EoP0=; b=tWIB8i3FdawSVg28ITcJPFCpKWo7rjBOVdoDKxJe3vBcKvE+xbzMwgWysixGCnHJz5 55t5mpnx4f+U6QEkIwdCqHo5qFF4QC1ANTrtrhKTfH2pJfM3ilqQt/NhRUI98uM3UXlY WCwbeS1g0rxYhgVK9pdwyE+a7RaLX+klBuM7cMlyVIXgMUvrHnB2Jh2WDYkq1t5Kv6bd JxEVuNqvsuoxw/zb7syDPYRv2bUDXQMssiII9V2KWQIESTjPowaJlu1SyVrcf3KsDaXI vR7saFQ2Bje7ueEg9DaaeM1BoNVTcRSHbDcJ7md5LycK5XIhyjCRbMPPyr25pYQdco3j 0G1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=cyGM2yxm; 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 x4-20020aa7d6c4000000b004ad152b8f57si17787904edr.552.2023.02.21.04.58.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:58:46 -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=cyGM2yxm; 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 953E039E4F7A for ; Tue, 21 Feb 2023 12:20:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id 7981D3889E34 for ; Tue, 21 Feb 2023 12:04:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7981D3889E34 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-x330.google.com with SMTP id l7-20020a05600c1d0700b003dc4050c94aso2978136wms.4 for ; Tue, 21 Feb 2023 04:04:44 -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=Nd5wpyvFm9PX5M7bVKGxlEFLVOWCCXxnBB0ZN5+EoP0=; b=cyGM2yxmhjdIsXgbes5Ev9mln/+JzKUELa5KxbVOY8MlZeVTyHPXarg4vu0IZBIT+7 RlUFufcTEcKr4N4Nvjnswdbk8pojhB8m4s2yFTk7hVMnAQ4vEqgddAFmoJRvD/EB+hI1 AiqXbJ46OBKicw7n6D1btnG4eFnKyplw12AvNtfhv36F+R62QPhIzaxIKCkvdNRFqFb9 zY8qnhb9U5K7EtcJhjZrVwhaksIXdVTsnf2d8P+Mnky4FQ9tZQqY+cuUDYh0gdCqQBRe IK1oAVraZSaFCWRAZGwcCYZDBAphbVApqgMXH6txebNoi3IxutG3HH7zJcpjXTEHNiqS efqA== 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=Nd5wpyvFm9PX5M7bVKGxlEFLVOWCCXxnBB0ZN5+EoP0=; b=eBGTZRkAKOJa+Sopy46DQzRp/fS5qKcequFQ+GpW10/Y2lMSq0wUKfzd0Vm0mInJkb lZELJeuJOXJnQqrGiTFE9ZHUbU61dz2teXaSQCTV4S/yMGaIn1ARchekluACA88Ci/Xd H/7gIqxzLDImZ+lc8xc1JT+wj98C+TPYTUSjmsOShW+qTE2HAYdDXgsAhCsl449aFY1/ 0NXewLU2O6aCfm9kLD8qcRnj4VlmLfaM5rvFMq7gELCM4ogHEidP0iVW8y9wC4nsoAYt d/WIdyI6BcOQIfSAwJzMF9y/eSCgxH5u78JHJxWuquZAEE9+K5dYed3knW4pyI/Z6PZe bGdQ== X-Gm-Message-State: AO0yUKUOevzqyJoPOinLFwIASpo3aN6v8/MQBLbxwOfcUdDBdDwdeSsv dSLhcYjXO7gAK6WHG8ST4kSG01tgTwzZ4dhYuA== X-Received: by 2002:a05:600c:3088:b0:3d3:49db:9b25 with SMTP id g8-20020a05600c308800b003d349db9b25mr3569648wmn.26.1676981082339; Tue, 21 Feb 2023 04:04:42 -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.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:41 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 100/103] gccrs: Cleanup unused parameters to fix the bootstrap build Date: Tue, 21 Feb 2023 13:02:30 +0100 Message-Id: <20230221120230.596966-101-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?1758445516815484138?= X-GMAIL-MSGID: =?utf-8?q?1758445516815484138?= From: Philip Herron gcc/rust/ChangeLog: * backend/rust-compile-type.cc (TyTyResolveCompile::visit): Remove unused parameters. * backend/rust-constexpr.cc (constant_value_1): Likewise. (fold_non_dependent_init): Likewise. * backend/rust-tree.cc (publicly_uniquely_derived_p): Likewise. (instantiation_dependent_expression_p): Likewise. (type_has_nontrivial_copy_init): Likewise. (is_normal_capture_proxy): Likewise. (resolve_nondeduced_context): Likewise. (undeduced_auto_decl): Likewise. (require_deduced_type): Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise. * checks/errors/privacy/rust-reachability.cc (ReachabilityVisitor::visit): Likewise. * checks/errors/privacy/rust-visibility-resolver.cc (VisibilityResolver::visit): Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/lints/rust-lint-marklive.cc (MarkLive::go): Likewise. * checks/lints/rust-lint-unused-var.cc (unused_var_walk_fn): Likewise. * expand/rust-macro-builtins.cc (try_expand_single_string_literal): Likewise. (try_expand_many_expr): Likewise. (parse_single_string_literal): Likewise. (MacroBuiltin::assert_handler): Likewise. (MacroBuiltin::file_handler): Likewise. (MacroBuiltin::column_handler): Likewise. (MacroBuiltin::concat_handler): Likewise. (MacroBuiltin::env_handler): Likewise. (MacroBuiltin::line_handler): Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise. (ASTLoweringBase::handle_doc_item_attribute): Likewise. * hir/rust-hir-dump.cc (Dump::visit): Likewise. * hir/tree/rust-hir-full-test.cc (ConstGenericParam::accept_vis): Likewise. * lex/rust-lex.cc (Lexer::parse_utf8_escape): Likewise. (Lexer::parse_string): Likewise. (Lexer::parse_char_or_lifetime): Likewise. * lex/rust-lex.h: Likewise. * metadata/rust-export-metadata.cc: Likewise. * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Likewise. * resolve/rust-ast-resolve-type.cc (ResolveType::visit): Likewise. (ResolveTypeToCanonicalPath::visit): Likewise. * resolve/rust-ast-verify-assignee.h: Likewise. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise. * typecheck/rust-hir-type-check-expr.h: Likewise. * typecheck/rust-hir-type-check-item.h: Likewise. * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Likewise. * typecheck/rust-tyty-rules.h: Likewise. * util/rust-attributes.cc (AttributeChecker::visit): Likewise. --- gcc/rust/backend/rust-compile-type.cc | 8 +- gcc/rust/backend/rust-constexpr.cc | 6 +- gcc/rust/backend/rust-tree.cc | 38 +- .../errors/privacy/rust-privacy-reporter.cc | 58 +-- .../errors/privacy/rust-reachability.cc | 4 +- .../privacy/rust-visibility-resolver.cc | 8 +- gcc/rust/checks/errors/rust-const-checker.cc | 132 +++---- gcc/rust/checks/errors/rust-unsafe-checker.cc | 142 +++---- gcc/rust/checks/lints/rust-lint-marklive.cc | 2 +- gcc/rust/checks/lints/rust-lint-unused-var.cc | 2 +- gcc/rust/expand/rust-macro-builtins.cc | 20 +- gcc/rust/hir/rust-ast-lower-base.cc | 352 +++++++++--------- gcc/rust/hir/rust-hir-dump.cc | 4 +- gcc/rust/hir/tree/rust-hir-full-test.cc | 2 +- gcc/rust/lex/rust-lex.cc | 6 +- gcc/rust/lex/rust-lex.h | 2 +- gcc/rust/metadata/rust-export-metadata.cc | 24 +- gcc/rust/resolve/rust-ast-resolve-expr.cc | 6 +- gcc/rust/resolve/rust-ast-resolve-type.cc | 6 +- gcc/rust/resolve/rust-ast-verify-assignee.h | 8 +- gcc/rust/resolve/rust-early-name-resolver.cc | 120 +++--- gcc/rust/typecheck/rust-hir-type-check-expr.h | 32 +- gcc/rust/typecheck/rust-hir-type-check-item.h | 4 +- .../typecheck/rust-hir-type-check-pattern.cc | 10 +- gcc/rust/typecheck/rust-tyty-rules.h | 48 +-- gcc/rust/util/rust-attributes.cc | 312 ++++++++-------- 26 files changed, 661 insertions(+), 695 deletions(-) diff --git a/gcc/rust/backend/rust-compile-type.cc b/gcc/rust/backend/rust-compile-type.cc index c8e1d3b4036..a1db6ade9fb 100644 --- a/gcc/rust/backend/rust-compile-type.cc +++ b/gcc/rust/backend/rust-compile-type.cc @@ -428,7 +428,7 @@ TyTyResolveCompile::visit (const TyTy::SliceType &type) } void -TyTyResolveCompile::visit (const TyTy::BoolType &type) +TyTyResolveCompile::visit (const TyTy::BoolType &) { translated = ctx->get_backend ()->named_type ("bool", @@ -532,7 +532,7 @@ TyTyResolveCompile::visit (const TyTy::FloatType &type) } void -TyTyResolveCompile::visit (const TyTy::USizeType &type) +TyTyResolveCompile::visit (const TyTy::USizeType &) { translated = ctx->get_backend ()->named_type ( "usize", @@ -542,7 +542,7 @@ TyTyResolveCompile::visit (const TyTy::USizeType &type) } void -TyTyResolveCompile::visit (const TyTy::ISizeType &type) +TyTyResolveCompile::visit (const TyTy::ISizeType &) { translated = ctx->get_backend ()->named_type ( "isize", @@ -552,7 +552,7 @@ TyTyResolveCompile::visit (const TyTy::ISizeType &type) } void -TyTyResolveCompile::visit (const TyTy::CharType &type) +TyTyResolveCompile::visit (const TyTy::CharType &) { translated = ctx->get_backend ()->named_type ("char", diff --git a/gcc/rust/backend/rust-constexpr.cc b/gcc/rust/backend/rust-constexpr.cc index 23d940d04ce..912d73b5d7c 100644 --- a/gcc/rust/backend/rust-constexpr.cc +++ b/gcc/rust/backend/rust-constexpr.cc @@ -3996,8 +3996,7 @@ constexpr_fn_retval (const constexpr_ctx *ctx, tree body) // return an aggregate constant. If UNSHARE_P, return an unshared // copy of the initializer. static tree -constant_value_1 (tree decl, bool strict_p, bool return_aggregate_cst_ok_p, - bool unshare_p) +constant_value_1 (tree decl, bool, bool, bool unshare_p) { while (TREE_CODE (decl) == CONST_DECL) { @@ -6478,8 +6477,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, /* Like maybe_constant_init but first fully instantiate the argument. */ tree -fold_non_dependent_init (tree t, - tsubst_flags_t complain /*=tf_warning_or_error*/, +fold_non_dependent_init (tree t, tsubst_flags_t /*=tf_warning_or_error*/, bool manifestly_const_eval /*=false*/, tree object /* = NULL_TREE */) { diff --git a/gcc/rust/backend/rust-tree.cc b/gcc/rust/backend/rust-tree.cc index d2d170c23f1..8243d4cf5c6 100644 --- a/gcc/rust/backend/rust-tree.cc +++ b/gcc/rust/backend/rust-tree.cc @@ -2060,11 +2060,7 @@ rs_tree_equal (tree t1, tree t2) /* TRUE iff TYPE is publicly & uniquely derived from PARENT. */ -bool -publicly_uniquely_derived_p (tree parent, tree type) -{ - return false; -} +bool publicly_uniquely_derived_p (tree, tree) { return false; } // forked from gcc/cp/typeck.cc comp_except_types @@ -3344,11 +3340,7 @@ release_tree_vector (vec *vec) /* As above, but also check value-dependence of the expression as a whole. */ -bool -instantiation_dependent_expression_p (tree expression) -{ - return false; -} +bool instantiation_dependent_expression_p (tree) { return false; } // forked from gcc/cp/cvt.cc cp_get_callee @@ -3398,11 +3390,7 @@ scalarish_type_p (const_tree t) constructors are deleted. This function implements the ABI notion of non-trivial copy, which has diverged from the one in the standard. */ -bool -type_has_nontrivial_copy_init (const_tree type) -{ - return false; -} +bool type_has_nontrivial_copy_init (const_tree) { return false; } // forked from gcc/cp/tree.cc build_local_temp @@ -3425,11 +3413,7 @@ build_local_temp (tree type) /* Returns true iff DECL is a capture proxy for a normal capture (i.e. without explicit initializer). */ -bool -is_normal_capture_proxy (tree decl) -{ - return false; -} +bool is_normal_capture_proxy (tree) { return false; } // forked from gcc/cp/c-common.cc reject_gcc_builtin @@ -3694,7 +3678,7 @@ char_type_p (tree type) lvalue for the function template specialization. */ tree -resolve_nondeduced_context (tree orig_expr, tsubst_flags_t complain) +resolve_nondeduced_context (tree orig_expr, tsubst_flags_t) { return orig_expr; } @@ -3973,21 +3957,13 @@ decl_constant_var_p (tree decl) /* Returns true iff DECL is a variable or function declared with an auto type that has not yet been deduced to a real type. */ -bool -undeduced_auto_decl (tree decl) -{ - return false; -} +bool undeduced_auto_decl (tree) { return false; } // forked from gcc/cp/decl.cc require_deduced_type /* Complain if DECL has an undeduced return type. */ -bool -require_deduced_type (tree decl, tsubst_flags_t complain) -{ - return true; -} +bool require_deduced_type (tree, tsubst_flags_t) { return true; } /* Return the location of a tree passed to %+ formats. */ diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc index a126e7b4462..7417f31b510 100644 --- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc +++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc @@ -226,7 +226,7 @@ PrivacyReporter::visit (HIR::PathInExpression &path) } void -PrivacyReporter::visit (HIR::TypePathSegmentFunction &segment) +PrivacyReporter::visit (HIR::TypePathSegmentFunction &) { // FIXME: Do we need to do anything for this? } @@ -253,7 +253,7 @@ PrivacyReporter::visit (HIR::QualifiedPathInType &path) } void -PrivacyReporter::visit (HIR::LiteralExpr &expr) +PrivacyReporter::visit (HIR::LiteralExpr &) { // Literals cannot contain any sort of privacy violation } @@ -371,13 +371,13 @@ PrivacyReporter::visit (HIR::TupleIndexExpr &expr) } void -PrivacyReporter::visit (HIR::StructExprStruct &expr) +PrivacyReporter::visit (HIR::StructExprStruct &) { // FIXME: We need to check the visibility of the type it refers to here } void -PrivacyReporter::visit (HIR::StructExprFieldIdentifier &field) +PrivacyReporter::visit (HIR::StructExprFieldIdentifier &) {} void @@ -426,7 +426,7 @@ PrivacyReporter::visit (HIR::FieldAccessExpr &expr) } void -PrivacyReporter::visit (HIR::ClosureExpr &expr) +PrivacyReporter::visit (HIR::ClosureExpr &) { // Not handled yet } @@ -443,7 +443,7 @@ PrivacyReporter::visit (HIR::BlockExpr &expr) } void -PrivacyReporter::visit (HIR::ContinueExpr &expr) +PrivacyReporter::visit (HIR::ContinueExpr &) {} void @@ -474,7 +474,7 @@ PrivacyReporter::visit (HIR::RangeToExpr &expr) } void -PrivacyReporter::visit (HIR::RangeFullExpr &expr) +PrivacyReporter::visit (HIR::RangeFullExpr &) {} void @@ -485,7 +485,7 @@ PrivacyReporter::visit (HIR::RangeFromToInclExpr &expr) } void -PrivacyReporter::visit (HIR::RangeToInclExpr &expr) +PrivacyReporter::visit (HIR::RangeToInclExpr &) { // Not handled yet } @@ -564,14 +564,14 @@ PrivacyReporter::visit (HIR::IfExprConseqIfLet &expr) } void -PrivacyReporter::visit (HIR::IfLetExpr &expr) +PrivacyReporter::visit (HIR::IfLetExpr &) { // TODO: We need to visit the if_let_expr // TODO: We need to visit the block as well } void -PrivacyReporter::visit (HIR::IfLetExprConseqElse &expr) +PrivacyReporter::visit (HIR::IfLetExprConseqElse &) { // TODO: We need to visit the if_let_expr // TODO: We need to visit the if_block as well @@ -579,7 +579,7 @@ PrivacyReporter::visit (HIR::IfLetExprConseqElse &expr) } void -PrivacyReporter::visit (HIR::IfLetExprConseqIf &expr) +PrivacyReporter::visit (HIR::IfLetExprConseqIf &) { // TODO: We need to visit the if_let_expr // TODO: We need to visit the if_block as well @@ -587,7 +587,7 @@ PrivacyReporter::visit (HIR::IfLetExprConseqIf &expr) } void -PrivacyReporter::visit (HIR::IfLetExprConseqIfLet &expr) +PrivacyReporter::visit (HIR::IfLetExprConseqIfLet &) { // TODO: We need to visit the if_let_expr // TODO: We need to visit the if_block as well @@ -601,13 +601,13 @@ PrivacyReporter::visit (HIR::MatchExpr &expr) } void -PrivacyReporter::visit (HIR::AwaitExpr &expr) +PrivacyReporter::visit (HIR::AwaitExpr &) { // Not handled yet } void -PrivacyReporter::visit (HIR::AsyncBlockExpr &expr) +PrivacyReporter::visit (HIR::AsyncBlockExpr &) { // Not handled yet } @@ -628,11 +628,11 @@ PrivacyReporter::visit (HIR::Module &module) } void -PrivacyReporter::visit (HIR::ExternCrate &crate) +PrivacyReporter::visit (HIR::ExternCrate &) {} void -PrivacyReporter::visit (HIR::UseDeclaration &use_decl) +PrivacyReporter::visit (HIR::UseDeclaration &) { // FIXME: Is there anything we need to do here? } @@ -647,51 +647,51 @@ PrivacyReporter::visit (HIR::Function &function) } void -PrivacyReporter::visit (HIR::TypeAlias &type_alias) +PrivacyReporter::visit (HIR::TypeAlias &) { // TODO: Check the type here } void -PrivacyReporter::visit (HIR::StructStruct &struct_item) +PrivacyReporter::visit (HIR::StructStruct &) { // TODO: Check the type of all fields } void -PrivacyReporter::visit (HIR::TupleStruct &tuple_struct) +PrivacyReporter::visit (HIR::TupleStruct &) { // TODO: Check the type of all fields } void -PrivacyReporter::visit (HIR::EnumItem &item) +PrivacyReporter::visit (HIR::EnumItem &) { // TODO: Check the type of all variants } void -PrivacyReporter::visit (HIR::EnumItemTuple &item) +PrivacyReporter::visit (HIR::EnumItemTuple &) { // TODO: Check the type } void -PrivacyReporter::visit (HIR::EnumItemStruct &item) +PrivacyReporter::visit (HIR::EnumItemStruct &) { // TODO: Check the type } void -PrivacyReporter::visit (HIR::EnumItemDiscriminant &item) +PrivacyReporter::visit (HIR::EnumItemDiscriminant &) {} void -PrivacyReporter::visit (HIR::Enum &enum_item) +PrivacyReporter::visit (HIR::Enum &) {} void -PrivacyReporter::visit (HIR::Union &union_item) +PrivacyReporter::visit (HIR::Union &) { // TODO: Check the type } @@ -711,7 +711,7 @@ PrivacyReporter::visit (HIR::StaticItem &static_item) } void -PrivacyReporter::visit (HIR::Trait &trait) +PrivacyReporter::visit (HIR::Trait &) { // FIXME: We need to be an ItemVisitor as well // for (auto &item : trait.get_trait_items ()) @@ -726,15 +726,15 @@ PrivacyReporter::visit (HIR::ImplBlock &impl) } void -PrivacyReporter::visit (HIR::ExternBlock &block) +PrivacyReporter::visit (HIR::ExternBlock &) { // FIXME: We need to be an ItemVisitor as well - // for (auto &item : block.get_extern_items ()) + // for (auto &block: block.get_extern_items ()) // item->accept_vis (*this); } void -PrivacyReporter::visit (HIR::EmptyStmt &stmt) +PrivacyReporter::visit (HIR::EmptyStmt &) {} void diff --git a/gcc/rust/checks/errors/privacy/rust-reachability.cc b/gcc/rust/checks/errors/privacy/rust-reachability.cc index d61193ec139..b9a2b363708 100644 --- a/gcc/rust/checks/errors/privacy/rust-reachability.cc +++ b/gcc/rust/checks/errors/privacy/rust-reachability.cc @@ -140,7 +140,7 @@ ReachabilityVisitor::visit (HIR::StructStruct &struct_item) } void -ReachabilityVisitor::visit (HIR::TupleStruct &tuple_struct) +ReachabilityVisitor::visit (HIR::TupleStruct &) {} void @@ -227,7 +227,7 @@ ReachabilityVisitor::visit (HIR::ImplBlock &impl) } void -ReachabilityVisitor::visit (HIR::ExternBlock &block) +ReachabilityVisitor::visit (HIR::ExternBlock &) {} // FIXME: How can we visit Blocks in the current configuration? Have a full diff --git a/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc b/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc index c27bf791b28..becb9fd93a7 100644 --- a/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc +++ b/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc @@ -141,11 +141,11 @@ VisibilityResolver::visit (HIR::Module &mod) } void -VisibilityResolver::visit (HIR::ExternCrate &crate) +VisibilityResolver::visit (HIR::ExternCrate &) {} void -VisibilityResolver::visit (HIR::UseDeclaration &use_decl) +VisibilityResolver::visit (HIR::UseDeclaration &) {} void @@ -185,7 +185,7 @@ VisibilityResolver::visit (HIR::Enum &enum_item) } void -VisibilityResolver::visit (HIR::Union &union_item) +VisibilityResolver::visit (HIR::Union &) {} void @@ -238,7 +238,7 @@ VisibilityResolver::visit (HIR::ImplBlock &impl) } void -VisibilityResolver::visit (HIR::ExternBlock &block) +VisibilityResolver::visit (HIR::ExternBlock &) {} } // namespace Privacy diff --git a/gcc/rust/checks/errors/rust-const-checker.cc b/gcc/rust/checks/errors/rust-const-checker.cc index 9161fa1ea2a..576c1b170d6 100644 --- a/gcc/rust/checks/errors/rust-const-checker.cc +++ b/gcc/rust/checks/errors/rust-const-checker.cc @@ -114,43 +114,43 @@ ConstChecker::check_default_const_generics ( } void -ConstChecker::visit (Lifetime &lifetime) +ConstChecker::visit (Lifetime &) {} void -ConstChecker::visit (LifetimeParam &lifetime_param) +ConstChecker::visit (LifetimeParam &) {} void -ConstChecker::visit (PathInExpression &path) +ConstChecker::visit (PathInExpression &) {} void -ConstChecker::visit (TypePathSegment &segment) +ConstChecker::visit (TypePathSegment &) {} void -ConstChecker::visit (TypePathSegmentGeneric &segment) +ConstChecker::visit (TypePathSegmentGeneric &) {} void -ConstChecker::visit (TypePathSegmentFunction &segment) +ConstChecker::visit (TypePathSegmentFunction &) {} void -ConstChecker::visit (TypePath &path) +ConstChecker::visit (TypePath &) {} void -ConstChecker::visit (QualifiedPathInExpression &path) +ConstChecker::visit (QualifiedPathInExpression &) {} void -ConstChecker::visit (QualifiedPathInType &path) +ConstChecker::visit (QualifiedPathInType &) {} void -ConstChecker::visit (LiteralExpr &expr) +ConstChecker::visit (LiteralExpr &) {} void @@ -270,11 +270,11 @@ ConstChecker::visit (TupleIndexExpr &expr) } void -ConstChecker::visit (StructExprStruct &expr) +ConstChecker::visit (StructExprStruct &) {} void -ConstChecker::visit (StructExprFieldIdentifier &field) +ConstChecker::visit (StructExprFieldIdentifier &) {} void @@ -297,7 +297,7 @@ ConstChecker::visit (StructExprStructFields &expr) } void -ConstChecker::visit (StructExprStructBase &expr) +ConstChecker::visit (StructExprStructBase &) {} void @@ -398,7 +398,7 @@ ConstChecker::visit (BlockExpr &expr) } void -ConstChecker::visit (ContinueExpr &expr) +ConstChecker::visit (ContinueExpr &) {} void @@ -428,7 +428,7 @@ ConstChecker::visit (RangeToExpr &expr) } void -ConstChecker::visit (RangeFullExpr &expr) +ConstChecker::visit (RangeFullExpr &) {} void @@ -439,7 +439,7 @@ ConstChecker::visit (RangeFromToInclExpr &expr) } void -ConstChecker::visit (RangeToInclExpr &expr) +ConstChecker::visit (RangeToInclExpr &) { // FIXME: Visit to_expr } @@ -558,31 +558,31 @@ ConstChecker::visit (MatchExpr &expr) } void -ConstChecker::visit (AwaitExpr &expr) +ConstChecker::visit (AwaitExpr &) { // TODO: Visit expression } void -ConstChecker::visit (AsyncBlockExpr &expr) +ConstChecker::visit (AsyncBlockExpr &) { // TODO: Visit block expression } void -ConstChecker::visit (TypeParam ¶m) +ConstChecker::visit (TypeParam &) {} void -ConstChecker::visit (ConstGenericParam ¶m) +ConstChecker::visit (ConstGenericParam &) {} void -ConstChecker::visit (LifetimeWhereClauseItem &item) +ConstChecker::visit (LifetimeWhereClauseItem &) {} void -ConstChecker::visit (TypeBoundWhereClauseItem &item) +ConstChecker::visit (TypeBoundWhereClauseItem &) {} void @@ -593,23 +593,23 @@ ConstChecker::visit (Module &module) } void -ConstChecker::visit (ExternCrate &crate) +ConstChecker::visit (ExternCrate &) {} void -ConstChecker::visit (UseTreeGlob &use_tree) +ConstChecker::visit (UseTreeGlob &) {} void -ConstChecker::visit (UseTreeList &use_tree) +ConstChecker::visit (UseTreeList &) {} void -ConstChecker::visit (UseTreeRebind &use_tree) +ConstChecker::visit (UseTreeRebind &) {} void -ConstChecker::visit (UseDeclaration &use_decl) +ConstChecker::visit (UseDeclaration &) {} void @@ -653,15 +653,15 @@ ConstChecker::visit (TupleStruct &tuple_struct) } void -ConstChecker::visit (EnumItem &enum_item) +ConstChecker::visit (EnumItem &) {} void -ConstChecker::visit (EnumItemTuple &item) +ConstChecker::visit (EnumItemTuple &) {} void -ConstChecker::visit (EnumItemStruct &item) +ConstChecker::visit (EnumItemStruct &) {} void @@ -723,7 +723,7 @@ ConstChecker::visit (TraitItemConst &item) } void -ConstChecker::visit (TraitItemType &item) +ConstChecker::visit (TraitItemType &) {} void @@ -747,11 +747,11 @@ ConstChecker::visit (ImplBlock &impl) } void -ConstChecker::visit (ExternalStaticItem &item) +ConstChecker::visit (ExternalStaticItem &) {} void -ConstChecker::visit (ExternalFunctionItem &item) +ConstChecker::visit (ExternalFunctionItem &) {} void @@ -763,87 +763,87 @@ ConstChecker::visit (ExternBlock &block) } void -ConstChecker::visit (LiteralPattern &pattern) +ConstChecker::visit (LiteralPattern &) {} void -ConstChecker::visit (IdentifierPattern &pattern) +ConstChecker::visit (IdentifierPattern &) {} void -ConstChecker::visit (WildcardPattern &pattern) +ConstChecker::visit (WildcardPattern &) {} void -ConstChecker::visit (RangePatternBoundLiteral &bound) +ConstChecker::visit (RangePatternBoundLiteral &) {} void -ConstChecker::visit (RangePatternBoundPath &bound) +ConstChecker::visit (RangePatternBoundPath &) {} void -ConstChecker::visit (RangePatternBoundQualPath &bound) +ConstChecker::visit (RangePatternBoundQualPath &) {} void -ConstChecker::visit (RangePattern &pattern) +ConstChecker::visit (RangePattern &) {} void -ConstChecker::visit (ReferencePattern &pattern) +ConstChecker::visit (ReferencePattern &) {} void -ConstChecker::visit (StructPatternFieldTuplePat &field) +ConstChecker::visit (StructPatternFieldTuplePat &) {} void -ConstChecker::visit (StructPatternFieldIdentPat &field) +ConstChecker::visit (StructPatternFieldIdentPat &) {} void -ConstChecker::visit (StructPatternFieldIdent &field) +ConstChecker::visit (StructPatternFieldIdent &) {} void -ConstChecker::visit (StructPattern &pattern) +ConstChecker::visit (StructPattern &) {} void -ConstChecker::visit (TupleStructItemsNoRange &tuple_items) +ConstChecker::visit (TupleStructItemsNoRange &) {} void -ConstChecker::visit (TupleStructItemsRange &tuple_items) +ConstChecker::visit (TupleStructItemsRange &) {} void -ConstChecker::visit (TupleStructPattern &pattern) +ConstChecker::visit (TupleStructPattern &) {} void -ConstChecker::visit (TuplePatternItemsMultiple &tuple_items) +ConstChecker::visit (TuplePatternItemsMultiple &) {} void -ConstChecker::visit (TuplePatternItemsRanged &tuple_items) +ConstChecker::visit (TuplePatternItemsRanged &) {} void -ConstChecker::visit (TuplePattern &pattern) +ConstChecker::visit (TuplePattern &) {} void -ConstChecker::visit (GroupedPattern &pattern) +ConstChecker::visit (GroupedPattern &) {} void -ConstChecker::visit (SlicePattern &pattern) +ConstChecker::visit (SlicePattern &) {} void -ConstChecker::visit (EmptyStmt &stmt) +ConstChecker::visit (EmptyStmt &) {} void @@ -866,39 +866,39 @@ ConstChecker::visit (ExprStmtWithBlock &stmt) } void -ConstChecker::visit (TraitBound &bound) +ConstChecker::visit (TraitBound &) {} void -ConstChecker::visit (ImplTraitType &type) +ConstChecker::visit (ImplTraitType &) {} void -ConstChecker::visit (TraitObjectType &type) +ConstChecker::visit (TraitObjectType &) {} void -ConstChecker::visit (ParenthesisedType &type) +ConstChecker::visit (ParenthesisedType &) {} void -ConstChecker::visit (ImplTraitTypeOneBound &type) +ConstChecker::visit (ImplTraitTypeOneBound &) {} void -ConstChecker::visit (TupleType &type) +ConstChecker::visit (TupleType &) {} void -ConstChecker::visit (NeverType &type) +ConstChecker::visit (NeverType &) {} void -ConstChecker::visit (RawPointerType &type) +ConstChecker::visit (RawPointerType &) {} void -ConstChecker::visit (ReferenceType &type) +ConstChecker::visit (ReferenceType &) {} void @@ -912,15 +912,15 @@ ConstChecker::visit (ArrayType &type) } void -ConstChecker::visit (SliceType &type) +ConstChecker::visit (SliceType &) {} void -ConstChecker::visit (InferredType &type) +ConstChecker::visit (InferredType &) {} void -ConstChecker::visit (BareFunctionType &type) +ConstChecker::visit (BareFunctionType &) {} } // namespace HIR diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.cc b/gcc/rust/checks/errors/rust-unsafe-checker.cc index 3d534743eeb..94808632c04 100644 --- a/gcc/rust/checks/errors/rust-unsafe-checker.cc +++ b/gcc/rust/checks/errors/rust-unsafe-checker.cc @@ -180,11 +180,11 @@ UnsafeChecker::check_function_call (HirId node_id, Location locus) } void -UnsafeChecker::visit (Lifetime &lifetime) +UnsafeChecker::visit (Lifetime &) {} void -UnsafeChecker::visit (LifetimeParam &lifetime_param) +UnsafeChecker::visit (LifetimeParam &) {} void @@ -203,31 +203,31 @@ UnsafeChecker::visit (PathInExpression &path) } void -UnsafeChecker::visit (TypePathSegment &segment) +UnsafeChecker::visit (TypePathSegment &) {} void -UnsafeChecker::visit (TypePathSegmentGeneric &segment) +UnsafeChecker::visit (TypePathSegmentGeneric &) {} void -UnsafeChecker::visit (TypePathSegmentFunction &segment) +UnsafeChecker::visit (TypePathSegmentFunction &) {} void -UnsafeChecker::visit (TypePath &path) +UnsafeChecker::visit (TypePath &) {} void -UnsafeChecker::visit (QualifiedPathInExpression &path) +UnsafeChecker::visit (QualifiedPathInExpression &) {} void -UnsafeChecker::visit (QualifiedPathInType &path) +UnsafeChecker::visit (QualifiedPathInType &) {} void -UnsafeChecker::visit (LiteralExpr &expr) +UnsafeChecker::visit (LiteralExpr &) {} void @@ -349,11 +349,11 @@ UnsafeChecker::visit (TupleIndexExpr &expr) } void -UnsafeChecker::visit (StructExprStruct &expr) +UnsafeChecker::visit (StructExprStruct &) {} void -UnsafeChecker::visit (StructExprFieldIdentifier &field) +UnsafeChecker::visit (StructExprFieldIdentifier &) {} void @@ -376,7 +376,7 @@ UnsafeChecker::visit (StructExprStructFields &expr) } void -UnsafeChecker::visit (StructExprStructBase &expr) +UnsafeChecker::visit (StructExprStructBase &) {} void @@ -469,7 +469,7 @@ UnsafeChecker::visit (BlockExpr &expr) } void -UnsafeChecker::visit (ContinueExpr &expr) +UnsafeChecker::visit (ContinueExpr &) {} void @@ -499,7 +499,7 @@ UnsafeChecker::visit (RangeToExpr &expr) } void -UnsafeChecker::visit (RangeFullExpr &expr) +UnsafeChecker::visit (RangeFullExpr &) {} void @@ -633,31 +633,31 @@ UnsafeChecker::visit (MatchExpr &expr) } void -UnsafeChecker::visit (AwaitExpr &expr) +UnsafeChecker::visit (AwaitExpr &) { // TODO: Visit expression } void -UnsafeChecker::visit (AsyncBlockExpr &expr) +UnsafeChecker::visit (AsyncBlockExpr &) { // TODO: Visit block expression } void -UnsafeChecker::visit (TypeParam ¶m) +UnsafeChecker::visit (TypeParam &) {} void -UnsafeChecker::visit (ConstGenericParam ¶m) +UnsafeChecker::visit (ConstGenericParam &) {} void -UnsafeChecker::visit (LifetimeWhereClauseItem &item) +UnsafeChecker::visit (LifetimeWhereClauseItem &) {} void -UnsafeChecker::visit (TypeBoundWhereClauseItem &item) +UnsafeChecker::visit (TypeBoundWhereClauseItem &) {} void @@ -668,23 +668,23 @@ UnsafeChecker::visit (Module &module) } void -UnsafeChecker::visit (ExternCrate &crate) +UnsafeChecker::visit (ExternCrate &) {} void -UnsafeChecker::visit (UseTreeGlob &use_tree) +UnsafeChecker::visit (UseTreeGlob &) {} void -UnsafeChecker::visit (UseTreeList &use_tree) +UnsafeChecker::visit (UseTreeList &) {} void -UnsafeChecker::visit (UseTreeRebind &use_tree) +UnsafeChecker::visit (UseTreeRebind &) {} void -UnsafeChecker::visit (UseDeclaration &use_decl) +UnsafeChecker::visit (UseDeclaration &) {} void @@ -702,42 +702,42 @@ UnsafeChecker::visit (Function &function) } void -UnsafeChecker::visit (TypeAlias &type_alias) +UnsafeChecker::visit (TypeAlias &) { // FIXME: What do we need to do to handle type aliasing? Is it possible to // have unsafe types? Type aliases on unsafe functions? } void -UnsafeChecker::visit (StructStruct &struct_item) +UnsafeChecker::visit (StructStruct &) {} void -UnsafeChecker::visit (TupleStruct &tuple_struct) +UnsafeChecker::visit (TupleStruct &) {} void -UnsafeChecker::visit (EnumItem &item) +UnsafeChecker::visit (EnumItem &) {} void -UnsafeChecker::visit (EnumItemTuple &item) +UnsafeChecker::visit (EnumItemTuple &) {} void -UnsafeChecker::visit (EnumItemStruct &item) +UnsafeChecker::visit (EnumItemStruct &) {} void -UnsafeChecker::visit (EnumItemDiscriminant &item) +UnsafeChecker::visit (EnumItemDiscriminant &) {} void -UnsafeChecker::visit (Enum &enum_item) +UnsafeChecker::visit (Enum &) {} void -UnsafeChecker::visit (Union &union_item) +UnsafeChecker::visit (Union &) {} void @@ -767,7 +767,7 @@ UnsafeChecker::visit (TraitItemConst &item) } void -UnsafeChecker::visit (TraitItemType &item) +UnsafeChecker::visit (TraitItemType &) {} void @@ -787,11 +787,11 @@ UnsafeChecker::visit (ImplBlock &impl) } void -UnsafeChecker::visit (ExternalStaticItem &item) +UnsafeChecker::visit (ExternalStaticItem &) {} void -UnsafeChecker::visit (ExternalFunctionItem &item) +UnsafeChecker::visit (ExternalFunctionItem &) {} void @@ -803,87 +803,87 @@ UnsafeChecker::visit (ExternBlock &block) } void -UnsafeChecker::visit (LiteralPattern &pattern) +UnsafeChecker::visit (LiteralPattern &) {} void -UnsafeChecker::visit (IdentifierPattern &pattern) +UnsafeChecker::visit (IdentifierPattern &) {} void -UnsafeChecker::visit (WildcardPattern &pattern) +UnsafeChecker::visit (WildcardPattern &) {} void -UnsafeChecker::visit (RangePatternBoundLiteral &bound) +UnsafeChecker::visit (RangePatternBoundLiteral &) {} void -UnsafeChecker::visit (RangePatternBoundPath &bound) +UnsafeChecker::visit (RangePatternBoundPath &) {} void -UnsafeChecker::visit (RangePatternBoundQualPath &bound) +UnsafeChecker::visit (RangePatternBoundQualPath &) {} void -UnsafeChecker::visit (RangePattern &pattern) +UnsafeChecker::visit (RangePattern &) {} void -UnsafeChecker::visit (ReferencePattern &pattern) +UnsafeChecker::visit (ReferencePattern &) {} void -UnsafeChecker::visit (StructPatternFieldTuplePat &field) +UnsafeChecker::visit (StructPatternFieldTuplePat &) {} void -UnsafeChecker::visit (StructPatternFieldIdentPat &field) +UnsafeChecker::visit (StructPatternFieldIdentPat &) {} void -UnsafeChecker::visit (StructPatternFieldIdent &field) +UnsafeChecker::visit (StructPatternFieldIdent &) {} void -UnsafeChecker::visit (StructPattern &pattern) +UnsafeChecker::visit (StructPattern &) {} void -UnsafeChecker::visit (TupleStructItemsNoRange &tuple_items) +UnsafeChecker::visit (TupleStructItemsNoRange &) {} void -UnsafeChecker::visit (TupleStructItemsRange &tuple_items) +UnsafeChecker::visit (TupleStructItemsRange &) {} void -UnsafeChecker::visit (TupleStructPattern &pattern) +UnsafeChecker::visit (TupleStructPattern &) {} void -UnsafeChecker::visit (TuplePatternItemsMultiple &tuple_items) +UnsafeChecker::visit (TuplePatternItemsMultiple &) {} void -UnsafeChecker::visit (TuplePatternItemsRanged &tuple_items) +UnsafeChecker::visit (TuplePatternItemsRanged &) {} void -UnsafeChecker::visit (TuplePattern &pattern) +UnsafeChecker::visit (TuplePattern &) {} void -UnsafeChecker::visit (GroupedPattern &pattern) +UnsafeChecker::visit (GroupedPattern &) {} void -UnsafeChecker::visit (SlicePattern &pattern) +UnsafeChecker::visit (SlicePattern &) {} void -UnsafeChecker::visit (EmptyStmt &stmt) +UnsafeChecker::visit (EmptyStmt &) {} void @@ -906,55 +906,55 @@ UnsafeChecker::visit (ExprStmtWithBlock &stmt) } void -UnsafeChecker::visit (TraitBound &bound) +UnsafeChecker::visit (TraitBound &) {} void -UnsafeChecker::visit (ImplTraitType &type) +UnsafeChecker::visit (ImplTraitType &) {} void -UnsafeChecker::visit (TraitObjectType &type) +UnsafeChecker::visit (TraitObjectType &) {} void -UnsafeChecker::visit (ParenthesisedType &type) +UnsafeChecker::visit (ParenthesisedType &) {} void -UnsafeChecker::visit (ImplTraitTypeOneBound &type) +UnsafeChecker::visit (ImplTraitTypeOneBound &) {} void -UnsafeChecker::visit (TupleType &type) +UnsafeChecker::visit (TupleType &) {} void -UnsafeChecker::visit (NeverType &type) +UnsafeChecker::visit (NeverType &) {} void -UnsafeChecker::visit (RawPointerType &type) +UnsafeChecker::visit (RawPointerType &) {} void -UnsafeChecker::visit (ReferenceType &type) +UnsafeChecker::visit (ReferenceType &) {} void -UnsafeChecker::visit (ArrayType &type) +UnsafeChecker::visit (ArrayType &) {} void -UnsafeChecker::visit (SliceType &type) +UnsafeChecker::visit (SliceType &) {} void -UnsafeChecker::visit (InferredType &type) +UnsafeChecker::visit (InferredType &) {} void -UnsafeChecker::visit (BareFunctionType &type) +UnsafeChecker::visit (BareFunctionType &) {} } // namespace HIR diff --git a/gcc/rust/checks/lints/rust-lint-marklive.cc b/gcc/rust/checks/lints/rust-lint-marklive.cc index c914b549257..63927811149 100644 --- a/gcc/rust/checks/lints/rust-lint-marklive.cc +++ b/gcc/rust/checks/lints/rust-lint-marklive.cc @@ -78,7 +78,7 @@ MarkLive::Analysis (HIR::Crate &crate) // visited first time // 2. save all the live symbols in liveSymbols void -MarkLive::go (HIR::Crate &crate) +MarkLive::go (HIR::Crate &) { while (!worklist.empty ()) { diff --git a/gcc/rust/checks/lints/rust-lint-unused-var.cc b/gcc/rust/checks/lints/rust-lint-unused-var.cc index dff9c269962..ba5ffb9372b 100644 --- a/gcc/rust/checks/lints/rust-lint-unused-var.cc +++ b/gcc/rust/checks/lints/rust-lint-unused-var.cc @@ -53,7 +53,7 @@ check_decl (tree *t) } static tree -unused_var_walk_fn (tree *t, int *walk_subtrees, void *closure) +unused_var_walk_fn (tree *t, int *, void *) { switch (TREE_CODE (*t)) { diff --git a/gcc/rust/expand/rust-macro-builtins.cc b/gcc/rust/expand/rust-macro-builtins.cc index 9bed3ddbe79..11334409fe3 100644 --- a/gcc/rust/expand/rust-macro-builtins.cc +++ b/gcc/rust/expand/rust-macro-builtins.cc @@ -99,7 +99,6 @@ try_extract_string_literal_from_fragment (const Location &parent_locus, static std::unique_ptr try_expand_single_string_literal (AST::Expr *input_expr, - const Location &invoc_locus, MacroExpander *expander) { auto nodes = try_expand_macro_expression (input_expr, expander); @@ -116,8 +115,8 @@ try_expand_single_string_literal (AST::Expr *input_expr, static std::vector> try_expand_many_expr (Parser &parser, - const Location &invoc_locus, const TokenId last_token_id, - MacroExpander *expander, bool &has_error) + const TokenId last_token_id, MacroExpander *expander, + bool &has_error) { auto restrictions = Rust::ParseRestrictions (); // stop parsing when encountered a braces/brackets @@ -204,8 +203,7 @@ parse_single_string_literal (AST::DelimTokenTree &invoc_token_tree, // when the expression does not seem to be a string literal, we then try // to parse/expand it as macro to see if it expands to a string literal auto expr = parser.parse_expr (); - lit_expr - = try_expand_single_string_literal (expr.get (), invoc_locus, expander); + lit_expr = try_expand_single_string_literal (expr.get (), expander); } parser.skip_token (last_token_id); @@ -265,7 +263,7 @@ load_file_bytes (const char *filename) } // namespace AST::Fragment -MacroBuiltin::assert_handler (Location invoc_locus, AST::MacroInvocData &invoc) +MacroBuiltin::assert_handler (Location, AST::MacroInvocData &) { rust_debug ("assert!() called"); @@ -273,7 +271,7 @@ MacroBuiltin::assert_handler (Location invoc_locus, AST::MacroInvocData &invoc) } AST::Fragment -MacroBuiltin::file_handler (Location invoc_locus, AST::MacroInvocData &invoc) +MacroBuiltin::file_handler (Location invoc_locus, AST::MacroInvocData &) { auto current_file = Session::get_instance ().linemap->location_file (invoc_locus); @@ -283,7 +281,7 @@ MacroBuiltin::file_handler (Location invoc_locus, AST::MacroInvocData &invoc) } AST::Fragment -MacroBuiltin::column_handler (Location invoc_locus, AST::MacroInvocData &invoc) +MacroBuiltin::column_handler (Location invoc_locus, AST::MacroInvocData &) { auto current_column = Session::get_instance ().linemap->location_to_column (invoc_locus); @@ -401,7 +399,7 @@ MacroBuiltin::concat_handler (Location invoc_locus, AST::MacroInvocData &invoc) auto last_token_id = macro_end_token (invoc_token_tree, parser); /* NOTE: concat! could accept no argument, so we don't have any checks here */ - auto expanded_expr = try_expand_many_expr (parser, invoc_locus, last_token_id, + auto expanded_expr = try_expand_many_expr (parser, last_token_id, invoc.get_expander (), has_error); for (auto &expr : expanded_expr) { @@ -451,7 +449,7 @@ MacroBuiltin::env_handler (Location invoc_locus, AST::MacroInvocData &invoc) std::unique_ptr lit_expr = nullptr; bool has_error = false; - auto expanded_expr = try_expand_many_expr (parser, invoc_locus, last_token_id, + auto expanded_expr = try_expand_many_expr (parser, last_token_id, invoc.get_expander (), has_error); if (has_error) return AST::Fragment::create_error (); @@ -591,7 +589,7 @@ MacroBuiltin::include_handler (Location invoc_locus, AST::MacroInvocData &invoc) } AST::Fragment -MacroBuiltin::line_handler (Location invoc_locus, AST::MacroInvocData &invoc) +MacroBuiltin::line_handler (Location invoc_locus, AST::MacroInvocData &) { auto current_line = Session::get_instance ().linemap->location_to_line (invoc_locus); diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc index f5402efe066..33795726b2f 100644 --- a/gcc/rust/hir/rust-ast-lower-base.cc +++ b/gcc/rust/hir/rust-ast-lower-base.cc @@ -25,499 +25,499 @@ namespace Rust { namespace HIR { void -ASTLoweringBase::visit (AST::Token &tok) +ASTLoweringBase::visit (AST::Token &) {} void -ASTLoweringBase::visit (AST::DelimTokenTree &delim_tok_tree) +ASTLoweringBase::visit (AST::DelimTokenTree &) {} void -ASTLoweringBase::visit (AST::AttrInputMetaItemContainer &input) +ASTLoweringBase::visit (AST::AttrInputMetaItemContainer &) {} -// void ASTLoweringBase::visit(MetaItem& meta_item) {} -// void vsit(Stmt& stmt) {} -// void ASTLoweringBase::visit(Expr& expr) {} +// void ASTLoweringBase::visit(MetaItemmeta_item) {} +// void vsit(Stmtstmt) {} +// void ASTLoweringBase::visit(Exprexpr) {} void -ASTLoweringBase::visit (AST::IdentifierExpr &ident_expr) +ASTLoweringBase::visit (AST::IdentifierExpr &) {} -// void ASTLoweringBase::visit(Pattern& pattern) {} -// void ASTLoweringBase::visit(Type& type) {} -// void ASTLoweringBase::visit(TypeParamBound& type_param_bound) {} +// void ASTLoweringBase::visit(Patternpattern) {} +// void ASTLoweringBase::visit(Typetype) {} +// void ASTLoweringBase::visit(TypeParamBoundtype_param_bound) {} void -ASTLoweringBase::visit (AST::Lifetime &lifetime) +ASTLoweringBase::visit (AST::Lifetime &) {} -// void ASTLoweringBase::visit(GenericParam& generic_param) {} +// void ASTLoweringBase::visit(GenericParamgeneric_param) {} void -ASTLoweringBase::visit (AST::LifetimeParam &lifetime_param) +ASTLoweringBase::visit (AST::LifetimeParam &) {} void -ASTLoweringBase::visit (AST::ConstGenericParam &const_param) +ASTLoweringBase::visit (AST::ConstGenericParam &) {} -// void ASTLoweringBase::visit(TraitItem& trait_item) {} -// void ASTLoweringBase::visit(InherentImplItem& inherent_impl_item) {} -// void ASTLoweringBase::visit(TraitImplItem& trait_impl_item) {} +// void ASTLoweringBase::visit(TraitItemtrait_item) {} +// void ASTLoweringBase::visit(InherentImplIteminherent_impl_item) {} +// void ASTLoweringBase::visit(TraitImplItemtrait_impl_item) {} // rust-path.h void -ASTLoweringBase::visit (AST::PathInExpression &path) +ASTLoweringBase::visit (AST::PathInExpression &) {} void -ASTLoweringBase::visit (AST::TypePathSegment &segment) +ASTLoweringBase::visit (AST::TypePathSegment &) {} void -ASTLoweringBase::visit (AST::TypePathSegmentGeneric &segment) +ASTLoweringBase::visit (AST::TypePathSegmentGeneric &) {} void -ASTLoweringBase::visit (AST::TypePathSegmentFunction &segment) +ASTLoweringBase::visit (AST::TypePathSegmentFunction &) {} void -ASTLoweringBase::visit (AST::TypePath &path) +ASTLoweringBase::visit (AST::TypePath &) {} void -ASTLoweringBase::visit (AST::QualifiedPathInExpression &path) +ASTLoweringBase::visit (AST::QualifiedPathInExpression &) {} void -ASTLoweringBase::visit (AST::QualifiedPathInType &path) +ASTLoweringBase::visit (AST::QualifiedPathInType &) {} // rust-expr.h void -ASTLoweringBase::visit (AST::LiteralExpr &expr) +ASTLoweringBase::visit (AST::LiteralExpr &) {} void -ASTLoweringBase::visit (AST::AttrInputLiteral &attr_input) +ASTLoweringBase::visit (AST::AttrInputLiteral &) {} void -ASTLoweringBase::visit (AST::MetaItemLitExpr &meta_item) +ASTLoweringBase::visit (AST::MetaItemLitExpr &) {} void -ASTLoweringBase::visit (AST::MetaItemPathLit &meta_item) +ASTLoweringBase::visit (AST::MetaItemPathLit &) {} void -ASTLoweringBase::visit (AST::BorrowExpr &expr) +ASTLoweringBase::visit (AST::BorrowExpr &) {} void -ASTLoweringBase::visit (AST::DereferenceExpr &expr) +ASTLoweringBase::visit (AST::DereferenceExpr &) {} void -ASTLoweringBase::visit (AST::ErrorPropagationExpr &expr) +ASTLoweringBase::visit (AST::ErrorPropagationExpr &) {} void -ASTLoweringBase::visit (AST::NegationExpr &expr) +ASTLoweringBase::visit (AST::NegationExpr &) {} void -ASTLoweringBase::visit (AST::ArithmeticOrLogicalExpr &expr) +ASTLoweringBase::visit (AST::ArithmeticOrLogicalExpr &) {} void -ASTLoweringBase::visit (AST::ComparisonExpr &expr) +ASTLoweringBase::visit (AST::ComparisonExpr &) {} void -ASTLoweringBase::visit (AST::LazyBooleanExpr &expr) +ASTLoweringBase::visit (AST::LazyBooleanExpr &) {} void -ASTLoweringBase::visit (AST::TypeCastExpr &expr) +ASTLoweringBase::visit (AST::TypeCastExpr &) {} void -ASTLoweringBase::visit (AST::AssignmentExpr &expr) +ASTLoweringBase::visit (AST::AssignmentExpr &) {} void -ASTLoweringBase::visit (AST::CompoundAssignmentExpr &expr) +ASTLoweringBase::visit (AST::CompoundAssignmentExpr &) {} void -ASTLoweringBase::visit (AST::GroupedExpr &expr) +ASTLoweringBase::visit (AST::GroupedExpr &) {} -// void ASTLoweringBase::visit(ArrayElems& elems) {} +// void ASTLoweringBase::visit(ArrayElemselems) {} void -ASTLoweringBase::visit (AST::ArrayElemsValues &elems) +ASTLoweringBase::visit (AST::ArrayElemsValues &) {} void -ASTLoweringBase::visit (AST::ArrayElemsCopied &elems) +ASTLoweringBase::visit (AST::ArrayElemsCopied &) {} void -ASTLoweringBase::visit (AST::ArrayExpr &expr) +ASTLoweringBase::visit (AST::ArrayExpr &) {} void -ASTLoweringBase::visit (AST::ArrayIndexExpr &expr) +ASTLoweringBase::visit (AST::ArrayIndexExpr &) {} void -ASTLoweringBase::visit (AST::TupleExpr &expr) +ASTLoweringBase::visit (AST::TupleExpr &) {} void -ASTLoweringBase::visit (AST::TupleIndexExpr &expr) +ASTLoweringBase::visit (AST::TupleIndexExpr &) {} void -ASTLoweringBase::visit (AST::StructExprStruct &expr) +ASTLoweringBase::visit (AST::StructExprStruct &) {} -// void ASTLoweringBase::visit(StructExprField& field) {} +// void ASTLoweringBase::visit(StructExprFieldfield) {} void -ASTLoweringBase::visit (AST::StructExprFieldIdentifier &field) +ASTLoweringBase::visit (AST::StructExprFieldIdentifier &) {} void -ASTLoweringBase::visit (AST::StructExprFieldIdentifierValue &field) +ASTLoweringBase::visit (AST::StructExprFieldIdentifierValue &) {} void -ASTLoweringBase::visit (AST::StructExprFieldIndexValue &field) +ASTLoweringBase::visit (AST::StructExprFieldIndexValue &) {} void -ASTLoweringBase::visit (AST::StructExprStructFields &expr) +ASTLoweringBase::visit (AST::StructExprStructFields &) {} void -ASTLoweringBase::visit (AST::StructExprStructBase &expr) +ASTLoweringBase::visit (AST::StructExprStructBase &) {} void -ASTLoweringBase::visit (AST::CallExpr &expr) +ASTLoweringBase::visit (AST::CallExpr &) {} void -ASTLoweringBase::visit (AST::MethodCallExpr &expr) +ASTLoweringBase::visit (AST::MethodCallExpr &) {} void -ASTLoweringBase::visit (AST::FieldAccessExpr &expr) +ASTLoweringBase::visit (AST::FieldAccessExpr &) {} void -ASTLoweringBase::visit (AST::ClosureExprInner &expr) +ASTLoweringBase::visit (AST::ClosureExprInner &) {} void -ASTLoweringBase::visit (AST::BlockExpr &expr) +ASTLoweringBase::visit (AST::BlockExpr &) {} void -ASTLoweringBase::visit (AST::ClosureExprInnerTyped &expr) +ASTLoweringBase::visit (AST::ClosureExprInnerTyped &) {} void -ASTLoweringBase::visit (AST::ContinueExpr &expr) +ASTLoweringBase::visit (AST::ContinueExpr &) {} void -ASTLoweringBase::visit (AST::BreakExpr &expr) +ASTLoweringBase::visit (AST::BreakExpr &) {} void -ASTLoweringBase::visit (AST::RangeFromToExpr &expr) +ASTLoweringBase::visit (AST::RangeFromToExpr &) {} void -ASTLoweringBase::visit (AST::RangeFromExpr &expr) +ASTLoweringBase::visit (AST::RangeFromExpr &) {} void -ASTLoweringBase::visit (AST::RangeToExpr &expr) +ASTLoweringBase::visit (AST::RangeToExpr &) {} void -ASTLoweringBase::visit (AST::RangeFullExpr &expr) +ASTLoweringBase::visit (AST::RangeFullExpr &) {} void -ASTLoweringBase::visit (AST::RangeFromToInclExpr &expr) +ASTLoweringBase::visit (AST::RangeFromToInclExpr &) {} void -ASTLoweringBase::visit (AST::RangeToInclExpr &expr) +ASTLoweringBase::visit (AST::RangeToInclExpr &) {} void -ASTLoweringBase::visit (AST::ReturnExpr &expr) +ASTLoweringBase::visit (AST::ReturnExpr &) {} void -ASTLoweringBase::visit (AST::UnsafeBlockExpr &expr) +ASTLoweringBase::visit (AST::UnsafeBlockExpr &) {} void -ASTLoweringBase::visit (AST::LoopExpr &expr) +ASTLoweringBase::visit (AST::LoopExpr &) {} void -ASTLoweringBase::visit (AST::WhileLoopExpr &expr) +ASTLoweringBase::visit (AST::WhileLoopExpr &) {} void -ASTLoweringBase::visit (AST::WhileLetLoopExpr &expr) +ASTLoweringBase::visit (AST::WhileLetLoopExpr &) {} void -ASTLoweringBase::visit (AST::ForLoopExpr &expr) +ASTLoweringBase::visit (AST::ForLoopExpr &) {} void -ASTLoweringBase::visit (AST::IfExpr &expr) +ASTLoweringBase::visit (AST::IfExpr &) {} void -ASTLoweringBase::visit (AST::IfExprConseqElse &expr) +ASTLoweringBase::visit (AST::IfExprConseqElse &) {} void -ASTLoweringBase::visit (AST::IfExprConseqIf &expr) +ASTLoweringBase::visit (AST::IfExprConseqIf &) {} void -ASTLoweringBase::visit (AST::IfExprConseqIfLet &expr) +ASTLoweringBase::visit (AST::IfExprConseqIfLet &) {} void -ASTLoweringBase::visit (AST::IfLetExpr &expr) +ASTLoweringBase::visit (AST::IfLetExpr &) {} void -ASTLoweringBase::visit (AST::IfLetExprConseqElse &expr) +ASTLoweringBase::visit (AST::IfLetExprConseqElse &) {} void -ASTLoweringBase::visit (AST::IfLetExprConseqIf &expr) +ASTLoweringBase::visit (AST::IfLetExprConseqIf &) {} void -ASTLoweringBase::visit (AST::IfLetExprConseqIfLet &expr) +ASTLoweringBase::visit (AST::IfLetExprConseqIfLet &) {} -// void ASTLoweringBase::visit(MatchCase& match_case) {} -// void ASTLoweringBase:: (AST::MatchCaseBlockExpr &match_case) {} -// void ASTLoweringBase:: (AST::MatchCaseExpr &match_case) {} +// void ASTLoweringBase::visit(MatchCasematch_case) {} +// void ASTLoweringBase:: (AST::MatchCaseBlockExpr &) {} +// void ASTLoweringBase:: (AST::MatchCaseExpr &) {} void -ASTLoweringBase::visit (AST::MatchExpr &expr) +ASTLoweringBase::visit (AST::MatchExpr &) {} void -ASTLoweringBase::visit (AST::AwaitExpr &expr) +ASTLoweringBase::visit (AST::AwaitExpr &) {} void -ASTLoweringBase::visit (AST::AsyncBlockExpr &expr) +ASTLoweringBase::visit (AST::AsyncBlockExpr &) {} // rust-item.h void -ASTLoweringBase::visit (AST::TypeParam ¶m) +ASTLoweringBase::visit (AST::TypeParam &) {} -// void ASTLoweringBase::visit(WhereClauseItem& item) {} +// void ASTLoweringBase::visit(WhereClauseItemitem) {} void -ASTLoweringBase::visit (AST::LifetimeWhereClauseItem &item) +ASTLoweringBase::visit (AST::LifetimeWhereClauseItem &) {} void -ASTLoweringBase::visit (AST::TypeBoundWhereClauseItem &item) +ASTLoweringBase::visit (AST::TypeBoundWhereClauseItem &) {} void -ASTLoweringBase::visit (AST::Method &method) +ASTLoweringBase::visit (AST::Method &) {} void -ASTLoweringBase::visit (AST::Module &module) +ASTLoweringBase::visit (AST::Module &) {} void -ASTLoweringBase::visit (AST::ExternCrate &crate) +ASTLoweringBase::visit (AST::ExternCrate &) {} -// void ASTLoweringBase::visit(UseTree& use_tree) {} +// void ASTLoweringBase::visit(UseTreeuse_tree) {} void -ASTLoweringBase::visit (AST::UseTreeGlob &use_tree) +ASTLoweringBase::visit (AST::UseTreeGlob &) {} void -ASTLoweringBase::visit (AST::UseTreeList &use_tree) +ASTLoweringBase::visit (AST::UseTreeList &) {} void -ASTLoweringBase::visit (AST::UseTreeRebind &use_tree) +ASTLoweringBase::visit (AST::UseTreeRebind &) {} void -ASTLoweringBase::visit (AST::UseDeclaration &use_decl) +ASTLoweringBase::visit (AST::UseDeclaration &) {} void -ASTLoweringBase::visit (AST::Function &function) +ASTLoweringBase::visit (AST::Function &) {} void -ASTLoweringBase::visit (AST::TypeAlias &type_alias) +ASTLoweringBase::visit (AST::TypeAlias &) {} void -ASTLoweringBase::visit (AST::StructStruct &struct_item) +ASTLoweringBase::visit (AST::StructStruct &) {} void -ASTLoweringBase::visit (AST::TupleStruct &tuple_struct) +ASTLoweringBase::visit (AST::TupleStruct &) {} void -ASTLoweringBase::visit (AST::EnumItem &item) +ASTLoweringBase::visit (AST::EnumItem &) {} void -ASTLoweringBase::visit (AST::EnumItemTuple &item) +ASTLoweringBase::visit (AST::EnumItemTuple &) {} void -ASTLoweringBase::visit (AST::EnumItemStruct &item) +ASTLoweringBase::visit (AST::EnumItemStruct &) {} void -ASTLoweringBase::visit (AST::EnumItemDiscriminant &item) +ASTLoweringBase::visit (AST::EnumItemDiscriminant &) {} void -ASTLoweringBase::visit (AST::Enum &enum_item) +ASTLoweringBase::visit (AST::Enum &) {} void -ASTLoweringBase::visit (AST::Union &union_item) +ASTLoweringBase::visit (AST::Union &) {} void -ASTLoweringBase::visit (AST::ConstantItem &const_item) +ASTLoweringBase::visit (AST::ConstantItem &) {} void -ASTLoweringBase::visit (AST::StaticItem &static_item) +ASTLoweringBase::visit (AST::StaticItem &) {} void -ASTLoweringBase::visit (AST::TraitItemFunc &item) +ASTLoweringBase::visit (AST::TraitItemFunc &) {} void -ASTLoweringBase::visit (AST::TraitItemMethod &item) +ASTLoweringBase::visit (AST::TraitItemMethod &) {} void -ASTLoweringBase::visit (AST::TraitItemConst &item) +ASTLoweringBase::visit (AST::TraitItemConst &) {} void -ASTLoweringBase::visit (AST::TraitItemType &item) +ASTLoweringBase::visit (AST::TraitItemType &) {} void -ASTLoweringBase::visit (AST::Trait &trait) +ASTLoweringBase::visit (AST::Trait &) {} void -ASTLoweringBase::visit (AST::InherentImpl &impl) +ASTLoweringBase::visit (AST::InherentImpl &) {} void -ASTLoweringBase::visit (AST::TraitImpl &impl) +ASTLoweringBase::visit (AST::TraitImpl &) {} -// void ASTLoweringBase::visit(ExternalItem& item) {} +// void ASTLoweringBase::visit(ExternalItemitem) {} void -ASTLoweringBase::visit (AST::ExternalStaticItem &item) +ASTLoweringBase::visit (AST::ExternalStaticItem &) {} void -ASTLoweringBase::visit (AST::ExternalFunctionItem &item) +ASTLoweringBase::visit (AST::ExternalFunctionItem &) {} void -ASTLoweringBase::visit (AST::ExternBlock &block) +ASTLoweringBase::visit (AST::ExternBlock &) {} // rust-macro.h void -ASTLoweringBase::visit (AST::MacroMatchFragment &match) +ASTLoweringBase::visit (AST::MacroMatchFragment &) {} void -ASTLoweringBase::visit (AST::MacroMatchRepetition &match) +ASTLoweringBase::visit (AST::MacroMatchRepetition &) {} void -ASTLoweringBase::visit (AST::MacroMatcher &matcher) +ASTLoweringBase::visit (AST::MacroMatcher &) {} void -ASTLoweringBase::visit (AST::MacroRulesDefinition &rules_def) +ASTLoweringBase::visit (AST::MacroRulesDefinition &) {} void -ASTLoweringBase::visit (AST::MacroInvocation ¯o_invoc) +ASTLoweringBase::visit (AST::MacroInvocation &) {} void -ASTLoweringBase::visit (AST::MetaItemPath &meta_item) +ASTLoweringBase::visit (AST::MetaItemPath &) {} void -ASTLoweringBase::visit (AST::MetaItemSeq &meta_item) +ASTLoweringBase::visit (AST::MetaItemSeq &) {} void -ASTLoweringBase::visit (AST::MetaWord &meta_item) +ASTLoweringBase::visit (AST::MetaWord &) {} void -ASTLoweringBase::visit (AST::MetaNameValueStr &meta_item) +ASTLoweringBase::visit (AST::MetaNameValueStr &) {} void -ASTLoweringBase::visit (AST::MetaListPaths &meta_item) +ASTLoweringBase::visit (AST::MetaListPaths &) {} void -ASTLoweringBase::visit (AST::MetaListNameValueStr &meta_item) +ASTLoweringBase::visit (AST::MetaListNameValueStr &) {} // rust-pattern.h void -ASTLoweringBase::visit (AST::LiteralPattern &pattern) +ASTLoweringBase::visit (AST::LiteralPattern &) {} void -ASTLoweringBase::visit (AST::IdentifierPattern &pattern) +ASTLoweringBase::visit (AST::IdentifierPattern &) {} void -ASTLoweringBase::visit (AST::WildcardPattern &pattern) +ASTLoweringBase::visit (AST::WildcardPattern &) {} -// void ASTLoweringBase::visit(RangePatternBound& bound) {} +// void ASTLoweringBase::visit(RangePatternBoundbound) {} void -ASTLoweringBase::visit (AST::RangePatternBoundLiteral &bound) +ASTLoweringBase::visit (AST::RangePatternBoundLiteral &) {} void -ASTLoweringBase::visit (AST::RangePatternBoundPath &bound) +ASTLoweringBase::visit (AST::RangePatternBoundPath &) {} void -ASTLoweringBase::visit (AST::RangePatternBoundQualPath &bound) +ASTLoweringBase::visit (AST::RangePatternBoundQualPath &) {} void -ASTLoweringBase::visit (AST::RangePattern &pattern) +ASTLoweringBase::visit (AST::RangePattern &) {} void -ASTLoweringBase::visit (AST::ReferencePattern &pattern) +ASTLoweringBase::visit (AST::ReferencePattern &) {} -// void ASTLoweringBase::visit(StructPatternField& field) {} +// void ASTLoweringBase::visit(StructPatternFieldfield) {} void -ASTLoweringBase::visit (AST::StructPatternFieldTuplePat &field) +ASTLoweringBase::visit (AST::StructPatternFieldTuplePat &) {} void -ASTLoweringBase::visit (AST::StructPatternFieldIdentPat &field) +ASTLoweringBase::visit (AST::StructPatternFieldIdentPat &) {} void -ASTLoweringBase::visit (AST::StructPatternFieldIdent &field) +ASTLoweringBase::visit (AST::StructPatternFieldIdent &) {} void -ASTLoweringBase::visit (AST::StructPattern &pattern) +ASTLoweringBase::visit (AST::StructPattern &) {} -// void ASTLoweringBase::visit(TupleStructItems& tuple_items) {} +// void ASTLoweringBase::visit(TupleStructItemstuple_items) {} void -ASTLoweringBase::visit (AST::TupleStructItemsNoRange &tuple_items) +ASTLoweringBase::visit (AST::TupleStructItemsNoRange &) {} void -ASTLoweringBase::visit (AST::TupleStructItemsRange &tuple_items) +ASTLoweringBase::visit (AST::TupleStructItemsRange &) {} void -ASTLoweringBase::visit (AST::TupleStructPattern &pattern) +ASTLoweringBase::visit (AST::TupleStructPattern &) {} -// void ASTLoweringBase::visit(TuplePatternItems& tuple_items) {} +// void ASTLoweringBase::visit(TuplePatternItemstuple_items) {} void -ASTLoweringBase::visit (AST::TuplePatternItemsMultiple &tuple_items) +ASTLoweringBase::visit (AST::TuplePatternItemsMultiple &) {} void -ASTLoweringBase::visit (AST::TuplePatternItemsRanged &tuple_items) +ASTLoweringBase::visit (AST::TuplePatternItemsRanged &) {} void -ASTLoweringBase::visit (AST::TuplePattern &pattern) +ASTLoweringBase::visit (AST::TuplePattern &) {} void -ASTLoweringBase::visit (AST::GroupedPattern &pattern) +ASTLoweringBase::visit (AST::GroupedPattern &) {} void -ASTLoweringBase::visit (AST::SlicePattern &pattern) +ASTLoweringBase::visit (AST::SlicePattern &) {} // rust-stmt.h void -ASTLoweringBase::visit (AST::EmptyStmt &stmt) +ASTLoweringBase::visit (AST::EmptyStmt &) {} void -ASTLoweringBase::visit (AST::LetStmt &stmt) +ASTLoweringBase::visit (AST::LetStmt &) {} void -ASTLoweringBase::visit (AST::ExprStmtWithoutBlock &stmt) +ASTLoweringBase::visit (AST::ExprStmtWithoutBlock &) {} void -ASTLoweringBase::visit (AST::ExprStmtWithBlock &stmt) +ASTLoweringBase::visit (AST::ExprStmtWithBlock &) {} // rust-type.h void -ASTLoweringBase::visit (AST::TraitBound &bound) +ASTLoweringBase::visit (AST::TraitBound &) {} void -ASTLoweringBase::visit (AST::ImplTraitType &type) +ASTLoweringBase::visit (AST::ImplTraitType &) {} void -ASTLoweringBase::visit (AST::TraitObjectType &type) +ASTLoweringBase::visit (AST::TraitObjectType &) {} void -ASTLoweringBase::visit (AST::ParenthesisedType &type) +ASTLoweringBase::visit (AST::ParenthesisedType &) {} void -ASTLoweringBase::visit (AST::ImplTraitTypeOneBound &type) +ASTLoweringBase::visit (AST::ImplTraitTypeOneBound &) {} void -ASTLoweringBase::visit (AST::TraitObjectTypeOneBound &type) +ASTLoweringBase::visit (AST::TraitObjectTypeOneBound &) {} void -ASTLoweringBase::visit (AST::TupleType &type) +ASTLoweringBase::visit (AST::TupleType &) {} void -ASTLoweringBase::visit (AST::NeverType &type) +ASTLoweringBase::visit (AST::NeverType &) {} void -ASTLoweringBase::visit (AST::RawPointerType &type) +ASTLoweringBase::visit (AST::RawPointerType &) {} void -ASTLoweringBase::visit (AST::ReferenceType &type) +ASTLoweringBase::visit (AST::ReferenceType &) {} void -ASTLoweringBase::visit (AST::ArrayType &type) +ASTLoweringBase::visit (AST::ArrayType &) {} void -ASTLoweringBase::visit (AST::SliceType &type) +ASTLoweringBase::visit (AST::SliceType &) {} void -ASTLoweringBase::visit (AST::InferredType &type) +ASTLoweringBase::visit (AST::InferredType &) {} void -ASTLoweringBase::visit (AST::BareFunctionType &type) +ASTLoweringBase::visit (AST::BareFunctionType &) {} HIR::Lifetime @@ -742,7 +742,7 @@ ASTLoweringBase::handle_outer_attributes (const ItemWrapper &item) } void -ASTLoweringBase::handle_doc_item_attribute (const ItemWrapper &item, +ASTLoweringBase::handle_doc_item_attribute (const ItemWrapper &, const AST::Attribute &attr) { auto simple_doc_comment = attr.has_attr_input () diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc index 261a36daa05..875e1dd9374 100644 --- a/gcc/rust/hir/rust-hir-dump.cc +++ b/gcc/rust/hir/rust-hir-dump.cc @@ -200,7 +200,7 @@ void Dump::visit (ClosureExpr &) {} void -Dump::visit (BlockExpr &block_expr) +Dump::visit (BlockExpr &) { stream << "BlockExpr" << ":" @@ -324,7 +324,7 @@ void Dump::visit (UseDeclaration &) {} void -Dump::visit (Function &function) +Dump::visit (Function &) { indent++; stream << std::string (indent, indent_char); diff --git a/gcc/rust/hir/tree/rust-hir-full-test.cc b/gcc/rust/hir/tree/rust-hir-full-test.cc index f6e27b9a35f..230b7f72a85 100644 --- a/gcc/rust/hir/tree/rust-hir-full-test.cc +++ b/gcc/rust/hir/tree/rust-hir-full-test.cc @@ -5256,7 +5256,7 @@ ConstGenericParam::as_string () const } void -ConstGenericParam::accept_vis (HIRFullVisitor &vis) +ConstGenericParam::accept_vis (HIRFullVisitor &) {} } // namespace HIR diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc index 53c7aecd25b..ac7ced540e6 100644 --- a/gcc/rust/lex/rust-lex.cc +++ b/gcc/rust/lex/rust-lex.cc @@ -1364,7 +1364,7 @@ Lexer::parse_escape (char opening_char) /* Parses an escape (or string continue) in a string or character. Supports * unicode escapes. */ std::tuple -Lexer::parse_utf8_escape (char opening_char) +Lexer::parse_utf8_escape () { Codepoint output_char; int additional_length_offset = 0; @@ -1964,7 +1964,7 @@ Lexer::parse_string (Location loc) if (current_char32.value == '\\') { // parse escape - auto utf8_escape_pair = parse_utf8_escape ('\''); + auto utf8_escape_pair = parse_utf8_escape (); current_char32 = std::get<0> (utf8_escape_pair); if (current_char32 == Codepoint (0) && std::get<2> (utf8_escape_pair)) @@ -2365,7 +2365,7 @@ Lexer::parse_char_or_lifetime (Location loc) if (current_char32.value == '\\') { // parse escape - auto utf8_escape_pair = parse_utf8_escape ('\''); + auto utf8_escape_pair = parse_utf8_escape (); current_char32 = std::get<0> (utf8_escape_pair); length += std::get<1> (utf8_escape_pair); diff --git a/gcc/rust/lex/rust-lex.h b/gcc/rust/lex/rust-lex.h index a170e91f2cc..2dd60b365ef 100644 --- a/gcc/rust/lex/rust-lex.h +++ b/gcc/rust/lex/rust-lex.h @@ -109,7 +109,7 @@ private: std::pair parse_in_exponent_part (); std::pair parse_in_type_suffix (); std::tuple parse_escape (char opening_char); - std::tuple parse_utf8_escape (char opening_char); + std::tuple parse_utf8_escape (); int parse_partial_string_continue (); std::pair parse_partial_hex_escape (); std::pair parse_partial_unicode_escape (); diff --git a/gcc/rust/metadata/rust-export-metadata.cc b/gcc/rust/metadata/rust-export-metadata.cc index 56849323e79..49a7226476d 100644 --- a/gcc/rust/metadata/rust-export-metadata.cc +++ b/gcc/rust/metadata/rust-export-metadata.cc @@ -157,18 +157,18 @@ class ExportVisItems : public HIR::HIRVisItemVisitor public: ExportVisItems (ExportContext &context) : ctx (context) {} - void visit (HIR::Module &module) override {} - void visit (HIR::ExternCrate &crate) override {} - void visit (HIR::UseDeclaration &use_decl) override {} - void visit (HIR::TypeAlias &type_alias) override {} - void visit (HIR::StructStruct &struct_item) override {} - void visit (HIR::TupleStruct &tuple_struct) override {} - void visit (HIR::Enum &enum_item) override {} - void visit (HIR::Union &union_item) override {} - void visit (HIR::ConstantItem &const_item) override {} - void visit (HIR::StaticItem &static_item) override {} - void visit (HIR::ImplBlock &impl) override {} - void visit (HIR::ExternBlock &block) override {} + void visit (HIR::Module &) override {} + void visit (HIR::ExternCrate &) override {} + void visit (HIR::UseDeclaration &) override {} + void visit (HIR::TypeAlias &) override {} + void visit (HIR::StructStruct &) override {} + void visit (HIR::TupleStruct &) override {} + void visit (HIR::Enum &) override {} + void visit (HIR::Union &) override {} + void visit (HIR::ConstantItem &) override {} + void visit (HIR::StaticItem &) override {} + void visit (HIR::ImplBlock &) override {} + void visit (HIR::ExternBlock &) override {} void visit (HIR::Trait &trait) override { ctx.emit_trait (trait); } diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.cc b/gcc/rust/resolve/rust-ast-resolve-expr.cc index 536c828beb4..4dfc0833d91 100644 --- a/gcc/rust/resolve/rust-ast-resolve-expr.cc +++ b/gcc/rust/resolve/rust-ast-resolve-expr.cc @@ -102,7 +102,7 @@ ResolveExpr::visit (AST::AssignmentExpr &expr) ResolveExpr::go (expr.get_right_expr ().get (), prefix, canonical_prefix); // need to verify the assignee - VerifyAsignee::go (expr.get_left_expr ().get (), expr.get_node_id ()); + VerifyAsignee::go (expr.get_left_expr ().get ()); } void @@ -141,7 +141,7 @@ ResolveExpr::visit (AST::CompoundAssignmentExpr &expr) ResolveExpr::go (expr.get_right_expr ().get (), prefix, canonical_prefix); // need to verify the assignee - VerifyAsignee::go (expr.get_left_expr ().get (), expr.get_node_id ()); + VerifyAsignee::go (expr.get_left_expr ().get ()); } void @@ -553,7 +553,7 @@ ResolveExpr::visit (AST::RangeToExpr &expr) } void -ResolveExpr::visit (AST::RangeFullExpr &expr) +ResolveExpr::visit (AST::RangeFullExpr &) { // nothing to do } diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc b/gcc/rust/resolve/rust-ast-resolve-type.cc index e5c712aba07..16d05f3792b 100644 --- a/gcc/rust/resolve/rust-ast-resolve-type.cc +++ b/gcc/rust/resolve/rust-ast-resolve-type.cc @@ -61,13 +61,13 @@ ResolveType::visit (AST::RawPointerType &type) } void -ResolveType::visit (AST::InferredType &type) +ResolveType::visit (AST::InferredType &) { // FIXME } void -ResolveType::visit (AST::NeverType &type) +ResolveType::visit (AST::NeverType &) { // FIXME } @@ -505,7 +505,7 @@ ResolveTypeToCanonicalPath::visit (AST::TraitObjectTypeOneBound &type) } void -ResolveTypeToCanonicalPath::visit (AST::TraitObjectType &type) +ResolveTypeToCanonicalPath::visit (AST::TraitObjectType &) { // FIXME is this actually allowed? dyn A+B gcc_unreachable (); diff --git a/gcc/rust/resolve/rust-ast-verify-assignee.h b/gcc/rust/resolve/rust-ast-verify-assignee.h index e05a2251bb9..8d09c9b6564 100644 --- a/gcc/rust/resolve/rust-ast-verify-assignee.h +++ b/gcc/rust/resolve/rust-ast-verify-assignee.h @@ -30,9 +30,9 @@ class VerifyAsignee : public ResolverBase using Rust::Resolver::ResolverBase::visit; public: - static bool go (AST::Expr *assignee, NodeId parent) + static bool go (AST::Expr *assignee) { - VerifyAsignee checker (parent); + VerifyAsignee checker; assignee->accept_vis (checker); if (!checker.ok) rust_error_at (assignee->get_locus (), @@ -70,10 +70,10 @@ public: expr.get_dereferenced_expr ()->accept_vis (*this); } - void visit (AST::PathInExpression &expr) override { ok = true; } + void visit (AST::PathInExpression &) override { ok = true; } private: - VerifyAsignee (NodeId parent) : ResolverBase (), ok (false) {} + VerifyAsignee () : ResolverBase (), ok (false) {} bool ok; }; diff --git a/gcc/rust/resolve/rust-early-name-resolver.cc b/gcc/rust/resolve/rust-early-name-resolver.cc index 6b1f1e9c52f..8100564dc78 100644 --- a/gcc/rust/resolve/rust-early-name-resolver.cc +++ b/gcc/rust/resolve/rust-early-name-resolver.cc @@ -60,31 +60,31 @@ EarlyNameResolver::resolve_qualified_path_type (AST::QualifiedPathType &path) } void -EarlyNameResolver::visit (AST::Token &tok) +EarlyNameResolver::visit (AST::Token &) {} void -EarlyNameResolver::visit (AST::DelimTokenTree &delim_tok_tree) +EarlyNameResolver::visit (AST::DelimTokenTree &) {} void -EarlyNameResolver::visit (AST::AttrInputMetaItemContainer &input) +EarlyNameResolver::visit (AST::AttrInputMetaItemContainer &) {} void -EarlyNameResolver::visit (AST::IdentifierExpr &ident_expr) +EarlyNameResolver::visit (AST::IdentifierExpr &) {} void -EarlyNameResolver::visit (AST::Lifetime &lifetime) +EarlyNameResolver::visit (AST::Lifetime &) {} void -EarlyNameResolver::visit (AST::LifetimeParam &lifetime_param) +EarlyNameResolver::visit (AST::LifetimeParam &) {} void -EarlyNameResolver::visit (AST::ConstGenericParam &const_param) +EarlyNameResolver::visit (AST::ConstGenericParam &) {} // FIXME: ARTHUR: Do we need to perform macro resolution for paths as well? @@ -98,7 +98,7 @@ EarlyNameResolver::visit (AST::PathInExpression &path) } void -EarlyNameResolver::visit (AST::TypePathSegment &segment) +EarlyNameResolver::visit (AST::TypePathSegment &) {} void @@ -144,19 +144,19 @@ EarlyNameResolver::visit (AST::QualifiedPathInType &path) } void -EarlyNameResolver::visit (AST::LiteralExpr &expr) +EarlyNameResolver::visit (AST::LiteralExpr &) {} void -EarlyNameResolver::visit (AST::AttrInputLiteral &attr_input) +EarlyNameResolver::visit (AST::AttrInputLiteral &) {} void -EarlyNameResolver::visit (AST::MetaItemLitExpr &meta_item) +EarlyNameResolver::visit (AST::MetaItemLitExpr &) {} void -EarlyNameResolver::visit (AST::MetaItemPathLit &meta_item) +EarlyNameResolver::visit (AST::MetaItemPathLit &) {} void @@ -271,11 +271,11 @@ EarlyNameResolver::visit (AST::TupleIndexExpr &expr) } void -EarlyNameResolver::visit (AST::StructExprStruct &expr) +EarlyNameResolver::visit (AST::StructExprStruct &) {} void -EarlyNameResolver::visit (AST::StructExprFieldIdentifier &field) +EarlyNameResolver::visit (AST::StructExprFieldIdentifier &) {} void @@ -298,7 +298,7 @@ EarlyNameResolver::visit (AST::StructExprStructFields &expr) } void -EarlyNameResolver::visit (AST::StructExprStructBase &expr) +EarlyNameResolver::visit (AST::StructExprStructBase &) {} void @@ -352,7 +352,7 @@ EarlyNameResolver::visit (AST::ClosureExprInnerTyped &expr) } void -EarlyNameResolver::visit (AST::ContinueExpr &expr) +EarlyNameResolver::visit (AST::ContinueExpr &) {} void @@ -382,7 +382,7 @@ EarlyNameResolver::visit (AST::RangeToExpr &expr) } void -EarlyNameResolver::visit (AST::RangeFullExpr &expr) +EarlyNameResolver::visit (AST::RangeFullExpr &) {} void @@ -539,7 +539,7 @@ EarlyNameResolver::visit (AST::TypeParam ¶m) } void -EarlyNameResolver::visit (AST::LifetimeWhereClauseItem &item) +EarlyNameResolver::visit (AST::LifetimeWhereClauseItem &) {} void @@ -576,23 +576,23 @@ EarlyNameResolver::visit (AST::Module &module) } void -EarlyNameResolver::visit (AST::ExternCrate &crate) +EarlyNameResolver::visit (AST::ExternCrate &) {} void -EarlyNameResolver::visit (AST::UseTreeGlob &use_tree) +EarlyNameResolver::visit (AST::UseTreeGlob &) {} void -EarlyNameResolver::visit (AST::UseTreeList &use_tree) +EarlyNameResolver::visit (AST::UseTreeList &) {} void -EarlyNameResolver::visit (AST::UseTreeRebind &use_tree) +EarlyNameResolver::visit (AST::UseTreeRebind &) {} void -EarlyNameResolver::visit (AST::UseDeclaration &use_decl) +EarlyNameResolver::visit (AST::UseDeclaration &) {} void @@ -632,27 +632,27 @@ EarlyNameResolver::visit (AST::TupleStruct &tuple_struct) } void -EarlyNameResolver::visit (AST::EnumItem &item) +EarlyNameResolver::visit (AST::EnumItem &) {} void -EarlyNameResolver::visit (AST::EnumItemTuple &item) +EarlyNameResolver::visit (AST::EnumItemTuple &) {} void -EarlyNameResolver::visit (AST::EnumItemStruct &item) +EarlyNameResolver::visit (AST::EnumItemStruct &) {} void -EarlyNameResolver::visit (AST::EnumItemDiscriminant &item) +EarlyNameResolver::visit (AST::EnumItemDiscriminant &) {} void -EarlyNameResolver::visit (AST::Enum &enum_item) +EarlyNameResolver::visit (AST::Enum &) {} void -EarlyNameResolver::visit (AST::Union &union_item) +EarlyNameResolver::visit (AST::Union &) {} void @@ -716,7 +716,7 @@ EarlyNameResolver::visit (AST::TraitItemConst &item) } void -EarlyNameResolver::visit (AST::TraitItemType &item) +EarlyNameResolver::visit (AST::TraitItemType &) {} void @@ -777,15 +777,15 @@ EarlyNameResolver::visit (AST::ExternBlock &block) } void -EarlyNameResolver::visit (AST::MacroMatchFragment &match) +EarlyNameResolver::visit (AST::MacroMatchFragment &) {} void -EarlyNameResolver::visit (AST::MacroMatchRepetition &match) +EarlyNameResolver::visit (AST::MacroMatchRepetition &) {} void -EarlyNameResolver::visit (AST::MacroMatcher &matcher) +EarlyNameResolver::visit (AST::MacroMatcher &) {} void @@ -853,31 +853,31 @@ EarlyNameResolver::visit (AST::MacroInvocation &invoc) // FIXME: ARTHUR: Do we need to resolve these as well here? void -EarlyNameResolver::visit (AST::MetaItemPath &meta_item) +EarlyNameResolver::visit (AST::MetaItemPath &) {} void -EarlyNameResolver::visit (AST::MetaItemSeq &meta_item) +EarlyNameResolver::visit (AST::MetaItemSeq &) {} void -EarlyNameResolver::visit (AST::MetaWord &meta_item) +EarlyNameResolver::visit (AST::MetaWord &) {} void -EarlyNameResolver::visit (AST::MetaNameValueStr &meta_item) +EarlyNameResolver::visit (AST::MetaNameValueStr &) {} void -EarlyNameResolver::visit (AST::MetaListPaths &meta_item) +EarlyNameResolver::visit (AST::MetaListPaths &) {} void -EarlyNameResolver::visit (AST::MetaListNameValueStr &meta_item) +EarlyNameResolver::visit (AST::MetaListNameValueStr &) {} void -EarlyNameResolver::visit (AST::LiteralPattern &pattern) +EarlyNameResolver::visit (AST::LiteralPattern &) {} void @@ -888,19 +888,19 @@ EarlyNameResolver::visit (AST::IdentifierPattern &pattern) } void -EarlyNameResolver::visit (AST::WildcardPattern &pattern) +EarlyNameResolver::visit (AST::WildcardPattern &) {} void -EarlyNameResolver::visit (AST::RangePatternBoundLiteral &bound) +EarlyNameResolver::visit (AST::RangePatternBoundLiteral &) {} void -EarlyNameResolver::visit (AST::RangePatternBoundPath &bound) +EarlyNameResolver::visit (AST::RangePatternBoundPath &) {} void -EarlyNameResolver::visit (AST::RangePatternBoundQualPath &bound) +EarlyNameResolver::visit (AST::RangePatternBoundQualPath &) {} void @@ -929,11 +929,11 @@ EarlyNameResolver::visit (AST::StructPatternFieldIdentPat &field) } void -EarlyNameResolver::visit (AST::StructPatternFieldIdent &field) +EarlyNameResolver::visit (AST::StructPatternFieldIdent &) {} void -EarlyNameResolver::visit (AST::StructPattern &pattern) +EarlyNameResolver::visit (AST::StructPattern &) {} void @@ -994,7 +994,7 @@ EarlyNameResolver::visit (AST::SlicePattern &pattern) } void -EarlyNameResolver::visit (AST::EmptyStmt &stmt) +EarlyNameResolver::visit (AST::EmptyStmt &) {} void @@ -1022,55 +1022,55 @@ EarlyNameResolver::visit (AST::ExprStmtWithBlock &stmt) } void -EarlyNameResolver::visit (AST::TraitBound &bound) +EarlyNameResolver::visit (AST::TraitBound &) {} void -EarlyNameResolver::visit (AST::ImplTraitType &type) +EarlyNameResolver::visit (AST::ImplTraitType &) {} void -EarlyNameResolver::visit (AST::TraitObjectType &type) +EarlyNameResolver::visit (AST::TraitObjectType &) {} void -EarlyNameResolver::visit (AST::ParenthesisedType &type) +EarlyNameResolver::visit (AST::ParenthesisedType &) {} void -EarlyNameResolver::visit (AST::ImplTraitTypeOneBound &type) +EarlyNameResolver::visit (AST::ImplTraitTypeOneBound &) {} void -EarlyNameResolver::visit (AST::TraitObjectTypeOneBound &type) +EarlyNameResolver::visit (AST::TraitObjectTypeOneBound &) {} void -EarlyNameResolver::visit (AST::TupleType &type) +EarlyNameResolver::visit (AST::TupleType &) {} void -EarlyNameResolver::visit (AST::NeverType &type) +EarlyNameResolver::visit (AST::NeverType &) {} void -EarlyNameResolver::visit (AST::RawPointerType &type) +EarlyNameResolver::visit (AST::RawPointerType &) {} void -EarlyNameResolver::visit (AST::ReferenceType &type) +EarlyNameResolver::visit (AST::ReferenceType &) {} void -EarlyNameResolver::visit (AST::ArrayType &type) +EarlyNameResolver::visit (AST::ArrayType &) {} void -EarlyNameResolver::visit (AST::SliceType &type) +EarlyNameResolver::visit (AST::SliceType &) {} void -EarlyNameResolver::visit (AST::InferredType &type) +EarlyNameResolver::visit (AST::InferredType &) {} void diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h index d800549dea2..796cc65ba66 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.h +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h @@ -72,27 +72,21 @@ public: void visit (HIR::ClosureExpr &expr) override; // TODO - void visit (HIR::ErrorPropagationExpr &expr) override {} - void visit (HIR::RangeToInclExpr &expr) override {} - void visit (HIR::WhileLetLoopExpr &expr) override {} - void visit (HIR::ForLoopExpr &expr) override {} - void visit (HIR::IfExprConseqIfLet &expr) override {} - void visit (HIR::IfLetExprConseqElse &expr) override {} - void visit (HIR::IfLetExprConseqIf &expr) override {} - void visit (HIR::IfLetExprConseqIfLet &expr) override {} - void visit (HIR::AwaitExpr &expr) override {} - void visit (HIR::AsyncBlockExpr &expr) override {} + void visit (HIR::ErrorPropagationExpr &) override {} + void visit (HIR::RangeToInclExpr &) override {} + void visit (HIR::WhileLetLoopExpr &) override {} + void visit (HIR::ForLoopExpr &) override {} + void visit (HIR::IfExprConseqIfLet &) override {} + void visit (HIR::IfLetExprConseqElse &) override {} + void visit (HIR::IfLetExprConseqIf &) override {} + void visit (HIR::IfLetExprConseqIfLet &) override {} + void visit (HIR::AwaitExpr &) override {} + void visit (HIR::AsyncBlockExpr &) override {} // don't need to implement these see rust-hir-type-check-struct-field.h - void visit (HIR::StructExprFieldIdentifier &field) override - { - gcc_unreachable (); - } - void visit (HIR::StructExprFieldIdentifierValue &field) override - { - gcc_unreachable (); - } - void visit (HIR::StructExprFieldIndexValue &field) override + void visit (HIR::StructExprFieldIdentifier &) override { gcc_unreachable (); } + void visit (HIR::StructExprFieldIndexValue &) override { gcc_unreachable (); } + void visit (HIR::StructExprFieldIdentifierValue &) override { gcc_unreachable (); } diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.h b/gcc/rust/typecheck/rust-hir-type-check-item.h index 10085c90629..2268fdb6e6c 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-item.h +++ b/gcc/rust/typecheck/rust-hir-type-check-item.h @@ -48,8 +48,8 @@ public: void visit (HIR::Trait &trait_block) override; // nothing to do - void visit (HIR::ExternCrate &crate) override {} - void visit (HIR::UseDeclaration &use_decl) override {} + void visit (HIR::ExternCrate &) override {} + void visit (HIR::UseDeclaration &) override {} protected: std::vector diff --git a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc index 82af7294d69..b017a851b5d 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc @@ -381,34 +381,34 @@ TypeCheckPattern::visit (HIR::RangePattern &pattern) } void -TypeCheckPattern::visit (HIR::IdentifierPattern &pattern) +TypeCheckPattern::visit (HIR::IdentifierPattern &) { infered = parent; } void -TypeCheckPattern::visit (HIR::GroupedPattern &pattern) +TypeCheckPattern::visit (HIR::GroupedPattern &) { // TODO gcc_unreachable (); } void -TypeCheckPattern::visit (HIR::QualifiedPathInExpression &pattern) +TypeCheckPattern::visit (HIR::QualifiedPathInExpression &) { // TODO gcc_unreachable (); } void -TypeCheckPattern::visit (HIR::ReferencePattern &pattern) +TypeCheckPattern::visit (HIR::ReferencePattern &) { // TODO gcc_unreachable (); } void -TypeCheckPattern::visit (HIR::SlicePattern &pattern) +TypeCheckPattern::visit (HIR::SlicePattern &) { // TODO gcc_unreachable (); diff --git a/gcc/rust/typecheck/rust-tyty-rules.h b/gcc/rust/typecheck/rust-tyty-rules.h index 4b1fe4fd418..cfe269221bd 100644 --- a/gcc/rust/typecheck/rust-tyty-rules.h +++ b/gcc/rust/typecheck/rust-tyty-rules.h @@ -123,53 +123,53 @@ public: return resolved; } - virtual void visit (TupleType &type) override {} + virtual void visit (TupleType &) override {} - virtual void visit (ADTType &type) override {} + virtual void visit (ADTType &) override {} - virtual void visit (InferType &type) override {} + virtual void visit (InferType &) override {} - virtual void visit (FnType &type) override {} + virtual void visit (FnType &) override {} - virtual void visit (FnPtr &type) override {} + virtual void visit (FnPtr &) override {} - virtual void visit (ArrayType &type) override {} + virtual void visit (ArrayType &) override {} - virtual void visit (SliceType &type) override {} + virtual void visit (SliceType &) override {} - virtual void visit (BoolType &type) override {} + virtual void visit (BoolType &) override {} - virtual void visit (IntType &type) override {} + virtual void visit (IntType &) override {} - virtual void visit (UintType &type) override {} + virtual void visit (UintType &) override {} - virtual void visit (USizeType &type) override {} + virtual void visit (USizeType &) override {} - virtual void visit (ISizeType &type) override {} + virtual void visit (ISizeType &) override {} - virtual void visit (FloatType &type) override {} + virtual void visit (FloatType &) override {} - virtual void visit (ErrorType &type) override {} + virtual void visit (ErrorType &) override {} - virtual void visit (CharType &type) override {} + virtual void visit (CharType &) override {} - virtual void visit (ReferenceType &type) override {} + virtual void visit (ReferenceType &) override {} - virtual void visit (PointerType &type) override {} + virtual void visit (PointerType &) override {} - virtual void visit (ParamType &type) override {} + virtual void visit (ParamType &) override {} - virtual void visit (StrType &type) override {} + virtual void visit (StrType &) override {} - virtual void visit (NeverType &type) override {} + virtual void visit (NeverType &) override {} - virtual void visit (PlaceholderType &type) override {} + virtual void visit (PlaceholderType &) override {} - virtual void visit (ProjectionType &type) override {} + virtual void visit (ProjectionType &) override {} - virtual void visit (DynamicObjectType &type) override {} + virtual void visit (DynamicObjectType &) override {} - virtual void visit (ClosureType &type) override {} + virtual void visit (ClosureType &) override {} protected: BaseRules (BaseType *base) diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc index 1c85273e541..33f2c932d09 100644 --- a/gcc/rust/util/rust-attributes.cc +++ b/gcc/rust/util/rust-attributes.cc @@ -210,342 +210,342 @@ AttributeChecker::check_attributes (const AST::AttrVec &attributes) } void -AttributeChecker::visit (AST::Token &tok) +AttributeChecker::visit (AST::Token &) {} void -AttributeChecker::visit (AST::DelimTokenTree &delim_tok_tree) +AttributeChecker::visit (AST::DelimTokenTree &) {} void -AttributeChecker::visit (AST::AttrInputMetaItemContainer &input) +AttributeChecker::visit (AST::AttrInputMetaItemContainer &) {} void -AttributeChecker::visit (AST::IdentifierExpr &ident_expr) +AttributeChecker::visit (AST::IdentifierExpr &) {} void -AttributeChecker::visit (AST::Lifetime &lifetime) +AttributeChecker::visit (AST::Lifetime &) {} void -AttributeChecker::visit (AST::LifetimeParam &lifetime_param) +AttributeChecker::visit (AST::LifetimeParam &) {} void -AttributeChecker::visit (AST::ConstGenericParam &const_param) +AttributeChecker::visit (AST::ConstGenericParam &) {} // rust-path.h void -AttributeChecker::visit (AST::PathInExpression &path) +AttributeChecker::visit (AST::PathInExpression &) {} void -AttributeChecker::visit (AST::TypePathSegment &segment) +AttributeChecker::visit (AST::TypePathSegment &) {} void -AttributeChecker::visit (AST::TypePathSegmentGeneric &segment) +AttributeChecker::visit (AST::TypePathSegmentGeneric &) {} void -AttributeChecker::visit (AST::TypePathSegmentFunction &segment) +AttributeChecker::visit (AST::TypePathSegmentFunction &) {} void -AttributeChecker::visit (AST::TypePath &path) +AttributeChecker::visit (AST::TypePath &) {} void -AttributeChecker::visit (AST::QualifiedPathInExpression &path) +AttributeChecker::visit (AST::QualifiedPathInExpression &) {} void -AttributeChecker::visit (AST::QualifiedPathInType &path) +AttributeChecker::visit (AST::QualifiedPathInType &) {} // rust-expr.h void -AttributeChecker::visit (AST::LiteralExpr &expr) +AttributeChecker::visit (AST::LiteralExpr &) {} void -AttributeChecker::visit (AST::AttrInputLiteral &attr_input) +AttributeChecker::visit (AST::AttrInputLiteral &) {} void -AttributeChecker::visit (AST::MetaItemLitExpr &meta_item) +AttributeChecker::visit (AST::MetaItemLitExpr &) {} void -AttributeChecker::visit (AST::MetaItemPathLit &meta_item) +AttributeChecker::visit (AST::MetaItemPathLit &) {} void -AttributeChecker::visit (AST::BorrowExpr &expr) +AttributeChecker::visit (AST::BorrowExpr &) {} void -AttributeChecker::visit (AST::DereferenceExpr &expr) +AttributeChecker::visit (AST::DereferenceExpr &) {} void -AttributeChecker::visit (AST::ErrorPropagationExpr &expr) +AttributeChecker::visit (AST::ErrorPropagationExpr &) {} void -AttributeChecker::visit (AST::NegationExpr &expr) +AttributeChecker::visit (AST::NegationExpr &) {} void -AttributeChecker::visit (AST::ArithmeticOrLogicalExpr &expr) +AttributeChecker::visit (AST::ArithmeticOrLogicalExpr &) {} void -AttributeChecker::visit (AST::ComparisonExpr &expr) +AttributeChecker::visit (AST::ComparisonExpr &) {} void -AttributeChecker::visit (AST::LazyBooleanExpr &expr) +AttributeChecker::visit (AST::LazyBooleanExpr &) {} void -AttributeChecker::visit (AST::TypeCastExpr &expr) +AttributeChecker::visit (AST::TypeCastExpr &) {} void -AttributeChecker::visit (AST::AssignmentExpr &expr) +AttributeChecker::visit (AST::AssignmentExpr &) {} void -AttributeChecker::visit (AST::CompoundAssignmentExpr &expr) +AttributeChecker::visit (AST::CompoundAssignmentExpr &) {} void -AttributeChecker::visit (AST::GroupedExpr &expr) +AttributeChecker::visit (AST::GroupedExpr &) {} void -AttributeChecker::visit (AST::ArrayElemsValues &elems) +AttributeChecker::visit (AST::ArrayElemsValues &) {} void -AttributeChecker::visit (AST::ArrayElemsCopied &elems) +AttributeChecker::visit (AST::ArrayElemsCopied &) {} void -AttributeChecker::visit (AST::ArrayExpr &expr) +AttributeChecker::visit (AST::ArrayExpr &) {} void -AttributeChecker::visit (AST::ArrayIndexExpr &expr) +AttributeChecker::visit (AST::ArrayIndexExpr &) {} void -AttributeChecker::visit (AST::TupleExpr &expr) +AttributeChecker::visit (AST::TupleExpr &) {} void -AttributeChecker::visit (AST::TupleIndexExpr &expr) +AttributeChecker::visit (AST::TupleIndexExpr &) {} void -AttributeChecker::visit (AST::StructExprStruct &expr) +AttributeChecker::visit (AST::StructExprStruct &) {} void -AttributeChecker::visit (AST::StructExprFieldIdentifier &field) +AttributeChecker::visit (AST::StructExprFieldIdentifier &) {} void -AttributeChecker::visit (AST::StructExprFieldIdentifierValue &field) +AttributeChecker::visit (AST::StructExprFieldIdentifierValue &) {} void -AttributeChecker::visit (AST::StructExprFieldIndexValue &field) +AttributeChecker::visit (AST::StructExprFieldIndexValue &) {} void -AttributeChecker::visit (AST::StructExprStructFields &expr) +AttributeChecker::visit (AST::StructExprStructFields &) {} void -AttributeChecker::visit (AST::StructExprStructBase &expr) +AttributeChecker::visit (AST::StructExprStructBase &) {} void -AttributeChecker::visit (AST::CallExpr &expr) +AttributeChecker::visit (AST::CallExpr &) {} void -AttributeChecker::visit (AST::MethodCallExpr &expr) +AttributeChecker::visit (AST::MethodCallExpr &) {} void -AttributeChecker::visit (AST::FieldAccessExpr &expr) +AttributeChecker::visit (AST::FieldAccessExpr &) {} void -AttributeChecker::visit (AST::ClosureExprInner &expr) +AttributeChecker::visit (AST::ClosureExprInner &) {} void -AttributeChecker::visit (AST::BlockExpr &expr) +AttributeChecker::visit (AST::BlockExpr &) {} void -AttributeChecker::visit (AST::ClosureExprInnerTyped &expr) +AttributeChecker::visit (AST::ClosureExprInnerTyped &) {} void -AttributeChecker::visit (AST::ContinueExpr &expr) +AttributeChecker::visit (AST::ContinueExpr &) {} void -AttributeChecker::visit (AST::BreakExpr &expr) +AttributeChecker::visit (AST::BreakExpr &) {} void -AttributeChecker::visit (AST::RangeFromToExpr &expr) +AttributeChecker::visit (AST::RangeFromToExpr &) {} void -AttributeChecker::visit (AST::RangeFromExpr &expr) +AttributeChecker::visit (AST::RangeFromExpr &) {} void -AttributeChecker::visit (AST::RangeToExpr &expr) +AttributeChecker::visit (AST::RangeToExpr &) {} void -AttributeChecker::visit (AST::RangeFullExpr &expr) +AttributeChecker::visit (AST::RangeFullExpr &) {} void -AttributeChecker::visit (AST::RangeFromToInclExpr &expr) +AttributeChecker::visit (AST::RangeFromToInclExpr &) {} void -AttributeChecker::visit (AST::RangeToInclExpr &expr) +AttributeChecker::visit (AST::RangeToInclExpr &) {} void -AttributeChecker::visit (AST::ReturnExpr &expr) +AttributeChecker::visit (AST::ReturnExpr &) {} void -AttributeChecker::visit (AST::UnsafeBlockExpr &expr) +AttributeChecker::visit (AST::UnsafeBlockExpr &) {} void -AttributeChecker::visit (AST::LoopExpr &expr) +AttributeChecker::visit (AST::LoopExpr &) {} void -AttributeChecker::visit (AST::WhileLoopExpr &expr) +AttributeChecker::visit (AST::WhileLoopExpr &) {} void -AttributeChecker::visit (AST::WhileLetLoopExpr &expr) +AttributeChecker::visit (AST::WhileLetLoopExpr &) {} void -AttributeChecker::visit (AST::ForLoopExpr &expr) +AttributeChecker::visit (AST::ForLoopExpr &) {} void -AttributeChecker::visit (AST::IfExpr &expr) +AttributeChecker::visit (AST::IfExpr &) {} void -AttributeChecker::visit (AST::IfExprConseqElse &expr) +AttributeChecker::visit (AST::IfExprConseqElse &) {} void -AttributeChecker::visit (AST::IfExprConseqIf &expr) +AttributeChecker::visit (AST::IfExprConseqIf &) {} void -AttributeChecker::visit (AST::IfExprConseqIfLet &expr) +AttributeChecker::visit (AST::IfExprConseqIfLet &) {} void -AttributeChecker::visit (AST::IfLetExpr &expr) +AttributeChecker::visit (AST::IfLetExpr &) {} void -AttributeChecker::visit (AST::IfLetExprConseqElse &expr) +AttributeChecker::visit (AST::IfLetExprConseqElse &) {} void -AttributeChecker::visit (AST::IfLetExprConseqIf &expr) +AttributeChecker::visit (AST::IfLetExprConseqIf &) {} void -AttributeChecker::visit (AST::IfLetExprConseqIfLet &expr) +AttributeChecker::visit (AST::IfLetExprConseqIfLet &) {} void -AttributeChecker::visit (AST::MatchExpr &expr) +AttributeChecker::visit (AST::MatchExpr &) {} void -AttributeChecker::visit (AST::AwaitExpr &expr) +AttributeChecker::visit (AST::AwaitExpr &) {} void -AttributeChecker::visit (AST::AsyncBlockExpr &expr) +AttributeChecker::visit (AST::AsyncBlockExpr &) {} // rust-item.h void -AttributeChecker::visit (AST::TypeParam ¶m) +AttributeChecker::visit (AST::TypeParam &) {} void -AttributeChecker::visit (AST::LifetimeWhereClauseItem &item) +AttributeChecker::visit (AST::LifetimeWhereClauseItem &) {} void -AttributeChecker::visit (AST::TypeBoundWhereClauseItem &item) +AttributeChecker::visit (AST::TypeBoundWhereClauseItem &) {} void -AttributeChecker::visit (AST::Method &method) +AttributeChecker::visit (AST::Method &) {} void -AttributeChecker::visit (AST::Module &module) +AttributeChecker::visit (AST::Module &) {} void -AttributeChecker::visit (AST::ExternCrate &crate) +AttributeChecker::visit (AST::ExternCrate &) {} void -AttributeChecker::visit (AST::UseTreeGlob &use_tree) +AttributeChecker::visit (AST::UseTreeGlob &) {} void -AttributeChecker::visit (AST::UseTreeList &use_tree) +AttributeChecker::visit (AST::UseTreeList &) {} void -AttributeChecker::visit (AST::UseTreeRebind &use_tree) +AttributeChecker::visit (AST::UseTreeRebind &) {} void -AttributeChecker::visit (AST::UseDeclaration &use_decl) +AttributeChecker::visit (AST::UseDeclaration &) {} void -AttributeChecker::visit (AST::Function &function) +AttributeChecker::visit (AST::Function &) {} void -AttributeChecker::visit (AST::TypeAlias &type_alias) +AttributeChecker::visit (AST::TypeAlias &) {} void @@ -555,287 +555,287 @@ AttributeChecker::visit (AST::StructStruct &struct_item) } void -AttributeChecker::visit (AST::TupleStruct &tuple_struct) +AttributeChecker::visit (AST::TupleStruct &) {} void -AttributeChecker::visit (AST::EnumItem &item) +AttributeChecker::visit (AST::EnumItem &) {} void -AttributeChecker::visit (AST::EnumItemTuple &item) +AttributeChecker::visit (AST::EnumItemTuple &) {} void -AttributeChecker::visit (AST::EnumItemStruct &item) +AttributeChecker::visit (AST::EnumItemStruct &) {} void -AttributeChecker::visit (AST::EnumItemDiscriminant &item) +AttributeChecker::visit (AST::EnumItemDiscriminant &) {} void -AttributeChecker::visit (AST::Enum &enum_item) +AttributeChecker::visit (AST::Enum &) {} void -AttributeChecker::visit (AST::Union &union_item) +AttributeChecker::visit (AST::Union &) {} void -AttributeChecker::visit (AST::ConstantItem &const_item) +AttributeChecker::visit (AST::ConstantItem &) {} void -AttributeChecker::visit (AST::StaticItem &static_item) +AttributeChecker::visit (AST::StaticItem &) {} void -AttributeChecker::visit (AST::TraitItemFunc &item) +AttributeChecker::visit (AST::TraitItemFunc &) {} void -AttributeChecker::visit (AST::TraitItemMethod &item) +AttributeChecker::visit (AST::TraitItemMethod &) {} void -AttributeChecker::visit (AST::TraitItemConst &item) +AttributeChecker::visit (AST::TraitItemConst &) {} void -AttributeChecker::visit (AST::TraitItemType &item) +AttributeChecker::visit (AST::TraitItemType &) {} void -AttributeChecker::visit (AST::Trait &trait) +AttributeChecker::visit (AST::Trait &) {} void -AttributeChecker::visit (AST::InherentImpl &impl) +AttributeChecker::visit (AST::InherentImpl &) {} void -AttributeChecker::visit (AST::TraitImpl &impl) +AttributeChecker::visit (AST::TraitImpl &) {} void -AttributeChecker::visit (AST::ExternalStaticItem &item) +AttributeChecker::visit (AST::ExternalStaticItem &) {} void -AttributeChecker::visit (AST::ExternalFunctionItem &item) +AttributeChecker::visit (AST::ExternalFunctionItem &) {} void -AttributeChecker::visit (AST::ExternBlock &block) +AttributeChecker::visit (AST::ExternBlock &) {} // rust-macro.h void -AttributeChecker::visit (AST::MacroMatchFragment &match) +AttributeChecker::visit (AST::MacroMatchFragment &) {} void -AttributeChecker::visit (AST::MacroMatchRepetition &match) +AttributeChecker::visit (AST::MacroMatchRepetition &) {} void -AttributeChecker::visit (AST::MacroMatcher &matcher) +AttributeChecker::visit (AST::MacroMatcher &) {} void -AttributeChecker::visit (AST::MacroRulesDefinition &rules_def) +AttributeChecker::visit (AST::MacroRulesDefinition &) {} void -AttributeChecker::visit (AST::MacroInvocation ¯o_invoc) +AttributeChecker::visit (AST::MacroInvocation &) {} void -AttributeChecker::visit (AST::MetaItemPath &meta_item) +AttributeChecker::visit (AST::MetaItemPath &) {} void -AttributeChecker::visit (AST::MetaItemSeq &meta_item) +AttributeChecker::visit (AST::MetaItemSeq &) {} void -AttributeChecker::visit (AST::MetaWord &meta_item) +AttributeChecker::visit (AST::MetaWord &) {} void -AttributeChecker::visit (AST::MetaNameValueStr &meta_item) +AttributeChecker::visit (AST::MetaNameValueStr &) {} void -AttributeChecker::visit (AST::MetaListPaths &meta_item) +AttributeChecker::visit (AST::MetaListPaths &) {} void -AttributeChecker::visit (AST::MetaListNameValueStr &meta_item) +AttributeChecker::visit (AST::MetaListNameValueStr &) {} // rust-pattern.h void -AttributeChecker::visit (AST::LiteralPattern &pattern) +AttributeChecker::visit (AST::LiteralPattern &) {} void -AttributeChecker::visit (AST::IdentifierPattern &pattern) +AttributeChecker::visit (AST::IdentifierPattern &) {} void -AttributeChecker::visit (AST::WildcardPattern &pattern) +AttributeChecker::visit (AST::WildcardPattern &) {} -// void AttributeChecker::visit(RangePatternBound& bound){} +// void AttributeChecker::visit(RangePatternBound& ){} void -AttributeChecker::visit (AST::RangePatternBoundLiteral &bound) +AttributeChecker::visit (AST::RangePatternBoundLiteral &) {} void -AttributeChecker::visit (AST::RangePatternBoundPath &bound) +AttributeChecker::visit (AST::RangePatternBoundPath &) {} void -AttributeChecker::visit (AST::RangePatternBoundQualPath &bound) +AttributeChecker::visit (AST::RangePatternBoundQualPath &) {} void -AttributeChecker::visit (AST::RangePattern &pattern) +AttributeChecker::visit (AST::RangePattern &) {} void -AttributeChecker::visit (AST::ReferencePattern &pattern) +AttributeChecker::visit (AST::ReferencePattern &) {} -// void AttributeChecker::visit(StructPatternField& field){} +// void AttributeChecker::visit(StructPatternField& ){} void -AttributeChecker::visit (AST::StructPatternFieldTuplePat &field) +AttributeChecker::visit (AST::StructPatternFieldTuplePat &) {} void -AttributeChecker::visit (AST::StructPatternFieldIdentPat &field) +AttributeChecker::visit (AST::StructPatternFieldIdentPat &) {} void -AttributeChecker::visit (AST::StructPatternFieldIdent &field) +AttributeChecker::visit (AST::StructPatternFieldIdent &) {} void -AttributeChecker::visit (AST::StructPattern &pattern) +AttributeChecker::visit (AST::StructPattern &) {} -// void AttributeChecker::visit(TupleStructItems& tuple_items){} +// void AttributeChecker::visit(TupleStructItems& ){} void -AttributeChecker::visit (AST::TupleStructItemsNoRange &tuple_items) +AttributeChecker::visit (AST::TupleStructItemsNoRange &) {} void -AttributeChecker::visit (AST::TupleStructItemsRange &tuple_items) +AttributeChecker::visit (AST::TupleStructItemsRange &) {} void -AttributeChecker::visit (AST::TupleStructPattern &pattern) +AttributeChecker::visit (AST::TupleStructPattern &) {} -// void AttributeChecker::visit(TuplePatternItems& tuple_items){} +// void AttributeChecker::visit(TuplePatternItems& ){} void -AttributeChecker::visit (AST::TuplePatternItemsMultiple &tuple_items) +AttributeChecker::visit (AST::TuplePatternItemsMultiple &) {} void -AttributeChecker::visit (AST::TuplePatternItemsRanged &tuple_items) +AttributeChecker::visit (AST::TuplePatternItemsRanged &) {} void -AttributeChecker::visit (AST::TuplePattern &pattern) +AttributeChecker::visit (AST::TuplePattern &) {} void -AttributeChecker::visit (AST::GroupedPattern &pattern) +AttributeChecker::visit (AST::GroupedPattern &) {} void -AttributeChecker::visit (AST::SlicePattern &pattern) +AttributeChecker::visit (AST::SlicePattern &) {} // rust-stmt.h void -AttributeChecker::visit (AST::EmptyStmt &stmt) +AttributeChecker::visit (AST::EmptyStmt &) {} void -AttributeChecker::visit (AST::LetStmt &stmt) +AttributeChecker::visit (AST::LetStmt &) {} void -AttributeChecker::visit (AST::ExprStmtWithoutBlock &stmt) +AttributeChecker::visit (AST::ExprStmtWithoutBlock &) {} void -AttributeChecker::visit (AST::ExprStmtWithBlock &stmt) +AttributeChecker::visit (AST::ExprStmtWithBlock &) {} // rust-type.h void -AttributeChecker::visit (AST::TraitBound &bound) +AttributeChecker::visit (AST::TraitBound &) {} void -AttributeChecker::visit (AST::ImplTraitType &type) +AttributeChecker::visit (AST::ImplTraitType &) {} void -AttributeChecker::visit (AST::TraitObjectType &type) +AttributeChecker::visit (AST::TraitObjectType &) {} void -AttributeChecker::visit (AST::ParenthesisedType &type) +AttributeChecker::visit (AST::ParenthesisedType &) {} void -AttributeChecker::visit (AST::ImplTraitTypeOneBound &type) +AttributeChecker::visit (AST::ImplTraitTypeOneBound &) {} void -AttributeChecker::visit (AST::TraitObjectTypeOneBound &type) +AttributeChecker::visit (AST::TraitObjectTypeOneBound &) {} void -AttributeChecker::visit (AST::TupleType &type) +AttributeChecker::visit (AST::TupleType &) {} void -AttributeChecker::visit (AST::NeverType &type) +AttributeChecker::visit (AST::NeverType &) {} void -AttributeChecker::visit (AST::RawPointerType &type) +AttributeChecker::visit (AST::RawPointerType &) {} void -AttributeChecker::visit (AST::ReferenceType &type) +AttributeChecker::visit (AST::ReferenceType &) {} void -AttributeChecker::visit (AST::ArrayType &type) +AttributeChecker::visit (AST::ArrayType &) {} void -AttributeChecker::visit (AST::SliceType &type) +AttributeChecker::visit (AST::SliceType &) {} void -AttributeChecker::visit (AST::InferredType &type) +AttributeChecker::visit (AST::InferredType &) {} void -AttributeChecker::visit (AST::BareFunctionType &type) +AttributeChecker::visit (AST::BareFunctionType &) {} } // namespace Analysis From patchwork Tue Feb 21 12:02:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60067 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1848013wrn; Tue, 21 Feb 2023 05:01:57 -0800 (PST) X-Google-Smtp-Source: AK7set97fDYo2nb3ikJ/4j++jEVKaHK/SCafKQAPdAklru5CPgn7r6psz+coid8BYU3FCgL6wdg/ X-Received: by 2002:a17:906:1747:b0:8b1:3d15:1e2c with SMTP id d7-20020a170906174700b008b13d151e2cmr11073339eje.9.1676984517167; Tue, 21 Feb 2023 05:01:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984517; cv=none; d=google.com; s=arc-20160816; b=hGdvP379dt5IKGZoh++V3w6zJMNmRSHntJ2CMN+67UTGIX2xOt6s0MKbhW/w9cRVYR T/lTR88++HuX/tEnkLqyco8scG9thbuVTvWuKcjRDIUIcKkRaqes+gorXrdBmRw+Xg0G 8FG3ksJFTYPnaIOu/Jz5Tfq1sGKxnNIo7GxUL2Lx4ixCj0vrh9FDrifEaZ2CZQhpJC0x iAxpV2y1R0+jaj46XNOWcwr3VOXR0cwH4mNhz0rBV3jcHxHZjMj06mCMaV5P2FvMOcCN AIh5I6jxUm58+cN1GGkUbQpcafZ7ve153FVWZGtTPJlZt/4in6Yix+KLOavLlbpF+CGh eJJw== 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=jehO+nbtO2fKMrarGdStxvuPhPrSdYDt+puBijSZjUY=; b=NxAC2kvgAB0zR/N149zgQbPkVk6rHNc6lmr86DWg5kBEQtcyGopBcLrgMenlSNtXeh 5PqQrnBIRP3t0C01lmVVpUvjZm42FXqGNS3pV/AlydJCxh2sdzKXWYpBUkDs+dDoRsRX k52FvAzPM7ZuV9c6D2AD0Q+FsMAJFA7bHyNvRaVTOEbebR9lsg4mb76GDof9MQjorZu+ 4srHm/+VeRgwUYLCM31+dTGI2Y3llABFL+hy7v2skfnzoBFG5u0LpetbOPzyzeLVZrhL lCbAXCOzhkbL1REAug6pl9pYaoaErzDt3yyDw96I9zRsUXMzQYm5/gQ+Z4LengbRIsaA /R9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=aKzR84aI; 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 p23-20020a170907911700b008b17b53c86esi14348922ejq.362.2023.02.21.05.01.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 05:01:57 -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=aKzR84aI; 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 0EC43390FFFC for ; Tue, 21 Feb 2023 12:22:06 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 858B0382CD72 for ; Tue, 21 Feb 2023 12:04:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 858B0382CD72 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-x436.google.com with SMTP id z8so3886335wrm.8 for ; Tue, 21 Feb 2023 04:04:43 -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=jehO+nbtO2fKMrarGdStxvuPhPrSdYDt+puBijSZjUY=; b=aKzR84aIXBw2runU4CPs4LGH/+PlT9uEdSWlo7vR0LbzjO3JcQE8wig+c3ay2eQkVO fkSXCs/b0nQFQwMVEfpV5SyyA8k4D/+DttHsTaolZl/CdCwWVjdhse+zeTa0kgN9f1g4 BToaebrHDHKwL54PyWSCL+SVXgIMhP6I/4Eq8Sq8pH5VZj8F7t4gXIIffWJ1IPXB+y92 q8L+uKbxW/+vqRjLx9jGmSQo9DDTSHSmYSxJZZHhd1S7uXQ0HEzkjk5ZG4RPwC77TUKa 1Ca0jEXRECwqJBsI/hV8yVjtZdvDOuKIRkKWviu1OtJ6Y+2VHSiGnopuqaPIcgE0QiD5 lLgw== 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=jehO+nbtO2fKMrarGdStxvuPhPrSdYDt+puBijSZjUY=; b=1O/wg0+Au3MvtsfVNcnvAVeGqq8cYDt0u25Xw3O07q6GpK0gu0/7SIl3yGCETPqobv z5IJqXjsgCGWUZLnL/60d3wtu9yqhXx0byrwpfi9+2xvDnIpDUbFt5KjfzV6gaJa/wdi hT7cDiVdLTtqg84pF6zPdGy9VYqis0AdKnaTDOuK/8fu66wKOBZrKoD4GqNFuJNg/K2N 28abLXqE/jcclFZshlzxe6HGWkiTI6TjWqF42RlMPMvesevQvomAdwVwiKOfohcRbG07 dQrj9iwM3+ayaraZzQMTzvoUOKLcC1w1HzFb7CKnG24DZzfDZzpD0gy9uwARae8UTcNU 790A== X-Gm-Message-State: AO0yUKVxp6FfwtOhLCTt/985f7xvidlM2Cm3mFR6vaY0oxvNDeck491O 612h5IP/lGKwWOxSJL/EJ96IhYGXtja26yc5kg== X-Received: by 2002:a5d:4f8b:0:b0:2c5:5881:be0f with SMTP id d11-20020a5d4f8b000000b002c55881be0fmr4247309wru.25.1676981082904; Tue, 21 Feb 2023 04:04:42 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:42 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Thomas Schwinge Subject: [committed 101/103] gccrs: Repair 'gcc/rust/lang.opt' comment Date: Tue, 21 Feb 2023 13:02:31 +0100 Message-Id: <20230221120230.596966-102-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=ham 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?1758445717214959880?= X-GMAIL-MSGID: =?utf-8?q?1758445717214959880?= From: Thomas Schwinge ... lost in #1527 commit 138a6260124740208b8f3aff2e38617f43b05fe8 "rust: Add -frust-compile-until option". gcc/rust/ChangeLog: * lang.opt: Fix ordering of file. --- gcc/rust/lang.opt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/gcc/rust/lang.opt b/gcc/rust/lang.opt index 40aafaf34d2..aab168334f6 100644 --- a/gcc/rust/lang.opt +++ b/gcc/rust/lang.opt @@ -117,6 +117,7 @@ Rust Joined RejectNegative o Rust Joined Separate +; Documented in common.opt frust-compile-until= Rust Joined RejectNegative Enum(frust_compile_until) Var(flag_rust_compile_until) @@ -158,7 +159,4 @@ Enum(frust_compile_until) String(compilation) Value(9) EnumValue Enum(frust_compile_until) String(end) Value(10) - -; Documented in common.opt - ; This comment is to ensure we retain the blank line above. From patchwork Tue Feb 21 12:02:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60070 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1848730wrn; Tue, 21 Feb 2023 05:03:00 -0800 (PST) X-Google-Smtp-Source: AK7set+MQwYNVboA+pqlX227ysMuDELOuMEFKEJTS2diBa2FviOHzeOxhkFktciilMqQC4KN1J5r X-Received: by 2002:a05:6402:35d0:b0:4ad:f811:e267 with SMTP id z16-20020a05640235d000b004adf811e267mr4523733edc.12.1676984580359; Tue, 21 Feb 2023 05:03:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984580; cv=none; d=google.com; s=arc-20160816; b=hWLAVsGws0Z2xmr4fqP/10Mdt6RMzocfdfG0x18DFnZhZEzNXEPBLBPknm7BLBPmCP p++XMsKgtFf9vpSJAxGMGB3LeT7hmGum/5WvIQnc8N5ElfNBQ4s84LvsannLcXDY08af wM6sXG7vm/Kf9oL7VvwjJsEqPcWapkEivGVMDXPy2hfCLHeh7iTUa03jlF8yJqJsWF1o mrO0DFa3HoJ7VOunIioYpSqOYTTG7UJ4KZbJqgUAW3XqJY01SXpdSSUw/snM2oW1nXFI poEVSiskl02Cr1mcAaLxmcU5MPZFelvHfcFRmZ1Gf0LKU8MeyUlnrKMhft4V2roeLHZ3 /kPg== 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=O+eVsLskO//1T8m9ezVwPdHxARyYtOAjaAGX8aDDa28=; b=xBPC2YS0HxtAB56RGrnseyRvYGY88Y+3tpPVhNr6kpscCy89w8aaPVk75fRXzS16Um bG2+ms+sAQGk1hM+WM96cYSbqobqcApm/89HNxOcoDqBq4SX60JZv0ZhxCOB25P/aAM2 RjAn5KJtrvd8bnWJshtTGibNB6imTkvJ6zSlmFVGsFx5EA2UAuKCu0MrzK9egVeOzqQf A0WOXNzYnf8ViV8xSeeTq3/Vx7o7li4GOSfzES6NtJuwdOxEt2lmuFhs/GsK9Y4akHrS Bl8AiZ8QI4ku5zJBBKllbRymwdOQwKZbO0BHCyvxIXZhek/AvRsXFaUnuHYeCDfMkW1A 8wkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=L78VhTBP; 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 b16-20020aa7dc10000000b004ad0c88b54dsi15639753edu.527.2023.02.21.05.03.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 05:03:00 -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=L78VhTBP; 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 45E0C383504F for ; Tue, 21 Feb 2023 12:22:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 67B213889E2E for ; Tue, 21 Feb 2023 12:04:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 67B213889E2E 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 c12so4165781wrw.1 for ; Tue, 21 Feb 2023 04:04:44 -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=O+eVsLskO//1T8m9ezVwPdHxARyYtOAjaAGX8aDDa28=; b=L78VhTBP6jzDXbqD4gKNh1d+oal3tfy5on7GMPV2MdnNsqgW0UKFoHNbd7P6nej8Q+ wFCGbliI6zWh+3j+b4Qv853FMiGU7duXkgknu2MHxRxiwnf0K1JMEaJPOD72f2CKT1Jz dxhIwSFp+YtftYyRNAGfB8Tavdq6pZ9eLC6aIHy6qNcjrmnWqbcDG0xb0nVcW6s3ivrm M5BrYS+P4SlHqDobTRUWlrOg7K63kgq7aIKxsv8Jae1JBdMR8Ol+ocxRy7aXpid1/8ud 9KOgUdebegESb9Qbrv9Ay+EKirAmwusrp2Y8hqtA18ZFDuPHa8PRHwPD00TGD1hNlG2i h0zQ== 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=O+eVsLskO//1T8m9ezVwPdHxARyYtOAjaAGX8aDDa28=; b=CeMtNbBGad66qJ15aC6QxVLpS/M3LNR4gC4l5W8eXuI0YaQnjE9agltwYR6GEzKv7C 2gHi7PkrM/5YW4YEECJY3br3p9Pj1wxh/9l7uLnkZ7KQEtN+eeWztOJXDPNas5yEzBps 99XDHRb0j1/iwfBJXXGbO5DXl0DKZXzdo4U/wLQeCXTb8HHc5RX21CS0kAVUaIjJAUFo gpErWB8hgNH5n+KkLkmaY8AL+ZVNLFDZyj8hDCClXGTia1ZTIlgJjnFCDIcMWrbCpWS6 eSrbsVS7W7k9T6Jpj4WjbwY1xe7ou6w4IDoiNJ6DZn81P63q6WsSEnFiOruW/YWa7Atd eICw== X-Gm-Message-State: AO0yUKWhyONw2AucyXq5GFUYKJL3VKv7cUTCq+USRrsCg5n6i/u8nPnf O3svEqokSCf4Kvz0CduuOuHrfl6saKKMY45N2g== X-Received: by 2002:a5d:5985:0:b0:2c5:7dd2:319f with SMTP id n5-20020a5d5985000000b002c57dd2319fmr3893874wri.32.1676981083747; Tue, 21 Feb 2023 04:04:43 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:43 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 102/103] gccrs: const evaluator: Remove get_nth_callarg Date: Tue, 21 Feb 2023 13:02:32 +0100 Message-Id: <20230221120230.596966-103-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=ham 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?1758445783342823877?= X-GMAIL-MSGID: =?utf-8?q?1758445783342823877?= From: Arthur Cohen We only used one path of the C++ folder's get_nth_callarg function: CALL_EXPR_ARG. Replace all calls to get_nth_callarg by macro calls to CALL_EXPR_ARG gcc/rust/ChangeLog: * backend/rust-constexpr.cc (get_nth_callarg): Remove function. (rs_bind_parameters_in_call): Use CALL_EXPR_ARG instead. (potential_constant_expression_1): Likewise. --- gcc/rust/backend/rust-constexpr.cc | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/gcc/rust/backend/rust-constexpr.cc b/gcc/rust/backend/rust-constexpr.cc index 912d73b5d7c..4e581a3f2cf 100644 --- a/gcc/rust/backend/rust-constexpr.cc +++ b/gcc/rust/backend/rust-constexpr.cc @@ -81,8 +81,6 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, bool potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, tsubst_flags_t flags); -inline tree -get_nth_callarg (tree t, int n); tree unshare_constructor (tree t MEM_STAT_DECL); void @@ -3081,7 +3079,7 @@ rs_bind_parameters_in_call (const constexpr_ctx *ctx, tree t, tree fun, tree type = parms ? TREE_TYPE (parms) : void_type_node; if (parms && DECL_BY_REFERENCE (parms)) type = TREE_TYPE (type); - x = get_nth_callarg (t, i); + x = CALL_EXPR_ARG (t, i); if (TREE_ADDRESSABLE (type)) /* Undo convert_for_arg_passing work here. */ @@ -4080,17 +4078,6 @@ maybe_constexpr_fn (tree t) return (DECL_DECLARED_CONSTEXPR_P (t)); } -// forked from gcc/cp/constexpr.cc get_nth_callarg - -/* We have an expression tree T that represents a call, either CALL_EXPR. - Return the Nth argument. */ - -inline tree -get_nth_callarg (tree t, int n) -{ - return CALL_EXPR_ARG (t, n); -} - // forked from gcc/cp/constexpr.cc var_in_maybe_constexpr_fn /* True if T was declared in a function that might be constexpr: either a @@ -5808,7 +5795,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fun) && !DECL_CONSTRUCTOR_P (fun)) { - tree x = get_nth_callarg (t, 0); + tree x = CALL_EXPR_ARG (t, 0); /* Don't require an immediately constant value, as constexpr substitution might not use the value. */ @@ -5837,7 +5824,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, } for (; i < nargs; ++i) { - tree x = get_nth_callarg (t, i); + tree x = CALL_EXPR_ARG (t, i); /* In a template, reference arguments haven't been converted to REFERENCE_TYPE and we might not even know if the parameter is a reference, so accept lvalue constants too. */ From patchwork Tue Feb 21 12:02:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60058 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1845345wrn; Tue, 21 Feb 2023 04:56:46 -0800 (PST) X-Google-Smtp-Source: AK7set8gXD787XOrpN5amAAP699MNBP6GKozSQLE/mta5WzBASirK5jef7NlY5hAzqPybBJuIZWp X-Received: by 2002:a17:907:7f04:b0:8b1:3191:286f with SMTP id qf4-20020a1709077f0400b008b13191286fmr15472160ejc.25.1676984206630; Tue, 21 Feb 2023 04:56:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984206; cv=none; d=google.com; s=arc-20160816; b=eMWYqzIO1OZY/SJA1/8JPwRZvpGicHCfFiaY1S1iN+qlkrixQZ9pfobMHnWq2jGUgQ q2ldgTXQSGfGNMa4rid8QTujPOu+6eYSEPrX9r9Ik9mQ+KkqdPFpkLCbtkC5bF8cBJw4 ksba8PScqA0YlC7XNUnuSrseFtixT6oeDK8gZpu7bGSp1qQ3iN7PMDs5ANzJobUGVSc7 uulhrOGCsLlvk0MCvkV3OdAd54rmCKxO3VJnAq4YUZ6IS6FaS8vjgksE//2rZhX9AL4f RT10ZTKq7alesOuKdYCG+qoaIn9Vo1WmUWlCx+R2Gl+9XGIaLWzMiBummoj2zDk0Bhaj 9WgQ== 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=ZAOUsP2npSjwiaAmGaIOtVbIZ0LMGLpQCOjDz68RRTM=; b=Qsu9sTxWvj04X4CGOGl4v0Esbw8VPQHjvkkvNVJd8izGNrrAtBBm3X3wHYPAHddGeY /qQoLDjBDgARvBUO40zLhkqPsisNGluQYtALWTScLVO7J6PfMnvsnTLHVYSMRu6EyAEa R9oN7fMYh3v1LJyOQuQCZWFUZcJIupBYRtn+tkpZ8rsXxyFYweZHQ2LZ2kqOj95YxKN4 WWDdNUeTWNEfUSE5yT1GIb10dlQ1VI6TiE7dpySjwDotVGoY8aQYqk+7GmpX49e1coSJ WBI+K5KsAwM1YltQGIpbQ8aSRChzBHuKs2m4OdQH+cexDL8ZI/cwcJo330QxPlHnS4uW t4aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b="EV6N/5pB"; 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 kb17-20020a170907925100b008cdb0cd5e80si7800915ejb.107.2023.02.21.04.56.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:56:46 -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="EV6N/5pB"; 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 8695538E817D for ; Tue, 21 Feb 2023 12:19:42 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id 18760388A412 for ; Tue, 21 Feb 2023 12:04:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 18760388A412 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-x431.google.com with SMTP id l1so3888653wry.10 for ; Tue, 21 Feb 2023 04:04:45 -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=ZAOUsP2npSjwiaAmGaIOtVbIZ0LMGLpQCOjDz68RRTM=; b=EV6N/5pBQpErS+rYdSOp2jOTITCxccVWkMHVXrec0FPnGCP3hczth675NC8Iz5R687 E4gWIGJ4bxMS0fY6ArpN2Qw106iBvMIIjm/v03eJHFkAnwjzo1W+a7UfqFtMN9uIhXXt 78N2a7CpYzgbCMnYKP1WDWyF++uumbbjxI0rxdirVpLSJi4iAQZf0b1eqhUCkjqbaGg2 EoJqyMJHuyrg1tt1lqrlwpAIz2seRGxkEbJDuGBUbC9RldcImv1jcjXbusMMOq+jgyX3 q5xMcs9JF9WWIDsDJpgfPeJQSL6+et+bV/3RP4ZW27NqGRq7a6jHw1EUOAiPRNySPhil 5dUA== 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=ZAOUsP2npSjwiaAmGaIOtVbIZ0LMGLpQCOjDz68RRTM=; b=zbk1QohbI26vS/paoIzIoIEyhMTfkeH9+ju8fYvKQ5mQUrfx0F4Bupo34g6+7XFWiJ q5vOycZC8bSuy1uYHxRCwP6m8TW1/NWpS1SHA1EHLwgXRfO5AO6xz5RM3+ChJdXnlzY2 /xQhKtl6YL7DD5wlIBEZLL+uRir7ClmwuDTecQBCKUZOTonW3YrTPDLGseBjalJtiO7C 0AtyxXP7xJqMJ5ywG7MgRmz/YAKAy5BPHHIThPpZTYeUv9p3gS1GTz0Pad09+TfH7AAW IPiy/AKqSkDMUItYTwS2yzK7v65aipiOB5/qwsoFHy/OJnf8OMPGSl1PA5mgS2wZ71YW U22Q== X-Gm-Message-State: AO0yUKXfuW6qAvG2H9fNUDB894za1g3raA3ExYHgKBh4UiCa6TZTD+yr kCS0JEsL9fexCoSm62b6i2BXubrdRIHP7u1Yqg== X-Received: by 2002:adf:eb07:0:b0:2c7:46f:c410 with SMTP id s7-20020adfeb07000000b002c7046fc410mr1585660wrn.36.1676981084396; Tue, 21 Feb 2023 04:04:44 -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.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:43 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Raiki Tamura Subject: [committed 103/103] gccrs: add math intrinsics Date: Tue, 21 Feb 2023 13:02:33 +0100 Message-Id: <20230221120230.596966-104-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?1758445391265103369?= X-GMAIL-MSGID: =?utf-8?q?1758445391265103369?= From: Raiki Tamura gcc/rust/ChangeLog: * backend/rust-builtins.cc (BuiltinsContext::setup_math_fns): New functions. gcc/testsuite/ChangeLog: * rust/compile/torture/intrinsics-math.rs: New test. --- gcc/rust/backend/rust-builtins.cc | 122 +++++++++++- .../rust/compile/torture/intrinsics-math.rs | 173 ++++++++++++++++++ 2 files changed, 291 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/rust/compile/torture/intrinsics-math.rs diff --git a/gcc/rust/backend/rust-builtins.cc b/gcc/rust/backend/rust-builtins.cc index 66b3becc47a..0517a9aeaf0 100644 --- a/gcc/rust/backend/rust-builtins.cc +++ b/gcc/rust/backend/rust-builtins.cc @@ -59,13 +59,127 @@ BuiltinsContext::setup_overflow_fns () void BuiltinsContext::setup_math_fns () { - tree math_function_type_f32 + tree fn_type_f32_to_f32 = build_function_type_list (float_type_node, float_type_node, NULL_TREE); + tree fn_type_f64_to_f64 + = build_function_type_list (double_type_node, double_type_node, NULL_TREE); + tree fn_type_f32_f32_to_f32 + = build_function_type_list (float_type_node, float_type_node, + float_type_node, NULL_TREE); + tree fn_type_f64_f64_to_f64 + = build_function_type_list (double_type_node, double_type_node, + double_type_node, NULL_TREE); + tree fn_type_f32_i32_to_f32 + = build_function_type_list (float_type_node, float_type_node, + integer_type_node, NULL_TREE); + tree fn_type_f64_i32_to_f64 + = build_function_type_list (double_type_node, double_type_node, + integer_type_node, NULL_TREE); - define_builtin ("sinf32", BUILT_IN_SINF, "__builtin_sinf", "sinf", - math_function_type_f32, builtin_const); define_builtin ("sqrtf32", BUILT_IN_SQRTF, "__builtin_sqrtf", "sqrtf", - math_function_type_f32, builtin_const); + fn_type_f32_to_f32, builtin_const); + define_builtin ("sqrtf64", BUILT_IN_SQRT, "__builtin_sqrt", "sqrt", + fn_type_f64_to_f64, builtin_const); + + define_builtin ("powif32", BUILT_IN_POWIF, "__builtin_powif", "powif", + fn_type_f32_i32_to_f32, builtin_const); + define_builtin ("powif64", BUILT_IN_POWI, "__builtin_powi", "powi", + fn_type_f64_i32_to_f64, builtin_const); + + define_builtin ("sinf32", BUILT_IN_SINF, "__builtin_sinf", "sinf", + fn_type_f32_to_f32, builtin_const); + define_builtin ("sinf64", BUILT_IN_SIN, "__builtin_sin", "sin", + fn_type_f64_to_f64, builtin_const); + + define_builtin ("cosf32", BUILT_IN_COSF, "__builtin_cosf", "cosf", + fn_type_f32_to_f32, builtin_const); + define_builtin ("cosf64", BUILT_IN_COS, "__builtin_cos", "cos", + fn_type_f64_to_f64, builtin_const); + + define_builtin ("powf32", BUILT_IN_POWF, "__builtin_powf", "powf", + fn_type_f32_f32_to_f32, builtin_const); + define_builtin ("powf64", BUILT_IN_POW, "__builtin_pow", "pow", + fn_type_f64_f64_to_f64, builtin_const); + + define_builtin ("expf32", BUILT_IN_EXPF, "__builtin_expf", "expf", + fn_type_f32_to_f32, builtin_const); + define_builtin ("expf64", BUILT_IN_EXP, "__builtin_exp", "exp", + fn_type_f64_to_f64, builtin_const); + + define_builtin ("exp2f32", BUILT_IN_EXP2F, "__builtin_exp2f", "exp2f", + fn_type_f32_to_f32, builtin_const); + define_builtin ("exp2f64", BUILT_IN_EXP2, "__builtin_exp2", "exp2", + fn_type_f64_to_f64, builtin_const); + + define_builtin ("logf32", BUILT_IN_LOGF, "__builtin_logf", "logf", + fn_type_f32_to_f32, builtin_const); + define_builtin ("logf64", BUILT_IN_LOG, "__builtin_log", "log", + fn_type_f64_to_f64, builtin_const); + + define_builtin ("log10f32", BUILT_IN_LOG10F, "__builtin_log10f", "log10f", + fn_type_f32_to_f32, builtin_const); + define_builtin ("log10f64", BUILT_IN_LOG10, "__builtin_log10", "log10", + fn_type_f64_to_f64, builtin_const); + + define_builtin ("log2f32", BUILT_IN_LOG2F, "__builtin_log2f", "log2f", + fn_type_f32_to_f32, builtin_const); + define_builtin ("log2f64", BUILT_IN_LOG2, "__builtin_log2", "log2", + fn_type_f64_to_f64, builtin_const); + + define_builtin ("fmaf32", BUILT_IN_FMAF, "__builtin_fmaf", "fmaf", + fn_type_f32_f32_to_f32, builtin_const); + define_builtin ("fmaf64", BUILT_IN_FMA, "__builtin_fma", "fma", + fn_type_f64_f64_to_f64, builtin_const); + + define_builtin ("fabsf32", BUILT_IN_FABSF, "__builtin_fabsf", "fabsf", + fn_type_f32_to_f32, builtin_const); + define_builtin ("fabsf64", BUILT_IN_FABS, "__builtin_fabs", "fabs", + fn_type_f64_to_f64, builtin_const); + + define_builtin ("minnumf32", BUILT_IN_FMINF, "__builtin_fminf", "fminf", + fn_type_f32_f32_to_f32, builtin_const); + define_builtin ("minnumf64", BUILT_IN_FMIN, "__builtin_fmin", "fmin", + fn_type_f64_f64_to_f64, builtin_const); + + define_builtin ("maxnumf32", BUILT_IN_FMAXF, "__builtin_fmaxf", "fmaxf", + fn_type_f32_f32_to_f32, builtin_const); + define_builtin ("maxnumf64", BUILT_IN_FMAX, "__builtin_fmax", "fmax", + fn_type_f64_f64_to_f64, builtin_const); + + define_builtin ("copysignf32", BUILT_IN_COPYSIGNF, "__builtin_copysignf", + "copysignf", fn_type_f32_f32_to_f32, builtin_const); + define_builtin ("copysignf64", BUILT_IN_COPYSIGN, "__builtin_copysign", + "copysign", fn_type_f64_f64_to_f64, builtin_const); + + define_builtin ("floorf32", BUILT_IN_FLOORF, "__builtin_floorf", "floorf", + fn_type_f32_to_f32, builtin_const); + define_builtin ("floorf64", BUILT_IN_FLOOR, "__builtin_floor", "floor", + fn_type_f64_to_f64, builtin_const); + + define_builtin ("ceilf32", BUILT_IN_CEILF, "__builtin_ceilf", "ceilf", + fn_type_f32_to_f32, builtin_const); + define_builtin ("ceilf64", BUILT_IN_CEIL, "__builtin_ceil", "ceil", + fn_type_f64_to_f64, builtin_const); + + define_builtin ("truncf32", BUILT_IN_TRUNCF, "__builtin_truncf", "truncf", + fn_type_f32_to_f32, builtin_const); + define_builtin ("truncf64", BUILT_IN_TRUNC, "__builtin_trunc", "trunc", + fn_type_f64_to_f64, builtin_const); + + define_builtin ("rintf32", BUILT_IN_RINTF, "__builtin_rintf", "rintf", + fn_type_f32_to_f32, builtin_const); + define_builtin ("rintf64", BUILT_IN_RINT, "__builtin_rint", "rint", + fn_type_f64_to_f64, builtin_const); + + define_builtin ("nearbyintf32", BUILT_IN_NEARBYINTF, "__builtin_nearbyintf", + "nearbyintf", fn_type_f32_to_f32, builtin_const); + define_builtin ("nearbyintf64", BUILT_IN_NEARBYINT, "__builtin_nearbyint", + "nearbyint", fn_type_f64_to_f64, builtin_const); + + define_builtin ("roundf32", BUILT_IN_ROUNDF, "__builtin_roundf", "roundf", + fn_type_f32_to_f32, builtin_const); + define_builtin ("roundf64", BUILT_IN_ROUND, "__builtin_round", "round", + fn_type_f64_to_f64, builtin_const); } void diff --git a/gcc/testsuite/rust/compile/torture/intrinsics-math.rs b/gcc/testsuite/rust/compile/torture/intrinsics-math.rs new file mode 100644 index 00000000000..fb329baafdd --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/intrinsics-math.rs @@ -0,0 +1,173 @@ +// { dg-additional-options -fdump-tree-original } + +#![feature(intrinsics)] +extern "rust-intrinsic" { + pub fn sqrtf32(x: f32) -> f32; + pub fn sqrtf64(x: f64) -> f64; + + pub fn sinf32(x: f32) -> f32; + pub fn sinf64(x: f64) -> f64; + + pub fn cosf32(x: f32) -> f32; + pub fn cosf64(x: f64) -> f64; + + pub fn powf32(a: f32, x: f32) -> f32; + pub fn powf64(a: f64, x: f64) -> f64; + + pub fn expf32(x: f32) -> f32; + pub fn expf64(x: f64) -> f64; + + pub fn exp2f32(x: f32) -> f32; + pub fn exp2f64(x: f64) -> f64; + + pub fn logf32(x: f32) -> f32; + pub fn logf64(x: f64) -> f64; + + pub fn log10f32(x: f32) -> f32; + pub fn log10f64(x: f64) -> f64; + + pub fn log2f32(x: f32) -> f32; + pub fn log2f64(x: f64) -> f64; + + pub fn fmaf32(a: f32, b: f32, c: f32) -> f32; + pub fn fmaf64(a: f64, b: f64, c: f64) -> f64; + + pub fn fabsf32(x: f32) -> f32; + pub fn fabsf64(x: f64) -> f64; + + pub fn minnumf32(x: f32, y: f32) -> f32; + pub fn minnumf64(x: f64, y: f64) -> f64; + + pub fn maxnumf32(x: f32, y: f32) -> f32; + pub fn maxnumf64(x: f64, y: f64) -> f64; + + pub fn copysignf32(x: f32, y: f32) -> f32; + pub fn copysignf64(x: f64, y: f64) -> f64; + + pub fn floorf32(x: f32) -> f32; + pub fn floorf64(x: f64) -> f64; + + pub fn ceilf32(x: f32) -> f32; + pub fn ceilf64(x: f64) -> f64; + + pub fn truncf32(x: f32) -> f32; + pub fn truncf64(x: f64) -> f64; + + pub fn rintf32(x: f32) -> f32; + pub fn rintf64(x: f64) -> f64; + + pub fn nearbyintf32(x: f32) -> f32; + pub fn nearbyintf64(x: f64) -> f64; + + pub fn roundf32(x: f32) -> f32; + pub fn roundf64(x: f64) -> f64; +} + +fn main() { + unsafe fn foo() { + let mut f32; + let mut f64; + + f32 = sqrtf32(1f32); + // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_sqrtf \(1\.0e\+0\);$} 1 original } } + f64 = sqrtf64(2f64); + // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_sqrt \(2\.0e\+0\);$} 1 original } } + + f32 = sinf32(39f32); + // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_sinf \(3\.9e\+1\);$} 1 original } } + f64 = sinf64(40f64); + // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_sin \(4\.0e\+1\);$} 1 original } } + + f32 = cosf32(5f32); + // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_cosf \(5\.0e\+0\);$} 1 original } } + f64 = cosf64(6f64); + // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_cos \(6\.0e\+0\);$} 1 original } } + + f32 = powf32(7f32, 8f32); + // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_powf \(7\.0e\+0, 8\.0e\+0\);$} 1 original } } + f64 = powf64(9f64, 10f64); + // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_pow \(9\.0e\+0, 1\.0e\+1\);$} 1 original } } + + f32 = expf32(11f32); + // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_expf \(1\.1e\+1\);$} 1 original } } + f64 = expf64(12f64); + // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_exp \(1\.2e\+1\);$} 1 original } } + + f32 = exp2f32(13f32); + // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_expf \(1\.1e\+1\);$} 1 original } } + f64 = exp2f64(14f64); + // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_exp \(1\.2e\+1\);$} 1 original } } + + f32 = logf32(15f32); + // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_logf \(1\.5e\+1\);$} 1 original } } + f64 = logf64(16f64); + // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_log \(1\.6e\+1\);$} 1 original } } + + f32 = log10f32(17f32); + // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_log10f \(1\.7e\+1\);$} 1 original } } + f64 = log10f64(18f64); + // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_log10 \(1\.8e\+1\);$} 1 original } } + + f32 = log2f32(19f32); + // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_log2f \(1\.9e\+1\);$} 1 original } } + f64 = log2f64(20f64); + // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_log2 \(2\.0e\+1\);$} 1 original } } + + f32 = fmaf32(21f32, 22f32, 23f32); + // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_fmaf \(2\.1e\+1, 2\.2e\+1, 2\.3e\+1\);$} 1 original } } + f64 = fmaf64(24f64, 25f64, 26f64); + // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_fma \(2\.4e\+1, 2\.5e\+1, 2\.6e\+1\);$} 1 original } } + + f32 = fabsf32(27f32); + // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_fabsf \(2\.7e\+1\);$} 1 original } } + f64 = fabsf64(28f64); + // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_fabs \(2\.8e\+1\);$} 1 original } } + + f32 = minnumf32(29f32, 30f32); + // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_fminf \(2\.9e\+1, 3\.0e\+1\);$} 1 original } } + f64 = minnumf64(31f64, 32f64); + // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_fmin \(3\.1e\+1, 3\.2e\+1\);$} 1 original } } + + f32 = maxnumf32(33f32, 34f32); + // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_fmaxf \(3\.3e\+1, 3\.4e\+1\);$} 1 original } } + f64 = maxnumf64(35f64, 36f64); + // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_fmax \(3\.5e\+1, 3\.6e\+1\);$} 1 original } } + + f32 = copysignf32(37f32, 38f32); + // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_copysignf \(3\.7e\+1, 3\.8e\+1\);$} 1 original } } + f64 = copysignf64(39f64, 40f64); + // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_copysign \(3\.9e\+1, 4\.0e\+1\);$} 1 original } } + + f32 = floorf32(41f32); + // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_floorf \(4\.1e\+1\);$} 1 original } } + f64 = floorf64(42f64); + // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_floor \(4\.2e\+1\);$} 1 original } } + + f32 = ceilf32(43f32); + // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_ceilf \(4\.3e\+1\);$} 1 original } } + f64 = ceilf64(44f64); + // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_ceil \(4\.4e\+1\);$} 1 original } } + + f32 = truncf32(45f32); + // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_truncf \(4\.5e\+1\);$} 1 original } } + f64 = truncf64(46f64); + // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_trunc \(4\.6e\+1\);$} 1 original } } + + f32 = rintf32(47f32); + // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_rintf \(4\.7e\+1\);$} 1 original } } + f64 = rintf64(48f64); + // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_rint \(4\.8e\+1\);$} 1 original } } + + f32 = nearbyintf32(49f32); + // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_nearbyintf \(4\.9e\+1\);$} 1 original } } + f64 = nearbyintf64(50f64); + // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_nearbyint \(5\.0e\+1\);$} 1 original } } + + f32 = roundf32(51f32); + // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_roundf \(5\.1e\+1\);$} 1 original } } + f64 = roundf64(52f64); + // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_round \(5\.2e\+1\);$} 1 original } } + } + + unsafe { foo() }; +}