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: 1765422 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=embecosm.com header.i=@embecosm.com header.a=rsa-sha256 header.s=google header.b=bo2K0Xuo; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Ps60C2PjVz1yZj for ; Thu, 6 Apr 2023 00:07:39 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D3A30389941C for ; Wed, 5 Apr 2023 14:07: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 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-Google-Smtp-Source: AKy350ZZevs9LwOqQuGH09qENdjEr7b7WFymeiZg5r57b4ObI6dmnwMblGuu3RtnZRjGQvSgx5Tv4Q== 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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