From patchwork Wed Apr 5 14:02: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: 79624 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp337464vqo; Wed, 5 Apr 2023 07:11:51 -0700 (PDT) X-Google-Smtp-Source: AKy350Zg9ebujH0Q4whP8sZiOQfU6ymZWUvABrVP795E92ff+/ChsXUBqD3jEXkImCPDjAUFb1bV X-Received: by 2002:a17:906:2cd5:b0:8b8:c06e:52d8 with SMTP id r21-20020a1709062cd500b008b8c06e52d8mr2936769ejr.36.1680703911206; Wed, 05 Apr 2023 07:11:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680703911; cv=none; d=google.com; s=arc-20160816; b=n7CMwDEunyEDzRvqxRHneckdemDQ4D5/E6cqRWDgnPDLm0R+nKGkGJVi2wWMIyJXee Yn/GJKnaSPGOMUOyxrwtT5ovWQoo9FcJxhXNYWZ3CDSwTzsHb93uMOp3mS+KzpMVJu+W tQr0tTsLMqJ925d4/u4hAOcBXj5ZC7/o7l7erZokMMke6ibSPHH8jdA1Br2iUmkwy12G zOnUOH3QYMPUPI61al7dTpGGQcRDICJUQlZguiwuA2nIhpNEeOEaPc7e62UwFgHSHVFb DF6K/dm3C+ncUDGF80Vc1n4ffDyi8EX3m4NzYyEDhXVv8rPFlV7tv03OS497ifNl6sau eRMA== 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=oZDWDde/k2+yujBddSbukxrLiUCZqzqs0Hs9osQBgt8=; b=MtOHjKgh5kkCtXSqeOhZmxfuetIcL6pGVi9/by+q//Vuyoam+Rfhqc2sNtFTEhsDAs a9bA1Iz8+Em3sFOWnvPOPcJIk1oIe2dZR0fKdv7GCOt1HN2/h0Y4omDaMwF8p+RTo0PD IEDeMZ+XzJn9KwXnLtTop2DjnpwcLNTFL8ETrATUEeW+4F07AYepqo87dewi2V+mAAbE n95W9mJZNnrWzu02q8JOC1Yeu2ZNYiYI1RqXMn0JVIz2ncgyQW1ri/N4Pzq+rY6jSS7V nru+JV4bx9Rk8DHogUGGSBHS1Fiz5NmFmLvZBStJE5JHjdtn4gIxRP+tKai+HkVqlGMd IpnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=bo2K0Xuo; 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 z6-20020a1709064e0600b0093341115a9asi8805372eju.307.2023.04.05.07.11.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:11:51 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=bo2K0Xuo; 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 1D6B8394B02A for ; Wed, 5 Apr 2023 14:07:35 +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 2B0E43858D38 for ; Wed, 5 Apr 2023 14:05:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2B0E43858D38 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 he13so1340144wmb.2 for ; Wed, 05 Apr 2023 07:05:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703535; 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=oZDWDde/k2+yujBddSbukxrLiUCZqzqs0Hs9osQBgt8=; b=bo2K0XuoSDx4KzTizuT/bCOOylBwl/kXGKpjQrAIbnn6N7OE63N29MzvLG8ibfwqej mgD0wU7C6Y/t7L7uZMMWjsBxwOCci2BoD508Dpv9DSjDXtWisFF+9X7PgGJXlQZRzwqr O5V7zNz+5Sg0Ltwmm5hwqFj4sh4u1Hikvw4qRNElVRIQrZi9TEx7VZWj5I+OInhg17Kq AhLxzpcdMSueqwkIyHRukcasnWFyPET2RbO48I3cGkBoX4wm4+vX+aKOm4zBghonMhzh xQrCf/WrI2+xc2ooXuriXAA6F6YyJEWTKCHIXZ6Y/lKrN8C9hNZanZkyyIvNwpf3uVur IzQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703535; 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=oZDWDde/k2+yujBddSbukxrLiUCZqzqs0Hs9osQBgt8=; b=op3K6FtSxmXXxi3cf3Qy1/bH7cxRaUhAVAuzoqa03uH7ptJUHVc+kyPyIWQ2rlJiNv iqx4VWkJgjMqQdKcdbDzMp51H8/u8asx+izAM9BL40zdFPk+BqAzLo11sXhSNBQ7crLe p20F3Hx2+yp1Q3JY4mAjCBeC6rdeLv1olLiwbHmwlZVLhDhoaSaZsjPvA6JSgspWGQja 2aaR/U4kQfOYfge3y+Q6GKkMoVpqCo3M6yQcYdcClogjUPn476rkly7eZSsGiwcPB3yv P+nK7kNzz3yx5Z1xt5k2rEEgI4LU7qR2D+S8S1w6nccIXbCAUlB9T8opgP7swfd+yXhz 7GgQ== X-Gm-Message-State: AAQBX9c5mElniX+82rSiW0FP0GS4dP9gv2OZm+bFPQSKMxzbQr64PYZG cyRCvUILyBbQhImEvXUHwv555fKmPgrP4uFLSQ== X-Received: by 2002:a1c:f617:0:b0:3ee:672d:caae with SMTP id w23-20020a1cf617000000b003ee672dcaaemr4752031wmc.36.1680703535616; Wed, 05 Apr 2023 07:05:35 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.05.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:35 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [committed 11/88] gccrs: Change how CompileVarDecl outputs Bvariable's Date: Wed, 5 Apr 2023 16:02:55 +0200 Message-Id: <20230405140411.3016563-12-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405140411.3016563-1-arthur.cohen@embecosm.com> References: <20230405140411.3016563-1-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.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?1762345784124821463?= X-GMAIL-MSGID: =?utf-8?q?1762345784124821463?= From: Owen Avery This allows patterns to declare multiple/no variables gcc/rust/ChangeLog: * backend/rust-compile-base.cc (HIRCompileBase::compile_locals_for_block): Allow patterns to declare zero or multiple variables. * backend/rust-compile-var-decl.h: Change function declaration. Signed-off-by: Owen Avery --- gcc/rust/backend/rust-compile-base.cc | 4 +--- gcc/rust/backend/rust-compile-var-decl.h | 26 ++++++++++++++---------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc index 568abf9ca2c..c108661d983 100644 --- a/gcc/rust/backend/rust-compile-base.cc +++ b/gcc/rust/backend/rust-compile-base.cc @@ -457,9 +457,7 @@ HIRCompileBase::compile_locals_for_block (Context *ctx, Resolver::Rib &rib, // compile the local tree type = TyTyResolveCompile::compile (ctx, tyty); - Bvariable *compiled - = CompileVarDecl::compile (fndecl, type, pattern, ctx); - locals.push_back (compiled); + CompileVarDecl::compile (fndecl, type, pattern, locals, ctx); } return locals; } diff --git a/gcc/rust/backend/rust-compile-var-decl.h b/gcc/rust/backend/rust-compile-var-decl.h index 00146a42e9d..791ee9c1112 100644 --- a/gcc/rust/backend/rust-compile-var-decl.h +++ b/gcc/rust/backend/rust-compile-var-decl.h @@ -30,12 +30,11 @@ class CompileVarDecl : public HIRCompileBase, public HIR::HIRPatternVisitor using HIR::HIRPatternVisitor::visit; public: - static ::Bvariable *compile (tree fndecl, tree translated_type, - HIR::Pattern *pattern, Context *ctx) + static void compile (tree fndecl, tree translated_type, HIR::Pattern *pattern, + std::vector &locals, Context *ctx) { - CompileVarDecl compiler (ctx, fndecl, translated_type); + CompileVarDecl compiler (ctx, fndecl, translated_type, locals); pattern->accept_vis (compiler); - return compiler.compiled_variable; } void visit (HIR::IdentifierPattern &pattern) override @@ -43,26 +42,30 @@ public: if (!pattern.is_mut ()) translated_type = ctx->get_backend ()->immutable_type (translated_type); - compiled_variable + Bvariable *var = ctx->get_backend ()->local_variable (fndecl, pattern.get_identifier (), translated_type, NULL /*decl_var*/, pattern.get_locus ()); HirId stmt_id = pattern.get_pattern_mappings ().get_hirid (); - ctx->insert_var_decl (stmt_id, compiled_variable); + ctx->insert_var_decl (stmt_id, var); + + locals.push_back (var); } void visit (HIR::WildcardPattern &pattern) override { translated_type = ctx->get_backend ()->immutable_type (translated_type); - compiled_variable + Bvariable *var = ctx->get_backend ()->local_variable (fndecl, "_", translated_type, NULL /*decl_var*/, pattern.get_locus ()); HirId stmt_id = pattern.get_pattern_mappings ().get_hirid (); - ctx->insert_var_decl (stmt_id, compiled_variable); + ctx->insert_var_decl (stmt_id, var); + + locals.push_back (var); } // Empty visit for unused Pattern HIR nodes. @@ -78,15 +81,16 @@ public: void visit (HIR::TupleStructPattern &) override {} private: - CompileVarDecl (Context *ctx, tree fndecl, tree translated_type) + CompileVarDecl (Context *ctx, tree fndecl, tree translated_type, + std::vector &locals) : HIRCompileBase (ctx), fndecl (fndecl), translated_type (translated_type), - compiled_variable (ctx->get_backend ()->error_variable ()) + locals (locals) {} tree fndecl; tree translated_type; - Bvariable *compiled_variable; + std::vector &locals; }; } // namespace Compile