{"id":2223303,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2223303/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/20260414231905.191063-37-arthur.cohen@embecosm.com/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/1.1/projects/17/?format=json","name":"GNU Compiler Collection","link_name":"gcc","list_id":"gcc-patches.gcc.gnu.org","list_email":"gcc-patches@gcc.gnu.org","web_url":null,"scm_url":null,"webscm_url":null},"msgid":"<20260414231905.191063-37-arthur.cohen@embecosm.com>","date":"2026-04-14T23:18:58","name":"[COMMITTED,37/43] gccrs: Replace usages of chainon","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"1f7dbe5b5d4e30a504d59dc4855f249d5287107e","submitter":{"id":83476,"url":"http://patchwork.ozlabs.org/api/1.1/people/83476/?format=json","name":"Arthur Cohen","email":"arthur.cohen@embecosm.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/20260414231905.191063-37-arthur.cohen@embecosm.com/mbox/","series":[{"id":499900,"url":"http://patchwork.ozlabs.org/api/1.1/series/499900/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=499900","date":"2026-04-14T23:18:24","name":"[COMMITTED,01/43] gccrs: testsuite:Add a testcase for setup_associated_types","version":1,"mbox":"http://patchwork.ozlabs.org/series/499900/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2223303/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2223303/checks/","tags":{},"headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=embecosm.com header.i=@embecosm.com header.a=rsa-sha256\n header.s=google header.b=SJTNVguv;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=embecosm.com header.i=@embecosm.com header.a=rsa-sha256\n header.s=google header.b=SJTNVguv","sourceware.org;\n dmarc=none (p=none dis=none) header.from=embecosm.com","sourceware.org; spf=pass smtp.mailfrom=embecosm.com","server2.sourceware.org;\n arc=none smtp.remote-ip=209.85.128.52"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fwLBb6gl5z1yHc\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 15 Apr 2026 09:31:19 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 8227D4BA23C3\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 14 Apr 2026 23:31:17 +0000 (GMT)","from mail-wm1-f52.google.com (mail-wm1-f52.google.com\n [209.85.128.52])\n by sourceware.org (Postfix) with ESMTPS id 489C14BA23D8\n for <gcc-patches@gcc.gnu.org>; Tue, 14 Apr 2026 23:15:09 +0000 (GMT)","by mail-wm1-f52.google.com with SMTP id\n 5b1f17b1804b1-488d2079582so56259995e9.2\n for <gcc-patches@gcc.gnu.org>; Tue, 14 Apr 2026 16:15:09 -0700 (PDT)","from platypus.localdomain (176-147-231-59.abo.bbox.fr.\n [176.147.231.59]) by smtp.gmail.com with ESMTPSA id\n 5b1f17b1804b1-488f1dd8806sm3325945e9.3.2026.04.14.16.15.05\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Tue, 14 Apr 2026 16:15:06 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 8227D4BA23C3","OpenDKIM Filter v2.11.0 sourceware.org 489C14BA23D8"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 489C14BA23D8","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 489C14BA23D8","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776208509; cv=none;\n b=oHTiclCR9vhNiii5arYiHrYxHajFQW3Zx9/4jK3W2gFe03YjjdbZycWOaxGtogCzP8jSKhRMGPARFyAWpNLKsjuCnGpqDOzYkEvIJXzmPW0hCuRp9pPtfWj0Ew3aZ+lbCC809OadKbgt+6Sbhwf5tEkqmiVnwzOT4zp/J6bTuds=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776208509; c=relaxed/simple;\n bh=13jP3p3YoRPWxfouafJzOay3Oez3yninu/Frl9M3rzI=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=nbcKLtkIamZd5FMcgiJYGw5ISCu5F1y5yFqXJy0137XcRFLe2sytK7IbkCa4odI6sMYQLNRkGaytCmlxYGQs5m2OHjAmMD1rBzHBnnGAEj6fwggVc00kl3WjTKLH7JX1PIiTIzY744CKXg3oTjpTz2bSLuhqAnY3hK1MsyOhOeQ=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=embecosm.com; s=google; t=1776208508; x=1776813308; darn=gcc.gnu.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=JVBUFKzjtbeq3k7kHKERuVA3x7C9HRQK1GxMCQ9XoN0=;\n b=SJTNVguvKK9ijFQ/8B6C7dSz3CMKvAqwdN+udDtefdF8d1qFYe9zuxPthN7lqFvPnp\n N41Q2/oJT9cUVXrHFf8sZj4YBb+zc2mApA8WsO72aKsa+vRfavau/L5kZ8040VzMe/uP\n Ef14/LyceuaIhIEjQMAjKlGXrdpeKe76BfTcpK3TZmPoRx5LG7vFY5rm9gMXDnrbWcrX\n GYFwt83aBKGqfYe4h3OnuZkUiQxnLHwXUjz30s1Q3UxMsGJKVO+RMOzFMSu2mYhuHcDF\n +ciJZ+tJ1NCKTcxSdtm8LJb9444484XJ6O3elM3EYGtesQwctMd2c3fQbfD9CNrif5vd\n Bx1g==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776208508; x=1776813308;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=JVBUFKzjtbeq3k7kHKERuVA3x7C9HRQK1GxMCQ9XoN0=;\n b=SgxKMlJs0ePav/Ks6mGb6cXriG73cGKD33O3WcBdvS7zLESOxkuh0zTtnVF0eLcV9A\n wMIVjudwT0Yr8GNq4OIW+pAFWvYnQ9iUert/k81I389D+a9avZDZwz8//0yWYboLLP2A\n KMVt1glu6QF+SwNhptDw7MkhP8lv/QYaG2bWdCK08yJ1sIGzEEYCTpO/7MMvzfbf8o8T\n mKhcOuKtlJk72lXlSD5Nsuef8s8AYuf8Kcqe+lP43CCi3Z/5pBoJ5kzbH6CICOGyqU3V\n NTrWGAVSZ7aWcoxTXOCC/BmZ00umoacgmHOLnSoiVhFIuImA3CeiLLtS4CvMNMJxLM4o\n CoQg==","X-Gm-Message-State":"AOJu0YxvVrLvdaq0y113mtmda8v7gpMz1GDaPeDMnFUIxeaBIM9mq63d\n oqmPFFZLLHXT1UYYg/YXy95LYYRTqiD7fYl0ylIN57PaVg5ATqvq2n5QvwCL3Rb/cp4GWAcGNq9\n mLXCLew==","X-Gm-Gg":"AeBDieskN5BtjextnOCoN3F62eO6sN1Lu/2+lEi5eV6zCWhsGL3pI+DlLN8GDDKbRAQ\n JfRCbXi1NrhOmz0LEdGZiA2ZmvBVK611VceUyiJ/ilK9coxPVUMWPVWmyXcvg2QWVwJV07Gjs92\n FaIy5xJ08WbRiSD5mvVixTW1XL1o/9N5L/oOp5hGOfxbsMCWlMQd7q7uDpN6ToQnIkgD1rhu0JE\n AZJCXPk//CdO5GcuMDWpFbJLETMIaEhux2O8wprYLZRpSHPb3iMuzXGw1dCuuSJ18vllmgNGy+8\n 6m4uYVgoXokRo2Ph0N7FQWW7vs9qn2bxN4IXjbeT5ujoicsR3aeKvWDwZZ/gJ5xAUyHNfvKD80v\n MtEEMb59q2ERiDXxLFxDW0Rbdcff80xcg7U0ZN7bun/W2qKh1ornMGs0ZBJ2gMlbBRVV6PwRUFW\n t2y07AtgBJ50Bi0dvfgjRrwf0THcPMVzzx/g2bNCrghui8xM6Uc2Qp/5/H++0Udp9NjwGte9zsM\n reHhg==","X-Received":"by 2002:a05:600c:8591:b0:486:fab9:a578 with SMTP id\n 5b1f17b1804b1-488d67eca69mr203643375e9.11.1776208507866;\n Tue, 14 Apr 2026 16:15:07 -0700 (PDT)","From":"arthur.cohen@embecosm.com","To":"gcc-patches@gcc.gnu.org","Cc":"gcc-rust@gcc.gnu.org,\n\tOwen Avery <powerboat9.gamer@gmail.com>","Subject":"[COMMITTED 37/43] gccrs: Replace usages of chainon","Date":"Wed, 15 Apr 2026 01:18:58 +0200","Message-ID":"<20260414231905.191063-37-arthur.cohen@embecosm.com>","X-Mailer":"git-send-email 2.50.1","In-Reply-To":"<20260414231905.191063-1-arthur.cohen@embecosm.com>","References":"<20260414231905.191063-1-arthur.cohen@embecosm.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"},"content":"From: Owen Avery <powerboat9.gamer@gmail.com>\n\ngcc/rust/ChangeLog:\n\n\t* backend/rust-compile-asm.cc: Include \"rust-ggc.h\".\n\t(chain_asm_operand): Use GGC::ChainList.\n\t(CompileAsm::asm_construct_outputs): Likewise.\n\t(CompileAsm::asm_construct_inputs): Likewise.\n\t(CompileLlvmAsm::construct_operands): Likewise.\n\t(CompileLlvmAsm::construct_clobbers): Likewise.\n\t* util/rust-ggc.h (class ChainList): New class.\n\nSigned-off-by: Owen Avery <powerboat9.gamer@gmail.com>\n---\n gcc/rust/backend/rust-compile-asm.cc | 34 ++++++++++++-------------\n gcc/rust/util/rust-ggc.h             | 38 ++++++++++++++++++++++++++++\n 2 files changed, 55 insertions(+), 17 deletions(-)","diff":"diff --git a/gcc/rust/backend/rust-compile-asm.cc b/gcc/rust/backend/rust-compile-asm.cc\nindex be0305a6e50..2ac65bd6520 100644\n--- a/gcc/rust/backend/rust-compile-asm.cc\n+++ b/gcc/rust/backend/rust-compile-asm.cc\n@@ -1,16 +1,16 @@\n #include \"rust-compile-asm.h\"\n #include \"rust-compile-expr.h\"\n #include \"rust-system.h\"\n+#include \"rust-ggc.h\"\n \n namespace Rust {\n namespace Compile {\n \n-static tree\n-chain_asm_operand (tree head, const char *constraint, tree value)\n+static void\n+chain_asm_operand (GGC::ChainList &ls, const char *constraint, tree value)\n {\n   auto name = build_string (strlen (constraint) + 1, constraint);\n-  return chainon (head,\n-\t\t  build_tree_list (build_tree_list (NULL_TREE, name), value));\n+  ls.push_back (build_tree_list (build_tree_list (NULL_TREE, name), value));\n }\n \n CompileAsm::CompileAsm (Context *ctx) : HIRCompileBase (ctx) {}\n@@ -107,7 +107,7 @@ CompileAsm::asm_construct_outputs (HIR::InlineAsm &expr)\n {\n   // TODO: Do i need to do this?\n \n-  tree head = NULL_TREE;\n+  GGC::ChainList ls;\n   for (auto &operand : expr.get_operands ())\n     {\n       tl::optional<std::reference_wrapper<HIR::Expr>> out_expr\n@@ -118,9 +118,9 @@ CompileAsm::asm_construct_outputs (HIR::InlineAsm &expr)\n       tree out_tree = CompileExpr::Compile (*out_expr, this->ctx);\n       // expects a tree list\n       // TODO: This assumes that the output is a register\n-      head = chain_asm_operand (head, \"=r\", out_tree);\n+      chain_asm_operand (ls, \"=r\", out_tree);\n     }\n-  return head;\n+  return ls.get_head ();\n }\n \n tl::optional<std::reference_wrapper<HIR::Expr>>\n@@ -147,7 +147,8 @@ tree\n CompileAsm::asm_construct_inputs (HIR::InlineAsm &expr)\n {\n   // TODO: Do i need to do this?\n-  tree head = NULL_TREE;\n+\n+  GGC::ChainList ls;\n   for (auto &operand : expr.get_operands ())\n     {\n       tl::optional<std::reference_wrapper<HIR::Expr>> in_expr\n@@ -158,9 +159,9 @@ CompileAsm::asm_construct_inputs (HIR::InlineAsm &expr)\n       tree in_tree = CompileExpr::Compile (*in_expr, this->ctx);\n       // expects a tree list\n       // TODO: This assumes that the input is a register\n-      head = chain_asm_operand (head, \"r\", in_tree);\n+      chain_asm_operand (ls, \"r\", in_tree);\n     }\n-  return head;\n+  return ls.get_head ();\n }\n \n tree\n@@ -182,29 +183,28 @@ CompileLlvmAsm::CompileLlvmAsm (Context *ctx) : HIRCompileBase (ctx) {}\n tree\n CompileLlvmAsm::construct_operands (std::vector<HIR::LlvmOperand> operands)\n {\n-  tree head = NULL_TREE;\n+  GGC::ChainList ls;\n   for (auto &operand : operands)\n     {\n       tree t = CompileExpr::Compile (*operand.expr, this->ctx);\n       auto name = build_string (operand.constraint.size () + 1,\n \t\t\t\toperand.constraint.c_str ());\n-      head = chainon (head,\n-\t\t      build_tree_list (build_tree_list (NULL_TREE, name), t));\n+      ls.push_back (build_tree_list (build_tree_list (NULL_TREE, name), t));\n     }\n-  return head;\n+  return ls.get_head ();\n }\n \n tree\n CompileLlvmAsm::construct_clobbers (std::vector<AST::TupleClobber> clobbers)\n {\n-  tree head = NULL_TREE;\n+  GGC::ChainList ls;\n   for (auto &clobber : clobbers)\n     {\n       auto name\n \t= build_string (clobber.symbol.size () + 1, clobber.symbol.c_str ());\n-      head = chainon (head, build_tree_list (NULL_TREE, name));\n+      ls.push_back (build_tree_list (NULL_TREE, name));\n     }\n-  return head;\n+  return ls.get_head ();\n }\n \n tree\ndiff --git a/gcc/rust/util/rust-ggc.h b/gcc/rust/util/rust-ggc.h\nindex e4ebabd412c..eb4b327fb9a 100644\n--- a/gcc/rust/util/rust-ggc.h\n+++ b/gcc/rust/util/rust-ggc.h\n@@ -60,6 +60,44 @@ operator== (const std::string &a, const Ident &b)\n   return b == a;\n }\n \n+class ChainList\n+{\n+  tree head;\n+  tree *tail_cdr;\n+\n+public:\n+  ChainList () : head (NULL_TREE), tail_cdr (&head) {}\n+\n+  ChainList (ChainList &&oth)\n+  {\n+    head = oth.head;\n+    if (oth.tail_cdr == &oth.head)\n+      tail_cdr = &oth.head;\n+    else\n+      tail_cdr = oth.tail_cdr;\n+    oth.head = NULL_TREE;\n+    oth.tail_cdr = &oth.head;\n+  }\n+\n+  ChainList &operator= (ChainList &&oth)\n+  {\n+    this->~ChainList ();\n+    new (this) ChainList (std::move (oth));\n+    return *this;\n+  }\n+\n+  tree get_head () const { return head; }\n+\n+  // TREE_CHAIN (ent) will be modified\n+  // making ent a node in this list\n+  // do not push a single tree to multiple ChainList objects\n+  void push_back (tree ent)\n+  {\n+    *tail_cdr = ent;\n+    tail_cdr = &TREE_CHAIN (ent);\n+  }\n+};\n+\n } // namespace GGC\n \n } // namespace Rust\n","prefixes":["COMMITTED","37/43"]}