From patchwork Wed Apr 5 14:02: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: 79621 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp335476vqo; Wed, 5 Apr 2023 07:09:11 -0700 (PDT) X-Google-Smtp-Source: AKy350YNBi2jmMaKgmtknJHOEsXPNET9KtjeuRf6Uzk7+7PnnYQEejwlJhOkGfUyActwSzNoKRGY X-Received: by 2002:a17:906:2e86:b0:884:930:b017 with SMTP id o6-20020a1709062e8600b008840930b017mr3154324eji.60.1680703751194; Wed, 05 Apr 2023 07:09:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680703751; cv=none; d=google.com; s=arc-20160816; b=fD5qLnh+X0m73i/VfQuLkrOHkvlDQCbaVvFiryeCVhZsYGpQDvOz7XvDOC/jHQnQwA KRjZpp4FoiPr+mbWSOnlytcojLDa4xXbFW3rrn2Xusv2nM+m/2JlHPCPkA6PuZ7vzA0a zlXneGNtdZa9AuG/Jt+JayOxH2Eyjztgza1W/wSYA6cd8CGVJx4oB1JCh2WLEdUndav2 KRBfiXG8FXExGIHh0d1BK0IUJ6c5CCqdEHpHstWyX7p1jFUmPl2CrwqWEpvc64ND3cpH io1RZ+B+AN+oe/cZc+oL7IJ1kndbDr48TLbx4E5hUPNWRqsxNbmau1br8p6TDtOXQVSx xw/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=9KRxqBSNGTKQudzYYa9cq9QXCkRmXZjXx2LFPc+FxV0=; b=gojgVuvroTbCP4apw7HVX0fMXvkbwVz7kKug0QhdKxZfvMgG0x6lgEfoZZg2KCUBZx frN3POoWtAPDAVVDID6Su7KcdwD4miMLZz3z5lV/x7vZR/H8ptr1gGfxdRUYovB7iyie b0wi5kANtThPpKHLTKWaIStebauOI4/xeiFl+Wd+zFjs+ZhnxX3995Zhz1TNIlc0wO+P iYYefjFtU+jf7zwE31ZaIZuZOjwZamnuQvcels3CIwy3Ic9d+n2P+mXl5/6a/exp/IMP 4pgaOgFRCFB4rUhM78BA8LvpvIplPcdUxvXGko54Q8TWpZ+rweROUB6XiARwhCbZJlKO V+ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=RmRzPc9z; 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 y2-20020a17090668c200b009324eea0cedsi3441470ejr.72.2023.04.05.07.09.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:09:11 -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=RmRzPc9z; 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 481F23885C24 for ; Wed, 5 Apr 2023 14:06: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 DA6ED3858C60 for ; Wed, 5 Apr 2023 14:05:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DA6ED3858C60 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 e18so36325026wra.9 for ; Wed, 05 Apr 2023 07:05:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703519; 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=9KRxqBSNGTKQudzYYa9cq9QXCkRmXZjXx2LFPc+FxV0=; b=RmRzPc9z0cjaS4eWe2ae5kuVLz/iQMMehAtaHmBdJH808hZF6sJ+jqwhbPwDQWzrvi vE3dG4d5sCdlaJOwWmn8T77PfSvxeauH8tpYgPmObkeo5MLhcF5g8dEiTUz63zFKUSDB xjev32V/tGvG1iHqQcroLztuLO+Ue6o/vzG3ntjsBBMc+Bd2m+TcBa5aZPuK0V+Qr9wQ lofk5kCu+UG3M0f+CiSjJpF1jx5Wrgew8TSG+nxjX+/AGfGGX2sTKJe5kMe5Qte/omeW wOjhVR8TOuFn2KNBLr5chVyMaL0M91NTZpkuc0fSUmSYRWnReMeJpwvmK+IoZ+ShB9Ii 6NBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703519; 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=9KRxqBSNGTKQudzYYa9cq9QXCkRmXZjXx2LFPc+FxV0=; b=M6q516jx6z1xppDntO8FxOqYEmIrTc5tT1PtkPHnZounEVAojaRhW1AGeKaeZjQEcb 8dLo3lzJGDyEvLl112avAMrgbdphOAX/uee1DWIcdTOefgrPr7elxKsrimvvi7RbBDnC RhFTL4OSloNMdQ+Y5CGkH669eXTRdunzB0KS+/2L/SZ4KUA6hO+QzPOEEhSaQVTKwEaT YuCLN3yEMcl6XYIr8GSxhk+RJvuMK6VPYER8We2Um3ZWMPOw8upuZbkniapJiKIloCbA 0cRNIpzxwGgtHzDyuXXOnD7hESFLt+d4ctfs+ICqKNyb1Mm9ZhMe5aA9z3IUqEbP9QuS xBGA== X-Gm-Message-State: AAQBX9eoqIUTP/03SfkYkJgn1bKq4XaXGq20NSp+EvqVNxJPK+7yP1lu C6N/CXv2YK6J+lSd0ttwjgci8A7N5mlqPZ9lEw== X-Received: by 2002:adf:e746:0:b0:2dc:cad4:87b9 with SMTP id c6-20020adfe746000000b002dccad487b9mr3755742wrn.68.1680703519318; Wed, 05 Apr 2023 07:05:19 -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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:19 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 01/88] gccrs: fatal_error_flag: Fix typo in error message Date: Wed, 5 Apr 2023 16:02:44 +0200 Message-Id: <20230405140411.3016563-2-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?1762345616688440249?= X-GMAIL-MSGID: =?utf-8?q?1762345616688440249?= From: Arthur Cohen gcc/rust/ChangeLog: * rust-session-manager.cc (Session::compile_crate): Fix typo. --- gcc/rust/rust-session-manager.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc index 732aabe1f26..70b058ff992 100644 --- a/gcc/rust/rust-session-manager.cc +++ b/gcc/rust/rust-session-manager.cc @@ -438,7 +438,7 @@ Session::compile_crate (const char *filename) "manner by passing the following flag:\n\n" "`-frust-incomplete-and-experimental-compiler-do-not-use`\n\nor by " "defining the following environment variable (any value will " - "do)\n\nGCCRS_INCOMPLETE_AND_EXPERIMENTAL_COMPILER_DO_NOT_USE\n\nFor" + "do)\n\nGCCRS_INCOMPLETE_AND_EXPERIMENTAL_COMPILER_DO_NOT_USE\n\nFor " "cargo-gccrs, this means passing\n\n" "GCCRS_EXTRA_FLAGS=\"-frust-incomplete-and-experimental-compiler-do-not-" "use\"\n\nas an environment variable."); From patchwork Wed Apr 5 14:02: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: 79617 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp333375vqo; Wed, 5 Apr 2023 07:06:53 -0700 (PDT) X-Google-Smtp-Source: AKy350ZP20DGXIkWY3zlCMyJC80MqoS6HX/5flbZqDTL9UkV4meR1pFAbGmXMGzVyTzR5atoOcwp X-Received: by 2002:a17:906:6894:b0:944:18ef:c970 with SMTP id n20-20020a170906689400b0094418efc970mr3310083ejr.32.1680703613660; Wed, 05 Apr 2023 07:06:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680703613; cv=none; d=google.com; s=arc-20160816; b=ER8F/dExeiqXhrxo19mmdEtYGEcEn7kZ0YAHHX5r6qDUOUMEbRRQMs7lmFJp0NUrVs dzgxCLTfQ2vINUeK5IrZG8D5o2DVR58TlRVT30FMlYJR+wmNyDaoJi6ZUp3rApYDplXH k+xjWhwFSgsK+cI/k3wVmIxABBr78LBRE33EzOXpONEa8KT2mQuDtmqfhEwDgH58jJrP V/KDTOZMoRkuyyTB7/FFtQMxBm0ym9g4Q7NqC1HexMa0bwtQv7u5I6Yj/0VsZYxYbfqd Xr674AB3NWIV/HDwU7/mc31wXBEWuHd+By/OKv64xeo2qDyZ188o3vRgs8lxcWw2Rj1P wJHw== 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=FP0FHKjiKLOOhKCwIKB/P6DVVdwJ963gOaP8iS2bk6I=; b=FuWf3CgxLTGS1ggthhbIBFavjgkf8b6U0LC4xIRjGAcE9ep98/rPRH6RhxOxsTHlk2 UPrUnwKxzKSMXNw1DiMQKuRc/R2paBb++nB++br7qXzyjaFZU7d9zpLvmI6NUGMWjKiC 9y1fqPtHc2UHXTd5cmyCpmBQ657Q4tmV5cVCvBYv84zYiuaZraIAfZfZ1HfpvXOGLh4G cXA4qdmqZM8GOJ0D5LnibCooJqxASLWGCE/V973cXKjzIl0ng9Q/TjJcPrcpYhEiGATw iXBJICC20tG4DEqlWDKujWNdGo0L2HyAE77K44TJf7l/AT4f1VOXt31hFdW3tTTtY+2b mU7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Fj4eayMf; 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 hg13-20020a1709072ccd00b008bded90af7csi994193ejc.531.2023.04.05.07.06.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:53 -0700 (PDT) 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=Fj4eayMf; 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 3E601387089B for ; Wed, 5 Apr 2023 14:05:59 +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 3C82C3858C2C for ; Wed, 5 Apr 2023 14:05:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3C82C3858C2C 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 d11-20020a05600c3acb00b003ef6e6754c5so18370637wms.5 for ; Wed, 05 Apr 2023 07:05:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703520; 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=FP0FHKjiKLOOhKCwIKB/P6DVVdwJ963gOaP8iS2bk6I=; b=Fj4eayMfqZd7abUGWOTz9M4Bgs4lzRMIjg9DdqrM6Qh8g3opg5SA8mTR6JF1TvH++e KZoB453DVUH8ZgAWjTqgTrEDT/6FLF57sP5+CHv6aM/wDZMf37ZP0neE+Liftw62sX0Z cjVmPoDCqdRjDACfvPwsqLV9vTmbTsBK0U9G0CoYE7xqJPgMMn62LYtwH1zzPtQ2FyfP jzMvYPo1E7Lf0gbKaZi4XJvMnE3ZE+5rqSn08r5uiR9KNdGYGz+/kncM44hMmsKuY0FE ZDdf6pCbdc9Hwse2U/qAEQ+HSIXDwYgIiew87eOcWYWFLLhJPARwIPEZGoOuta4+AXq3 IWbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703520; 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=FP0FHKjiKLOOhKCwIKB/P6DVVdwJ963gOaP8iS2bk6I=; b=QWim909xNbjtxTkm6uNFkNa5iuH3ZfT0qBrOMejKeaT6B5OOBtRRLegUts+uMsZTxv 86JL73fLSfS+8AUZFUYp5ZSPADhbuHR0rr2nd1GQXqAbooh/l3uGBCHEuLld4a8pm1kv k3P1J4q1cWiDW/tA04mQn8YeN4WfprJ2zsYYUczycrvraD3VBQrplvZ1A7K5nGXEFoP7 KrDalmEmPxyvjfQroO7TwuquduRGClOkMpo7U2XpktTPPEzquCMsZ0sCMroQq09Hzm9a T6RI7gnrYJQJQNSNPFo4NAaCTfOWAcP64zusMijkC7B5PMC3fI4fk8puUvszrFpZYzsf CFLQ== X-Gm-Message-State: AAQBX9cNcYef15N3RcB/Xy5GZlDHsqQQHwMGc6uIgKA2WWM2XZjtvx61 kmxE73Fb573bvi8FDx8PuALO7tbPWH+bnM+uGQ== X-Received: by 2002:a1c:f206:0:b0:3f0:5fda:c95f with SMTP id s6-20020a1cf206000000b003f05fdac95fmr3773962wmc.26.1680703520701; Wed, 05 Apr 2023 07:05:20 -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.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:20 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Prajwal S N Subject: [committed 02/88] gccrs: unsafe: check use of `target_feature` attribute Date: Wed, 5 Apr 2023 16:02:45 +0200 Message-Id: <20230405140411.3016563-3-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.6 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?1762345472173846127?= X-GMAIL-MSGID: =?utf-8?q?1762345472173846127?= From: Prajwal S N The `target_feature` attribute is for conditional compilation and may or may not compile on all platforms. Using it requires an unsafe function or block. gcc/rust/ChangeLog: * checks/errors/rust-unsafe-checker.cc (check_target_attr): New function. (UnsafeChecker::check_function_attr): Call into `check_target_attr`. (UnsafeChecker::visit): Check for target_feature attributes. * checks/errors/rust-unsafe-checker.h: Add declarations. * util/rust-attributes.cc: Add attribute. gcc/testsuite/ChangeLog: * rust/compile/unsafe11.rs: New test. Signed-off-by: Prajwal S N --- gcc/rust/checks/errors/rust-unsafe-checker.cc | 29 ++++++++++++++++++- gcc/rust/checks/errors/rust-unsafe-checker.h | 5 ++++ gcc/rust/util/rust-attributes.cc | 3 ++ gcc/testsuite/rust/compile/unsafe11.rs | 8 +++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/rust/compile/unsafe11.rs diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.cc b/gcc/rust/checks/errors/rust-unsafe-checker.cc index 94808632c04..3c369a2a81a 100644 --- a/gcc/rust/checks/errors/rust-unsafe-checker.cc +++ b/gcc/rust/checks/errors/rust-unsafe-checker.cc @@ -179,6 +179,31 @@ UnsafeChecker::check_function_call (HirId node_id, Location locus) locus); } +static void +check_target_attr (HIR::Function *fn, Location locus) +{ + if (std::any_of (fn->get_outer_attrs ().begin (), + fn->get_outer_attrs ().end (), + [] (const AST::Attribute &attr) { + return attr.get_path ().as_string () == "target_feature"; + })) + rust_error_at (locus, + "call to function with %<#[target_feature]%> requires " + "unsafe function or block"); +} + +void +UnsafeChecker::check_function_attr (HirId node_id, Location locus) +{ + if (unsafe_context.is_in_context ()) + return; + + auto maybe_fn = mappings.lookup_hir_item (node_id); + + if (maybe_fn && maybe_fn->get_item_kind () == Item::ItemKind::Function) + check_target_attr (static_cast (maybe_fn), locus); +} + void UnsafeChecker::visit (Lifetime &) {} @@ -398,11 +423,13 @@ UnsafeChecker::visit (CallExpr &expr) rust_assert (mappings.lookup_node_to_hir (ref_node_id, &definition_id)); - // At this point we have the function's HIR Id. There are two checks we + // At this point we have the function's HIR Id. There are three checks we // must perform: // 1. The function is an unsafe one // 2. The function is an extern one + // 3. The function is marked with a target_feature attribute check_function_call (definition_id, expr.get_locus ()); + check_function_attr (definition_id, expr.get_locus ()); if (expr.has_params ()) for (auto &arg : expr.get_arguments ()) diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.h b/gcc/rust/checks/errors/rust-unsafe-checker.h index 9df44db06a9..2abd3a62351 100644 --- a/gcc/rust/checks/errors/rust-unsafe-checker.h +++ b/gcc/rust/checks/errors/rust-unsafe-checker.h @@ -46,6 +46,11 @@ private: */ void check_function_call (HirId node_id, Location locus); + /** + * Check if any unsafe attributes are present on a function + */ + void check_function_attr (HirId node_id, Location locus); + StackedContexts unsafe_context; Resolver::TypeCheckContext &context; diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc index 33f2c932d09..0458f6902b7 100644 --- a/gcc/rust/util/rust-attributes.cc +++ b/gcc/rust/util/rust-attributes.cc @@ -41,6 +41,9 @@ static const BuiltinAttrDefinition __definitions[] {"repr", CODE_GENERATION}, {"path", EXPANSION}, {"macro_use", NAME_RESOLUTION}, + // FIXME: This is not implemented yet, see + // https://github.com/Rust-GCC/gccrs/issues/1475 + {"target_feature", CODE_GENERATION}, // From now on, these are reserved by the compiler and gated through // #![feature(rustc_attrs)] {"rustc_inherit_overflow_checks", CODE_GENERATION}}; diff --git a/gcc/testsuite/rust/compile/unsafe11.rs b/gcc/testsuite/rust/compile/unsafe11.rs new file mode 100644 index 00000000000..c87902fcd5f --- /dev/null +++ b/gcc/testsuite/rust/compile/unsafe11.rs @@ -0,0 +1,8 @@ +#[target_feature(sse)] +fn foo() { + let a: usize = 0; +} + +fn main() { + foo() // { dg-error "requires unsafe function or block" } +} From patchwork Wed Apr 5 14:02: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: 79620 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp335167vqo; Wed, 5 Apr 2023 07:08:46 -0700 (PDT) X-Google-Smtp-Source: AKy350a+rM2erESBI21VHGCTh1UqCb6IhFoPz6E7IjO949YiBOxIE4uQdW3WW5dzmrkEZZB9KiVR X-Received: by 2002:a17:906:653:b0:939:90ee:e086 with SMTP id t19-20020a170906065300b0093990eee086mr2866289ejb.28.1680703725922; Wed, 05 Apr 2023 07:08:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680703725; cv=none; d=google.com; s=arc-20160816; b=axXpO2fwEaVJRZES2glaUhAhtmJsUa6y1eZ1TazcKJafUIfWvvoKITmtiL7ZiyVjlR Tz2I6rrS61RT4lZRSbNAP7WrWN/4WYpi0BiG3SzwxMfuLjT0hTBmJy7HoYyoQpDkYeaV A+E8FMX0ebGp5A7bHJnHQgz34o7n2Se0iqF2iO0nwQPLe9AtthC37BJUC9DHDCyIQQk8 qu+suraOjsvDY8wE947HOTy7CwF9ytd/T0lys50H7sXvifeHzJeCZd8SyqpxOl5siCok i+n/UupjaWKgF9xc+jKl4hJMFKQdjYIKzW87O+6nuEcmztKGllPjy0Qi3hnqWvB0m5YR E6jQ== 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=FSxq5+A8+oY5sQbXA81GHyEj8sJ39KrhMhafqu7g3kM=; b=fWKQUTpqH/pfA3pIFQEulZ6fJ8it4FU8vvRPscPF+T2u4RMuVZEpfIyoazBUJg2Tze k6VHuLAyZaER5ZfcasTU3nX30aAEZ48L3XwV09BxWaWUIDhUv6vpV37st43r0ptoN7Vw AGEDeI3Z9Ec6bIauGdo1NSwqG0DvRPZrcZ7gYEBppFgDA2LvHda2Re3ou9hP8HBZQ/Zc DTblXL7is3soPrp5Oh4v4RpFKmt8vWGe3NjHpZMd+eJ/05jh9dZltqFsBSRVl3gdzEQy xArE7e+NnmD1O9zT3tzn02C7qt0jdlbhHVwHy98mY98GutEYw+O1Y/j2ehPcXQXVc8fg b5Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=O6qjsX0T; 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 qk11-20020a1709077f8b00b00949957e112fsi371382ejc.274.2023.04.05.07.08.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:08:45 -0700 (PDT) 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=O6qjsX0T; 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 4AA6D382A2E2 for ; Wed, 5 Apr 2023 14:06: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 230ED3856DE8 for ; Wed, 5 Apr 2023 14:05:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 230ED3856DE8 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 l12so36314385wrm.10 for ; Wed, 05 Apr 2023 07:05:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703528; 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=FSxq5+A8+oY5sQbXA81GHyEj8sJ39KrhMhafqu7g3kM=; b=O6qjsX0TFaKOcleF7oU7TgNnkjWQ/GZ8cF18osltZg0g1t1E7VijdGqRDMPZlaCzlL SlLRc408cxxnZCxOTp3QUpJLHN61/0dNuocBzIsI3DPnxQhamd7Tp+TLndnF7WuKXuTU jcpFN8sslWREPxyV84XY43eFrU0Kjak30UItr2wgCYvXvZDnC3HeVvR50cpNiDHpsF3p hoAc56OAEJehllEYtwUegCauunvlzXYfh+CpdAbhoevky9+LOzRq/DCEN77QBQJy1yVu sMFqDZm7lq8SY7DbbqEbisoiOk9N36FiqkJpkthLvD5ekLg3szQnum0qh+5hkDx15aAy HoUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703528; 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=FSxq5+A8+oY5sQbXA81GHyEj8sJ39KrhMhafqu7g3kM=; b=H3iwRlHqRS54fx2ijbqatyt+rMvG2mifhQmSCemVunQOrw7IwQEdlHH8eZqCtrcaqv WT44h46JInDVaaNhksSwW3vhpd7L2gvpqpinQ23eFuZ+HOofjAFUQH9QPz/qBqTpwWtJ CVW0JUrFO1c56MX/UQa/CmSKphpvJpBaVsrCNL5Sgwz+Rdl13g4Ajj7/e11gGHXMTzq2 TytjxCL7sBSbTqw5srp9Jfg66OerlPdRn1Zh+MEVKRc47qYgTSMD++97mzQL67ix7J2i SL+BVgeI87/7hQP2xfcu2doQILTQmIIUGeDTlTauUgin77Qj+D8RF3blslGsUFmZvgEf na7A== X-Gm-Message-State: AAQBX9fduzSN7FK1B/7ezNIANW8tdPCvWCKZ9kcXPVQAMa1zmSSCdeqW thh0mim8EKCm1smiZBzygbf9jnajwTk/m6BRxA== X-Received: by 2002:a5d:4b0a:0:b0:2e5:6de5:fe9 with SMTP id v10-20020a5d4b0a000000b002e56de50fe9mr4284820wrq.66.1680703528761; Wed, 05 Apr 2023 07:05:28 -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.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:28 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Dave , Dave Evans Subject: [committed 03/88] gccrs: Check for mutable references in const functions Date: Wed, 5 Apr 2023 16:02:47 +0200 Message-Id: <20230405140411.3016563-4-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.6 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?1762345589990956944?= X-GMAIL-MSGID: =?utf-8?q?1762345589990956944?= From: Dave Use StackedContext instead. Fix error string Signed-off-by: Dave Evans (Squashed commits) Check for mutable references in const functions using StackedContext gcc/rust/ChangeLog: * checks/errors/rust-const-checker.cc (ConstChecker::visit): Use StackedContext class. gcc/testsuite/ChangeLog: * rust/compile/const10.rs: New test. Signed-off-by: Dave Evans --- gcc/rust/checks/errors/rust-const-checker.cc | 8 ++++++-- gcc/testsuite/rust/compile/const10.rs | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/rust/compile/const10.rs diff --git a/gcc/rust/checks/errors/rust-const-checker.cc b/gcc/rust/checks/errors/rust-const-checker.cc index 576c1b170d6..7e31c9f9c28 100644 --- a/gcc/rust/checks/errors/rust-const-checker.cc +++ b/gcc/rust/checks/errors/rust-const-checker.cc @@ -898,8 +898,12 @@ ConstChecker::visit (RawPointerType &) {} void -ConstChecker::visit (ReferenceType &) -{} +ConstChecker::visit (ReferenceType &type) +{ + if (const_context.is_in_context () && type.is_mut ()) + rust_error_at (type.get_locus (), + "mutable references are not allowed in constant functions"); +} void ConstChecker::visit (ArrayType &type) diff --git a/gcc/testsuite/rust/compile/const10.rs b/gcc/testsuite/rust/compile/const10.rs new file mode 100644 index 00000000000..9ab82744fbd --- /dev/null +++ b/gcc/testsuite/rust/compile/const10.rs @@ -0,0 +1,3 @@ +const fn foo (a: &mut i32) { // { dg-error "mutable references are not allowed in constant functions" } + *a = 1; +} From patchwork Wed Apr 5 14:02: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: 79623 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp336513vqo; Wed, 5 Apr 2023 07:10:30 -0700 (PDT) X-Google-Smtp-Source: AKy350bI/GxSybCYBUXYAV04qDoU48G9/cQ1qooas6iHs2/4WsICCvirlVsia7IwWdIuDfXFepd+ X-Received: by 2002:aa7:d859:0:b0:4fa:aee8:235f with SMTP id f25-20020aa7d859000000b004faaee8235fmr1864236eds.9.1680703830244; Wed, 05 Apr 2023 07:10:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680703830; cv=none; d=google.com; s=arc-20160816; b=SLrnPlWQymDiCNob1MKIY5akgIrhB/JJsd9vd2VhaUinoTihbv3NZUVFe6NqZwFVn2 jB5GS1+BWaRUE3BuZqe6Ztyv9AHXjumz0MCGAEQafRS7IAP4SF6b4RlGO1tLlW1YV6vk lpb+t69OJaGq04mJefscI4ZIA0kMSu3AmeBdnTwBaH4bguOtRcX34D24gu+SmoEtWwqU x4IpKdc+iyBDI62TO0mpBQNzEv1Z4O/NpamoWmCdAHjnvdPCOJoV8PMVt69Hfx4aQ5Mu /5J2vtChfJcp/c8W+wzOH2RQ35I0gu0HkncYAgsimnxIVHsqZm4DZZAB1HgPjDl/KylI S/Tg== 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=7jGqIhnCvLCExBSHTdhRQCiCVGfsMOwDCWAqMZ4yqAc=; b=CEURQ93riOfKAp5dJrtPRDkFlCNk3zV8bpmVMJvzRvImu6nyvt9BJR3UvjkekjGOFV cbByESRy99QPoL9H7PGXfYKNcGzBHSUyxlWsSAj6pNo94SOn+DSZoKn/9AHHddpWXKgu AvdVQeMk2IFDSTkPc3AZ5ER47wAqg19Ae0CrvK7aGQ2EMdefGArWnxGK87/FyM4yUuT2 x87NWr8xDLHVthib9+oK0WJx4OhCo4ir5AG+4w0NGWw71N+H2R44RaZPOEakKrxRTCcP 18XmFEYAVcos5FuHA6dgp24Jh+MaU8zxuQtNj+i1liASRtzh9axreTP93vG3Ihtj7uS+ s6Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=fMvcHqWI; 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 q10-20020aa7da8a000000b00501df8f316bsi1506137eds.308.2023.04.05.07.10.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:10:30 -0700 (PDT) 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=fMvcHqWI; 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 525EB38A8166 for ; Wed, 5 Apr 2023 14:07:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id EB3383856251 for ; Wed, 5 Apr 2023 14:05:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EB3383856251 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-x32f.google.com with SMTP id o32so20948765wms.1 for ; Wed, 05 Apr 2023 07:05:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703531; 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=7jGqIhnCvLCExBSHTdhRQCiCVGfsMOwDCWAqMZ4yqAc=; b=fMvcHqWIOkCMLsqizO+3O2Rht2X366y53xtkndaeqfBpRRIDv/XmZfmJDsDBEh+LZt SWf7LlIAWfMp2BXggFMMkl21GFr46ZemSXMuQzP8bmutqqHxkmSIaclMptI6tDtrnwdS byj6DsJkcDZlMLLOgMeEe25V4QpEH2AkSk+MNJYfrM3w8Cw9cPzUQ0lhKZWDD1tKHgky sweOCJxc8ZMAy/99Iv/9YYAQb39rwItOuK65IjiO19iDezD72Bp0U2lMY5RTQC0XpPRz 3K/VayeoL/dFD69pqdBsjj8Br/zYlICsSL4PgzuQTqTdX7al6YeKa+PBNhvT9svZ0TUl zwxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703531; 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=7jGqIhnCvLCExBSHTdhRQCiCVGfsMOwDCWAqMZ4yqAc=; b=6xwuI0NDp7aUgz1X2a3SjWMqmg+jTx6q6QnLAhDTWHPzVpgaeKo9F8M6SXW2oQfeGT QlzmjOO0fSE3SAYzp+CZqD6JeBr+kdcLG0U1DkajpVAMctEG2IMGwwjjXAdUsCart/Ba l+US8+2wluDC6q/ZIAFmpLT6BzZQEYQCZk6t2G+HneiXFS4T4CbWrmPsTLpA/3OeEuW8 pZidNxHF5k+VUHOfTOyKwL18KSWCt3O7HOxORYSdRKyYdFTpMiaNUa7IggVgS8Y1QpIY r/pECcbCmoWgcN/AT2BtjLsviHzyUe9oS/+qBUhLMW5ruZQT+udzevnxY+FY2mtbHMvb XZrg== X-Gm-Message-State: AAQBX9dpY1sgdRqHfxvdI1q6lj/QSGopQX6jfrrq2Ycf72iWkj5Bkdo+ zwZZf7huf9wYjwcbbxVIgeHoGZ+FQG7YZy1cfA== X-Received: by 2002:a05:600c:22d1:b0:3ee:4678:dde with SMTP id 17-20020a05600c22d100b003ee46780ddemr4909219wmg.27.1680703531354; Wed, 05 Apr 2023 07:05:31 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:31 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, mxlol233 Subject: [committed 04/88] gccrs: rust: add bound parsing in parse_generic_arg. Date: Wed, 5 Apr 2023 16:02:48 +0200 Message-Id: <20230405140411.3016563-5-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.6 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?1762345699406579013?= X-GMAIL-MSGID: =?utf-8?q?1762345699406579013?= From: mxlol233 gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_generic_arg): Add proper bound parsing. gcc/testsuite/ChangeLog: * rust/compile/bounds.rs: New test. Signed-off-by: Xiao Ma --- gcc/rust/parse/rust-parse-impl.h | 17 +++++++++++++++++ gcc/testsuite/rust/compile/bounds.rs | 10 ++++++++++ 2 files changed, 27 insertions(+) create mode 100644 gcc/testsuite/rust/compile/bounds.rs diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index cbd40efcc9b..959e0338a10 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -6198,6 +6198,23 @@ Parser::parse_generic_arg () else return AST::GenericArg::create_error (); } + else if (next_tok->get_id () == COLON) + { + lexer.skip_token (); // skip ident + lexer.skip_token (); // skip colon + + auto tok = lexer.peek_token (); + std::vector> bounds + = parse_type_param_bounds (); + + auto type = std::unique_ptr ( + new AST::TraitObjectType (std::move (bounds), tok->get_locus (), + false)); + if (type) + return AST::GenericArg::create_type (std::move (type)); + else + return AST::GenericArg::create_error (); + } lexer.skip_token (); return AST::GenericArg::create_ambiguous (tok->get_str (), tok->get_locus ()); diff --git a/gcc/testsuite/rust/compile/bounds.rs b/gcc/testsuite/rust/compile/bounds.rs new file mode 100644 index 00000000000..ecb10d81f65 --- /dev/null +++ b/gcc/testsuite/rust/compile/bounds.rs @@ -0,0 +1,10 @@ +trait Foo { + type Bar; +} + +trait Copy {} + + +fn c>() where F::Bar: Copy { // { dg-warning "function is never used: 'c'" } +} + From patchwork Wed Apr 5 14:02:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 79619 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp334595vqo; Wed, 5 Apr 2023 07:08:09 -0700 (PDT) X-Google-Smtp-Source: AKy350bKurKhgPAwBxacdZIosO64lZGNTTezQemDDAdKqv22uQtpTpOQssKn35J0n6ykQRl261ZG X-Received: by 2002:a17:906:f988:b0:931:6b2b:a671 with SMTP id li8-20020a170906f98800b009316b2ba671mr2893511ejb.65.1680703689165; Wed, 05 Apr 2023 07:08:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680703689; cv=none; d=google.com; s=arc-20160816; b=nENft37/Xkq8EX4aV8Ddo0WM8eBZ+qnAJbgHu/rCOTFP81x8v4/ltbQBfgtv4ySVdG uPiBaZlyh2HFGg4vrxKmkuf//t9MeMz/HQX9sqRMEX5otmm4obdL3lY0/idk/9C+TofL bFom0CDQCBxc/8V8XbcFmJHycTHLfsL0BI2hPDLv3wzRxGZxs//hNuf+N9hsKyg4dA7O BUDG9AXrLZIybZYF7V4pVHL87hpj31X9qh4M1v1nKpUVhuWOUFHn2YieIWzZE14oulTN vcLaobChPSLLjT6PdII6JXCqSCBkdULnkdXo/GciKtw5xYqVMbbDtu+ijmWX5GApMg0G eiPQ== 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=fey2adoMyhHkhtZZLm06vZfC1VjIUPwv0hjPjOivt98=; b=dYJwxVz/zXIoamoCB61wC6umxjUxdArdU1ODgytidZSqrvX2J/fVeFcp090+f4WAyw miGqNqLY3ywD6Cf8fll4iDQg6ot2/m/GDRudPNt0tQg8rstY8VB0gl7HhWyTMj31lAts idmlqOv40AbsNGUEKeBBPvAx4d+056k8q1r278EQmFZIOelKckU1V3Y8gRuk7eRI8OUe 23K8x3wPXJZDEx2HWYKYTQiLNOzRKVs5H10etJP79rwqx7Moy09zKL9d5eVls3SjElIE i1nx8jpsXCU7GcSdrNePEU/9IqwfTPrBnFbI5rZM1uYToh14TewjD7h1PWgQ9b2YVjJd a4zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b="TX/+nac1"; 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 f22-20020a170906049600b009332ffacd59si74744eja.765.2023.04.05.07.08.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:08:09 -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="TX/+nac1"; 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 1B07B3882050 for ; Wed, 5 Apr 2023 14:06:26 +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 9600D3856974 for ; Wed, 5 Apr 2023 14:05:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9600D3856974 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 m6-20020a05600c3b0600b003ee6e324b19so22072170wms.1 for ; Wed, 05 Apr 2023 07:05:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703532; 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=fey2adoMyhHkhtZZLm06vZfC1VjIUPwv0hjPjOivt98=; b=TX/+nac1no4MGt4QGpFA2+PZE3rmGsZT+oGcdZt73wRD/yT+CpMUzdZ8gplximcYxY OdD6e4/xWNjGX+pWnfV9c08odZuLpa81B6GxNhLfH02RQOheC6FIlX457sy6dWzEWUj9 fbtbUp2KWmaTwkGw0egwDrHRTEdaRle0HcjraDyIjUThjYuDAJ5vpUJ6pFJ7Nl9dVElx 7xDV/BDL/LsY0IKwf5ZEVSvjo+V6UrhnH0klH32bW2RnzTnDZuRvOsBGtd9PPuwwFUkl 743nZFrFJgjjYUvy644rGnvy6GomCH1vAA9hnE1c90MLTyU8vpGPCsbNzdlymvLAc9Xu FcMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703532; 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=fey2adoMyhHkhtZZLm06vZfC1VjIUPwv0hjPjOivt98=; b=5wK3MxXwPXfJgKsTl1ojMgyrRs+xwkNpJmziqNM860Y+mDzZN8CrCQRQ6v4Qs74Unp q+ZopnDRTr02Sc9dkRzGIwymUiHZAh4XEl7gFvbROCPvUwf9uOy9wdZ3xa8HsqYqI9KU s/kBYfoMCukyBUbO9e8wqLVMOi6jreKgoBPAmumZ4Caeg5iKWUL8jAxYAwtaCUjTvq3g 271qJFbvILNbhvT4VaveYAqj+0CVqxXMwWZHNCcheHZBg4XfsszItyB5IFBmYjulHvS4 +e3MkhKkcxYqgiS5OM/DewfkGzB+XO5/DyaYtoI66+MYCt1p8oaVauaLdYtuImm46fIh 7CLA== X-Gm-Message-State: AAQBX9cqHXhmhHcXB10dUqkxS/oR72bowUlyUbRou0r7Bf+ex8oAxx+Q NRsAnT3kUioo80PSYuU4y1+FrpKoPgZ7ScpzJg== X-Received: by 2002:a7b:c7cd:0:b0:3df:e6bb:768 with SMTP id z13-20020a7bc7cd000000b003dfe6bb0768mr4705848wmk.24.1680703531754; Wed, 05 Apr 2023 07:05:31 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:31 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Raiki Tamura Subject: [committed 05/88] gccrs: Implement declarative macro 2.0 parser Date: Wed, 5 Apr 2023 16:02:49 +0200 Message-Id: <20230405140411.3016563-6-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.6 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?1762345551143988528?= X-GMAIL-MSGID: =?utf-8?q?1762345551143988528?= From: Raiki Tamura gcc/rust/ChangeLog: * ast/rust-ast-full-decls.h (class MacroItem): Remove forward declaration. * ast/rust-ast-full-test.cc (MacroRulesDefinition): Rework MacroRulesDefinition class * ast/rust-ast.h (class MacroItem): Remove abstract class. * ast/rust-item.h (class MacroItem): Remove forward declaration. * ast/rust-macro.h (class MacroItem): Likewise. (class MacroRulesDefinition): Add MacroKind enum. (class MacroInvocation): Fix inheritance. * lex/rust-token.h: Token "macro" is now used. * parse/rust-parse-impl.h (Parser::parse_item): Add handling for MACRO. (Parser::parse_vis_item): Call into parse_decl_macro_def. (Parser::parse_macro_item): Delete function. (Parser::parse_macro_rules_def): Return MBE macros only. (Parser::parse_decl_macro_def): New function. (Parser::parse_stmt): Handle MACRO token. (Parser::parse_stmt_or_expr_without_block): Call into parse_macro_rules_def. * parse/rust-parse.h: Declare new function. gcc/testsuite/ChangeLog: * rust/compile/decl_macro1.rs: New test. * rust/compile/decl_macro2.rs: New test. * rust/compile/decl_macro3.rs: New test. * rust/compile/decl_macro4.rs: New test. * rust/compile/decl_macro5.rs: New test. * rust/compile/decl_macro6.rs: New test. * rust/compile/decl_macro7.rs: New test. * rust/execute/torture/decl_macro1.rs: New test. * rust/execute/torture/decl_macro2.rs: New test. * rust/execute/torture/decl_macro3.rs: New test. * rust/execute/torture/decl_macro4.rs: New test. Signed-off-by: Raiki Tamura --- gcc/rust/ast/rust-ast-full-decls.h | 1 - gcc/rust/ast/rust-ast-full-test.cc | 1 + gcc/rust/ast/rust-ast.h | 5 - gcc/rust/ast/rust-item.h | 2 - gcc/rust/ast/rust-macro.h | 65 +++-- gcc/rust/lex/rust-token.h | 2 +- gcc/rust/parse/rust-parse-impl.h | 229 +++++++++++++----- gcc/rust/parse/rust-parse.h | 3 +- gcc/testsuite/rust/compile/decl_macro1.rs | 2 + gcc/testsuite/rust/compile/decl_macro2.rs | 2 + gcc/testsuite/rust/compile/decl_macro3.rs | 4 + gcc/testsuite/rust/compile/decl_macro4.rs | 5 + gcc/testsuite/rust/compile/decl_macro5.rs | 5 + gcc/testsuite/rust/compile/decl_macro6.rs | 5 + gcc/testsuite/rust/compile/decl_macro7.rs | 4 + .../rust/execute/torture/decl_macro1.rs | 8 + .../rust/execute/torture/decl_macro2.rs | 8 + .../rust/execute/torture/decl_macro3.rs | 15 ++ .../rust/execute/torture/decl_macro4.rs | 15 ++ 19 files changed, 301 insertions(+), 80 deletions(-) create mode 100644 gcc/testsuite/rust/compile/decl_macro1.rs create mode 100644 gcc/testsuite/rust/compile/decl_macro2.rs create mode 100644 gcc/testsuite/rust/compile/decl_macro3.rs create mode 100644 gcc/testsuite/rust/compile/decl_macro4.rs create mode 100644 gcc/testsuite/rust/compile/decl_macro5.rs create mode 100644 gcc/testsuite/rust/compile/decl_macro6.rs create mode 100644 gcc/testsuite/rust/compile/decl_macro7.rs create mode 100644 gcc/testsuite/rust/execute/torture/decl_macro1.rs create mode 100644 gcc/testsuite/rust/execute/torture/decl_macro2.rs create mode 100644 gcc/testsuite/rust/execute/torture/decl_macro3.rs create mode 100644 gcc/testsuite/rust/execute/torture/decl_macro4.rs diff --git a/gcc/rust/ast/rust-ast-full-decls.h b/gcc/rust/ast/rust-ast-full-decls.h index 136a25ab9aa..58b12a1be0e 100644 --- a/gcc/rust/ast/rust-ast-full-decls.h +++ b/gcc/rust/ast/rust-ast-full-decls.h @@ -51,7 +51,6 @@ class Lifetime; class GenericParam; class LifetimeParam; class ConstGenericParam; -class MacroItem; class TraitItem; class InherentImplItem; class TraitImplItem; diff --git a/gcc/rust/ast/rust-ast-full-test.cc b/gcc/rust/ast/rust-ast-full-test.cc index 4f593dcbd49..280f59ffb16 100644 --- a/gcc/rust/ast/rust-ast-full-test.cc +++ b/gcc/rust/ast/rust-ast-full-test.cc @@ -1284,6 +1284,7 @@ MacroRulesDefinition::as_string () const // get outer attrs str += append_attributes (outer_attrs, OUTER); + // TODO: deal with macro_2_0 str += "macro_rules!"; str += rule_name; diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index aa86f2f9826..5f18233eb0f 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -1350,11 +1350,6 @@ protected: } }; -// A macro item AST node - abstract base class -class MacroItem : public Item -{ -}; - // Item used in trait declarations - abstract base class class TraitItem { diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 7ea7b86562f..37ed2beabfc 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -4391,8 +4391,6 @@ protected: } }; -// Replaced with forward decls - defined in "rust-macro.h" -class MacroItem; class MacroRulesDefinition; } // namespace AST } // namespace Rust diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h index fc4b5b82fb5..bff8c7ac6fb 100644 --- a/gcc/rust/ast/rust-macro.h +++ b/gcc/rust/ast/rust-macro.h @@ -23,13 +23,11 @@ #include "rust-ast.h" #include "rust-ast-fragment.h" #include "rust-location.h" +#include "rust-item.h" +#include "rust-make-unique.h" namespace Rust { namespace AST { - -// Decls as definitions moved to rust-ast.h -class MacroItem; - class MacroFragSpec { public: @@ -446,8 +444,18 @@ public: }; // A macro rules definition item AST node -class MacroRulesDefinition : public MacroItem +class MacroRulesDefinition : public VisItem { +public: + enum MacroKind + { + // Macro by Example (legacy macro rules) + MBE, + // Declarative macros 2.0 + DeclMacro, + }; + +private: std::vector outer_attrs; Identifier rule_name; // MacroRulesDef rules_def; @@ -460,6 +468,7 @@ class MacroRulesDefinition : public MacroItem std::function associated_transcriber; // Since we can't compare std::functions, we need to use an extra boolean bool is_builtin_rule; + MacroKind kind; /** * Default function to use as an associated transcriber. This function should @@ -479,27 +488,51 @@ class MacroRulesDefinition : public MacroItem * I am not aware of the implications of this decision. The rustc spec does * mention that using the same parser for macro definitions and invocations * is "extremely self-referential and non-intuitive". */ - -public: - std::string as_string () const override; - MacroRulesDefinition (Identifier rule_name, DelimType delim_type, std::vector rules, - std::vector outer_attrs, Location locus) - : outer_attrs (std::move (outer_attrs)), rule_name (std::move (rule_name)), + std::vector outer_attrs, Location locus, + MacroKind kind, Visibility vis) + : VisItem (std::move (vis), outer_attrs), + outer_attrs (std::move (outer_attrs)), rule_name (std::move (rule_name)), delim_type (delim_type), rules (std::move (rules)), locus (locus), - associated_transcriber (dummy_builtin), is_builtin_rule (false) + associated_transcriber (dummy_builtin), is_builtin_rule (false), + kind (kind) {} MacroRulesDefinition ( Identifier builtin_name, DelimType delim_type, - std::function associated_transcriber) - : outer_attrs (std::vector ()), rule_name (builtin_name), + std::function associated_transcriber, + MacroKind kind, Visibility vis) + : VisItem (std::move (vis), std::vector ()), + outer_attrs (std::vector ()), rule_name (builtin_name), delim_type (delim_type), rules (std::vector ()), locus (Location ()), associated_transcriber (associated_transcriber), - is_builtin_rule (true) + is_builtin_rule (true), kind (kind) {} +public: + std::string as_string () const override; + + static std::unique_ptr + mbe (Identifier rule_name, DelimType delim_type, std::vector rules, + std::vector outer_attrs, Location locus) + { + return Rust::make_unique ( + MacroRulesDefinition (rule_name, delim_type, rules, outer_attrs, locus, + AST::MacroRulesDefinition::MacroKind::MBE, + AST::Visibility::create_error ())); + } + + static std::unique_ptr + decl_macro (Identifier rule_name, std::vector rules, + std::vector outer_attrs, Location locus, + Visibility vis) + { + return Rust::make_unique (MacroRulesDefinition ( + rule_name, AST::DelimType::CURLY, rules, outer_attrs, locus, + AST::MacroRulesDefinition::MacroKind::DeclMacro, vis)); + } + void accept_vis (ASTVisitor &vis) override; // Invalid if rule name is empty, so base stripping on that. @@ -549,7 +582,7 @@ protected: * compile time */ class MacroInvocation : public TypeNoBounds, public Pattern, - public MacroItem, + public Item, public TraitItem, public TraitImplItem, public InherentImplItem, diff --git a/gcc/rust/lex/rust-token.h b/gcc/rust/lex/rust-token.h index 18f1afa664b..0fc55a20beb 100644 --- a/gcc/rust/lex/rust-token.h +++ b/gcc/rust/lex/rust-token.h @@ -171,7 +171,7 @@ enum PrimitiveCoreType RS_TOKEN_KEYWORD (IN, "in") \ RS_TOKEN_KEYWORD (LET, "let") \ RS_TOKEN_KEYWORD (LOOP, "loop") \ - RS_TOKEN_KEYWORD (MACRO, "macro") /* unused */ \ + RS_TOKEN_KEYWORD (MACRO, "macro") \ RS_TOKEN_KEYWORD (MATCH_TOK, "match") \ RS_TOKEN_KEYWORD (MOD, "mod") \ RS_TOKEN_KEYWORD (MOVE, "move") \ diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 959e0338a10..d71bafded63 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -1032,11 +1032,6 @@ Parser::parse_item (bool called_from_statement) // parse outer attributes for item AST::AttrVec outer_attrs = parse_outer_attributes (); - - // TODO: decide how to deal with VisItem vs MacroItem dichotomy - /* best current solution: catch all keywords that would imply a VisItem in a - * switch and have MacroItem as a last resort */ - const_TokenPtr t = lexer.peek_token (); switch (t->get_id ()) @@ -1064,6 +1059,7 @@ Parser::parse_item (bool called_from_statement) case STATIC_TOK: case TRAIT: case IMPL: + case MACRO: /* TODO: implement union keyword but not really because of * context-dependence crappy hack way to parse a union written below to * separate it from the good code. */ @@ -1078,7 +1074,7 @@ Parser::parse_item (bool called_from_statement) case CRATE: case DOLLAR_SIGN: // almost certainly macro invocation semi - return parse_macro_item (std::move (outer_attrs)); + return parse_macro_invocation_semi (std::move (outer_attrs)); break; // crappy hack to do union "keyword" case IDENTIFIER: @@ -1092,19 +1088,18 @@ Parser::parse_item (bool called_from_statement) else if (t->get_str () == "macro_rules") { // macro_rules! macro item - return parse_macro_item (std::move (outer_attrs)); + return parse_macro_rules_def (std::move (outer_attrs)); } else if (lexer.peek_token (1)->get_id () == SCOPE_RESOLUTION || lexer.peek_token (1)->get_id () == EXCLAM) { /* path (probably) or macro invocation, so probably a macro invocation * semi */ - return parse_macro_item (std::move (outer_attrs)); + return parse_macro_invocation_semi (std::move (outer_attrs)); } gcc_fallthrough (); default: // otherwise unrecognised - // return parse_macro_item(std::move(outer_attrs)); add_error (Error (t->get_locus (), "unrecognised token %qs for start of %s", t->get_token_description (), @@ -1335,6 +1330,8 @@ Parser::parse_vis_item (AST::AttrVec outer_attrs) lexer.skip_token (1); // TODO: is this right thing to do? return nullptr; } + case MACRO: + return parse_decl_macro_def (std::move (vis), std::move (outer_attrs)); default: // otherwise vis item clearly doesn't exist, which is not an error // has a catch-all post-switch return to allow other breaks to occur @@ -1343,42 +1340,6 @@ Parser::parse_vis_item (AST::AttrVec outer_attrs) return nullptr; } -// Parses a MacroItem (either a MacroInvocationSemi or MacroRulesDefinition). -template -std::unique_ptr -Parser::parse_macro_item (AST::AttrVec outer_attrs) -{ - const_TokenPtr t = lexer.peek_token (); - - /* dodgy way of detecting macro due to weird context-dependence thing. - * probably can be improved */ - // TODO: ensure that string compare works properly - if (t->get_id () == IDENTIFIER && t->get_str () == "macro_rules") - { - return parse_macro_rules_def (std::move (outer_attrs)); - } - else - { - // DEBUG: TODO: remove - rust_debug ( - "DEBUG - parse_macro_item called and token is not macro_rules"); - if (t->get_id () == IDENTIFIER) - { - rust_debug ("just add to last error: token is not macro_rules and is " - "instead '%s'", - t->get_str ().c_str ()); - } - else - { - rust_debug ("just add to last error: token is not macro_rules and is " - "not an identifier either - it is '%s'", - t->get_token_description ()); - } - - return parse_macro_invocation_semi (std::move (outer_attrs)); - } -} - // Parses a macro rules definition syntax extension whatever thing. template std::unique_ptr @@ -1512,16 +1473,16 @@ Parser::parse_macro_rules_def (AST::AttrVec outer_attrs) { // as this is the end, allow recovery (probably) - may change return std::unique_ptr ( - new AST::MacroRulesDefinition ( + AST::MacroRulesDefinition::mbe ( std::move (rule_name), delim_type, std::move (macro_rules), std::move (outer_attrs), macro_locus)); } } return std::unique_ptr ( - new AST::MacroRulesDefinition (std::move (rule_name), delim_type, - std::move (macro_rules), - std::move (outer_attrs), macro_locus)); + AST::MacroRulesDefinition::mbe (std::move (rule_name), delim_type, + std::move (macro_rules), + std::move (outer_attrs), macro_locus)); } else { @@ -1541,6 +1502,165 @@ Parser::parse_macro_rules_def (AST::AttrVec outer_attrs) } } +// Parses a declarative macro 2.0 definition. +template +std::unique_ptr +Parser::parse_decl_macro_def (AST::Visibility vis, + AST::AttrVec outer_attrs) +{ + // ensure that first token is identifier saying "macro" + const_TokenPtr t = lexer.peek_token (); + if (t->get_id () != MACRO) + { + Error error ( + t->get_locus (), + "declarative macro definition does not start with %"); + add_error (std::move (error)); + + // skip after somewhere? + return nullptr; + } + lexer.skip_token (); + Location macro_locus = t->get_locus (); + + // parse macro name + const_TokenPtr ident_tok = expect_token (IDENTIFIER); + if (ident_tok == nullptr) + { + return nullptr; + } + Identifier rule_name = ident_tok->get_str (); + + t = lexer.peek_token (); + if (t->get_id () == LEFT_PAREN) + { + // single definiton of macro rule + // e.g. `macro foo($e:expr) {}` + + // parse macro matcher + Location locus = lexer.peek_token ()->get_locus (); + AST::MacroMatcher matcher = parse_macro_matcher (); + if (matcher.is_error ()) + return nullptr; + + // check delimiter of macro matcher + if (matcher.get_delim_type () != AST::DelimType::PARENS) + { + Error error (locus, "only parenthesis can be used for a macro " + "matcher in declarative macro definition"); + add_error (std::move (error)); + return nullptr; + } + + Location transcriber_loc = lexer.peek_token ()->get_locus (); + AST::DelimTokenTree delim_tok_tree = parse_delim_token_tree (); + AST::MacroTranscriber transcriber (delim_tok_tree, transcriber_loc); + + if (transcriber.get_token_tree ().get_delim_type () + != AST::DelimType::CURLY) + { + Error error (transcriber_loc, + "only braces can be used for a macro transcriber " + "in declarative macro definition"); + add_error (std::move (error)); + return nullptr; + } + + AST::MacroRule macro_rule + = AST::MacroRule (std::move (matcher), std::move (transcriber), locus); + std::vector macro_rules; + macro_rules.push_back (macro_rule); + + return std::unique_ptr ( + AST::MacroRulesDefinition::decl_macro (std::move (rule_name), + macro_rules, + std::move (outer_attrs), + macro_locus, vis)); + } + else if (t->get_id () == LEFT_CURLY) + { + // multiple definitions of macro rule separated by comma + // e.g. `macro foo { () => {}, ($e:expr) => {}, }` + + // parse left curly + const_TokenPtr left_curly = expect_token (LEFT_CURLY); + if (left_curly == nullptr) + { + return nullptr; + } + + // parse actual macro rules + std::vector macro_rules; + + // must be at least one macro rule, so parse it + AST::MacroRule initial_rule = parse_macro_rule (); + if (initial_rule.is_error ()) + { + Error error ( + lexer.peek_token ()->get_locus (), + "required first macro rule in declarative macro definition " + "could not be parsed"); + add_error (std::move (error)); + + // skip after somewhere? + return nullptr; + } + macro_rules.push_back (std::move (initial_rule)); + + t = lexer.peek_token (); + // parse macro rules + while (t->get_id () == COMMA) + { + // skip comma + lexer.skip_token (); + + // don't parse if end of macro rules + if (token_id_matches_delims (lexer.peek_token ()->get_id (), + AST::CURLY)) + { + break; + } + + // try to parse next rule + AST::MacroRule rule = parse_macro_rule (); + if (rule.is_error ()) + { + Error error ( + lexer.peek_token ()->get_locus (), + "failed to parse macro rule in declarative macro definition"); + add_error (std::move (error)); + + return nullptr; + } + + macro_rules.push_back (std::move (rule)); + + t = lexer.peek_token (); + } + + // parse right curly + const_TokenPtr right_curly = expect_token (RIGHT_CURLY); + if (right_curly == nullptr) + { + return nullptr; + } + + return std::unique_ptr ( + AST::MacroRulesDefinition::decl_macro (std::move (rule_name), + std::move (macro_rules), + std::move (outer_attrs), + macro_locus, vis)); + } + else + { + add_error (Error (t->get_locus (), + "unexpected token %qs - expecting delimiters " + "(for a declarative macro definiton)", + t->get_token_description ())); + return nullptr; + } +} + // Parses a semi-coloned (except for full block) macro invocation item. template std::unique_ptr @@ -6004,6 +6124,7 @@ Parser::parse_stmt (ParseRestrictions restrictions) case STATIC_TOK: case TRAIT: case IMPL: + case MACRO: /* TODO: implement union keyword but not really because of * context-dependence crappy hack way to parse a union written below to * separate it from the good code. */ @@ -6019,7 +6140,7 @@ Parser::parse_stmt (ParseRestrictions restrictions) case CRATE: case DOLLAR_SIGN: // almost certainly macro invocation semi - return parse_macro_item (std::move (outer_attrs)); + return parse_macro_invocation_semi (std::move (outer_attrs)); break; // crappy hack to do union "keyword" case IDENTIFIER: @@ -6032,7 +6153,7 @@ Parser::parse_stmt (ParseRestrictions restrictions) else if (t->get_str () == "macro_rules") { // macro_rules! macro item - return parse_macro_item (std::move (outer_attrs)); + return parse_macro_rules_def (std::move (outer_attrs)); } else if (lexer.peek_token (1)->get_id () == SCOPE_RESOLUTION || lexer.peek_token (1)->get_id () == EXCLAM) @@ -6040,7 +6161,7 @@ Parser::parse_stmt (ParseRestrictions restrictions) // FIXME: ensure doesn't take any expressions by mistake /* path (probably) or macro invocation, so probably a macro * invocation semi */ - return parse_macro_item (std::move (outer_attrs)); + return parse_macro_invocation_semi (std::move (outer_attrs)); } gcc_fallthrough (); // TODO: find out how to disable gcc "implicit fallthrough" warning @@ -11711,8 +11832,8 @@ Parser::parse_stmt_or_expr_without_block () else if (t->get_str () == "macro_rules") { // macro_rules! macro item - std::unique_ptr item ( - parse_macro_item (std::move (outer_attrs))); + std::unique_ptr item ( + parse_macro_rules_def (std::move (outer_attrs))); return ExprOrStmt (std::move (item)); } else if (lexer.peek_token (1)->get_id () == SCOPE_RESOLUTION diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index 8449181b12f..5c0fcc3f174 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -197,6 +197,8 @@ private: AST::DelimTokenTree parse_delim_token_tree (); std::unique_ptr parse_macro_rules_def (AST::AttrVec outer_attrs); + std::unique_ptr + parse_decl_macro_def (AST::Visibility vis, AST::AttrVec outer_attrs); std::unique_ptr parse_macro_invocation_semi (AST::AttrVec outer_attrs); std::unique_ptr @@ -209,7 +211,6 @@ private: // Top-level item-related std::unique_ptr parse_vis_item (AST::AttrVec outer_attrs); - std::unique_ptr parse_macro_item (AST::AttrVec outer_attrs); // VisItem subclass-related std::unique_ptr parse_module (AST::Visibility vis, diff --git a/gcc/testsuite/rust/compile/decl_macro1.rs b/gcc/testsuite/rust/compile/decl_macro1.rs new file mode 100644 index 00000000000..4a81a71e500 --- /dev/null +++ b/gcc/testsuite/rust/compile/decl_macro1.rs @@ -0,0 +1,2 @@ +#![feature(decl_macro)] +macro m() {} diff --git a/gcc/testsuite/rust/compile/decl_macro2.rs b/gcc/testsuite/rust/compile/decl_macro2.rs new file mode 100644 index 00000000000..cbe19b0c14b --- /dev/null +++ b/gcc/testsuite/rust/compile/decl_macro2.rs @@ -0,0 +1,2 @@ +#![feature(decl_macro)] +pub macro m($e: expr) { $e + $e } diff --git a/gcc/testsuite/rust/compile/decl_macro3.rs b/gcc/testsuite/rust/compile/decl_macro3.rs new file mode 100644 index 00000000000..d48da7835f9 --- /dev/null +++ b/gcc/testsuite/rust/compile/decl_macro3.rs @@ -0,0 +1,4 @@ +#![feature(decl_macro)] +macro foo { + () => {} +} diff --git a/gcc/testsuite/rust/compile/decl_macro4.rs b/gcc/testsuite/rust/compile/decl_macro4.rs new file mode 100644 index 00000000000..b8576cf0dd8 --- /dev/null +++ b/gcc/testsuite/rust/compile/decl_macro4.rs @@ -0,0 +1,5 @@ +#![feature(decl_macro)] +macro foo { + () => { 0 }, + ($n: expr) => { $n + 1 }, +} \ No newline at end of file diff --git a/gcc/testsuite/rust/compile/decl_macro5.rs b/gcc/testsuite/rust/compile/decl_macro5.rs new file mode 100644 index 00000000000..b4ea20ffa74 --- /dev/null +++ b/gcc/testsuite/rust/compile/decl_macro5.rs @@ -0,0 +1,5 @@ +#![feature(decl_macro)] +macro foo { + () => [], + ($h: expr, $(t: expr),*) => ($h), +} diff --git a/gcc/testsuite/rust/compile/decl_macro6.rs b/gcc/testsuite/rust/compile/decl_macro6.rs new file mode 100644 index 00000000000..5c5e7002a98 --- /dev/null +++ b/gcc/testsuite/rust/compile/decl_macro6.rs @@ -0,0 +1,5 @@ +#![feature(decl_macro)] +macro m {} +// { dg-error "unexpected token .\}. - expecting delimiters .for a macro matcher." "" { target *-*-* } .-1 } +// { dg-error "required first macro rule in declarative macro definition could not be parsed" "" { target *-*-* } .-2 } +// { dg-error "failed to parse item in crate" "" { target *-*-* } .-3 } diff --git a/gcc/testsuite/rust/compile/decl_macro7.rs b/gcc/testsuite/rust/compile/decl_macro7.rs new file mode 100644 index 00000000000..7327fb56782 --- /dev/null +++ b/gcc/testsuite/rust/compile/decl_macro7.rs @@ -0,0 +1,4 @@ +#![feature(decl_macro)] +pub macro hello() [ "Hello" ] +// { dg-error "only braces can be used for a macro transcriber in declarative macro definition" "" { target *-*-* } .-1 } +// { dg-error "failed to parse item in crate" } \ No newline at end of file diff --git a/gcc/testsuite/rust/execute/torture/decl_macro1.rs b/gcc/testsuite/rust/execute/torture/decl_macro1.rs new file mode 100644 index 00000000000..accc8b1db8e --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/decl_macro1.rs @@ -0,0 +1,8 @@ +#![feature(decl_macro)] +macro one() { + 1 +} + +fn main() -> i32 { + one!() - 1 +} diff --git a/gcc/testsuite/rust/execute/torture/decl_macro2.rs b/gcc/testsuite/rust/execute/torture/decl_macro2.rs new file mode 100644 index 00000000000..f42b96262fe --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/decl_macro2.rs @@ -0,0 +1,8 @@ +#![feature(decl_macro)] +macro one { + () => { 1 } +} + +fn main() -> i32 { + one!() - 1 +} diff --git a/gcc/testsuite/rust/execute/torture/decl_macro3.rs b/gcc/testsuite/rust/execute/torture/decl_macro3.rs new file mode 100644 index 00000000000..fa2cf793cf2 --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/decl_macro3.rs @@ -0,0 +1,15 @@ +#![feature(decl_macro)] +macro add { + ($e:expr) => { + $e + }, + ($h:expr, $($t:expr),*) => { + $h + add!($($t),*) + }, +} + +fn main() -> i32 { + let a = add!(1, 2, 3); + + a - 6 +} diff --git a/gcc/testsuite/rust/execute/torture/decl_macro4.rs b/gcc/testsuite/rust/execute/torture/decl_macro4.rs new file mode 100644 index 00000000000..e700e63161d --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/decl_macro4.rs @@ -0,0 +1,15 @@ +#![feature(decl_macro)] +pub macro add { + ($e:expr) => { + $e + }, + ($h:expr, $($t:expr),*) => { + $h + add!($($t),*) + }, +} + +fn main() -> i32 { + let a = add!(1, 2, 3); + + a - 6 +} From patchwork Wed Apr 5 14:02: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: 79622 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp335660vqo; Wed, 5 Apr 2023 07:09:25 -0700 (PDT) X-Google-Smtp-Source: AKy350Y9+MnFeRnZoykVs4bevtsU5flFN+GPGRuqrL2wNaTC5WTsad99jJaOt8ps7ujHqJK9V3nP X-Received: by 2002:a17:906:a04c:b0:931:75f5:36db with SMTP id bg12-20020a170906a04c00b0093175f536dbmr2846022ejb.11.1680703764962; Wed, 05 Apr 2023 07:09:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680703764; cv=none; d=google.com; s=arc-20160816; b=RT8aZflyluZNk9n6tSLu6yGJV58wq/1pwFTmg+R5cdNV1tui6tHLdTXJqBX9VcvCOz QXE8id+r967Ow1fm4Yt+Rw0j4Dry82MI3A7sgFPJEq6UxOr7/luatcrTOyAX30O2MIiB mI5wnsOSAsnt9Pj87TnpBE7RIFX3g126te1EosmHrdxXjBfXHJRb9xy9aPowT+aiMucN 0VZpWxzAdIQGqBrn0seIOBkfFnkSMu2O0DOTdeNVEfmG92K13DT5Z/3+BH4fMT5c+Ecq XnXbFVY7oQzDHManMUGN1tUN6svVLjxOZYdh+EiIg2EFGvB5zevWGvBC2+M0F/gLdpOV 58PQ== 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=7tTXTtx8/xnSVb54wRORL/77orvdZsHkhaZekhyjbrk=; b=zRYCoOgG16S8VR+W4B9UwAjsc9htrAdZE3nziHqmvb52xU41DhlJamw2jbky1JjHZB CtDvfBX5K87+YBzc4hPNLSxrItbulUcb5/JBeAYDZmd4X5ckCgmHkyTBEys33VoNK4NN ZIzEUTERx5SkHVJPMn8r85jAgs36gAac9nzWqUz9dkf8sfRemQ5asxG3jeDp2PzO1Syy AT2UKAc2hoimooseuWRvNUpbj+IfI9EJzRT8BL85MmGARADzc7SBCsV8NXxNaAnIezS6 MVZgT8nTSjoYKgvCFb6ydx2b/ciLBKdjorS0ZuB/UHAbON7YtkDxSQhUzgKXRDypBE8f QSrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=TmIxw8+O; 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 m21-20020a170906581500b00931d3414a47si4617485ejq.200.2023.04.05.07.09.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:09:24 -0700 (PDT) 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=TmIxw8+O; 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 211AB388C03D for ; Wed, 5 Apr 2023 14:06:47 +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 D0F123858C31 for ; Wed, 5 Apr 2023 14:05:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D0F123858C31 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 he13so1340028wmb.2 for ; Wed, 05 Apr 2023 07:05:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703532; 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=7tTXTtx8/xnSVb54wRORL/77orvdZsHkhaZekhyjbrk=; b=TmIxw8+O+RtpeeZYInuh2NmgtrhZ+FUEvtWjUoCeDdsF2ft+1H8K2g7MiX/H0cQV6u e4YIGwuZ3p+f6rW8VWuyY+UChFk1B2HJNRwOiticOW9FXSUvnqCMwmxD+ZS3jqWj/NGZ Ksd7KfQlz9LbUprXLFZyPlqVMKKZnbTplZ+/GAmOAwzSj7iGe18FSgfqEPiSz2PsGVkk CsjoJT4v4HFy7I3fJXezz4H4E1tFmdO0NOqwyT8cMV3T096xPUwtBx+G6t8DeAsP8rK9 RbkWOmRl6H+HHPQwtgPuqnYLQ26PkX0k+UgSWc3AUweWIhBJKNr7b7S+Sh0XJvvsx4CD k+Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703532; 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=7tTXTtx8/xnSVb54wRORL/77orvdZsHkhaZekhyjbrk=; b=LM6KnCReT3WueWFphcyKLEu1yL+0kyYbdvZLXYfVx7Ha43mqJEgOGj6BnhyQw/jM2r nmWZF/zr02TdfHjftBMugu0UipEf//be0rE8PMROXvk62QoxCeSnlWf2mhqDBpMpqIhV JqSDT3O0tjklVYhVs+8s1JtQ/9XgBqQcLnwe+YX0GOiRWmkQF5uJTAOw+ZrZgT6efx4Z VLVX4OvuxmbSFGLcBpsnAFYkO0kwuogfaqHAWfjNGb9pqrIEuhCHcwTuPNoWNp9nPORu 2DtJI2AmdE7hYBF682xouW+1lGSPcLSiI2sfbRQsjWmPm6EJKhS4uLj5bxfFVkJXWnsq 9wOQ== X-Gm-Message-State: AAQBX9fu0sgMDeZKY9IXCb2wYySY5BEyIKl74Tor4hOvkKoC+IciwTGo ngZL8clow4BLlwGJu8bejhEtzic5FnwVxV7Pdw== X-Received: by 2002:a05:600c:218d:b0:3ee:36f:3485 with SMTP id e13-20020a05600c218d00b003ee036f3485mr5109703wme.8.1680703532380; Wed, 05 Apr 2023 07:05:32 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:32 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 06/88] gccrs: Add name resolution to generic argument associated item bindings Date: Wed, 5 Apr 2023 16:02:50 +0200 Message-Id: <20230405140411.3016563-7-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?1762345630920570134?= X-GMAIL-MSGID: =?utf-8?q?1762345630920570134?= From: Philip Herron When specifying generic arguments to Traits we can also specify the associated types using `` syntax we need to add name resolution to the type argument here and rely on the type resolution pass to ensure the associated type exists and to setup the associated types accordingly. Addresses #1720 gcc/rust/ChangeLog: * resolve/rust-ast-resolve-type.cc (ResolveGenericArgs::go): Add name resolution to Trait items. Signed-off-by: Philip Herron --- gcc/rust/resolve/rust-ast-resolve-type.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc b/gcc/rust/resolve/rust-ast-resolve-type.cc index 16d05f3792b..28ab0697431 100644 --- a/gcc/rust/resolve/rust-ast-resolve-type.cc +++ b/gcc/rust/resolve/rust-ast-resolve-type.cc @@ -589,6 +589,11 @@ ResolveGenericArgs::go (AST::GenericArgs &generic_args, resolver.resolve_disambiguated_generic (arg); } + + for (auto &binding : generic_args.get_binding_args ()) + { + ResolveType::go (binding.get_type ().get ()); + } } } // namespace Resolver From patchwork Wed Apr 5 14:02: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: 79630 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp340179vqo; Wed, 5 Apr 2023 07:15:04 -0700 (PDT) X-Google-Smtp-Source: AKy350aRC+9FkOCSEfXFdeCupJWBm/tcT56OjkjsPfJs2qlCuON3TvYD1obavSwwtEXU4IPH1ck6 X-Received: by 2002:a05:6402:40c8:b0:502:508c:e546 with SMTP id z8-20020a05640240c800b00502508ce546mr1710932edb.6.1680704104268; Wed, 05 Apr 2023 07:15:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704104; cv=none; d=google.com; s=arc-20160816; b=hlJs67UmdmBUDYQagjUwbr89GEFtQkF7hwbFyRLhrqMaFs+IN92yMDsbV8hMLQlWVt TU8bHaj13rkfvd/CEFcyuEpm/O/yCKVISkOK4dcabveUw5ssR9FtkBhbVWkmDY4tXqI4 FsfkjXfoOyQ/0EDzpZofefIEBXpOqnCpUZHd6eDV13w4x+AmBdfedO59ci7MpoMfqLDh 2Wi2OYS1jIAYZG5WWvz1R5f9jK5BdkINOx+aqABMyhqOXm19yvhB7ri1kxq0p11D9M5Q XpHHIcfkofjTnKLvNqTp/Rbxzz5ws+2EFrPvJsPg9uE3SJ8AeoEWXCf8Z0vcJ+G08Lqc 8s2A== 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=Tp6SnEuHWm8vBC5WmWyH9Q6wIVWfD7BEbVqFTHjuXu8=; b=wLzrJvfRv6oEKoWWTeLgNYlhfqlAH73KQ86noen5yxPtJtmwV1e6IELM8MV1furzs1 gRErOJ/bdbofP7ceS7rcOSEYhQrwJLE7PLeDr9oPI2ws9ES7a9jrnZICYViUBB4NRiFr j3NrbBRS2/c02jy7qQZrsgVDDotyIlNUYadeqvg6m7PM7j0YiLQMiqdpD67tQzosbh7y eBTHWqynWJ+Ko//K0TrlvOX5x76KXewfEdnmWJiyrK80Kb7uuJCCFKhYJ14E+YimVovZ uEDrl/cqDBAz2hCHpjAEWzXwQxmDj3n3EEfDmuBk1flexQbmLTNArEUWqnVKg3jBvNRJ +lMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=TmzmDLm6; 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 a13-20020aa7d74d000000b004fbc39bd3a9si13942256eds.318.2023.04.05.07.15.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:15:04 -0700 (PDT) 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=TmzmDLm6; 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 8188C388202B for ; Wed, 5 Apr 2023 14:08:32 +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 1428C385B508 for ; Wed, 5 Apr 2023 14:05:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1428C385B508 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 d11-20020a05600c3acb00b003ef6e6754c5so18371020wms.5 for ; Wed, 05 Apr 2023 07:05:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703533; 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=Tp6SnEuHWm8vBC5WmWyH9Q6wIVWfD7BEbVqFTHjuXu8=; b=TmzmDLm6ldVoO3KNG/59/iOmAKB2RrNYOYXNGKcoQHV/TjWHKYLmO8eBUyASQ7U4v3 ZsEJ89sE/9UK+gHGrc3h8GlzPfsSjhxc9ifXJDRVjLaPmwGJP7PA7Vr5Bw63rVjrCpku ELD5nV/VkLCKGycjvoqEpsqZZlMu1FRs7hKGEqM2uBxLz1W1wDKbmAiwEVhgzViPjTFp aLlNXV9E6QTG5sv3Jm4A0q+LRcyyGbwvsPF5V/NBZWYBXH7jwELCoC7vpPQB3sTzIzwi Bxf2o7sFcCqRjRQJ0Hs/EwpGcT1wCsv+3iU9rl7EGU6RCCAnDLSD3h/6nFpBydLiGwAQ aXwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703533; 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=Tp6SnEuHWm8vBC5WmWyH9Q6wIVWfD7BEbVqFTHjuXu8=; b=BD2ElAP7g0MyGVv3jBVeBvDrt4RkoglkYeQkLxj29jRHD14zckEiP4yBMgkwltzpHL KTf2QZ+k6xqa+hWPUG3hgzI/Bx1Hg1CQfx57aa/knKHZE3WT5Yfk55RAl1XO9/s+vVBY WzeNaJV1wZsOn6HlVUV/VBf+vjqGPoqwSdTqRG6Uh5Hb5IRA6yYe/cp1Jq3IFNfYzM60 9W1THdDGCkjcgHB+YzCNJLJJycnmkgLPC1NfaEIhyec3NzU5Q2dx/P9M91SfkbG/ezPI Cxt9nqekUP95bGPoZ/WAWEyQgAWnYmN8wbNEGZOdayMR341sYyMmyJCOWTGIqUF5Usu1 w5rQ== X-Gm-Message-State: AAQBX9fTolizvDitcvvv9oPLJUluPB5QqwYRLsudzqzqB2Rk65mcwA8T FTyWY8gkeQyUmD0ztwb9V7lQ4W6sK6kEpja4+g== X-Received: by 2002:a05:600c:1f06:b0:3f0:5ed7:f859 with SMTP id bd6-20020a05600c1f0600b003f05ed7f859mr2005497wmb.7.1680703533099; Wed, 05 Apr 2023 07:05:33 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:32 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 07/88] gccrs: Support associated type bound arguments Date: Wed, 5 Apr 2023 16:02:51 +0200 Message-Id: <20230405140411.3016563-8-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.6 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?1762345986528193995?= X-GMAIL-MSGID: =?utf-8?q?1762345986528193995?= From: Philip Herron This patch adds support for the GenercArgsBinding type, where you can specify the associated types of a trait bound using `` style syntax. Note that the type-resolution relys on the i32 impl for Add as type resolution will resolve the `a+a` to the core::ops::Add method so code generation will require this to exist. I have ameded testsuite/rust/compile/bounds.rs as this code is wrongly creating an HIR::GenericArgs with a trait-object type and causing issues. the parsing is still correct but we dont have the mechanism to represent this in AST and HIR properly. I think we will need a new HIR::GenericArgs AssociatedTypeBindingBound or something similar. We are still lacking bounds checking during are type coercions and unifications so running this example using an f32 will wrongly pass type checking, this will need addressed next. Fixes #1720 gcc/rust/ChangeLog: * hir/tree/rust-hir-path.h: Add const get_identifier and get_type method. * typecheck/rust-hir-path-probe.h: Use new SubstitutionArgumentMappings constructor. * typecheck/rust-hir-trait-resolve.cc: Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. * typecheck/rust-tyty-bounds.cc (TypeCheckBase::get_predicate_from_bound): Do not assert failure on size mismatch anymore. (TypeBoundPredicate::TypeBoundPredicate): Use new SubstitutionArgumentMappings constructor. (TypeBoundPredicate::operator=): Likewise. (TypeBoundPredicate::apply_generic_arguments): Likewise. (TypeBoundPredicateItem::get_tyty_for_receiver): Likewise. (TypeBoundPredicate::get_num_associated_bindings): Likewise. (TypeBoundPredicate::lookup_associated_type): Fix implementation for new system. (TypeBoundPredicate::get_associated_type_items): Likewise. * typecheck/rust-tyty.cc (SubstitutionRef::get_mappings_from_generic_args): Add new behavior. (SubstitutionRef::infer_substitions): Use new constructor and add comment. (SubstitutionRef::solve_missing_mappings_from_this): Use new constructor. * typecheck/rust-tyty.h: Define new constructors. gcc/testsuite/ChangeLog: * rust/compile/bounds.rs: change to use -fsyntax-only * rust/execute/torture/issue-1720.rs: New test. Signed-off-by: Philip Herron --- gcc/rust/hir/tree/rust-hir-path.h | 4 +- gcc/rust/typecheck/rust-hir-path-probe.h | 3 +- gcc/rust/typecheck/rust-hir-trait-resolve.cc | 11 +-- .../typecheck/rust-hir-type-check-expr.cc | 12 ++- gcc/rust/typecheck/rust-tyty-bounds.cc | 89 ++++++++++++++++--- gcc/rust/typecheck/rust-tyty.cc | 73 +++++++++++++-- gcc/rust/typecheck/rust-tyty.h | 48 ++++++++-- gcc/testsuite/rust/compile/bounds.rs | 8 +- .../rust/execute/torture/issue-1720.rs | 26 ++++++ 9 files changed, 236 insertions(+), 38 deletions(-) create mode 100644 gcc/testsuite/rust/execute/torture/issue-1720.rs diff --git a/gcc/rust/hir/tree/rust-hir-path.h b/gcc/rust/hir/tree/rust-hir-path.h index 17eedb8d741..740de9391a0 100644 --- a/gcc/rust/hir/tree/rust-hir-path.h +++ b/gcc/rust/hir/tree/rust-hir-path.h @@ -105,9 +105,11 @@ public: std::string as_string () const; - Identifier get_identifier () const { return identifier; } + Identifier &get_identifier () { return identifier; } + const Identifier &get_identifier () const { return identifier; } std::unique_ptr &get_type () { return type; } + const std::unique_ptr &get_type () const { return type; } Location get_locus () const { return locus; } }; diff --git a/gcc/rust/typecheck/rust-hir-path-probe.h b/gcc/rust/typecheck/rust-hir-path-probe.h index 6d6bcf8e7cd..bb8698ce0e1 100644 --- a/gcc/rust/typecheck/rust-hir-path-probe.h +++ b/gcc/rust/typecheck/rust-hir-path-probe.h @@ -362,7 +362,8 @@ protected: mappings.push_back (TyTy::SubstitutionArg (param, receiver->clone ())); Location locus; // FIXME - TyTy::SubstitutionArgumentMappings args (std::move (mappings), locus); + TyTy::SubstitutionArgumentMappings args (std::move (mappings), {}, + locus); trait_item_tyty = SubstMapperInternal::Resolve (trait_item_tyty, args); } diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc index 2ec9b2ef83e..85cad8e9c21 100644 --- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc +++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc @@ -441,8 +441,8 @@ AssociatedImplTrait::setup_associated_types ( param_mappings[p.get_symbol ()] = a.get_tyty ()->get_ref (); }; - TyTy::SubstitutionArgumentMappings infer_arguments (std::move (args), locus, - param_subst_cb); + TyTy::SubstitutionArgumentMappings infer_arguments (std::move (args), {}, + locus, param_subst_cb); TyTy::BaseType *impl_self_infer = (associated_self->needs_generic_substitutions ()) ? SubstMapperInternal::Resolve (associated_self, infer_arguments) @@ -489,8 +489,9 @@ AssociatedImplTrait::setup_associated_types ( hrtb_bound_arguments.push_back (r); } - rust_assert (impl_trait_predicate_args.size () - == hrtb_bound_arguments.size ()); + if (impl_trait_predicate_args.size () != hrtb_bound_arguments.size ()) + return; + for (size_t i = 0; i < impl_trait_predicate_args.size (); i++) { TyTy::BaseType *a = impl_trait_predicate_args.at (i); @@ -521,7 +522,7 @@ AssociatedImplTrait::setup_associated_types ( } TyTy::SubstitutionArgumentMappings associated_type_args ( - std::move (associated_arguments), locus); + std::move (associated_arguments), {}, locus); ImplTypeIterator iter (*impl, [&] (HIR::TypeAlias &type) { TraitItemReference *resolved_trait_item = nullptr; diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc index 5c43cc8c7b4..46a14eb6e92 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc @@ -618,7 +618,8 @@ TypeCheckExpr::visit (HIR::RangeFromToExpr &expr) const TyTy::SubstitutionParamMapping *param_ref = &adt->get_substs ().at (0); subst_mappings.push_back (TyTy::SubstitutionArg (param_ref, unified)); - TyTy::SubstitutionArgumentMappings subst (subst_mappings, expr.get_locus ()); + TyTy::SubstitutionArgumentMappings subst (subst_mappings, {}, + expr.get_locus ()); infered = SubstMapperInternal::Resolve (adt, subst); } @@ -664,7 +665,8 @@ TypeCheckExpr::visit (HIR::RangeFromExpr &expr) const TyTy::SubstitutionParamMapping *param_ref = &adt->get_substs ().at (0); subst_mappings.push_back (TyTy::SubstitutionArg (param_ref, from_ty)); - TyTy::SubstitutionArgumentMappings subst (subst_mappings, expr.get_locus ()); + TyTy::SubstitutionArgumentMappings subst (subst_mappings, {}, + expr.get_locus ()); infered = SubstMapperInternal::Resolve (adt, subst); } @@ -709,7 +711,8 @@ TypeCheckExpr::visit (HIR::RangeToExpr &expr) const TyTy::SubstitutionParamMapping *param_ref = &adt->get_substs ().at (0); subst_mappings.push_back (TyTy::SubstitutionArg (param_ref, from_ty)); - TyTy::SubstitutionArgumentMappings subst (subst_mappings, expr.get_locus ()); + TyTy::SubstitutionArgumentMappings subst (subst_mappings, {}, + expr.get_locus ()); infered = SubstMapperInternal::Resolve (adt, subst); } @@ -792,7 +795,8 @@ TypeCheckExpr::visit (HIR::RangeFromToInclExpr &expr) const TyTy::SubstitutionParamMapping *param_ref = &adt->get_substs ().at (0); subst_mappings.push_back (TyTy::SubstitutionArg (param_ref, unified)); - TyTy::SubstitutionArgumentMappings subst (subst_mappings, expr.get_locus ()); + TyTy::SubstitutionArgumentMappings subst (subst_mappings, {}, + expr.get_locus ()); infered = SubstMapperInternal::Resolve (adt, subst); } diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc b/gcc/rust/typecheck/rust-tyty-bounds.cc index 20a81ada6c4..30f7b0d02e3 100644 --- a/gcc/rust/typecheck/rust-tyty-bounds.cc +++ b/gcc/rust/typecheck/rust-tyty-bounds.cc @@ -145,11 +145,10 @@ TypeCheckBase::get_predicate_from_bound (HIR::TypePath &type_path) 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 ()) + // we try to apply generic arguments when they are non empty and or when the + // predicate requires them so that we get the relevant Foo expects x number + // arguments but got zero see test case rust/compile/traits12.rs + if (!args.is_empty () || predicate.requires_generic_args ()) { // this is applying generic arguments to a trait reference predicate.apply_generic_arguments (&args); @@ -222,7 +221,7 @@ TypeBoundPredicate::TypeBoundPredicate (const TypeBoundPredicate &other) } used_arguments - = SubstitutionArgumentMappings (copied_arg_mappings, + = SubstitutionArgumentMappings (copied_arg_mappings, {}, other.used_arguments.get_locus ()); } @@ -258,7 +257,7 @@ TypeBoundPredicate::operator= (const TypeBoundPredicate &other) } used_arguments - = SubstitutionArgumentMappings (copied_arg_mappings, + = SubstitutionArgumentMappings (copied_arg_mappings, {}, other.used_arguments.get_locus ()); return *this; @@ -331,6 +330,19 @@ TypeBoundPredicate::apply_generic_arguments (HIR::GenericArgs *generic_args) if (ok && arg.get_tyty () != nullptr) sub.fill_param_ty (subst_mappings, subst_mappings.get_locus ()); } + + // associated argument mappings + for (auto &it : subst_mappings.get_binding_args ()) + { + std::string identifier = it.first; + TyTy::BaseType *type = it.second; + + TypeBoundPredicateItem item = lookup_associated_item (identifier); + rust_assert (!item.is_error ()); + + const auto item_ref = item.get_raw_item (); + item_ref->associated_type_set (type); + } } bool @@ -389,7 +401,8 @@ TypeBoundPredicateItem::get_tyty_for_receiver (const TyTy::BaseType *receiver) adjusted_mappings.push_back (std::move (arg)); } - SubstitutionArgumentMappings adjusted (adjusted_mappings, gargs.get_locus (), + SubstitutionArgumentMappings adjusted (adjusted_mappings, {}, + gargs.get_locus (), gargs.get_subst_cb (), true /* trait-mode-flag */); return Resolver::SubstMapperInternal::Resolve (trait_item_tyty, adjusted); @@ -421,6 +434,19 @@ TypeBoundPredicate::handle_substitions ( p->set_ty_ref (s->get_ty_ref ()); } + // associated argument mappings + for (auto &it : subst_mappings.get_binding_args ()) + { + std::string identifier = it.first; + TyTy::BaseType *type = it.second; + + TypeBoundPredicateItem item = lookup_associated_item (identifier); + rust_assert (!item.is_error ()); + + const auto item_ref = item.get_raw_item (); + item_ref->associated_type_set (type); + } + // FIXME more error handling at some point // used_arguments = subst_mappings; // error_flag |= used_arguments.is_error (); @@ -440,6 +466,13 @@ TypeBoundPredicate::requires_generic_args () const bool TypeBoundPredicate::contains_associated_types () const { + return get_num_associated_bindings () > 0; +} + +size_t +TypeBoundPredicate::get_num_associated_bindings () const +{ + size_t count = 0; auto trait_ref = get (); for (const auto &trait_item : trait_ref->get_trait_items ()) { @@ -447,9 +480,45 @@ TypeBoundPredicate::contains_associated_types () const = trait_item.get_trait_item_type () == Resolver::TraitItemReference::TraitItemType::TYPE; if (is_associated_type) - return true; + count++; + } + return count; +} + +TypeBoundPredicateItem +TypeBoundPredicate::lookup_associated_type (const std::string &search) +{ + TypeBoundPredicateItem item = lookup_associated_item (search); + + // only need to check that it is infact an associated type because other wise + // if it was not found it will just be an error node anyway + if (!item.is_error ()) + { + const auto raw = item.get_raw_item (); + if (raw->get_trait_item_type () + != Resolver::TraitItemReference::TraitItemType::TYPE) + return TypeBoundPredicateItem::error (); + } + return item; +} + +std::vector +TypeBoundPredicate::get_associated_type_items () +{ + std::vector items; + auto trait_ref = get (); + for (const auto &trait_item : trait_ref->get_trait_items ()) + { + bool is_associated_type + = trait_item.get_trait_item_type () + == Resolver::TraitItemReference::TraitItemType::TYPE; + if (is_associated_type) + { + TypeBoundPredicateItem item (this, &trait_item); + items.push_back (std::move (item)); + } } - return false; + return items; } // trait item reference diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index 71f0de1bbab..fd57a534562 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -674,14 +674,58 @@ SubstitutionParamMapping::override_context () SubstitutionArgumentMappings SubstitutionRef::get_mappings_from_generic_args (HIR::GenericArgs &args) { + std::map binding_arguments; if (args.get_binding_args ().size () > 0) { - RichLocation r (args.get_locus ()); - for (auto &binding : args.get_binding_args ()) - r.add_range (binding.get_locus ()); + if (supports_associated_bindings ()) + { + if (args.get_binding_args ().size () > get_num_associated_bindings ()) + { + RichLocation r (args.get_locus ()); + + rust_error_at (r, + "generic item takes at most %lu type binding " + "arguments but %lu were supplied", + (unsigned long) get_num_associated_bindings (), + (unsigned long) args.get_binding_args ().size ()); + return SubstitutionArgumentMappings::error (); + } - rust_error_at (r, "associated type bindings are not allowed here"); - return SubstitutionArgumentMappings::error (); + for (auto &binding : args.get_binding_args ()) + { + BaseType *resolved + = Resolver::TypeCheckType::Resolve (binding.get_type ().get ()); + if (resolved == nullptr + || resolved->get_kind () == TyTy::TypeKind::ERROR) + { + rust_error_at (binding.get_locus (), + "failed to resolve type arguments"); + return SubstitutionArgumentMappings::error (); + } + + // resolve to relevant binding + auto binding_item + = lookup_associated_type (binding.get_identifier ()); + if (binding_item.is_error ()) + { + rust_error_at (binding.get_locus (), + "unknown associated type binding: %s", + binding.get_identifier ().c_str ()); + return SubstitutionArgumentMappings::error (); + } + + binding_arguments[binding.get_identifier ()] = resolved; + } + } + else + { + RichLocation r (args.get_locus ()); + for (auto &binding : args.get_binding_args ()) + r.add_range (binding.get_locus ()); + + rust_error_at (r, "associated type bindings are not allowed here"); + return SubstitutionArgumentMappings::error (); + } } // for inherited arguments @@ -745,6 +789,7 @@ SubstitutionRef::get_mappings_from_generic_args (HIR::GenericArgs &args) if (resolved->contains_type_parameters ()) { SubstitutionArgumentMappings intermediate (mappings, + binding_arguments, args.get_locus ()); resolved = Resolver::SubstMapperInternal::Resolve (resolved, intermediate); @@ -758,7 +803,8 @@ SubstitutionRef::get_mappings_from_generic_args (HIR::GenericArgs &args) } } - return SubstitutionArgumentMappings (mappings, args.get_locus ()); + return SubstitutionArgumentMappings (mappings, binding_arguments, + args.get_locus ()); } BaseType * @@ -791,7 +837,13 @@ SubstitutionRef::infer_substitions (Location locus) } } - SubstitutionArgumentMappings infer_arguments (std::move (args), locus); + // FIXME do we need to add inference variables to all the possible bindings? + // it might just lead to inference variable hell not 100% sure if rustc does + // this i think the language might needs this to be explicitly set + + SubstitutionArgumentMappings infer_arguments (std::move (args), + {} /* binding_arguments */, + locus); return handle_substitions (std::move (infer_arguments)); } @@ -835,7 +887,9 @@ SubstitutionRef::adjust_mappings_for_this ( if (resolved_mappings.empty ()) return SubstitutionArgumentMappings::error (); - return SubstitutionArgumentMappings (resolved_mappings, mappings.get_locus (), + return SubstitutionArgumentMappings (resolved_mappings, + mappings.get_binding_args (), + mappings.get_locus (), mappings.get_subst_cb (), mappings.trait_item_mode ()); } @@ -901,6 +955,7 @@ SubstitutionRef::solve_mappings_from_receiver_for_self ( } return SubstitutionArgumentMappings (resolved_mappings, + mappings.get_binding_args (), mappings.get_locus ()); } @@ -952,7 +1007,7 @@ SubstitutionRef::solve_missing_mappings_from_this (SubstitutionRef &ref, resolved_mappings.push_back (std::move (argument)); } - return SubstitutionArgumentMappings (resolved_mappings, locus); + return SubstitutionArgumentMappings (resolved_mappings, {}, locus); } bool diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index 0fd664c8d46..20a243fe980 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -675,16 +675,17 @@ class SubstitutionArgumentMappings { public: SubstitutionArgumentMappings (std::vector mappings, + std::map binding_args, Location locus, ParamSubstCb param_subst_cb = nullptr, bool trait_item_flag = false) - : mappings (mappings), locus (locus), param_subst_cb (param_subst_cb), - trait_item_flag (trait_item_flag) + : mappings (mappings), binding_args (binding_args), locus (locus), + param_subst_cb (param_subst_cb), trait_item_flag (trait_item_flag) {} SubstitutionArgumentMappings (const SubstitutionArgumentMappings &other) - : mappings (other.mappings), locus (other.locus), - param_subst_cb (other.param_subst_cb), + : mappings (other.mappings), binding_args (other.binding_args), + locus (other.locus), param_subst_cb (other.param_subst_cb), trait_item_flag (other.trait_item_flag) {} @@ -692,6 +693,7 @@ public: operator= (const SubstitutionArgumentMappings &other) { mappings = other.mappings; + binding_args = other.binding_args; locus = other.locus; param_subst_cb = other.param_subst_cb; trait_item_flag = other.trait_item_flag; @@ -705,7 +707,7 @@ public: static SubstitutionArgumentMappings error () { - return SubstitutionArgumentMappings ({}, Location (), nullptr, false); + return SubstitutionArgumentMappings ({}, {}, Location (), nullptr, false); } bool is_error () const { return mappings.size () == 0; } @@ -759,6 +761,16 @@ public: const std::vector &get_mappings () const { return mappings; } + std::map &get_binding_args () + { + return binding_args; + } + + const std::map &get_binding_args () const + { + return binding_args; + } + std::string as_string () const { std::string buffer; @@ -783,6 +795,7 @@ public: private: std::vector mappings; + std::map binding_args; Location locus; ParamSubstCb param_subst_cb; bool trait_item_flag; @@ -813,6 +826,24 @@ public: return buffer.empty () ? "" : "<" + buffer + ">"; } + bool supports_associated_bindings () const + { + return get_num_associated_bindings () > 0; + } + + // this is overridden in TypeBoundPredicate + // which support bindings we don't add them directly to the SubstitutionRef + // base class because this class represents the fn. The only + // construct which supports associated types + virtual size_t get_num_associated_bindings () const { return 0; } + + // this is overridden in TypeBoundPredicate + virtual TypeBoundPredicateItem + lookup_associated_type (const std::string &search) + { + return TypeBoundPredicateItem::error (); + } + size_t get_num_substitutions () const { return substitutions.size (); } std::vector &get_substs () { return substitutions; } @@ -1040,6 +1071,13 @@ public: DefId get_id () const { return reference; } + std::vector get_associated_type_items (); + + size_t get_num_associated_bindings () const override final; + + TypeBoundPredicateItem + lookup_associated_type (const std::string &search) override final; + private: DefId reference; Location locus; diff --git a/gcc/testsuite/rust/compile/bounds.rs b/gcc/testsuite/rust/compile/bounds.rs index ecb10d81f65..57ff17ffcdc 100644 --- a/gcc/testsuite/rust/compile/bounds.rs +++ b/gcc/testsuite/rust/compile/bounds.rs @@ -1,10 +1,12 @@ +// { dg-options "-fsyntax-only" } trait Foo { type Bar; } trait Copy {} - -fn c>() where F::Bar: Copy { // { dg-warning "function is never used: 'c'" } +fn c>() +where + F::Bar: Copy, +{ } - diff --git a/gcc/testsuite/rust/execute/torture/issue-1720.rs b/gcc/testsuite/rust/execute/torture/issue-1720.rs new file mode 100644 index 00000000000..771d7eec537 --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/issue-1720.rs @@ -0,0 +1,26 @@ +mod core { + mod ops { + #[lang = "add"] + pub trait Add { + type Output; + + fn add(self, rhs: Rhs) -> Self::Output; + } + } +} + +impl core::ops::Add for i32 { + type Output = i32; + + fn add(self, rhs: i32) -> Self::Output { + self + rhs + } +} + +pub fn foo>(a: T) -> i32 { + a + a +} + +pub fn main() -> i32 { + foo(1) - 2 +} From patchwork Wed Apr 5 14:02: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: 79626 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp337940vqo; Wed, 5 Apr 2023 07:12:25 -0700 (PDT) X-Google-Smtp-Source: AKy350ZWe0gMP2sT9JFxnArCxngLgnOFFEwIfd9tXBMKiQAbeFROx1lizt7+B1KgbVE8+AaQv7xB X-Received: by 2002:a17:906:53c3:b0:947:791b:fdcb with SMTP id p3-20020a17090653c300b00947791bfdcbmr2755825ejo.21.1680703945767; Wed, 05 Apr 2023 07:12:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680703945; cv=none; d=google.com; s=arc-20160816; b=TuISCAbo5pW3YYcVBnChiwBhxLOepxveGiWIkoEKm1AksYVu3sR7jbS9SX/xjiqHr6 rvQ7XHgWwvnh48t/hjXrUmMr1zDVbgvge7HxHiQKwKMxpdZsJIOtZFmy07NyAABAVBiO Du0FLRdLz+DsQIRA0feYWJl2WFMSIkwiErwlVR/1vsj7lp5cJpug828b3IfGQbOcCtMe AH+RfwxRcA5baWexvKDF9nt/PjMwJJEFWWJGyjjWZNhJ2zYggMQiNbclV6T8Aw5WpuW6 cy9vjPzYsbWqY670PGTZqZnTAMTLUPlhYsWfc1ZLkiZMBh8DY7ZZ6sj8wQB438XId7Nj GJAw== 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=td7w8xMvXd+idHBKS25RwiAfSfo1HS4YakefQENQu4A=; b=W3ILb0I/zEJFwWHjmqokZ62LQ2YIRQpWXzWNcWvYqSse90zJiE7A7uzlm+8bsg7bCj hcURyFDc+aSIZybwjCWeFDE0IZ1SrUlb4SqbFIrS8sIFKgM8xwRUr5/LMuC0BJlWZmY5 9xp6BVGo8oTSxXz7JGLPfd9vW0HVF/qbDwJi+VLZ8dTwr/Jc2q3erb70bS4pF13XiOEq EPZmEDPSHMQfWiPQP9u3YFuqD2gPRabHStUU7Uki9aIf0w1ZOCPxJgYqViGmFwy1r7qt bB7QS9nj1yHySsR4a5lFx79Yvn06ZebYvE2ZoQG22CKwqW6+Mjq7QZtgrE6A6uxXK1Hw ACQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b="UolBPd/H"; 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 c9-20020aa7df09000000b005027736d73csi2864668edy.209.2023.04.05.07.12.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:12:25 -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="UolBPd/H"; 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 221263952519 for ; Wed, 5 Apr 2023 14:07:46 +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 30AC63858433 for ; Wed, 5 Apr 2023 14:05:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 30AC63858433 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 d17so36311794wrb.11 for ; Wed, 05 Apr 2023 07:05:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703533; 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=td7w8xMvXd+idHBKS25RwiAfSfo1HS4YakefQENQu4A=; b=UolBPd/HBlKCtrivfwDKuvNuHPukmSVzgzZ+8VZIB+snlJCtyp78cuh5HQg2xeBTZc MpqKbSZFqrRq3Rymi/0rdv8defDur2puZQnaNYY+V0TGo3t8uE18mcWGksIPhyLxzyXr r1c2hRpAebCQMD79orMh5GeQeOYtpmuQPpgLExqq6mXWlM0muyO3ggxuLMlpuuBGu9bC B0Za1VutvOcIOM8sYzSsjYrw28me356ZeN87fNS8jfnSrToCu/iUGPT9L1xQNGxdwl/Y Z1LXbDuxOj3UwMK2YXtBeQkSDpUaZaI+j6/7Q9W3IbCY69WkDeSJlqJCw+7jTqcAK3/F O73A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703533; 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=td7w8xMvXd+idHBKS25RwiAfSfo1HS4YakefQENQu4A=; b=vFuJh1cl/sDa3WGjGx4f8yT0jSIok9r49wC2/nufDlXMwq+HuvycT5/MhAxebutRvt tnxrmwLl9VUlsOuoj1520gTW/2B4hZOYzeQ2X4Xp1eN/rlWjXFwe1i/smkD9ibbiAYIZ SvmYORUIZGF5Yln3ScrIdRIaSdX7Wq6a0lbVDFeppbGVI9N3N15GRSHtBiAz+D/z1e9m mGNH8pHedWJGc82e2RTumEaAJUFQ5QEZAiM3uTuOCcQKIoO9gGOBXJsa5Hh3Tt7clKWJ gqwAAGA14l0FupCI1khCyhA5nWQcY6470sU37XSpGBrgVxJ72vFWpeW50F4NnmdJ31NO ge6Q== X-Gm-Message-State: AAQBX9erNiVmAX6Kvddh5Co0eY15wlQi6OxOUsOW3t7TAjNTOi4Q/teU xfkfHFZQC0iUKrSigFaaB9T76371cuYKg55gQA== X-Received: by 2002:adf:eb4b:0:b0:2d8:82f9:9dbd with SMTP id u11-20020adfeb4b000000b002d882f99dbdmr3507254wrn.11.1680703533650; Wed, 05 Apr 2023 07:05:33 -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.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:33 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [committed 08/88] gccrs: Reuse TypeCheckPattern on LetStmt's Date: Wed, 5 Apr 2023 16:02:52 +0200 Message-Id: <20230405140411.3016563-9-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.6 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?1762345820756173052?= X-GMAIL-MSGID: =?utf-8?q?1762345820756173052?= From: Owen Avery Update Rust type-checking to reuse TypeCheckPattern on HIR::LetStmt's. This will unify the paths and improve error handling. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): Cleanup LetStmt type checking. Signed-off-by: Owen Avery --- gcc/rust/typecheck/rust-hir-type-check-stmt.cc | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-type-check-stmt.cc b/gcc/rust/typecheck/rust-hir-type-check-stmt.cc index 437782e8102..956249a7607 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-stmt.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-stmt.cc @@ -82,7 +82,7 @@ TypeCheckStmt::visit (HIR::LetStmt &stmt) { infered = TyTy::TupleType::get_unit_type (stmt.get_mappings ().get_hirid ()); - const HIR::Pattern &stmt_pattern = *stmt.get_pattern (); + HIR::Pattern &stmt_pattern = *stmt.get_pattern (); TyTy::BaseType *init_expr_ty = nullptr; Location init_expr_locus; if (stmt.has_init_expr ()) @@ -111,27 +111,25 @@ TypeCheckStmt::visit (HIR::LetStmt &stmt) TyTy::TyWithLocation (specified_ty, specified_ty_locus), TyTy::TyWithLocation (init_expr_ty, init_expr_locus), stmt.get_locus ()); - context->insert_type (stmt_pattern.get_pattern_mappings (), specified_ty); + TypeCheckPattern::Resolve (&stmt_pattern, specified_ty); } else { // let x:i32; if (specified_ty != nullptr) { - context->insert_type (stmt_pattern.get_pattern_mappings (), - specified_ty); + TypeCheckPattern::Resolve (&stmt_pattern, specified_ty); } // let x = 123; else if (init_expr_ty != nullptr) { - context->insert_type (stmt_pattern.get_pattern_mappings (), - init_expr_ty); + TypeCheckPattern::Resolve (&stmt_pattern, init_expr_ty); } // let x; else { - context->insert_type ( - stmt_pattern.get_pattern_mappings (), + TypeCheckPattern::Resolve ( + &stmt_pattern, new TyTy::InferType ( stmt_pattern.get_pattern_mappings ().get_hirid (), TyTy::InferType::InferTypeKind::GENERAL, stmt.get_locus ())); From patchwork Wed Apr 5 14:02: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: 79625 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp337465vqo; Wed, 5 Apr 2023 07:11:51 -0700 (PDT) X-Google-Smtp-Source: AKy350aXWFpqPeFbTn0g8Ww7pMKdNBnSRhkOP3SqlNp/tiZ+ZSfAx5RCOFaYiEwO1QclmKG3FLxf X-Received: by 2002:a17:906:368d:b0:931:636e:de5a with SMTP id a13-20020a170906368d00b00931636ede5amr2926688ejc.31.1680703911248; 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=0CVN/Mp5EP1QZjvCcI56VkMVae9qYiowtBhv/jhrHgHmqAO94Gto2s5fqPDsURHUI1 zFDTtXp3bHHGiEY7y9Ns6ohH2myop5b0WtaSYyqN8UoXHOvXwxzu7OUDDAj1Z1XSYX9W 9GuUVICq8yfCn1UQOcqLOrBaQUrNoqcCW5m3jGQ1Aa5BkrqDlmz8LmQTWNOW+jZzgSbj o9Tp1gHqUtqBRqwLzTxTiR3pajLP/VS4RwJCtL511PvFeG+r9bUVYYKDI6L/QYTWv8os yYvFD2RJ/c3jjhOkjogsb+oqG/FP4DSNWLQ9xYjNWJZpdhVvavHRxUBcJR/KYHKSk+Xa FiCQ== 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=51PEspkDcmiXoo4pzo1UuUsXRaxb+ly/OpVFXeCOfn8=; b=HjIHdvjKlFe9EGdTs9cxvElAE0nqCypbL5HSYUyqindbjOF4AiBMMCY8D0XpH9GWO1 iSvvz1GoSwaaUjUQ5SSYQR/GHB99mu7KB5WceFaCSmHLmJUOg8k1+DomlpS5EzRXFgrz nRJ4jnYcgmjZZEgOFlL8/8PR8eUDFRjQgVDLiynFCgC9oxoD1HWqIUkVJrNhZaaQqJgr OQrgKHIAOF2dmrewp1NaspKruhhG73lXylbvbNyaLpqI1zTQQ0B+hLjYFLrs4p7Qky67 MSFf4/SSy+sxFyAnk967DiTveiSgQT5+y+KXZP5jVk7+qKveSjY3WXyj2z1+0+X4fJEG yflw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=BEbFgVbN; 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 k26-20020a1709062a5a00b00926f64a9e55si375347eje.898.2023.04.05.07.11.51 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 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=BEbFgVbN; 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 5EC6F38845F7 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-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id 07F4E385C301 for ; Wed, 5 Apr 2023 14:05:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 07F4E385C301 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-x335.google.com with SMTP id v14-20020a05600c470e00b003f06520825fso1157423wmo.0 for ; Wed, 05 Apr 2023 07:05:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703534; 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=51PEspkDcmiXoo4pzo1UuUsXRaxb+ly/OpVFXeCOfn8=; b=BEbFgVbNg7SyYWhZDQONk40y72NHMxAgXMbsm7W527X5bsGpD6OOCilrDGrwnsYjRP QpO+yLPlOchBs2c08eCY001XujtFpwDmXGs+e5I3BcrF2jCYz0g7FBfYJFaJvel1+lDW GzQ2v4JXE/CDAM4/B0qTBmB1lssOo6R8ZW7rvTjeLu0TkwzmAXN8yPSIjiVx5CEkjtBj LYPb0a31Mr0qBAs/7+R5nMuthcXXTjUSEXO+o70hebv3ZTRCrIjRuPMqpdkNvMGukwVb jgdEp/j3MI9FMTPXjj3LQTUdK2ZF9YrEkgbxX1yRssxDTtemXReRx8NRhoBKh1xFnevU eZJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703534; 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=51PEspkDcmiXoo4pzo1UuUsXRaxb+ly/OpVFXeCOfn8=; b=5g2LGiFJxuk0boLrraOooqphtEuJbOgCadYuAtJsQBVZIQPq3ydfglroJEcEC4lMWh cSbHW85D68Q+KeuAS6mSljHi7BnUNIrRpHMqM5RSvP3qUGbmjPHCYD1FOB3YWIhIA9YV C1PKonQzq9iIJPrLtfZMk7aMPR7JEXGOJ1IfNvnY7HcNfQYgTV6GlTL+GHDG6tC0gW0y uOsNtOBahAMOz+0ZuZd0xy5S+9mlGQ2YuYkV7+H5sWN1hw1B72rR+55XWwmjSN4Uy3+n yEkzkTDJtDm5fySlai310mjie9n7bQPBzDu9MTSnQ7Kb6oTaNmLlrrOpu7U176B2bGuG wQdA== X-Gm-Message-State: AAQBX9eyFfSygRVKWVnJ2SQCXK6Wrl4g6tMRrUv/bbQhu0yPvnS+QQi3 LlI57sZO8m+grdkGj+sPzzdYXjA4iqh4MbWwAQ== X-Received: by 2002:a7b:c85a:0:b0:3ef:7594:48cc with SMTP id c26-20020a7bc85a000000b003ef759448ccmr4803354wml.23.1680703534429; Wed, 05 Apr 2023 07:05:34 -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.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:33 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, mxlol233 Subject: [committed 09/88] gccrs: Add get_locus function for abstract class MetaItemInner. Date: Wed, 5 Apr 2023 16:02:53 +0200 Message-Id: <20230405140411.3016563-10-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.6 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?1762345784267453456?= X-GMAIL-MSGID: =?utf-8?q?1762345784267453456?= From: mxlol233 This commit adds virtual function get_locus to base class MetaItemInner, which is helpful when we need to print diagnostics on some sub-classes of MetaItemInner. gcc/rust/ChangeLog: * ast/rust-ast.h: Add get_locus method. * ast/rust-expr.h: Likewise. * ast/rust-macro.h: Likewise. Signed-off-by: Xiao Ma --- gcc/rust/ast/rust-ast.h | 2 ++ gcc/rust/ast/rust-expr.h | 8 ++++++++ gcc/rust/ast/rust-macro.h | 12 ++++++++++++ 3 files changed, 22 insertions(+) diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 5f18233eb0f..d30e6d494f2 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -630,6 +630,8 @@ public: virtual ~MetaItemInner (); + virtual Location get_locus () const = 0; + virtual std::string as_string () const = 0; virtual void accept_vis (ASTVisitor &vis) = 0; diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index c58fae5e564..34bc6993ab6 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -150,6 +150,8 @@ public: std::string as_string () const override { return lit_expr.as_string (); } + Location get_locus () const override { return lit_expr.get_locus (); } + void accept_vis (ASTVisitor &vis) override; bool check_cfg_predicate (const Session &session) const override; @@ -178,6 +180,12 @@ public: return path.as_string () + " = " + lit.as_string (); } + // There are two Locations in MetaItemPathLit (path and lit_expr), + // we have no idea use which of them, just simply return UNKNOWN_LOCATION + // now. + // Maybe we will figure out when we really need the location in the future. + Location get_locus () const override { return Location (UNKNOWN_LOCATION); } + void accept_vis (ASTVisitor &vis) override; bool check_cfg_predicate (const Session &session) const override; diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h index bff8c7ac6fb..4226c6919ff 100644 --- a/gcc/rust/ast/rust-macro.h +++ b/gcc/rust/ast/rust-macro.h @@ -725,6 +725,8 @@ public: return path; } + Location get_locus () const override { return path.get_locus (); } + bool check_cfg_predicate (const Session &session) const override; Attribute to_attribute () const override; @@ -778,6 +780,8 @@ public: void accept_vis (ASTVisitor &vis) override; + Location get_locus () const override { return path.get_locus (); } + bool check_cfg_predicate (const Session &session) const override; Attribute to_attribute () const override; @@ -805,6 +809,8 @@ public: void accept_vis (ASTVisitor &vis) override; + Location get_locus () const override { return ident_locus; } + bool check_cfg_predicate (const Session &session) const override; Attribute to_attribute () const override; @@ -847,6 +853,8 @@ public: return std::unique_ptr (clone_meta_item_inner_impl ()); } + Location get_locus () const override { return ident_locus; } + bool check_cfg_predicate (const Session &session) const override; Attribute to_attribute () const override; @@ -885,6 +893,8 @@ public: void accept_vis (ASTVisitor &vis) override; + Location get_locus () const override { return ident_locus; } + bool check_cfg_predicate (const Session &session) const override; Attribute to_attribute () const override; @@ -919,6 +929,8 @@ public: void accept_vis (ASTVisitor &vis) override; + Location get_locus () const override { return ident_locus; } + bool check_cfg_predicate (const Session &session) const override; Attribute to_attribute () const override; From patchwork Wed Apr 5 14:02: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: 79627 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp339464vqo; Wed, 5 Apr 2023 07:14:18 -0700 (PDT) X-Google-Smtp-Source: AKy350Zhk99JasiOvObXh1hcs/I4HrnreQCz85PM/5KhnRKX8dK36I7SO3kjxkoNTcdvpcesPFeT X-Received: by 2002:a17:906:8450:b0:93e:8791:7d8e with SMTP id e16-20020a170906845000b0093e87917d8emr2922223ejy.2.1680704058599; Wed, 05 Apr 2023 07:14:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704058; cv=none; d=google.com; s=arc-20160816; b=Mo7+2ZSOe7yo6kNIDspDdnkH/IoggEcqKWbXJl0DaW60AFtl7USsH+VJMMwZOKh9j9 1z6dK0XpQqlz/Zw+GTC2W9fjLUWVuSEAYKNpX/3Nfzw8RkuAeEu2p4yS5Bauqf2rHl0A Jmu9ZCG/QUk1dP3KK7CsGPtYlfovLritRMto3IgaMk0lO4eVq/qlmqBbcU52bLjD1+95 HRfQmtMTscYRchFROOvwqNRYp94Er+EsCFZ+zenFvtHpEf33cUQ2qrtgnuN412GGYr6w HRxfZCIoqc8Sa1BUtET4bC8gcYQlk12vCypuVE5ZpDNPDsHeqcXUxaCP6kp/7ku8V3KH nigw== 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=54dS6FrJwYhk+06LJqCTGLmIFZu5DQOrMSHvcyd5Q/c=; b=dvZ9JfodoUNiABL7MFmFOKEgDi/pR3lm+iu0KnTBPAZaTdMGs9Qx5em9Vx7aiGgANc yy0vCChuwsN30jcoTdWIC+/C21EKFRmXEBcr+9kwOGI7ZYi0OnClqCJVb8WYWsJ0U+ps 8V4SZd3pf7amAMXtlbeRvhGxDBo6Pc/reUu1gfIPh5Q8+q0Bt0Va753/NJk6OEI7vIMI r0UTuZb/c5z0jbYSeFtCqq0KdSPbmtEH8fnpWNMmw8iMwlW5C1u5gLrmb+JV9LTJfBg2 lbYIxIJ/OLwbfjxoz1OHiezcvggdd8EeQ9LLmk3k4iUWGbjBoAP1N7CaV7RiNo//Psug 2B5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=PcvdxtYQ; 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 a23-20020a1709063e9700b008d78cb027b7si1173064ejj.667.2023.04.05.07.14.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:14:18 -0700 (PDT) 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=PcvdxtYQ; 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 3008239502DE for ; Wed, 5 Apr 2023 14:08:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id B94EF3858C2B for ; Wed, 5 Apr 2023 14:05:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B94EF3858C2B 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-x32c.google.com with SMTP id m8so10051857wmq.5 for ; Wed, 05 Apr 2023 07:05:36 -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=54dS6FrJwYhk+06LJqCTGLmIFZu5DQOrMSHvcyd5Q/c=; b=PcvdxtYQ8HfaQjhzwh/k53gNTWnOhqfXLLil5lWa/BS6uRT26Co3bkNhZY/TsQX3t4 NXLqGQMcDePb816rsFFNjL/8laE69SYmXPiK/KeggTaRMqavy7rdBma/onHvgdFaVzYh ilSM3r4XZGnX4/NWf35c0VXfmWHfxtIQoqY0fm8LP97124fbXJ+YFd7q7KqJoCEh9rWn 0GWmgOYEn80Vfnt3i2ulkZK5hcTaUlZ8D8uLCd/ckvFtvyrSe9vFdBXc5qIF9MtcSpT4 mDGczLXQztFKi9jt1Hf6AYut3d67/scrD+j7VRCueMc5yFzo0RqST+0Sqm1p851SVtf6 uFvg== 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=54dS6FrJwYhk+06LJqCTGLmIFZu5DQOrMSHvcyd5Q/c=; b=Dx2BnVkjg9+d37SO0KcZW1DUaDhMIQWhntaslgzSzwohsCKeIE0cIQneFg9rqWZVTb +13B98NQJ+IyFyzVbMTdKd1rzap/MKUdrTjqKKtQ8rVOGowjLhjqdRvccMuG0tEdtMyc WFe1pu0rWThm5JYwPHhURrGTBZkRxfW5TejDhs2aKXaOoc40N/nSr8qTLi/PE3YbZCRh zGFS2ixvySL0U1beyNRmDeG2x/QOsIzlJA7OAGT3TDfHt03rFlZb4PLzU/cdcE1PijMf 8isdDC4XiQGsUqxZ84EH03MMuPWfBSVNRjrr3HINy40RRVCw5IxvkXAjrtFfxqLYDhvl e96A== X-Gm-Message-State: AAQBX9fa06WeH4pWVG09A6InvkleJEEVv28yJLq1FS5HeyDaq2dNdqWp 2aI1PzxnGPEypZB2au5d1WYrSQqH7q0M7x9row== X-Received: by 2002:a05:600c:25a:b0:3ed:237f:3da with SMTP id 26-20020a05600c025a00b003ed237f03damr5204318wmj.22.1680703535210; 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.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:34 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, mxlol233 Subject: [committed 10/88] gccrs: diagnostics: Add underline for tokens in diagnostics. Date: Wed, 5 Apr 2023 16:02:54 +0200 Message-Id: <20230405140411.3016563-11-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=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?1762345939104911847?= X-GMAIL-MSGID: =?utf-8?q?1762345939104911847?= From: mxlol233 Currently, the diagnostics only point to the corresponding token's start position by carets, and lack of underlines for full token. This commit add support for such underlines in diagnostics by encoding range information in location_t. gcc/rust/ChangeLog: * lex/rust-lex.cc (Lexer::build_token): Make location enclose entire token. (Lexer::parse_byte_char): Likewise. (Lexer::parse_byte_string): Likewise. (Lexer::parse_raw_byte_string): Likewise. (Lexer::parse_raw_identifier): Likewise. (Lexer::parse_string): Likewise. (Lexer::parse_identifier_or_keyword): Likewise. (Lexer::parse_raw_string): Likewise. (Lexer::parse_non_decimal_int_literal): Likewise. (Lexer::parse_decimal_int_or_float): Likewise. (Lexer::parse_char_or_lifetime): Likewise. gcc/testsuite/ChangeLog: * rust/compile/diagnostic_underline.rs: New test. Signed-off-by: Xiao Ma --- gcc/rust/lex/rust-lex.cc | 57 +++++++++++++++++++ .../rust/compile/diagnostic_underline.rs | 15 +++++ 2 files changed, 72 insertions(+) create mode 100644 gcc/testsuite/rust/compile/diagnostic_underline.rs diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc index ac7ced540e6..9967cecb2e2 100644 --- a/gcc/rust/lex/rust-lex.cc +++ b/gcc/rust/lex/rust-lex.cc @@ -447,6 +447,7 @@ Lexer::build_token () // match arm arrow skip_input (); current_column += 2; + loc += 1; return Token::make (MATCH_ARROW, loc); } @@ -455,6 +456,7 @@ Lexer::build_token () // equality operator skip_input (); current_column += 2; + loc += 1; return Token::make (EQUAL_EQUAL, loc); } @@ -473,6 +475,7 @@ Lexer::build_token () // return type specifier skip_input (); current_column += 2; + loc += 1; return Token::make (RETURN_TYPE, loc); } @@ -481,6 +484,7 @@ Lexer::build_token () // minus-assign skip_input (); current_column += 2; + loc += 1; return Token::make (MINUS_EQ, loc); } @@ -496,6 +500,7 @@ Lexer::build_token () // add-assign skip_input (); current_column += 2; + loc += 1; return Token::make (PLUS_EQ, loc); } @@ -517,6 +522,7 @@ Lexer::build_token () // multiplication-assign skip_input (); current_column += 2; + loc += 1; return Token::make (ASTERISK_EQ, loc); } @@ -535,6 +541,7 @@ Lexer::build_token () // division-assign skip_input (); current_column += 2; + loc += 1; return Token::make (DIV_EQ, loc); } @@ -602,6 +609,8 @@ Lexer::build_token () start_line (current_line, max_column_hint); str.shrink_to_fit (); + + loc += str.size () - 1; if (is_inner) return Token::make_inner_doc_comment (loc, std::move (str)); else @@ -756,6 +765,8 @@ Lexer::build_token () } str.shrink_to_fit (); + + loc += str.size () - 1; if (is_inner) return Token::make_inner_doc_comment (loc, std::move (str)); else @@ -773,6 +784,7 @@ Lexer::build_token () // modulo-assign skip_input (); current_column += 2; + loc += 1; return Token::make (PERCENT_EQ, loc); } @@ -788,6 +800,7 @@ Lexer::build_token () // xor-assign? skip_input (); current_column += 2; + loc += 1; return Token::make (CARET_EQ, loc); } @@ -805,6 +818,7 @@ Lexer::build_token () // left-shift assign skip_input (1); current_column += 3; + loc += 2; return Token::make (LEFT_SHIFT_EQ, loc); } @@ -813,6 +827,7 @@ Lexer::build_token () // left-shift skip_input (); current_column += 2; + loc += 1; return Token::make (LEFT_SHIFT, loc); } @@ -822,6 +837,7 @@ Lexer::build_token () // smaller than or equal to skip_input (); current_column += 2; + loc += 1; return Token::make (LESS_OR_EQUAL, loc); } @@ -840,6 +856,7 @@ Lexer::build_token () // right-shift-assign skip_input (1); current_column += 3; + loc += 2; return Token::make (RIGHT_SHIFT_EQ, loc); } @@ -848,6 +865,7 @@ Lexer::build_token () // right-shift skip_input (); current_column += 2; + loc += 1; return Token::make (RIGHT_SHIFT, loc); } @@ -857,6 +875,7 @@ Lexer::build_token () // larger than or equal to skip_input (); current_column += 2; + loc += 1; return Token::make (GREATER_OR_EQUAL, loc); } @@ -872,6 +891,7 @@ Lexer::build_token () // scope resolution :: skip_input (); current_column += 2; + loc += 1; return Token::make (SCOPE_RESOLUTION, loc); } @@ -888,6 +908,7 @@ Lexer::build_token () // not equal boolean operator skip_input (); current_column += 2; + loc += 1; return Token::make (NOT_EQUAL, loc); } @@ -937,6 +958,7 @@ Lexer::build_token () // bitwise or-assign? skip_input (); current_column += 2; + loc += 1; return Token::make (PIPE_EQ, loc); } @@ -945,6 +967,7 @@ Lexer::build_token () // logical or skip_input (); current_column += 2; + loc += 1; return Token::make (OR, loc); } @@ -961,6 +984,7 @@ Lexer::build_token () // bitwise and-assign? skip_input (); current_column += 2; + loc += 1; return Token::make (AMP_EQ, loc); } @@ -969,6 +993,7 @@ Lexer::build_token () // logical and skip_input (); current_column += 2; + loc += 1; return Token::make (LOGICAL_AND, loc); } @@ -987,6 +1012,7 @@ Lexer::build_token () // ellipsis skip_input (1); current_column += 3; + loc += 2; return Token::make (ELLIPSIS, loc); } @@ -995,6 +1021,7 @@ Lexer::build_token () // ..= skip_input (1); current_column += 3; + loc += 2; return Token::make (DOT_DOT_EQ, loc); } @@ -1003,6 +1030,7 @@ Lexer::build_token () // .. skip_input (); current_column += 2; + loc += 1; return Token::make (DOT_DOT, loc); } @@ -1717,6 +1745,8 @@ Lexer::parse_byte_char (Location loc) current_column += length; + loc += length - 1; + return Token::make_byte_char (loc, byte_char); } @@ -1781,6 +1811,7 @@ Lexer::parse_byte_string (Location loc) } str.shrink_to_fit (); + loc += str.size () - 1; return Token::make_byte_string (loc, std::move (str)); } @@ -1861,6 +1892,8 @@ Lexer::parse_raw_byte_string (Location loc) current_column += length; + loc += length - 1; + str.shrink_to_fit (); return Token::make_byte_string (loc, std::move (str)); @@ -1912,6 +1945,7 @@ Lexer::parse_raw_identifier (Location loc) else { str.shrink_to_fit (); + loc += length - 1; return Token::make_identifier (loc, std::move (str)); } @@ -2009,6 +2043,8 @@ Lexer::parse_string (Location loc) } str.shrink_to_fit (); + loc += length - 1; + return Token::make_string (loc, std::move (str)); } @@ -2043,6 +2079,8 @@ Lexer::parse_identifier_or_keyword (Location loc) str.shrink_to_fit (); + loc += length - 1; + TokenId keyword = classify_keyword (str); if (keyword == IDENTIFIER) return Token::make_identifier (loc, std::move (str)); @@ -2120,6 +2158,8 @@ Lexer::parse_raw_string (Location loc, int initial_hash_count) current_column += length; + loc += length - 1; + str.shrink_to_fit (); return Token::make_string (loc, std::move (str)); @@ -2183,6 +2223,9 @@ Lexer::parse_non_decimal_int_literal (Location loc, IsDigitFunc is_digit_func, : ""))); return nullptr; } + + loc += length - 1; + return Token::make_int (loc, std::move (existent_str), type_hint); } @@ -2275,6 +2318,8 @@ Lexer::parse_decimal_int_or_float (Location loc) current_column += length; + loc += length - 1; + str.shrink_to_fit (); return Token::make_float (loc, std::move (str), type_hint); } @@ -2295,6 +2340,8 @@ Lexer::parse_decimal_int_or_float (Location loc) current_column += length; + loc += length - 1; + str.shrink_to_fit (); return Token::make_float (loc, std::move (str), CORETYPE_UNKNOWN); } @@ -2324,6 +2371,8 @@ Lexer::parse_decimal_int_or_float (Location loc) current_column += length; + loc += length - 1; + str.shrink_to_fit (); return Token::make_float (loc, std::move (str), type_hint); } @@ -2345,6 +2394,8 @@ Lexer::parse_decimal_int_or_float (Location loc) current_column += length; + loc += length - 1; + str.shrink_to_fit (); return Token::make_int (loc, std::move (str), type_hint); } @@ -2382,6 +2433,8 @@ Lexer::parse_char_or_lifetime (Location loc) current_column += length; + loc += length - 1; + return Token::make_char (loc, current_char32); } else @@ -2399,6 +2452,8 @@ Lexer::parse_char_or_lifetime (Location loc) // TODO fix due to different widths of utf-8 chars? current_column += 3; + loc += 2; + return Token::make_char (loc, current_char32); } else if (ISDIGIT (current_char32.value) || ISALPHA (current_char32.value) @@ -2421,6 +2476,8 @@ Lexer::parse_char_or_lifetime (Location loc) current_column += length; + loc += length - 1; + str.shrink_to_fit (); return Token::make_lifetime (loc, std::move (str)); } diff --git a/gcc/testsuite/rust/compile/diagnostic_underline.rs b/gcc/testsuite/rust/compile/diagnostic_underline.rs new file mode 100644 index 00000000000..fcbf468e1c8 --- /dev/null +++ b/gcc/testsuite/rust/compile/diagnostic_underline.rs @@ -0,0 +1,15 @@ +// { dg-additional-options "-quiet" } + +/* { dg-options "-fdiagnostics-show-caret" } */ + + +fn barbarbar() {} + +const fn foo() { + barbarbar();// { dg-error "only functions marked as 'const' are allowed to be called from constant contexts" } +/* { dg-begin-multiline-output "" } + barbarbar();// + ^~~~~~~~~ +{ dg-end-multiline-output "" } */ +} + 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 From patchwork Wed Apr 5 14:02: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: 79640 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp343503vqo; Wed, 5 Apr 2023 07:19:05 -0700 (PDT) X-Google-Smtp-Source: AKy350YIQLgFT2jImyaXkyOI0XC05rLcQqAZFlT93LRMAggl4iuWBeHs6vI+dop/EEyu0Btcy7Y2 X-Received: by 2002:a17:907:3d92:b0:93d:1c2b:bd23 with SMTP id he18-20020a1709073d9200b0093d1c2bbd23mr4165649ejc.39.1680704345756; Wed, 05 Apr 2023 07:19:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704345; cv=none; d=google.com; s=arc-20160816; b=TRoARkSoJmnn+iN5sNVF3CgWxjbxMQ+TsuEvzVeppK3FpilY+KN/twwW9CrYLyXyaj /hMz5/EawNCNOkEdVyMUc9hz1TuaHxqzbUqSICw8pM4ZNoSMql+bdfEviLoH8MfbTvMj M6/Kp0iRvdZQx5aketDIHfwilPBJ3vUshmiBP1Fg/ZV1bxupIWxEO93lbd4GObwmvR8W 9tQ9fMQcDMh6X6gxXkIMJOb7Ja1+RDsHXyHOyDF0V0Gf9X0LMKZcSZhK61kBQFOrumrO IUS0i1lc7fvAPQECrvqpoPdeVhAmjbhvaroFCEo7vmM46c+vjNjRuEhRwNeFbnVJQLnr TB9Q== 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=I62DKEyh9VWZHoh2Wavuo9yxy6Cfr1NJrWVLtVSueQQ=; b=O/gCBoQeWvd5TPn/1El/ZwH5BmKdNgGcifXdT8A/ss/VpJ+772Tk8YjakOvhCCUvG5 t4ftSP47hGSI/lUEy68TSjsKYksozbWFQ24taX9QZ6Ifm+fejZkEaLsI1sRPQrknthCP +AY3IGz3uyWLluwSDZZYvgePO52Jvw3MrRwOid4kpdKYI7aVJIU+4rsaVhvF4RDJM0N0 q3rsnnIBbCCySSCOBJLujgilmvFZKoJ95G5pKVx6WOGiCq4xXM1cpiGbAJ+77EizwQzo WfnuVJXIZz70+2aQW3wrbi5FG9Eg08/QoBvlLr/nKT8h8I4WpzU5vwaDB9QYWAuB37ze ex/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=HRN4dIbM; 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 b1-20020a170906150100b0092bec96207asi10311099ejd.309.2023.04.05.07.19.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:19:05 -0700 (PDT) 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=HRN4dIbM; 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 A078B385B518 for ; Wed, 5 Apr 2023 14:09:45 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id AE7E43856DF9 for ; Wed, 5 Apr 2023 14:05:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AE7E43856DF9 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-x329.google.com with SMTP id l15-20020a05600c4f0f00b003ef6d684102so18505910wmq.3 for ; Wed, 05 Apr 2023 07:05:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703537; 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=I62DKEyh9VWZHoh2Wavuo9yxy6Cfr1NJrWVLtVSueQQ=; b=HRN4dIbMngiJnKh5zH/9GauwmtfeYORaQ7jEoKch8cTvHoI16iiJubBQEI9zfXW7KM xxdWJM/8JUvQ2+6PJxp1B6x9Ygu7AMXOaFxhlNGkRuPTPwCeix4YlUdgyXP41XcaXuaa y+DOhJYXawmoKyNMWOwFgY3Jr/J1COZBmnjBqOddCntsIIG+4KVmxJJ0HJx0Aw31208r k9FxvyBCBC+GPkhO1C1JDxnwm+/+79FSzJBInt+YUiwtPFoZ8D15HN+jLMP860eCGci8 3/F5hpk12fMVV3EbWxrp8aUgVxz1gQjGjgxgPPPDFP/Frj7h2t7KyJP4np5bxzhlGDn0 ZXJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703537; 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=I62DKEyh9VWZHoh2Wavuo9yxy6Cfr1NJrWVLtVSueQQ=; b=D5G/wcPoPiaadD7IA5M1tDT40boUdJJDBseYEQc1XslX1PKOURFeDeVftpsQ55w2YJ lSq+3AeuqNTgPWtyLztoWKHUZW/y70MI6bMmIgAwaU2oJ8SpjqDUtNG+9HXowB0eUr1N AF5O+aTIKc9LmilX3PdmnsYcY7BK+v0LQj34r7Qohqq5OMvn90eJ199cdrz8T9qDZRf5 t9RHhvx6tCmOXgNbmlsENZr5AGqiqRcMg9lpwCB2r+1PunkwNIi2eth0KMXhkIbQbLHA nTt7bL9JVacQYl48rn9XFLGisOxM+tPktl0zCAVENHo9FfuZxCvyrLI06W4NM0Q/VuKv +b7A== X-Gm-Message-State: AAQBX9e+YSvvru5NUsa5OjtZasQILJWp+BVhxaWzK6skeKQ3gdn04O7h CSAN6u7MNNEtwwhIfHvHxBORQ3gV0lXXhrXefg== X-Received: by 2002:a05:600c:21c1:b0:3ee:3d2d:841a with SMTP id x1-20020a05600c21c100b003ee3d2d841amr4697276wmj.24.1680703536413; Wed, 05 Apr 2023 07:05:36 -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:36 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 12/88] gccrs: testsuite: Handle Windows carriage returns properly Date: Wed, 5 Apr 2023 16:02:56 +0200 Message-Id: <20230405140411.3016563-13-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.6 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?1762346239910711699?= X-GMAIL-MSGID: =?utf-8?q?1762346239910711699?= From: Arthur Cohen In dg-output, check for \r* carriage returns to make sure execution tests pass on windows platforms gcc/testsuite/ChangeLog: * rust/execute/torture/builtin_macro_cfg.rs: Handle carriage returns properly. * rust/execute/torture/builtin_macro_concat.rs: Likewise. * rust/execute/torture/builtin_macro_env.rs: Likewise. * rust/execute/torture/builtin_macro_include_bytes.rs: Likewise. * rust/execute/torture/builtin_macro_include_str.rs: Likewise. * rust/execute/torture/builtin_macro_line.rs: Likewise. * rust/execute/torture/builtin_macros1.rs: Likewise. * rust/execute/torture/builtin_macros3.rs: Likewise. * rust/execute/torture/cfg1.rs: Likewise. * rust/execute/torture/cfg2.rs: Likewise. * rust/execute/torture/cfg3.rs: Likewise. * rust/execute/torture/cfg4.rs: Likewise. * rust/execute/torture/coercion1.rs: Likewise. * rust/execute/torture/coercion2.rs: Likewise. * rust/execute/torture/extern_mod4.rs: Likewise. * rust/execute/torture/helloworld1.rs: Likewise. * rust/execute/torture/helloworld2.rs: Likewise. * rust/execute/torture/issue-1198.rs: Likewise. * rust/execute/torture/issue-1231.rs: Likewise. * rust/execute/torture/issue-1232.rs: Likewise. * rust/execute/torture/issue-1249.rs: Likewise. * rust/execute/torture/issue-1436.rs: Likewise. * rust/execute/torture/issue-1496.rs: Likewise. * rust/execute/torture/issue-647.rs: Likewise. * rust/execute/torture/issue-845.rs: Likewise. * rust/execute/torture/issue-851.rs: Likewise. * rust/execute/torture/issue-858.rs: Likewise. * rust/execute/torture/issue-976.rs: Likewise. * rust/execute/torture/macros10.rs: Likewise. * rust/execute/torture/macros11.rs: Likewise. * rust/execute/torture/macros12.rs: Likewise. * rust/execute/torture/macros13.rs: Likewise. * rust/execute/torture/macros14.rs: Likewise. * rust/execute/torture/macros2.rs: Likewise. * rust/execute/torture/macros22.rs: Likewise. * rust/execute/torture/macros29.rs: Likewise. * rust/execute/torture/macros3.rs: Likewise. * rust/execute/torture/macros30.rs: Likewise. * rust/execute/torture/macros31.rs: Likewise. * rust/execute/torture/macros7.rs: Likewise. * rust/execute/torture/macros8.rs: Likewise. * rust/execute/torture/macros9.rs: Likewise. * rust/execute/torture/match1.rs: Likewise. * rust/execute/torture/match2.rs: Likewise. * rust/execute/torture/match3.rs: Likewise. * rust/execute/torture/match_bool1.rs: Likewise. * rust/execute/torture/match_byte1.rs: Likewise. * rust/execute/torture/match_char1.rs: Likewise. * rust/execute/torture/match_int1.rs: Likewise. * rust/execute/torture/match_loop1.rs: Likewise. * rust/execute/torture/match_range1.rs: Likewise. * rust/execute/torture/match_range2.rs: Likewise. * rust/execute/torture/match_tuple1.rs: Likewise. * rust/execute/torture/method1.rs: Likewise. * rust/execute/torture/method2.rs: Likewise. * rust/execute/torture/method3.rs: Likewise. * rust/execute/torture/method4.rs: Likewise. * rust/execute/torture/operator_overload_1.rs: Likewise. * rust/execute/torture/operator_overload_10.rs: Likewise. * rust/execute/torture/operator_overload_11.rs: Likewise. * rust/execute/torture/operator_overload_12.rs: Likewise. * rust/execute/torture/operator_overload_2.rs: Likewise. * rust/execute/torture/operator_overload_4.rs: Likewise. * rust/execute/torture/operator_overload_5.rs: Likewise. * rust/execute/torture/operator_overload_6.rs: Likewise. * rust/execute/torture/operator_overload_7.rs: Likewise. * rust/execute/torture/operator_overload_8.rs: Likewise. * rust/execute/torture/operator_overload_9.rs: Likewise. * rust/execute/torture/str-layout1.rs: Likewise. * rust/execute/torture/str-zero.rs: Likewise. * rust/execute/torture/trait1.rs: Likewise. * rust/execute/torture/trait10.rs: Likewise. * rust/execute/torture/trait11.rs: Likewise. * rust/execute/torture/trait12.rs: Likewise. * rust/execute/torture/trait13.rs: Likewise. * rust/execute/torture/trait2.rs: Likewise. * rust/execute/torture/trait3.rs: Likewise. * rust/execute/torture/trait4.rs: Likewise. * rust/execute/torture/trait5.rs: Likewise. * rust/execute/torture/trait6.rs: Likewise. * rust/execute/torture/trait7.rs: Likewise. * rust/execute/torture/trait8.rs: Likewise. * rust/execute/torture/trait9.rs: Likewise. * rust/execute/torture/closure2.rs: Likewise. * rust/execute/torture/closure3.rs: Likewise. * rust/execute/torture/loop-condition-eval.rs: Likewise. * rust/execute/torture/operator_overload_3.rs: Likewise. --- .../rust/execute/torture/builtin_macro_cfg.rs | 8 ++--- .../execute/torture/builtin_macro_concat.rs | 2 +- .../rust/execute/torture/builtin_macro_env.rs | 2 +- .../torture/builtin_macro_include_bytes.rs | 2 +- .../torture/builtin_macro_include_str.rs | 2 +- .../execute/torture/builtin_macro_line.rs | 2 +- .../rust/execute/torture/builtin_macros1.rs | 2 +- .../rust/execute/torture/builtin_macros3.rs | 5 ++- gcc/testsuite/rust/execute/torture/cfg1.rs | 2 +- gcc/testsuite/rust/execute/torture/cfg2.rs | 2 +- gcc/testsuite/rust/execute/torture/cfg3.rs | 2 +- gcc/testsuite/rust/execute/torture/cfg4.rs | 2 +- .../rust/execute/torture/closure2.rs | 2 +- .../rust/execute/torture/closure3.rs | 2 +- .../rust/execute/torture/coercion1.rs | 2 +- .../rust/execute/torture/coercion2.rs | 2 +- .../rust/execute/torture/extern_mod4.rs | 2 +- .../rust/execute/torture/helloworld1.rs | 2 +- .../rust/execute/torture/helloworld2.rs | 2 +- .../rust/execute/torture/issue-1198.rs | 2 +- .../rust/execute/torture/issue-1231.rs | 2 +- .../rust/execute/torture/issue-1232.rs | 2 +- .../rust/execute/torture/issue-1249.rs | 2 +- .../rust/execute/torture/issue-1436.rs | 1 - .../rust/execute/torture/issue-1496.rs | 2 +- .../rust/execute/torture/issue-647.rs | 2 +- .../rust/execute/torture/issue-845.rs | 2 +- .../rust/execute/torture/issue-851.rs | 2 +- .../rust/execute/torture/issue-858.rs | 2 +- .../rust/execute/torture/issue-976.rs | 2 +- .../execute/torture/loop-condition-eval.rs | 2 +- .../rust/execute/torture/macros10.rs | 2 +- .../rust/execute/torture/macros11.rs | 2 +- .../rust/execute/torture/macros12.rs | 2 +- .../rust/execute/torture/macros13.rs | 2 +- .../rust/execute/torture/macros14.rs | 2 +- gcc/testsuite/rust/execute/torture/macros2.rs | 2 +- .../rust/execute/torture/macros22.rs | 2 +- .../rust/execute/torture/macros29.rs | 2 +- gcc/testsuite/rust/execute/torture/macros3.rs | 2 +- .../rust/execute/torture/macros30.rs | 2 +- .../rust/execute/torture/macros31.rs | 2 +- gcc/testsuite/rust/execute/torture/macros7.rs | 2 +- gcc/testsuite/rust/execute/torture/macros8.rs | 2 +- gcc/testsuite/rust/execute/torture/macros9.rs | 2 +- gcc/testsuite/rust/execute/torture/match1.rs | 2 +- gcc/testsuite/rust/execute/torture/match2.rs | 2 +- gcc/testsuite/rust/execute/torture/match3.rs | 2 +- .../rust/execute/torture/match_bool1.rs | 2 +- .../rust/execute/torture/match_byte1.rs | 2 +- .../rust/execute/torture/match_char1.rs | 2 +- .../rust/execute/torture/match_int1.rs | 2 +- .../rust/execute/torture/match_loop1.rs | 2 +- .../rust/execute/torture/match_range1.rs | 2 +- .../rust/execute/torture/match_range2.rs | 2 +- .../rust/execute/torture/match_tuple1.rs | 2 +- gcc/testsuite/rust/execute/torture/method1.rs | 2 +- gcc/testsuite/rust/execute/torture/method2.rs | 2 +- gcc/testsuite/rust/execute/torture/method3.rs | 2 +- gcc/testsuite/rust/execute/torture/method4.rs | 2 +- .../execute/torture/operator_overload_1.rs | 2 +- .../execute/torture/operator_overload_10.rs | 2 +- .../execute/torture/operator_overload_11.rs | 2 +- .../execute/torture/operator_overload_12.rs | 2 +- .../execute/torture/operator_overload_2.rs | 2 +- .../execute/torture/operator_overload_3.rs | 2 +- .../execute/torture/operator_overload_4.rs | 2 +- .../execute/torture/operator_overload_5.rs | 2 +- .../execute/torture/operator_overload_6.rs | 2 +- .../execute/torture/operator_overload_7.rs | 2 +- .../execute/torture/operator_overload_8.rs | 2 +- .../execute/torture/operator_overload_9.rs | 2 +- .../rust/execute/torture/str-layout1.rs | 2 +- .../rust/execute/torture/str-zero.rs | 33 +++++++++---------- gcc/testsuite/rust/execute/torture/trait1.rs | 2 +- gcc/testsuite/rust/execute/torture/trait10.rs | 2 +- gcc/testsuite/rust/execute/torture/trait11.rs | 2 +- gcc/testsuite/rust/execute/torture/trait12.rs | 2 +- gcc/testsuite/rust/execute/torture/trait13.rs | 2 +- gcc/testsuite/rust/execute/torture/trait2.rs | 2 +- gcc/testsuite/rust/execute/torture/trait3.rs | 2 +- gcc/testsuite/rust/execute/torture/trait4.rs | 2 +- gcc/testsuite/rust/execute/torture/trait5.rs | 2 +- gcc/testsuite/rust/execute/torture/trait6.rs | 2 +- gcc/testsuite/rust/execute/torture/trait7.rs | 2 +- gcc/testsuite/rust/execute/torture/trait8.rs | 2 +- gcc/testsuite/rust/execute/torture/trait9.rs | 2 +- 87 files changed, 104 insertions(+), 109 deletions(-) diff --git a/gcc/testsuite/rust/execute/torture/builtin_macro_cfg.rs b/gcc/testsuite/rust/execute/torture/builtin_macro_cfg.rs index fad2daef6bc..a8d6ae0f7ca 100644 --- a/gcc/testsuite/rust/execute/torture/builtin_macro_cfg.rs +++ b/gcc/testsuite/rust/execute/torture/builtin_macro_cfg.rs @@ -1,5 +1,5 @@ // { dg-additional-options "-w -frust-cfg=A" } -// { dg-output "A\n" } +// { dg-output "A\r*\n" } #[rustc_builtin_macro] macro_rules! cfg { () => {{}}; @@ -12,7 +12,7 @@ extern "C" { fn print(s: &str) { unsafe { printf( - "%s\n" as *const str as *const i8, + "%s\n\0" as *const str as *const i8, s as *const str as *const i8, ); } @@ -21,11 +21,11 @@ fn print(s: &str) { fn main() -> i32 { let cfg = cfg!(A); if cfg { - print("A"); + print("A\0"); } let cfg = cfg!(B); if cfg { - print("B"); + print("B\0"); } 0 diff --git a/gcc/testsuite/rust/execute/torture/builtin_macro_concat.rs b/gcc/testsuite/rust/execute/torture/builtin_macro_concat.rs index 9b33924f5a1..a9d68e0cd35 100644 --- a/gcc/testsuite/rust/execute/torture/builtin_macro_concat.rs +++ b/gcc/testsuite/rust/execute/torture/builtin_macro_concat.rs @@ -1,4 +1,4 @@ -// { dg-output "\ntest10btrue2.15\ntest10bfalse2.151\n" } +// { dg-output "\r*\ntest10btrue2.15\r*\ntest10bfalse2.151\r*\n" } #[rustc_builtin_macro] macro_rules! concat { () => {{}}; diff --git a/gcc/testsuite/rust/execute/torture/builtin_macro_env.rs b/gcc/testsuite/rust/execute/torture/builtin_macro_env.rs index a5c80b25728..d64e2a00097 100644 --- a/gcc/testsuite/rust/execute/torture/builtin_macro_env.rs +++ b/gcc/testsuite/rust/execute/torture/builtin_macro_env.rs @@ -1,4 +1,4 @@ -// { dg-output "VALUE\nVALUE\n" } +// { dg-output "VALUE\r*\nVALUE\r*\n" } // { dg-set-compiler-env-var ENV_MACRO_TEST "VALUE" } #[rustc_builtin_macro] macro_rules! env { diff --git a/gcc/testsuite/rust/execute/torture/builtin_macro_include_bytes.rs b/gcc/testsuite/rust/execute/torture/builtin_macro_include_bytes.rs index 087f0220de5..8be55773036 100644 --- a/gcc/testsuite/rust/execute/torture/builtin_macro_include_bytes.rs +++ b/gcc/testsuite/rust/execute/torture/builtin_macro_include_bytes.rs @@ -1,4 +1,4 @@ -// { dg-output "104\n33\n1\n" } +// { dg-output "104\r*\n33\r*\n1\r*\n" } #[rustc_builtin_macro] macro_rules! include_bytes { () => {{}}; diff --git a/gcc/testsuite/rust/execute/torture/builtin_macro_include_str.rs b/gcc/testsuite/rust/execute/torture/builtin_macro_include_str.rs index 6f9871d379c..43d40c9c0df 100644 --- a/gcc/testsuite/rust/execute/torture/builtin_macro_include_str.rs +++ b/gcc/testsuite/rust/execute/torture/builtin_macro_include_str.rs @@ -1,4 +1,4 @@ -// { dg-output "hello, include!\n" } +// { dg-output "hello, include!\r*\n" } #[rustc_builtin_macro] macro_rules! include_str { () => {{}}; diff --git a/gcc/testsuite/rust/execute/torture/builtin_macro_line.rs b/gcc/testsuite/rust/execute/torture/builtin_macro_line.rs index 02541ed52e2..9998de1402d 100644 --- a/gcc/testsuite/rust/execute/torture/builtin_macro_line.rs +++ b/gcc/testsuite/rust/execute/torture/builtin_macro_line.rs @@ -1,4 +1,4 @@ -// { dg-output "18\n21\n" } +// { dg-output "18\r*\n21\r*\n" } extern "C" { fn printf(fmt: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/builtin_macros1.rs b/gcc/testsuite/rust/execute/torture/builtin_macros1.rs index 5976478e426..5bccb16e0f9 100644 --- a/gcc/testsuite/rust/execute/torture/builtin_macros1.rs +++ b/gcc/testsuite/rust/execute/torture/builtin_macros1.rs @@ -1,4 +1,4 @@ -// { dg-output "rust/execute/torture/builtin_macros1.rs" } +// { dg-output "rust/execute/torture/builtin_macros1.rs\r*" } #[rustc_builtin_macro] macro_rules! file { () => {{}}; diff --git a/gcc/testsuite/rust/execute/torture/builtin_macros3.rs b/gcc/testsuite/rust/execute/torture/builtin_macros3.rs index 24555cbdb8a..5a024fa0e24 100644 --- a/gcc/testsuite/rust/execute/torture/builtin_macros3.rs +++ b/gcc/testsuite/rust/execute/torture/builtin_macros3.rs @@ -1,4 +1,4 @@ -// { dg-output "14\n42\n" } +// { dg-output "14\r*\n42\r*\n" } #[rustc_builtin_macro] macro_rules! column { () => {{}}; @@ -19,10 +19,9 @@ fn main() -> i32 { print(c0); - let c1 = column!(); + let c1 = /* --------------------- */ column!(); print(c1); 0 } - diff --git a/gcc/testsuite/rust/execute/torture/cfg1.rs b/gcc/testsuite/rust/execute/torture/cfg1.rs index d3c56295503..648d1f1ff72 100644 --- a/gcc/testsuite/rust/execute/torture/cfg1.rs +++ b/gcc/testsuite/rust/execute/torture/cfg1.rs @@ -1,5 +1,5 @@ // { dg-additional-options "-w -frust-cfg=A" } -// { dg-output "test1\n" } +// { dg-output "test1\r*\n" } extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/cfg2.rs b/gcc/testsuite/rust/execute/torture/cfg2.rs index 5048bcb2791..7b75ac6962f 100644 --- a/gcc/testsuite/rust/execute/torture/cfg2.rs +++ b/gcc/testsuite/rust/execute/torture/cfg2.rs @@ -1,5 +1,5 @@ // { dg-additional-options "-w -frust-cfg=A" } -// { dg-output "test1\n" } +// { dg-output "test1\r*\n" } extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/cfg3.rs b/gcc/testsuite/rust/execute/torture/cfg3.rs index 89312344b23..97a8fb8e461 100644 --- a/gcc/testsuite/rust/execute/torture/cfg3.rs +++ b/gcc/testsuite/rust/execute/torture/cfg3.rs @@ -1,5 +1,5 @@ // { dg-additional-options "-w -frust-cfg=A" } -// { dg-output "test1\n" } +// { dg-output "test1\r*\n" } extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/cfg4.rs b/gcc/testsuite/rust/execute/torture/cfg4.rs index d1c2a22a0ff..97026d902d0 100644 --- a/gcc/testsuite/rust/execute/torture/cfg4.rs +++ b/gcc/testsuite/rust/execute/torture/cfg4.rs @@ -1,5 +1,5 @@ // { dg-additional-options "-w -frust-cfg=A" } -// { dg-output "test1\ntest2\n" } +// { dg-output "test1\r*\ntest2\r*\n" } extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/closure2.rs b/gcc/testsuite/rust/execute/torture/closure2.rs index 45b3b5ce8b4..8e1502dfa43 100644 --- a/gcc/testsuite/rust/execute/torture/closure2.rs +++ b/gcc/testsuite/rust/execute/torture/closure2.rs @@ -1,4 +1,4 @@ -// { dg-output "3\n" } +// { dg-output "3\r*\n" } extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/closure3.rs b/gcc/testsuite/rust/execute/torture/closure3.rs index 62cf3a082cf..8fa9445ab62 100644 --- a/gcc/testsuite/rust/execute/torture/closure3.rs +++ b/gcc/testsuite/rust/execute/torture/closure3.rs @@ -1,4 +1,4 @@ -// { dg-output "3\n" } +// { dg-output "3\r*\n" } extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/coercion1.rs b/gcc/testsuite/rust/execute/torture/coercion1.rs index 2cdb9bbca38..6ca28233d60 100644 --- a/gcc/testsuite/rust/execute/torture/coercion1.rs +++ b/gcc/testsuite/rust/execute/torture/coercion1.rs @@ -1,4 +1,4 @@ -/* { dg-output "123\n123\n" } */ +/* { dg-output "123\r*\n123\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/coercion2.rs b/gcc/testsuite/rust/execute/torture/coercion2.rs index 12dd68ff5f7..047fd536dca 100644 --- a/gcc/testsuite/rust/execute/torture/coercion2.rs +++ b/gcc/testsuite/rust/execute/torture/coercion2.rs @@ -1,4 +1,4 @@ -/* { dg-output "123\n123\n" } */ +/* { dg-output "123\r*\n123\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/extern_mod4.rs b/gcc/testsuite/rust/execute/torture/extern_mod4.rs index 99b6fb5c9ba..55be2b8115f 100644 --- a/gcc/testsuite/rust/execute/torture/extern_mod4.rs +++ b/gcc/testsuite/rust/execute/torture/extern_mod4.rs @@ -1,5 +1,5 @@ // { dg-additional-options "-w" } -// { dg-output "12" } +// { dg-output "12\r*" } mod modules; extern "C" { diff --git a/gcc/testsuite/rust/execute/torture/helloworld1.rs b/gcc/testsuite/rust/execute/torture/helloworld1.rs index d416efa33af..8803156b5fd 100644 --- a/gcc/testsuite/rust/execute/torture/helloworld1.rs +++ b/gcc/testsuite/rust/execute/torture/helloworld1.rs @@ -1,4 +1,4 @@ -/* { dg-output "Hello World" }*/ +/* { dg-output "Hello World\r*" }*/ extern "C" { fn puts(s: *const i8); } diff --git a/gcc/testsuite/rust/execute/torture/helloworld2.rs b/gcc/testsuite/rust/execute/torture/helloworld2.rs index cc05f3798fa..912301bcb26 100644 --- a/gcc/testsuite/rust/execute/torture/helloworld2.rs +++ b/gcc/testsuite/rust/execute/torture/helloworld2.rs @@ -1,4 +1,4 @@ -/* { dg-output "Hello World 123\n" }*/ +/* { dg-output "Hello World 123\r*\n" }*/ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/issue-1198.rs b/gcc/testsuite/rust/execute/torture/issue-1198.rs index fce44ad1994..bbc58f0f370 100644 --- a/gcc/testsuite/rust/execute/torture/issue-1198.rs +++ b/gcc/testsuite/rust/execute/torture/issue-1198.rs @@ -1,4 +1,4 @@ -/* { dg-output "foo_deref\nimm_deref\n123\n" } */ +/* { dg-output "foo_deref\r*\nimm_deref\r*\n123\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/issue-1231.rs b/gcc/testsuite/rust/execute/torture/issue-1231.rs index 970e86f917a..321df5fec55 100644 --- a/gcc/testsuite/rust/execute/torture/issue-1231.rs +++ b/gcc/testsuite/rust/execute/torture/issue-1231.rs @@ -1,5 +1,5 @@ // { dg-additional-options "-w" } -// { dg-output "outer\ninner\n" } +// { dg-output "outer\r*\ninner\r*\n" } extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/issue-1232.rs b/gcc/testsuite/rust/execute/torture/issue-1232.rs index c56d5c18695..9215efdba6c 100644 --- a/gcc/testsuite/rust/execute/torture/issue-1232.rs +++ b/gcc/testsuite/rust/execute/torture/issue-1232.rs @@ -1,5 +1,5 @@ // { dg-additional-options "-w" } -// { dg-output "slice_access=3\n" } +// { dg-output "slice_access=3\r*\n" } extern "rust-intrinsic" { #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")] fn offset(dst: *const T, offset: isize) -> *const T; diff --git a/gcc/testsuite/rust/execute/torture/issue-1249.rs b/gcc/testsuite/rust/execute/torture/issue-1249.rs index 072204ea877..06911074c30 100644 --- a/gcc/testsuite/rust/execute/torture/issue-1249.rs +++ b/gcc/testsuite/rust/execute/torture/issue-1249.rs @@ -1,5 +1,5 @@ // { dg-options "-w" } -// { dg-output "1\n2\n" } +// { dg-output "1\r*\n2\r*\n" } extern "C" { fn printf(s: *const i8, ...); diff --git a/gcc/testsuite/rust/execute/torture/issue-1436.rs b/gcc/testsuite/rust/execute/torture/issue-1436.rs index 5c079a61f07..96de5d69194 100644 --- a/gcc/testsuite/rust/execute/torture/issue-1436.rs +++ b/gcc/testsuite/rust/execute/torture/issue-1436.rs @@ -1,5 +1,4 @@ // { dg-options "-w" } -// { dg-output "" } mod intrinsics { extern "rust-intrinsic" { #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")] diff --git a/gcc/testsuite/rust/execute/torture/issue-1496.rs b/gcc/testsuite/rust/execute/torture/issue-1496.rs index 9f08b2ae98a..af4201b7d3e 100644 --- a/gcc/testsuite/rust/execute/torture/issue-1496.rs +++ b/gcc/testsuite/rust/execute/torture/issue-1496.rs @@ -1,4 +1,4 @@ -/* { dg-output "foo_deref\nimm_deref\n123\n" } */ +/* { dg-output "foo_deref\r*\nimm_deref\r*\n123\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/issue-647.rs b/gcc/testsuite/rust/execute/torture/issue-647.rs index 3f427ccb785..d76d43b6110 100644 --- a/gcc/testsuite/rust/execute/torture/issue-647.rs +++ b/gcc/testsuite/rust/execute/torture/issue-647.rs @@ -1,4 +1,4 @@ -/* { dg-output "Hello World 123\n" }*/ +/* { dg-output "Hello World 123\r*\n" }*/ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/issue-845.rs b/gcc/testsuite/rust/execute/torture/issue-845.rs index 4c689e3b6c8..f96714d4bae 100644 --- a/gcc/testsuite/rust/execute/torture/issue-845.rs +++ b/gcc/testsuite/rust/execute/torture/issue-845.rs @@ -1,4 +1,4 @@ -// { dg-output "Foo::bar\n" } +// { dg-output "Foo::bar\r*\n" } // { dg-additional-options "-w" } extern "C" { fn printf(s: *const i8, ...); diff --git a/gcc/testsuite/rust/execute/torture/issue-851.rs b/gcc/testsuite/rust/execute/torture/issue-851.rs index 3881c7a2ada..b3b2b480ec2 100644 --- a/gcc/testsuite/rust/execute/torture/issue-851.rs +++ b/gcc/testsuite/rust/execute/torture/issue-851.rs @@ -1,4 +1,4 @@ -/* { dg-output "Result: 123\n" } */ +/* { dg-output "Result: 123\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/issue-858.rs b/gcc/testsuite/rust/execute/torture/issue-858.rs index 5a43f3e1b1a..51a15613844 100644 --- a/gcc/testsuite/rust/execute/torture/issue-858.rs +++ b/gcc/testsuite/rust/execute/torture/issue-858.rs @@ -1,4 +1,4 @@ -/* { dg-output "Result: 123\n" } */ +/* { dg-output "Result: 123\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/issue-976.rs b/gcc/testsuite/rust/execute/torture/issue-976.rs index 42cf596fb7d..cf6cfa66cd1 100644 --- a/gcc/testsuite/rust/execute/torture/issue-976.rs +++ b/gcc/testsuite/rust/execute/torture/issue-976.rs @@ -1,4 +1,4 @@ -/* { dg-output "hi" } */ +/* { dg-output "hi\r*" } */ fn main() -> i32 { { extern "C" { diff --git a/gcc/testsuite/rust/execute/torture/loop-condition-eval.rs b/gcc/testsuite/rust/execute/torture/loop-condition-eval.rs index 008965917ab..67ac00ced59 100644 --- a/gcc/testsuite/rust/execute/torture/loop-condition-eval.rs +++ b/gcc/testsuite/rust/execute/torture/loop-condition-eval.rs @@ -1,4 +1,4 @@ -// { dg-output "1\n" } +// { dg-output "1\r*\n" } pub fn test() -> u64 { let mut n = 113383; // #20 in https://oeis.org/A006884 while n != 1 { diff --git a/gcc/testsuite/rust/execute/torture/macros10.rs b/gcc/testsuite/rust/execute/torture/macros10.rs index 155a440ee04..4f976f0b317 100644 --- a/gcc/testsuite/rust/execute/torture/macros10.rs +++ b/gcc/testsuite/rust/execute/torture/macros10.rs @@ -1,4 +1,4 @@ -// { dg-output "18\n" } +// { dg-output "18\r*\n" } extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/macros11.rs b/gcc/testsuite/rust/execute/torture/macros11.rs index 5bde97d3dd4..70e5f25cf71 100644 --- a/gcc/testsuite/rust/execute/torture/macros11.rs +++ b/gcc/testsuite/rust/execute/torture/macros11.rs @@ -1,4 +1,4 @@ -// { dg-output "2" } +// { dg-output "2\r*" } extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/macros12.rs b/gcc/testsuite/rust/execute/torture/macros12.rs index d310dff9ba8..deb424ffdbc 100644 --- a/gcc/testsuite/rust/execute/torture/macros12.rs +++ b/gcc/testsuite/rust/execute/torture/macros12.rs @@ -1,4 +1,4 @@ -// { dg-output "0\n" } +// { dg-output "0\r*\n" } extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/macros13.rs b/gcc/testsuite/rust/execute/torture/macros13.rs index afb20264625..ec36a21f26e 100644 --- a/gcc/testsuite/rust/execute/torture/macros13.rs +++ b/gcc/testsuite/rust/execute/torture/macros13.rs @@ -1,4 +1,4 @@ -// { dg-output "18\n" } +// { dg-output "18\r*\n" } extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/macros14.rs b/gcc/testsuite/rust/execute/torture/macros14.rs index 00656546d4c..189fadd9861 100644 --- a/gcc/testsuite/rust/execute/torture/macros14.rs +++ b/gcc/testsuite/rust/execute/torture/macros14.rs @@ -1,4 +1,4 @@ -// { dg-output "15\n" } +// { dg-output "15\r*\n" } extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/macros2.rs b/gcc/testsuite/rust/execute/torture/macros2.rs index ba5098710ea..aca528a08aa 100644 --- a/gcc/testsuite/rust/execute/torture/macros2.rs +++ b/gcc/testsuite/rust/execute/torture/macros2.rs @@ -1,4 +1,4 @@ -// { dg-output "arg\narg\narg\n" } +// { dg-output "arg\r*\narg\r*\narg\r*\n" } extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/macros22.rs b/gcc/testsuite/rust/execute/torture/macros22.rs index 3f291ace98e..60ffae145ed 100644 --- a/gcc/testsuite/rust/execute/torture/macros22.rs +++ b/gcc/testsuite/rust/execute/torture/macros22.rs @@ -1,4 +1,4 @@ -// { dg-output "1\n2\nNaN\n3\n" } +// { dg-output "1\r*\n2\r*\nNaN\r*\n3\r*\n" } macro_rules! print_num { ($l:literal) => {{ diff --git a/gcc/testsuite/rust/execute/torture/macros29.rs b/gcc/testsuite/rust/execute/torture/macros29.rs index 306979b9b5b..9c2cc0e6a1b 100644 --- a/gcc/testsuite/rust/execute/torture/macros29.rs +++ b/gcc/testsuite/rust/execute/torture/macros29.rs @@ -1,4 +1,4 @@ -// { dg-output "1\n" } +// { dg-output "1\r*\n" } #[rustc_builtin_macro] macro_rules! concat { () => {{}}; diff --git a/gcc/testsuite/rust/execute/torture/macros3.rs b/gcc/testsuite/rust/execute/torture/macros3.rs index 00f6d253f50..91936c1ca83 100644 --- a/gcc/testsuite/rust/execute/torture/macros3.rs +++ b/gcc/testsuite/rust/execute/torture/macros3.rs @@ -1,4 +1,4 @@ -// { dg-output "invok\ninvok\ninvok\ninvok\ninvok\n" } +// { dg-output "invok\r*\ninvok\r*\ninvok\r*\ninvok\r*\ninvok\r*\n" } extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/macros30.rs b/gcc/testsuite/rust/execute/torture/macros30.rs index ab36f5e78af..7ec77d06982 100644 --- a/gcc/testsuite/rust/execute/torture/macros30.rs +++ b/gcc/testsuite/rust/execute/torture/macros30.rs @@ -1,4 +1,4 @@ -// { dg-output "1\n" } +// { dg-output "1\r*\n" } #[rustc_builtin_macro] macro_rules! concat { () => {{}}; diff --git a/gcc/testsuite/rust/execute/torture/macros31.rs b/gcc/testsuite/rust/execute/torture/macros31.rs index 483f897a92b..4c6378a68c2 100644 --- a/gcc/testsuite/rust/execute/torture/macros31.rs +++ b/gcc/testsuite/rust/execute/torture/macros31.rs @@ -1,5 +1,5 @@ // { dg-additional-options "-w -frust-cfg=A" } -// { dg-output "A\nB\n" } +// { dg-output "A\r*\nB\r*\n" } #[rustc_builtin_macro] macro_rules! cfg { () => {{}}; diff --git a/gcc/testsuite/rust/execute/torture/macros7.rs b/gcc/testsuite/rust/execute/torture/macros7.rs index ed1f922f581..b8af009aed4 100644 --- a/gcc/testsuite/rust/execute/torture/macros7.rs +++ b/gcc/testsuite/rust/execute/torture/macros7.rs @@ -1,4 +1,4 @@ -// { dg-output "any\nany\nany\n" } +// { dg-output "any\r*\nany\r*\nany\r*\n" } extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/macros8.rs b/gcc/testsuite/rust/execute/torture/macros8.rs index a12aca4910e..e532237ecde 100644 --- a/gcc/testsuite/rust/execute/torture/macros8.rs +++ b/gcc/testsuite/rust/execute/torture/macros8.rs @@ -1,4 +1,4 @@ -// { dg-output "zo1\nzo1\n" } +// { dg-output "zo1\r*\nzo1\r*\n" } extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/macros9.rs b/gcc/testsuite/rust/execute/torture/macros9.rs index 0e3fd24e8a9..81aa3683bb3 100644 --- a/gcc/testsuite/rust/execute/torture/macros9.rs +++ b/gcc/testsuite/rust/execute/torture/macros9.rs @@ -1,4 +1,4 @@ -// { dg-output "oom\noom\noom\n" } +// { dg-output "oom\r*\noom\r*\noom\r*\n" } extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/match1.rs b/gcc/testsuite/rust/execute/torture/match1.rs index e5af512f15d..66a5be3792a 100644 --- a/gcc/testsuite/rust/execute/torture/match1.rs +++ b/gcc/testsuite/rust/execute/torture/match1.rs @@ -1,4 +1,4 @@ -// { dg-output "Foo::A\nFoo::B\nFoo::C x\nFoo::D 20 80\n" } +// { dg-output "Foo::A\r*\nFoo::B\r*\nFoo::C x\r*\nFoo::D 20 80\r*\n" } extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/match2.rs b/gcc/testsuite/rust/execute/torture/match2.rs index 02cedf29b3c..3c9fbde262a 100644 --- a/gcc/testsuite/rust/execute/torture/match2.rs +++ b/gcc/testsuite/rust/execute/torture/match2.rs @@ -1,4 +1,4 @@ -// { dg-output "123\n80\n" } +// { dg-output "123\r*\n80\r*\n" } extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/match3.rs b/gcc/testsuite/rust/execute/torture/match3.rs index 8cded3044df..3dda9a35db3 100644 --- a/gcc/testsuite/rust/execute/torture/match3.rs +++ b/gcc/testsuite/rust/execute/torture/match3.rs @@ -1,4 +1,4 @@ -// { dg-output "Foo::A\nwildcard\nwildcard\nFoo::D 20 80\n" } +// { dg-output "Foo::A\r*\nwildcard\r*\nwildcard\r*\nFoo::D 20 80\r*\n" } extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/match_bool1.rs b/gcc/testsuite/rust/execute/torture/match_bool1.rs index 101dbb58571..2fb5e02b273 100644 --- a/gcc/testsuite/rust/execute/torture/match_bool1.rs +++ b/gcc/testsuite/rust/execute/torture/match_bool1.rs @@ -1,4 +1,4 @@ -// { dg-output "182 is more than 100\n55 is less than 100\n" } +// { dg-output "182 is more than 100\r*\n55 is less than 100\r*\n" } extern "C" { fn printf(s: *const i8, ...); diff --git a/gcc/testsuite/rust/execute/torture/match_byte1.rs b/gcc/testsuite/rust/execute/torture/match_byte1.rs index 3546cfb9d8b..4261b2b9f5e 100644 --- a/gcc/testsuite/rust/execute/torture/match_byte1.rs +++ b/gcc/testsuite/rust/execute/torture/match_byte1.rs @@ -1,4 +1,4 @@ -// { dg-output "a\nseven\nquote\nelse" } +// { dg-output "a\r*\nseven\r*\nquote\r*\nelse" } extern "C" { fn printf(s: *const i8, ...); diff --git a/gcc/testsuite/rust/execute/torture/match_char1.rs b/gcc/testsuite/rust/execute/torture/match_char1.rs index fa65876a907..1584b419daa 100644 --- a/gcc/testsuite/rust/execute/torture/match_char1.rs +++ b/gcc/testsuite/rust/execute/torture/match_char1.rs @@ -1,4 +1,4 @@ -// { dg-output "amazing\nwildcard\ncompiler\nproductivity\n" } +// { dg-output "amazing\r*\nwildcard\r*\ncompiler\r*\nproductivity\r*\n" } extern "C" { fn printf(s: *const i8, ...); diff --git a/gcc/testsuite/rust/execute/torture/match_int1.rs b/gcc/testsuite/rust/execute/torture/match_int1.rs index 209429added..a7deefbaa02 100644 --- a/gcc/testsuite/rust/execute/torture/match_int1.rs +++ b/gcc/testsuite/rust/execute/torture/match_int1.rs @@ -1,4 +1,4 @@ -// { dg-output "other!\nother!\nother!\nfifteen!\nfifteen!\nother!\nother!\nfifteen!\n" } +// { dg-output "other!\r*\nother!\r*\nother!\r*\nfifteen!\r*\nfifteen!\r*\nother!\r*\nother!\r*\nfifteen!\r*\n" } extern "C" { fn printf(s: *const i8, ...); diff --git a/gcc/testsuite/rust/execute/torture/match_loop1.rs b/gcc/testsuite/rust/execute/torture/match_loop1.rs index bb6aee946f6..578712fa7f5 100644 --- a/gcc/testsuite/rust/execute/torture/match_loop1.rs +++ b/gcc/testsuite/rust/execute/torture/match_loop1.rs @@ -1,4 +1,4 @@ -// { dg-output "E::One\nE::Two\nbreak!\n" } +// { dg-output "E::One\r*\nE::Two\r*\nbreak!\r*\n" } extern "C" { fn printf(s: *const i8, ...); diff --git a/gcc/testsuite/rust/execute/torture/match_range1.rs b/gcc/testsuite/rust/execute/torture/match_range1.rs index 82e9e34a989..3b705407fb2 100644 --- a/gcc/testsuite/rust/execute/torture/match_range1.rs +++ b/gcc/testsuite/rust/execute/torture/match_range1.rs @@ -1,4 +1,4 @@ -// { dg-output "zero to END_RANGE\nzero to END_RANGE\nelse\n" } +// { dg-output "zero to END_RANGE\r*\nzero to END_RANGE\r*\nelse\r*\n" } extern "C" { fn printf(s: *const i8, ...); diff --git a/gcc/testsuite/rust/execute/torture/match_range2.rs b/gcc/testsuite/rust/execute/torture/match_range2.rs index 8153f9e1c7e..517f2bbeb84 100644 --- a/gcc/testsuite/rust/execute/torture/match_range2.rs +++ b/gcc/testsuite/rust/execute/torture/match_range2.rs @@ -1,4 +1,4 @@ -// { dg-output "lowercase\nuppercase\nother\n" } +// { dg-output "lowercase\r*\nuppercase\r*\nother\r*\n" } extern "C" { fn printf(s: *const i8, ...); diff --git a/gcc/testsuite/rust/execute/torture/match_tuple1.rs b/gcc/testsuite/rust/execute/torture/match_tuple1.rs index cb61cc0847c..2ae3ca7db4e 100644 --- a/gcc/testsuite/rust/execute/torture/match_tuple1.rs +++ b/gcc/testsuite/rust/execute/torture/match_tuple1.rs @@ -1,4 +1,4 @@ -// { dg-output "x:15\ny:20\n" } +// { dg-output "x:15\r*\ny:20\r*\n" } extern "C" { fn printf(s: *const i8, ...); diff --git a/gcc/testsuite/rust/execute/torture/method1.rs b/gcc/testsuite/rust/execute/torture/method1.rs index 6af6133939b..c57944b93eb 100644 --- a/gcc/testsuite/rust/execute/torture/method1.rs +++ b/gcc/testsuite/rust/execute/torture/method1.rs @@ -1,4 +1,4 @@ -/* { dg-output "124\n458" } */ +/* { dg-output "124\r*\n458" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/method2.rs b/gcc/testsuite/rust/execute/torture/method2.rs index f532b4488c6..79a35eb53d8 100644 --- a/gcc/testsuite/rust/execute/torture/method2.rs +++ b/gcc/testsuite/rust/execute/torture/method2.rs @@ -1,5 +1,5 @@ // { dg-additional-options "-w" } -// { dg-output "foo_deref\nimm_deref\n" } +// { dg-output "foo_deref\r*\nimm_deref\r*\n" } extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/method3.rs b/gcc/testsuite/rust/execute/torture/method3.rs index 0e9e8ff42a0..7217d35c4b3 100644 --- a/gcc/testsuite/rust/execute/torture/method3.rs +++ b/gcc/testsuite/rust/execute/torture/method3.rs @@ -1,5 +1,5 @@ // { dg-additional-options "-w" } -// { dg-output "mut_deref\nfoobar: 123\n" } +// { dg-output "mut_deref\r*\nfoobar: 123\r*\n" } extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/method4.rs b/gcc/testsuite/rust/execute/torture/method4.rs index 5c6fdfe02c3..ba1ffd1da36 100644 --- a/gcc/testsuite/rust/execute/torture/method4.rs +++ b/gcc/testsuite/rust/execute/torture/method4.rs @@ -1,5 +1,5 @@ // { dg-additional-options "-w" } -// { dg-output "mut_deref\nfoobar: 123\n" } +// { dg-output "mut_deref\r*\nfoobar: 123\r*\n" } extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/operator_overload_1.rs b/gcc/testsuite/rust/execute/torture/operator_overload_1.rs index 5a28c5f4e93..064a77651ad 100644 --- a/gcc/testsuite/rust/execute/torture/operator_overload_1.rs +++ b/gcc/testsuite/rust/execute/torture/operator_overload_1.rs @@ -1,4 +1,4 @@ -/* { dg-output "3\n" } */ +/* { dg-output "3\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/operator_overload_10.rs b/gcc/testsuite/rust/execute/torture/operator_overload_10.rs index f5d45db5338..3fa5afd01f3 100644 --- a/gcc/testsuite/rust/execute/torture/operator_overload_10.rs +++ b/gcc/testsuite/rust/execute/torture/operator_overload_10.rs @@ -1,4 +1,4 @@ -/* { dg-output "foo_deref\n123\n" } */ +/* { dg-output "foo_deref\r*\n123\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/operator_overload_11.rs b/gcc/testsuite/rust/execute/torture/operator_overload_11.rs index 1919941c486..94bc1cd9d96 100644 --- a/gcc/testsuite/rust/execute/torture/operator_overload_11.rs +++ b/gcc/testsuite/rust/execute/torture/operator_overload_11.rs @@ -1,4 +1,4 @@ -// { dg-output "1\n" } +// { dg-output "1\r*\n" } // { dg-additional-options "-w" } extern "C" { fn printf(s: *const i8, ...); diff --git a/gcc/testsuite/rust/execute/torture/operator_overload_12.rs b/gcc/testsuite/rust/execute/torture/operator_overload_12.rs index 7433330fa31..d525ec44e8f 100644 --- a/gcc/testsuite/rust/execute/torture/operator_overload_12.rs +++ b/gcc/testsuite/rust/execute/torture/operator_overload_12.rs @@ -1,4 +1,4 @@ -// { dg-output "1\n" } +// { dg-output "1\r*\n" } // { dg-additional-options "-w" } extern "C" { fn printf(s: *const i8, ...); diff --git a/gcc/testsuite/rust/execute/torture/operator_overload_2.rs b/gcc/testsuite/rust/execute/torture/operator_overload_2.rs index a577718451d..fab3a83b7f5 100644 --- a/gcc/testsuite/rust/execute/torture/operator_overload_2.rs +++ b/gcc/testsuite/rust/execute/torture/operator_overload_2.rs @@ -1,4 +1,4 @@ -/* { dg-output "3\n" } */ +/* { dg-output "3\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/operator_overload_3.rs b/gcc/testsuite/rust/execute/torture/operator_overload_3.rs index 57f58076c3e..2bcb1c4267c 100644 --- a/gcc/testsuite/rust/execute/torture/operator_overload_3.rs +++ b/gcc/testsuite/rust/execute/torture/operator_overload_3.rs @@ -1,4 +1,4 @@ -/* { dg-output "3\n3\n" } */ +/* { dg-output "3\r*\n3\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/operator_overload_4.rs b/gcc/testsuite/rust/execute/torture/operator_overload_4.rs index ce9887b2ead..e1fcbac1c77 100644 --- a/gcc/testsuite/rust/execute/torture/operator_overload_4.rs +++ b/gcc/testsuite/rust/execute/torture/operator_overload_4.rs @@ -1,4 +1,4 @@ -/* { dg-output "neg\n" } */ +/* { dg-output "neg\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/operator_overload_5.rs b/gcc/testsuite/rust/execute/torture/operator_overload_5.rs index a525f743680..2ba87285ef1 100644 --- a/gcc/testsuite/rust/execute/torture/operator_overload_5.rs +++ b/gcc/testsuite/rust/execute/torture/operator_overload_5.rs @@ -1,4 +1,4 @@ -/* { dg-output "not\n" } */ +/* { dg-output "not\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/operator_overload_6.rs b/gcc/testsuite/rust/execute/torture/operator_overload_6.rs index fbd2a8fa9d3..50463e74761 100644 --- a/gcc/testsuite/rust/execute/torture/operator_overload_6.rs +++ b/gcc/testsuite/rust/execute/torture/operator_overload_6.rs @@ -1,4 +1,4 @@ -/* { dg-output "add_assign\n3\n" } */ +/* { dg-output "add_assign\r*\n3\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/operator_overload_7.rs b/gcc/testsuite/rust/execute/torture/operator_overload_7.rs index 886a7010efc..50107bb4324 100644 --- a/gcc/testsuite/rust/execute/torture/operator_overload_7.rs +++ b/gcc/testsuite/rust/execute/torture/operator_overload_7.rs @@ -1,4 +1,4 @@ -/* { dg-output "imm_deref\n123\n" } */ +/* { dg-output "imm_deref\r*\n123\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/operator_overload_8.rs b/gcc/testsuite/rust/execute/torture/operator_overload_8.rs index 862e29a4bc6..e0338b917f5 100644 --- a/gcc/testsuite/rust/execute/torture/operator_overload_8.rs +++ b/gcc/testsuite/rust/execute/torture/operator_overload_8.rs @@ -1,4 +1,4 @@ -/* { dg-output "imm_deref\n123\n" } */ +/* { dg-output "imm_deref\r*\n123\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/operator_overload_9.rs b/gcc/testsuite/rust/execute/torture/operator_overload_9.rs index fd972e28ab3..608ad0fe94e 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 "mut_deref\n123\n" } */ +/* { dg-output "mut_deref\r*\n123\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/str-layout1.rs b/gcc/testsuite/rust/execute/torture/str-layout1.rs index 80bdc2a9c9f..39c1e38d77b 100644 --- a/gcc/testsuite/rust/execute/torture/str-layout1.rs +++ b/gcc/testsuite/rust/execute/torture/str-layout1.rs @@ -1,5 +1,5 @@ // { dg-additional-options "-w" } -// { dg-output "t1sz=5 t2sz=10" } +// { dg-output "t1sz=5 t2sz=10\r*" } mod mem { extern "rust-intrinsic" { #[rustc_const_stable(feature = "const_transmute", since = "1.46.0")] diff --git a/gcc/testsuite/rust/execute/torture/str-zero.rs b/gcc/testsuite/rust/execute/torture/str-zero.rs index e7fba0d1372..9042f54436e 100644 --- a/gcc/testsuite/rust/execute/torture/str-zero.rs +++ b/gcc/testsuite/rust/execute/torture/str-zero.rs @@ -1,26 +1,23 @@ -/* { dg-output "bar foo baz foobar\n" } */ -extern "C" -{ - fn printf(s: *const i8, ...); - fn memchr(s: *const i8, c: u8, n: usize) -> *const i8; +/* { dg-output "bar foo baz foobar\r*\n" } */ +extern "C" { + fn printf(s: *const i8, ...); + fn memchr(s: *const i8, c: u8, n: usize) -> *const i8; } -pub fn main () -> i32 -{ - let f = "%s %s %s %s\n\0"; - let s = "bar\0\ +pub fn main() -> i32 { + let f = "%s %s %s %s\n\0"; + let s = "bar\0\ foo\ \x00\ baz\u{0000}\ foobar\0"; - let cf = f as *const str as *const i8; - let cs = s as *const str as *const i8; - unsafe - { - let cs2 = memchr (cs, b'f', 5); - let cs3 = memchr (cs2, b'b', 5); - let cs4 = memchr (cs3, b'f', 5); - printf (cf, cs, cs2, cs3, cs4); + let cf = f as *const str as *const i8; + let cs = s as *const str as *const i8; + unsafe { + let cs2 = memchr(cs, b'f', 5); + let cs3 = memchr(cs2, b'b', 5); + let cs4 = memchr(cs3, b'f', 5); + printf(cf, cs, cs2, cs3, cs4); } - 0 + 0 } diff --git a/gcc/testsuite/rust/execute/torture/trait1.rs b/gcc/testsuite/rust/execute/torture/trait1.rs index dc3cc471c33..d4f5878ef18 100644 --- a/gcc/testsuite/rust/execute/torture/trait1.rs +++ b/gcc/testsuite/rust/execute/torture/trait1.rs @@ -1,4 +1,4 @@ -/* { dg-output "S::f\nT1::f\nT2::f\n" } */ +/* { dg-output "S::f\r*\nT1::f\r*\nT2::f\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/trait10.rs b/gcc/testsuite/rust/execute/torture/trait10.rs index e581e324bbf..b0bdeab9091 100644 --- a/gcc/testsuite/rust/execute/torture/trait10.rs +++ b/gcc/testsuite/rust/execute/torture/trait10.rs @@ -1,4 +1,4 @@ -/* { dg-output "123\n" } */ +/* { dg-output "123\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/trait11.rs b/gcc/testsuite/rust/execute/torture/trait11.rs index 283c9ecd0ed..ed7b7c9d6ee 100644 --- a/gcc/testsuite/rust/execute/torture/trait11.rs +++ b/gcc/testsuite/rust/execute/torture/trait11.rs @@ -1,4 +1,4 @@ -/* { dg-output "3\n" } */ +/* { dg-output "3\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/trait12.rs b/gcc/testsuite/rust/execute/torture/trait12.rs index 68b0a4014ad..a4ba5be116e 100644 --- a/gcc/testsuite/rust/execute/torture/trait12.rs +++ b/gcc/testsuite/rust/execute/torture/trait12.rs @@ -1,4 +1,4 @@ -/* { dg-output "3\n" } */ +/* { dg-output "3\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/trait13.rs b/gcc/testsuite/rust/execute/torture/trait13.rs index 3071da27a6a..49befb8fbb1 100644 --- a/gcc/testsuite/rust/execute/torture/trait13.rs +++ b/gcc/testsuite/rust/execute/torture/trait13.rs @@ -1,4 +1,4 @@ -/* { dg-output "123\n456\n" } */ +/* { dg-output "123\r*\n456\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/trait2.rs b/gcc/testsuite/rust/execute/torture/trait2.rs index c96615fa891..9974f70da8c 100644 --- a/gcc/testsuite/rust/execute/torture/trait2.rs +++ b/gcc/testsuite/rust/execute/torture/trait2.rs @@ -1,4 +1,4 @@ -/* { dg-output "Bar::A = 456\n::A = 456\n" } */ +/* { dg-output "Bar::A = 456\r*\n::A = 456\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/trait3.rs b/gcc/testsuite/rust/execute/torture/trait3.rs index accfa9d0a36..6fe92ef70f9 100644 --- a/gcc/testsuite/rust/execute/torture/trait3.rs +++ b/gcc/testsuite/rust/execute/torture/trait3.rs @@ -1,4 +1,4 @@ -/* { dg-output "123, 777" } */ +/* { dg-output "123, 777\r*" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/trait4.rs b/gcc/testsuite/rust/execute/torture/trait4.rs index 8c0d257cd7e..3b2d000780a 100644 --- a/gcc/testsuite/rust/execute/torture/trait4.rs +++ b/gcc/testsuite/rust/execute/torture/trait4.rs @@ -1,4 +1,4 @@ -/* { dg-output "123\n" }*/ +/* { dg-output "123\r*\n" }*/ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/trait5.rs b/gcc/testsuite/rust/execute/torture/trait5.rs index 49f11a6085a..f9c0dfdae74 100644 --- a/gcc/testsuite/rust/execute/torture/trait5.rs +++ b/gcc/testsuite/rust/execute/torture/trait5.rs @@ -1,4 +1,4 @@ -/* { dg-output "123\n123\n" } */ +/* { dg-output "123\r*\n123\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/trait6.rs b/gcc/testsuite/rust/execute/torture/trait6.rs index c83d6666c87..74363c2ddac 100644 --- a/gcc/testsuite/rust/execute/torture/trait6.rs +++ b/gcc/testsuite/rust/execute/torture/trait6.rs @@ -1,4 +1,4 @@ -/* { dg-output "123\n" } */ +/* { dg-output "123\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/trait7.rs b/gcc/testsuite/rust/execute/torture/trait7.rs index 064f88d5de9..fc1bbe87170 100644 --- a/gcc/testsuite/rust/execute/torture/trait7.rs +++ b/gcc/testsuite/rust/execute/torture/trait7.rs @@ -1,4 +1,4 @@ -/* { dg-output "123\n" } */ +/* { dg-output "123\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/trait8.rs b/gcc/testsuite/rust/execute/torture/trait8.rs index 14392ff0cca..c26737f58e6 100644 --- a/gcc/testsuite/rust/execute/torture/trait8.rs +++ b/gcc/testsuite/rust/execute/torture/trait8.rs @@ -1,4 +1,4 @@ -/* { dg-output "123\n" } */ +/* { dg-output "123\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/execute/torture/trait9.rs b/gcc/testsuite/rust/execute/torture/trait9.rs index c0e6d36f183..738d1935291 100644 --- a/gcc/testsuite/rust/execute/torture/trait9.rs +++ b/gcc/testsuite/rust/execute/torture/trait9.rs @@ -1,4 +1,4 @@ -/* { dg-output "3\n" } */ +/* { dg-output "3\r*\n" } */ extern "C" { fn printf(s: *const i8, ...); } From patchwork Wed Apr 5 14:02: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: 79629 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp340110vqo; Wed, 5 Apr 2023 07:15:00 -0700 (PDT) X-Google-Smtp-Source: AKy350aF9eysH2FVlAF+toTiHFjl+j6dMRY8aiK/Bl3sjYmpC6jIoJNj3Nn9xzrJKeunL8uHmbHY X-Received: by 2002:a17:907:9482:b0:947:d3d0:ae1c with SMTP id dm2-20020a170907948200b00947d3d0ae1cmr4219873ejc.0.1680704013137; Wed, 05 Apr 2023 07:13:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704013; cv=none; d=google.com; s=arc-20160816; b=Q2/3o5d+FNUWEP3pPUWlpquahftbmjp0N5+N7YQIPFLCeg7JO/mif8d+O37V93mMwK ckqVCORo0xTw21YTqDN7X8A6qTibcBIjIlmvbzz8AaTcuq7RnMbrVLajHS5OkJCHkbdU EFE9Oor2CXGRbRe6PZK/XjSZ9hMXJj9mK5KGd3Kdrq4PWEZLHRp0Ex1PNrLok57+teKU ui9YKrEsoxsdG2QsH+zK/Z86Wm4/6ugBNUf0UJXDFZIvkFpOymYtOwXxWbEn0mZbgiLL 4ZaTR9a52WKUpXdfyHuk+OgAxRS/HzaT21wgzhvdio/QFICLpUkl0LCtFuSM7kZKV/6U XI7A== 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=Pddnt64uhDd2xOJ//V8eWFN8+JETMcDquFpibYe22ts=; b=RF5/ivN2g6jjhNdYosq/75EUdJr5DnmoXrSsVFgvUArsf7SUCkyS3gwU6iP0dYasEO DM60St6pLMmi8EzQflPsdTqGjzO6u7ohYWNE4hvRg3vhGdcjUqFhY7I21LFcGeBwitQD zcXuvgsPGCz7cnEU4KTV4fQpINnkmsNHq1FmJMRnXpaeQJtSMv9AYNp7dRzoPvKlJK+L MuLKep+hWw9vzE2sjsbHF6LZ5qKxpoO9fvjGay8kiyO7Z/FQ1dMU87jvRvD4vgjprfRR chIA6JstabHXikrl7rVuYg3beAu3hKzfKZc8DkhnfC2SFf3M3NNaZ6XHUzh++3/RVrxU GeJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=EhIKJikH; 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 l9-20020a1709066b8900b009217e23a19esi806703ejr.599.2023.04.05.07.13.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:13:33 -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=EhIKJikH; 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 A2C1E3948A53 for ; Wed, 5 Apr 2023 14:08:06 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id 76C0D38555BB for ; Wed, 5 Apr 2023 14:05:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 76C0D38555BB 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-x32c.google.com with SMTP id j18-20020a05600c1c1200b003ee5157346cso23815218wms.1 for ; Wed, 05 Apr 2023 07:05:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703537; 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=Pddnt64uhDd2xOJ//V8eWFN8+JETMcDquFpibYe22ts=; b=EhIKJikH1LA3gPKJ0ah/VzY1VucyZcHKNAhpU57j2wOfCSISmxwIfnQDm1wdVCerDd aUFcJkKUMj2DpIeMBCqqlBDuY3qgYLeYYrw78+ItZBX0S7npH/3khwi/zrdCW/IRw9jQ 8Cmen8/eZCsAnkvYhsuRbJvX1FjW9lClx/bFjiSaRuzL2MDuaIZucXhZtJEUoAQn2w9K 8zqt1Jc9EXlAiHq8tb2/z9pzsDletXLDXhNJ/OriiAW1J2Jv99D5rlKQaEIUPsR03q9T rO+kVnkD6pmkn5yObX0dCaFlz69sdiF+ubW4Avm04vjRAYbXY3r3Hat+tWN/1nzH5AEj SWmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703537; 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=Pddnt64uhDd2xOJ//V8eWFN8+JETMcDquFpibYe22ts=; b=68IaYYGybNb7I0+oV1aCydVXOwA0wplqoK8UUR00BqSnmMlfj2powxyrLCC+uzzEuM 3SmOBdApPvecgACocgLRwpQ+3HzEiOwXWQ4kuLaaDxnyvMM4ReCxaP/Tr4NlKBKLmD2Z FewrFF8yYV7iJ3gOkbNj56K1F+Af0BBFjWXPKf4pFgRG67RZfkm7kj5d/aRKUKn26lbB QcqWOUxWIEmzdPToArofD6/1wmWsInGGMYjiWXgzIvLYWivgtiL24MUqUimiCcKMYeW+ PPnzKhxGh5tQJwdqU1H9TENe7232fXhZm/Y9EU1Gd4rzW8B+ZOp5IQis2Jl7jV+hYObP 2V8w== X-Gm-Message-State: AAQBX9drjM58s2anj73/fdqcWMexkJZcT19OELWEcnUx2TYBDsX7s+9J XJhIu8rtLhKoz/IgpGrjkFX64pa6wEx+C7oUBQ== X-Received: by 2002:a05:600c:221a:b0:3ee:6cdf:c357 with SMTP id z26-20020a05600c221a00b003ee6cdfc357mr4814630wml.20.1680703536961; Wed, 05 Apr 2023 07:05:36 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:36 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [committed 13/88] gccrs: Support GroupedPattern during name resolution Date: Wed, 5 Apr 2023 16:02:57 +0200 Message-Id: <20230405140411.3016563-14-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?1762345891157987276?= X-GMAIL-MSGID: =?utf-8?q?1762345891157987276?= From: Owen Avery gcc/rust/ChangeLog: * resolve/rust-ast-resolve-pattern.h: Support GroupedPattern properly. Signed-off-by: Owen Avery --- gcc/rust/resolve/rust-ast-resolve-pattern.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gcc/rust/resolve/rust-ast-resolve-pattern.h b/gcc/rust/resolve/rust-ast-resolve-pattern.h index 5f2b7293cf2..3e74f0a4cc6 100644 --- a/gcc/rust/resolve/rust-ast-resolve-pattern.h +++ b/gcc/rust/resolve/rust-ast-resolve-pattern.h @@ -77,6 +77,11 @@ public: pattern.get_node_id (), pattern.get_locus (), type); } + void visit (AST::GroupedPattern &pattern) override + { + pattern.get_pattern_in_parens ()->accept_vis (*this); + } + // cases in a match expression void visit (AST::PathInExpression &pattern) override; From patchwork Wed Apr 5 14:02: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: 79628 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp339917vqo; Wed, 5 Apr 2023 07:14:47 -0700 (PDT) X-Google-Smtp-Source: AKy350YwIrcW6e0D0IwmntsjQ6L6QG4E5xRjlC1xH0y66VitRu7D+NmdjzsA301A98Wkoe4xyDJB X-Received: by 2002:a17:906:4a8b:b0:944:43e:7983 with SMTP id x11-20020a1709064a8b00b00944043e7983mr3267034eju.67.1680704087330; Wed, 05 Apr 2023 07:14:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704087; cv=none; d=google.com; s=arc-20160816; b=X274bUS2G2rCwlb3U5ogv+a3YVpzFsBdlJcG2hT5VE2t4NnoIMhjSOUPQDteg/KGz5 cFVjWHz1d9I/fXdIPPF6OgBY0vAmssvSVMZC3MlLmXZa+Az8iG3XPmK+Uf7RA3JWyCkX B0DE9vBzaoEu2/0xP5ADd0qZAQp1Ei4mmBDMUytb3/DXJPUzYNtf2GItzPylL4J7e7E4 KVl1EgsklHvC+57H2aNrY0v/ZfgSXKG+9bWMvCFq8MuxcQkANcpSYbTA01JXeJSI45Pb gYYn41ATNOIT3ffOBRgzQBWbolqdaNQCjVQ6AAQFAiXMj1TpN3Ided9q07DuKx2g8tkO 2GTQ== 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=ijCAWty14IN6VF2vyYT9cikgJKQ0mlLXSf1w3+dmMVc=; b=wo5vmOL0cfJSrAJw59CSoR8HEelMzHSSeeDfnR6/wWzZ2yQJL4Um0eylegUURVHN9s wNhTaeQKyu8tQn7EmRsKul3CZtj2RNEDO2gEppd+Id0jl7F47ZEeinDJ0LpmoNHgMOb3 7GbG5iiYrNwQ32omQqSa9AZjJXXWCzzJ0vjZuQ5PtAF/49cViaze30ulw+HjVtxIRYpZ xAJgzRdEIIMwSP7K+kTwXSpatUZbY9Gn490L8qdA/UdNRH2TiVaqfHWLCfeLmaLDvgGR 3RDK1Y89pnid2SVbZwGDr5RblsIFgbiutCTa1aVPNvo9yl15QavZ52KXyrJ4PCscvbr2 W4vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=O1w4Hby7; 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 p11-20020a170906b20b00b0093defbd6296si1365666ejz.1053.2023.04.05.07.14.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:14:47 -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=O1w4Hby7; 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 114A7396E022 for ; Wed, 5 Apr 2023 14:08:28 +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 DECBF38555BF for ; Wed, 5 Apr 2023 14:05:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DECBF38555BF 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 d11-20020a05600c3acb00b003ef6e6754c5so18371167wms.5 for ; Wed, 05 Apr 2023 07:05:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703537; 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=ijCAWty14IN6VF2vyYT9cikgJKQ0mlLXSf1w3+dmMVc=; b=O1w4Hby7lhrGO8DLS+F92oigpwfTxD4zRZ/Kf/WapjV81TMYP+iQhtScS9uDdP0Z6k 0Mykd3f9wWYYYLma9e1rtayT/2/h03fxW+R3Zr10WOsNwxWG1OuaLnY540+wJn7fgWPR nMjTgoenthsTmm+zaCR9nI4bnBj1GEaP8eH70vmIvllkm5axyXD1XT7Djxgoj5y3VcyI 8SFPfy/xMqRYjAiSFjE4Es4M8tfRX/uon1FRVs7dYCIT4lOoCLaBG5+1mlM4jSQR6Wp3 kB0LYNmQ2EtJcjCSIL9YTVFaf0qmuBNutD+Tmd2cMiWAWnX+QsEBhfql9lTK/nqDI7x4 EbxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703537; 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=ijCAWty14IN6VF2vyYT9cikgJKQ0mlLXSf1w3+dmMVc=; b=Rvwu+ZaeP1cWfSaspcVhNh4p3NtBQ2c0RQFShlBAc4XsC9MFXLYjEQSCgsSLTCKgBL tIayN1kHJ24jDLfDd+a5xjggVy4NlhbZAcbNTeR5elXWAMVe23o2HsPiHtD0JFrVgtGV milxeFfwxkkCiDW2YPeJQ+rlDDDipBL/8bK3AOKqXMVCmnpyxiyCrxewqWZOmP+oSadK 9vo1b/APYHQcRSM7pgK0euYZCx6AQ9pYA6cYTGlm5fvcFaVaCI+OefaQ0DE7GFR5XSh+ Du7cm1m3eGVUqzxY88KGhkiGFmH5RGb0R6lFYmU5BkcZX56ca5Xc7W7dcOK7sADdKnAE Wz4A== X-Gm-Message-State: AAQBX9eljqZ4a88v78Z8VyRQfCBj7kaFXyYsPf2abAPggs8y4XFSzPXn heAv1tlpxoaDXl1Y5+Ltvujo9qui7NgB8bctWA== X-Received: by 2002:a7b:c301:0:b0:3ef:5dd6:2f94 with SMTP id k1-20020a7bc301000000b003ef5dd62f94mr4738550wmj.31.1680703537384; Wed, 05 Apr 2023 07:05:37 -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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:37 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Lyra Subject: [committed 14/88] gccrs: Do not crash on empty macros expand. Fixes #1712 Date: Wed, 5 Apr 2023 16:02:58 +0200 Message-Id: <20230405140411.3016563-15-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.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, 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?1762345969074373634?= X-GMAIL-MSGID: =?utf-8?q?1762345969074373634?= From: Lyra This commit fixes a compiler crash when expanding an empty macro into an existing AST. gcc/rust/ChangeLog: * expand/rust-macro-expand.cc (transcribe_expression): Fix ICE when expanding empty macros. gcc/testsuite/ChangeLog: * rust/compile/macro45.rs: New test. Signed-off-by: Lyra Karenai --- gcc/rust/expand/rust-macro-expand.cc | 2 ++ gcc/testsuite/rust/compile/macro45.rs | 7 +++++++ 2 files changed, 9 insertions(+) create mode 100644 gcc/testsuite/rust/compile/macro45.rs diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc index 9c3523e0515..bf914ee19e3 100644 --- a/gcc/rust/expand/rust-macro-expand.cc +++ b/gcc/rust/expand/rust-macro-expand.cc @@ -839,6 +839,8 @@ static AST::Fragment transcribe_expression (Parser &parser) { auto expr = parser.parse_expr (); + if (expr == nullptr) + return AST::Fragment::create_error (); return AST::Fragment::complete ({std::move (expr)}); } diff --git a/gcc/testsuite/rust/compile/macro45.rs b/gcc/testsuite/rust/compile/macro45.rs new file mode 100644 index 00000000000..52dbcbb0016 --- /dev/null +++ b/gcc/testsuite/rust/compile/macro45.rs @@ -0,0 +1,7 @@ +macro_rules! empty { + () => {}; // { dg-error "found unexpected token '\}' in null denotation" } +} + +fn main() { + let a = empty!(); +} From patchwork Wed Apr 5 14:02: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: 79631 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp341656vqo; Wed, 5 Apr 2023 07:16:41 -0700 (PDT) X-Google-Smtp-Source: AKy350ZYQOaMxuPs+EuIg0r0KSxy0vVEkoOW4OveL+F7EYZEkh9HnAI9W3ttJ7AVORrS0JtQEUsq X-Received: by 2002:aa7:ce0c:0:b0:4ac:ce82:9825 with SMTP id d12-20020aa7ce0c000000b004acce829825mr2157932edv.16.1680704201285; Wed, 05 Apr 2023 07:16:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704201; cv=none; d=google.com; s=arc-20160816; b=ZrWwxq7Mm5sSiV8ZgmSCg6CPJNh/JB7jVtfrMN5osyPBSYfRJ9MKQuTkPUu01xbgRm wTnX7gVoYE6HCMn0MKorAyB2x6wjVQrCw/GEIoN7QuiE9ZtX3QX4Tp9n9IQ0WbjKl4Zi vHg8cpdt+RcNM5oFnswhvU0OI7f/yK4R4AkUyU4ZHvzqin+7/TJPlXvQ+i2oLIjAYGHV /26a6AGIlU1SGZG4tSDyvhhftE1XAPhHs/Jvwn3doV+c3/p8H7tLyvWoOgpTq0WYUwQf GUbZhxq/1QZJnzLoeD6K5kDMsC49GH9Qxk26DPIxI4Jn/2T/+PFeao2mCay00KidN8WF iDqg== 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=3+JwrA5Px+x7StU2k1VGnS5w8ORk8tczXa/XIvXs5eQ=; b=U+dIkafWpDw8gNvvtgMSQ9mLNrTX3uomBxnPYJvP0BRoh7sRv7NA8EC8gbjptybokr dfrQ6qxGKwsN6s6gHlpKIH7JNvo3eEX87Od1xbnJ/GoIQK8BkbQaey4BcPYi4VGnFRpm nobcst1kqCZ8dDLWm6GxCWm+CJRuoosQv3zAg/ki/iqFcl4ocLfkmxzPqk+sGuyTXe9l SwkHE0obaACGIWv4+Xv/IVannmDTIrgmT3T7CO7qTz+7OlhEGkrXg1spkevhnQxdNIqx 42UZMR9oOzZ0VUVT946Xt7l5kZWuQbq6UQaYGBICtniO4+u1RwWUw4ri/9IH1iz5wiwv meog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=VJlnlRGG; 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 w18-20020aa7d292000000b004fcf925a8acsi3082970edq.251.2023.04.05.07.16.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:16:41 -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=VJlnlRGG; 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 146903882AEF for ; Wed, 5 Apr 2023 14:09:05 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id ED175385701E for ; Wed, 5 Apr 2023 14:05:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ED175385701E 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-x32c.google.com with SMTP id i5-20020a05600c354500b003edd24054e0so23809586wmq.4 for ; Wed, 05 Apr 2023 07:05:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703538; 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=3+JwrA5Px+x7StU2k1VGnS5w8ORk8tczXa/XIvXs5eQ=; b=VJlnlRGGLA45jR7Rjr0baZGU8/Xl/smn9GVpWv1ey6Ptxd605RagiQ7kXrKyrJqbdd woVrOUu89HqTtBd0GgTbmxSmtcx6gbltPyWijzs3ibIZlFcXmsU2XSoyBj82n1dOy9wW 9rP2IztMBi2gYAcB3BrYYxDWEL5G1hhUwTN4xXhJ0HfMUF9r3ZegOqHxyk3M1xGbGno0 Ff0rZd3WLnlG+yJns4xLlD9IexGP7NX58cCUxcnUjtfRnFUuvTZmDqIBCLYG5lKDp1T3 CoxAa8MemfwLp4ICXAyVTpGS8aACYSkdRxmQbPgcJYruuFNe/lOBZ1mMU9HGPzh6Y+yZ mAbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703538; 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=3+JwrA5Px+x7StU2k1VGnS5w8ORk8tczXa/XIvXs5eQ=; b=X0G4zn+fn/oUdtIFSUCRo09afP1n7HQH/fv3V6ZoeKdhVnBTnn+QezoLRJbw9n6knq MEeRkoa6vfMoXVYQHOXRDfglFxiVb3QhpM6VxyVz941qROOMoS8mS9wLuHj5ZHvmwcom wjDnvxD/VKQZOWt2NjQPKhSuImT4Sqyztj9RlCYS6TJzrq/AlHGAuFBkuA+tnN0lnO8f jo6Tvc97wTuJvQdmzHRBeTHQa43bpZr5gBnjqYJf6FFujRL7vbuKe50CS+gf04ij9bBm y5wX7jldF/++DTIn96gT9Y62uMtBvU4fJtl6JJ6h7R7cGnKiRFjmFd0ZGB22kNXe1zC9 WAww== X-Gm-Message-State: AAQBX9dWRgkiL2v4xTEYVBMv0ioYKYjtBfJxoPdrcVp6DYJILraBcQwe 7kL0U9qDMTwrZI7E/soD6OjmkoQmzB90O3/LBA== X-Received: by 2002:a1c:6a1a:0:b0:3f0:41b3:9256 with SMTP id f26-20020a1c6a1a000000b003f041b39256mr4889157wmc.10.1680703538300; Wed, 05 Apr 2023 07:05:38 -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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:38 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [committed 15/88] gccrs: Add HIR lowering for GroupedPattern Date: Wed, 5 Apr 2023 16:02:59 +0200 Message-Id: <20230405140411.3016563-16-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.6 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?1762346088538055541?= X-GMAIL-MSGID: =?utf-8?q?1762346088538055541?= From: Owen Avery gcc/rust/ChangeLog: * hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Add proper visitor. * hir/rust-ast-lower-pattern.h: Declare it. Signed-off-by: Owen Avery --- gcc/rust/hir/rust-ast-lower-pattern.cc | 16 ++++++++++++++++ gcc/rust/hir/rust-ast-lower-pattern.h | 1 + 2 files changed, 17 insertions(+) diff --git a/gcc/rust/hir/rust-ast-lower-pattern.cc b/gcc/rust/hir/rust-ast-lower-pattern.cc index 30a188286c8..8ee3a979a33 100644 --- a/gcc/rust/hir/rust-ast-lower-pattern.cc +++ b/gcc/rust/hir/rust-ast-lower-pattern.cc @@ -243,5 +243,21 @@ ASTLoweringPattern::visit (AST::RangePattern &pattern) std::move (upper_bound), pattern.get_locus ()); } +void +ASTLoweringPattern::visit (AST::GroupedPattern &pattern) +{ + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, pattern.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + HIR::Pattern *inner + = ASTLoweringPattern::translate (pattern.get_pattern_in_parens ().get ()); + + translated + = new HIR::GroupedPattern (mapping, std::unique_ptr (inner), + pattern.get_locus ()); +} + } // namespace HIR } // namespace Rust diff --git a/gcc/rust/hir/rust-ast-lower-pattern.h b/gcc/rust/hir/rust-ast-lower-pattern.h index 8b191d56868..0075e27e9c0 100644 --- a/gcc/rust/hir/rust-ast-lower-pattern.h +++ b/gcc/rust/hir/rust-ast-lower-pattern.h @@ -39,6 +39,7 @@ public: void visit (AST::TuplePattern &pattern) override; void visit (AST::LiteralPattern &pattern) override; void visit (AST::RangePattern &pattern) override; + void visit (AST::GroupedPattern &pattern) override; private: ASTLoweringPattern (); From patchwork Wed Apr 5 14:03: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: 79641 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp343588vqo; Wed, 5 Apr 2023 07:19:14 -0700 (PDT) X-Google-Smtp-Source: AKy350YpNq0o6JNzFWmjtbr25+84nB/5XxIWqqqJat7FKbJby5EVsO14WuRbPZ616uydhslk+S/K X-Received: by 2002:a17:907:5c7:b0:928:796d:71e8 with SMTP id wg7-20020a17090705c700b00928796d71e8mr3880289ejb.3.1680704354424; Wed, 05 Apr 2023 07:19:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704354; cv=none; d=google.com; s=arc-20160816; b=XwHckC9SRykIZMR2BZCtX0jVOr8TS9CtHxRdO1eWKy6aicRjH5FbgzusefGcRn+Wzr bgl1zCSwWLZnSuLDmyO0ZYy3ftlE/xTSzBhMuX33rQKuNk6L5HkCYGTm0R8Smw6nHqgl lsj/sJtB7GAnGpGjwOs7vGJnKXqCAx94GQshAFE2Yff3Ek2iYl2ERnGZdqsTE/9SsI8C Lb/DzptngirAajBukhkis+DznO/aA0uyApDfrH/QjC+LThg+ArchJ+dK9mpQl6AomD1t oqwIHSk/N++XTCuHyI7O04okyCpApSiVdS/Kwd1BnRlYbGCeNnA4kU/dFltqAN69Sedk s+5A== 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=sMkoscIEeOuQXRmkTvqa/38owLhMvajHs7aIBsVJ9QA=; b=Fny0TPs5rQGxKW2OHfeC3+LyLOnVO5Z4SrWtHpsIUS+HgQHXov2CdQmdNYpvkpfu+Q xaOb2/zu2duQZRYtw66IdgCefmana0p4yHsMwnr4q5Yco2gUp4gXcejLA0elxq1V4uMO I9FF9ui0ZVfBp/QND0XErSQm6U7OFG+7P7KaxRi0T4wPK5p/I3A2CFcPpnOPZiOgH+EJ ZU8xy4muRSyJm/F7lTBUvjILlSahZmC04SQdiZorIA1Av1Cx4UKJ1oQ4N2+Qx6NqcU4h EMPAq03w4DTNb1ERFUbZbgBwzQ3N5SJTKchTcXCGqxBw6j9TWykgE027foAeRB+CcMoL 5LUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=fw41Lej8; 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 a15-20020a1709063a4f00b00932f1463036si2105410ejf.283.2023.04.05.07.19.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:19:14 -0700 (PDT) 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=fw41Lej8; 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 D8A373AA941E for ; Wed, 5 Apr 2023 14:09:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id 726C93856941 for ; Wed, 5 Apr 2023 14:05:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 726C93856941 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-x32b.google.com with SMTP id l15-20020a05600c4f0f00b003ef6d684102so18505961wmq.3 for ; Wed, 05 Apr 2023 07:05:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703539; 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=sMkoscIEeOuQXRmkTvqa/38owLhMvajHs7aIBsVJ9QA=; b=fw41Lej8h732HYZ6AYZecvoOAXMVfANQao6UK/BScFO6nNkamo0p1oUuKvrKb+PTig qEb0PfcZBo3Wh5F4dwF+1bSq7XDm2MEY2X0CqUFM8ewcUvVq5llKAfFk6x4+zFnGfbct bt08fmwl4R+vRgA8fFbUQPCsjHQnLiBUj8V+78HvUnT638keBYrON7XdDMp8Ab4lEQ0a 3aXOOYHbFlOYuhLBZIIlW9J0LyGJ6eJXtOLPca+/5nPrXoTpmMrWInxHWlUY+xOHtxOJ 06hETBCFUx1MhnFX8zJiVfS5ugApqJ8jMoiIl2Rr4jM3Xqeh50GAuZXrhSs4VeD091o3 i7dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703539; 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=sMkoscIEeOuQXRmkTvqa/38owLhMvajHs7aIBsVJ9QA=; b=Ltq5BsQlYxK7sd5QStb+bRP7UVbgEH7W9UHpoF2XXs1P5pJJbfTKINtu9lcPFdJB1e mUu67qYPe38X/+931j/bh4OyJzFfM4CACb2ncihgT5i+Q1OJAGflgPhGZQEDRHf3Frs2 /qpGDm1/9PiO48f+P0VarUbFhZvGK6y4v3f1QtBQIy5XoH57rqljm/hOUbxiAGj+kBIz Oh82AzYOqGCfD8S3MKHD6dIuokRBsL+oWyCOrRreAzlZPXEvfWsdm0TK8Zp4YADXXOLW eIDRhc6NUj5rZXFdqO6ydBjcmkR4SgLD3cruZ1nCzIFAsjFeCN0v3qg0qXdwLUoW3QvF 6t7A== X-Gm-Message-State: AAQBX9c8A586FgL6hbMxDabAcp8IEm5oJjbu0xBxXbKMIFZAyiRDODjX L7G7uXzrtU8hIxwYAx2qI6fOf4omN3n+s3eh9g== X-Received: by 2002:a05:600c:2202:b0:3eb:f59f:6daf with SMTP id z2-20020a05600c220200b003ebf59f6dafmr4786204wml.34.1680703538961; Wed, 05 Apr 2023 07:05:38 -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.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:38 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [committed 16/88] gccrs: Add get_item method for HIR::GroupedPattern Date: Wed, 5 Apr 2023 16:03:00 +0200 Message-Id: <20230405140411.3016563-17-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?1762346249052411393?= X-GMAIL-MSGID: =?utf-8?q?1762346249052411393?= From: Owen Avery gcc/rust/ChangeLog: * hir/tree/rust-hir-pattern.h: Add get_item method. Signed-off-by: Owen Avery --- gcc/rust/hir/tree/rust-hir-pattern.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gcc/rust/hir/tree/rust-hir-pattern.h b/gcc/rust/hir/tree/rust-hir-pattern.h index 80fa9b791a7..b7a230c526f 100644 --- a/gcc/rust/hir/tree/rust-hir-pattern.h +++ b/gcc/rust/hir/tree/rust-hir-pattern.h @@ -1269,6 +1269,12 @@ public: return PatternType::GROUPED; } + std::unique_ptr &get_item () { return pattern_in_parens; } + const std::unique_ptr &get_item () const + { + return pattern_in_parens; + } + protected: /* Use covariance to implement clone function as returning this object rather * than base */ From patchwork Wed Apr 5 14:03: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: 79632 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp341789vqo; Wed, 5 Apr 2023 07:16:51 -0700 (PDT) X-Google-Smtp-Source: AKy350Za2iGku9t4g82WJoP8j6uBvgZe+Zflj38S7hf0MV4Q6vd1H49CS90HEQ+ATXd6U79JzEG/ X-Received: by 2002:a17:906:3918:b0:947:94fb:3ac6 with SMTP id f24-20020a170906391800b0094794fb3ac6mr3130526eje.33.1680704211810; Wed, 05 Apr 2023 07:16:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704211; cv=none; d=google.com; s=arc-20160816; b=mxICX44CcczxLcGo5+5Daey0Ga1f6OMED1qrusE+KXPzr7jJmgAILm9zHbYuind032 zRE1WcNzkmFHushP+AjLVtyV6mNzZb9w/KtIAdAcfte9ylsbQvmx/b2c6s7IlOR0KJGd JmRLE08BjcrwHHtDDcQ3ReDh3wrTTvGLWDAZTopfsj1IY5dYCkRpOiKUYBZBcbka/Hcu JtFbZd8w0IbPyvA4gChRf0oU/BGOfaFIKHXXFTYQ7wYBkgx6nYvoHF9xcXt+hyexhPS/ JXkjY0DD9NeCIROQ5zGmSCiVJKPaIZzWq9iMP5TLzhAZjDYQ+FA6c3KjOHui7p0UXqGK sn3Q== 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=kER+HgDwmN0dv1nYolUZqZjdHGtscx/yx91ms7Xn40U=; b=082yP4mZXO6RUWt9c/XPhxxmdBapNTfEqmbcOFS35D7kRLbVHaHOSUnsEb0s2qY5Oa H40O82e7aL0IPoQrjnEPGWYSmXZxu++/wG3vqBVOm6EBySQ5PJLsfHDhJDm/kzYbsKkt k08pO57GrH3eqdfMxjXassuKFdHm64NcF5vDAVs/znUtoZUR9ZWg+7X/Haj+TnWWJCHg IiBU+b+HRsMLQgh4uIFZRcFG1Vw4oPryGDk+XnhuczCfz6vRVeAPzGZzLzra2aiHaJbZ m82ESuYqW1cTKlEpG0eitPfWfHwls4j45yAFU4NPRsN8cUm/TRDAY1JTRT4J+L9dMuJl s1Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=aB0KO4td; 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 u7-20020a17090626c700b009316b784857si1601945ejc.352.2023.04.05.07.16.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:16:51 -0700 (PDT) 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=aB0KO4td; 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 B55D0396E431 for ; Wed, 5 Apr 2023 14:09:07 +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 467F8385416E for ; Wed, 5 Apr 2023 14:05:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 467F8385416E 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 t4so31097308wra.7 for ; Wed, 05 Apr 2023 07:05:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703539; 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=kER+HgDwmN0dv1nYolUZqZjdHGtscx/yx91ms7Xn40U=; b=aB0KO4tdHyxz2bmWdnCyNsJJQDPORF4HSY7ucDKmmIZ5W0LhJmbmJUogEJKVM9lzd/ cG/mPJ2oCR0HST6NJmGOtsn1p6T6DM9kR2q9B8ZzAheKuUqUO3A3C1gGNQj5B5esP9v5 5qJPLXswbGt0QKn9phtKkBZLEcNK/2vUP6ABfS4jnCiUYJxADnlhdyNrYi0Z6QJ0mIhH CkYoo8asaWTTBcsxA8P/1k1JYGmVrzYoW0CYDooDSrXhbcWNijyxs8smFK05BsTPAm9i lk7wyGEoY+MIFIbdFUr9loP01S3JdttnlVizDofm/rkCdfjikB5zI0eveU/7GUTBMX1p 1AuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703539; 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=kER+HgDwmN0dv1nYolUZqZjdHGtscx/yx91ms7Xn40U=; b=kfLlhsknG2PPbsFKbfDrTaWhMnAAg13/BVRmvcWgO94xiSRjUGfqVzywF5VBfrZFlr 0wBM4d0eEPt7eUOBxN7nDtc8iDpvKO06+/9Wiloexl4OLt51DaHmcR0PnTQVJ0iFKO0f 9IiwfkIg8935JULGsqvoGjtWsKr9iuu9/fbHVn42ZPgZ4/0l+Lx5m6FotsW5A/SWWYr4 Ky8ifrjbAA1xkUBJpfCb1kC02BKtvLk63Z+r+WJ12jWkiw3YzLeGTAxD8mg+uaZ845VF 9huRXqsxPhQX9zTh7EuZz826raRNaNNR6dnYOTriLQ7vFVLEBJAXq/oI371T3CkFnUPr DzgQ== X-Gm-Message-State: AAQBX9ceKak5HExWrYDZYE950nakV3ZWnXs7fBLYcZ7TNSAtvP2kzLr+ +j6i3FPgGsZcEjbx/j8R/TK24rQucRgRl9FzYw== X-Received: by 2002:adf:f691:0:b0:2d6:6af:4891 with SMTP id v17-20020adff691000000b002d606af4891mr4376614wrp.3.1680703539638; Wed, 05 Apr 2023 07:05:39 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:39 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [committed 17/88] gccrs: Add type resolution for grouped patterns Date: Wed, 5 Apr 2023 16:03:01 +0200 Message-Id: <20230405140411.3016563-18-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.6 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?1762346099725454551?= X-GMAIL-MSGID: =?utf-8?q?1762346099725454551?= From: Owen Avery gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Add proper visitor. Signed-off-by: Owen Avery --- gcc/rust/typecheck/rust-hir-type-check-pattern.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc index b017a851b5d..393f4158003 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc @@ -387,10 +387,12 @@ TypeCheckPattern::visit (HIR::IdentifierPattern &) } void -TypeCheckPattern::visit (HIR::GroupedPattern &) +TypeCheckPattern::visit (HIR::GroupedPattern &pattern) { - // TODO - gcc_unreachable (); + TyTy::BaseType *inner_ty + = TypeCheckPattern::Resolve (pattern.get_item ().get (), parent); + infered = inner_ty->clone (); + infered->set_ref (pattern.get_pattern_mappings ().get_hirid ()); } void From patchwork Wed Apr 5 14:03: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: 79635 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp342535vqo; Wed, 5 Apr 2023 07:17:45 -0700 (PDT) X-Google-Smtp-Source: AKy350Z+o3pRpkwqecHFcKbVH+xq1jrGQPaXQY3e/NFIyNw5yy1CEaOF5wHb2v2fvnROut5kdEGE X-Received: by 2002:a17:907:8dc6:b0:949:7c05:71ab with SMTP id tg6-20020a1709078dc600b009497c0571abmr1495445ejc.66.1680704265621; Wed, 05 Apr 2023 07:17:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704265; cv=none; d=google.com; s=arc-20160816; b=qUW4bX7f/ZlUZA3aSeyFyWAyZPN7hDkgKB4L/cDizdgn5pTUQ0pN6ADFzq9IEDe83j WOrRiznU54ZpLnm8kRRlOI00bpn/9+bmymIiYdnWUaHJmKWPqmEl5fPwZF7zzvXMWlR9 UoRS8v/jxjNSisFAaTFyPSizlJSLiASWakix5+G3AOaK8Wul60vGSEIkdFXRWbzFvTor CWW+XrC4XcFbfmk4996RqB4IxRrCd3fg/sIVlMnHgG1MeLzVavyecQ4EzEQ2wPN1Zqkc T08eydRe1N4vuW8JgHEEVL0e4L/2lLIl5KvVa7rGI26i/1x0XZbk9IZ7kWzakLVkbUUp EJKw== 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=59GujSJupxSzHGb9w1DRSZMjtWbfaGnwc2ZfcVYjN9c=; b=mRsCw3gigX0mDz0YZmVyQcESNHUtcP8Q4eAwLAMQ7sfWXu/SMvNYq8WZhC8vjxYDzD Y7SiPQlPtNm9Om6OcZL7Hi/5QgCwn0sY77GYJX8u0K0CnlffMcI8ChpN6eGe0AWv9vIw 6brhZMd2HHMUtyfAOQNCOr7tbX8wP61zqZsKUVgjAh1aTmqsbr2+70EHIoAUFQwn6AXW VrL34zlBIJEjzSXntIO9RG9crUIQQFVfwx5UvvO7pndCKvuHf1RMxWhdfFd0glVkAMJQ lDdPOuupzHyxj54ii/KUNKlB5bJaKJWa+jB7tbmNq+4C6e75bKy7FPJ0Ik+exDmiXzsj d+gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=UoVAIBS1; 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 l10-20020aa7c30a000000b005042f928970si520552edq.650.2023.04.05.07.17.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:17:45 -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=UoVAIBS1; 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 B57EE382CFD1 for ; Wed, 5 Apr 2023 14:09:26 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id A2DAD385417C for ; Wed, 5 Apr 2023 14:05:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A2DAD385417C 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-x42d.google.com with SMTP id j24so36391781wrd.0 for ; Wed, 05 Apr 2023 07:05:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703540; 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=59GujSJupxSzHGb9w1DRSZMjtWbfaGnwc2ZfcVYjN9c=; b=UoVAIBS1HWG1QRvekQ05EVPvn3JJNmV+uNgI5CT48TttfqS584q4wHqjT1azxtliFu 73y9muO7vu8f9ZDPHOrse0c/zIiLlSwb/WWWT9KTNTFKHf81SE+HLU1jZl7VV7rDlL0c 0bOhPZwwmYQFtSP6Eob8t+G7yXfGPVdy4aXXPhZKqOfp46q7jxExJ77hVBAk9wRGbBaS rcR3ZnAn+aIx4ovv1DiyhTIVbxDVYFm82tiYLTUjzLwKFFf2fmW8S2Tnzit7NYKEFe26 SiNpNoniSVH+cfqCa4bOZrkrLHXHD8l4pZ0kBRJWlbh9o4596rVHJjW5fYSxuS0P4gr9 nI9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703540; 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=59GujSJupxSzHGb9w1DRSZMjtWbfaGnwc2ZfcVYjN9c=; b=W2mZy3/YpHRcisxZcXiIOrSL+C+/qpLSJY032DYSf61hlB4oT6QzTdZBudfsUuSz4N FmemRSHmBZVCDOkWFAoEoYNLyAZT8q6F7mG39VGIQ3h/p+d85yPc4zPNsyrU/kZ+36IT Ug/24JNB26zLsHz4W97pmAeyyEML58Fe31FrS1/cmknbFvxk8h5lNLkxdaWpQylwdzQ9 aCZK9NNz5QB7WhODssoU3EAyYTShU6CTJgXHSDnKx6srknXc7xF/WZqq1UC+hEcdoxz2 YAW8KRYswSNLRiFLdYZkoj7U/oMIoXHoQS/cqjq8lLYWyY3KYof2dgeEQvxbyKQwSD4M IvGA== X-Gm-Message-State: AAQBX9eQZMwiK2YgCIZkwtQgLvspTNAZHAfzCBre5y9+EAdIP/6Ltmay AgP/JD+DYugjQSc1SYxWqdjsTVXwa/uLPYc8qQ== X-Received: by 2002:adf:df8b:0:b0:2c9:d91b:a6ff with SMTP id z11-20020adfdf8b000000b002c9d91ba6ffmr4111666wrl.21.1680703540249; Wed, 05 Apr 2023 07:05:40 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:39 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [committed 18/88] gccrs: Added missing GroupedPattern visitors for code generation Date: Wed, 5 Apr 2023 16:03:02 +0200 Message-Id: <20230405140411.3016563-19-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.6 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?1762346155870651534?= X-GMAIL-MSGID: =?utf-8?q?1762346155870651534?= From: Owen Avery gcc/rust/ChangeLog: * backend/rust-compile-pattern.cc (CompilePatternCaseLabelExpr::visit): Add proper visitor. (CompilePatternBindings::visit): Likewise. * backend/rust-compile-pattern.h: Declare them. Signed-off-by: Owen Avery --- gcc/rust/backend/rust-compile-pattern.cc | 12 ++++++++++++ gcc/rust/backend/rust-compile-pattern.h | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/gcc/rust/backend/rust-compile-pattern.cc b/gcc/rust/backend/rust-compile-pattern.cc index fc70d4ba58d..9218b815dd8 100644 --- a/gcc/rust/backend/rust-compile-pattern.cc +++ b/gcc/rust/backend/rust-compile-pattern.cc @@ -161,6 +161,12 @@ CompilePatternCaseLabelExpr::visit (HIR::RangePattern &pattern) case_label_expr = build_case_label (lower, upper, associated_case_label); } +void +CompilePatternCaseLabelExpr::visit (HIR::GroupedPattern &pattern) +{ + pattern.get_item ()->accept_vis (*this); +} + // setup the bindings void @@ -329,5 +335,11 @@ CompilePatternBindings::visit (HIR::StructPattern &pattern) } } +void +CompilePatternBindings::visit (HIR::GroupedPattern &pattern) +{ + pattern.get_item ()->accept_vis (*this); +} + } // namespace Compile } // namespace Rust diff --git a/gcc/rust/backend/rust-compile-pattern.h b/gcc/rust/backend/rust-compile-pattern.h index 22812a45405..43334affca7 100644 --- a/gcc/rust/backend/rust-compile-pattern.h +++ b/gcc/rust/backend/rust-compile-pattern.h @@ -38,9 +38,9 @@ public: void visit (HIR::TupleStructPattern &pattern) override; void visit (HIR::WildcardPattern &pattern) override; void visit (HIR::RangePattern &pattern) override; + void visit (HIR::GroupedPattern &pattern) override; // Empty visit for unused Pattern HIR nodes. - void visit (HIR::GroupedPattern &) override {} void visit (HIR::IdentifierPattern &) override {} void visit (HIR::LiteralPattern &) override; void visit (HIR::QualifiedPathInExpression &) override {} @@ -70,9 +70,9 @@ public: void visit (HIR::StructPattern &pattern) override; void visit (HIR::TupleStructPattern &pattern) override; + void visit (HIR::GroupedPattern &) override; // Empty visit for unused Pattern HIR nodes. - void visit (HIR::GroupedPattern &) override {} void visit (HIR::IdentifierPattern &) override {} void visit (HIR::LiteralPattern &) override {} void visit (HIR::PathInExpression &) override {} From patchwork Wed Apr 5 14:03: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: 79658 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp345326vqo; Wed, 5 Apr 2023 07:21:33 -0700 (PDT) X-Google-Smtp-Source: AKy350bzhcgkiHz1xZagqivl46zNWr3PMrle8Ja8h31ggwb/8ElsLF2ljxbO2YyvVCsFr7Fa3AYQ X-Received: by 2002:aa7:d74f:0:b0:4fd:2a29:ceac with SMTP id a15-20020aa7d74f000000b004fd2a29ceacmr2105461eds.14.1680704493010; Wed, 05 Apr 2023 07:21:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704492; cv=none; d=google.com; s=arc-20160816; b=dl3WnDYFqOSsvp8BiylDSCy7lCbAMpfuoOfJyKbEMoKv/bl+c4vglxud45RQg5G/Hw exGHLchlSEooSYtKFsduAzv3Ct+iMllDXJyc/B1Bbg6SMkso2ROLFhuwTgVi9XTYHikL Sv2mwNSZrteeSiaBhi9f2qzl9+A/OiGVzbK6OfqiWHjFVFIqpMxtL1PTJdRcGACyMCIk FUVKmufK2T1Uqwlw0jDQQwfT0oyXvjulmVvHEmdn35i00Y1uy7dRvbUF0ph+MpOzsEGY g2M25Hk/nXVt3dJBhDk/+dPxSOH9qgzGiRBpJO2fBJ2P4ikTyPeybT9vwYitZKX4+0cV Npbw== 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=sGEoB5nrT8ogJUJfDdjoR7Lupp2E9RJ+AFD+MwADerI=; b=K8N2HP21mZU1K2L76kSlRr9pwRVvVZrcJ+5Ya8+fz2mYZ7aBX3Wg3JjU+Vi0sYD8Uq 7R86tNUmjBdNtQbgd/hzChCZxlTXTeYMzm3nhpH8N+7/MlgfHlsrryAC7gdv/GE9ja+z slW389UiwfWLIt0cLVu0b0D/lb2U6dmqqpTS/TAjMegmIODTb6s40IiH3kfyK1B7rcvQ JCdky+JCGTJWK/c7fGXGUb1NzzeSTxSuFrB3CujuNEUbJMtsHDIFocN2bCHCtRFrSX8+ u5nLME7/JQ4lou1JjaNqQITGSBzMsdkNvuGwmQDU9rD7h2FWzq/+4VLxn1e4vCYQlVjo r8Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Pl+megf5; 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 bq3-20020a056402214300b004af50024631si9465414edb.433.2023.04.05.07.21.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:21:32 -0700 (PDT) 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=Pl+megf5; 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 C4A283892BB6 for ; Wed, 5 Apr 2023 14:10:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id D50493853804 for ; Wed, 5 Apr 2023 14:05:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D50493853804 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-x329.google.com with SMTP id l10-20020a05600c1d0a00b003f04bd3691eso7160170wms.5 for ; Wed, 05 Apr 2023 07:05:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703541; 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=sGEoB5nrT8ogJUJfDdjoR7Lupp2E9RJ+AFD+MwADerI=; b=Pl+megf5vBII9xWwtnt/pze1X7KgAwo0BUVmOc0cAIX2PtvDXhNBJp7mzPoyjVhevP J0jojpfm5qBOFlAlIat2nHN+tVbzzMPUOkMDBRXhiq1s8FzxFOdzvROZolG+cVF0d4xi QFphQH54QM4K8AdSLD6U5wTjYbdu2q2RVKjqBKb8STLlI6REo6d5OfhygCPa7mNTP/5Y PDMV4TRG5VjT0WXCG/gf9dwYMuJDg6g9AUNSFZIF9gGqLmZ75WXys5QcaM7yDwXdjWws CUNPOwEvUW15t9R9jcx4fxNHOIwNOTiqjXl/5vnkQW37xkKx4CbAqRttfyXtBdfss8sL lMkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703541; 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=sGEoB5nrT8ogJUJfDdjoR7Lupp2E9RJ+AFD+MwADerI=; b=GAmeIh3OJgnjuT9W4ZZb/59T4Sp4uUWoCCoG0peTW6lwP1JrJ1O1xzM7G3BHJHYPeY EQsgTDUDvdQOsWdkqur162177amQlopQe9UM9dgFJqysmxM/lmKA8hJm2gRGvbiBRS6U lvWDjZL5bswSwlNNtFDkHiE6aChFDTU00FD8QqVlq61tTfC8XixcQAZrvQp8DhTziegu qf3ed3er7FlSwyoEY4V86R7rUggF++aiwstZzD03qL6N+YppJaChA+xXUrDO8MEP/PI8 wbhRnwmQETfA+9iMlnytQhgKTsjSwfkHUFqSoqhZVTZst/vBkybId+JosDlNCHMcsz+p 2E1g== X-Gm-Message-State: AAQBX9f50d+zb59L0a/GMtgqJkHG4mCmjS3JzQw6TV1iWi2LgCVHubXw ywJu2rBS1tr/ha+XtKOGE1bihIuuzGk50S2EVg== X-Received: by 2002:a7b:c855:0:b0:3ed:276d:81a4 with SMTP id c21-20020a7bc855000000b003ed276d81a4mr4778826wml.32.1680703541084; Wed, 05 Apr 2023 07:05:41 -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.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:40 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Parthib Subject: [committed 19/88] gccrs: Rename file rust-ast-full-test.cc to rust-ast.cc Date: Wed, 5 Apr 2023 16:03:03 +0200 Message-Id: <20230405140411.3016563-20-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?1762346394394354393?= X-GMAIL-MSGID: =?utf-8?q?1762346394394354393?= From: Parthib gcc/rust/ChangeLog: * Make-lang.in: Rename object file. * ast/rust-ast-full-test.cc: Moved to... * ast/rust-ast.cc: ...here. --- gcc/rust/Make-lang.in | 2 +- gcc/rust/ast/{rust-ast-full-test.cc => rust-ast.cc} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename gcc/rust/ast/{rust-ast-full-test.cc => rust-ast.cc} (100%) diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index dddc70a26ec..87f3ba66eba 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -73,7 +73,7 @@ GRS_OBJS = \ rust/rust-lex.o \ rust/rust-cfg-parser.o \ rust/rust-parse.o \ - rust/rust-ast-full-test.o \ + rust/rust-ast.o \ rust/rust-ast-fragment.o \ rust/rust-ast-dump.o \ rust/rust-hir-dump.o \ diff --git a/gcc/rust/ast/rust-ast-full-test.cc b/gcc/rust/ast/rust-ast.cc similarity index 100% rename from gcc/rust/ast/rust-ast-full-test.cc rename to gcc/rust/ast/rust-ast.cc From patchwork Wed Apr 5 14:03: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: 79660 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp345675vqo; Wed, 5 Apr 2023 07:22:00 -0700 (PDT) X-Google-Smtp-Source: AKy350YZqCRAOnfC7Fzo3771xhLlZKOSWURCMd6B6rjyVc5a3vfMSu3l3ORpHsnjD+IvFJpdTt5E X-Received: by 2002:a17:907:6ea5:b0:8de:acd1:90f0 with SMTP id sh37-20020a1709076ea500b008deacd190f0mr3871027ejc.3.1680704520368; Wed, 05 Apr 2023 07:22:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704520; cv=none; d=google.com; s=arc-20160816; b=OLRiMc8v7H9wbhdzzrEc+TM4qDlVb+R4DVF4IACRYrf+ygG5CzKDdIwEuA0nMko1UL i6Pkk9GegcXTJEVYyfzvMdtjY5nNT7FSbkHBXpn8Dytu7T/4nWwupuaGgZuYaEmW2ONo fvw0NKWQWHourVpTictlxhkrmBj9EEVtgCG0qdP0tk3SONN9lp2Cqp4qrVaNu4XdqT7/ w92anvWrDI+snkbTMeCS8qpcTy+cppKnn7JK+tqGL7WopZqc8SftLU5GbBiwSpQsMQaV GpAdFYlU1lRYnTl2OrG01T0o75nDmoHW9wZtfY/Afj80+pFeOqZJk5Yf2HBLXRevLpQF fgLg== 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=ubMvXqxUmwYakqie+HrSxx0MSHjdKuyL1C8BLM9Vecc=; b=iM3YP+9X8gg0aFKgtSOSDJdFj0BcYy0lw6dTGQeBLqdfp/A/fXFbcBWcrxp5+cVWSO ydBF8eVsV+ond/rYIFsTp70VerjecQWuTzmiSiVUs8rpG4wEn23xnGmreTdWOPGsWbFd 2/4uLBjHmAQqugSAZ1NTObKEtO2rXXz7rz5X9Sh0GKA/0yIgvjExEZxjawhl0gE28ihl c5jc/hZV9PuWqOvx4U8nywvL/SnbBiWIg7ofWcMlO2o/rgoR0+8RkcFnzisKWPhYBJFj NurS9uFOhh4pfEQ5llXJ8zHjXrsZX8CMOaFdnaadZrXy8j1EdX9Rx6AQ07pyNkY3e5GY DxxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=HxxlVZJd; 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 hq8-20020a1709073f0800b00934d983a240si293234ejc.280.2023.04.05.07.22.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:22:00 -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=HxxlVZJd; 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 387A7384F00E for ; Wed, 5 Apr 2023 14:10:27 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id 7D648385B519 for ; Wed, 5 Apr 2023 14:05:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7D648385B519 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-x32f.google.com with SMTP id j18-20020a05600c1c1200b003ee5157346cso23815348wms.1 for ; Wed, 05 Apr 2023 07:05:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703542; 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=ubMvXqxUmwYakqie+HrSxx0MSHjdKuyL1C8BLM9Vecc=; b=HxxlVZJd+ntWCfjeUFmbF2mOCYv5io7sYfF2yiqFpCVBfROHlfaOcgqIK6GHONFRXL wnHPfLifMizEoFYAyaiGLAvr0/Y/u2vkJC/Q14qo68XnwydpmYi/ZXqFTr7aA2NEjmMr PwFhkq/T/sqKfz4+gJrlcaps5fV7O5ziEZuhwLSdMaNTPP77ljoQNwaekVd2oH+zaLJN dKW8N5wNholhDRMJXMnuzICQUa2ruupRfMFcUnDKsxew7GpCGga13anCNox6Gn2f+WqQ abIpRMTaZB9LErkPrAsoFjz7Yo+D4afPO4MXjCRz78ky1TQFO1GjEvqhuNkIwpneSqaN uVMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703542; 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=ubMvXqxUmwYakqie+HrSxx0MSHjdKuyL1C8BLM9Vecc=; b=ogiuAQ92hQPeewuVg8owB0PgeiRbwPpI5OV0Bq0dBLKTpE8ljDuFMIPBnt2EHGm4ch dw6+1NrhBi3QADoVGfPIhZfebo8aeudftgCvG2NqqVr76j74B7Cor6Dbs3CJh9RvcsJv wKXYuU7AgspxiEfpgaKn238EyuOJGLgkSTXWZl5XvzyByI720lELtYTLuLZPA5PlIpC6 qp5+vS27G88/pcggksf6QXNNiPy/UwA62/J9aPvSryM0kWKMQE7uDFIaoPy9FhCEgUQL m6voviD6U/uLSR7b8fad3XDJ/80khewXS7qukaqqP5bjWcaF9cKSfAad08flhJr5BsOf PEPQ== X-Gm-Message-State: AAQBX9df8eFUblINIRybFXnXNsX3qTy/b9fypd/M73/FweikSwd/pFoN nWhivxgWd2Jra4OLlnNg5wIjSqkhKyKprRpvjA== X-Received: by 2002:a7b:cd15:0:b0:3ef:6ae7:8994 with SMTP id f21-20020a7bcd15000000b003ef6ae78994mr5041352wmj.22.1680703541730; Wed, 05 Apr 2023 07:05:41 -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.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:41 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Abdul Rafey Subject: [committed 20/88] gccrs: moved operator.h to util/rust-operators.h Date: Wed, 5 Apr 2023 16:03:04 +0200 Message-Id: <20230405140411.3016563-21-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.6 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?1762346423411045462?= X-GMAIL-MSGID: =?utf-8?q?1762346423411045462?= From: Abdul Rafey gcc/rust/ChangeLog: * ast/rust-ast.cc: Fix include list. * ast/rust-expr.h: Likewise. * hir/tree/rust-hir-expr.h: Likewise. * rust-backend.h: Likewise. * util/rust-lang-item.h: Likewise. * operator.h: Moved to... * util/rust-operators.h: ...here. Signed-off-by: Abdul Rafey --- gcc/rust/ast/rust-ast.cc | 2 +- gcc/rust/ast/rust-expr.h | 2 +- gcc/rust/hir/tree/rust-hir-expr.h | 2 +- gcc/rust/rust-backend.h | 2 +- gcc/rust/util/rust-lang-item.h | 2 +- gcc/rust/{operator.h => util/rust-operators.h} | 0 6 files changed, 5 insertions(+), 5 deletions(-) rename gcc/rust/{operator.h => util/rust-operators.h} (100%) diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index 280f59ffb16..60a9f01e17f 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -25,7 +25,7 @@ along with GCC; see the file COPYING3. If not see #include "rust-session-manager.h" #include "rust-lex.h" #include "rust-parse.h" -#include "operator.h" +#include "rust-operators.h" /* Compilation unit used for various AST-related functions that would make * the headers too long if they were defined inline and don't receive any diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index 34bc6993ab6..3ed1885d5af 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -3,7 +3,7 @@ #include "rust-ast.h" #include "rust-path.h" -#include "operator.h" +#include "rust-operators.h" namespace Rust { namespace AST { diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h index cc884420bef..bf103516800 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -23,7 +23,7 @@ #include "rust-ast-full-decls.h" #include "rust-hir.h" #include "rust-hir-path.h" -#include "operator.h" +#include "rust-operators.h" namespace Rust { namespace HIR { diff --git a/gcc/rust/rust-backend.h b/gcc/rust/rust-backend.h index 01c5fc40e8c..076104f3a40 100644 --- a/gcc/rust/rust-backend.h +++ b/gcc/rust/rust-backend.h @@ -26,7 +26,7 @@ #include "rust-location.h" #include "rust-linemap.h" #include "rust-diagnostics.h" -#include "operator.h" +#include "util/rust-operators.h" #include "tree.h" // Pointers to these types are created by the backend, passed to the diff --git a/gcc/rust/util/rust-lang-item.h b/gcc/rust/util/rust-lang-item.h index ea0c91aa5f2..29c364bad61 100644 --- a/gcc/rust/util/rust-lang-item.h +++ b/gcc/rust/util/rust-lang-item.h @@ -17,7 +17,7 @@ // . #include "rust-system.h" -#include "operator.h" +#include "rust-operators.h" namespace Rust { namespace Analysis { diff --git a/gcc/rust/operator.h b/gcc/rust/util/rust-operators.h similarity index 100% rename from gcc/rust/operator.h rename to gcc/rust/util/rust-operators.h From patchwork Wed Apr 5 14:03: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: 79671 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp347695vqo; Wed, 5 Apr 2023 07:25:00 -0700 (PDT) X-Google-Smtp-Source: AKy350YkIXobAuVa+8u3zODbgSo3tbfATiFGPYXV/SshQaX04qKQb6o86FvAjqOOsO1RC78Co/8E X-Received: by 2002:a17:906:11c5:b0:878:7a0e:5730 with SMTP id o5-20020a17090611c500b008787a0e5730mr3152163eja.56.1680704700736; Wed, 05 Apr 2023 07:25:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704700; cv=none; d=google.com; s=arc-20160816; b=TrRM9eyqEf/WvMxelUhlEHoBSXV0JFbKNMQoq3EHzCVS9rztcSrEpt7+qYbw81JnW9 8iiNilAlrw9EEE7LLEzcq2opEs1EE9YbEe57BftGQyrVRN8xROcJ+BlMa1JD5u+6Xf6x 5NY+8801zXXmz+9YZ/W2z2aJw4cxLEndezoQjZ1LN8QFcEs3O/m8d8ixe02ljBmSKSD0 ESzvn6d09E88LR42psn0nDmqOQA0acyBMxY8x7r3egnKpwkMBAUw8HcF/+SlxeFKyFai voE1OryjoWc8dzcygMUW+1TqRknyyideN5qqbZE9ShkGkSvlOJKkd6NXgsV1VhKikIDY 2lcg== 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=wFsC4ZrvK5kPI6X14aA2eunQSHlGOe6V20FjAJ0hMdc=; b=ksVXP5DhtlfuELVdgKX3CDj/cwEn4Jp/lT+jrZ5kka/NbEr5ulfk+Ns8BFzUC3m6V9 QTnJrrO5bd6Jz9qIom4TYd/QUd4b2J94Hc9sXci5QIQK0lD4QqllKcltiXMB9KJeOlmA 7hb8sNBwJF+dej2W5hnpxvWX2UbLE1QouwaI9kVzq5s8gHfW6mnX6JyDoTz5MAekgn4d 1SnLd0niCpoxAA3OUwG+qUPKU145i+g/SDBCRXLs43iL3OGF5IGQGKXi88wy2DFolZzQ 0gdZE5UXiyzxJfaXatOvxoGy6sl00sMiB+e069/BK47DKr3uo3HX2ic2OYu2gzJhZ8lo fGyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Rkp2472d; 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 d3-20020a1709067f0300b00932e5d0cc46si2095975ejr.930.2023.04.05.07.25.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:25:00 -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=Rkp2472d; 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 97A4038D9077 for ; Wed, 5 Apr 2023 14:11:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id 0C680385382B for ; Wed, 5 Apr 2023 14:05:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0C680385382B 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-x32c.google.com with SMTP id s13so20939263wmr.4 for ; Wed, 05 Apr 2023 07:05:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703542; 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=wFsC4ZrvK5kPI6X14aA2eunQSHlGOe6V20FjAJ0hMdc=; b=Rkp2472dfczn+QVixUp4TMN3iOyOoHsOVE7N9u0vKeN9Y3MqnSCc1iGKspLyux1MYQ Ifl5IyH90qxsrZ4bUlXYoc0oR2nRLTVGTbNmO6V0yiAIbhujYEF52SS4EE/9c5rex75+ S4RRY1AjXHQvGfwSsX1rHSoEDLRcN/4j8uzx35USt8rBMBQYbsXudgdpyYjIlfxgrTQe l2DHPOlLhJgIR7Hwd6KALct7zp2bvLOhABoYw7FWaH0kJLT98e/JTOg2NBn4Mh6O0w9f JHZgl1gyBsr+5xu2+V5EhtVi+HaTu/Sp9KAYXcu998sPExAuiAxlFnNj4OTx5JjANCd4 ukug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703542; 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=wFsC4ZrvK5kPI6X14aA2eunQSHlGOe6V20FjAJ0hMdc=; b=AjxqOojTihioJRJEpPxWxI0vhtMeppe/HyO0M/LmxRpMgWZyXvR+nljKoOHQ8NLZsa p5aOhE0TSC1+Fp2PHH97pX/4scPHS9foxpGrkFkbo/y/JDeK8bl/n8KR4vrqPdjkOwbu ggECOALLVDLZwWLCkZAvvYsIbJxdjRiQ3aObYUF3INeMAMzhk1UmbavRuXP8gLITntaM N+zTM1XJ9kAtUk2TQ/KJ9FnINInLlhdG3sH6GFCGpw1wtXtPaqm7t7XHSs0PXE6iHxeS DDazRnHhhpRue3s8U12Czl6kZAEowWW6DbzEq1pN/BEpVdwdszSj88VDVkv30Ox/XWxX HWzQ== X-Gm-Message-State: AAQBX9fhCGCVTb/qO/XsW8Mp1EtLuUCcBvldvz0ABjKYJGp8pC04DReo U9AvLY7NPYE6wZHlBYRwrWmfAI9tkLw+VVSi5A== X-Received: by 2002:a1c:f013:0:b0:3ed:29d9:56ae with SMTP id a19-20020a1cf013000000b003ed29d956aemr4629588wmb.6.1680703542636; Wed, 05 Apr 2023 07:05:42 -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.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:42 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Abdul Rafey Subject: [committed 21/88] gccrs: fixed compiler error message on wildcard pattern within expression Date: Wed, 5 Apr 2023 16:03:05 +0200 Message-Id: <20230405140411.3016563-22-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.6 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?1762346612173691836?= X-GMAIL-MSGID: =?utf-8?q?1762346612173691836?= From: Abdul Rafey gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::null_denotation): Add proper error when seeing wildcard var on right side of assignment. gcc/testsuite/ChangeLog: * rust/compile/issue-867.rs: New test. Signed-off-by: Abdul Rafey --- gcc/rust/parse/rust-parse-impl.h | 6 ++++++ gcc/testsuite/rust/compile/issue-867.rs | 8 ++++++++ 2 files changed, 14 insertions(+) create mode 100644 gcc/testsuite/rust/compile/issue-867.rs diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index d71bafded63..af749ca9200 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -13021,6 +13021,12 @@ Parser::null_denotation (const_TokenPtr tok, case UNSAFE: return parse_unsafe_block_expr (std::move (outer_attrs), tok->get_locus ()); + case UNDERSCORE: + add_error ( + Error (tok->get_locus (), + "use of %qs is not allowed on the right-side of an assignment", + tok->get_token_description ())); + return nullptr; default: if (!restrictions.expr_can_be_null) add_error (Error (tok->get_locus (), diff --git a/gcc/testsuite/rust/compile/issue-867.rs b/gcc/testsuite/rust/compile/issue-867.rs new file mode 100644 index 00000000000..8e120685c1a --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-867.rs @@ -0,0 +1,8 @@ +fn main() { + let _ = 42; + let a = _ + 123; // { dg-error "use of '_' is not allowed on the right-side of an assignment" } + // { dg-error {failed to parse expression in let statement} "" { target *-*-* } .-1 } + // { dg-error {failed to parse statement or expression without block in block expression} "" { target *-*-* } .-2 } + // { dg-error {unrecognised token '\}' for start of item} "" { target *-*-* } .+2 } + // { dg-error {failed to parse item in crate} "" { target *-*-* } .+1 } +} From patchwork Wed Apr 5 14:03: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: 79668 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp346867vqo; Wed, 5 Apr 2023 07:23:44 -0700 (PDT) X-Google-Smtp-Source: AKy350YKKWd59SDGZw6NrQlkqWWJxoP1aTbhaZqK3nit8TuQZWkvcd0pOZvOcTrBmrqfkKX2fldk X-Received: by 2002:aa7:cd62:0:b0:4fd:29a1:6a58 with SMTP id ca2-20020aa7cd62000000b004fd29a16a58mr2190818edb.19.1680704624132; Wed, 05 Apr 2023 07:23:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704624; cv=none; d=google.com; s=arc-20160816; b=uPWLai+iVUVuVmNVEwXYgoQ2f0SogFjd6/Qs6MryEZRgJEd/ffeF2lUOgJqG2ySzEZ 9Solu0bCGDk4RgQAhzfPDt77s4V8fRHs+vV1wN9GBJP3B4bwe5ta0B1UOSoLH43hzQLW fmiDBeNqGwwcBp0de30IOIfxdlH3HrSoJYqlJKQ9NpiV5REAVp4tyEEogV/Ju+ImP8Dg pwa/70pzdbNLOfNDaWsqujlLtGye/Qo3cFvuCXYPTXCq4GnJi86bJTPo78lfuv19EjZj tSTri9RLOjQYmSLGo6ObSHUThO6ABDKTdgLby1RoqEKSGRGdSSEzHscxvS7x9dgwhLbh U4dw== 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=83qDQLIx+/pit3LfqseKTngaMoyJ6cGYBuwK0YmyyI0=; b=0JUDIfkSXKIRgK9y2bfyxMYDksqgwjYBtEDub1EjhmkHXD6rD45nFcI1cEjxJcOkyR nqJhYR3sLeYD+BgHGA2Gzo5+wTam1Yispo4qrvYkg297c/ur7FFkPmBqHxBFlhOWqJVU l+eC95RsdPgGlFz7gbwrPSxFqfieUEg9ZL8vrr0BEyVsYUlyHobW8ovlbcHi7Z+qTIPe dpMUDKRKqbqwB0tAtiHtu9NxMsYOKppFc+2fCbRXFdJFWtm7phxuAYNHnLMNcPDGfpUV oqJajq2ejhOr5BG5hVaOvqa0WnCHxS2o5ADq5IOc7e6ja0TgjcYP7K/W79wNmWh6HxlW pWvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Tr4VSHfF; 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 w14-20020aa7d28e000000b005004ce1b26fsi3109117edq.593.2023.04.05.07.23.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:23:44 -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=Tr4VSHfF; 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 36B9E385085E for ; Wed, 5 Apr 2023 14:10:52 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id B2E433853544 for ; Wed, 5 Apr 2023 14:05:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B2E433853544 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-x331.google.com with SMTP id n10-20020a05600c4f8a00b003ee93d2c914so23481955wmq.2 for ; Wed, 05 Apr 2023 07:05:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703543; 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=83qDQLIx+/pit3LfqseKTngaMoyJ6cGYBuwK0YmyyI0=; b=Tr4VSHfFPBsZiYP5B0c/kU08HY5sBnAtiJvHoxl1hpUCeom/3Sq2jFnugHYJ8NGEG7 jDjdPNrquc7TE4UcMyGyh6iju9Jy+I9soZrEuZDvPwS+aoOHpwK8Z/MSJ3zEgcT5Ze3K ctKMslAAmxFjmvySG6jJ+5VzOaQoCdH99S0TSjsDNOHeqcdjMGYkmgC+F8qcGUn/rVD4 SW7/DCYwVf7PLutz9KeXpk1FHvPbILTKUB/g4txqYCBtjIfr+q3P1aE1BRv0pobQdAt0 jVc9YeC/0X67Gz8rOXMKZyFiXmXq8NKFXr0XhxgPaOdHPN4pY0okaJA3HPm1+8W/RO+O 8iFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703543; 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=83qDQLIx+/pit3LfqseKTngaMoyJ6cGYBuwK0YmyyI0=; b=kQPNNKPdXYGeLMOgCANGp9Wp6WArwXGWzmAGBYoN116jUp15QG/kEzEcZCOOzWiXBF qKhkEE0+U3+SljGg8qxcmBsuluJHrcT0NwY1OETl5a4Hnxt03gytg7AL9qGULe65pHin T1ExGKPRI5rHuXVfz1mg+3UZXKIFUbi6sbCpPKVS9XzSFONykicKVF+rHCiMEcUifgaT ZJLKijbfhM9sZGl1iViXt1MwbWNyiN5X5bcqtYcBpPJiWUGdAcPXy9KREKXT28Sd55Ua pikxHj1gYBF85sJnP/MIJc4R9umQehvmJpGmKof9FS9IoCqlq8Ednyqq6ulO2Jx/xjdn OI+w== X-Gm-Message-State: AAQBX9eGM79g6KN9JqbWvlTsvjOjluWeYdcr2WHvoEVTUKlNz+5yxT/n Ippj8sRRfJ/UJNTZvI4GwnpSn8Nin2lAZym1KA== X-Received: by 2002:a05:600c:20d:b0:3ea:f75d:4626 with SMTP id 13-20020a05600c020d00b003eaf75d4626mr4796818wmi.38.1680703543271; Wed, 05 Apr 2023 07:05:43 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:42 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Abdul Rafey Subject: [committed 22/88] gccrs: fixed indentations in AST pretty expanded dump of trait Date: Wed, 5 Apr 2023 16:03:06 +0200 Message-Id: <20230405140411.3016563-23-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.6 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?1762346531831774646?= X-GMAIL-MSGID: =?utf-8?q?1762346531831774646?= From: Abdul Rafey gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): removed extra indentations in trait ast dump Signed-off-by: Abdul Rafey --- gcc/rust/ast/rust-ast-dump.cc | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 77e04b972dc..58eb35ad1db 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1072,8 +1072,6 @@ Dump::visit (TypeBoundWhereClauseItem &item) void Dump::visit (Method &method) { - // FIXME: Do we really need to dump the indentation here? - stream << indentation; visit (method.get_visibility ()); stream << "fn " << method.get_method_name () << '('; @@ -1326,7 +1324,7 @@ void Dump::visit (TraitItemFunc &item) { auto func = item.get_trait_function_decl (); - stream << indentation << "fn " << func.get_identifier () << '('; + stream << "fn " << func.get_identifier () << '('; visit_items_joined_by_separator (func.get_function_params ()); @@ -1340,9 +1338,6 @@ Dump::visit (TraitItemMethod &item) { auto method = item.get_trait_method_decl (); - // 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 () << '('; From patchwork Wed Apr 5 14:03: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: 79647 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp344154vqo; Wed, 5 Apr 2023 07:20:00 -0700 (PDT) X-Google-Smtp-Source: AKy350bLTAHkXgC0GcwZjaatHjKUxI8AyBud5u8L1C3kFftYKV9hG3bdPxBOZvAzPxZk0nDe4Vec X-Received: by 2002:a17:906:f51:b0:88a:1ea9:a5ea with SMTP id h17-20020a1709060f5100b0088a1ea9a5eamr3030317ejj.65.1680704400418; Wed, 05 Apr 2023 07:20:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704400; cv=none; d=google.com; s=arc-20160816; b=iEO75q9Jhsg8dW5OImqXrIoDoy0iWOnfd0IIvUP905rfGh9s8EPK6QC0tgw/C5Q9KU DZLMGdWXe+dh6lU+ECKamiuTIRJp9Wsyz5ayE6wRq7gtbjCcxSvHUnm5aRjd5YPBPS5l nlUjRgGPM6SPKDo/AbLwRJXexWWviGwJ2hJbBv8KFjj+TTrDb8k9W0igud+/lB3Eu7YQ zj3Vkm6TajwYkyoaIlHpjfoMd4omSf1yjZLZvJrLii590++gekuJ21k7yuE5/qWeMpEm SaLeFbj26y8avOWT959143LZyDP7GcGvXjkkFmRauDnWOXEIqEBQr4/v2nlqAD6P4+Eo 7irw== 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=XASHR5fWYWYoKYBrrl1/4rFLy0iFDUR8UCc7yuPK6aM=; b=G/RoZjMR9g9ifaLsi8hUoY0KVTj5ME2ykk6czMASr/Xjbkd/+yiB/hQHN9970uLNcX xdM1WRxcD+su8pVdzbJFxb1fMQP9rLF/nuBTqgjF15xUbVQNEf6s8qRGOfwtP6i8qVDc c3GFRo2lg3WfaeIiapN/UQ3RJBlirMbLILURrWBPatbCQmvsLs6LCaHUawnCgpqrKtjO sdvYDarPoqkL1x8SCPV04Ywz2IeR4CNOw69mFr6FEFfGptjvFtxTow+QmJNZzB5HdXtU wtuh7Y/ieT/rZEbNw17R6BQ1NvX1Cx9aL434+zMjgQbnfKi24dmsxgYW353/S7xjRh7f BNUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=UvTn39J1; 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 lh19-20020a170906f8d300b009263490cbeasi4789290ejb.92.2023.04.05.07.20.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:20:00 -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=UvTn39J1; 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 EE1413ACBCA6 for ; Wed, 5 Apr 2023 14:09:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id 7FE353857344 for ; Wed, 5 Apr 2023 14:05:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7FE353857344 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-x32a.google.com with SMTP id l10-20020a05600c1d0a00b003f04bd3691eso7160271wms.5 for ; Wed, 05 Apr 2023 07:05:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703544; 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=XASHR5fWYWYoKYBrrl1/4rFLy0iFDUR8UCc7yuPK6aM=; b=UvTn39J1+0LYyKjS6qgW/yb/KznNaD7RdB6HerdW/Ru+h5eoePmHA3xzVTef5+aE7b M0AY/p3BWE/DV+UCpqkROHn1DpLMG//vd8itx/It3ztLa/iH69j++dr7P2NFTWlYwATs G/7rQYYsu852LUzuIdQLJ0WSlubIq3osNnHS/Wkx6uu8ek3dQQAhrO39akfV8ofDTLlh A+Zh3tnyp78VK5yjehca7YFCQaIs5oq1RREHvQ7PfZSgTe8ImWppm/j5Af1GrctQh+vh wfuGyoYZBsx4rffKChR1C41/MZBc69HUqoUhkHMh5C6cc6V7oGdDJQ0/jKgPwxISHcRA YupA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703544; 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=XASHR5fWYWYoKYBrrl1/4rFLy0iFDUR8UCc7yuPK6aM=; b=BchcLdfziHRjJV0Z+yc//wpu2yYstrYQ8navWZ/r+mLMLqiGsEEDXQLBE5Sz03e/mW tDkeuXntmJPGJeDIga2rF7Bp64OQw2zquBcO0Nt4I0tAuR4Oyt7x3oWE99Eh8zUwT43S Id7/h1fCjKOU5jJ0TwTwjCh061Mzsicq6T5WBnZEBKa7y72CYcywU89K0blwGajvMgn2 6q8uhJfm963YCWpUYIONdjp02CCqAVzWynkeUHVvny9cvz0EzO0byyfz8G7xqRMwRdyo RI5Uezzv5Jbppqu1yZu56DVJgygcuGnWHuuZ4Une6e9ubruC3LKL3GjxrZNzrs1fa0+k Autg== X-Gm-Message-State: AAQBX9cjnvMlmy4NiTCcY3FF/qUdfATiy3T6rPkHN3tfqK75yqQKOhFp sQ7pBZ9fGct4Hn98xzH0j1cePjIV5MtOnbA74g== X-Received: by 2002:a7b:cc98:0:b0:3ed:8079:27d7 with SMTP id p24-20020a7bcc98000000b003ed807927d7mr4689779wma.40.1680703543977; Wed, 05 Apr 2023 07:05:43 -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.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:43 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 23/88] gccrs: macro: Allow builtin `MacroInvocation`s within the AST Date: Wed, 5 Apr 2023 16:03:07 +0200 Message-Id: <20230405140411.3016563-24-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?1762346297455959923?= X-GMAIL-MSGID: =?utf-8?q?1762346297455959923?= From: Arthur Cohen gcc/rust/ChangeLog: * ast/rust-macro.h (enum class): Add `BuiltinMacro` enum class. * expand/rust-attribute-visitor.cc (AttrVisitor::visit): Mention switching on `macro.kind` once builtin macro invocations are properly handled. * parse/rust-parse-impl.h (Parser::parse_macro_invocation): Switch to new MacroInvocation API. (Parser::parse_type): Likewise. (Parser::parse_type_no_bounds): Likewise. --- gcc/rust/ast/rust-macro.h | 110 ++++++++++++++++++---- gcc/rust/expand/rust-attribute-visitor.cc | 2 + gcc/rust/parse/rust-parse-impl.h | 70 +++++++------- 3 files changed, 126 insertions(+), 56 deletions(-) diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h index 4226c6919ff..68dd7d660d3 100644 --- a/gcc/rust/ast/rust-macro.h +++ b/gcc/rust/ast/rust-macro.h @@ -578,8 +578,30 @@ protected: } }; +/** + * All builtin macros possible + */ +enum class BuiltinMacro +{ + Assert, + File, + Line, + Column, + IncludeBytes, + IncludeStr, + CompileError, + Concat, + Env, + Cfg, + Include +}; + /* AST node of a macro invocation, which is replaced by the macro result at - * compile time */ + * compile time. This is technically a sum-type/tagged-union, which represents + * both classic macro invocations and builtin macro invocations. Regular macro + * invocations are expanded lazily, but builtin macro invocations need to be + * expanded eagerly, hence the differentiation. + */ class MacroInvocation : public TypeNoBounds, public Pattern, public Item, @@ -589,26 +611,47 @@ class MacroInvocation : public TypeNoBounds, public ExternalItem, public ExprWithoutBlock { - std::vector outer_attrs; - MacroInvocData invoc_data; - Location locus; - - // Important for when we actually expand the macro - bool is_semi_coloned; - - NodeId node_id; - public: + enum class InvocKind + { + Regular, + Builtin, + }; + std::string as_string () const override; - MacroInvocation (MacroInvocData invoc_data, - std::vector outer_attrs, Location locus, - bool is_semi_coloned = false) - : outer_attrs (std::move (outer_attrs)), - invoc_data (std::move (invoc_data)), locus (locus), - is_semi_coloned (is_semi_coloned), - node_id (Analysis::Mappings::get ()->get_next_node_id ()) - {} + /** + * The default constructor you should use. Whenever we parse a macro call, we + * cannot possibly know whether or not this call refers to a builtin macro or + * a regular macro. With name resolution and scopes and nested macro calls, + * this is literally impossible. Hence, always start by creating a `Regular` + * MacroInvocation which will then (maybe!) become a `Builtin` macro + * invocation in the expander. + */ + static std::unique_ptr + Regular (MacroInvocData invoc_data, std::vector outer_attrs, + Location locus, bool is_semi_coloned = false) + { + return std::unique_ptr ( + new MacroInvocation (InvocKind::Regular, Optional::none (), + invoc_data, outer_attrs, locus, is_semi_coloned)); + } + + /** + * Create a builtin macro invocation. This can only be done after macro + * name-resolution and within the macro expander, so unless you're modifying + * these visitors, you probably do not want to use this function. + */ + static std::unique_ptr + Builtin (BuiltinMacro kind, MacroInvocData invoc_data, + std::vector outer_attrs, Location locus, + bool is_semi_coloned = false) + { + return std::unique_ptr ( + new MacroInvocation (InvocKind::Builtin, + Optional::some (kind), invoc_data, + outer_attrs, locus, is_semi_coloned)); + } Location get_locus () const override final { return locus; } @@ -642,6 +685,37 @@ public: bool has_semicolon () const { return is_semi_coloned; } + InvocKind get_kind () const { return kind; } + Optional get_builtin_kind () const { return builtin_kind; } + +private: + /* Full constructor */ + MacroInvocation (InvocKind kind, Optional builtin_kind, + MacroInvocData invoc_data, + std::vector outer_attrs, Location locus, + bool is_semi_coloned) + : outer_attrs (std::move (outer_attrs)), locus (locus), + node_id (Analysis::Mappings::get ()->get_next_node_id ()), + invoc_data (std::move (invoc_data)), is_semi_coloned (is_semi_coloned), + kind (kind), builtin_kind (builtin_kind) + {} + + std::vector outer_attrs; + Location locus; + NodeId node_id; + + /* The data given to the macro invocation */ + MacroInvocData invoc_data; + + /* Important for when we actually expand the macro */ + bool is_semi_coloned; + + /* Is this a builtin macro or a regular macro */ + InvocKind kind; + + /* If it is a builtin macro, which one */ + Optional builtin_kind = Optional::none (); + protected: /* Use covariance to implement clone function as returning this object rather * than base */ diff --git a/gcc/rust/expand/rust-attribute-visitor.cc b/gcc/rust/expand/rust-attribute-visitor.cc index a1895749b82..6bceed62096 100644 --- a/gcc/rust/expand/rust-attribute-visitor.cc +++ b/gcc/rust/expand/rust-attribute-visitor.cc @@ -389,6 +389,8 @@ AttrVisitor::visit (AST::ConstGenericParam &) void AttrVisitor::visit (AST::MacroInvocation ¯o_invoc) { + // FIXME: Probably need to check macro_invoc.kind + // initial strip test based on outer attrs expander.expand_cfg_attrs (macro_invoc.get_outer_attrs ()); if (expander.fails_cfg_with_expand (macro_invoc.get_outer_attrs ())) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index af749ca9200..a0bc2e10d2f 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -1752,10 +1752,9 @@ Parser::parse_macro_invocation_semi ( { // as this is the end, allow recovery (probably) - may change - return std::unique_ptr ( - new AST::MacroInvocation (std::move (invoc_data), - std::move (outer_attrs), macro_locus, - true)); + return AST::MacroInvocation::Regular (std::move (invoc_data), + std::move (outer_attrs), + macro_locus, true); } } @@ -1764,9 +1763,9 @@ Parser::parse_macro_invocation_semi ( t->get_token_description (), lexer.peek_token ()->get_token_description ()); - return std::unique_ptr ( - new AST::MacroInvocation (std::move (invoc_data), - std::move (outer_attrs), macro_locus, true)); + return AST::MacroInvocation::Regular (std::move (invoc_data), + std::move (outer_attrs), + macro_locus, true); } else { @@ -1814,10 +1813,9 @@ Parser::parse_macro_invocation (AST::AttrVec outer_attrs) Location macro_locus = macro_path.get_locus (); - return std::unique_ptr ( - new AST::MacroInvocation (AST::MacroInvocData (std::move (macro_path), - std::move (delim_tok_tree)), - std::move (outer_attrs), macro_locus)); + return AST::MacroInvocation::Regular ( + AST::MacroInvocData (std::move (macro_path), std::move (delim_tok_tree)), + std::move (outer_attrs), macro_locus); } // Parses a macro rule definition - does not parse semicolons. @@ -9308,11 +9306,10 @@ Parser::parse_type (bool save_errors) AST::DelimTokenTree tok_tree = parse_delim_token_tree (); - return std::unique_ptr ( - new AST::MacroInvocation ( - AST::MacroInvocData (std::move (macro_path), - std::move (tok_tree)), - {}, locus)); + return AST::MacroInvocation::Regular ( + AST::MacroInvocData (std::move (macro_path), + std::move (tok_tree)), + {}, locus); } case PLUS: { // type param bounds @@ -10146,11 +10143,10 @@ Parser::parse_type_no_bounds () AST::DelimTokenTree tok_tree = parse_delim_token_tree (); - return std::unique_ptr ( - new AST::MacroInvocation ( - AST::MacroInvocData (std::move (macro_path), - std::move (tok_tree)), - {}, locus)); + return AST::MacroInvocation::Regular ( + AST::MacroInvocData (std::move (macro_path), + std::move (tok_tree)), + {}, locus); } default: // assume that this is a type path and not an error @@ -12010,18 +12006,17 @@ Parser::parse_path_based_stmt_or_expr ( { lexer.skip_token (); - std::unique_ptr stmt ( - new AST::MacroInvocation (std::move (invoc_data), - std::move (outer_attrs), - stmt_or_expr_loc, true)); + auto stmt + = AST::MacroInvocation::Regular (std::move (invoc_data), + std::move (outer_attrs), + stmt_or_expr_loc, true); return ExprOrStmt (std::move (stmt)); } // otherwise, create macro invocation - std::unique_ptr expr ( - new AST::MacroInvocation (std::move (invoc_data), - std::move (outer_attrs), - stmt_or_expr_loc, false)); + auto expr = AST::MacroInvocation::Regular (std::move (invoc_data), + std::move (outer_attrs), + stmt_or_expr_loc, false); return ExprOrStmt (std::move (expr)); } else @@ -12330,17 +12325,16 @@ Parser::parse_macro_invocation_maybe_semi ( { lexer.skip_token (); - std::unique_ptr stmt ( - new AST::MacroInvocation (std::move (invoc_data), - std::move (outer_attrs), macro_locus, - true)); + auto stmt = AST::MacroInvocation::Regular (std::move (invoc_data), + std::move (outer_attrs), + macro_locus, true); return ExprOrStmt (std::move (stmt)); } // otherwise, create macro invocation - std::unique_ptr expr ( - new AST::MacroInvocation (std::move (invoc_data), - std::move (outer_attrs), macro_locus)); + auto expr + = AST::MacroInvocation::Regular (std::move (invoc_data), + std::move (outer_attrs), macro_locus); return ExprOrStmt (std::move (expr)); } else @@ -14552,9 +14546,9 @@ Parser::parse_macro_invocation_partial ( Location macro_locus = converted_path.get_locus (); - return std::unique_ptr (new AST::MacroInvocation ( + return AST::MacroInvocation::Regular ( AST::MacroInvocData (std::move (converted_path), std::move (tok_tree)), - std::move (outer_attrs), macro_locus, restrictions.expr_can_be_stmt)); + std::move (outer_attrs), macro_locus, restrictions.expr_can_be_stmt); } /* Parses a struct expr struct with a path in expression already parsed (but From patchwork Wed Apr 5 14:03: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: 79654 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp344910vqo; Wed, 5 Apr 2023 07:21:01 -0700 (PDT) X-Google-Smtp-Source: AKy350aG6oomVTc+dE/KjUcHlWJvkBiIxnlObtFT3a+SKqOaIxgFk5TSMXh7WZ2oPaXmNgrjq/eZ X-Received: by 2002:a17:906:4547:b0:947:a6d8:6ea8 with SMTP id s7-20020a170906454700b00947a6d86ea8mr2772107ejq.21.1680704461791; Wed, 05 Apr 2023 07:21:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704461; cv=none; d=google.com; s=arc-20160816; b=L/xWJt6twbaInFGqCQSW6lepKBMNuXikdrhgbrUUBwn5+aBmDpALIPXKA5qLfRXKZT dtSAE3PjvNmEgIYfZ0hKSievVL+UyvdIE5jXyUw+KNvNPgvnC9WS5kHR5r2lUM3dv8tp UMC/44ZdsxT0mc9AgoRn/nv2xnp95SQiweGz6wOyDdEOdaxE3oxv46k9mMJD6FN1frlq 9fwh0DHUjMb/R2NEt9iXeZkPjQSAynDaY2ZQtKxJ+4DVEgLbWm9CGWZoeGR5U25Xl047 +VT1pcAl2BCIX9AeNPrbDtXCBPK6+zuY8AUIZZ9DYZUVq88hwsHJiXBz50oCzgF6v8Jm XN5g== 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=HcbuOV94LWC1C2MdNfwgmAGCZC9Vo6kcMiQCQqZU0eM=; b=IkbVtYPQsmtOx/r78hvR37gWEWX6opsq9FIKD8l3KG/MaJ4BmNKDGuJPK+sSrrGKUA wLbwuQBgshnMSfzcD6UgD3tTKoGERglmQdNRTlMbXOg0JJWdXTQAQJgaMd90KVEo1ybi XBZZFGxThhFPeo60I+yD8L9q9cFMhK9gttqAFCCBtAU1EXnuc4qO8dtF5PMaS5bfS/i0 A8Yt2gBbavdsGXz9e5WE+62FXSfL3EgXZQDot9kY6AWgbi6TRBCH12NGpfP3WADtPet3 AfAVjwwDSzS+WpDBj8lJY4ACIO/l6Ag6rNw0eqjMDzLXmRgZ/9zeiTxHgWhTey13WMzZ 1QKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=gK9liulf; 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 9-20020a170906218900b009377c5b6b0asi184595eju.275.2023.04.05.07.21.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:21:01 -0700 (PDT) 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=gK9liulf; 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 E523638ABF0B for ; Wed, 5 Apr 2023 14:10:13 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id 9367F3856DC7 for ; Wed, 5 Apr 2023 14:05:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9367F3856DC7 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-x32f.google.com with SMTP id o32so20949209wms.1 for ; Wed, 05 Apr 2023 07:05:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703545; 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=HcbuOV94LWC1C2MdNfwgmAGCZC9Vo6kcMiQCQqZU0eM=; b=gK9liulfTOH8LclOBwOVonz9348AH5qrySmAIoAewR2qwnvH1ZAHP2XNKylarFyghU fr7HKkGh9IiRiXeZHDsScpdeY6hsoLF8xXpi1iE+uoqpkSp5qxqcKdeo8UsEztmrW1B7 78gEuU7JZf7HQ3fL64kYxpAdq4Ob02jmcuABYWp64UMGVsSujJ6qQxBcpqnkERkDQj9b pTensMUyDKWeP6xVhnL7SGZGsJbYczVS2AJB+XWw12ynZAXWIJ3jzmBLfHC9HfZ80lWG D3pFwC1USpQOluqdVkP6ikRlgbWCN3MTOBme7QFtI/rpP+UG4iYr+71/WycxB0h/I4Da Tp/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703545; 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=HcbuOV94LWC1C2MdNfwgmAGCZC9Vo6kcMiQCQqZU0eM=; b=N3AY+HV/fzutMZd+fIdZpPo/1wHEVQMdfVnnRB4Ve/8kz5tNJzq9jtnbzcxkhA0S78 UU6XSwbJH7HfVzRVAgiFjg+/kG+cYBPQHgo/v368AwFI8dRtOxpVDdTI6oMCMvql3u+K SsPT9nfFcnBNgz2YLfRwBax2cyy5Pmsa441VmpAXEtxDFDrhsoUSzpWzG4iPUC7cGr3o fvfggfaGt4+WmIDpvdtOYifx3O7kUOxck5tccDLU6MloJc4l5M6Aen2Gb8a5xAeUKpHB P3udKfdU4+Hbt+qRyaAU488UP46JUQOLaxcT669JQ3maPx9273MSY0uA4PjaiVBjJuAO 9heA== X-Gm-Message-State: AAQBX9dMf/Hb9BToCm8HDH7E4Qbff5tKjzFUI9gTd2Whoga7OvG0XAQ+ graJ6EmK++SSCdoQxaOybr03Lb0CwkQLAfWgxw== X-Received: by 2002:a7b:c4c2:0:b0:3eb:38b0:e757 with SMTP id g2-20020a7bc4c2000000b003eb38b0e757mr2013971wmk.10.1680703544739; Wed, 05 Apr 2023 07:05:44 -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.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:44 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [committed 24/88] gccrs: Create and use CompilePatternLet visitor for compiling let statments Date: Wed, 5 Apr 2023 16:03:08 +0200 Message-Id: <20230405140411.3016563-25-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.6 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?1762346361504816095?= X-GMAIL-MSGID: =?utf-8?q?1762346361504816095?= From: Owen Avery gcc/rust/ChangeLog: * backend/rust-compile-pattern.cc (CompilePatternLet::visit): New function. * backend/rust-compile-stmt.cc (CompileStmt::visit): Likewise. * backend/rust-compile-pattern.h (class CompilePatternLet): New visitor. Signed-off-by: Owen Avery --- gcc/rust/backend/rust-compile-pattern.cc | 58 ++++++++++++++++ gcc/rust/backend/rust-compile-pattern.h | 87 ++++++++++++++++++++++++ gcc/rust/backend/rust-compile-stmt.cc | 31 +-------- 3 files changed, 148 insertions(+), 28 deletions(-) diff --git a/gcc/rust/backend/rust-compile-pattern.cc b/gcc/rust/backend/rust-compile-pattern.cc index 9218b815dd8..e13d6caf7e6 100644 --- a/gcc/rust/backend/rust-compile-pattern.cc +++ b/gcc/rust/backend/rust-compile-pattern.cc @@ -341,5 +341,63 @@ CompilePatternBindings::visit (HIR::GroupedPattern &pattern) pattern.get_item ()->accept_vis (*this); } +void +CompilePatternLet::visit (HIR::IdentifierPattern &pattern) +{ + Bvariable *var = nullptr; + rust_assert ( + ctx->lookup_var_decl (pattern.get_pattern_mappings ().get_hirid (), &var)); + + auto fnctx = ctx->peek_fn (); + if (ty->is_unit ()) + { + ctx->add_statement (init_expr); + + tree stmt_type = TyTyResolveCompile::compile (ctx, ty); + + auto unit_type_init_expr + = ctx->get_backend ()->constructor_expression (stmt_type, false, {}, -1, + rval_locus); + auto s = ctx->get_backend ()->init_statement (fnctx.fndecl, var, + unit_type_init_expr); + ctx->add_statement (s); + } + else + { + auto s + = ctx->get_backend ()->init_statement (fnctx.fndecl, var, init_expr); + ctx->add_statement (s); + } +} + +void +CompilePatternLet::visit (HIR::WildcardPattern &pattern) +{ + Bvariable *var = nullptr; + rust_assert ( + ctx->lookup_var_decl (pattern.get_pattern_mappings ().get_hirid (), &var)); + + auto fnctx = ctx->peek_fn (); + if (ty->is_unit ()) + { + ctx->add_statement (init_expr); + + tree stmt_type = TyTyResolveCompile::compile (ctx, ty); + + auto unit_type_init_expr + = ctx->get_backend ()->constructor_expression (stmt_type, false, {}, -1, + rval_locus); + auto s = ctx->get_backend ()->init_statement (fnctx.fndecl, var, + unit_type_init_expr); + ctx->add_statement (s); + } + else + { + auto s + = ctx->get_backend ()->init_statement (fnctx.fndecl, var, init_expr); + ctx->add_statement (s); + } +} + } // namespace Compile } // namespace Rust diff --git a/gcc/rust/backend/rust-compile-pattern.h b/gcc/rust/backend/rust-compile-pattern.h index 43334affca7..317a3451161 100644 --- a/gcc/rust/backend/rust-compile-pattern.h +++ b/gcc/rust/backend/rust-compile-pattern.h @@ -91,5 +91,92 @@ protected: tree match_scrutinee_expr; }; +class CompilePatternLet : public HIRCompileBase, public HIR::HIRPatternVisitor +{ +public: + static void Compile (HIR::Pattern *pattern, tree init_expr, + TyTy::BaseType *ty, Location rval_locus, Context *ctx) + { + CompilePatternLet compiler (ctx, init_expr, ty, rval_locus); + pattern->accept_vis (compiler); + } + + void visit (HIR::IdentifierPattern &) override; + void visit (HIR::WildcardPattern &) override; + + // check for unimplemented Pattern HIR nodes. + void visit (HIR::GroupedPattern &pattern) override + { + rust_sorry_at (pattern.get_locus (), + "grouped pattern let statements not supported"); + } + + void visit (HIR::LiteralPattern &pattern) override + { + rust_sorry_at (pattern.get_locus (), + "literal pattern let statements not supported"); + } + + void visit (HIR::PathInExpression &pattern) override + { + rust_sorry_at (pattern.get_locus (), + "path-in-expression pattern let statements not supported"); + } + + void visit (HIR::QualifiedPathInExpression &pattern) override + { + rust_sorry_at ( + pattern.get_locus (), + "qualified-path-in-expression pattern let statements not supported"); + } + + void visit (HIR::RangePattern &pattern) override + { + rust_sorry_at (pattern.get_locus (), + "range pattern let statements not supported"); + } + + void visit (HIR::ReferencePattern &pattern) override + { + rust_sorry_at (pattern.get_locus (), + "reference pattern let statements not supported"); + } + + void visit (HIR::SlicePattern &pattern) override + { + rust_sorry_at (pattern.get_locus (), + "slice pattern let statements not supported"); + } + + void visit (HIR::StructPattern &pattern) override + { + rust_sorry_at (pattern.get_locus (), + "struct pattern let statements not supported"); + } + + void visit (HIR::TuplePattern &pattern) override + { + rust_sorry_at (pattern.get_locus (), + "tuple pattern let statements not supported"); + } + + void visit (HIR::TupleStructPattern &pattern) override + { + rust_sorry_at (pattern.get_locus (), + "tuple-struct pattern let statements not supported"); + } + +protected: + CompilePatternLet (Context *ctx, tree init_expr, TyTy::BaseType *ty, + Location rval_locus) + : HIRCompileBase (ctx), init_expr (init_expr), ty (ty), + rval_locus (rval_locus) + {} + + tree init_expr; + TyTy::BaseType *ty; + Location rval_locus; +}; + } // namespace Compile } // namespace Rust diff --git a/gcc/rust/backend/rust-compile-stmt.cc b/gcc/rust/backend/rust-compile-stmt.cc index 3fc2528ff6b..6bb4ead9451 100644 --- a/gcc/rust/backend/rust-compile-stmt.cc +++ b/gcc/rust/backend/rust-compile-stmt.cc @@ -16,6 +16,7 @@ // along with GCC; see the file COPYING3. If not see // . +#include "rust-compile-pattern.h" #include "rust-compile-stmt.h" #include "rust-compile-expr.h" @@ -53,7 +54,7 @@ CompileStmt::visit (HIR::LetStmt &stmt) if (!stmt.has_init_expr ()) return; - const HIR::Pattern &stmt_pattern = *stmt.get_pattern (); + HIR::Pattern &stmt_pattern = *stmt.get_pattern (); HirId stmt_id = stmt_pattern.get_pattern_mappings ().get_hirid (); TyTy::BaseType *ty = nullptr; @@ -65,15 +66,6 @@ CompileStmt::visit (HIR::LetStmt &stmt) return; } - Bvariable *var = nullptr; - if (!ctx->lookup_var_decl (stmt_id, &var)) - { - // FIXME this should be an assertion instead and use error mark node - rust_fatal_error (stmt.get_locus (), - "failed to lookup compiled variable declaration"); - return; - } - tree init = CompileExpr::Compile (stmt.get_init_expr (), ctx); // FIXME use error_mark_node, check that CompileExpr returns error_mark_node // on failure and make this an assertion @@ -84,7 +76,6 @@ CompileStmt::visit (HIR::LetStmt &stmt) bool ok = ctx->get_tyctx ()->lookup_type ( stmt.get_init_expr ()->get_mappings ().get_hirid (), &actual); rust_assert (ok); - tree stmt_type = TyTyResolveCompile::compile (ctx, ty); Location lvalue_locus = stmt.get_pattern ()->get_locus (); Location rvalue_locus = stmt.get_init_expr ()->get_locus (); @@ -92,23 +83,7 @@ CompileStmt::visit (HIR::LetStmt &stmt) init = coercion_site (stmt.get_mappings ().get_hirid (), init, actual, expected, lvalue_locus, rvalue_locus); - auto fnctx = ctx->peek_fn (); - if (ty->is_unit ()) - { - ctx->add_statement (init); - - auto unit_type_init_expr - = ctx->get_backend ()->constructor_expression (stmt_type, false, {}, -1, - rvalue_locus); - auto s = ctx->get_backend ()->init_statement (fnctx.fndecl, var, - unit_type_init_expr); - ctx->add_statement (s); - } - else - { - auto s = ctx->get_backend ()->init_statement (fnctx.fndecl, var, init); - ctx->add_statement (s); - } + CompilePatternLet::Compile (&stmt_pattern, init, ty, rvalue_locus, ctx); } } // namespace Compile From patchwork Wed Apr 5 14:03: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: 79662 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp345860vqo; Wed, 5 Apr 2023 07:22:15 -0700 (PDT) X-Google-Smtp-Source: AKy350a2vTBj/DFg6K2FqcIsZrbS1FdVJKc0voUx8e6V+4gcaZaFzX8tvFR6oZZ+SnrM6yDwFGkJ X-Received: by 2002:a05:6402:442:b0:4fa:d75c:16cd with SMTP id p2-20020a056402044200b004fad75c16cdmr2108746edw.34.1680704535566; Wed, 05 Apr 2023 07:22:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704535; cv=none; d=google.com; s=arc-20160816; b=kWNodstLW84iU7gDcPyCl4yILFFbFlYHnb2N++E/aZ7c28QPWXJOkdsNa4Z1+aP1Tp tKxckIl2N/SOFldr6wa8SZCawUlxSSCDQ+hchUQMPnnvRIr55/BXZJIX1CWs5kNOH4IG +5E2UtGAps7BOnQRKQEQ9wqPyidQyjcEvctZFmHqMjAWVu0UVSaezeEIIZ9j+iNtKfCN z4iJ3pjKnUH7p8qQk5+oJAwwTq0n2YjZtiteVKFZ9t3UzkB9EuLC9mAqp7NO+hU2fVHW GB7VRtJiyjhbmpDyqiGwEpV0UEpqOzzwoEvVbWKeY45LjGvS5J6iUNtCLrZQrutfpdSt YgvQ== 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=QakCs6H3M9FTFnLP6py8l673boYHcq3ipw/eJQMIuOQ=; b=f4wpaOPR1ln3TEcI84lKQUQ+BviguVcoi3rcxC/FTcugdZ0f8aOuZSGir9KeyYQFTR sTBsVKKtmBLTsbgR9OZD3atxWpuYsKizdi7TPf0UZC7uyE2SvZ/ND2yCQCZH8juWUpAi h9auyp6IjcN0HQlLTr7GDDrKJukaCMoNlhneiLmxluPqgqO+gxmeUDjW20TThwtwC4i+ bpQReE8/eI2vd4vvZvTHcFOjvJUzFBdgX8cuDwonw0+gQ9XgDcHcifd9DsGZELCUiaB3 lNUM7kHhK+sl8IMo0Rn7AWOFJ28kfKBC3cgz02VaFN3Oi2T7v7ywG63KKOGLy1p6GQS/ gPbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=hE6xnLGz; 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 f8-20020a056402004800b004ab162a8415si1211519edu.283.2023.04.05.07.22.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:22:15 -0700 (PDT) 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=hE6xnLGz; 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 D92FB385B53D for ; Wed, 5 Apr 2023 14:10:30 +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 B1C02385735A for ; Wed, 5 Apr 2023 14:05:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B1C02385735A 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 n10-20020a05600c4f8a00b003ee93d2c914so23482056wmq.2 for ; Wed, 05 Apr 2023 07:05:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703545; 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=QakCs6H3M9FTFnLP6py8l673boYHcq3ipw/eJQMIuOQ=; b=hE6xnLGzQl6qb6TUxuZwYni+kdQmcnfGdMDxFsdwG7d5A/SSZDvUH6LG7tvAzHF8ZJ 598sFqUMKphX0oP3Fw3ZuRWmGfkdMthNwfzlUDU8LP/r4haAv0ZEG2lqhkXlXQM8T3bx Ww2Iapk4O6qT3Xdzdcl4nt1OXv7+CzBn9nwcJ95Sieh0K16vU8zl+NsVRci4B/FxIy9n tiK+Z8OyToJEnPFZF8xzUg79thl0mXdxlBPnAcsO9aQslMEtlOE5XXyZyodjGUBRSWmm 9HntkcO6iYwT3MRHRSQQB3nQjLj1PZ3Razky06PzEnUjej8xeMhr51sNjOy3HZ908vqc 4w9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703545; 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=QakCs6H3M9FTFnLP6py8l673boYHcq3ipw/eJQMIuOQ=; b=hTD89U5IWGNYOtJJCkOmswn4QQeX6S90bNFvzlPW1AIcE6FDVjMEWbMOJGxGLLHtf+ o7o04xkGlUGPa2k1CS0HdUiYYmdj0GMuhqugI7HBQrri59oH+8jyX1lUXlIPgFy0FSOM i9PtCGoOi+rkBG246+YEXnta8KpPgPBrGP+VUc2DBqTtqDdNYbnpIGpWEnLjAPxbNC6x d/vCl2H5w3/2JpjrAWypKgEkFjiCfqC9tQHCnpa9FktxagI/1oAYwhGiKC7GHWHGUu8B zYy10bnJNxOe2eS9RBTVTVgZMhlaDctKQvhBPWUHkfpAMk5dMDDfk7HPpjQIeWh5qiUt fbGw== X-Gm-Message-State: AAQBX9eHFw42m3TVhDoUYM8eQXgOUhtwZYbWwoRMMUaAp2/xXS7FZzwe uJIVuZaYytJC41cM43ySNJXo9slbsRWY0L7JOQ== X-Received: by 2002:a7b:cb86:0:b0:3df:e41f:8396 with SMTP id m6-20020a7bcb86000000b003dfe41f8396mr4657384wmi.37.1680703545251; Wed, 05 Apr 2023 07:05:45 -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.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:45 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 25/88] gccrs: parser: Allow parsing multiple reference types Date: Wed, 5 Apr 2023 16:03:09 +0200 Message-Id: <20230405140411.3016563-26-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?1762346439305355688?= X-GMAIL-MSGID: =?utf-8?q?1762346439305355688?= From: Arthur Cohen The parser now recursively tries to parse a reference type after seeing a `&` or `&&` token. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_type): Handle double ampersan properly (Parser::parse_reference_type): Call into `parse_reference_type_inner` and wrap double reference types in another `AST::ReferenceType` node (Parser::parse_reference_type_inner): Add parsing implementation which does not care about the leading token (& or &&) (Parser::parse_type_no_bounds): Handle double ampersand properly * parse/rust-parse.h: Declare `parse_reference_type_inner` gcc/testsuite/ChangeLog: * rust/compile/multi_reference_type.rs: New test. --- gcc/rust/parse/rust-parse-impl.h | 33 +++++++++++++++---- gcc/rust/parse/rust-parse.h | 2 ++ .../rust/compile/multi_reference_type.rs | 12 +++++++ 3 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/rust/compile/multi_reference_type.rs diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index a0bc2e10d2f..23b033fb26e 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -9237,6 +9237,7 @@ Parser::parse_type (bool save_errors) // raw pointer type return parse_raw_pointer_type (); case AMP: // does this also include AMP_AMP? + case LOGICAL_AND: // reference type return parse_reference_type (); case LIFETIME: { @@ -9886,14 +9887,10 @@ Parser::parse_bare_function_type ( std::move (return_type), best_try_locus)); } -// Parses a reference type (mutable or immutable, with given lifetime). template std::unique_ptr -Parser::parse_reference_type () +Parser::parse_reference_type_inner (Location locus) { - Location locus = lexer.peek_token ()->get_locus (); - skip_token (AMP); - // parse optional lifetime AST::Lifetime lifetime = AST::Lifetime::error (); if (lexer.peek_token ()->get_id () == LIFETIME) @@ -9932,6 +9929,29 @@ Parser::parse_reference_type () std::move (lifetime))); } +// Parses a reference type (mutable or immutable, with given lifetime). +template +std::unique_ptr +Parser::parse_reference_type () +{ + auto t = lexer.peek_token (); + auto locus = t->get_locus (); + + switch (t->get_id ()) + { + case AMP: + skip_token (AMP); + return parse_reference_type_inner (locus); + case LOGICAL_AND: + skip_token (LOGICAL_AND); + return std::unique_ptr ( + new AST::ReferenceType (false, parse_reference_type_inner (locus), + locus)); + default: + gcc_unreachable (); + } +} + // Parses a raw (unsafe) pointer type. template std::unique_ptr @@ -10079,7 +10099,8 @@ Parser::parse_type_no_bounds () case ASTERISK: // raw pointer type return parse_raw_pointer_type (); - case AMP: // does this also include AMP_AMP? + case AMP: // does this also include AMP_AMP? Yes! Which is... LOGICAL_AND? + case LOGICAL_AND: // reference type return parse_reference_type (); case LIFETIME: diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index 5c0fcc3f174..2f767bb2a53 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -604,6 +604,8 @@ private: std::unique_ptr parse_type_no_bounds (); std::unique_ptr parse_slice_or_array_type (); std::unique_ptr parse_raw_pointer_type (); + std::unique_ptr + parse_reference_type_inner (Location locus); std::unique_ptr parse_reference_type (); std::unique_ptr parse_bare_function_type (std::vector for_lifetimes); diff --git a/gcc/testsuite/rust/compile/multi_reference_type.rs b/gcc/testsuite/rust/compile/multi_reference_type.rs new file mode 100644 index 00000000000..5ad7d84adbc --- /dev/null +++ b/gcc/testsuite/rust/compile/multi_reference_type.rs @@ -0,0 +1,12 @@ +fn main() { + let a = 15u8; + let a: &u8 = &a; + let a: &&u8 = &a; + let a: &&&u8 = &a; + let _: &&&&u8 = &a; + + let _: &&u8; + let _: &mut &u8; + let _: &&mut u8; + let _: &mut &mut &u8; +} From patchwork Wed Apr 5 14:03: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: 79667 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp346490vqo; Wed, 5 Apr 2023 07:23:13 -0700 (PDT) X-Google-Smtp-Source: AKy350YVkWZ70EK0E/twJgWtKkfdGYUEIu0diM6dYh5lNU4yxyFRZ/Real06cl3OZwChGQPq58v9 X-Received: by 2002:a17:906:844c:b0:948:c047:477d with SMTP id e12-20020a170906844c00b00948c047477dmr2983777ejy.22.1680704593463; Wed, 05 Apr 2023 07:23:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704593; cv=none; d=google.com; s=arc-20160816; b=gIPhuhNTpYQ1zhUuU4gjeGD5Z+UIBal5qhDSjY87vYPGtS52PAmJvwnK1JuKFrlmuq bmhTtXkTa1GGkuj47hAoqjfw5QO8+TRtAJT4d/RywZTv13hKYUeeR/45+yLfNls10fDE 21AfsBIngTDl5J3f+FcCcfGc6jzD3OGlOkXMef7CJ85GqJo2gHcyur+pJMsU18yu38Iq XSLiPx98VtO3ItT8GRFnth9ruDv9CEal89CRQc6Bj+RpvDrw2H0iooUbm1Z2/DL/4VwO QCONUA24yjav1bv8Fuf2q6xzBETN6KGYghTSOG0leMpBOsUyeEf39Y5fgK4OBbuoniAR s8gw== 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=vuIL/HfJX9pgiMKtUJfVGb8QqLuJ/GMhmTEGRiwbmSM=; b=Rl/m0F8Wbb5ug2StHe/6xhJlMv0dyKFJMLVWbLffrgrHIs1UwAKUUfpKANyVFuiLCz vIVAI9pprTTmvUBH92CoZvG+XU1EgBrw0ZHkh2mXNT3oDNLseu3kJbsRJOjIEQhR0ZM5 75G9joX3ldjRmSJS7YD6GjsJvbzNqG3vt13aoyhpc7r/DdFdYtdEfRhILV7sBlnC1BKK 0DhmSVB1+qbfbLuQJ3TDE/nl2SJFhhPgDx8gvf6KJ4Mo5bigfRrDWWhvdnPpTR4BwuyW pspg9D++u9J9hjl+sOLJ1rLS9dEb+R2iW9q3+yRxrphZ+rdIbuC4724n2gYb/XJczkqT 9f3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=e4sIOpSk; 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 u21-20020a17090617d500b009272de342c3si1615708eje.927.2023.04.05.07.23.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:23:13 -0700 (PDT) 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=e4sIOpSk; 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 1B2E23881D00 for ; Wed, 5 Apr 2023 14:10:45 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id 692003856DD7 for ; Wed, 5 Apr 2023 14:05:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 692003856DD7 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-x32c.google.com with SMTP id p34so20957935wms.3 for ; Wed, 05 Apr 2023 07:05:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703547; 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=vuIL/HfJX9pgiMKtUJfVGb8QqLuJ/GMhmTEGRiwbmSM=; b=e4sIOpSkbWUhNOmKPVte46wKH7UVbKht7mWSJaTyKw/WNpULqwQFp1odmaf/HVjqYC iltwsbmQw9UgqzNqXL4uqQ2cJ4egAEzYT3JAK2S9QTJJ0S/0ET8b6hILUpg8gjw7Xspt e7BGjdg72FKoKfSDyYCMBYmZlgEmNTaOcXabEcPB7BuS6dE33xTlVa3VkDJ7fhtdt66B +kSGltrF2fs7ArG/qdM5ACLca0wvxN1Ec35hWqcpGvU2AWVzfMOhbO/dn61/1QLIb2ri wr3UyPDURWVGWyjMI4J6s1KNR6OBuJRkoutA0OXg/jsP5Zf5tsuIYWr6AA2qAl0dpcGR 59Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703547; 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=vuIL/HfJX9pgiMKtUJfVGb8QqLuJ/GMhmTEGRiwbmSM=; b=ib7VcX4VlekIHnlHL444YzsCYGWzPLBK0d0B4wIoiG6t4MGBXWqatEWqTHYfK6z1/S UzbheAv1kx5pclrVZsmtsj1JhaTS2FId5PO1Z+gW9Z1EcVdtjOUU646X/wW5JayTTW0r G2ivKDKc/Hc3ag1RXQIfkXI1zZt/+xsOqG54GbASpvQoNtvy49EUGubZdr7cqv+xcij0 9SWQbMStaVSBhM9cbwLbVOoC2mv6Jg5CkztR9p6Rdc6WebeDi2dpTL1dI8B4rAXiMFrH 1ywmkgjLwFjIerTq6BAuPHZWYU6RG40Rh1Fvh7UhYK8rCBR8EOwv91Lxa6T9sHxZmIe/ uNNw== X-Gm-Message-State: AAQBX9dkvQIUoDogijKTmV1664s4nFN6BZ/gBFTgL4UJWgagH2MLHN2H tKRIqCoYeVCq2an7Pa/AGn7jLJri/w1WjgflUQ== X-Received: by 2002:a05:600c:283:b0:3ed:346d:452f with SMTP id 3-20020a05600c028300b003ed346d452fmr4704294wmk.26.1680703546022; Wed, 05 Apr 2023 07:05:46 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:45 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, MAHAD Subject: [committed 26/88] gccrs: Move rust-buffered-queue.h to util folder #1766 Date: Wed, 5 Apr 2023 16:03:10 +0200 Message-Id: <20230405140411.3016563-27-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.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, 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?1762346500166725957?= X-GMAIL-MSGID: =?utf-8?q?1762346500166725957?= From: MAHAD gcc/rust/ChangeLog: * rust-buffered-queue.h: Moved to... * util/rust-buffered-queue.h: ...here. Signed-off-by: Muhammad Mahad --- gcc/rust/{ => util}/rust-buffered-queue.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename gcc/rust/{ => util}/rust-buffered-queue.h (100%) diff --git a/gcc/rust/rust-buffered-queue.h b/gcc/rust/util/rust-buffered-queue.h similarity index 100% rename from gcc/rust/rust-buffered-queue.h rename to gcc/rust/util/rust-buffered-queue.h From patchwork Wed Apr 5 14:03: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: 79670 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp347316vqo; Wed, 5 Apr 2023 07:24:26 -0700 (PDT) X-Google-Smtp-Source: AKy350ZJbJ+Nhk+onz/uodBegBN3Ao/TJPpV5wCd08UOOjwMospdnjLR260abVWKXS+j9KyzhlpQ X-Received: by 2002:a17:906:280a:b0:8aa:33c4:87d5 with SMTP id r10-20020a170906280a00b008aa33c487d5mr2808364ejc.10.1680704666672; Wed, 05 Apr 2023 07:24:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704666; cv=none; d=google.com; s=arc-20160816; b=0H5uci0k4SPHsUqW/G/pW6AQGphhTe7CQ9T8X3Ybk8VZf6PROmGPHNdUFjpbPijGI1 Suj9+E1K9wlZJSnPWDlCXDeVXFHdvDGUTimSvYu6VZxmhLEC1te1LmQ+5zGpNB6kx3xC hrBbUTqBXBDvwpnphE9tUmZBmf56ZohvojFwCzDwFrFUANGWWiH1sUweUelCMFE58Mus E1xjdq1sMTAgj8MnndlUqK5LF0h5vU/924IyZD5gdPrdGE8gKF+05PvhtzgJKn1zGAiT 07guNTFvdI+Iz22CrxE+9dnV5apG5GWRqhNZMusXEIssNaeOw/r8QOyLJmGjoV3IjpBi k1cw== 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=0KlPUlrXdqre4uyKtTF0IFsFUnw78mID3C6zmKeCKjA=; b=wiMHmoVow0YKNRt68/m1XxXJfy0LuGt7Lxwcbjz/th+1CtMO13pTQlNWi90vLK5C7M Fhkku0M50N7c6e9ER/IIYw/FCajt2nty9o2WMTYXvBxMQcguqFCn1nqH1OGLsbjNXY78 ZbFTdHRYPYtIBaTnerIZVgaBTZRcZ2LfPGinsi/x/cNOOtpMxTPbTUl5KA6oEGW5+StM QN2vCOGlCX93L3hkvg08rdtApxPg3JytSwbYo/n7iPNo/WOKS0oFqMx5N/yL49UIfMK6 G/IVfQza5T7qhwSjIxGcwQnPd5Wy4D/fQIdAr16W7KP2Q9FuXRKNOcAt9qi/viuTbCfP JUBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b="M5/jf9u6"; 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 lc7-20020a170906f90700b008cbb481fc84si9632862ejb.20.2023.04.05.07.24.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:24:26 -0700 (PDT) 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="M5/jf9u6"; 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 C63E1383024B for ; Wed, 5 Apr 2023 14:11:01 +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 12D0F385703C for ; Wed, 5 Apr 2023 14:05:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 12D0F385703C 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 he13so1340566wmb.2 for ; Wed, 05 Apr 2023 07:05:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703547; 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=0KlPUlrXdqre4uyKtTF0IFsFUnw78mID3C6zmKeCKjA=; b=M5/jf9u6F+6l5SufZWCmq4hbPYZSpET5aLlui5JoPwJO8eEZKXQ0tfNKfOz0fp81jg /J8gidW+8KOilCXoa5hy4BnSU94GlrlQl1y98wNTvzR2CVFjAXaltfpWvGkIFn0JYEVj hRfh3HDWVtnWzL+xEFhppX81UAFVJLv0n/9rTNfkzm/AqDrKa6mIwKu321Mq0ttzzMmu Soosrox93N+YN1dBE/ajBtJD4ylh0rAhRSd2Wijjk1jfdpg1VxOAEUzxaAiyd/qSRjvl gaToFJCo7D71jEfFNqwAy/2NooUVy4OO+k2Qg2clpkpqlEiN6Oxze0PwUf9ZigTMUErC NaWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703547; 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=0KlPUlrXdqre4uyKtTF0IFsFUnw78mID3C6zmKeCKjA=; b=KlAiqG0IV/UsJ7bYpaykhq7H9+y5cfrOSzNvuu6b8ukf6+mZkce6pdNEURAsAZBkbe GZyJJtpTJmSmhNkh9SPcdT2V3mUEGLO9O50uBhdLp61LLNXrs9Uhg8wkEIkxR/aDQe2v LkEL1wX1Uu8AJju095oD1fCfS710qKMNOU3mKkE7K9A7YYTgshTJqHg5DfEabKDUX6/l 7C/mxvTjvbX76SlczRNLSN9XQPCTnaR9R3ktwtsHdWjKJyECkC/0J6ihJ9OVOSC27973 JQi+ovDMjY/zYKD8rh5wmRarF7I6AoyFkL5+D4MKaU8NnZXwG+4WH0re/zgsyF3EcUhI tjQg== X-Gm-Message-State: AAQBX9e/ikfTh9l67EMgWRXwz2LLJgjSRn2xzr5njks6Vdzspir39+W0 P0geFGU1wiHUrq0Rg02O7mNqTuW5MXXn18pTRA== X-Received: by 2002:a1c:7c11:0:b0:3ee:289a:4382 with SMTP id x17-20020a1c7c11000000b003ee289a4382mr5122772wmc.8.1680703547421; Wed, 05 Apr 2023 07:05:47 -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.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:46 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [committed 27/88] gccrs: Improve GroupedPattern lowering Date: Wed, 5 Apr 2023 16:03:11 +0200 Message-Id: <20230405140411.3016563-28-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.6 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?1762346576649462532?= X-GMAIL-MSGID: =?utf-8?q?1762346576649462532?= From: Owen Avery gcc/rust/ChangeLog: * hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Lower AST::GroupedPattern to its inner pattern. Signed-off-by: Owen Avery --- gcc/rust/hir/rust-ast-lower-pattern.cc | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/gcc/rust/hir/rust-ast-lower-pattern.cc b/gcc/rust/hir/rust-ast-lower-pattern.cc index 8ee3a979a33..a0fd8dded38 100644 --- a/gcc/rust/hir/rust-ast-lower-pattern.cc +++ b/gcc/rust/hir/rust-ast-lower-pattern.cc @@ -246,17 +246,7 @@ ASTLoweringPattern::visit (AST::RangePattern &pattern) void ASTLoweringPattern::visit (AST::GroupedPattern &pattern) { - auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, pattern.get_node_id (), - mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); - - HIR::Pattern *inner - = ASTLoweringPattern::translate (pattern.get_pattern_in_parens ().get ()); - - translated - = new HIR::GroupedPattern (mapping, std::unique_ptr (inner), - pattern.get_locus ()); + pattern.get_pattern_in_parens ()->accept_vis (*this); } } // namespace HIR From patchwork Wed Apr 5 14:03: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: 79672 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp348049vqo; Wed, 5 Apr 2023 07:25:33 -0700 (PDT) X-Google-Smtp-Source: AKy350awTDqIRuxL1gBuoHKAaLzztOkjdQ713sAbw3vVeoUEwVJfS/KHknGhjEdJiqfHqUA595FJ X-Received: by 2002:a17:906:4910:b0:931:2f49:c040 with SMTP id b16-20020a170906491000b009312f49c040mr3299278ejq.51.1680704733126; Wed, 05 Apr 2023 07:25:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704733; cv=none; d=google.com; s=arc-20160816; b=xfkHK20HrySW7OAdu1lg00T/yA8jdlAfYfkvEy8tkwsbpzZHdFkI6UVBrTtLvrHl2w IJyAY+VWQWok2CrLCb2nFzCmwHj2LLAm8e2V1VjMmesfVOx5nJiV/hL0Y1+WXTN/aA4u zh9Hi8WHzi4oFiqIna2ZpsO3SwwUNLhRulux8eekdEKhvGGQ1tLgYE7CohrGjYRi2u3s rg9PYhVCCrxlpy/765CHIjqaIyu67Afn2/32Q5fWgprZlnx6FNnja8mZ/caEEN8fTfI0 9vmavt31CIAzZdq8F6kbpUz+maNV5uCEki1mpgVZKhDi4eXOMwuGtuZJzBc42MgWYphM VE7g== 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=7M/j+prtAdg5/Ga2UZA8D2V2bN2jQPO2st4o1MLsKTQ=; b=xggUAw9O3WyDhjkyMubUrqIc7GioGB0iehIeaC+L9qqWh5E2fsHPYI+zSYGIJLwCa1 1Y+IvKJ4/wLDWt/Zl9RAvC036rsPo/TPOBngVKvvc9qL6DMTpw+AOJ1NTqWsIOAOiZU5 IXyQuA2h+cxvyYIiGSrqMDVZYUSnwpBm08Va1pcMRJvYYSbbY+6IsgSJVsNIGSHpUpkL U/XqlJdzNVFbUHRursYZnL/nBQlImgha0jo6anPVrenp4qZUKfrOvw4s8oQ8pH/+d9cz YvDb4nHpGT4vAeAsqtL0bkgLWnHfWjxs3nqPHdaw7Iy6+vgfxMPiBzu7/wHEVT4fviGe 4hNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Pvse7NMu; 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 e26-20020a056402089a00b00501d7ce6144si3572810edy.474.2023.04.05.07.25.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:25:33 -0700 (PDT) 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=Pvse7NMu; 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 C47173ACBC9A for ; Wed, 5 Apr 2023 14:11:16 +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 98BB1385703E for ; Wed, 5 Apr 2023 14:05:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 98BB1385703E 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 s13so20939458wmr.4 for ; Wed, 05 Apr 2023 07:05:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703548; 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=7M/j+prtAdg5/Ga2UZA8D2V2bN2jQPO2st4o1MLsKTQ=; b=Pvse7NMuD7OAooWWgNTaMEj6iyC1EdGIzbADKr+56hCMr1u+9VB/wYgimk6iu8aszr 29KfvzL4071HnYJQJGAyzpldOlA1n2liCxInGZoImN3enOyXKvLZd4KSfI5OI+DWa/j2 S5utlNMuNPXT1I4pHh+DNI/qc7/5VZ+0MHxjp+4LDcUh4DN/P2Nqq/8k4hwkumy7Ej8P a11JNjdFFJPOq+Incd/20h13xlXBZlzBZp2w2EdDC3YyzIgWRUCm2hg9SR6LYLtIqD7a lzU9RE9P44z+HM4CEpaeE5Lx5tpo9P/H4jZxBYCTAKSwF5qTEh8Swi2rG7HdVWL2CcB4 Y8XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703548; 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=7M/j+prtAdg5/Ga2UZA8D2V2bN2jQPO2st4o1MLsKTQ=; b=csuaL4Ws+HQFRlotnFlQnOIZv11ToolyjxV6kINx0GiluzJzXdpuiVF2yiAbl3oGop p3o7TgCKpEOGGWjg66sQzsKoAeyBOU3XPoQZ9GsiYyPVHAiMtCOLkubOM9McudvNXdcD 0AxKiMwgi2we5FLUdMwbRKgQbmUqxg8UeRLOuuiy6UtrWHMGTd2rWZMw91sHOiWSi675 64ntITZmv98dJxjx0RXfVdrjAXACBaAHAKV5ldgFpSLBgTO2pjuljJLql1ujr4bUanzf qQW62VPlSKFji8zjzKiro5obHDbhmjnCbEE1U50C2x5lJYzFt3e+7iEMRciUQf5CHA+E SiYw== X-Gm-Message-State: AAQBX9dYWiNh2m60QnX7WNLxYwCK4QfORaS3w7P+g4+Z1avmUItX4XzD f0OV/Wo3Ji8hCfLa3hyhmJb4vx1zS5nlvus6lA== X-Received: by 2002:a7b:ca54:0:b0:3f0:3c2:3fa4 with SMTP id m20-20020a7bca54000000b003f003c23fa4mr4878729wml.12.1680703548052; Wed, 05 Apr 2023 07:05:48 -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.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:47 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [committed 28/88] gccrs: Remove HIR::GroupedPattern Date: Wed, 5 Apr 2023 16:03:12 +0200 Message-Id: <20230405140411.3016563-29-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.6 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?1762346645790134968?= X-GMAIL-MSGID: =?utf-8?q?1762346645790134968?= From: Owen Avery gcc/rust/ChangeLog: * backend/rust-compile-fnparam.h (CompileFnParam::visit): Remove HIR::GroupedPattern visitor. * backend/rust-compile-pattern.cc (CompilePatternCaseLabelExpr::visit): Remove HIR::GroupedPattern visitor. (CompilePatternBindings::visit): Remove HIR::GroupedPattern visitor. * backend/rust-compile-pattern.h (CompilePatternCaseLabelExpr::visit): Remove HIR::GroupedPattern visitor. (CompilePatternBindings::visit): Remove HIR::GroupedPattern visitor. (CompilePatternLet::visit): Remove HIR::GroupedPattern visitor. * backend/rust-compile-resolve-path.h (ResolvePathRef::visit): Remove HIR::GroupedPattern visitor. * backend/rust-compile-var-decl.h (CompileVarDecl::visit): Remove HIR::GroupedPattern visitor. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Remove HIR::GroupedPattern visitor. * checks/errors/rust-const-checker.h (ConstChecker::visit): Remove HIR::GroupedPattern visitor. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Remove HIR::GroupedPattern visitor. * checks/errors/rust-unsafe-checker.h (UnsafeChecker::visit): Remove HIR::GroupedPattern visitor. * hir/rust-hir-dump.cc (Dump::visit): Remove HIR::GroupedPattern visitor. * hir/rust-hir-dump.h (Dump::visit): Remove HIR::GroupedPattern visitor. * hir/tree/rust-hir-full-decls.h (class GroupedPattern): Remove class. * hir/tree/rust-hir-full-test.cc (GroupedPattern::accept_vis): Remove method. * hir/tree/rust-hir-pattern.h (class GroupedPattern): Remove class. * hir/tree/rust-hir-visitor.h (HIRFullVisitor::visit): Remove HIR::GroupedPattern visitor. (HIRFullVisitorBase::visit): Remove HIR::GroupedPattern visitor. (HIRPatternVisitor::visit): Remove HIR::GroupedPattern visitor. * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Remove HIR::GroupedPattern visitor. * typecheck/rust-hir-type-check-pattern.h (TypeCheckPattern::visit): Remove HIR::GroupedPattern visitor. Signed-off-by: Owen Avery --- gcc/rust/backend/rust-compile-fnparam.h | 1 - gcc/rust/backend/rust-compile-pattern.cc | 12 ---- gcc/rust/backend/rust-compile-pattern.h | 8 --- gcc/rust/backend/rust-compile-resolve-path.h | 1 - gcc/rust/backend/rust-compile-var-decl.h | 1 - gcc/rust/checks/errors/rust-const-checker.cc | 4 -- gcc/rust/checks/errors/rust-const-checker.h | 1 - gcc/rust/checks/errors/rust-unsafe-checker.cc | 4 -- gcc/rust/checks/errors/rust-unsafe-checker.h | 1 - gcc/rust/hir/rust-hir-dump.cc | 3 - gcc/rust/hir/rust-hir-dump.h | 1 - gcc/rust/hir/tree/rust-hir-full-decls.h | 1 - gcc/rust/hir/tree/rust-hir-full-test.cc | 12 ---- gcc/rust/hir/tree/rust-hir-pattern.h | 69 ------------------- gcc/rust/hir/tree/rust-hir-visitor.h | 3 - .../typecheck/rust-hir-type-check-pattern.cc | 9 --- .../typecheck/rust-hir-type-check-pattern.h | 1 - 17 files changed, 132 deletions(-) diff --git a/gcc/rust/backend/rust-compile-fnparam.h b/gcc/rust/backend/rust-compile-fnparam.h index 0d99814a6b3..10e8b67c140 100644 --- a/gcc/rust/backend/rust-compile-fnparam.h +++ b/gcc/rust/backend/rust-compile-fnparam.h @@ -39,7 +39,6 @@ public: void visit (HIR::TupleStructPattern &) override; // Empty visit for unused Pattern HIR nodes. - void visit (HIR::GroupedPattern &) override {} void visit (HIR::LiteralPattern &) override {} void visit (HIR::PathInExpression &) override {} void visit (HIR::QualifiedPathInExpression &) override {} diff --git a/gcc/rust/backend/rust-compile-pattern.cc b/gcc/rust/backend/rust-compile-pattern.cc index e13d6caf7e6..bad98be44d0 100644 --- a/gcc/rust/backend/rust-compile-pattern.cc +++ b/gcc/rust/backend/rust-compile-pattern.cc @@ -161,12 +161,6 @@ CompilePatternCaseLabelExpr::visit (HIR::RangePattern &pattern) case_label_expr = build_case_label (lower, upper, associated_case_label); } -void -CompilePatternCaseLabelExpr::visit (HIR::GroupedPattern &pattern) -{ - pattern.get_item ()->accept_vis (*this); -} - // setup the bindings void @@ -335,12 +329,6 @@ CompilePatternBindings::visit (HIR::StructPattern &pattern) } } -void -CompilePatternBindings::visit (HIR::GroupedPattern &pattern) -{ - pattern.get_item ()->accept_vis (*this); -} - void CompilePatternLet::visit (HIR::IdentifierPattern &pattern) { diff --git a/gcc/rust/backend/rust-compile-pattern.h b/gcc/rust/backend/rust-compile-pattern.h index 317a3451161..ddf5b14265e 100644 --- a/gcc/rust/backend/rust-compile-pattern.h +++ b/gcc/rust/backend/rust-compile-pattern.h @@ -38,7 +38,6 @@ public: void visit (HIR::TupleStructPattern &pattern) override; void visit (HIR::WildcardPattern &pattern) override; void visit (HIR::RangePattern &pattern) override; - void visit (HIR::GroupedPattern &pattern) override; // Empty visit for unused Pattern HIR nodes. void visit (HIR::IdentifierPattern &) override {} @@ -70,7 +69,6 @@ public: void visit (HIR::StructPattern &pattern) override; void visit (HIR::TupleStructPattern &pattern) override; - void visit (HIR::GroupedPattern &) override; // Empty visit for unused Pattern HIR nodes. void visit (HIR::IdentifierPattern &) override {} @@ -105,12 +103,6 @@ public: void visit (HIR::WildcardPattern &) override; // check for unimplemented Pattern HIR nodes. - void visit (HIR::GroupedPattern &pattern) override - { - rust_sorry_at (pattern.get_locus (), - "grouped pattern let statements not supported"); - } - void visit (HIR::LiteralPattern &pattern) override { rust_sorry_at (pattern.get_locus (), diff --git a/gcc/rust/backend/rust-compile-resolve-path.h b/gcc/rust/backend/rust-compile-resolve-path.h index 67ff7eed2d5..6aec7be472f 100644 --- a/gcc/rust/backend/rust-compile-resolve-path.h +++ b/gcc/rust/backend/rust-compile-resolve-path.h @@ -45,7 +45,6 @@ public: void visit (HIR::QualifiedPathInExpression &expr) override; // Empty visit for unused Pattern HIR nodes. - void visit (HIR::GroupedPattern &) override {} void visit (HIR::IdentifierPattern &) override {} void visit (HIR::LiteralPattern &) override {} void visit (HIR::RangePattern &) override {} diff --git a/gcc/rust/backend/rust-compile-var-decl.h b/gcc/rust/backend/rust-compile-var-decl.h index 791ee9c1112..9e07999f273 100644 --- a/gcc/rust/backend/rust-compile-var-decl.h +++ b/gcc/rust/backend/rust-compile-var-decl.h @@ -69,7 +69,6 @@ public: } // Empty visit for unused Pattern HIR nodes. - void visit (HIR::GroupedPattern &) override {} void visit (HIR::LiteralPattern &) override {} void visit (HIR::PathInExpression &) override {} void visit (HIR::QualifiedPathInExpression &) override {} diff --git a/gcc/rust/checks/errors/rust-const-checker.cc b/gcc/rust/checks/errors/rust-const-checker.cc index 7e31c9f9c28..3752cf36716 100644 --- a/gcc/rust/checks/errors/rust-const-checker.cc +++ b/gcc/rust/checks/errors/rust-const-checker.cc @@ -834,10 +834,6 @@ void ConstChecker::visit (TuplePattern &) {} -void -ConstChecker::visit (GroupedPattern &) -{} - void ConstChecker::visit (SlicePattern &) {} diff --git a/gcc/rust/checks/errors/rust-const-checker.h b/gcc/rust/checks/errors/rust-const-checker.h index 238173874aa..e0402361367 100644 --- a/gcc/rust/checks/errors/rust-const-checker.h +++ b/gcc/rust/checks/errors/rust-const-checker.h @@ -186,7 +186,6 @@ private: virtual void visit (TuplePatternItemsMultiple &tuple_items) override; virtual void visit (TuplePatternItemsRanged &tuple_items) override; virtual void visit (TuplePattern &pattern) override; - virtual void visit (GroupedPattern &pattern) override; virtual void visit (SlicePattern &pattern) override; virtual void visit (EmptyStmt &stmt) override; virtual void visit (LetStmt &stmt) override; diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.cc b/gcc/rust/checks/errors/rust-unsafe-checker.cc index 3c369a2a81a..ff7a0b3f85a 100644 --- a/gcc/rust/checks/errors/rust-unsafe-checker.cc +++ b/gcc/rust/checks/errors/rust-unsafe-checker.cc @@ -901,10 +901,6 @@ void UnsafeChecker::visit (TuplePattern &) {} -void -UnsafeChecker::visit (GroupedPattern &) -{} - void UnsafeChecker::visit (SlicePattern &) {} diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.h b/gcc/rust/checks/errors/rust-unsafe-checker.h index 2abd3a62351..ce270c0e7ef 100644 --- a/gcc/rust/checks/errors/rust-unsafe-checker.h +++ b/gcc/rust/checks/errors/rust-unsafe-checker.h @@ -168,7 +168,6 @@ private: virtual void visit (TuplePatternItemsMultiple &tuple_items) override; virtual void visit (TuplePatternItemsRanged &tuple_items) override; virtual void visit (TuplePattern &pattern) override; - virtual void visit (GroupedPattern &pattern) override; virtual void visit (SlicePattern &pattern) override; virtual void visit (EmptyStmt &stmt) override; virtual void visit (LetStmt &stmt) override; diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc index 875e1dd9374..10720c43294 100644 --- a/gcc/rust/hir/rust-hir-dump.cc +++ b/gcc/rust/hir/rust-hir-dump.cc @@ -457,9 +457,6 @@ void Dump::visit (TuplePattern &) {} void -Dump::visit (GroupedPattern &) -{} -void Dump::visit (SlicePattern &) {} diff --git a/gcc/rust/hir/rust-hir-dump.h b/gcc/rust/hir/rust-hir-dump.h index 8715a95ada8..b66e6b13f7c 100644 --- a/gcc/rust/hir/rust-hir-dump.h +++ b/gcc/rust/hir/rust-hir-dump.h @@ -163,7 +163,6 @@ private: virtual void visit (TuplePatternItemsMultiple &) override; virtual void visit (TuplePatternItemsRanged &) override; virtual void visit (TuplePattern &) override; - virtual void visit (GroupedPattern &) override; virtual void visit (SlicePattern &) override; virtual void visit (EmptyStmt &) override; diff --git a/gcc/rust/hir/tree/rust-hir-full-decls.h b/gcc/rust/hir/tree/rust-hir-full-decls.h index 7870a5497ed..30adda6a1f3 100644 --- a/gcc/rust/hir/tree/rust-hir-full-decls.h +++ b/gcc/rust/hir/tree/rust-hir-full-decls.h @@ -206,7 +206,6 @@ class TuplePatternItems; class TuplePatternItemsMultiple; class TuplePatternItemsRanged; class TuplePattern; -class GroupedPattern; class SlicePattern; // rust-type.h diff --git a/gcc/rust/hir/tree/rust-hir-full-test.cc b/gcc/rust/hir/tree/rust-hir-full-test.cc index 230b7f72a85..b6646d61b28 100644 --- a/gcc/rust/hir/tree/rust-hir-full-test.cc +++ b/gcc/rust/hir/tree/rust-hir-full-test.cc @@ -4476,12 +4476,6 @@ TuplePattern::accept_vis (HIRFullVisitor &vis) vis.visit (*this); } -void -GroupedPattern::accept_vis (HIRFullVisitor &vis) -{ - vis.visit (*this); -} - void SlicePattern::accept_vis (HIRFullVisitor &vis) { @@ -4608,12 +4602,6 @@ EmptyStmt::accept_vis (HIRStmtVisitor &vis) vis.visit (*this); } -void -GroupedPattern::accept_vis (HIRPatternVisitor &vis) -{ - vis.visit (*this); -} - void WildcardPattern::accept_vis (HIRPatternVisitor &vis) { diff --git a/gcc/rust/hir/tree/rust-hir-pattern.h b/gcc/rust/hir/tree/rust-hir-pattern.h index b7a230c526f..5243d7898c0 100644 --- a/gcc/rust/hir/tree/rust-hir-pattern.h +++ b/gcc/rust/hir/tree/rust-hir-pattern.h @@ -1215,75 +1215,6 @@ protected: } }; -// HIR node representing a pattern in parentheses, used to control precedence -class GroupedPattern : public Pattern -{ - std::unique_ptr pattern_in_parens; - Location locus; - Analysis::NodeMapping mappings; - -public: - std::string as_string () const override - { - return "(" + pattern_in_parens->as_string () + ")"; - } - - GroupedPattern (Analysis::NodeMapping mappings, - std::unique_ptr pattern_in_parens, Location locus) - : pattern_in_parens (std::move (pattern_in_parens)), locus (locus), - mappings (mappings) - {} - - // Copy constructor uses clone - GroupedPattern (GroupedPattern const &other) - : pattern_in_parens (other.pattern_in_parens->clone_pattern ()), - locus (other.locus), mappings (other.mappings) - {} - - // Overload assignment operator to clone - GroupedPattern &operator= (GroupedPattern const &other) - { - pattern_in_parens = other.pattern_in_parens->clone_pattern (); - locus = other.locus; - mappings = other.mappings; - - return *this; - } - - // default move semantics - GroupedPattern (GroupedPattern &&other) = default; - GroupedPattern &operator= (GroupedPattern &&other) = default; - - Location get_locus () const override { return locus; } - - void accept_vis (HIRFullVisitor &vis) override; - void accept_vis (HIRPatternVisitor &vis) override; - - Analysis::NodeMapping get_pattern_mappings () const override final - { - return mappings; - } - - PatternType get_pattern_type () const override final - { - return PatternType::GROUPED; - } - - std::unique_ptr &get_item () { return pattern_in_parens; } - const std::unique_ptr &get_item () const - { - return pattern_in_parens; - } - -protected: - /* Use covariance to implement clone function as returning this object rather - * than base */ - GroupedPattern *clone_pattern_impl () const override - { - return new GroupedPattern (*this); - } -}; - // HIR node representing patterns that can match slices and arrays class SlicePattern : public Pattern { diff --git a/gcc/rust/hir/tree/rust-hir-visitor.h b/gcc/rust/hir/tree/rust-hir-visitor.h index ba6cad7614b..a635f9079f1 100644 --- a/gcc/rust/hir/tree/rust-hir-visitor.h +++ b/gcc/rust/hir/tree/rust-hir-visitor.h @@ -138,7 +138,6 @@ public: virtual void visit (TuplePatternItemsMultiple &tuple_items) = 0; virtual void visit (TuplePatternItemsRanged &tuple_items) = 0; virtual void visit (TuplePattern &pattern) = 0; - virtual void visit (GroupedPattern &pattern) = 0; virtual void visit (SlicePattern &pattern) = 0; virtual void visit (EmptyStmt &stmt) = 0; virtual void visit (LetStmt &stmt) = 0; @@ -290,7 +289,6 @@ public: virtual void visit (TuplePatternItemsMultiple &) override {} virtual void visit (TuplePatternItemsRanged &) override {} virtual void visit (TuplePattern &) override {} - virtual void visit (GroupedPattern &) override {} virtual void visit (SlicePattern &) override {} virtual void visit (EmptyStmt &) override {} @@ -470,7 +468,6 @@ public: class HIRPatternVisitor { public: - virtual void visit (GroupedPattern &) = 0; virtual void visit (IdentifierPattern &) = 0; virtual void visit (LiteralPattern &) = 0; virtual void visit (PathInExpression &) = 0; diff --git a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc index 393f4158003..fd4814c3604 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc @@ -386,15 +386,6 @@ TypeCheckPattern::visit (HIR::IdentifierPattern &) infered = parent; } -void -TypeCheckPattern::visit (HIR::GroupedPattern &pattern) -{ - TyTy::BaseType *inner_ty - = TypeCheckPattern::Resolve (pattern.get_item ().get (), parent); - infered = inner_ty->clone (); - infered->set_ref (pattern.get_pattern_mappings ().get_hirid ()); -} - void TypeCheckPattern::visit (HIR::QualifiedPathInExpression &) { diff --git a/gcc/rust/typecheck/rust-hir-type-check-pattern.h b/gcc/rust/typecheck/rust-hir-type-check-pattern.h index bdfc90723e9..e7550071548 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-pattern.h +++ b/gcc/rust/typecheck/rust-hir-type-check-pattern.h @@ -39,7 +39,6 @@ public: void visit (HIR::LiteralPattern &pattern) override; void visit (HIR::RangePattern &pattern) override; void visit (HIR::IdentifierPattern &pattern) override; - void visit (HIR::GroupedPattern &pattern) override; void visit (HIR::QualifiedPathInExpression &pattern) override; void visit (HIR::ReferencePattern &pattern) override; void visit (HIR::SlicePattern &pattern) override; From patchwork Wed Apr 5 14:03: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: 79673 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp348286vqo; Wed, 5 Apr 2023 07:26:00 -0700 (PDT) X-Google-Smtp-Source: AKy350a5p4V/yapPejw6INSE7HWeLgDBBGuuaZKynv/aHBEfcSU1YAuVesnKLP+3APFGAlcLlDoy X-Received: by 2002:a17:906:3c52:b0:941:1cf6:dbea with SMTP id i18-20020a1709063c5200b009411cf6dbeamr3559334ejg.55.1680704760330; Wed, 05 Apr 2023 07:26:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704760; cv=none; d=google.com; s=arc-20160816; b=AFRF9cFCrrjow6S53Hrlf4Uz7y/wlGi0I7yctryoGUEHHgtQRpFb13xjDdwk13P4nF 2cjViTJ+4tataR70A8WqGb+pEzdJGBA5YgnPbMD/1KbjbPuxXcxaoM8rxbv06TThMxb6 vj8uafh1M/PbxNkYqvmK3cqXNNDc7iDqU72aaFrWH9Ymorf6gi9m5UfVz53gdc0XcFJq wWoopgOnq+POXXol93QIdkwPix3XPFco4VyV9K7sJWCvpAgMu8LKJakj+MOh8uSANGBZ G+xwC2t2wvvNrG4npbMbYAGAbqCKSbL1ZEtKjzcxIHQmATZJZ7kkwrD1seEv3/raYNeg cx+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=F/LMRN4J6NtEY2kPr9euv93Xpqb7Yxnuzh469XKJk44=; b=dF5ccRbgQSgIIUJFoECOrb4DBzxNeHyCwFDZmY+U5AEfqvZyiaNhwAK2xOe3Q+3khi PehGY4VwTRpG5FsVyR7Urh1Pp/AsWATX5ol6BBAsLgEM2i12woLqs4VDOfLGmhidnly0 +c5ezwbEeUMWp/YMhK+TFGfERBzZ6eNFu0Uguqcb7kEnPt+sSyuASnpMpbkFwVMogBI+ eavum/g6He7+PzGMfqmpKZX86D1m8OoGy03tCDdrUPM30PotXIbqfvM3UiqAWGiWvyHN NTF0gRV09XXqUeh8cJh5pMZCPmXQz3L2XlXIS/8HboEvqF6dBmG6mWeGfLQMN07tW9QU ixNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b="HqlQX7g/"; 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 a23-20020a17090682d700b0093001429138si11492201ejy.13.2023.04.05.07.26.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:26:00 -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="HqlQX7g/"; 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 28EFE3959C69 for ; Wed, 5 Apr 2023 14:11:23 +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 2CC4F385842C for ; Wed, 5 Apr 2023 14:05:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2CC4F385842C 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 j18-20020a05600c1c1200b003ee5157346cso23815575wms.1 for ; Wed, 05 Apr 2023 07:05:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703548; 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=F/LMRN4J6NtEY2kPr9euv93Xpqb7Yxnuzh469XKJk44=; b=HqlQX7g/lykHQhS0S4Ouv2V7sllgorYoh1oiC7wYqOShJuBv88kfkxM/W839uZ0/LE 5aHojQhTxgZUP3rMlCDfG70ihSKUnZeZDLz7vtyD8VlMF7fdMx1yKAMLYT6K+5r2ELRl ISLLiGnscVtYO2EW8DGkBjBfBRUDTKIKW3aEtnVvOe1DmXsE0rZEdMNJ+SQ3hx5M/ncv 7y/XH26GfHXTJnPQqiUELiDqOA18M2CaTgsae583yhs9ISpPx0WDahgZqsuQxJkQCjoS S1EyKVkfzYTZvIU33TSL44qOgGS2h3GbrOE/LFUp4l3qIstBdunwd7+ROqxeY9M2xpO3 xHYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703548; 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=F/LMRN4J6NtEY2kPr9euv93Xpqb7Yxnuzh469XKJk44=; b=PM8mUbV3KyH8w/wlssd1y7QFRPWrTe0tqR35zWQkiw+hG7bOn2A84Tktp65yEPK/Rb csEdJVAiCVE1FOzxGC1IDdktfSHHBImvxwDoHckmL/EUwTKIBtoDNCtoIAryRYD3FpbK AGxHg1AV4g4S+hOIgMJwiGndIRXQyTN1g67FnVIAga+yksi/ZYRxqffq6oiz8c2pn11H 2yps6Q2t+so+q4M0WfZJ4D/DHMrxp5tMrqUhy1d0OA/mQfWCfHUBueMei05e3kfhjzx6 txjiopJmGdGklRKrYm7cJzNELlhf+C0p21X8Z7fD4vK2sZ72bSyD6RARTJxXqwEVhoui SOPQ== X-Gm-Message-State: AAQBX9csgyJ4EggwXG9DVEhTQmIluKA+u1IX7QpFfOIFN2VubGc9J27A PPy+uGwkjuQLWfR6BJtl1lu/u4ML6QM/ijRu7g== X-Received: by 2002:a1c:7904:0:b0:3ef:128d:7167 with SMTP id l4-20020a1c7904000000b003ef128d7167mr5012586wme.13.1680703548471; Wed, 05 Apr 2023 07:05:48 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:48 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [committed 29/88] gccrs: Optimize HIR::ReferencePattern Date: Wed, 5 Apr 2023 16:03:13 +0200 Message-Id: <20230405140411.3016563-30-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.6 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?1762346674684844482?= X-GMAIL-MSGID: =?utf-8?q?1762346674684844482?= From: Owen Avery gcc/rust/ChangeLog: * hir/tree/rust-hir-pattern.h (class ReferencePattern): Remove has_two_amps field. * hir/tree/rust-hir-full-test.cc (ReferencePattern::as_string): Remove usage of ReferencePattern::has_two_amps. Signed-off-by: Owen Avery --- gcc/rust/hir/tree/rust-hir-full-test.cc | 5 ----- gcc/rust/hir/tree/rust-hir-pattern.h | 13 +++++-------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/gcc/rust/hir/tree/rust-hir-full-test.cc b/gcc/rust/hir/tree/rust-hir-full-test.cc index b6646d61b28..0ddb8418e95 100644 --- a/gcc/rust/hir/tree/rust-hir-full-test.cc +++ b/gcc/rust/hir/tree/rust-hir-full-test.cc @@ -2583,11 +2583,6 @@ ReferencePattern::as_string () const { std::string str ("&"); - if (has_two_amps) - { - str += "&"; - } - if (is_mut ()) { str += "mut "; diff --git a/gcc/rust/hir/tree/rust-hir-pattern.h b/gcc/rust/hir/tree/rust-hir-pattern.h index 5243d7898c0..83b041d2770 100644 --- a/gcc/rust/hir/tree/rust-hir-pattern.h +++ b/gcc/rust/hir/tree/rust-hir-pattern.h @@ -424,7 +424,6 @@ protected: // HIR node for pattern based on dereferencing the pointers given class ReferencePattern : public Pattern { - bool has_two_amps; Mutability mut; std::unique_ptr pattern; Location locus; @@ -435,16 +434,15 @@ public: ReferencePattern (Analysis::NodeMapping mappings, std::unique_ptr pattern, Mutability reference_mut, - bool ref_has_two_amps, Location locus) - : has_two_amps (ref_has_two_amps), mut (reference_mut), - pattern (std::move (pattern)), locus (locus), mappings (mappings) + Location locus) + : mut (reference_mut), pattern (std::move (pattern)), locus (locus), + mappings (mappings) {} // Copy constructor requires clone ReferencePattern (ReferencePattern const &other) - : has_two_amps (other.has_two_amps), mut (other.mut), - pattern (other.pattern->clone_pattern ()), locus (other.locus), - mappings (other.mappings) + : mut (other.mut), pattern (other.pattern->clone_pattern ()), + locus (other.locus), mappings (other.mappings) {} // Overload assignment operator to clone @@ -452,7 +450,6 @@ public: { pattern = other.pattern->clone_pattern (); mut = other.mut; - has_two_amps = other.has_two_amps; locus = other.locus; mappings = other.mappings; From patchwork Wed Apr 5 14:03: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: 79674 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp348696vqo; Wed, 5 Apr 2023 07:26:39 -0700 (PDT) X-Google-Smtp-Source: AKy350ZJ/5/8+ajIubDhU5Jgyn2pXwsCnwIdxfU55ZEjFGMUOhgXEJ7/RU0vLmNIV5BS7+heOPI5 X-Received: by 2002:aa7:cd5b:0:b0:4fc:d331:515 with SMTP id v27-20020aa7cd5b000000b004fcd3310515mr1876785edw.5.1680704799581; Wed, 05 Apr 2023 07:26:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704799; cv=none; d=google.com; s=arc-20160816; b=p7Ykv8Lm8pXurhE1ffOilGfFrRgzIlnhBz8pgUevE/c7yCExHliHKXnUecuklyLWjX uRg63rh8V+SYsL2EB6EEgoe7v4+KuaWcgwnEj9tA0MPP7S+nlvbRTyE3y+GLl48co+cs IlWurpJynKr7iutNUkAhpjSQa1AtdLtKzkxhkaYpF/Vm7ujmOsWqVA+F+rYcI4Z6puWv 0d6g9Xza31kf6iyN3Zx25cbtC9/TfOHEXs6FzRaQhuLsc0Kqy7OkhviCPJZHwlF1ngVa xuRbHTvoKfeJtI1Gn6mhps9Hc5S4wmUzznudRdZulpZIcvQBHggNTGzPq8Z1edY5o7F4 HqqQ== 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=Pk/YR01fm2xN7HmxJNkxvY1XwVk0ob+ZXWLT0uilaw0=; b=Zxj+mOpBe65rHgFmMhhv5KdVO1s+OzlTXMbWUrxOoXWlV1y4ZD0Zars0U2ch+mFxcR O9e9qVNJwglhscrul4UpLQWKkoN1m1BANt7daANGrbxENaj7TGI11EzxiK2lEQBQtTII dRjHfR5u7DNeKjFDkz1TyGaaGn82ZAGA8Un4ZqS2aToSz7mBsviR7FDblqvRaubmpRt5 tnYezkXilaPgWL/dV/t2RBb4ATGB2JgVsIaWeHPJ6GfGwt3GciCw6dHwZoPbAF9/K7Mw boQqVJvfv/zQGHltR6MzuPX8nJeeYPzLVX8Gn/CZOWqjEERZWSYhquRvYWd6ZAydyDaq loNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=EysPVRRP; 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 r23-20020a056402035700b005021d251232si3942287edw.20.2023.04.05.07.26.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:26:39 -0700 (PDT) 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=EysPVRRP; 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 6157138E4D2B for ; Wed, 5 Apr 2023 14:11:32 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id CB87438555AC for ; Wed, 5 Apr 2023 14:05:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CB87438555AC 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-x32c.google.com with SMTP id p34so20958044wms.3 for ; Wed, 05 Apr 2023 07:05:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703549; 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=Pk/YR01fm2xN7HmxJNkxvY1XwVk0ob+ZXWLT0uilaw0=; b=EysPVRRPr7iDBWyMu3A3gmluDdNn/nIACx7sbaoFieqqLPApZL52kcJgBvgcTn99VJ bU2KsleNCIQpuVktZq0ngZsjio7cfIIJDwM88tWePw92gb88iC1e+sab9vJo80KUs/CP FUoshlBiP0A+CthUCC6pnXmmek9vt3exu8eJuib1UTbp2HQ/VC1yRe5P45pcBKFihFAa Z7N5AA8BHbaU0be91lBOe8lZlsziVnqW5RuKhiy9b3Hb1ybuRUSh3+4oNW1ZdoeoxKq7 e0VOK+Ydm384QvBVQ+knJPRjXRIlJrwWLGnJEF+VolC/N4JlxiX1w+VYEpMxgnwCV8M3 usbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703549; 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=Pk/YR01fm2xN7HmxJNkxvY1XwVk0ob+ZXWLT0uilaw0=; b=ZI0D5gYHkGLyvgCDLBsUCNObzkYIokp6C1dHqmNY3WABB7nkROYHWzdtyZT8lW419l zWlrBISDwC2Fx1rofhnp2PCnhMTtQSJ+zcGlsNLbS6yQ4nGotZZNHf+784oBF/YmEkBd X7d2afthi5s0bho1DxTQllF5BUTR39KkltzN+PCM9kcveQ1bz3FH/mgNlV1+ALEmJb4S yOx8Y443WGyR78bhkkEe+XvpQc2GLf0r+SuWvDDbYHb6YUh+p+4wk3CV612ezCRIXXJG d+Esi/3UmAmmPhgVF4eVlwAMoOLuJADrv1SmRSPujJF+b34sdqBkn3QRteWNOhlfCwHt 4+Vw== X-Gm-Message-State: AAQBX9d0Zg5f8LvaunwbNDlQdKc+2xw431YM5qA1ib4/Y9jjNWvXSI94 TuWBHO2NWYd0By2HAAcC+416W9Pg9G7a6jFq2Q== X-Received: by 2002:a7b:cb50:0:b0:3ee:6d88:774a with SMTP id v16-20020a7bcb50000000b003ee6d88774amr1824962wmj.14.1680703549409; Wed, 05 Apr 2023 07:05:49 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:48 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [committed 30/88] gccrs: Implement lowering ReferencePattern from AST to HIR Date: Wed, 5 Apr 2023 16:03:14 +0200 Message-Id: <20230405140411.3016563-31-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.6 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?1762346715899594451?= X-GMAIL-MSGID: =?utf-8?q?1762346715899594451?= From: Owen Avery gcc/rust/ChangeLog: * ast/rust-pattern.h: (ReferencePattern::is_double_reference): Add method. (ReferencePattern::get_is_mut): Add method. * hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Add ReferencePattern visitor. * hir/rust-ast-lower-pattern.h: (ASTLoweringPattern::visit): Add ReferencePattern visitor. Signed-off-by: Owen Avery --- gcc/rust/ast/rust-pattern.h | 4 ++++ gcc/rust/hir/rust-ast-lower-pattern.cc | 29 ++++++++++++++++++++++++++ gcc/rust/hir/rust-ast-lower-pattern.h | 1 + 3 files changed, 34 insertions(+) diff --git a/gcc/rust/ast/rust-pattern.h b/gcc/rust/ast/rust-pattern.h index c86bdf6f820..cf5d2ead10d 100644 --- a/gcc/rust/ast/rust-pattern.h +++ b/gcc/rust/ast/rust-pattern.h @@ -469,6 +469,10 @@ public: return pattern; } + bool is_double_reference () const { return has_two_amps; } + + bool get_is_mut () const { return is_mut; } + NodeId get_node_id () const { return node_id; } NodeId get_pattern_node_id () const override final { return node_id; } diff --git a/gcc/rust/hir/rust-ast-lower-pattern.cc b/gcc/rust/hir/rust-ast-lower-pattern.cc index a0fd8dded38..1961c740624 100644 --- a/gcc/rust/hir/rust-ast-lower-pattern.cc +++ b/gcc/rust/hir/rust-ast-lower-pattern.cc @@ -249,5 +249,34 @@ ASTLoweringPattern::visit (AST::GroupedPattern &pattern) pattern.get_pattern_in_parens ()->accept_vis (*this); } +void +ASTLoweringPattern::visit (AST::ReferencePattern &pattern) +{ + auto crate_num = mappings->get_current_crate (); + Analysis::NodeMapping mapping (crate_num, pattern.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + + HIR::Pattern *inner + = ASTLoweringPattern::translate (pattern.get_referenced_pattern ().get ()); + + translated + = new HIR::ReferencePattern (mapping, std::unique_ptr (inner), + pattern.get_is_mut () ? Mutability::Mut + : Mutability::Imm, + pattern.get_locus ()); + + if (pattern.is_double_reference ()) + { + Analysis::NodeMapping mapping2 (crate_num, pattern.get_node_id (), + mappings->get_next_hir_id (crate_num), + UNKNOWN_LOCAL_DEFID); + translated + = new HIR::ReferencePattern (mapping2, + std::unique_ptr (translated), + Mutability::Imm, pattern.get_locus ()); + } +} + } // namespace HIR } // namespace Rust diff --git a/gcc/rust/hir/rust-ast-lower-pattern.h b/gcc/rust/hir/rust-ast-lower-pattern.h index 0075e27e9c0..2d175a25cb4 100644 --- a/gcc/rust/hir/rust-ast-lower-pattern.h +++ b/gcc/rust/hir/rust-ast-lower-pattern.h @@ -40,6 +40,7 @@ public: void visit (AST::LiteralPattern &pattern) override; void visit (AST::RangePattern &pattern) override; void visit (AST::GroupedPattern &pattern) override; + void visit (AST::ReferencePattern &pattern) override; private: ASTLoweringPattern (); From patchwork Wed Apr 5 14:03: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: 79682 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp352378vqo; Wed, 5 Apr 2023 07:31:41 -0700 (PDT) X-Google-Smtp-Source: AKy350bqAWc/1knlrTHPxz52Kn9BiGY8ty9RYTGhcAsqSCMYzc9D53gOXLiP0649Fk4X4mOGUxJZ X-Received: by 2002:a05:6402:4c6:b0:502:9289:51e5 with SMTP id n6-20020a05640204c600b00502928951e5mr2032238edw.14.1680705101520; Wed, 05 Apr 2023 07:31:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705101; cv=none; d=google.com; s=arc-20160816; b=OrAsavtz0q83vn+gkAprxS0Vrc4bJIiEytihe4T2lHUbJHYKL5m29bcC5QE8y/6a4O WCpKkKA6Lh4zcUo/q5W0Po28n7W/IFIib4FNiXooWwJG9H5Momi4S8NVfahQ6vglN1YJ J/dj10PAhb8du4+8rjoVYbF6MFIKLlHOPtmTNpooSRTgEt2GhmBK8s1qsc/tD5glKwaY hdbBL0Wys5MexDaNaZEJicHUaGqb6oGV+5XRwrgrs+si/YxR/VbB/yqLJ92xGVLe018/ QcZAZNCEq1e0WmeKLW+adVJeslb1G6enBT7OpJc/PW6w3i4FaFUPH9i7wHyw5/nAiMo0 Vf/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=LmpZNkxa1VjPJMe703i8g9eO/nZAZKuBclfGJvZQZxY=; b=hvpaBISMzloHIOsTv1Nshg0m+HtDHpNlmDgJymlIikhCLdg+OGm3PDE5moEyw7I+Ds kvWb279+FK2cSaBtlBucaW+5hNSGMLKf2f6kWbTkLlP/zKtsBMhIeKpLdWQ2zruQmV2N wqydC1SAdAa+45UhVIKFJ0Lg+5CgYaHefBtp1pEaId+kUOOVeVB4LNK7h7YcDlvmD6Ae gC2ViDGUKbA+McTOepjyErnR0GRG6TOPX+vgj9rZxqOH9ktaza+hMZSbaXPfSsT4R4ED LI9gv0uLmXTsp3YdsmYsrPUBJs70f315ii9M/YtqWzeY/UHdT6rFYLdzWDgok20T+mGe tgnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Omdt7fj5; 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 s5-20020aa7c545000000b004fe92442646si2157966edr.497.2023.04.05.07.31.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:31:41 -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=Omdt7fj5; 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 176CE3A47F76 for ; Wed, 5 Apr 2023 14:12:41 +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 26E4E3858D20 for ; Wed, 5 Apr 2023 14:05:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 26E4E3858D20 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 i9so36346031wrp.3 for ; Wed, 05 Apr 2023 07:05:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703550; 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=LmpZNkxa1VjPJMe703i8g9eO/nZAZKuBclfGJvZQZxY=; b=Omdt7fj5H0Z4ufcWuJJ46RQ8mx7euHOV2oqAGibMiurFGIlgrss37uzIb25mXeOxzn Q07Was52ACHLpsu6WrvU5QLr0W0w+L1sWY1DAGsELOxCi/Whm6unHengOIH/sIaV/gNZ C2ymcqwoNFxG7l2Kg1UunTKVuRGy2Z+ipnuvbQpOJZ6NbZnXHw0ck7TaKH5RyeyuqEcB YurpWUFuily3CINnEa1765UlR6gJvyy6Zr5Jzs72TjKFTE85QJlZa58oax3aPp0uEdRg 2w1RaDIDxcWJHYGnPzs2/LdHEu24wz5UoZCLXxGEFQmRgtpjVA4UY5gAbk1+3NAwwdR6 EZog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703550; 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=LmpZNkxa1VjPJMe703i8g9eO/nZAZKuBclfGJvZQZxY=; b=IFrzb9fGxhvTdEoQ2zbfxKM1XRtEKINO7P3ZLTi5w5bpwwi4c1E8/gI90rpVOVkDmu eIaNVbIfESUQw5TNLtHEbJSg33b3zm4mQ5ROWWmQVuIT4WlJDZ1cjb49lS4M/TP/rBgw 4i/8F0YH3wp0VI3SAeEFkWVHOGPfLnqLBLzagAdBVIM7r0jsOuA9EmpaVKak9cESil3A NkV8rO7aL0Xod28NMiwOm4nZaIgcXLJkzeXe79+qKnQonGlWV9YV1pRsQsgK2LNqtUuf IdO75XczGu0K5xhi6llEX4BPYw/9QeuvutX4SP9F2CDIyaojo6P4/Ad47/ZgtHTrgiGN ZcIw== X-Gm-Message-State: AAQBX9dYPu7/U4oOxyCxqS0brDKM6W42IsaXn5fUCXPXBuVUt276kocE PsNI0YQNrz3bHRVVtYwHS9ixHodaXDMJaxnP/g== X-Received: by 2002:a5d:4388:0:b0:2c7:1c08:121c with SMTP id i8-20020a5d4388000000b002c71c08121cmr4566987wrq.61.1680703550074; Wed, 05 Apr 2023 07:05:50 -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.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:49 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 31/88] gccrs: parser: Improve parsing of complex generic arguments Date: Wed, 5 Apr 2023 16:03:15 +0200 Message-Id: <20230405140411.3016563-32-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.6 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?1762347032787030758?= X-GMAIL-MSGID: =?utf-8?q?1762347032787030758?= From: Arthur Cohen The parser was missing code for handling complex type arguments such as type paths or nested generics. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_generic_arg): Handle type paths and nested generics properly. gcc/testsuite/ChangeLog: * rust/compile/parse_complex_generic_application.rs: New test. * rust/compile/parse_complex_generic_application2.rs: New test. --- gcc/rust/parse/rust-parse-impl.h | 4 +++- .../parse_complex_generic_application.rs | 17 +++++++++++++++++ .../parse_complex_generic_application2.rs | 10 ++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/rust/compile/parse_complex_generic_application.rs create mode 100644 gcc/testsuite/rust/compile/parse_complex_generic_application2.rs diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 23b033fb26e..3610790815c 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -6309,7 +6309,9 @@ Parser::parse_generic_arg () // could either have a valid type or a macro (FIXME: anything else?). So // we need one bit of lookahead to differentiate if this is really auto next_tok = lexer.peek_token (1); - if (next_tok->get_id () == EXCLAM) + if (next_tok->get_id () == LEFT_ANGLE + || next_tok->get_id () == SCOPE_RESOLUTION + || next_tok->get_id () == EXCLAM) { auto type = parse_type (); if (type) diff --git a/gcc/testsuite/rust/compile/parse_complex_generic_application.rs b/gcc/testsuite/rust/compile/parse_complex_generic_application.rs new file mode 100644 index 00000000000..d5c7bf488b7 --- /dev/null +++ b/gcc/testsuite/rust/compile/parse_complex_generic_application.rs @@ -0,0 +1,17 @@ +pub enum Either { + Left(T), + Right(E), +} + +pub mod err { + pub struct Error; + pub struct ErrorWrap(T); +} + +pub fn foo_err() -> Either<(), err::Error> { + Either::Left(()) +} + +pub fn foo_err_wrap() -> Either<(), err::ErrorWrap> { + Either::Left(()) +} diff --git a/gcc/testsuite/rust/compile/parse_complex_generic_application2.rs b/gcc/testsuite/rust/compile/parse_complex_generic_application2.rs new file mode 100644 index 00000000000..0361931c50c --- /dev/null +++ b/gcc/testsuite/rust/compile/parse_complex_generic_application2.rs @@ -0,0 +1,10 @@ +pub enum Either { + Left(L), + Right(R), +} + +pub struct Wrap(T); + +pub fn foo_wrap() -> Either<(), Wrap> { + Either::Left(()) +} From patchwork Wed Apr 5 14:03: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: 79678 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp350614vqo; Wed, 5 Apr 2023 07:29:27 -0700 (PDT) X-Google-Smtp-Source: AKy350bJ+EZ8mOOvl3l4SXjKW8B8izBEz9uy+prO1vsn41nf3jix5TG4+N6myh67/Ri2m67ICm/j X-Received: by 2002:a17:906:4cda:b0:947:d9b1:89a3 with SMTP id q26-20020a1709064cda00b00947d9b189a3mr2549067ejt.27.1680704967369; Wed, 05 Apr 2023 07:29:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704967; cv=none; d=google.com; s=arc-20160816; b=p56y0RCFavGSS3sS+OPE5z/F/gyhu1yPPZmJ+Y2YXhFlnfbhB6DYsjI+EV/yODH9Q3 2iObOTigI0rws3mMOko2+KQ1mCH9//L6xp8u9evFFTu+rkNpsTAouw3gjFgc1GM5Bxk/ wn0SRps0hbtLn2I5+8C3UWR4djnW1f3JWTxCXEmilFcByBUSh+knUFyDoI0B7N8ehoVR VdEugANugyF3Dab0VW387QV7/gKkg7D8gamAbW8WiBdY1UQYXfUuqsqR9GffO2Z+ZsBp Hs5nLHocnD2cJKVp+g7JR63taLFAcAAdIb1c/HnWxuwXXsjuqm8uOVPqb1QqFBlc0JM4 BfaA== 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=WjHsg0/yMP9qY8d1KkNefjEqBT8kG3AOgrofVA59VIE=; b=kg5H+jJMtN7WStnm1vTCGrZIGCpjH+VZf5tsPhTxtR8R82QyttgzvfbwwXgBNsjUuQ klqE/uu4hoPLA9Lqs4Dp28B2LHEUZ1lfrOFj8d2lR+NFbtrbBwnYkK84hhGf1QsuOwXB 1g4DvfEU1YVvoCMmnurP2gJqabMjFU5nGN/ZNEi1Zf5hi+sLYqhf8T+btcHDAdk2mmfK eUdJ9uTUqBYIrPyWapjiPL7nc2Z/x7MMqVJ1vemHtEjGASNubIHLW2NnC55Wuu4Nxfib +U+KEmYAwIySqSKgsDdnyjoVFybzsL8jagGvYInJGMFnAXsVmke2RRo9Yc1kwraWmhTd 3SCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=LGRYiOIV; 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 d21-20020a1709063ed500b00933f276be3fsi1498791ejj.656.2023.04.05.07.29.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:29:27 -0700 (PDT) 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=LGRYiOIV; 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 50D3239266A9 for ; Wed, 5 Apr 2023 14:12:10 +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 DBB493853821 for ; Wed, 5 Apr 2023 14:05:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DBB493853821 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 r29so36306579wra.13 for ; Wed, 05 Apr 2023 07:05:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703551; 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=WjHsg0/yMP9qY8d1KkNefjEqBT8kG3AOgrofVA59VIE=; b=LGRYiOIVI7ePlGlY/JAVfxWcr/XkxDgdDJxRxJDcWzlo+cKCVAw3KhQa9pyN6ghA7s fqj4wJx2ldosKlEHhP1Hmxa5L5/LCHpCcG5I95V8/uZX5aARfrPX3lIQRh8v6zFb7zSP o8RMIoSKaJ2E/sGvE/TyBmtiWfvVYDGajcH2S+fOGNCLppYI+XOLyT/JFkM+N5M0aHnR oB53dB7/njzvNoff9yZjK+9hDqgttWOiUhgNmyqwERv/c8T8hjt/Nb9G0vE/5AvVUdlc GVphRKMWbO9Cvn36K+fHId3AEqHj6U3V6VCHacik2gPQzsGyp/D+ll5qWTA1rRqsO66K QO6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703551; 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=WjHsg0/yMP9qY8d1KkNefjEqBT8kG3AOgrofVA59VIE=; b=ZDIMqRR4a0hyZarqZpqk2n13xo+59AAiypwwOhpWT5bqFBicD644pyfm13aaCl5vK1 vaU6V3w2IJCAvi1Bx/AkCMKtr02/MQPDs5oJeceMmmRhFFhzpaH8WP7ZzvJpib5pwL8x H82XXfxHdLbmijSAko8CFUenj3b5e15/daD31qeT4LOLyQRTBfFQD2Ab0SwGUNyRTMF8 Wa19Z+nHvb2Y4g5RiEqpBdkLcm81qW3H+3nji6IPCGgDBAB72bP6N1Ng8m61SKnaZ9Va z142WWuspCDSCgBKRdYrh+6PD91E9v70aFihWSeZtPPLPCBAFlDhHEPgbXtQf2K1k8qM mdqw== X-Gm-Message-State: AAQBX9e7jyd21Rc+kot1xPpyNz24HrOO0pQmM+5N6fqoz0IsSarBv1fO 7Gwneq3O9Ega9gpv/KqHo2uhaCvmVli+22czOw== X-Received: by 2002:adf:fa0c:0:b0:2ce:da65:1e1d with SMTP id m12-20020adffa0c000000b002ceda651e1dmr2153204wrr.24.1680703551070; Wed, 05 Apr 2023 07:05:51 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:50 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 32/88] gccrs: parser: Fix parsing of closure param list Date: Wed, 5 Apr 2023 16:03:16 +0200 Message-Id: <20230405140411.3016563-33-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.6 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?1762346892068323841?= X-GMAIL-MSGID: =?utf-8?q?1762346892068323841?= From: Arthur Cohen gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_closure_expr): Advance tokens properly when parsing closure param list. gcc/testsuite/ChangeLog: * rust/compile/closure_move_expr.rs: New test. --- gcc/rust/parse/rust-parse-impl.h | 2 ++ gcc/testsuite/rust/compile/closure_move_expr.rs | 9 +++++++++ 2 files changed, 11 insertions(+) create mode 100644 gcc/testsuite/rust/compile/closure_move_expr.rs diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 3610790815c..4ceb978f7f4 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -7592,6 +7592,7 @@ Parser::parse_closure_expr (AST::AttrVec outer_attrs) case PIPE: // actually may have parameters lexer.skip_token (); + t = lexer.peek_token (); while (t->get_id () != PIPE) { @@ -7608,6 +7609,7 @@ Parser::parse_closure_expr (AST::AttrVec outer_attrs) if (lexer.peek_token ()->get_id () != COMMA) { + lexer.skip_token (); // not an error but means param list is done break; } diff --git a/gcc/testsuite/rust/compile/closure_move_expr.rs b/gcc/testsuite/rust/compile/closure_move_expr.rs new file mode 100644 index 00000000000..780c316e0af --- /dev/null +++ b/gcc/testsuite/rust/compile/closure_move_expr.rs @@ -0,0 +1,9 @@ +// { dg-additional-options "-fsyntax-only" } + +fn foo() { + move |l: u32, r: u32| l + r +} + +fn foo2() { + |l: u32, r: u32| l + r +} From patchwork Wed Apr 5 14:03: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: 79680 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp350982vqo; Wed, 5 Apr 2023 07:30:04 -0700 (PDT) X-Google-Smtp-Source: AKy350ZUNAexKCF6r0QTYTHHE6OEQP3q0VSXX7dWJOwxTZvCYK3IhxqWQ54/nG5V+8SUGkHd+uMG X-Received: by 2002:a17:906:ccc2:b0:92c:16cc:2dcd with SMTP id ot2-20020a170906ccc200b0092c16cc2dcdmr2925046ejb.33.1680705003857; Wed, 05 Apr 2023 07:30:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705003; cv=none; d=google.com; s=arc-20160816; b=bvVLI70jsJ56dGnDU0s5DuiSCnlG59yERD1z9l4blKlaXw9fRYNGxm7Tq5jYwZq20t La0VpStEqhswZ9YfGng4H3Doz/kf708Fz6R/lNmAsMZM24P4j501G2weJ6toV6R0Olh0 tk1W1kvLl7mN1VWp7KJ0yH9UlSK622G1jgsjOwzSxe9SEq65MPFzN+lzghM7jo+vQa7e ipWu5fDbe22fKB/mrylMlHow9IpdzEr87XokV6PL1OvJ5iy2FPbWbplSMO5IFXTldp0i RKNa6EsdK4m8ruIDSzNTr5nTznMGGWKk7evpu56CM1v/+BvAp2tE/lhQl0ZnlFz/Emr/ 3cHg== 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=45DNQu9fBFY6qFaUoOeFel8jIU22OK+1TD92XMz9Rj4=; b=HElaWZowqoJvhn6zr6vKhR/uUMLReJLmQnIp70kBvFZK8UbVEKeOVyVYTotlawKeSQ uZvS4dSpVhanG981C1cPWz4yniPul9+YsL4vrOUTP/zAgx/ZKz+HBEy5m3GySl6C19Ed xScvTvqQeRVvDiLK/sbvfw7rVr3pSnF4XSeqSduwLMQlY06VzuXa5Y6d/A/b1Lc+EKT5 pXaqlgDMC1ioLaEQtIyIe+L7PsWdSguUPahInYEcLEg/dmCqK9pdakt4iX7oKWDnDIgP 9uoYSwpJk/AUosDMVbi8060IoI5BZY0SgaSRN8nMbd2c12KJFLjCrdmczveKiBYtIgeE gwKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=RojwQ+uH; 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 n13-20020a170906088d00b00946fa87bed8si884269eje.800.2023.04.05.07.30.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:30:03 -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=RojwQ+uH; 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 6F3393928A13 for ; Wed, 5 Apr 2023 14:12:18 +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 3CFCE3853556 for ; Wed, 5 Apr 2023 14:05:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3CFCE3853556 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 m2so36336240wrh.6 for ; Wed, 05 Apr 2023 07:05:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703552; 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=45DNQu9fBFY6qFaUoOeFel8jIU22OK+1TD92XMz9Rj4=; b=RojwQ+uHK2udovy+5Yxiu3q9KCMVeTtui4aEegMB7xbd8+fl48Ou6/91g7ZcVJfGou oScI9Wln/fovUbTAUHvtN3Kgc+6fEiKe/Cg+2hhodAgfuDvXTBFalXuBdwJVNAe5K/hk lh/4SqxF2ghLkAYkQqLniaPtEmbUxKQ/9SUndNY1w+WEq6O2A6yT21/p1ApXTDExSGe8 emLAWEkv/h39Z7i0UdvP+wn1UL/5R+yghD11iKAPHsrp/JT1BEtGPCT/casL/7NS63BK 3LCIktjOO9tbSOG+SKMSJw0kyaJZnaWBx7b71VmzWYl8+1CUVOkWibI3UN1d2BmsuwEd wWdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703552; 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=45DNQu9fBFY6qFaUoOeFel8jIU22OK+1TD92XMz9Rj4=; b=UflycqgGGSPBJlGZX7t81AVjsfFqcXZLiJzPPed+0g7FCNnhLEzq+x8hn2XfaNnUBi OzK0V+AHpu0G3AliRQQZc6gFKLJQl2Y1c/JRfZ6B8L221MpjFGqbV6Ma77wb8lTvNenZ fVyP5/hX90HjbLFspSOGFXbEanXhX6HUnIezjk1L2swMh02JHWJ5XREs72+y2vRut8II AAD8LL72MKZgGv8o4F/XUB0cgM6bo6rzNhem6FBpCVwDlRUZuuExPDVQsQkNlyQs5c1V nZjvitGDVWmjTo3SeC6o6+J9aJEm1UbajURqjm18PlaPlXNEMIZBJavOvHZUYgVWzxwH PMJA== X-Gm-Message-State: AAQBX9d8ufRlkd4lkNO1Rh9H91gFaUXD/+0V04tJDPssfyAoLevWAOkc pns6U6TbdkVFgJ3fCLOLeGVh9I5A3/jx+I7ApQ== X-Received: by 2002:adf:fdd0:0:b0:2ce:a862:551 with SMTP id i16-20020adffdd0000000b002cea8620551mr4388550wrs.58.1680703551698; Wed, 05 Apr 2023 07:05:51 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:51 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, mxlol233 Subject: [committed 33/88] gccrs: Add support for feature check. Date: Wed, 5 Apr 2023 16:03:17 +0200 Message-Id: <20230405140411.3016563-34-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, 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?1762346930066763090?= X-GMAIL-MSGID: =?utf-8?q?1762346930066763090?= From: mxlol233 This commit implements a very basic feature checking module. gcc/rust/ChangeLog: * Make-lang.in: Add object files: `rust-feature.o` and `rust-feature-gate.o` * checks/errors/rust-feature-gate.cc: New file. * checks/errors/rust-feature-gate.h: New file. * checks/errors/rust-feature.cc: New file. * checks/errors/rust-feature.h: New file. * rust-session-manager.cc: Add FeatureGate check. gcc/testsuite/ChangeLog: * rust/compile/feature.rs: New test. Signed-off-by: Xiao Ma --- gcc/rust/Make-lang.in | 2 + gcc/rust/checks/errors/rust-feature-gate.cc | 63 +++++++ gcc/rust/checks/errors/rust-feature-gate.h | 191 ++++++++++++++++++++ gcc/rust/checks/errors/rust-feature.cc | 66 +++++++ gcc/rust/checks/errors/rust-feature.h | 76 ++++++++ gcc/rust/rust-session-manager.cc | 4 + gcc/testsuite/rust/compile/feature.rs | 4 + 7 files changed, 406 insertions(+) create mode 100644 gcc/rust/checks/errors/rust-feature-gate.cc create mode 100644 gcc/rust/checks/errors/rust-feature-gate.h create mode 100644 gcc/rust/checks/errors/rust-feature.cc create mode 100644 gcc/rust/checks/errors/rust-feature.h create mode 100644 gcc/testsuite/rust/compile/feature.rs diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index 87f3ba66eba..a0c5757592e 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -161,6 +161,8 @@ GRS_OBJS = \ rust/rust-import-archive.o \ rust/rust-extern-crate.o \ rust/rust-builtins.o \ + rust/rust-feature.o \ + rust/rust-feature-gate.o \ $(END) # removed object files from here diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc b/gcc/rust/checks/errors/rust-feature-gate.cc new file mode 100644 index 00000000000..cd26f8a17f5 --- /dev/null +++ b/gcc/rust/checks/errors/rust-feature-gate.cc @@ -0,0 +1,63 @@ +// 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-feature-gate.h" +#include "rust-feature.h" + +namespace Rust { + +void +FeatureGate::check (AST::Crate &crate) +{ + std::vector valid_features; + for (const auto &attr : crate.inner_attrs) + { + if (attr.get_path ().as_string () == "feature") + { + const auto &attr_input = attr.get_attr_input (); + auto type = attr_input.get_attr_input_type (); + if (type == AST::AttrInput::AttrInputType::TOKEN_TREE) + { + const auto &option = static_cast ( + attr.get_attr_input ()); + std::unique_ptr meta_item ( + option.parse_to_meta_item ()); + for (const auto &item : meta_item->get_items ()) + { + const auto &name = item->as_string (); + auto tname = Feature::as_name (name); + if (!tname.is_none ()) + valid_features.push_back (Feature::create (tname.get ())); + else + rust_error_at (item->get_locus (), "unknown feature '%s'", + name.c_str ()); + } + } + } + } + valid_features.shrink_to_fit (); + + // TODO (mxlol233): add the real feature gate stuff. + auto &items = crate.items; + for (auto it = items.begin (); it != items.end (); it++) + { + auto &item = *it; + item->accept_vis (*this); + } +} +} // namespace Rust \ No newline at end of file diff --git a/gcc/rust/checks/errors/rust-feature-gate.h b/gcc/rust/checks/errors/rust-feature-gate.h new file mode 100644 index 00000000000..080c15ccd23 --- /dev/null +++ b/gcc/rust/checks/errors/rust-feature-gate.h @@ -0,0 +1,191 @@ +// 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_FEATURE_GATE_H +#define RUST_FEATURE_GATE_H + +#include "rust-ast-visitor.h" +#include "rust-ast-full.h" + +namespace Rust { + +struct Feature; + +class FeatureGate : public AST::ASTVisitor +{ +public: + FeatureGate () {} + + void check (AST::Crate &crate); + + void visit (AST::Token &tok) override {} + void visit (AST::DelimTokenTree &delim_tok_tree) override {} + void visit (AST::AttrInputMetaItemContainer &input) override {} + void visit (AST::IdentifierExpr &ident_expr) override {} + void visit (AST::Lifetime &lifetime) override {} + void visit (AST::LifetimeParam &lifetime_param) override {} + void visit (AST::ConstGenericParam &const_param) override {} + void visit (AST::PathInExpression &path) override {} + void visit (AST::TypePathSegment &segment) override {} + void visit (AST::TypePathSegmentGeneric &segment) override {} + void visit (AST::TypePathSegmentFunction &segment) override {} + void visit (AST::TypePath &path) override {} + void visit (AST::QualifiedPathInExpression &path) override {} + void visit (AST::QualifiedPathInType &path) override {} + void visit (AST::LiteralExpr &expr) override {} + void visit (AST::AttrInputLiteral &attr_input) override {} + void visit (AST::MetaItemLitExpr &meta_item) override {} + void visit (AST::MetaItemPathLit &meta_item) override {} + void visit (AST::BorrowExpr &expr) override {} + void visit (AST::DereferenceExpr &expr) override {} + void visit (AST::ErrorPropagationExpr &expr) override {} + void visit (AST::NegationExpr &expr) override {} + void visit (AST::ArithmeticOrLogicalExpr &expr) override {} + void visit (AST::ComparisonExpr &expr) override {} + void visit (AST::LazyBooleanExpr &expr) override {} + void visit (AST::TypeCastExpr &expr) override {} + void visit (AST::AssignmentExpr &expr) override {} + void visit (AST::CompoundAssignmentExpr &expr) override {} + void visit (AST::GroupedExpr &expr) override {} + void visit (AST::ArrayElemsValues &elems) override {} + void visit (AST::ArrayElemsCopied &elems) override {} + void visit (AST::ArrayExpr &expr) override {} + void visit (AST::ArrayIndexExpr &expr) override {} + void visit (AST::TupleExpr &expr) override {} + void visit (AST::TupleIndexExpr &expr) override {} + void visit (AST::StructExprStruct &expr) override {} + void visit (AST::StructExprFieldIdentifier &field) override {} + void visit (AST::StructExprFieldIdentifierValue &field) override {} + void visit (AST::StructExprFieldIndexValue &field) override {} + void visit (AST::StructExprStructFields &expr) override {} + void visit (AST::StructExprStructBase &expr) override {} + void visit (AST::CallExpr &expr) override {} + void visit (AST::MethodCallExpr &expr) override {} + void visit (AST::FieldAccessExpr &expr) override {} + void visit (AST::ClosureExprInner &expr) override {} + void visit (AST::BlockExpr &expr) override {} + void visit (AST::ClosureExprInnerTyped &expr) override {} + void visit (AST::ContinueExpr &expr) override {} + void visit (AST::BreakExpr &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::RangeToInclExpr &expr) override {} + void visit (AST::ReturnExpr &expr) override {} + void visit (AST::UnsafeBlockExpr &expr) override {} + void visit (AST::LoopExpr &expr) override {} + void visit (AST::WhileLoopExpr &expr) override {} + void visit (AST::WhileLetLoopExpr &expr) override {} + void visit (AST::ForLoopExpr &expr) override {} + void visit (AST::IfExpr &expr) override {} + void visit (AST::IfExprConseqElse &expr) override {} + void visit (AST::IfExprConseqIf &expr) override {} + void visit (AST::IfExprConseqIfLet &expr) override {} + void visit (AST::IfLetExpr &expr) override {} + void visit (AST::IfLetExprConseqElse &expr) override {} + void visit (AST::IfLetExprConseqIf &expr) override {} + void visit (AST::IfLetExprConseqIfLet &expr) override {} + void visit (AST::MatchExpr &expr) override {} + void visit (AST::AwaitExpr &expr) override {} + void visit (AST::AsyncBlockExpr &expr) override {} + void visit (AST::TypeParam ¶m) override {} + void visit (AST::LifetimeWhereClauseItem &item) override {} + void visit (AST::TypeBoundWhereClauseItem &item) override {} + void visit (AST::Method &method) override {} + void visit (AST::Module &module) override {} + void visit (AST::ExternCrate &crate) override {} + void visit (AST::UseTreeGlob &use_tree) override {} + void visit (AST::UseTreeList &use_tree) override {} + void visit (AST::UseTreeRebind &use_tree) override {} + void visit (AST::UseDeclaration &use_decl) override {} + void visit (AST::Function &function) override {} + void visit (AST::TypeAlias &type_alias) override {} + void visit (AST::StructStruct &struct_item) override {} + void visit (AST::TupleStruct &tuple_struct) override {} + void visit (AST::EnumItem &item) override {} + void visit (AST::EnumItemTuple &item) override {} + void visit (AST::EnumItemStruct &item) override {} + void visit (AST::EnumItemDiscriminant &item) override {} + void visit (AST::Enum &enum_item) override {} + void visit (AST::Union &union_item) override {} + void visit (AST::ConstantItem &const_item) override {} + void visit (AST::StaticItem &static_item) override {} + void visit (AST::TraitItemFunc &item) override {} + void visit (AST::TraitItemMethod &item) override {} + void visit (AST::TraitItemConst &item) override {} + void visit (AST::TraitItemType &item) override {} + void visit (AST::Trait &trait) override {} + void visit (AST::InherentImpl &impl) override {} + void visit (AST::TraitImpl &impl) override {} + void visit (AST::ExternalStaticItem &item) override {} + void visit (AST::ExternalFunctionItem &item) override {} + void visit (AST::ExternBlock &block) override {} + void visit (AST::MacroMatchFragment &match) override {} + void visit (AST::MacroMatchRepetition &match) override {} + void visit (AST::MacroMatcher &matcher) override {} + void visit (AST::MacroRulesDefinition &rules_def) override {} + void visit (AST::MacroInvocation ¯o_invoc) override {} + void visit (AST::MetaItemPath &meta_item) override {} + void visit (AST::MetaItemSeq &meta_item) override {} + void visit (AST::MetaWord &meta_item) override {} + void visit (AST::MetaNameValueStr &meta_item) override {} + void visit (AST::MetaListPaths &meta_item) override {} + void visit (AST::MetaListNameValueStr &meta_item) override {} + void visit (AST::LiteralPattern &pattern) override {} + void visit (AST::IdentifierPattern &pattern) override {} + void visit (AST::WildcardPattern &pattern) override {} + void visit (AST::RangePatternBoundLiteral &bound) override {} + void visit (AST::RangePatternBoundPath &bound) override {} + void visit (AST::RangePatternBoundQualPath &bound) override {} + void visit (AST::RangePattern &pattern) override {} + void visit (AST::ReferencePattern &pattern) override {} + void visit (AST::StructPatternFieldTuplePat &field) override {} + void visit (AST::StructPatternFieldIdentPat &field) override {} + void visit (AST::StructPatternFieldIdent &field) override {} + void visit (AST::StructPattern &pattern) override {} + void visit (AST::TupleStructItemsNoRange &tuple_items) override {} + void visit (AST::TupleStructItemsRange &tuple_items) override {} + void visit (AST::TupleStructPattern &pattern) override {} + void visit (AST::TuplePatternItemsMultiple &tuple_items) override {} + void visit (AST::TuplePatternItemsRanged &tuple_items) override {} + void visit (AST::TuplePattern &pattern) override {} + void visit (AST::GroupedPattern &pattern) override {} + void visit (AST::SlicePattern &pattern) override {} + void visit (AST::EmptyStmt &stmt) override {} + void visit (AST::LetStmt &stmt) override {} + void visit (AST::ExprStmtWithoutBlock &stmt) override {} + void visit (AST::ExprStmtWithBlock &stmt) override {} + void visit (AST::TraitBound &bound) override {} + void visit (AST::ImplTraitType &type) override {} + void visit (AST::TraitObjectType &type) override {} + void visit (AST::ParenthesisedType &type) override {} + void visit (AST::ImplTraitTypeOneBound &type) override {} + void visit (AST::TraitObjectTypeOneBound &type) override {} + void visit (AST::TupleType &type) override {} + void visit (AST::NeverType &type) override {} + void visit (AST::RawPointerType &type) override {} + void visit (AST::ReferenceType &type) override {} + void visit (AST::ArrayType &type) override {} + void visit (AST::SliceType &type) override {} + void visit (AST::InferredType &type) override {} + void visit (AST::BareFunctionType &type) override {} +}; +} // namespace Rust +#endif \ No newline at end of file diff --git a/gcc/rust/checks/errors/rust-feature.cc b/gcc/rust/checks/errors/rust-feature.cc new file mode 100644 index 00000000000..b87b4ca38ef --- /dev/null +++ b/gcc/rust/checks/errors/rust-feature.cc @@ -0,0 +1,66 @@ +// 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-feature.h" +#include "rust-session-manager.h" + +namespace Rust { + +Feature +Feature::create (Feature::Name name) +{ + switch (name) + { + case Feature::Name::ASSOCIATED_TYPE_BOUNDS: + return Feature (Feature::Name::ASSOCIATED_TYPE_BOUNDS, + Feature::State::ACCEPTED, "associated_type_bounds", + "1.34.0", 52662, + Optional::none (), ""); + case Feature::Name::INTRINSICS: + return Feature (Feature::Name::INTRINSICS, Feature::State::ACCEPTED, + "intrinsics", "1.0.0", 0, + Optional::none (), ""); + case Feature::Name::RUSTC_ATTRS: + return Feature (Feature::Name::RUSTC_ATTRS, Feature::State::ACCEPTED, + "rustc_attrs", "1.0.0", 0, + Optional::none (), ""); + case Feature::Name::DECL_MACRO: + return Feature (Feature::Name::DECL_MACRO, Feature::State::ACCEPTED, + "decl_macro", "1.0.0", 0, + Optional::none (), ""); + default: + gcc_unreachable (); + } +} + +const std::map Feature::name_hash_map = { + {"associated_type_bounds", Feature::Name::ASSOCIATED_TYPE_BOUNDS}, + {"intrinsics", Feature::Name::INTRINSICS}, + {"rustc_attrs", Feature::Name::RUSTC_ATTRS}, + {"decl_macro", Feature::Name::DECL_MACRO}, +}; + +Optional +Feature::as_name (const std::string &name) +{ + if (Feature::name_hash_map.count (name)) + return Optional::some (Feature::name_hash_map.at (name)); + return Optional::none (); +} + +} // namespace Rust \ No newline at end of file diff --git a/gcc/rust/checks/errors/rust-feature.h b/gcc/rust/checks/errors/rust-feature.h new file mode 100644 index 00000000000..bf93b090af5 --- /dev/null +++ b/gcc/rust/checks/errors/rust-feature.h @@ -0,0 +1,76 @@ +// 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_FEATURE_H +#define RUST_FEATURE_H + +#include "rust-session-manager.h" +#include "rust-optional.h" + +namespace Rust { + +class Feature +{ +public: + enum class State + { + ACCEPTED, + ACTIVE, + REMOVED, + STABILIZED, + }; + + enum class Name + { + ASSOCIATED_TYPE_BOUNDS, + INTRINSICS, + RUSTC_ATTRS, + DECL_MACRO, + }; + + const std::string &as_string () { return m_name_str; } + Name name () { return m_name; } + const std::string &description () { return m_description; } + State state () { return m_state; } + + static Optional as_name (const std::string &name); + static Feature create (Name name); + +private: + Feature (Name name, State state, const char *name_str, + const char *rustc_since, uint64_t issue_number, + const Optional &edition, + const char *description) + : m_state (state), m_name (name), m_name_str (name_str), + m_rustc_since (rustc_since), issue (issue_number), edition (edition), + m_description (description) + {} + + State m_state; + Name m_name; + std::string m_name_str; + std::string m_rustc_since; + uint64_t issue; + Optional edition; + std::string m_description; + + static const std::map name_hash_map; +}; + +} // namespace Rust +#endif \ No newline at end of file diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc index 70b058ff992..28ac2ba4a53 100644 --- a/gcc/rust/rust-session-manager.cc +++ b/gcc/rust/rust-session-manager.cc @@ -27,6 +27,7 @@ #include "rust-hir-type-check.h" #include "rust-privacy-check.h" #include "rust-const-checker.h" +#include "rust-feature-gate.h" #include "rust-tycheck-dump.h" #include "rust-compile.h" #include "rust-cfg-parser.h" @@ -558,6 +559,9 @@ Session::compile_crate (const char *filename) rust_debug ("END POST-EXPANSION AST DUMP"); } + // feature gating + FeatureGate ().check (parsed_crate); + if (last_step == CompileOptions::CompileStep::NameResolution) return; diff --git a/gcc/testsuite/rust/compile/feature.rs b/gcc/testsuite/rust/compile/feature.rs new file mode 100644 index 00000000000..305d112b7c4 --- /dev/null +++ b/gcc/testsuite/rust/compile/feature.rs @@ -0,0 +1,4 @@ +#![feature(AA)] //{ dg-error "unknown feature 'AA'" } + + +fn main(){} \ No newline at end of file From patchwork Wed Apr 5 14:03: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: 79675 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp349405vqo; Wed, 5 Apr 2023 07:27:44 -0700 (PDT) X-Google-Smtp-Source: AKy350ZRagqy6ttfL3jr06WyMV1S8T/kwwe7moN9nRRHV7uNB1/FQeg4u0ADQDDbqXUtsCMKPlZ6 X-Received: by 2002:aa7:d659:0:b0:502:52dd:57a2 with SMTP id v25-20020aa7d659000000b0050252dd57a2mr2188771edr.24.1680704864428; Wed, 05 Apr 2023 07:27:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704864; cv=none; d=google.com; s=arc-20160816; b=yLCl8y+ialfx9RY+lijmzJ0fJee+GCGNxyDuoi1jsO35QzfUZ6P76QPBFUg3sFfY9y RCkNo8J4A6ciVvel5SJKaTu/+V20ceN8vLsCTnnQE+XKsPVG+A0kENHfabmj99qX8qgw YkDPR2dgfZ6Mv5rLiGFF1Tgn350IB2WeuFeaRMnWldPR7CVo4HozFHEK5C8MRAkjss2D zaiDMRXdMGxqH/rTY2CjCG0IGHF0H1fZFWZfHR+xwri5c41LPKjdUaJeYb/+XqE0TiOq oEyuSaY5oijPZbc6Y5ohl1pWOvLIgzw6EwzbJbJrUTX/Mvy6uKEw72Vl3IQR0cjoq2nn P8eg== 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=IJv94FwdxVU7qFLsBfp5aqsTm7BXiKJFFXjCIiZgNqc=; b=fm2ffXd/iynNf1pe46UkoviQiN059ADQknNeSp3H3AGlkcd34C9IaNRmcuFhBjMf76 rw7lhBZ5ruJK1GFPISS1hFTCtsMcvXreBnnUnfRYUfpHn7oTgbQIw5Tmdc4CmroY5NL7 VIWUgo+oIm7BGeCag98Q3smL+WtPLA/o2URrfPkNNSWtSt+M2Aqj642M513LXeDncLI6 b426/mY7Du6VZs8AHRgZupV3pGMm47BoyuPXOXbeoJZn2J73GH/H4wQQP5Hu1pkQDDyO onmagjCxPkGIn7/VrvR5gm659hDCnSN6GamCW9lvPtLw1RzYV7pVBw8Y1FKh543GZdmt yRbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=emltIYwb; 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 b7-20020a056402138700b005024a8c6c30si3118609edv.272.2023.04.05.07.27.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:27:44 -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=emltIYwb; 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 865B538E7D44 for ; Wed, 5 Apr 2023 14:11:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 0523B3857033 for ; Wed, 5 Apr 2023 14:05:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0523B3857033 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-x42d.google.com with SMTP id j24so36392456wrd.0 for ; Wed, 05 Apr 2023 07:05:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703552; 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=IJv94FwdxVU7qFLsBfp5aqsTm7BXiKJFFXjCIiZgNqc=; b=emltIYwbesFQ69i36efGvsGu0HbAw90lCqROVYEUhq1trJjVq1v1sOVmj5HYrwQYdy fol7PILBKrFIsyxmzP9w9NtYl97sL474yPGMOOFSHI6mvnAWyZOCDEyFdPlBTwOFuu10 8UtveEyIFnoLYbDohBDwtETRU25k2j68cx5AoOG8rtFMNukSaRP60v5f1uTzd5fJxMWe msKv3/7zzDdz+QYt+sWViqDpddwmJ0lkArrJzyw7pfxsOWHGEOgJbBNXvp8CyhZ/18v5 aLfYHFB+AJM7709mVbTynZe9Zrj99E6zpr4AlzJlHeuCbAXx3R+2WEw2Wp/niXX2QmS5 hKlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703552; 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=IJv94FwdxVU7qFLsBfp5aqsTm7BXiKJFFXjCIiZgNqc=; b=dKNiM6yiihp8ih5KtsK+4X7Qg3RKAeJTfsn5CUXW2GVfxjxaxjl+6M3athRSEeJjJI k2a7BZTa8aGbZChSNsI62tspcrJ/Mo9GcZJngMTuzZRfCnKM6KBkCC8Nr9qM+StcnZwo l1aO/RgEOcI7U0jY4VrdCmpmEZJeDjy8CVjC3dJnb/fEd+8Eauu+ztyp1PxXBT8mfZLm aE+djEB/6r1+vQWdikXK8WdyUA6V519U7T2rOchnyFoEsXoercj/Eq64DpKJd7RUSBaA 04lccy+CRvD6s81EvK6nbXlZlts/cI0JOYVw0gzKosu6xK1LcKZtp+PF/fVhzxFkaA7f TZAg== X-Gm-Message-State: AAQBX9e7KtI30r75pmDLf6JR0kbacJhNCADvKnzl92fTDX4BT7T7NuYi v68wdtzG9RE5F+QcYgqvRFcGQZxhhF3eGMTwVA== X-Received: by 2002:adf:ce03:0:b0:2ce:a8f9:7cae with SMTP id p3-20020adfce03000000b002cea8f97caemr4696798wrn.53.1680703552129; Wed, 05 Apr 2023 07:05:52 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:51 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [committed 34/88] gccrs: Removed comment copy-pasted from gcc/tree.def Date: Wed, 5 Apr 2023 16:03:18 +0200 Message-Id: <20230405140411.3016563-35-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.6 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?1762346783963803610?= X-GMAIL-MSGID: =?utf-8?q?1762346783963803610?= From: Owen Avery gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): Removed copy-pasted comment. Signed-off-by: Owen Avery --- gcc/rust/backend/rust-compile-expr.cc | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index 436fc924a13..c26f6f440ec 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -1341,30 +1341,6 @@ CompileExpr::visit (HIR::MatchExpr &expr) // SWITCH_ALL_CASES_P is true if the switch includes a default label or the // case label ranges cover all possible values of the condition expression - /* Switch expression. - - TREE_TYPE is the original type of the condition, before any - language required type conversions. It may be NULL, in which case - the original type and final types are assumed to be the same. - - Operand 0 is the expression used to perform the branch, - Operand 1 is the body of the switch, which probably contains - CASE_LABEL_EXPRs. It may also be NULL, in which case operand 2 - must not be NULL. */ - // DEFTREECODE (SWITCH_EXPR, "switch_expr", tcc_statement, 2) - - /* Used to represent a case label. - - Operand 0 is CASE_LOW. It may be NULL_TREE, in which case the label - is a 'default' label. - Operand 1 is CASE_HIGH. If it is NULL_TREE, the label is a simple - (one-value) case label. If it is non-NULL_TREE, the case is a range. - Operand 2 is CASE_LABEL, which has the corresponding LABEL_DECL. - Operand 3 is CASE_CHAIN. This operand is only used in tree-cfg.cc to - speed up the lookup of case labels which use a particular edge in - the control flow graph. */ - // DEFTREECODE (CASE_LABEL_EXPR, "case_label_expr", tcc_statement, 4) - TyTy::TypeKind scrutinee_kind = check_match_scrutinee (expr, ctx); if (scrutinee_kind == TyTy::TypeKind::ERROR) { From patchwork Wed Apr 5 14:03: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: 79687 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp353916vqo; Wed, 5 Apr 2023 07:33:53 -0700 (PDT) X-Google-Smtp-Source: AKy350YkkdcSlCdpz0b7LddPDB2qEU26GxSPaZ+4Vhj8GW6ZCVvp/0cXFrh7opTJANRD0RjEFd98 X-Received: by 2002:a17:906:389a:b0:926:4e16:a551 with SMTP id q26-20020a170906389a00b009264e16a551mr2277134ejd.30.1680705233014; Wed, 05 Apr 2023 07:33:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705233; cv=none; d=google.com; s=arc-20160816; b=SPtB6PZju5snDw5jwTrPxeZDr3HVCpG3Zvk6Njgl5cX43zNaAk3M3yr2LG+R5xztg3 EvnoR16BdilmImJd1/efVnv+2vvL5psVc6fv3Yjr9zd7yQEFxBeBCmbKSMOpxU5HkRcI yuofp1JzevECWz6SSMk+aX1Cud59gXB7eEM1wP19rNLUzqfDpAbJwznWa1Lql+JcSXEr VcjA/F/SJlxxLXhXLbZiIn5Wt+DpNZWYwENc09tftexh+QV2K4OzpxXXT5Z6YMSIUKDL /+XIns23m/IUCa6xDaAgU7449f4/h2kG+FQvGPKpFSsKkqHme8fixlWdTE0zVpw6FwHx 2r9Q== 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=/cQSnI9jvcpfGvmqgitCi3DRuYQVR0oTJA4GWcgg+rw=; b=aXMhes7bbuWTryxi7OCxwtTQA63TcZJjK2Mm4EO0HG7DLV8bqIF5pMsLOmOTg9DT6u ON1qRFInzW+6fx9o4bXVTkd4a/Np1UTnbKyE5LWqOwdOA31ZS55H8inwvTT1dXB+BgM9 Hs2NdOJS46gfRityrv+OWNxdGiAOQUB8bBSnLHD8nBCZckq9/GDxEr5WhfwBwurZZm6o wHWu1fmF23scaq5xMXXysZY/gPeWIxdNZD5udsOktsdjbOs3QLpbwCt1n+nFvzTlk89R nTxeUos7gvhJX9L+PsN1kynNz0IZPXroUTkkEa84YvxsdSQcOv0PLgEbrVPl8PoEU7Tz Ftwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=CoMKIaa0; 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 i16-20020aa7c9d0000000b004bf976a1b56si2461105edt.627.2023.04.05.07.33.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:33:52 -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=CoMKIaa0; 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 0E0D4388DC50 for ; Wed, 5 Apr 2023 14:13:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id 3DE583853557 for ; Wed, 5 Apr 2023 14:05:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3DE583853557 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-x32c.google.com with SMTP id m8so10052480wmq.5 for ; Wed, 05 Apr 2023 07:05:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703552; 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=/cQSnI9jvcpfGvmqgitCi3DRuYQVR0oTJA4GWcgg+rw=; b=CoMKIaa0Z5KGqlmv72kesiMzMbb6wgTcPKMG0+mmTKDPt+W6TfCO5ZHmkiFJ90XKYO 213w3HmC7GDYW/EkEruUhdZlLNnjgKtOGvItUq0O1F/BN4t2Yv9JOAzX7Kz4434DcN/7 WN17OQma5AXrhZ66l1PRs4xPXZ5UT2VubMHPAM50q5rKZDXrYD+jiznUocX5IZa/lI7Z 4lSKJpL/aZwKsZ1czCjTHgmGwo5l2Vvw/Rn4gkF83aBuLb0hzh1DXak96x4VsbfzmdwY aQAaPwAa3eMOdVuCdUzjM7LNb0I/uVpunThjy+x9iCx64lHrcfeN044TtNVbtFOLr29+ wvcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703552; 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=/cQSnI9jvcpfGvmqgitCi3DRuYQVR0oTJA4GWcgg+rw=; b=B5C45VLvp8fZON4r2FpvOjMmMhD6sliC86HCBzVDbSf5B0RtCq/fyVvsybQupwCGFg kWkY3VC896nbDD12dIiVC5j/wosdF8FuQGi06S8WHuaOr9QAbIv6vqy9/n0iypR1nMl+ LjHpIgQKBDYS0Urru0JZuCQewd9VTPWOJ39YqGYj0/KrCm3PzL58AAhBSr1s7qqS4ZRx KUc4mYzMaqz87o9HFB9SH780a9G0TAua0sSKAtFVoN816zLlbwDhfrvDucQi6trYiqnS VGhuhW0XJNVDlok8N7BO4uaz+sE3om4vkoxzMNYPo+ZcxC7yVGBt94lW5f0Tiirl9zfa zu5w== X-Gm-Message-State: AAQBX9fxjrlwrM1AUYPhtQ+PL1r09sRDlNexSajETQNMjkq/ZnY6RHoy n1QXy02s6Xri+4FzR1coqG/hICYP6J9+CnBwPg== X-Received: by 2002:a05:600c:4da5:b0:3ee:93d2:c915 with SMTP id v37-20020a05600c4da500b003ee93d2c915mr2019032wmp.6.1680703552588; Wed, 05 Apr 2023 07:05:52 -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.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:52 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 35/88] gccrs: Add another test case for passing associated type-bounds Date: Wed, 5 Apr 2023 16:03:19 +0200 Message-Id: <20230405140411.3016563-36-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.6 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?1762347170797005647?= X-GMAIL-MSGID: =?utf-8?q?1762347170797005647?= From: Philip Herron This demonstrates that this also works for custom algebraic data types too. gcc/testsuite/ChangeLog: * rust/execute/torture/issue-1720-2.rs: New test. Signed-off-by: Philip Herron --- .../rust/execute/torture/issue-1720-2.rs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 gcc/testsuite/rust/execute/torture/issue-1720-2.rs diff --git a/gcc/testsuite/rust/execute/torture/issue-1720-2.rs b/gcc/testsuite/rust/execute/torture/issue-1720-2.rs new file mode 100644 index 00000000000..35833dbb813 --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/issue-1720-2.rs @@ -0,0 +1,30 @@ +mod core { + mod ops { + #[lang = "add"] + pub trait Add { + type Output; + + fn add(self, rhs: Rhs) -> Self::Output; + } + } +} + +struct Foo(i32); + +impl core::ops::Add for Foo { + type Output = i32; + + fn add(self, rhs: Foo) -> Self::Output { + self.0 + rhs.0 + } +} + +pub fn bar>(a: T) -> i32 { + a + a +} + +pub fn main() -> i32 { + let a = Foo(1); + + bar(a) - 2 +} From patchwork Wed Apr 5 14:03: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: 79676 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp349402vqo; Wed, 5 Apr 2023 07:27:44 -0700 (PDT) X-Google-Smtp-Source: AKy350YTM66A52CuF2YXG6DGLijTaihd17eYT9B89ene2aLpTHK+2qpVxjLroppvw6BgY4v53U6I X-Received: by 2002:a17:906:495:b0:930:d17b:959b with SMTP id f21-20020a170906049500b00930d17b959bmr3059841eja.22.1680704864133; Wed, 05 Apr 2023 07:27:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704864; cv=none; d=google.com; s=arc-20160816; b=UTLaT5StiudUZHsrpoHHHj8yTwNEgKouckotBYOp83DFpF1c7FdDCD85Gx96B/5wQV rqTC8Bpw/jjvCsluh88dPC/hsqfsBk3i/WG41M+juPiVmOjLKKOkEBA62z9gCHSH4yXF IUFT7nk6RDj6iFGOxBJAbiKU26Nw6EF7IktpTV8y586KHwqaJy6e1d7LRxKF87/hxZbv gsmKK1dLOT6SD8iZhvzuTdlZLRbKCcTw0mniYsbtUX7kmfOR8epM8thP5hwvvXINqZ4Y trzuDLdE+O8nQeRE7Dbebjvv8m4qsv5TlHW1ybSRDeYQMQR3a8KjmHmGLEmG6rAhDvJW clbA== 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=TMb6dOaZEARu81vby2cyTeo9PCXn8l9sBPaHTXh8D84=; b=e7mBYR2mOVycMWaS3jR/nyh5uO3kuIFSA5XJB1Mch0KnU9tMiYmWEMethLbxkFL3o1 0U0Y5og5kDQ9PsiM7NSfD83w7IzekhQcJDVWzbcysILtS/6k/pp+tHf7AtThn2SdoWsp parX3WhEPSSfQYug80XOBdUW6kEG0Ln24B8aYoPzwL5RW0e4oBz7mtmSY4NnuqcDNHyj EX5AvlwXV6Jh2dDMy/sQBdXYlLERsLhc/gyIYm+7vAJKeoBNS3h9TmWzdAkfvJsD86TX jQekJ6r7Ol2S9VeUEVtUuAPDNhdtzIx6rv+ZxQS1DrAXSnZAfNgfZD/KyYJ9qIigPxlg mHnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=M8882M9s; 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 z25-20020a170906075900b009395b8121cesi925201ejb.178.2023.04.05.07.27.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:27:44 -0700 (PDT) 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=M8882M9s; 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 7578D386C2CE for ; Wed, 5 Apr 2023 14:11:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id BCEA43851C15 for ; Wed, 5 Apr 2023 14:05:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BCEA43851C15 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-x32f.google.com with SMTP id o32so20949536wms.1 for ; Wed, 05 Apr 2023 07:05:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703553; 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=TMb6dOaZEARu81vby2cyTeo9PCXn8l9sBPaHTXh8D84=; b=M8882M9sNlp42X+pIAGNh0FK6jEwoHDEfTbepEAJ6sCA0ug1ZJzelv5xYSadjjjrNE l1kJ2S/ggFhJFHMenf5zSlbmMEkUVLXq+p0WKPL6SaEN7/uz9AIqmC759/bqsJ/uC10w JJ/YPAhmEBN13VfTnum9cX9Eb9+rVHpu4MsPpMux/pAXkkaumMiKwI8ww5HFZRDht2p0 9SnXZhu9rE/1VD0zu9Y1qqzMLearMnnBDx+eKSRy8KZXWU8ksS4+jNM61PummnH8X2v3 X2x6H3J3Aeu1eq67YDL90fg8IlFADeY4VhaJ+euFpiGapWDdBrKEbODX13eyQA353R1F ebbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703553; 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=TMb6dOaZEARu81vby2cyTeo9PCXn8l9sBPaHTXh8D84=; b=X2ceP5zLP3sJDW/oAMfKZAQdJv1AjphDgG6iEF+A3Y5CXeqHrTPhtir4T5ZtdMYaaa Znj9gRaG913GS9UhmWGlvLm1kyiH596GIthlWa4INL46whEBLvgfNFnTNRq+HRUanX5J nZwfwTb+5f4oEr80SnTFDZokEVRIQQLMuXpWXQlesVs6rSFXK/sDVcXG7zTWt/Wo74RJ bc/eArioPxH6o15IemtwDhkTD2p+dBxb7WCdwKY+PYgczl1xXKNv5QiBBtcMk2wNZx2D hsntXRai9r/P9eqsP33DW15Iy8zwnV3fsbnTBJ58GwXZVF2lNTWfpH37FGLuOPp+aeZs +tyw== X-Gm-Message-State: AAQBX9f0D8HPNpSBtKEISzIJvOB0X+adLpvilBDtb/HMrUASGB5TA+cc chxGc8FR6pTvm96Mfyp2RP/aQuIYb5vFby+38g== X-Received: by 2002:a1c:f216:0:b0:3ee:4ff0:83d6 with SMTP id s22-20020a1cf216000000b003ee4ff083d6mr4907618wmc.40.1680703553313; Wed, 05 Apr 2023 07:05:53 -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.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:53 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 36/88] gccrs: Move TypePredicateItem impl out of the header Date: Wed, 5 Apr 2023 16:03:20 +0200 Message-Id: <20230405140411.3016563-37-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.6 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?1762346783401149687?= X-GMAIL-MSGID: =?utf-8?q?1762346783401149687?= From: Philip Herron This moves the implementation code out of the header and into its respective cc file. Signed-off-by: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-tyty-bounds.cc (TypeBoundPredicateItem::error): refactor (TypeBoundPredicateItem::is_error): likewise (TypeBoundPredicateItem::get_parent): likewise * typecheck/rust-tyty.h: Move the implementation for the above --- gcc/rust/typecheck/rust-tyty-bounds.cc | 24 ++++++++++++++++++++++++ gcc/rust/typecheck/rust-tyty.h | 16 ++++------------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc b/gcc/rust/typecheck/rust-tyty-bounds.cc index 30f7b0d02e3..e7eb9a760f5 100644 --- a/gcc/rust/typecheck/rust-tyty-bounds.cc +++ b/gcc/rust/typecheck/rust-tyty-bounds.cc @@ -364,6 +364,30 @@ TypeBoundPredicate::lookup_associated_item (const std::string &search) const return TypeBoundPredicateItem (this, trait_item_ref); } +TypeBoundPredicateItem::TypeBoundPredicateItem ( + const TypeBoundPredicate *parent, + const Resolver::TraitItemReference *trait_item_ref) + : parent (parent), trait_item_ref (trait_item_ref) +{} + +TypeBoundPredicateItem +TypeBoundPredicateItem::error () +{ + return TypeBoundPredicateItem (nullptr, nullptr); +} + +bool +TypeBoundPredicateItem::is_error () const +{ + return parent == nullptr || trait_item_ref == nullptr; +} + +const TypeBoundPredicate * +TypeBoundPredicateItem::get_parent () const +{ + return parent; +} + TypeBoundPredicateItem TypeBoundPredicate::lookup_associated_item ( const Resolver::TraitItemReference *ref) const diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index 20a243fe980..7d32ed59494 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -82,19 +82,11 @@ class TypeBoundPredicateItem { public: TypeBoundPredicateItem (const TypeBoundPredicate *parent, - const Resolver::TraitItemReference *trait_item_ref) - : parent (parent), trait_item_ref (trait_item_ref) - {} + const Resolver::TraitItemReference *trait_item_ref); - static TypeBoundPredicateItem error () - { - return TypeBoundPredicateItem (nullptr, nullptr); - } + static TypeBoundPredicateItem error (); - bool is_error () const - { - return parent == nullptr || trait_item_ref == nullptr; - } + bool is_error () const; BaseType *get_tyty_for_receiver (const TyTy::BaseType *receiver); @@ -102,7 +94,7 @@ public: bool needs_implementation () const; - const TypeBoundPredicate *get_parent () const { return parent; } + const TypeBoundPredicate *get_parent () const; Location get_locus () const; From patchwork Wed Apr 5 14:03: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: 79679 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp350958vqo; Wed, 5 Apr 2023 07:30:02 -0700 (PDT) X-Google-Smtp-Source: AKy350Y+QwH4f5sMQ/6HgCFB4FXpqr5nby2JFjRdahm0bxSMSUtY3Qm68XxXlySC5W03leyYfhEe X-Received: by 2002:aa7:d4c3:0:b0:4fb:4354:ab2e with SMTP id t3-20020aa7d4c3000000b004fb4354ab2emr2112699edr.28.1680705002446; Wed, 05 Apr 2023 07:30:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705002; cv=none; d=google.com; s=arc-20160816; b=G/nPKcx+MTgZ5+ajS/VFPN5l8s8gs0mHseVgpbg2KruoLXAcErFmnBvz2uaxqsF9el 9o/Q45yiiX4fCBKaOYvFQiVv/P3O9I4IxXmRCUKWROsIBq/v73mnO5Mj08OiJBLrxxTq U+aGJP+8cZBS6iomXyJXUD8cmQl7P4GaNGjA0h933KmmxIby5CUGwmdnf3ja8kppG1xN 1gDk3RVtL0+okD9JSdtSaeg0Ox/AS2TYELh8o+ehROpwoI2v0euzawJHCUvK7KIwcHFy nNpek04fmsVO6FzFGRsQFCuvxsO7ZrSnLF/33O8xq/+XACNcvuCe78QYheNJ2iXTADtR xOiA== 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=vZ2ck1LP7RLliorD/w4KWwhmYFaX4KjIMQ5oOsUP1BU=; b=oyACXcNGq1T4hvHdSP58dWvS3tiAc6RgiGIMP+BrcLw7Hmy89mwVw/H3HcZPKUR8UY 0SGyR6supxZqDGNO6wTh9fmy7W96NrP1U0s4MWgIIDEtAgeIKDzMK2dQySK8BsF8KHfS luEfW9/dUB7VbixJ05Dqi22b2OVpkgjkBBqjof/eEB4wUiDH2Z5OPkIClvbOqnJYVaiM 85NDTjIMhuh0fF+Cbb6sjTjSv9+x3ZDPk1ZGcGVBPiiTbtxEmbUhH7FEwxP5vOaAd+nM ZXZgoUGbUf2mTnLv6XbqT/iJrS0FCDCpUZv8meVasVVd74SbFXpCClnRCTxpLLKPlbBI 1VIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b="NTv/AmFH"; 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 r12-20020aa7da0c000000b004fd1f9d8256si1354686eds.208.2023.04.05.07.30.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:30:02 -0700 (PDT) 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="NTv/AmFH"; 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 3CA0F3928A04 for ; Wed, 5 Apr 2023 14:12:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id 0E1B03851C28 for ; Wed, 5 Apr 2023 14:05:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0E1B03851C28 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-x32f.google.com with SMTP id o32so20949571wms.1 for ; Wed, 05 Apr 2023 07:05:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703554; 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=vZ2ck1LP7RLliorD/w4KWwhmYFaX4KjIMQ5oOsUP1BU=; b=NTv/AmFHVj83y4J3qtZAQm0dMJIu1uMWMKDsDz9pFmBCC0pAJY73mDwVodnM8VQBFU Fk8uj6krTSUhPARbhB/hhRb1HEiyEQpDFF3zZP2JpP02ogCytsi/XKI3sbHbK/0nk2ck 34ZB25XX2blIAkWiN4HrjyJ81MCBcIyLXlRUR+Z6TPZSAW2GFLT5mQDeUuqM8hQqoQhI j5ayqQpEh1iOAYYzmls77wFT6zsX7O6E/SivxL337l0vObXfUTxoBRKkWWbY1RZvz04j 4rcIoHMdyW+X3GdkHO5aSIEQLcUVGRv1Vm8OiuHRTbMdZgQ8k+V1vUKPwbJB53B2AbP1 DmKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703554; 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=vZ2ck1LP7RLliorD/w4KWwhmYFaX4KjIMQ5oOsUP1BU=; b=Dmb61n0VaoLJYq/CYmhK6UkCrmzkxg8FDy6R6fwna+JR67Pwqo8/DMCDYTIsyAmvwj EmCjqbKuTpWPx6V1QosNBRN9jjM0MEkuLMUr5Mmg68+EAozta8uYX41OQEZ3x9fdI208 jdOWnZ0RfIblU6zuqiC7z0xHWkLMM22vRmmkV7TZesLvkLCuhRNfxjYpH1Po1OZiD+PX UZVJpULbe8iZrWxZC5ikCGjVakpiTUtJHf9ASZr2SPYv1sKfRpzjMNaVm1pHFua3lEqI BijjOBd9tPRgU/hAbLtHGpq///qNdkc/e+EIyVqzI1jC1xFIcqjpxEp02YjnQBtbOG2O N2Qg== X-Gm-Message-State: AAQBX9ccYSdNWt5wb9Lb2Tk7dHytaiOqF0t5PXNW5SBxOWyQ6c52p3z9 AyuCpDSua/RRBDlvZ82hnmImy0ez05v4ibLD7A== X-Received: by 2002:a05:600c:246:b0:3ed:e447:1ed0 with SMTP id 6-20020a05600c024600b003ede4471ed0mr4857968wmj.14.1680703554241; Wed, 05 Apr 2023 07:05:54 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:53 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 37/88] gccrs: Refactor TyVar and TypeBoundPredicates Date: Wed, 5 Apr 2023 16:03:21 +0200 Message-Id: <20230405140411.3016563-38-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.6 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?1762346928543230833?= X-GMAIL-MSGID: =?utf-8?q?1762346928543230833?= From: Philip Herron This extract these helpers into seperate files Signed-off-by: Philip Herron gcc/rust/ChangeLog: * Make-lang.in: update makefile * typecheck/rust-tyty.cc (TyVar::TyVar): move to new file (TyVar::get_tyty): likewise (TyVar::get_implicit_infer_var): likewise (TyVar::subst_covariant_var): likewise (TyVar::clone): likewise (TyVar::monomorphized_clone): likewise (TyWithLocation::TyWithLocation): likewise * typecheck/rust-tyty.h (class BaseType): cleanup (class TypeBoundPredicate): move to its own file (class TypeBoundPredicateItem): likewise (class TypeBoundsMappings): likewise (class TyVar): likewise (class TyWithLocation): likewise * typecheck/rust-tyty-bounds.h: New file. * typecheck/rust-tyty-util.cc: New file. * typecheck/rust-tyty-util.h: New file. --- gcc/rust/Make-lang.in | 1 + gcc/rust/typecheck/rust-tyty-bounds.h | 88 +++++++++++++++++++ gcc/rust/typecheck/rust-tyty-util.cc | 116 ++++++++++++++++++++++++++ gcc/rust/typecheck/rust-tyty-util.h | 69 +++++++++++++++ gcc/rust/typecheck/rust-tyty.cc | 90 -------------------- gcc/rust/typecheck/rust-tyty.h | 90 +------------------- 6 files changed, 276 insertions(+), 178 deletions(-) create mode 100644 gcc/rust/typecheck/rust-tyty-bounds.h create mode 100644 gcc/rust/typecheck/rust-tyty-util.cc create mode 100644 gcc/rust/typecheck/rust-tyty-util.h diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index a0c5757592e..2aa61bcfb19 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -115,6 +115,7 @@ GRS_OBJS = \ rust/rust-pub-restricted-visitor.o \ rust/rust-privacy-reporter.o \ rust/rust-tyty.o \ + rust/rust-tyty-util.o \ rust/rust-tyty-call.o \ rust/rust-tyctx.o \ rust/rust-tyty-bounds.o \ diff --git a/gcc/rust/typecheck/rust-tyty-bounds.h b/gcc/rust/typecheck/rust-tyty-bounds.h new file mode 100644 index 00000000000..44839bd0b40 --- /dev/null +++ b/gcc/rust/typecheck/rust-tyty-bounds.h @@ -0,0 +1,88 @@ +// 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_TYTY_BOUNDS_H +#define RUST_TYTY_BOUNDS_H + +#include "rust-location.h" + +namespace Rust { + +namespace Resolver { +class TraitReference; +class TraitItemReference; +class AssociatedImplTrait; +} // namespace Resolver + +namespace TyTy { + +class BaseType; +class TypeBoundPredicate; +class TypeBoundPredicateItem +{ +public: + TypeBoundPredicateItem (const TypeBoundPredicate *parent, + const Resolver::TraitItemReference *trait_item_ref); + + static TypeBoundPredicateItem error (); + + bool is_error () const; + + BaseType *get_tyty_for_receiver (const TyTy::BaseType *receiver); + + const Resolver::TraitItemReference *get_raw_item () const; + + bool needs_implementation () const; + + const TypeBoundPredicate *get_parent () const; + + Location get_locus () const; + +private: + const TypeBoundPredicate *parent; + const Resolver::TraitItemReference *trait_item_ref; +}; + +class TypeBoundsMappings +{ +protected: + TypeBoundsMappings (std::vector specified_bounds); + +public: + std::vector &get_specified_bounds (); + + const std::vector &get_specified_bounds () const; + + size_t num_specified_bounds () const; + + std::string raw_bounds_as_string () const; + + std::string bounds_as_string () const; + + std::string raw_bounds_as_name () const; + +protected: + void add_bound (TypeBoundPredicate predicate); + + std::vector specified_bounds; +}; + +} // namespace TyTy +} // namespace Rust + +#endif // RUST_TYTY_BOUNDS_H diff --git a/gcc/rust/typecheck/rust-tyty-util.cc b/gcc/rust/typecheck/rust-tyty-util.cc new file mode 100644 index 00000000000..5037f68cb3f --- /dev/null +++ b/gcc/rust/typecheck/rust-tyty-util.cc @@ -0,0 +1,116 @@ +// 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-hir-type-check.h" +#include "rust-tyty.h" + +namespace Rust { +namespace TyTy { + +TyVar::TyVar (HirId ref) : ref (ref) +{ + // ensure this reference is defined within the context + auto context = Resolver::TypeCheckContext::get (); + BaseType *lookup = nullptr; + bool ok = context->lookup_type (ref, &lookup); + rust_assert (ok); +} + +BaseType * +TyVar::get_tyty () const +{ + auto context = Resolver::TypeCheckContext::get (); + BaseType *lookup = nullptr; + bool ok = context->lookup_type (ref, &lookup); + rust_assert (ok); + return lookup; +} + +TyVar +TyVar::get_implicit_infer_var (Location locus) +{ + auto mappings = Analysis::Mappings::get (); + auto context = Resolver::TypeCheckContext::get (); + + InferType *infer = new InferType (mappings->get_next_hir_id (), + InferType::InferTypeKind::GENERAL, locus); + context->insert_type (Analysis::NodeMapping (mappings->get_current_crate (), + UNKNOWN_NODEID, + infer->get_ref (), + UNKNOWN_LOCAL_DEFID), + infer); + mappings->insert_location (infer->get_ref (), locus); + + return TyVar (infer->get_ref ()); +} + +TyVar +TyVar::subst_covariant_var (TyTy::BaseType *orig, TyTy::BaseType *subst) +{ + if (orig->get_kind () != TyTy::TypeKind::PARAM) + return TyVar (subst->get_ty_ref ()); + else if (subst->get_kind () == TyTy::TypeKind::PARAM) + { + TyTy::ParamType *p = static_cast (subst); + if (p->resolve ()->get_kind () == TyTy::TypeKind::PARAM) + { + return TyVar (subst->get_ty_ref ()); + } + } + + return TyVar (subst->get_ref ()); +} + +TyVar +TyVar::clone () const +{ + TyTy::BaseType *c = get_tyty ()->clone (); + return TyVar (c->get_ref ()); +} + +TyVar +TyVar::monomorphized_clone () const +{ + auto mappings = Analysis::Mappings::get (); + auto context = Resolver::TypeCheckContext::get (); + + // this needs a new hirid + TyTy::BaseType *c = get_tyty ()->monomorphized_clone (); + c->set_ref (mappings->get_next_hir_id ()); + + // insert it + context->insert_type (Analysis::NodeMapping (mappings->get_current_crate (), + UNKNOWN_NODEID, c->get_ref (), + UNKNOWN_LOCAL_DEFID), + c); + + return TyVar (c->get_ref ()); +} + +TyWithLocation::TyWithLocation (BaseType *ty, Location locus) + : ty (ty), locus (locus) +{} + +TyWithLocation::TyWithLocation (BaseType *ty) : ty (ty) +{ + auto mappings = Analysis::Mappings::get (); + locus = mappings->lookup_location (ty->get_ref ()); +} + +} // namespace TyTy +} // namespace Rust diff --git a/gcc/rust/typecheck/rust-tyty-util.h b/gcc/rust/typecheck/rust-tyty-util.h new file mode 100644 index 00000000000..eccbb4423d5 --- /dev/null +++ b/gcc/rust/typecheck/rust-tyty-util.h @@ -0,0 +1,69 @@ +// 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_TYTY_UTIL_H +#define RUST_TYTY_UTIL_H + +#include "rust-hir-map.h" + +namespace Rust { +namespace TyTy { + +class BaseType; + +// this is a placeholder for types that can change like inference variables +class TyVar +{ +public: + explicit TyVar (HirId ref); + + HirId get_ref () const { return ref; } + + BaseType *get_tyty () const; + + TyVar clone () const; + + TyVar monomorphized_clone () const; + + static TyVar get_implicit_infer_var (Location locus); + + static TyVar subst_covariant_var (TyTy::BaseType *orig, + TyTy::BaseType *subst); + +private: + HirId ref; +}; + +class TyWithLocation +{ +public: + explicit TyWithLocation (BaseType *ty, Location locus); + explicit TyWithLocation (BaseType *ty); + + BaseType *get_ty () const { return ty; } + Location get_locus () const { return locus; } + +private: + BaseType *ty; + Location locus; +}; + +} // namespace TyTy +} // namespace Rust + +#endif // RUST_TYTY_UTIL_H diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index fd57a534562..55a8123ce87 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -330,96 +330,6 @@ BaseType::debug () const debug_str ().c_str ()); } -TyVar::TyVar (HirId ref) : ref (ref) -{ - // ensure this reference is defined within the context - auto context = Resolver::TypeCheckContext::get (); - BaseType *lookup = nullptr; - bool ok = context->lookup_type (ref, &lookup); - rust_assert (ok); -} - -BaseType * -TyVar::get_tyty () const -{ - auto context = Resolver::TypeCheckContext::get (); - BaseType *lookup = nullptr; - bool ok = context->lookup_type (ref, &lookup); - rust_assert (ok); - return lookup; -} - -TyVar -TyVar::get_implicit_infer_var (Location locus) -{ - auto mappings = Analysis::Mappings::get (); - auto context = Resolver::TypeCheckContext::get (); - - InferType *infer = new InferType (mappings->get_next_hir_id (), - InferType::InferTypeKind::GENERAL, locus); - context->insert_type (Analysis::NodeMapping (mappings->get_current_crate (), - UNKNOWN_NODEID, - infer->get_ref (), - UNKNOWN_LOCAL_DEFID), - infer); - mappings->insert_location (infer->get_ref (), locus); - - return TyVar (infer->get_ref ()); -} - -TyVar -TyVar::subst_covariant_var (TyTy::BaseType *orig, TyTy::BaseType *subst) -{ - if (orig->get_kind () != TyTy::TypeKind::PARAM) - return TyVar (subst->get_ty_ref ()); - else if (subst->get_kind () == TyTy::TypeKind::PARAM) - { - TyTy::ParamType *p = static_cast (subst); - if (p->resolve ()->get_kind () == TyTy::TypeKind::PARAM) - { - return TyVar (subst->get_ty_ref ()); - } - } - - return TyVar (subst->get_ref ()); -} - -TyVar -TyVar::clone () const -{ - TyTy::BaseType *c = get_tyty ()->clone (); - return TyVar (c->get_ref ()); -} - -TyVar -TyVar::monomorphized_clone () const -{ - auto mappings = Analysis::Mappings::get (); - auto context = Resolver::TypeCheckContext::get (); - - // this needs a new hirid - TyTy::BaseType *c = get_tyty ()->monomorphized_clone (); - c->set_ref (mappings->get_next_hir_id ()); - - // insert it - context->insert_type (Analysis::NodeMapping (mappings->get_current_crate (), - UNKNOWN_NODEID, c->get_ref (), - UNKNOWN_LOCAL_DEFID), - c); - - return TyVar (c->get_ref ()); -} - -TyWithLocation::TyWithLocation (BaseType *ty, Location locus) - : ty (ty), locus (locus) -{} - -TyWithLocation::TyWithLocation (BaseType *ty) : ty (ty) -{ - auto mappings = Analysis::Mappings::get (); - locus = mappings->lookup_location (ty->get_ref ()); -} - void InferType::accept_vis (TyVisitor &vis) { diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index 7d32ed59494..a8bdf6f3a15 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -25,6 +25,8 @@ #include "rust-abi.h" #include "rust-common.h" #include "rust-identifier.h" +#include "rust-tyty-bounds.h" +#include "rust-tyty-util.h" namespace Rust { @@ -76,57 +78,6 @@ public: static std::string to_string (TypeKind kind); }; -class BaseType; -class TypeBoundPredicate; -class TypeBoundPredicateItem -{ -public: - TypeBoundPredicateItem (const TypeBoundPredicate *parent, - const Resolver::TraitItemReference *trait_item_ref); - - static TypeBoundPredicateItem error (); - - bool is_error () const; - - BaseType *get_tyty_for_receiver (const TyTy::BaseType *receiver); - - const Resolver::TraitItemReference *get_raw_item () const; - - bool needs_implementation () const; - - const TypeBoundPredicate *get_parent () const; - - Location get_locus () const; - -private: - const TypeBoundPredicate *parent; - const Resolver::TraitItemReference *trait_item_ref; -}; - -class TypeBoundsMappings -{ -protected: - TypeBoundsMappings (std::vector specified_bounds); - -public: - std::vector &get_specified_bounds (); - - const std::vector &get_specified_bounds () const; - - size_t num_specified_bounds () const; - - std::string raw_bounds_as_string () const; - - std::string bounds_as_string () const; - - std::string raw_bounds_as_name () const; - -protected: - void add_bound (TypeBoundPredicate predicate); - - std::vector specified_bounds; -}; - extern void set_cmp_autoderef_mode (); extern void @@ -268,43 +219,6 @@ protected: Analysis::Mappings *mappings; }; -// this is a placeholder for types that can change like inference variables -class TyVar -{ -public: - explicit TyVar (HirId ref); - - HirId get_ref () const { return ref; } - - BaseType *get_tyty () const; - - TyVar clone () const; - - TyVar monomorphized_clone () const; - - static TyVar get_implicit_infer_var (Location locus); - - static TyVar subst_covariant_var (TyTy::BaseType *orig, - TyTy::BaseType *subst); - -private: - HirId ref; -}; - -class TyWithLocation -{ -public: - explicit TyWithLocation (BaseType *ty, Location locus); - explicit TyWithLocation (BaseType *ty); - - BaseType *get_ty () const { return ty; } - Location get_locus () const { return locus; } - -private: - BaseType *ty; - Location locus; -}; - class InferType : public BaseType { public: From patchwork Wed Apr 5 14:03: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: 79677 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp350007vqo; Wed, 5 Apr 2023 07:28:36 -0700 (PDT) X-Google-Smtp-Source: AKy350a3lgMUox1AW+Z11KNHbZqFkVtZbo4VpSjko83Fpk2bjXFRKSu9OXPEtkuWOFMsahbBEHM3 X-Received: by 2002:a17:906:7115:b0:921:7e42:2777 with SMTP id x21-20020a170906711500b009217e422777mr2847769ejj.69.1680704916122; Wed, 05 Apr 2023 07:28:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704916; cv=none; d=google.com; s=arc-20160816; b=s3kkTT7OD3kAJqGfQns8eLH0vEaoiMGSlkHnTYxJtXL/h/CbA3oNyxy1Ki1SGWMeMJ qVqqvof6FfD2f66KrTomDCURIe477j6Xi/3AfvolBAh+QgfjOHdMa27oStLpWG53L4pE 5rQv0d/bLSH+yKpTtjFkBbBQNkR79zEtJUzJ1wQfdwk9ftRSx+/YaosTi74+IqpLlzyM aNOgSVbhM0fjKzrUIfKPMw1vs1Nx6dA5gTFEu46jE/o6Y6OlcPAc9CjSZ80sa19HWcy2 e27W1AeBbb1UzKCClrIjIrTl0u2iE8LZycyz9Jag7Rs43XLSNHSG8M9kmCOIMlFb6WSJ OwAg== 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=hGGPnQ4kceGPM6pQ2i2+VLBnR8ygeXgtKVhP8DvtjAU=; b=BNWwBvIgf0LTGXN7YOjwkCMa0Fwa2OAJeBY6wXjm3KpME86+6h1liblXFLBDcwxCYj IGer8MUUuloITPGSqjRgsnVChVYR/+mfEBzCoO/C22aXvAs4ZssQMJxBZg7wayE3AkSe lse0r2+V59qkr8fkWhCiEKnOdmF3SVM2qjHUsg9+FGPZ+6cWFsQ7CXUozYPTkm52CrZF NUVdb0TPtjTNhhGK93JDHV7DA5QqfGdSTb9kl50S7gGM9qQ9OrnI14qvzd46DA8QYpc8 zGOdbjfp5bcpavyMDjmDDvA8WzLZLS7Huen1HkcimyKGsVbh0hGlIL2nsyc9mIz14vjg 3jgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Dftdj3DH; 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 wz6-20020a170906fe4600b00949581a4222si1489386ejb.330.2023.04.05.07.28.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:28:36 -0700 (PDT) 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=Dftdj3DH; 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 82BF938CCD74 for ; Wed, 5 Apr 2023 14:11:59 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id E1FD43856DE6 for ; Wed, 5 Apr 2023 14:05:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E1FD43856DE6 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-x32c.google.com with SMTP id j18-20020a05600c1c1200b003ee5157346cso23815794wms.1 for ; Wed, 05 Apr 2023 07:05:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703556; 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=hGGPnQ4kceGPM6pQ2i2+VLBnR8ygeXgtKVhP8DvtjAU=; b=Dftdj3DHWM7VWgasDqAIBsVE26+2patRvTW8VR6MucWGAIfvFJcc2NI3+P4jPJMG9t Cqg5TT/uB2FKAHMF2vGGFO6p5gAv5eYyiZEVet4l62s3moBA08BOrZP5SBB/t+ZLfEpx FUulLApeBZia0F6ft84DK5BDGrtmQrJ2cVF7431OctIomy0w1DqhV6Tx6C+Jg07dz2mE ldkOXp+E3zYB+9UORs1ZM62VYok+wPKL/85CU0L3GWs/FH+G/tmu0EAx7uph4tT7c1sc d1qISSz4GAgTlsZyhniOmUMVVHm34RQyImt0rpTlbfp1q1kYLRZy9k19bJBfebdPX1tj WxfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703556; 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=hGGPnQ4kceGPM6pQ2i2+VLBnR8ygeXgtKVhP8DvtjAU=; b=KPyDM3B+ewXk7cgRJ1Jt4wsLpO8OamQTYCj3eH73qQC/4eZfBJXVLJgAghxq2J8tUK ekkobZqceCZd8huTgb879YaNwA7ktIDGt1EJUIm7fmOj+UDyBlRkpj+9qx8XikiYzEuy VU7k6R492RBypAkSnrxW+KtrZMDW9i/C4p9CJRITsXhtw3cBc2o7JS0EkXF645hmzZ0J odT1keDCRmOajR+vMdKp74tfS3TsCZGkcPv+F5AOz2vRcOuDb2iQx8IMS5G59/WvQDy8 /KTkWq7/nMsNmtfBjOtkYr8utsjMwUeE1C1I7pZmg8OhRr9u8kZpKoA/u89E3zeSM6QJ PfwA== X-Gm-Message-State: AAQBX9cdn8J+0WZALi3PpeBviByWwLIpF1HfVHrhQCN8WNsRfkEJqyOn q1vMxD8XifYVU53R0pJOLNf9wwVyJ9oJNsu2BQ== X-Received: by 2002:a7b:c4c8:0:b0:3ee:289a:43a7 with SMTP id g8-20020a7bc4c8000000b003ee289a43a7mr5144393wmk.22.1680703555552; Wed, 05 Apr 2023 07:05:55 -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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:55 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 38/88] gccrs: Refactor SubstitutionRef base class into its own CC file Date: Wed, 5 Apr 2023 16:03:22 +0200 Message-Id: <20230405140411.3016563-39-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.6 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?1762346838296308238?= X-GMAIL-MSGID: =?utf-8?q?1762346838296308238?= From: Philip Herron Signed-off-by: Philip Herron gcc/rust/ChangeLog: * Make-lang.in: update the makefile * typecheck/rust-tyty.cc (SubstitutionParamMapping::need_substitution): likewise (SubstitutionParamMapping::override_context): likewise (SubstitutionRef::get_mappings_from_generic_args): likewise (SubstitutionRef::infer_substitions): likewise (SubstitutionRef::are_mappings_bound): likewise (SubstitutionRef::solve_missing_mappings_from_this): likewise (SubstitutionRef::monomorphize): likewise * typecheck/rust-tyty.h (class SubstitutionParamMapping): likewise (class SubstitutionArg): likewise (std::function. + +#include "rust-tyty-subst.h" +#include "rust-hir-full.h" +#include "rust-tyty.h" +#include "rust-hir-type-check.h" +#include "rust-substitution-mapper.h" +#include "rust-hir-type-check-type.h" + +namespace Rust { +namespace TyTy { + +SubstitutionParamMapping::SubstitutionParamMapping ( + const HIR::TypeParam &generic, ParamType *param) + : generic (generic), param (param) +{} + +SubstitutionParamMapping::SubstitutionParamMapping ( + const SubstitutionParamMapping &other) + : generic (other.generic), param (other.param) +{} + +std::string +SubstitutionParamMapping::as_string () const +{ + if (param == nullptr) + return "nullptr"; + + return param->get_name (); +} + +SubstitutionParamMapping +SubstitutionParamMapping::clone () const +{ + return SubstitutionParamMapping (generic, + static_cast (param->clone ())); +} + +ParamType * +SubstitutionParamMapping::get_param_ty () +{ + return param; +} + +const ParamType * +SubstitutionParamMapping::get_param_ty () const +{ + return param; +} + +const HIR::TypeParam & +SubstitutionParamMapping::get_generic_param () +{ + return generic; +}; + +bool +SubstitutionParamMapping::needs_substitution () const +{ + return !(get_param_ty ()->is_concrete ()); +} + +Location +SubstitutionParamMapping::get_param_locus () const +{ + return generic.get_locus (); +} + +bool +SubstitutionParamMapping::param_has_default_ty () const +{ + return generic.has_type (); +} + +BaseType * +SubstitutionParamMapping::get_default_ty () const +{ + TyVar var (generic.get_type_mappings ().get_hirid ()); + return var.get_tyty (); +} + +bool +SubstitutionParamMapping::need_substitution () const +{ + if (!param->can_resolve ()) + return true; + + auto resolved = param->resolve (); + return !resolved->is_concrete (); +} + +bool +SubstitutionParamMapping::fill_param_ty ( + SubstitutionArgumentMappings &subst_mappings, Location locus) +{ + SubstitutionArg arg = SubstitutionArg::error (); + bool ok = subst_mappings.get_argument_for_symbol (get_param_ty (), &arg); + if (!ok) + return true; + + TyTy::BaseType &type = *arg.get_tyty (); + if (type.get_kind () == TyTy::TypeKind::INFER) + { + type.inherit_bounds (*param); + } + else + { + if (!param->bounds_compatible (type, locus, true)) + return false; + } + + if (type.get_kind () == TypeKind::PARAM) + { + // delete param; + param = static_cast (type.clone ()); + } + else + { + // check the substitution is compatible with bounds + if (!param->bounds_compatible (type, locus, true)) + return false; + + // recursively pass this down to all HRTB's + for (auto &bound : param->get_specified_bounds ()) + bound.handle_substitions (subst_mappings); + + param->set_ty_ref (type.get_ref ()); + } + + return true; +} + +void +SubstitutionParamMapping::override_context () +{ + if (!param->can_resolve ()) + return; + + auto mappings = Analysis::Mappings::get (); + auto context = Resolver::TypeCheckContext::get (); + + context->insert_type (Analysis::NodeMapping (mappings->get_current_crate (), + UNKNOWN_NODEID, + param->get_ref (), + UNKNOWN_LOCAL_DEFID), + param->resolve ()); +} + +SubstitutionArg::SubstitutionArg (const SubstitutionParamMapping *param, + BaseType *argument) + : param (param), argument (argument) +{} + +SubstitutionArg::SubstitutionArg (const SubstitutionArg &other) + : param (other.param), argument (other.argument) +{} + +SubstitutionArg & +SubstitutionArg::operator= (const SubstitutionArg &other) +{ + param = other.param; + argument = other.argument; + return *this; +} + +BaseType * +SubstitutionArg::get_tyty () +{ + return argument; +} + +const BaseType * +SubstitutionArg::get_tyty () const +{ + return argument; +} + +const SubstitutionParamMapping * +SubstitutionArg::get_param_mapping () const +{ + return param; +} + +SubstitutionArg +SubstitutionArg::error () +{ + return SubstitutionArg (nullptr, nullptr); +} + +bool +SubstitutionArg::is_error () const +{ + return param == nullptr || argument == nullptr; +} + +bool +SubstitutionArg::is_conrete () const +{ + if (argument != nullptr) + return true; + + if (argument->get_kind () == TyTy::TypeKind::PARAM) + return false; + + return argument->is_concrete (); +} + +std::string +SubstitutionArg::as_string () const +{ + return param->as_string () + + (argument != nullptr ? ":" + argument->as_string () : ""); +} + +// SubstitutionArgumentMappings + +SubstitutionArgumentMappings::SubstitutionArgumentMappings ( + std::vector mappings, + std::map binding_args, Location locus, + ParamSubstCb param_subst_cb, bool trait_item_flag) + : mappings (mappings), binding_args (binding_args), locus (locus), + param_subst_cb (param_subst_cb), trait_item_flag (trait_item_flag) +{} + +SubstitutionArgumentMappings::SubstitutionArgumentMappings ( + const SubstitutionArgumentMappings &other) + : mappings (other.mappings), binding_args (other.binding_args), + locus (other.locus), param_subst_cb (other.param_subst_cb), + trait_item_flag (other.trait_item_flag) +{} + +SubstitutionArgumentMappings & +SubstitutionArgumentMappings::operator= ( + const SubstitutionArgumentMappings &other) +{ + mappings = other.mappings; + binding_args = other.binding_args; + locus = other.locus; + param_subst_cb = other.param_subst_cb; + trait_item_flag = other.trait_item_flag; + + return *this; +} + +SubstitutionArgumentMappings +SubstitutionArgumentMappings::error () +{ + return SubstitutionArgumentMappings ({}, {}, Location (), nullptr, false); +} + +bool +SubstitutionArgumentMappings::is_error () const +{ + return mappings.size () == 0; +} + +bool +SubstitutionArgumentMappings::get_argument_for_symbol ( + const ParamType *param_to_find, SubstitutionArg *argument) +{ + for (auto &mapping : mappings) + { + const SubstitutionParamMapping *param = mapping.get_param_mapping (); + const ParamType *p = param->get_param_ty (); + + if (p->get_symbol ().compare (param_to_find->get_symbol ()) == 0) + { + *argument = mapping; + return true; + } + } + return false; +} + +bool +SubstitutionArgumentMappings::get_argument_at (size_t index, + SubstitutionArg *argument) +{ + if (index > mappings.size ()) + return false; + + *argument = mappings.at (index); + return true; +} + +bool +SubstitutionArgumentMappings::is_concrete () const +{ + for (auto &mapping : mappings) + { + if (!mapping.is_conrete ()) + return false; + } + return true; +} + +Location +SubstitutionArgumentMappings::get_locus () const +{ + return locus; +} + +size_t +SubstitutionArgumentMappings::size () const +{ + return mappings.size (); +} + +bool +SubstitutionArgumentMappings::is_empty () const +{ + return size () == 0; +} + +std::vector & +SubstitutionArgumentMappings::get_mappings () +{ + return mappings; +} + +const std::vector & +SubstitutionArgumentMappings::get_mappings () const +{ + return mappings; +} + +std::map & +SubstitutionArgumentMappings::get_binding_args () +{ + return binding_args; +} + +const std::map & +SubstitutionArgumentMappings::get_binding_args () const +{ + return binding_args; +} + +std::string +SubstitutionArgumentMappings::as_string () const +{ + std::string buffer; + for (auto &mapping : mappings) + { + buffer += mapping.as_string () + ", "; + } + return "<" + buffer + ">"; +} + +void +SubstitutionArgumentMappings::on_param_subst (const ParamType &p, + const SubstitutionArg &a) const +{ + if (param_subst_cb == nullptr) + return; + + param_subst_cb (p, a); +} + +ParamSubstCb +SubstitutionArgumentMappings::get_subst_cb () const +{ + return param_subst_cb; +} + +bool +SubstitutionArgumentMappings::trait_item_mode () const +{ + return trait_item_flag; +} + +// SubstitutionRef + +SubstitutionRef::SubstitutionRef ( + std::vector substitutions, + SubstitutionArgumentMappings arguments) + : substitutions (substitutions), used_arguments (arguments) +{} + +bool +SubstitutionRef::has_substitutions () const +{ + return substitutions.size () > 0; +} + +std::string +SubstitutionRef::subst_as_string () const +{ + std::string buffer; + for (size_t i = 0; i < substitutions.size (); i++) + { + const SubstitutionParamMapping &sub = substitutions.at (i); + buffer += sub.as_string (); + + if ((i + 1) < substitutions.size ()) + buffer += ", "; + } + + return buffer.empty () ? "" : "<" + buffer + ">"; +} + +bool +SubstitutionRef::supports_associated_bindings () const +{ + return get_num_associated_bindings () > 0; +} + +size_t +SubstitutionRef::get_num_associated_bindings () const +{ + return 0; +} + +TypeBoundPredicateItem +SubstitutionRef::lookup_associated_type (const std::string &search) +{ + return TypeBoundPredicateItem::error (); +} + +size_t +SubstitutionRef::get_num_substitutions () const +{ + return substitutions.size (); +} + +std::vector & +SubstitutionRef::get_substs () +{ + return substitutions; +} + +const std::vector & +SubstitutionRef::get_substs () const +{ + return substitutions; +} + +std::vector +SubstitutionRef::clone_substs () const +{ + std::vector clone; + + for (auto &sub : substitutions) + clone.push_back (sub.clone ()); + + return clone; +} + +void +SubstitutionRef::override_context () +{ + for (auto &sub : substitutions) + { + sub.override_context (); + } +} + +bool +SubstitutionRef::needs_substitution () const +{ + for (auto &sub : substitutions) + { + if (sub.need_substitution ()) + return true; + } + return false; +} + +bool +SubstitutionRef::was_substituted () const +{ + return !needs_substitution (); +} + +SubstitutionArgumentMappings +SubstitutionRef::get_substitution_arguments () const +{ + return used_arguments; +} + +size_t +SubstitutionRef::num_required_substitutions () const +{ + size_t n = 0; + for (auto &p : substitutions) + { + if (p.needs_substitution ()) + n++; + } + return n; +} + +size_t +SubstitutionRef::min_required_substitutions () const +{ + size_t n = 0; + for (auto &p : substitutions) + { + if (p.needs_substitution () && !p.param_has_default_ty ()) + n++; + } + return n; +} + +SubstitutionArgumentMappings +SubstitutionRef::get_used_arguments () const +{ + return used_arguments; +} + +SubstitutionArgumentMappings +SubstitutionRef::get_mappings_from_generic_args (HIR::GenericArgs &args) +{ + std::map binding_arguments; + if (args.get_binding_args ().size () > 0) + { + if (supports_associated_bindings ()) + { + if (args.get_binding_args ().size () > get_num_associated_bindings ()) + { + RichLocation r (args.get_locus ()); + + rust_error_at (r, + "generic item takes at most %lu type binding " + "arguments but %lu were supplied", + (unsigned long) get_num_associated_bindings (), + (unsigned long) args.get_binding_args ().size ()); + return SubstitutionArgumentMappings::error (); + } + + for (auto &binding : args.get_binding_args ()) + { + BaseType *resolved + = Resolver::TypeCheckType::Resolve (binding.get_type ().get ()); + if (resolved == nullptr + || resolved->get_kind () == TyTy::TypeKind::ERROR) + { + rust_error_at (binding.get_locus (), + "failed to resolve type arguments"); + return SubstitutionArgumentMappings::error (); + } + + // resolve to relevant binding + auto binding_item + = lookup_associated_type (binding.get_identifier ()); + if (binding_item.is_error ()) + { + rust_error_at (binding.get_locus (), + "unknown associated type binding: %s", + binding.get_identifier ().c_str ()); + return SubstitutionArgumentMappings::error (); + } + + binding_arguments[binding.get_identifier ()] = resolved; + } + } + else + { + RichLocation r (args.get_locus ()); + for (auto &binding : args.get_binding_args ()) + r.add_range (binding.get_locus ()); + + rust_error_at (r, "associated type bindings are not allowed here"); + return SubstitutionArgumentMappings::error (); + } + } + + // for inherited arguments + size_t offs = used_arguments.size (); + if (args.get_type_args ().size () + offs > substitutions.size ()) + { + RichLocation r (args.get_locus ()); + r.add_range (substitutions.front ().get_param_locus ()); + + rust_error_at ( + r, + "generic item takes at most %lu type arguments but %lu were supplied", + (unsigned long) substitutions.size (), + (unsigned long) args.get_type_args ().size ()); + return SubstitutionArgumentMappings::error (); + } + + if (args.get_type_args ().size () + offs < min_required_substitutions ()) + { + RichLocation r (args.get_locus ()); + r.add_range (substitutions.front ().get_param_locus ()); + + rust_error_at ( + r, + "generic item takes at least %lu type arguments but %lu were supplied", + (unsigned long) (min_required_substitutions () - offs), + (unsigned long) args.get_type_args ().size ()); + return SubstitutionArgumentMappings::error (); + } + + std::vector mappings = used_arguments.get_mappings (); + for (auto &arg : args.get_type_args ()) + { + BaseType *resolved = Resolver::TypeCheckType::Resolve (arg.get ()); + if (resolved == nullptr || resolved->get_kind () == TyTy::TypeKind::ERROR) + { + rust_error_at (args.get_locus (), "failed to resolve type arguments"); + return SubstitutionArgumentMappings::error (); + } + + SubstitutionArg subst_arg (&substitutions.at (offs), resolved); + offs++; + mappings.push_back (std::move (subst_arg)); + } + + // we must need to fill out defaults + size_t left_over + = num_required_substitutions () - min_required_substitutions (); + if (left_over > 0) + { + for (size_t offs = mappings.size (); offs < substitutions.size (); offs++) + { + SubstitutionParamMapping ¶m = substitutions.at (offs); + rust_assert (param.param_has_default_ty ()); + + BaseType *resolved = param.get_default_ty (); + if (resolved->get_kind () == TypeKind::ERROR) + return SubstitutionArgumentMappings::error (); + + // this resolved default might already contain default parameters + if (resolved->contains_type_parameters ()) + { + SubstitutionArgumentMappings intermediate (mappings, + binding_arguments, + args.get_locus ()); + resolved = Resolver::SubstMapperInternal::Resolve (resolved, + intermediate); + + if (resolved->get_kind () == TypeKind::ERROR) + return SubstitutionArgumentMappings::error (); + } + + SubstitutionArg subst_arg (¶m, resolved); + mappings.push_back (std::move (subst_arg)); + } + } + + return SubstitutionArgumentMappings (mappings, binding_arguments, + args.get_locus ()); +} + +BaseType * +SubstitutionRef::infer_substitions (Location locus) +{ + std::vector args; + std::map argument_mappings; + for (auto &p : get_substs ()) + { + if (p.needs_substitution ()) + { + const std::string &symbol = p.get_param_ty ()->get_symbol (); + auto it = argument_mappings.find (symbol); + bool have_mapping = it != argument_mappings.end (); + + if (have_mapping) + { + args.push_back (SubstitutionArg (&p, it->second)); + } + else + { + TyVar infer_var = TyVar::get_implicit_infer_var (locus); + args.push_back (SubstitutionArg (&p, infer_var.get_tyty ())); + argument_mappings[symbol] = infer_var.get_tyty (); + } + } + else + { + args.push_back (SubstitutionArg (&p, p.get_param_ty ()->resolve ())); + } + } + + // FIXME do we need to add inference variables to all the possible bindings? + // it might just lead to inference variable hell not 100% sure if rustc does + // this i think the language might needs this to be explicitly set + + SubstitutionArgumentMappings infer_arguments (std::move (args), + {} /* binding_arguments */, + locus); + return handle_substitions (std::move (infer_arguments)); +} + +SubstitutionArgumentMappings +SubstitutionRef::adjust_mappings_for_this ( + SubstitutionArgumentMappings &mappings) +{ + std::vector resolved_mappings; + for (size_t i = 0; i < substitutions.size (); i++) + { + auto &subst = substitutions.at (i); + + SubstitutionArg arg = SubstitutionArg::error (); + if (mappings.size () == substitutions.size ()) + { + mappings.get_argument_at (i, &arg); + } + else + { + if (subst.needs_substitution ()) + { + // get from passed in mappings + mappings.get_argument_for_symbol (subst.get_param_ty (), &arg); + } + else + { + // we should already have this somewhere + used_arguments.get_argument_for_symbol (subst.get_param_ty (), + &arg); + } + } + + bool ok = !arg.is_error (); + if (ok) + { + SubstitutionArg adjusted (&subst, arg.get_tyty ()); + resolved_mappings.push_back (std::move (adjusted)); + } + } + + if (resolved_mappings.empty ()) + return SubstitutionArgumentMappings::error (); + + return SubstitutionArgumentMappings (resolved_mappings, + mappings.get_binding_args (), + mappings.get_locus (), + mappings.get_subst_cb (), + mappings.trait_item_mode ()); +} + +bool +SubstitutionRef::are_mappings_bound (SubstitutionArgumentMappings &mappings) +{ + std::vector resolved_mappings; + for (size_t i = 0; i < substitutions.size (); i++) + { + auto &subst = substitutions.at (i); + + SubstitutionArg arg = SubstitutionArg::error (); + if (mappings.size () == substitutions.size ()) + { + mappings.get_argument_at (i, &arg); + } + else + { + if (subst.needs_substitution ()) + { + // get from passed in mappings + mappings.get_argument_for_symbol (subst.get_param_ty (), &arg); + } + else + { + // we should already have this somewhere + used_arguments.get_argument_for_symbol (subst.get_param_ty (), + &arg); + } + } + + bool ok = !arg.is_error (); + if (ok) + { + SubstitutionArg adjusted (&subst, arg.get_tyty ()); + resolved_mappings.push_back (std::move (adjusted)); + } + } + + return !resolved_mappings.empty (); +} + +// this function assumes that the mappings being passed are for the same type as +// this new substitution reference so ordering matters here +SubstitutionArgumentMappings +SubstitutionRef::solve_mappings_from_receiver_for_self ( + SubstitutionArgumentMappings &mappings) const +{ + std::vector resolved_mappings; + + rust_assert (mappings.size () == get_num_substitutions ()); + for (size_t i = 0; i < get_num_substitutions (); i++) + { + const SubstitutionParamMapping ¶m_mapping = substitutions.at (i); + SubstitutionArg &arg = mappings.get_mappings ().at (i); + + if (param_mapping.needs_substitution ()) + { + SubstitutionArg adjusted (¶m_mapping, arg.get_tyty ()); + resolved_mappings.push_back (std::move (adjusted)); + } + } + + return SubstitutionArgumentMappings (resolved_mappings, + mappings.get_binding_args (), + mappings.get_locus ()); +} + +SubstitutionArgumentMappings +SubstitutionRef::solve_missing_mappings_from_this (SubstitutionRef &ref, + SubstitutionRef &to) +{ + rust_assert (!ref.needs_substitution ()); + rust_assert (needs_substitution ()); + rust_assert (get_num_substitutions () == ref.get_num_substitutions ()); + + Location locus = used_arguments.get_locus (); + std::vector resolved_mappings; + + std::map> substs; + for (size_t i = 0; i < get_num_substitutions (); i++) + { + SubstitutionParamMapping &a = substitutions.at (i); + SubstitutionParamMapping &b = ref.substitutions.at (i); + + if (a.need_substitution ()) + { + const BaseType *root = a.get_param_ty ()->resolve ()->get_root (); + rust_assert (root->get_kind () == TyTy::TypeKind::PARAM); + const ParamType *p = static_cast (root); + + substs[p->get_ty_ref ()] = {static_cast (p->clone ()), + b.get_param_ty ()->resolve ()}; + } + } + + for (auto it = substs.begin (); it != substs.end (); it++) + { + HirId param_id = it->first; + BaseType *arg = it->second.second; + + const SubstitutionParamMapping *associate_param = nullptr; + for (SubstitutionParamMapping &p : to.substitutions) + { + if (p.get_param_ty ()->get_ty_ref () == param_id) + { + associate_param = &p; + break; + } + } + + rust_assert (associate_param != nullptr); + SubstitutionArg argument (associate_param, arg); + resolved_mappings.push_back (std::move (argument)); + } + + return SubstitutionArgumentMappings (resolved_mappings, {}, locus); +} + +bool +SubstitutionRef::monomorphize () +{ + auto context = Resolver::TypeCheckContext::get (); + for (const auto &subst : get_substs ()) + { + const TyTy::ParamType *pty = subst.get_param_ty (); + + if (!pty->can_resolve ()) + continue; + + const TyTy::BaseType *binding = pty->resolve (); + if (binding->get_kind () == TyTy::TypeKind::PARAM) + continue; + + for (const auto &bound : pty->get_specified_bounds ()) + { + const Resolver::TraitReference *specified_bound_ref = bound.get (); + + // setup any associated type mappings for the specified bonds and this + // type + auto candidates = Resolver::TypeBoundsProbe::Probe (binding); + + Resolver::AssociatedImplTrait *associated_impl_trait = nullptr; + for (auto &probed_bound : candidates) + { + const Resolver::TraitReference *bound_trait_ref + = probed_bound.first; + const HIR::ImplBlock *associated_impl = probed_bound.second; + + HirId impl_block_id + = associated_impl->get_mappings ().get_hirid (); + Resolver::AssociatedImplTrait *associated = nullptr; + bool found_impl_trait + = context->lookup_associated_trait_impl (impl_block_id, + &associated); + if (found_impl_trait) + { + bool found_trait + = specified_bound_ref->is_equal (*bound_trait_ref); + bool found_self + = associated->get_self ()->can_eq (binding, false); + if (found_trait && found_self) + { + associated_impl_trait = associated; + break; + } + } + } + + if (associated_impl_trait != nullptr) + { + associated_impl_trait->setup_associated_types (binding, bound); + } + } + } + + return true; +} + +} // namespace TyTy +} // namespace Rust diff --git a/gcc/rust/typecheck/rust-tyty-subst.h b/gcc/rust/typecheck/rust-tyty-subst.h new file mode 100644 index 00000000000..4d09a3013e7 --- /dev/null +++ b/gcc/rust/typecheck/rust-tyty-subst.h @@ -0,0 +1,316 @@ +// 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_TYTY_SUBST_H +#define RUST_TYTY_SUBST_H + +#include "rust-system.h" +#include "rust-location.h" +#include "rust-hir-full-decls.h" +#include "rust-tyty-bounds.h" + +namespace Rust { +namespace TyTy { + +class BaseType; +class ParamType; +class SubstitutionArgumentMappings; +class SubstitutionParamMapping +{ +public: + SubstitutionParamMapping (const HIR::TypeParam &generic, ParamType *param); + + SubstitutionParamMapping (const SubstitutionParamMapping &other); + + std::string as_string () const; + + bool fill_param_ty (SubstitutionArgumentMappings &subst_mappings, + Location locus); + + SubstitutionParamMapping clone () const; + + ParamType *get_param_ty (); + + const ParamType *get_param_ty () const; + + const HIR::TypeParam &get_generic_param (); + + // this is used for the backend to override the HirId ref of the param to + // what the concrete type is for the rest of the context + void override_context (); + + bool needs_substitution () const; + + Location get_param_locus () const; + + bool param_has_default_ty () const; + + BaseType *get_default_ty () const; + + bool need_substitution () const; + +private: + const HIR::TypeParam &generic; + ParamType *param; +}; + +class SubstitutionArg +{ +public: + SubstitutionArg (const SubstitutionParamMapping *param, BaseType *argument); + + // FIXME + // the copy constructors need removed - they are unsafe see + // TypeBoundPredicate + SubstitutionArg (const SubstitutionArg &other); + + SubstitutionArg &operator= (const SubstitutionArg &other); + + BaseType *get_tyty (); + + const BaseType *get_tyty () const; + + const SubstitutionParamMapping *get_param_mapping () const; + + static SubstitutionArg error (); + + bool is_error () const; + + bool is_conrete () const; + + std::string as_string () const; + +private: + const SubstitutionParamMapping *param; + BaseType *argument; +}; + +typedef std::function + ParamSubstCb; +class SubstitutionArgumentMappings +{ +public: + SubstitutionArgumentMappings (std::vector mappings, + std::map binding_args, + Location locus, + ParamSubstCb param_subst_cb = nullptr, + bool trait_item_flag = false); + + SubstitutionArgumentMappings (const SubstitutionArgumentMappings &other); + SubstitutionArgumentMappings & + operator= (const SubstitutionArgumentMappings &other); + + SubstitutionArgumentMappings (SubstitutionArgumentMappings &&other) = default; + SubstitutionArgumentMappings &operator= (SubstitutionArgumentMappings &&other) + = default; + + static SubstitutionArgumentMappings error (); + + bool is_error () const; + + bool get_argument_for_symbol (const ParamType *param_to_find, + SubstitutionArg *argument); + + bool get_argument_at (size_t index, SubstitutionArg *argument); + + // is_concrete means if the used args is non error, ie: non empty this will + // verify if actual real types have been put in place of are they still + // ParamTy + bool is_concrete () const; + + Location get_locus () const; + + size_t size () const; + + bool is_empty () const; + + std::vector &get_mappings (); + + const std::vector &get_mappings () const; + + std::map &get_binding_args (); + + const std::map &get_binding_args () const; + + std::string as_string () const; + + void on_param_subst (const ParamType &p, const SubstitutionArg &a) const; + + ParamSubstCb get_subst_cb () const; + + bool trait_item_mode () const; + +private: + std::vector mappings; + std::map binding_args; + Location locus; + ParamSubstCb param_subst_cb; + bool trait_item_flag; +}; + +class SubstitutionRef +{ +public: + SubstitutionRef (std::vector substitutions, + SubstitutionArgumentMappings arguments); + + bool has_substitutions () const; + + std::string subst_as_string () const; + + bool supports_associated_bindings () const; + + // this is overridden in TypeBoundPredicate + // which support bindings we don't add them directly to the SubstitutionRef + // base class because this class represents the fn. The only + // construct which supports associated types + virtual size_t get_num_associated_bindings () const; + + // this is overridden in TypeBoundPredicate + virtual TypeBoundPredicateItem + lookup_associated_type (const std::string &search); + + size_t get_num_substitutions () const; + + std::vector &get_substs (); + + const std::vector &get_substs () const; + + std::vector clone_substs () const; + + void override_context (); + + bool needs_substitution () const; + + bool was_substituted () const; + + SubstitutionArgumentMappings get_substitution_arguments () const; + + // this is the count of type params that are not substituted fuly + size_t num_required_substitutions () const; + + // this is the count of type params that need substituted taking into account + // possible defaults + size_t min_required_substitutions () const; + + // We are trying to subst into Struct Foo {} + // in the case of Foo{...} + // + // the substitions we have here define X,Y but the arguments have no bindings + // so its a matter of ordering + SubstitutionArgumentMappings + get_mappings_from_generic_args (HIR::GenericArgs &args); + + // Recursive substitutions + // Foo { a:A, b: B}; Bar {a:X, b: Foo} + // + // we have bindings for X Y Z and need to propagate the binding Y,Z into Foo + // Which binds to A,B + SubstitutionArgumentMappings + adjust_mappings_for_this (SubstitutionArgumentMappings &mappings); + + // Are the mappings here actually bound to this type. For example imagine the + // case: + // + // struct Foo(T); + // impl Foo { + // fn test(self) { ... } + // } + // + // In this case we have a generic ADT of Foo and an impl block of a generic T + // on Foo for the Self type. When we it comes to path resolution we can have: + // + // Foo::::test() + // + // This means the first segment of Foo:: returns the ADT Foo not the + // Self ADT bound to the T from the impl block. This means when it comes to + // the next segment of test which resolves to the function we need to check + // wether the arguments in the struct definition of foo can be bound here + // before substituting the previous segments type here. This functions acts as + // a guard for the solve_mappings_from_receiver_for_self to handle the case + // where arguments are not bound. This is important for this next case: + // + // struct Baz(A, B); + // impl Baz { + // fn test(a: X) -> X { + // a + // } + // } + // + // In this case Baz has been already substituted for the impl's Self to become + // ADT so that the function test only has 1 generic argument of X. + // The path for this will be: + // + // Baz::test::<_>(123) + // + // So the first segment here will be Baz<_, _> to try and infer the arguments + // which will be taken from the impl's Self type in this case since it is + // already substituted and like the previous case the check to see if we need + // to inherit the previous segments generic arguments takes place but the + // generic arguments are not bound to this type as they have already been + // substituted. + // + // Its important to remember from the first example the FnType actually looks + // like: + // + // fn test(self :Foo(T)) + // + // As the generic parameters are "bound" to each of the items in the impl + // block. So this check is about wether the arguments we have here can + // actually be bound to this type. + bool are_mappings_bound (SubstitutionArgumentMappings &mappings); + + // struct Foo(A, B); + // + // impl Foo; + // -> fn test(self, a: X) -> X + // + // We might invoke this via: + // + // a = Foo(123, 456f32); + // b = a.test::(false); + // + // we need to figure out relevant generic arguemts for self to apply to the + // fntype + SubstitutionArgumentMappings solve_mappings_from_receiver_for_self ( + SubstitutionArgumentMappings &mappings) const; + + // TODO comment + SubstitutionArgumentMappings + solve_missing_mappings_from_this (SubstitutionRef &ref, SubstitutionRef &to); + + // TODO comment + BaseType *infer_substitions (Location locus); + + // TODO comment + bool monomorphize (); + + // TODO comment + virtual BaseType *handle_substitions (SubstitutionArgumentMappings mappings) + = 0; + + SubstitutionArgumentMappings get_used_arguments () const; + +protected: + std::vector substitutions; + SubstitutionArgumentMappings used_arguments; +}; + +} // namespace TyTy +} // namespace Rust +#endif // RUST_TYTY_SUBST_H diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index 55a8123ce87..b45bd99b1bd 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -514,472 +514,6 @@ StructFieldType::monomorphized_clone () const get_field_type ()->monomorphized_clone (), locus); } -bool -SubstitutionParamMapping::need_substitution () const -{ - if (!param->can_resolve ()) - return true; - - auto resolved = param->resolve (); - return !resolved->is_concrete (); -} - -bool -SubstitutionParamMapping::fill_param_ty ( - SubstitutionArgumentMappings &subst_mappings, Location locus) -{ - SubstitutionArg arg = SubstitutionArg::error (); - bool ok = subst_mappings.get_argument_for_symbol (get_param_ty (), &arg); - if (!ok) - return true; - - TyTy::BaseType &type = *arg.get_tyty (); - if (type.get_kind () == TyTy::TypeKind::INFER) - { - type.inherit_bounds (*param); - } - else - { - if (!param->bounds_compatible (type, locus, true)) - return false; - } - - if (type.get_kind () == TypeKind::PARAM) - { - // delete param; - param = static_cast (type.clone ()); - } - else - { - // check the substitution is compatible with bounds - if (!param->bounds_compatible (type, locus, true)) - return false; - - // recursively pass this down to all HRTB's - for (auto &bound : param->get_specified_bounds ()) - bound.handle_substitions (subst_mappings); - - param->set_ty_ref (type.get_ref ()); - } - - return true; -} - -void -SubstitutionParamMapping::override_context () -{ - if (!param->can_resolve ()) - return; - - auto mappings = Analysis::Mappings::get (); - auto context = Resolver::TypeCheckContext::get (); - - context->insert_type (Analysis::NodeMapping (mappings->get_current_crate (), - UNKNOWN_NODEID, - param->get_ref (), - UNKNOWN_LOCAL_DEFID), - param->resolve ()); -} - -SubstitutionArgumentMappings -SubstitutionRef::get_mappings_from_generic_args (HIR::GenericArgs &args) -{ - std::map binding_arguments; - if (args.get_binding_args ().size () > 0) - { - if (supports_associated_bindings ()) - { - if (args.get_binding_args ().size () > get_num_associated_bindings ()) - { - RichLocation r (args.get_locus ()); - - rust_error_at (r, - "generic item takes at most %lu type binding " - "arguments but %lu were supplied", - (unsigned long) get_num_associated_bindings (), - (unsigned long) args.get_binding_args ().size ()); - return SubstitutionArgumentMappings::error (); - } - - for (auto &binding : args.get_binding_args ()) - { - BaseType *resolved - = Resolver::TypeCheckType::Resolve (binding.get_type ().get ()); - if (resolved == nullptr - || resolved->get_kind () == TyTy::TypeKind::ERROR) - { - rust_error_at (binding.get_locus (), - "failed to resolve type arguments"); - return SubstitutionArgumentMappings::error (); - } - - // resolve to relevant binding - auto binding_item - = lookup_associated_type (binding.get_identifier ()); - if (binding_item.is_error ()) - { - rust_error_at (binding.get_locus (), - "unknown associated type binding: %s", - binding.get_identifier ().c_str ()); - return SubstitutionArgumentMappings::error (); - } - - binding_arguments[binding.get_identifier ()] = resolved; - } - } - else - { - RichLocation r (args.get_locus ()); - for (auto &binding : args.get_binding_args ()) - r.add_range (binding.get_locus ()); - - rust_error_at (r, "associated type bindings are not allowed here"); - return SubstitutionArgumentMappings::error (); - } - } - - // for inherited arguments - size_t offs = used_arguments.size (); - if (args.get_type_args ().size () + offs > substitutions.size ()) - { - RichLocation r (args.get_locus ()); - r.add_range (substitutions.front ().get_param_locus ()); - - rust_error_at ( - r, - "generic item takes at most %lu type arguments but %lu were supplied", - (unsigned long) substitutions.size (), - (unsigned long) args.get_type_args ().size ()); - return SubstitutionArgumentMappings::error (); - } - - if (args.get_type_args ().size () + offs < min_required_substitutions ()) - { - RichLocation r (args.get_locus ()); - r.add_range (substitutions.front ().get_param_locus ()); - - rust_error_at ( - r, - "generic item takes at least %lu type arguments but %lu were supplied", - (unsigned long) (min_required_substitutions () - offs), - (unsigned long) args.get_type_args ().size ()); - return SubstitutionArgumentMappings::error (); - } - - std::vector mappings = used_arguments.get_mappings (); - for (auto &arg : args.get_type_args ()) - { - BaseType *resolved = Resolver::TypeCheckType::Resolve (arg.get ()); - if (resolved == nullptr || resolved->get_kind () == TyTy::TypeKind::ERROR) - { - rust_error_at (args.get_locus (), "failed to resolve type arguments"); - return SubstitutionArgumentMappings::error (); - } - - SubstitutionArg subst_arg (&substitutions.at (offs), resolved); - offs++; - mappings.push_back (std::move (subst_arg)); - } - - // we must need to fill out defaults - size_t left_over - = num_required_substitutions () - min_required_substitutions (); - if (left_over > 0) - { - for (size_t offs = mappings.size (); offs < substitutions.size (); offs++) - { - SubstitutionParamMapping ¶m = substitutions.at (offs); - rust_assert (param.param_has_default_ty ()); - - BaseType *resolved = param.get_default_ty (); - if (resolved->get_kind () == TypeKind::ERROR) - return SubstitutionArgumentMappings::error (); - - // this resolved default might already contain default parameters - if (resolved->contains_type_parameters ()) - { - SubstitutionArgumentMappings intermediate (mappings, - binding_arguments, - args.get_locus ()); - resolved = Resolver::SubstMapperInternal::Resolve (resolved, - intermediate); - - if (resolved->get_kind () == TypeKind::ERROR) - return SubstitutionArgumentMappings::error (); - } - - SubstitutionArg subst_arg (¶m, resolved); - mappings.push_back (std::move (subst_arg)); - } - } - - return SubstitutionArgumentMappings (mappings, binding_arguments, - args.get_locus ()); -} - -BaseType * -SubstitutionRef::infer_substitions (Location locus) -{ - std::vector args; - std::map argument_mappings; - for (auto &p : get_substs ()) - { - if (p.needs_substitution ()) - { - const std::string &symbol = p.get_param_ty ()->get_symbol (); - auto it = argument_mappings.find (symbol); - bool have_mapping = it != argument_mappings.end (); - - if (have_mapping) - { - args.push_back (SubstitutionArg (&p, it->second)); - } - else - { - TyVar infer_var = TyVar::get_implicit_infer_var (locus); - args.push_back (SubstitutionArg (&p, infer_var.get_tyty ())); - argument_mappings[symbol] = infer_var.get_tyty (); - } - } - else - { - args.push_back (SubstitutionArg (&p, p.get_param_ty ()->resolve ())); - } - } - - // FIXME do we need to add inference variables to all the possible bindings? - // it might just lead to inference variable hell not 100% sure if rustc does - // this i think the language might needs this to be explicitly set - - SubstitutionArgumentMappings infer_arguments (std::move (args), - {} /* binding_arguments */, - locus); - return handle_substitions (std::move (infer_arguments)); -} - -SubstitutionArgumentMappings -SubstitutionRef::adjust_mappings_for_this ( - SubstitutionArgumentMappings &mappings) -{ - std::vector resolved_mappings; - for (size_t i = 0; i < substitutions.size (); i++) - { - auto &subst = substitutions.at (i); - - SubstitutionArg arg = SubstitutionArg::error (); - if (mappings.size () == substitutions.size ()) - { - mappings.get_argument_at (i, &arg); - } - else - { - if (subst.needs_substitution ()) - { - // get from passed in mappings - mappings.get_argument_for_symbol (subst.get_param_ty (), &arg); - } - else - { - // we should already have this somewhere - used_arguments.get_argument_for_symbol (subst.get_param_ty (), - &arg); - } - } - - bool ok = !arg.is_error (); - if (ok) - { - SubstitutionArg adjusted (&subst, arg.get_tyty ()); - resolved_mappings.push_back (std::move (adjusted)); - } - } - - if (resolved_mappings.empty ()) - return SubstitutionArgumentMappings::error (); - - return SubstitutionArgumentMappings (resolved_mappings, - mappings.get_binding_args (), - mappings.get_locus (), - mappings.get_subst_cb (), - mappings.trait_item_mode ()); -} - -bool -SubstitutionRef::are_mappings_bound (SubstitutionArgumentMappings &mappings) -{ - std::vector resolved_mappings; - for (size_t i = 0; i < substitutions.size (); i++) - { - auto &subst = substitutions.at (i); - - SubstitutionArg arg = SubstitutionArg::error (); - if (mappings.size () == substitutions.size ()) - { - mappings.get_argument_at (i, &arg); - } - else - { - if (subst.needs_substitution ()) - { - // get from passed in mappings - mappings.get_argument_for_symbol (subst.get_param_ty (), &arg); - } - else - { - // we should already have this somewhere - used_arguments.get_argument_for_symbol (subst.get_param_ty (), - &arg); - } - } - - bool ok = !arg.is_error (); - if (ok) - { - SubstitutionArg adjusted (&subst, arg.get_tyty ()); - resolved_mappings.push_back (std::move (adjusted)); - } - } - - return !resolved_mappings.empty (); -} - -// this function assumes that the mappings being passed are for the same type as -// this new substitution reference so ordering matters here -SubstitutionArgumentMappings -SubstitutionRef::solve_mappings_from_receiver_for_self ( - SubstitutionArgumentMappings &mappings) const -{ - std::vector resolved_mappings; - - rust_assert (mappings.size () == get_num_substitutions ()); - for (size_t i = 0; i < get_num_substitutions (); i++) - { - const SubstitutionParamMapping ¶m_mapping = substitutions.at (i); - SubstitutionArg &arg = mappings.get_mappings ().at (i); - - if (param_mapping.needs_substitution ()) - { - SubstitutionArg adjusted (¶m_mapping, arg.get_tyty ()); - resolved_mappings.push_back (std::move (adjusted)); - } - } - - return SubstitutionArgumentMappings (resolved_mappings, - mappings.get_binding_args (), - mappings.get_locus ()); -} - -SubstitutionArgumentMappings -SubstitutionRef::solve_missing_mappings_from_this (SubstitutionRef &ref, - SubstitutionRef &to) -{ - rust_assert (!ref.needs_substitution ()); - rust_assert (needs_substitution ()); - rust_assert (get_num_substitutions () == ref.get_num_substitutions ()); - - Location locus = used_arguments.get_locus (); - std::vector resolved_mappings; - - std::map> substs; - for (size_t i = 0; i < get_num_substitutions (); i++) - { - SubstitutionParamMapping &a = substitutions.at (i); - SubstitutionParamMapping &b = ref.substitutions.at (i); - - if (a.need_substitution ()) - { - const BaseType *root = a.get_param_ty ()->resolve ()->get_root (); - rust_assert (root->get_kind () == TyTy::TypeKind::PARAM); - const ParamType *p = static_cast (root); - - substs[p->get_ty_ref ()] = {static_cast (p->clone ()), - b.get_param_ty ()->resolve ()}; - } - } - - for (auto it = substs.begin (); it != substs.end (); it++) - { - HirId param_id = it->first; - BaseType *arg = it->second.second; - - const SubstitutionParamMapping *associate_param = nullptr; - for (SubstitutionParamMapping &p : to.substitutions) - { - if (p.get_param_ty ()->get_ty_ref () == param_id) - { - associate_param = &p; - break; - } - } - - rust_assert (associate_param != nullptr); - SubstitutionArg argument (associate_param, arg); - resolved_mappings.push_back (std::move (argument)); - } - - return SubstitutionArgumentMappings (resolved_mappings, {}, locus); -} - -bool -SubstitutionRef::monomorphize () -{ - auto context = Resolver::TypeCheckContext::get (); - for (const auto &subst : get_substs ()) - { - const TyTy::ParamType *pty = subst.get_param_ty (); - - if (!pty->can_resolve ()) - continue; - - const TyTy::BaseType *binding = pty->resolve (); - if (binding->get_kind () == TyTy::TypeKind::PARAM) - continue; - - for (const auto &bound : pty->get_specified_bounds ()) - { - const Resolver::TraitReference *specified_bound_ref = bound.get (); - - // setup any associated type mappings for the specified bonds and this - // type - auto candidates = Resolver::TypeBoundsProbe::Probe (binding); - - Resolver::AssociatedImplTrait *associated_impl_trait = nullptr; - for (auto &probed_bound : candidates) - { - const Resolver::TraitReference *bound_trait_ref - = probed_bound.first; - const HIR::ImplBlock *associated_impl = probed_bound.second; - - HirId impl_block_id - = associated_impl->get_mappings ().get_hirid (); - Resolver::AssociatedImplTrait *associated = nullptr; - bool found_impl_trait - = context->lookup_associated_trait_impl (impl_block_id, - &associated); - if (found_impl_trait) - { - bool found_trait - = specified_bound_ref->is_equal (*bound_trait_ref); - bool found_self - = associated->get_self ()->can_eq (binding, false); - if (found_trait && found_self) - { - associated_impl_trait = associated; - break; - } - } - } - - if (associated_impl_trait != nullptr) - { - associated_impl_trait->setup_associated_types (binding, bound); - } - } - } - - return true; -} - void ADTType::accept_vis (TyVisitor &vis) { diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index a8bdf6f3a15..cb30a60ae96 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -27,6 +27,7 @@ #include "rust-identifier.h" #include "rust-tyty-bounds.h" #include "rust-tyty-util.h" +#include "rust-tyty-subst.h" namespace Rust { @@ -462,469 +463,6 @@ private: std::vector fields; }; -class SubstitutionParamMapping -{ -public: - SubstitutionParamMapping (const HIR::TypeParam &generic, ParamType *param) - : generic (generic), param (param) - {} - - SubstitutionParamMapping (const SubstitutionParamMapping &other) - : generic (other.generic), param (other.param) - {} - - std::string as_string () const - { - if (param == nullptr) - return "nullptr"; - - return param->get_name (); - } - - bool fill_param_ty (SubstitutionArgumentMappings &subst_mappings, - Location locus); - - SubstitutionParamMapping clone () const - { - return SubstitutionParamMapping (generic, static_cast ( - param->clone ())); - } - - ParamType *get_param_ty () { return param; } - - const ParamType *get_param_ty () const { return param; } - - const HIR::TypeParam &get_generic_param () { return generic; }; - - // this is used for the backend to override the HirId ref of the param to - // what the concrete type is for the rest of the context - void override_context (); - - bool needs_substitution () const - { - return !(get_param_ty ()->is_concrete ()); - } - - Location get_param_locus () const { return generic.get_locus (); } - - bool param_has_default_ty () const { return generic.has_type (); } - - BaseType *get_default_ty () const - { - TyVar var (generic.get_type_mappings ().get_hirid ()); - return var.get_tyty (); - } - - bool need_substitution () const; - -private: - const HIR::TypeParam &generic; - ParamType *param; -}; - -class SubstitutionArg -{ -public: - SubstitutionArg (const SubstitutionParamMapping *param, BaseType *argument) - : param (param), argument (argument) - {} - - // FIXME - // the copy constructors need removed - they are unsafe see - // TypeBoundPredicate - SubstitutionArg (const SubstitutionArg &other) - : param (other.param), argument (other.argument) - {} - - SubstitutionArg &operator= (const SubstitutionArg &other) - { - param = other.param; - argument = other.argument; - return *this; - } - - BaseType *get_tyty () { return argument; } - - const BaseType *get_tyty () const { return argument; } - - const SubstitutionParamMapping *get_param_mapping () const { return param; } - - static SubstitutionArg error () { return SubstitutionArg (nullptr, nullptr); } - - bool is_error () const { return param == nullptr || argument == nullptr; } - - bool is_conrete () const - { - if (argument != nullptr) - return true; - - if (argument->get_kind () == TyTy::TypeKind::PARAM) - return false; - - return argument->is_concrete (); - } - - std::string as_string () const - { - return param->as_string () - + (argument != nullptr ? ":" + argument->as_string () : ""); - } - -private: - const SubstitutionParamMapping *param; - BaseType *argument; -}; - -typedef std::function - ParamSubstCb; -class SubstitutionArgumentMappings -{ -public: - SubstitutionArgumentMappings (std::vector mappings, - std::map binding_args, - Location locus, - ParamSubstCb param_subst_cb = nullptr, - bool trait_item_flag = false) - : mappings (mappings), binding_args (binding_args), locus (locus), - param_subst_cb (param_subst_cb), trait_item_flag (trait_item_flag) - {} - - SubstitutionArgumentMappings (const SubstitutionArgumentMappings &other) - : mappings (other.mappings), binding_args (other.binding_args), - locus (other.locus), param_subst_cb (other.param_subst_cb), - trait_item_flag (other.trait_item_flag) - {} - - SubstitutionArgumentMappings & - operator= (const SubstitutionArgumentMappings &other) - { - mappings = other.mappings; - binding_args = other.binding_args; - locus = other.locus; - param_subst_cb = other.param_subst_cb; - trait_item_flag = other.trait_item_flag; - - return *this; - } - - SubstitutionArgumentMappings (SubstitutionArgumentMappings &&other) = default; - SubstitutionArgumentMappings &operator= (SubstitutionArgumentMappings &&other) - = default; - - static SubstitutionArgumentMappings error () - { - return SubstitutionArgumentMappings ({}, {}, Location (), nullptr, false); - } - - bool is_error () const { return mappings.size () == 0; } - - bool get_argument_for_symbol (const ParamType *param_to_find, - SubstitutionArg *argument) - { - for (auto &mapping : mappings) - { - const SubstitutionParamMapping *param = mapping.get_param_mapping (); - const ParamType *p = param->get_param_ty (); - - if (p->get_symbol ().compare (param_to_find->get_symbol ()) == 0) - { - *argument = mapping; - return true; - } - } - return false; - } - - bool get_argument_at (size_t index, SubstitutionArg *argument) - { - if (index > mappings.size ()) - return false; - - *argument = mappings.at (index); - return true; - } - - // is_concrete means if the used args is non error, ie: non empty this will - // verify if actual real types have been put in place of are they still - // ParamTy - bool is_concrete () const - { - for (auto &mapping : mappings) - { - if (!mapping.is_conrete ()) - return false; - } - return true; - } - - Location get_locus () const { return locus; } - - size_t size () const { return mappings.size (); } - - bool is_empty () const { return size () == 0; } - - std::vector &get_mappings () { return mappings; } - - const std::vector &get_mappings () const { return mappings; } - - std::map &get_binding_args () - { - return binding_args; - } - - const std::map &get_binding_args () const - { - return binding_args; - } - - std::string as_string () const - { - std::string buffer; - for (auto &mapping : mappings) - { - buffer += mapping.as_string () + ", "; - } - return "<" + buffer + ">"; - } - - void on_param_subst (const ParamType &p, const SubstitutionArg &a) const - { - if (param_subst_cb == nullptr) - return; - - param_subst_cb (p, a); - } - - ParamSubstCb get_subst_cb () const { return param_subst_cb; } - - bool trait_item_mode () const { return trait_item_flag; } - -private: - std::vector mappings; - std::map binding_args; - Location locus; - ParamSubstCb param_subst_cb; - bool trait_item_flag; -}; - -class SubstitutionRef -{ -public: - SubstitutionRef (std::vector substitutions, - SubstitutionArgumentMappings arguments) - : substitutions (substitutions), used_arguments (arguments) - {} - - bool has_substitutions () const { return substitutions.size () > 0; } - - std::string subst_as_string () const - { - std::string buffer; - for (size_t i = 0; i < substitutions.size (); i++) - { - const SubstitutionParamMapping &sub = substitutions.at (i); - buffer += sub.as_string (); - - if ((i + 1) < substitutions.size ()) - buffer += ", "; - } - - return buffer.empty () ? "" : "<" + buffer + ">"; - } - - bool supports_associated_bindings () const - { - return get_num_associated_bindings () > 0; - } - - // this is overridden in TypeBoundPredicate - // which support bindings we don't add them directly to the SubstitutionRef - // base class because this class represents the fn. The only - // construct which supports associated types - virtual size_t get_num_associated_bindings () const { return 0; } - - // this is overridden in TypeBoundPredicate - virtual TypeBoundPredicateItem - lookup_associated_type (const std::string &search) - { - return TypeBoundPredicateItem::error (); - } - - size_t get_num_substitutions () const { return substitutions.size (); } - - std::vector &get_substs () { return substitutions; } - - const std::vector &get_substs () const - { - return substitutions; - } - - std::vector clone_substs () const - { - std::vector clone; - - for (auto &sub : substitutions) - clone.push_back (sub.clone ()); - - return clone; - } - - void override_context () - { - for (auto &sub : substitutions) - { - sub.override_context (); - } - } - - bool needs_substitution () const - { - for (auto &sub : substitutions) - { - if (sub.need_substitution ()) - return true; - } - return false; - } - - bool was_substituted () const { return !needs_substitution (); } - - SubstitutionArgumentMappings get_substitution_arguments () const - { - return used_arguments; - } - - // this is the count of type params that are not substituted fuly - size_t num_required_substitutions () const - { - size_t n = 0; - for (auto &p : substitutions) - { - if (p.needs_substitution ()) - n++; - } - return n; - } - - // this is the count of type params that need substituted taking into account - // possible defaults - size_t min_required_substitutions () const - { - size_t n = 0; - for (auto &p : substitutions) - { - if (p.needs_substitution () && !p.param_has_default_ty ()) - n++; - } - return n; - } - - // We are trying to subst into Struct Foo {} - // in the case of Foo{...} - // - // the substitions we have here define X,Y but the arguments have no bindings - // so its a matter of ordering - SubstitutionArgumentMappings - get_mappings_from_generic_args (HIR::GenericArgs &args); - - // Recursive substitutions - // Foo { a:A, b: B}; Bar {a:X, b: Foo} - // - // we have bindings for X Y Z and need to propagate the binding Y,Z into Foo - // Which binds to A,B - SubstitutionArgumentMappings - adjust_mappings_for_this (SubstitutionArgumentMappings &mappings); - - // Are the mappings here actually bound to this type. For example imagine the - // case: - // - // struct Foo(T); - // impl Foo { - // fn test(self) { ... } - // } - // - // In this case we have a generic ADT of Foo and an impl block of a generic T - // on Foo for the Self type. When we it comes to path resolution we can have: - // - // Foo::::test() - // - // This means the first segment of Foo:: returns the ADT Foo not the - // Self ADT bound to the T from the impl block. This means when it comes to - // the next segment of test which resolves to the function we need to check - // wether the arguments in the struct definition of foo can be bound here - // before substituting the previous segments type here. This functions acts as - // a guard for the solve_mappings_from_receiver_for_self to handle the case - // where arguments are not bound. This is important for this next case: - // - // struct Baz(A, B); - // impl Baz { - // fn test(a: X) -> X { - // a - // } - // } - // - // In this case Baz has been already substituted for the impl's Self to become - // ADT so that the function test only has 1 generic argument of X. - // The path for this will be: - // - // Baz::test::<_>(123) - // - // So the first segment here will be Baz<_, _> to try and infer the arguments - // which will be taken from the impl's Self type in this case since it is - // already substituted and like the previous case the check to see if we need - // to inherit the previous segments generic arguments takes place but the - // generic arguments are not bound to this type as they have already been - // substituted. - // - // Its important to remember from the first example the FnType actually looks - // like: - // - // fn test(self :Foo(T)) - // - // As the generic parameters are "bound" to each of the items in the impl - // block. So this check is about wether the arguments we have here can - // actually be bound to this type. - bool are_mappings_bound (SubstitutionArgumentMappings &mappings); - - // struct Foo(A, B); - // - // impl Foo; - // -> fn test(self, a: X) -> X - // - // We might invoke this via: - // - // a = Foo(123, 456f32); - // b = a.test::(false); - // - // we need to figure out relevant generic arguemts for self to apply to the - // fntype - SubstitutionArgumentMappings solve_mappings_from_receiver_for_self ( - SubstitutionArgumentMappings &mappings) const; - - // TODO comment - SubstitutionArgumentMappings - solve_missing_mappings_from_this (SubstitutionRef &ref, SubstitutionRef &to); - - // TODO comment - BaseType *infer_substitions (Location locus); - - // TODO comment - bool monomorphize (); - - // TODO comment - virtual BaseType *handle_substitions (SubstitutionArgumentMappings mappings) - = 0; - - SubstitutionArgumentMappings get_used_arguments () const - { - return used_arguments; - } - -protected: - std::vector substitutions; - SubstitutionArgumentMappings used_arguments; -}; - class TypeBoundPredicate : public SubstitutionRef { public: From patchwork Wed Apr 5 14:03: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: 79699 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp357737vqo; Wed, 5 Apr 2023 07:39:23 -0700 (PDT) X-Google-Smtp-Source: AKy350Yr2XYbnLSFs/rqU04+dJvNJWCRZNJTya6FzaeJlHvVkUpAlbk7lXa8MqrgxBBIqm3PikXS X-Received: by 2002:aa7:c94f:0:b0:4fe:9621:ffdc with SMTP id h15-20020aa7c94f000000b004fe9621ffdcmr2386642edt.16.1680705563220; Wed, 05 Apr 2023 07:39:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705563; cv=none; d=google.com; s=arc-20160816; b=IsWNet/l0i9b08g10cnHasXUhwrplMpjwgB923rLnPEl/a+oNxJEGAQ7XE9FoFvl3m CnHcDhxl7QpcSL20jejEeqmnQLyo9Bu7diFagBCl9E51O27uYUDRZo7nWnnWeX59lkef 2XojHimLWa/rPmGiZYYZvMjl/O3c9BOtz/Uzo2Ec1v4/4FCCVAxe5X/JAGtgLqsNXdBV fvO1jC+AQkY+I4ORRnlfuxziZvfcpK18EQXS44n3oa/0hzXiNNkJPwh8O6h918BTLfaZ R48/zgvIW35NuyoKe2+S8Kg1NPPoVnvYURrg2PsnP5Hcc/bYXkHAVoTtbKrab4uPoCUv cHrw== 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=CaF3I/42LOTezVu5yUlHV28S9aQZ9Fre6YkQ+e3MUuo=; b=opgF6v2bXn74/zVPQtJEA+Z81GiDDCBUj5rfOxyi7pummShWoSNANBUQl+KJFVXP6a aRLOPSrVmIA9iLyBl/gS97fkAcppFYBJHNeVxEcjlnwI3yAXJU3PmyFh0sI8/FAth2BK S3e7grcAqzbPz/+s4ribh0XqySSD0ACSJA7rn3JgFNKkOwd+LfLjl7tZCffUz0ZrHeYK /eF6W2U/tgjiW7wyzUW0FfjzTbhf3AWleu65yiJW6qecOjGysYo9N4z+EXx9C7d517FU icye3ejVUZTYP/Ry9779ch9GxQqEzGy2Bw2d+MJrp4NeS5KDuC+T5fs/jMy9VaVsO8Fn HvqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=alE821vj; 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 s24-20020aa7cb18000000b0050212939157si2074095edt.654.2023.04.05.07.39.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:39:23 -0700 (PDT) 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=alE821vj; 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 F3FED396B646 for ; Wed, 5 Apr 2023 14:14:33 +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 D380038555B0 for ; Wed, 5 Apr 2023 14:05:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D380038555B0 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 m8so10052618wmq.5 for ; Wed, 05 Apr 2023 07:05:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703556; 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=CaF3I/42LOTezVu5yUlHV28S9aQZ9Fre6YkQ+e3MUuo=; b=alE821vj66aU8HmHF1EDaU79R5C+CJ2WYkPCj1gL9L3XJ5bG7PNo1Y2LD3sbyazwG2 YGWWIRUANZMoII3Pl0SHRCwYj5xiGqVWMv+5HMDNJA9IDkzor8LEV4j3pMLfDlWnU5oY tOymfpjwJkWa/ThaDMGnkhJjJytxgSmhXA0er25bTkVxX2C5uVX/Xcaykune5jo9x5xR aKFQNYq24PgJikobnfJRIWRSEuXjcPnJpHWs7dBrcurQiw69kv2LwDmSIbA5Qw1t+DGA P73aHJ7qs1xPNen6AFvqDlI9dWtgzeFdgx0tNNKSmsQfhs1vCb65uSZM1dxvpMYD+K9/ cDCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703556; 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=CaF3I/42LOTezVu5yUlHV28S9aQZ9Fre6YkQ+e3MUuo=; b=uhS2aGNQ/Ltxd2Beg/DLGtmsN1bTc3WrGL7jmHcJ486qNNkQKdCnOGvb8HjSIurSNi PN/8MopJqk96OcVhv9Sw+su+j3itg+Z7RWls3N71H4+XiglCwKJCTKLBBD9vz0Tt/nUU fcBD51x7tropisMHMmScrjJCl5AB2zOHALPm7wjHNJa0FvcYJoMZo0NjC3XtqRRhmIyB cwDkiMiN/IdLY5suI6S0CU7vbKckdNuUgh1b0um03eXdMgGwBucvsSi5xehWn4ii3aW4 oj3W78OH4qaksUcjJfQGQdgZ6AOBfB3PBN9n9/p2hoUIu3/QR8YKr68i2nh2wH5bACJB GroQ== X-Gm-Message-State: AAQBX9cl0bFsOWv5YWnME/rBGxoePIVff9Q0vA2JboM6RCIEZKtQ1bRz RLTZDuQOz/gpC/70b2ZpUQu//8vLDm8T5we7Pg== X-Received: by 2002:a05:600c:204d:b0:3ef:62cd:1eb with SMTP id p13-20020a05600c204d00b003ef62cd01ebmr5129581wmg.7.1680703556098; Wed, 05 Apr 2023 07:05:56 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:55 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 39/88] gccrs: Refactor all substitution mapper code implementation into its own CC file Date: Wed, 5 Apr 2023 16:03:23 +0200 Message-Id: <20230405140411.3016563-40-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.6 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, 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?1762347516676763691?= X-GMAIL-MSGID: =?utf-8?q?1762347516676763691?= From: Philip Herron Signed-off-by: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-substitution-mapper.cc (SubstMapper::SubstMapper): refactor (SubstMapper::Resolve): likewise (SubstMapper::InferSubst): likewise (SubstMapper::have_generic_args): likewise (SubstMapper::visit): likewise (SubstMapperInternal::visit): likewise (SubstMapperFromExisting::SubstMapperFromExisting): likewise (SubstMapperFromExisting::Resolve): likewise (SubstMapperFromExisting::visit): likewise (GetUsedSubstArgs::GetUsedSubstArgs): likewise (GetUsedSubstArgs::From): likewise (GetUsedSubstArgs::visit): likewise * typecheck/rust-substitution-mapper.h: refactor * typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::get_generic_param): likewise --- .../typecheck/rust-substitution-mapper.cc | 343 ++++++++++++++++++ gcc/rust/typecheck/rust-substitution-mapper.h | 286 +++------------ gcc/rust/typecheck/rust-tyty-subst.cc | 2 +- 3 files changed, 387 insertions(+), 244 deletions(-) diff --git a/gcc/rust/typecheck/rust-substitution-mapper.cc b/gcc/rust/typecheck/rust-substitution-mapper.cc index e1d988818bb..dc93857e60f 100644 --- a/gcc/rust/typecheck/rust-substitution-mapper.cc +++ b/gcc/rust/typecheck/rust-substitution-mapper.cc @@ -22,6 +22,116 @@ namespace Rust { namespace Resolver { +SubstMapper::SubstMapper (HirId ref, HIR::GenericArgs *generics, Location locus) + : resolved (new TyTy::ErrorType (ref)), generics (generics), locus (locus) +{} + +TyTy::BaseType * +SubstMapper::Resolve (TyTy::BaseType *base, Location locus, + HIR::GenericArgs *generics) +{ + SubstMapper mapper (base->get_ref (), generics, locus); + base->accept_vis (mapper); + rust_assert (mapper.resolved != nullptr); + return mapper.resolved; +} + +TyTy::BaseType * +SubstMapper::InferSubst (TyTy::BaseType *base, Location locus) +{ + return SubstMapper::Resolve (base, locus, nullptr); +} + +bool +SubstMapper::have_generic_args () const +{ + return generics != nullptr; +} + +void +SubstMapper::visit (TyTy::FnType &type) +{ + TyTy::FnType *concrete = nullptr; + if (!have_generic_args ()) + { + TyTy::BaseType *substs = type.infer_substitions (locus); + rust_assert (substs->get_kind () == TyTy::TypeKind::FNDEF); + concrete = static_cast (substs); + } + else + { + TyTy::SubstitutionArgumentMappings mappings + = type.get_mappings_from_generic_args (*generics); + if (mappings.is_error ()) + return; + + concrete = type.handle_substitions (mappings); + } + + if (concrete != nullptr) + resolved = concrete; +} + +void +SubstMapper::visit (TyTy::ADTType &type) +{ + TyTy::ADTType *concrete = nullptr; + if (!have_generic_args ()) + { + TyTy::BaseType *substs = type.infer_substitions (locus); + rust_assert (substs->get_kind () == TyTy::TypeKind::ADT); + concrete = static_cast (substs); + } + else + { + TyTy::SubstitutionArgumentMappings mappings + = type.get_mappings_from_generic_args (*generics); + if (mappings.is_error ()) + return; + + concrete = type.handle_substitions (mappings); + } + + if (concrete != nullptr) + resolved = concrete; +} + +void +SubstMapper::visit (TyTy::PlaceholderType &type) +{ + rust_assert (type.can_resolve ()); + resolved = SubstMapper::Resolve (type.resolve (), locus, generics); +} + +void +SubstMapper::visit (TyTy::ProjectionType &type) +{ + TyTy::ProjectionType *concrete = nullptr; + if (!have_generic_args ()) + { + TyTy::BaseType *substs = type.infer_substitions (locus); + rust_assert (substs->get_kind () == TyTy::TypeKind::PROJECTION); + concrete = static_cast (substs); + } + else + { + TyTy::SubstitutionArgumentMappings mappings + = type.get_mappings_from_generic_args (*generics); + if (mappings.is_error ()) + return; + + concrete = type.handle_substitions (mappings); + } + + if (concrete != nullptr) + resolved = concrete; +} + +SubstMapperInternal::SubstMapperInternal ( + HirId ref, TyTy::SubstitutionArgumentMappings &mappings) + : resolved (new TyTy::ErrorType (ref)), mappings (mappings) +{} + TyTy::BaseType * SubstMapperInternal::Resolve (TyTy::BaseType *base, TyTy::SubstitutionArgumentMappings &mappings) @@ -73,5 +183,238 @@ SubstMapperInternal::mappings_are_bound ( return false; } +void +SubstMapperInternal::visit (TyTy::FnType &type) +{ + TyTy::SubstitutionArgumentMappings adjusted + = type.adjust_mappings_for_this (mappings); + if (adjusted.is_error ()) + return; + + TyTy::BaseType *concrete = type.handle_substitions (adjusted); + if (concrete != nullptr) + resolved = concrete; +} + +void +SubstMapperInternal::visit (TyTy::ADTType &type) +{ + TyTy::SubstitutionArgumentMappings adjusted + = type.adjust_mappings_for_this (mappings); + if (adjusted.is_error ()) + return; + + TyTy::BaseType *concrete = type.handle_substitions (adjusted); + if (concrete != nullptr) + resolved = concrete; +} + +// these don't support generic arguments but might contain a type param +void +SubstMapperInternal::visit (TyTy::TupleType &type) +{ + resolved = type.handle_substitions (mappings); +} + +void +SubstMapperInternal::visit (TyTy::ReferenceType &type) +{ + resolved = type.handle_substitions (mappings); +} + +void +SubstMapperInternal::visit (TyTy::PointerType &type) +{ + resolved = type.handle_substitions (mappings); +} + +void +SubstMapperInternal::visit (TyTy::ParamType &type) +{ + resolved = type.handle_substitions (mappings); +} + +void +SubstMapperInternal::visit (TyTy::PlaceholderType &type) +{ + rust_assert (type.can_resolve ()); + if (mappings.trait_item_mode ()) + { + resolved = type.resolve (); + } + else + { + resolved = SubstMapperInternal::Resolve (type.resolve (), mappings); + } +} + +void +SubstMapperInternal::visit (TyTy::ProjectionType &type) +{ + resolved = type.handle_substitions (mappings); +} + +void +SubstMapperInternal::visit (TyTy::ClosureType &type) +{ + resolved = type.handle_substitions (mappings); +} + +void +SubstMapperInternal::visit (TyTy::ArrayType &type) +{ + resolved = type.handle_substitions (mappings); +} + +void +SubstMapperInternal::visit (TyTy::SliceType &type) +{ + resolved = type.handle_substitions (mappings); +} + +// nothing to do for these +void +SubstMapperInternal::visit (TyTy::InferType &type) +{ + resolved = type.clone (); +} +void +SubstMapperInternal::visit (TyTy::FnPtr &type) +{ + resolved = type.clone (); +} +void +SubstMapperInternal::visit (TyTy::BoolType &type) +{ + resolved = type.clone (); +} +void +SubstMapperInternal::visit (TyTy::IntType &type) +{ + resolved = type.clone (); +} +void +SubstMapperInternal::visit (TyTy::UintType &type) +{ + resolved = type.clone (); +} +void +SubstMapperInternal::visit (TyTy::FloatType &type) +{ + resolved = type.clone (); +} +void +SubstMapperInternal::visit (TyTy::USizeType &type) +{ + resolved = type.clone (); +} +void +SubstMapperInternal::visit (TyTy::ISizeType &type) +{ + resolved = type.clone (); +} +void +SubstMapperInternal::visit (TyTy::ErrorType &type) +{ + resolved = type.clone (); +} +void +SubstMapperInternal::visit (TyTy::CharType &type) +{ + resolved = type.clone (); +} +void +SubstMapperInternal::visit (TyTy::StrType &type) +{ + resolved = type.clone (); +} +void +SubstMapperInternal::visit (TyTy::NeverType &type) +{ + resolved = type.clone (); +} +void +SubstMapperInternal::visit (TyTy::DynamicObjectType &type) +{ + resolved = type.clone (); +} + +// SubstMapperFromExisting + +SubstMapperFromExisting::SubstMapperFromExisting (TyTy::BaseType *concrete, + TyTy::BaseType *receiver) + : concrete (concrete), receiver (receiver), resolved (nullptr) +{} + +TyTy::BaseType * +SubstMapperFromExisting::Resolve (TyTy::BaseType *concrete, + TyTy::BaseType *receiver) +{ + rust_assert (concrete->get_kind () == receiver->get_kind ()); + + SubstMapperFromExisting mapper (concrete, receiver); + concrete->accept_vis (mapper); + return mapper.resolved; +} + +void +SubstMapperFromExisting::visit (TyTy::FnType &type) +{ + rust_assert (type.was_substituted ()); + + TyTy::FnType *to_sub = static_cast (receiver); + resolved = to_sub->handle_substitions (type.get_substitution_arguments ()); +} + +void +SubstMapperFromExisting::visit (TyTy::ADTType &type) +{ + rust_assert (type.was_substituted ()); + + TyTy::ADTType *to_sub = static_cast (receiver); + resolved = to_sub->handle_substitions (type.get_substitution_arguments ()); +} + +void +SubstMapperFromExisting::visit (TyTy::ClosureType &type) +{ + rust_assert (type.was_substituted ()); + + TyTy::ClosureType *to_sub = static_cast (receiver); + resolved = to_sub->handle_substitions (type.get_substitution_arguments ()); +} + +// GetUsedSubstArgs + +GetUsedSubstArgs::GetUsedSubstArgs () + : args (TyTy::SubstitutionArgumentMappings::error ()) +{} + +TyTy::SubstitutionArgumentMappings +GetUsedSubstArgs::From (const TyTy::BaseType *from) +{ + GetUsedSubstArgs mapper; + from->accept_vis (mapper); + return mapper.args; +} + +void +GetUsedSubstArgs::visit (const TyTy::FnType &type) +{ + args = type.get_substitution_arguments (); +} + +void +GetUsedSubstArgs::visit (const TyTy::ADTType &type) +{ + args = type.get_substitution_arguments (); +} + +void +GetUsedSubstArgs::visit (const TyTy::ClosureType &type) +{ + args = type.get_substitution_arguments (); +} + } // namespace Resolver } // namespace Rust diff --git a/gcc/rust/typecheck/rust-substitution-mapper.h b/gcc/rust/typecheck/rust-substitution-mapper.h index 995d9c88ec4..43b80b36713 100644 --- a/gcc/rust/typecheck/rust-substitution-mapper.h +++ b/gcc/rust/typecheck/rust-substitution-mapper.h @@ -29,95 +29,16 @@ class SubstMapper : public TyTy::TyVisitor { public: static TyTy::BaseType *Resolve (TyTy::BaseType *base, Location locus, - HIR::GenericArgs *generics = nullptr) - { - SubstMapper mapper (base->get_ref (), generics, locus); - base->accept_vis (mapper); - rust_assert (mapper.resolved != nullptr); - return mapper.resolved; - } + HIR::GenericArgs *generics = nullptr); - static TyTy::BaseType *InferSubst (TyTy::BaseType *base, Location locus) - { - return SubstMapper::Resolve (base, locus, nullptr); - } + static TyTy::BaseType *InferSubst (TyTy::BaseType *base, Location locus); - bool have_generic_args () const { return generics != nullptr; } + bool have_generic_args () const; - void visit (TyTy::FnType &type) override - { - TyTy::FnType *concrete = nullptr; - if (!have_generic_args ()) - { - TyTy::BaseType *substs = type.infer_substitions (locus); - rust_assert (substs->get_kind () == TyTy::TypeKind::FNDEF); - concrete = static_cast (substs); - } - else - { - TyTy::SubstitutionArgumentMappings mappings - = type.get_mappings_from_generic_args (*generics); - if (mappings.is_error ()) - return; - - concrete = type.handle_substitions (mappings); - } - - if (concrete != nullptr) - resolved = concrete; - } - - void visit (TyTy::ADTType &type) override - { - TyTy::ADTType *concrete = nullptr; - if (!have_generic_args ()) - { - TyTy::BaseType *substs = type.infer_substitions (locus); - rust_assert (substs->get_kind () == TyTy::TypeKind::ADT); - concrete = static_cast (substs); - } - else - { - TyTy::SubstitutionArgumentMappings mappings - = type.get_mappings_from_generic_args (*generics); - if (mappings.is_error ()) - return; - - concrete = type.handle_substitions (mappings); - } - - if (concrete != nullptr) - resolved = concrete; - } - - void visit (TyTy::PlaceholderType &type) override - { - rust_assert (type.can_resolve ()); - resolved = SubstMapper::Resolve (type.resolve (), locus, generics); - } - - void visit (TyTy::ProjectionType &type) override - { - TyTy::ProjectionType *concrete = nullptr; - if (!have_generic_args ()) - { - TyTy::BaseType *substs = type.infer_substitions (locus); - rust_assert (substs->get_kind () == TyTy::TypeKind::PROJECTION); - concrete = static_cast (substs); - } - else - { - TyTy::SubstitutionArgumentMappings mappings - = type.get_mappings_from_generic_args (*generics); - if (mappings.is_error ()) - return; - - concrete = type.handle_substitions (mappings); - } - - if (concrete != nullptr) - resolved = concrete; - } + void visit (TyTy::FnType &type) override; + void visit (TyTy::ADTType &type) override; + void visit (TyTy::PlaceholderType &type) override; + void visit (TyTy::ProjectionType &type) override; // nothing to do for these void visit (TyTy::InferType &) override { gcc_unreachable (); } @@ -142,9 +63,7 @@ public: void visit (TyTy::ClosureType &) override { gcc_unreachable (); } private: - SubstMapper (HirId ref, HIR::GenericArgs *generics, Location locus) - : resolved (new TyTy::ErrorType (ref)), generics (generics), locus (locus) - {} + SubstMapper (HirId ref, HIR::GenericArgs *generics, Location locus); TyTy::BaseType *resolved; HIR::GenericArgs *generics; @@ -160,106 +79,33 @@ public: static bool mappings_are_bound (TyTy::BaseType *ty, TyTy::SubstitutionArgumentMappings &mappings); - void visit (TyTy::FnType &type) override - { - TyTy::SubstitutionArgumentMappings adjusted - = type.adjust_mappings_for_this (mappings); - if (adjusted.is_error ()) - return; - - TyTy::BaseType *concrete = type.handle_substitions (adjusted); - if (concrete != nullptr) - resolved = concrete; - } - - void visit (TyTy::ADTType &type) override - { - TyTy::SubstitutionArgumentMappings adjusted - = type.adjust_mappings_for_this (mappings); - if (adjusted.is_error ()) - return; - - TyTy::BaseType *concrete = type.handle_substitions (adjusted); - if (concrete != nullptr) - resolved = concrete; - } - - // these don't support generic arguments but might contain a type param - void visit (TyTy::TupleType &type) override - { - resolved = type.handle_substitions (mappings); - } - - void visit (TyTy::ReferenceType &type) override - { - resolved = type.handle_substitions (mappings); - } - - void visit (TyTy::PointerType &type) override - { - resolved = type.handle_substitions (mappings); - } - - void visit (TyTy::ParamType &type) override - { - resolved = type.handle_substitions (mappings); - } - - void visit (TyTy::PlaceholderType &type) override - { - rust_assert (type.can_resolve ()); - if (mappings.trait_item_mode ()) - { - resolved = type.resolve (); - } - else - { - resolved = SubstMapperInternal::Resolve (type.resolve (), mappings); - } - } - - void visit (TyTy::ProjectionType &type) override - { - resolved = type.handle_substitions (mappings); - } - - void visit (TyTy::ClosureType &type) override - { - resolved = type.handle_substitions (mappings); - } - - void visit (TyTy::ArrayType &type) override - { - resolved = type.handle_substitions (mappings); - } - - void visit (TyTy::SliceType &type) override - { - resolved = type.handle_substitions (mappings); - } - - // nothing to do for these - void visit (TyTy::InferType &type) override { resolved = type.clone (); } - void visit (TyTy::FnPtr &type) override { resolved = type.clone (); } - void visit (TyTy::BoolType &type) override { resolved = type.clone (); } - void visit (TyTy::IntType &type) override { resolved = type.clone (); } - void visit (TyTy::UintType &type) override { resolved = type.clone (); } - void visit (TyTy::FloatType &type) override { resolved = type.clone (); } - void visit (TyTy::USizeType &type) override { resolved = type.clone (); } - void visit (TyTy::ISizeType &type) override { resolved = type.clone (); } - void visit (TyTy::ErrorType &type) override { resolved = type.clone (); } - void visit (TyTy::CharType &type) override { resolved = type.clone (); } - void visit (TyTy::StrType &type) override { resolved = type.clone (); } - void visit (TyTy::NeverType &type) override { resolved = type.clone (); } - void visit (TyTy::DynamicObjectType &type) override - { - resolved = type.clone (); - } + void visit (TyTy::FnType &type) override; + void visit (TyTy::ADTType &type) override; + void visit (TyTy::TupleType &type) override; + void visit (TyTy::ReferenceType &type) override; + void visit (TyTy::PointerType &type) override; + void visit (TyTy::ParamType &type) override; + void visit (TyTy::PlaceholderType &type) override; + void visit (TyTy::ProjectionType &type) override; + void visit (TyTy::ClosureType &type) override; + void visit (TyTy::ArrayType &type) override; + void visit (TyTy::SliceType &type) override; + void visit (TyTy::InferType &type) override; + void visit (TyTy::FnPtr &type) override; + void visit (TyTy::BoolType &type) override; + void visit (TyTy::IntType &type) override; + void visit (TyTy::UintType &type) override; + void visit (TyTy::FloatType &type) override; + void visit (TyTy::USizeType &type) override; + void visit (TyTy::ISizeType &type) override; + void visit (TyTy::ErrorType &type) override; + void visit (TyTy::CharType &type) override; + void visit (TyTy::StrType &type) override; + void visit (TyTy::NeverType &type) override; + void visit (TyTy::DynamicObjectType &type) override; private: - SubstMapperInternal (HirId ref, TyTy::SubstitutionArgumentMappings &mappings) - : resolved (new TyTy::ErrorType (ref)), mappings (mappings) - {} + SubstMapperInternal (HirId ref, TyTy::SubstitutionArgumentMappings &mappings); TyTy::BaseType *resolved; TyTy::SubstitutionArgumentMappings &mappings; @@ -269,38 +115,11 @@ class SubstMapperFromExisting : public TyTy::TyVisitor { public: static TyTy::BaseType *Resolve (TyTy::BaseType *concrete, - TyTy::BaseType *receiver) - { - rust_assert (concrete->get_kind () == receiver->get_kind ()); - - SubstMapperFromExisting mapper (concrete, receiver); - concrete->accept_vis (mapper); - return mapper.resolved; - } + TyTy::BaseType *receiver); - void visit (TyTy::FnType &type) override - { - rust_assert (type.was_substituted ()); - - TyTy::FnType *to_sub = static_cast (receiver); - resolved = to_sub->handle_substitions (type.get_substitution_arguments ()); - } - - void visit (TyTy::ADTType &type) override - { - rust_assert (type.was_substituted ()); - - TyTy::ADTType *to_sub = static_cast (receiver); - resolved = to_sub->handle_substitions (type.get_substitution_arguments ()); - } - - void visit (TyTy::ClosureType &type) override - { - rust_assert (type.was_substituted ()); - - TyTy::ClosureType *to_sub = static_cast (receiver); - resolved = to_sub->handle_substitions (type.get_substitution_arguments ()); - } + void visit (TyTy::FnType &type) override; + void visit (TyTy::ADTType &type) override; + void visit (TyTy::ClosureType &type) override; void visit (TyTy::InferType &) override { gcc_unreachable (); } void visit (TyTy::TupleType &) override { gcc_unreachable (); } @@ -325,40 +144,21 @@ public: void visit (TyTy::DynamicObjectType &) override { gcc_unreachable (); } private: - SubstMapperFromExisting (TyTy::BaseType *concrete, TyTy::BaseType *receiver) - : concrete (concrete), receiver (receiver), resolved (nullptr) - {} + SubstMapperFromExisting (TyTy::BaseType *concrete, TyTy::BaseType *receiver); TyTy::BaseType *concrete; TyTy::BaseType *receiver; - TyTy::BaseType *resolved; }; class GetUsedSubstArgs : public TyTy::TyConstVisitor { public: - static TyTy::SubstitutionArgumentMappings From (const TyTy::BaseType *from) - { - GetUsedSubstArgs mapper; - from->accept_vis (mapper); - return mapper.args; - } - - void visit (const TyTy::FnType &type) override - { - args = type.get_substitution_arguments (); - } - - void visit (const TyTy::ADTType &type) override - { - args = type.get_substitution_arguments (); - } + static TyTy::SubstitutionArgumentMappings From (const TyTy::BaseType *from); - void visit (const TyTy::ClosureType &type) override - { - args = type.get_substitution_arguments (); - } + void visit (const TyTy::FnType &type) override; + void visit (const TyTy::ADTType &type) override; + void visit (const TyTy::ClosureType &type) override; void visit (const TyTy::InferType &) override {} void visit (const TyTy::TupleType &) override {} @@ -383,7 +183,7 @@ public: void visit (const TyTy::DynamicObjectType &) override {} private: - GetUsedSubstArgs () : args (TyTy::SubstitutionArgumentMappings::error ()) {} + GetUsedSubstArgs (); TyTy::SubstitutionArgumentMappings args; }; diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc b/gcc/rust/typecheck/rust-tyty-subst.cc index 64001459b4d..aceed29ff03 100644 --- a/gcc/rust/typecheck/rust-tyty-subst.cc +++ b/gcc/rust/typecheck/rust-tyty-subst.cc @@ -68,7 +68,7 @@ const HIR::TypeParam & SubstitutionParamMapping::get_generic_param () { return generic; -}; +} bool SubstitutionParamMapping::needs_substitution () const From patchwork Wed Apr 5 14:03: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: 79684 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp352815vqo; Wed, 5 Apr 2023 07:32:18 -0700 (PDT) X-Google-Smtp-Source: AKy350aGuL1r0tJA+L9ipqwjT77+9cqsoBkr9194tIiYo0z3phCI0ZbNgHUd3heFFkbrUXLGrvFB X-Received: by 2002:a17:906:ccc2:b0:92c:16cc:2dcd with SMTP id ot2-20020a170906ccc200b0092c16cc2dcdmr2933949ejb.33.1680705138030; Wed, 05 Apr 2023 07:32:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705138; cv=none; d=google.com; s=arc-20160816; b=aCBu8AnjdU3eDeSqiDRsFr1mvAgbwf0hP3skxOu3PNEEgXscERH4Kl/DvWqmkIElz2 oqiGhOfJDPJaFK5X64r3uiBn9YcRjCMyehG+Nh/l0ufgggN1HmUcA0BTNkmWY95ZychX KNrf2rb8/AmzTvolpHFWq4/Jt8T9ZX3W+ayF+d2e+IiUREwNl3N+l0MNMtiCJH/q5bhm 43ktmhrkoPhLeMAO0IGRD8+h1t8N8sQNtS2esZAYqFQPGhLQRaIB1QYpYhkisH31MBUu zf+/t7b9xVuwcGMv4dkUOaVJbZHQm6467SI5oK7ANUoZ9aab6HjekZt61dM9TjCQfyAU 3rBQ== 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=v8LlfW/dVfH+bREmWfTuMct9EbFkL6ygxutNPMja9do=; b=gp0KO1vUgGJYKi4nqwOS1iqHRcb0lSHtE2nItMxpg7hZnLLzBcAeTfIFkeqOWDWBjf 1MB71xluy3v1wzXaoN63zuq45NIgOnAyTWOymfofs3gV4BJQPkSPKcEoGVZARxm0YGuY 1hfJmsZcelnB0bf1eILlbfKgqQxTLrjCYAYzaHjTBcKPg3wtsVXzh3I2ZA9dHVUDKU9I ReD9EpLn/bwwd498mZHaroGa7GShaZCa3N5YE/298TSHvHwKpH4sU4ZTMJwczeLl4M00 m+pK6nvOSnRDwnKqd/xP75XEmdKBs8ZCOwht343JPF0Yp6+HmERJ5x7j7/uqu5NgjtKl oLDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b="A9/cRi5G"; 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 ay21-20020a056402203500b005021f0d5753si10478836edb.666.2023.04.05.07.32.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:32:18 -0700 (PDT) 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="A9/cRi5G"; 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 2621D3930C91 for ; Wed, 5 Apr 2023 14:12:50 +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 515F4384D197 for ; Wed, 5 Apr 2023 14:05:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 515F4384D197 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 p34so20958290wms.3 for ; Wed, 05 Apr 2023 07:05:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703556; 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=v8LlfW/dVfH+bREmWfTuMct9EbFkL6ygxutNPMja9do=; b=A9/cRi5GMBsTOBhQyHz1fHmGs24WO9TetxvM/xVBg1KoKR8LmxgHVFmOr2qv9b41w0 0Hp32V1opBx5a0eEVbHbFJSBErDwm60gwOQFxeWK+5E9HEfS/XTe03hsE1DZZhbOcuE1 +hPfdfiGHSV2vLbSh6b1YzLLcye9e2FwnPZNNkq1XXqdhjRNmVL6TgVMX31EpEsLGFjq BUPbumChBVhcbutBMyJn2C/TKr6xuVmUXrhB1OII9lmOd//GzyaO/ZkExzH2QEPgPBKM n2cwTvfNZ0D/51CzCp/M7olyIhkVR/riuHhgum2UYFsVT35WJdADiOceYFkVdJ5c60xH RH/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703556; 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=v8LlfW/dVfH+bREmWfTuMct9EbFkL6ygxutNPMja9do=; b=GpqmQkbWNGg6UMzVKsx+IvDpNMyhi7tzGHGQglY8j4oIRu88Rzi4UbyfqYYKg8luoe kJfh5/COJiUMjjetDynRuPqWrTWMGYXxrDL/xgKdaDN7kI94KEXL+ofcQuvSPC8+WJ0K QbZL8J4Z1YAemceUBKxb3bnvqJHTz9BmwKETuLYsuq6GjQKQzusQ4/+Im/O04tHLD5Se Ddb2cY6eVdBNVCMKO2MPwtpOoWoDTvQVyeEJTjzipDjAMJYkDxpCaK4oNz8gR5pyry4a hQwCPrLK04xzrwQvWaym2oDQvdWg5uRx654IlI6O+HHHTw+9MmRfhc3D+vEpI07EY70K 89ZA== X-Gm-Message-State: AAQBX9d3NSfBkU/qAmHqxBlSSY0B8MiLLyMiiQIUQv5MafCYeNsRV60m L07sl1aINalideKr2Do09khXn4w4JJWdVIK3uQ== X-Received: by 2002:a1c:7716:0:b0:3ee:67ff:4aad with SMTP id t22-20020a1c7716000000b003ee67ff4aadmr4697692wmi.26.1680703556539; Wed, 05 Apr 2023 07:05:56 -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.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:56 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 40/88] gccrs: Refactor BaseType, InferType and ErrorType impl into cc file Date: Wed, 5 Apr 2023 16:03:24 +0200 Message-Id: <20230405140411.3016563-41-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.6 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?1762347070686302134?= X-GMAIL-MSGID: =?utf-8?q?1762347070686302134?= From: Philip Herron Signed-off-by: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-tyty.cc (BaseType::BaseType): refactor (BaseType::~BaseType): likewise (BaseType::get_ref): likewise (BaseType::set_ref): likewise (BaseType::get_ty_ref): likewise (BaseType::set_ty_ref): likewise (BaseType::is_equal): likewise (BaseType::is_unit): likewise (BaseType::get_kind): likewise (BaseType::get_combined_refs): likewise (BaseType::append_reference): likewise (BaseType::supports_substitutions): likewise (BaseType::has_subsititions_defined): likewise (BaseType::can_substitute): likewise (BaseType::needs_generic_substitutions): likewise (BaseType::contains_type_parameters): likewise (BaseType::get_ident): likewise (BaseType::get_locus): likewise (InferType::InferType): likewise (InferType::get_infer_kind): likewise (InferType::get_name): likewise (InferType::is_concrete): likewise (ErrorType::ErrorType): likewise (ErrorType::is_unit): likewise (ErrorType::is_concrete): likewise (ErrorType::get_name): likewise (ErrorType::monomorphized_clone): likewise * typecheck/rust-tyty.h (class SubstitutionArgumentMappings): likewise --- gcc/rust/typecheck/rust-tyty.cc | 181 ++++++++++++++++++++++++++++++++ gcc/rust/typecheck/rust-tyty.h | 92 ++++++---------- 2 files changed, 211 insertions(+), 62 deletions(-) diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index b45bd99b1bd..079055e870d 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -146,6 +146,122 @@ is_primitive_type_kind (TypeKind kind) } } +// BASE TYPE + +BaseType::BaseType (HirId ref, HirId ty_ref, TypeKind kind, RustIdent ident, + std::set refs) + : TypeBoundsMappings ({}), kind (kind), ref (ref), ty_ref (ty_ref), + combined (refs), ident (ident), mappings (Analysis::Mappings::get ()) +{} + +BaseType::BaseType (HirId ref, HirId ty_ref, TypeKind kind, RustIdent ident, + std::vector specified_bounds, + std::set refs) + : TypeBoundsMappings (specified_bounds), kind (kind), ref (ref), + ty_ref (ty_ref), combined (refs), ident (ident), + mappings (Analysis::Mappings::get ()) +{} + +BaseType::~BaseType () {} + +HirId +BaseType::get_ref () const +{ + return ref; +} + +void +BaseType::set_ref (HirId id) +{ + if (id != ref) + append_reference (ref); + ref = id; +} + +HirId +BaseType::get_ty_ref () const +{ + return ty_ref; +} + +void +BaseType::set_ty_ref (HirId id) +{ + ty_ref = id; +} + +bool +BaseType::is_equal (const BaseType &other) const +{ + return get_kind () == other.get_kind (); +} + +bool +BaseType::is_unit () const +{ + return false; +} + +TypeKind +BaseType::get_kind () const +{ + return kind; +} + +std::set +BaseType::get_combined_refs () const +{ + return combined; +} + +void +BaseType::append_reference (HirId id) +{ + combined.insert (id); +} + +bool +BaseType::supports_substitutions () const +{ + return false; +} + +bool +BaseType::has_subsititions_defined () const +{ + return false; +} + +bool +BaseType::can_substitute () const +{ + return supports_substitutions () && has_subsititions_defined (); +} + +bool +BaseType::needs_generic_substitutions () const +{ + return false; +} + +bool +BaseType::contains_type_parameters () const +{ + return !is_concrete (); +} + +const RustIdent & +BaseType::get_ident () const +{ + return ident; +} + +Location +BaseType::get_locus () const +{ + return ident.locus; +} + bool BaseType::satisfies_bound (const TypeBoundPredicate &predicate) const { @@ -330,6 +446,40 @@ BaseType::debug () const debug_str ().c_str ()); } +// InferType + +InferType::InferType (HirId ref, InferTypeKind infer_kind, Location locus, + std::set refs) + : BaseType (ref, ref, TypeKind::INFER, + {Resolver::CanonicalPath::create_empty (), locus}, refs), + infer_kind (infer_kind) +{} + +InferType::InferType (HirId ref, HirId ty_ref, InferTypeKind infer_kind, + Location locus, std::set refs) + : BaseType (ref, ty_ref, TypeKind::INFER, + {Resolver::CanonicalPath::create_empty (), locus}, refs), + infer_kind (infer_kind) +{} + +InferType::InferTypeKind +InferType::get_infer_kind () const +{ + return infer_kind; +} + +std::string +InferType::get_name () const +{ + return as_string (); +} + +bool +InferType::is_concrete () const +{ + return true; +} + void InferType::accept_vis (TyVisitor &vis) { @@ -435,6 +585,35 @@ InferType::default_type (BaseType **type) const return false; } +// ErrorType + +ErrorType::ErrorType (HirId ref, std::set refs) + : BaseType (ref, ref, TypeKind::ERROR, + {Resolver::CanonicalPath::create_empty (), Location ()}, refs) +{} + +ErrorType::ErrorType (HirId ref, HirId ty_ref, std::set refs) + : BaseType (ref, ty_ref, TypeKind::ERROR, + {Resolver::CanonicalPath::create_empty (), Location ()}, refs) +{} + +bool +ErrorType::is_unit () const +{ + return true; +} +bool +ErrorType::is_concrete () const +{ + return false; +} + +std::string +ErrorType::get_name () const +{ + return as_string (); +} + void ErrorType::accept_vis (TyVisitor &vis) { @@ -477,6 +656,8 @@ ErrorType::monomorphized_clone () const return clone (); } +// Struct Field type + std::string StructFieldType::as_string () const { diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index cb30a60ae96..1a6bac3f864 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -89,20 +89,15 @@ class TyConstVisitor; class BaseType : public TypeBoundsMappings { public: - virtual ~BaseType () {} + virtual ~BaseType (); - HirId get_ref () const { return ref; } + HirId get_ref () const; - void set_ref (HirId id) - { - if (id != ref) - append_reference (ref); - ref = id; - } + void set_ref (HirId id); - HirId get_ty_ref () const { return ty_ref; } + HirId get_ty_ref () const; - void set_ty_ref (HirId id) { ty_ref = id; } + void set_ty_ref (HirId id); virtual void accept_vis (TyVisitor &vis) = 0; @@ -133,10 +128,7 @@ public: // ty are considered equal if they're of the same kind, and // 1. (For ADTs, arrays, tuples, refs) have the same underlying ty // 2. (For functions) have the same signature - virtual bool is_equal (const BaseType &other) const - { - return get_kind () == other.get_kind (); - } + virtual bool is_equal (const BaseType &other) const; bool satisfies_bound (const TypeBoundPredicate &predicate) const; @@ -148,11 +140,11 @@ public: void inherit_bounds ( const std::vector &specified_bounds); - virtual bool is_unit () const { return false; } + virtual bool is_unit () const; virtual bool is_concrete () const = 0; - TypeKind get_kind () const { return kind; } + TypeKind get_kind () const; /* Returns a pointer to a clone of this. The caller is responsible for * releasing the memory of the returned ty. */ @@ -162,22 +154,19 @@ public: virtual BaseType *monomorphized_clone () const = 0; // get_combined_refs returns the chain of node refs involved in unification - std::set get_combined_refs () const { return combined; } + std::set get_combined_refs () const; - void append_reference (HirId id) { combined.insert (id); } + void append_reference (HirId id); - virtual bool supports_substitutions () const { return false; } + virtual bool supports_substitutions () const; - virtual bool has_subsititions_defined () const { return false; } + virtual bool has_subsititions_defined () const; - virtual bool can_substitute () const - { - return supports_substitutions () && has_subsititions_defined (); - } + virtual bool can_substitute () const; - virtual bool needs_generic_substitutions () const { return false; } + virtual bool needs_generic_substitutions () const; - bool contains_type_parameters () const { return !is_concrete (); } + bool contains_type_parameters () const; std::string mappings_str () const; @@ -192,24 +181,17 @@ public: // Projections if available or error const BaseType *destructure () const; - const RustIdent &get_ident () const { return ident; } + const RustIdent &get_ident () const; - Location get_locus () const { return ident.locus; } + Location get_locus () const; protected: BaseType (HirId ref, HirId ty_ref, TypeKind kind, RustIdent ident, - std::set refs = std::set ()) - : TypeBoundsMappings ({}), kind (kind), ref (ref), ty_ref (ty_ref), - combined (refs), ident (ident), mappings (Analysis::Mappings::get ()) - {} + std::set refs = std::set ()); BaseType (HirId ref, HirId ty_ref, TypeKind kind, RustIdent ident, std::vector specified_bounds, - std::set refs = std::set ()) - : TypeBoundsMappings (specified_bounds), kind (kind), ref (ref), - ty_ref (ty_ref), combined (refs), ident (ident), - mappings (Analysis::Mappings::get ()) - {} + std::set refs = std::set ()); TypeKind kind; HirId ref; @@ -231,18 +213,10 @@ public: }; InferType (HirId ref, InferTypeKind infer_kind, Location locus, - std::set refs = std::set ()) - : BaseType (ref, ref, TypeKind::INFER, - {Resolver::CanonicalPath::create_empty (), locus}, refs), - infer_kind (infer_kind) - {} + std::set refs = std::set ()); InferType (HirId ref, HirId ty_ref, InferTypeKind infer_kind, Location locus, - std::set refs = std::set ()) - : BaseType (ref, ty_ref, TypeKind::INFER, - {Resolver::CanonicalPath::create_empty (), locus}, refs), - infer_kind (infer_kind) - {} + std::set refs = std::set ()); void accept_vis (TyVisitor &vis) override; void accept_vis (TyConstVisitor &vis) const override; @@ -256,13 +230,13 @@ public: BaseType *clone () const final override; BaseType *monomorphized_clone () const final override; - InferTypeKind get_infer_kind () const { return infer_kind; } + InferTypeKind get_infer_kind () const; - std::string get_name () const override final { return as_string (); } + std::string get_name () const override final; bool default_type (BaseType **type) const; - bool is_concrete () const final override { return true; } + bool is_concrete () const final override; private: InferTypeKind infer_kind; @@ -271,20 +245,15 @@ private: class ErrorType : public BaseType { public: - ErrorType (HirId ref, std::set refs = std::set ()) - : BaseType (ref, ref, TypeKind::ERROR, - {Resolver::CanonicalPath::create_empty (), Location ()}, refs) - {} + ErrorType (HirId ref, std::set refs = std::set ()); - ErrorType (HirId ref, HirId ty_ref, std::set refs = std::set ()) - : BaseType (ref, ty_ref, TypeKind::ERROR, - {Resolver::CanonicalPath::create_empty (), Location ()}, refs) - {} + ErrorType (HirId ref, HirId ty_ref, + std::set refs = std::set ()); void accept_vis (TyVisitor &vis) override; void accept_vis (TyConstVisitor &vis) const override; - bool is_unit () const override { return true; } + bool is_unit () const override; std::string as_string () const override; @@ -294,12 +263,11 @@ public: BaseType *clone () const final override; BaseType *monomorphized_clone () const final override; - std::string get_name () const override final { return as_string (); } + std::string get_name () const override final; - bool is_concrete () const final override { return false; } + bool is_concrete () const final override; }; -class SubstitutionArgumentMappings; class ParamType : public BaseType { public: From patchwork Wed Apr 5 14:03: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: 79690 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp355341vqo; Wed, 5 Apr 2023 07:35:49 -0700 (PDT) X-Google-Smtp-Source: AKy350ao3LWRXUBW7YcCedkx7kymEt0pryBS34UwKxRevL3bUwlS+F3brJ5c8+CuuhhRBaVA3+0s X-Received: by 2002:aa7:d615:0:b0:4fb:5607:6a24 with SMTP id c21-20020aa7d615000000b004fb56076a24mr2188010edr.8.1680705349762; Wed, 05 Apr 2023 07:35:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705349; cv=none; d=google.com; s=arc-20160816; b=H7oh76DAoZij5pfSuufRNmYgKRSsAtJ/yI+4GuJ3zz6BGbnTMpeQcCiddCeU+HVdcd yGaGRh2U8aAPl1aPsYxy3Nf442zl23tW9/MfHOCu6khPhnHrehosY2Y2VOUWEC7/vCA5 ux6XXkK5YYWDdy1BavzIAKrLRe3ZuQIK0+cS04f+mkECY6AH/Ps9K2b3Xsu8VHvQgCvt 5wyyIUa6v5WE8cE6/ZHcM5shHIqO6ISed5BWbmMmPmNHWk6SxoRx33gsbzMuBpQ336kh 0GBsFdu89uMhvohB8Tuu2KlqoSt2G4D1Q2IXF7E8HfbfECirg5z41SBpuBI28prw2jic T2uQ== 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=fMKpeeyj8e5rheVnzAGU55AINUOYg+UQsYb2D/lPNEY=; b=fdVEjaa6WxFYmorc+jaS28T2vvj/8cjqm3UvQ+3BnHui3vfYy+UQkpjqocHW8rOR5f jEdcSmkUbgMh5H2MJ8q8BoystW72QPbUAmRD14ylXe8n1udmVppFo2nnQLkW6RBxxyCZ tE/LifAva0N55slTQ8kgaYOiN2XdePvwgJ0lElGgDgtNAl4+Bv/iqCpgsiwzABC5BgUk l+BduvicgdfGnBLpVG0GsPoGI1iMfoiAv8fCb1hJ/wy26jx1CAGRx98U9hNVe7HwzT1P 6IYM+HO+TIrI7cuInlrTgBmweRPTFxMIZm02CHWlgA8qK8qMvCwHVl6lF9CnGJ+WyY45 B8jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=LUuFiOVm; 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 i11-20020aa7c70b000000b00501c4e398fasi1225529edq.142.2023.04.05.07.35.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:35:49 -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=LUuFiOVm; 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 B6FF93992EA1 for ; Wed, 5 Apr 2023 14:13:40 +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 3B93F3851405 for ; Wed, 5 Apr 2023 14:05:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3B93F3851405 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 d11-20020a05600c3acb00b003ef6e6754c5so18371797wms.5 for ; Wed, 05 Apr 2023 07:05:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703557; 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=fMKpeeyj8e5rheVnzAGU55AINUOYg+UQsYb2D/lPNEY=; b=LUuFiOVmJJ1ptQfPMd3tAF+ZaKeYl0PGhh+zTjvYAqx5rqOEzhrE7EHBihXDY7KjrO WfYAOiiRazXQULvF7FrreHhiQkKQO1C57e/iVM2uoRFyn9EY7Jo0neH9Q8vuXc9s2ZOQ bV0cuIBkgMBfUjfS2ViJnZqbRTuVlZniFhCM+Zax3F/MiiUfBN9oW41p23POWWL9SoMD zocvzUHveRn+qtv3bNMl0j1rVK4+FIvbiY04f3BhnU17GnwBzS/uBhdQH/Z42RzVcYhh Xq1Jb214TZq2SJUKdYY50hRUh+GSl7ao0J2wXutbOsE9MpVu7V6vHTqsoSoenGKooCEY XWjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703557; 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=fMKpeeyj8e5rheVnzAGU55AINUOYg+UQsYb2D/lPNEY=; b=P5Z5Cror4YyztmXHhqnUUZzeEawd+JlyFI6q/e3gTWXw477Rbr5TRANTMwihG+9SGi fvxoVdaevnH8fQfmZ/uZYBM7sxHZzKFgbKVNJHxIXQXH7rZOa3+pZF5/RhBK8rLBVpIR /lDDPUQiOD9jzdET0S0rcVVIqu+ZFgFtkdoerFbdw7gP6guNH3seYCBiAcyguPq7okbZ Pt2aDS4bJ7y9D8/sGFhoNQopp67Hxc7sob2Cg7RNhrM77ie4WANpo/NOo9xgIkIeGNup gkgVoJVOc4Ffz7+BG7ybr8CUabqV2RJnuD+rmVkaZdtJlhhHh1OqzjBJrCvKn3wfeGeM xI2A== X-Gm-Message-State: AAQBX9cMB5fSslUTcJQEq28eOn7EmLcnpeiWUytYfYo1oNi1HBF189Fs /bBE5h68RS2pltM4pQZT4sJ+ym8/PbdgjYhuUg== X-Received: by 2002:a05:600c:2c46:b0:3ef:d386:1a3b with SMTP id r6-20020a05600c2c4600b003efd3861a3bmr5187468wmg.34.1680703557453; Wed, 05 Apr 2023 07:05:57 -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.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:57 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 41/88] gccrs: Refactor PathProbe into cc file Date: Wed, 5 Apr 2023 16:03:25 +0200 Message-Id: <20230405140411.3016563-42-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.6 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?1762347293182090462?= X-GMAIL-MSGID: =?utf-8?q?1762347293182090462?= From: Philip Herron Signed-off-by: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-hir-path-probe.cc (PathProbeType::PathProbeType): refactor (PathProbeType::Probe): likewise (PathProbeType::visit): likewise (PathProbeType::process_enum_item_for_candiates): likewise (PathProbeType::process_impl_items_for_candidates): likewise (PathProbeType::is_reciever_generic): likewise (PathProbeImplTrait::PathProbeImplTrait): likewise (PathProbeImplTrait::Probe): likewise (PathProbeImplTrait::process_trait_impl_items_for_candidates): likewise * typecheck/rust-hir-path-probe.h (struct PathProbeCandidate): likewise * typecheck/rust-hir-trait-resolve.cc (PathProbeImplTrait::process_trait_impl_items_for_candidates): likewise --- gcc/rust/typecheck/rust-hir-path-probe.cc | 344 +++++++++++++++++++ gcc/rust/typecheck/rust-hir-path-probe.h | 302 +--------------- gcc/rust/typecheck/rust-hir-trait-resolve.cc | 22 -- 3 files changed, 360 insertions(+), 308 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-path-probe.cc b/gcc/rust/typecheck/rust-hir-path-probe.cc index cb3270d3623..06d8920d2eb 100644 --- a/gcc/rust/typecheck/rust-hir-path-probe.cc +++ b/gcc/rust/typecheck/rust-hir-path-probe.cc @@ -18,10 +18,168 @@ #include "rust-hir-path-probe.h" #include "rust-hir-type-check-item.h" +#include "rust-hir-trait-resolve.h" namespace Rust { namespace Resolver { +// PathProbeType + +PathProbeType::PathProbeType (const TyTy::BaseType *receiver, + const HIR::PathIdentSegment &query, + DefId specific_trait_id) + : TypeCheckBase (), receiver (receiver), search (query), + current_impl (nullptr), specific_trait_id (specific_trait_id) +{} + +std::set +PathProbeType::Probe (const TyTy::BaseType *receiver, + const HIR::PathIdentSegment &segment_name, + bool probe_impls, bool probe_bounds, + bool ignore_mandatory_trait_items, + DefId specific_trait_id) +{ + PathProbeType probe (receiver, segment_name, specific_trait_id); + if (probe_impls) + { + if (receiver->get_kind () == TyTy::TypeKind::ADT) + { + const TyTy::ADTType *adt + = static_cast (receiver); + if (adt->is_enum ()) + probe.process_enum_item_for_candiates (adt); + } + + probe.process_impl_items_for_candidates (); + } + + if (!probe_bounds) + return probe.candidates; + + if (!probe.is_reciever_generic ()) + { + std::vector> probed_bounds + = TypeBoundsProbe::Probe (receiver); + for (auto &candidate : probed_bounds) + { + const TraitReference *trait_ref = candidate.first; + if (specific_trait_id != UNKNOWN_DEFID) + { + if (trait_ref->get_mappings ().get_defid () != specific_trait_id) + continue; + } + + HIR::ImplBlock *impl = candidate.second; + probe.process_associated_trait_for_candidates ( + trait_ref, impl, ignore_mandatory_trait_items); + } + } + + for (const TyTy::TypeBoundPredicate &predicate : + receiver->get_specified_bounds ()) + { + const TraitReference *trait_ref = predicate.get (); + if (specific_trait_id != UNKNOWN_DEFID) + { + if (trait_ref->get_mappings ().get_defid () != specific_trait_id) + continue; + } + + probe.process_predicate_for_candidates (predicate, + ignore_mandatory_trait_items); + } + + return probe.candidates; +} + +void +PathProbeType::visit (HIR::TypeAlias &alias) +{ + Identifier name = alias.get_new_type_name (); + if (search.as_string ().compare (name) == 0) + { + HirId tyid = alias.get_mappings ().get_hirid (); + TyTy::BaseType *ty = nullptr; + bool ok = query_type (tyid, &ty); + rust_assert (ok); + + PathProbeCandidate::ImplItemCandidate impl_item_candidate{&alias, + current_impl}; + PathProbeCandidate candidate{ + PathProbeCandidate::CandidateType::IMPL_TYPE_ALIAS, ty, + alias.get_locus (), impl_item_candidate}; + candidates.insert (std::move (candidate)); + } +} + +void +PathProbeType::visit (HIR::ConstantItem &constant) +{ + Identifier name = constant.get_identifier (); + if (search.as_string ().compare (name) == 0) + { + HirId tyid = constant.get_mappings ().get_hirid (); + TyTy::BaseType *ty = nullptr; + bool ok = query_type (tyid, &ty); + rust_assert (ok); + + PathProbeCandidate::ImplItemCandidate impl_item_candidate{&constant, + current_impl}; + PathProbeCandidate candidate{ + PathProbeCandidate::CandidateType::IMPL_CONST, ty, + constant.get_locus (), impl_item_candidate}; + candidates.insert (std::move (candidate)); + } +} + +void +PathProbeType::visit (HIR::Function &function) +{ + Identifier name = function.get_function_name (); + if (search.as_string ().compare (name) == 0) + { + HirId tyid = function.get_mappings ().get_hirid (); + TyTy::BaseType *ty = nullptr; + bool ok = query_type (tyid, &ty); + rust_assert (ok); + + PathProbeCandidate::ImplItemCandidate impl_item_candidate{&function, + current_impl}; + PathProbeCandidate candidate{PathProbeCandidate::CandidateType::IMPL_FUNC, + ty, function.get_locus (), + impl_item_candidate}; + candidates.insert (std::move (candidate)); + } +} + +void +PathProbeType::process_enum_item_for_candiates (const TyTy::ADTType *adt) +{ + if (specific_trait_id != UNKNOWN_DEFID) + return; + + TyTy::VariantDef *v; + if (!adt->lookup_variant (search.as_string (), &v)) + return; + + PathProbeCandidate::EnumItemCandidate enum_item_candidate{adt, v}; + PathProbeCandidate candidate{PathProbeCandidate::CandidateType::ENUM_VARIANT, + receiver->clone (), + mappings->lookup_location (adt->get_ty_ref ()), + enum_item_candidate}; + candidates.insert (std::move (candidate)); +} + +void +PathProbeType::process_impl_items_for_candidates () +{ + mappings->iterate_impl_items ( + [&] (HirId id, HIR::ImplItem *item, HIR::ImplBlock *impl) mutable -> bool { + process_impl_item_candidate (id, item, impl); + return true; + }); +} + void PathProbeType::process_impl_item_candidate (HirId id, HIR::ImplItem *item, HIR::ImplBlock *impl) @@ -42,5 +200,191 @@ PathProbeType::process_impl_item_candidate (HirId id, HIR::ImplItem *item, item->accept_vis (*this); } +void +PathProbeType::process_associated_trait_for_candidates ( + const TraitReference *trait_ref, HIR::ImplBlock *impl, + bool ignore_mandatory_trait_items) +{ + const TraitItemReference *trait_item_ref = nullptr; + if (!trait_ref->lookup_trait_item (search.as_string (), &trait_item_ref)) + return; + + bool trait_item_needs_implementation = !trait_item_ref->is_optional (); + if (ignore_mandatory_trait_items && trait_item_needs_implementation) + return; + + PathProbeCandidate::CandidateType candidate_type; + switch (trait_item_ref->get_trait_item_type ()) + { + case TraitItemReference::TraitItemType::FN: + candidate_type = PathProbeCandidate::CandidateType::TRAIT_FUNC; + break; + case TraitItemReference::TraitItemType::CONST: + candidate_type = PathProbeCandidate::CandidateType::TRAIT_ITEM_CONST; + break; + case TraitItemReference::TraitItemType::TYPE: + candidate_type = PathProbeCandidate::CandidateType::TRAIT_TYPE_ALIAS; + break; + + case TraitItemReference::TraitItemType::ERROR: + default: + gcc_unreachable (); + break; + } + + TyTy::BaseType *trait_item_tyty = trait_item_ref->get_tyty (); + + // we can substitute the Self with the receiver here + if (trait_item_tyty->get_kind () == TyTy::TypeKind::FNDEF) + { + TyTy::FnType *fn = static_cast (trait_item_tyty); + TyTy::SubstitutionParamMapping *param = nullptr; + for (auto ¶m_mapping : fn->get_substs ()) + { + const HIR::TypeParam &type_param = param_mapping.get_generic_param (); + if (type_param.get_type_representation ().compare ("Self") == 0) + { + param = ¶m_mapping; + break; + } + } + rust_assert (param != nullptr); + + std::vector mappings; + mappings.push_back (TyTy::SubstitutionArg (param, receiver->clone ())); + + Location locus; // FIXME + TyTy::SubstitutionArgumentMappings args (std::move (mappings), {}, locus); + trait_item_tyty = SubstMapperInternal::Resolve (trait_item_tyty, args); + } + + PathProbeCandidate::TraitItemCandidate trait_item_candidate{trait_ref, + trait_item_ref, + impl}; + + PathProbeCandidate candidate{candidate_type, trait_item_tyty, + trait_item_ref->get_locus (), + trait_item_candidate}; + candidates.insert (std::move (candidate)); +} + +void +PathProbeType::process_predicate_for_candidates ( + const TyTy::TypeBoundPredicate &predicate, bool ignore_mandatory_trait_items) +{ + const TraitReference *trait_ref = predicate.get (); + + TyTy::TypeBoundPredicateItem item + = predicate.lookup_associated_item (search.as_string ()); + if (item.is_error ()) + return; + + if (ignore_mandatory_trait_items && item.needs_implementation ()) + return; + + const TraitItemReference *trait_item_ref = item.get_raw_item (); + PathProbeCandidate::CandidateType candidate_type; + switch (trait_item_ref->get_trait_item_type ()) + { + case TraitItemReference::TraitItemType::FN: + candidate_type = PathProbeCandidate::CandidateType::TRAIT_FUNC; + break; + case TraitItemReference::TraitItemType::CONST: + candidate_type = PathProbeCandidate::CandidateType::TRAIT_ITEM_CONST; + break; + case TraitItemReference::TraitItemType::TYPE: + candidate_type = PathProbeCandidate::CandidateType::TRAIT_TYPE_ALIAS; + break; + + case TraitItemReference::TraitItemType::ERROR: + default: + gcc_unreachable (); + break; + } + + TyTy::BaseType *trait_item_tyty = item.get_tyty_for_receiver (receiver); + PathProbeCandidate::TraitItemCandidate trait_item_candidate{trait_ref, + trait_item_ref, + nullptr}; + PathProbeCandidate candidate{candidate_type, trait_item_tyty, + trait_item_ref->get_locus (), + trait_item_candidate}; + candidates.insert (std::move (candidate)); +} + +std::vector> +PathProbeType::union_bounds ( + const std::vector> a, + const std::vector> b) + const +{ + std::map> mapper; + for (auto &ref : a) + { + mapper.insert ({ref.first->get_mappings ().get_defid (), ref}); + } + for (auto &ref : b) + { + mapper.insert ({ref.first->get_mappings ().get_defid (), ref}); + } + + std::vector> union_set; + for (auto it = mapper.begin (); it != mapper.end (); it++) + { + union_set.push_back ({it->second.first, it->second.second}); + } + return union_set; +} + +bool +PathProbeType::is_reciever_generic () const +{ + const TyTy::BaseType *root = receiver->get_root (); + bool receiver_is_type_param = root->get_kind () == TyTy::TypeKind::PARAM; + bool receiver_is_dyn = root->get_kind () == TyTy::TypeKind::DYNAMIC; + return receiver_is_type_param || receiver_is_dyn; +} + +// PathProbImplTrait + +PathProbeImplTrait::PathProbeImplTrait (const TyTy::BaseType *receiver, + const HIR::PathIdentSegment &query, + const TraitReference *trait_reference) + : PathProbeType (receiver, query, UNKNOWN_DEFID), + trait_reference (trait_reference) +{} + +std::set +PathProbeImplTrait::Probe (const TyTy::BaseType *receiver, + const HIR::PathIdentSegment &segment_name, + const TraitReference *trait_reference) +{ + PathProbeImplTrait probe (receiver, segment_name, trait_reference); + // iterate all impls for this trait and receiver + // then search for possible candidates using base class behaviours + probe.process_trait_impl_items_for_candidates (); + return probe.candidates; +} + +void +PathProbeImplTrait::process_trait_impl_items_for_candidates () +{ + mappings->iterate_impl_items ( + [&] (HirId id, HIR::ImplItem *item, HIR::ImplBlock *impl) mutable -> bool { + // just need to check if this is an impl block for this trait the next + // function checks the receiver + if (!impl->has_trait_ref ()) + return true; + + TraitReference *resolved + = TraitResolver::Lookup (*(impl->get_trait_ref ().get ())); + if (!trait_reference->is_equal (*resolved)) + return true; + + process_impl_item_candidate (id, item, impl); + return true; + }); +} + } // namespace Resolver } // namespace Rust diff --git a/gcc/rust/typecheck/rust-hir-path-probe.h b/gcc/rust/typecheck/rust-hir-path-probe.h index bb8698ce0e1..783282a0dc9 100644 --- a/gcc/rust/typecheck/rust-hir-path-probe.h +++ b/gcc/rust/typecheck/rust-hir-path-probe.h @@ -152,7 +152,7 @@ struct PathProbeCandidate return UNKNOWN_DEFID; } - bool operator< (const PathProbeCandidate &c) const + bool operator<(const PathProbeCandidate &c) const { return get_defid () < c.get_defid (); } @@ -165,144 +165,16 @@ public: Probe (const TyTy::BaseType *receiver, const HIR::PathIdentSegment &segment_name, bool probe_impls, bool probe_bounds, bool ignore_mandatory_trait_items, - DefId specific_trait_id = UNKNOWN_DEFID) - { - PathProbeType probe (receiver, segment_name, specific_trait_id); - if (probe_impls) - { - if (receiver->get_kind () == TyTy::TypeKind::ADT) - { - const TyTy::ADTType *adt - = static_cast (receiver); - if (adt->is_enum ()) - probe.process_enum_item_for_candiates (adt); - } - - probe.process_impl_items_for_candidates (); - } + DefId specific_trait_id = UNKNOWN_DEFID); - if (!probe_bounds) - return probe.candidates; - - if (!probe.is_reciever_generic ()) - { - std::vector> probed_bounds - = TypeBoundsProbe::Probe (receiver); - for (auto &candidate : probed_bounds) - { - const TraitReference *trait_ref = candidate.first; - if (specific_trait_id != UNKNOWN_DEFID) - { - if (trait_ref->get_mappings ().get_defid () - != specific_trait_id) - continue; - } - - HIR::ImplBlock *impl = candidate.second; - probe.process_associated_trait_for_candidates ( - trait_ref, impl, ignore_mandatory_trait_items); - } - } - - for (const TyTy::TypeBoundPredicate &predicate : - receiver->get_specified_bounds ()) - { - const TraitReference *trait_ref = predicate.get (); - if (specific_trait_id != UNKNOWN_DEFID) - { - if (trait_ref->get_mappings ().get_defid () != specific_trait_id) - continue; - } - - probe.process_predicate_for_candidates (predicate, - ignore_mandatory_trait_items); - } - - return probe.candidates; - } - - void visit (HIR::TypeAlias &alias) override - { - Identifier name = alias.get_new_type_name (); - if (search.as_string ().compare (name) == 0) - { - HirId tyid = alias.get_mappings ().get_hirid (); - TyTy::BaseType *ty = nullptr; - bool ok = query_type (tyid, &ty); - rust_assert (ok); - - PathProbeCandidate::ImplItemCandidate impl_item_candidate{&alias, - current_impl}; - PathProbeCandidate candidate{ - PathProbeCandidate::CandidateType::IMPL_TYPE_ALIAS, ty, - alias.get_locus (), impl_item_candidate}; - candidates.insert (std::move (candidate)); - } - } - - void visit (HIR::ConstantItem &constant) override - { - Identifier name = constant.get_identifier (); - if (search.as_string ().compare (name) == 0) - { - HirId tyid = constant.get_mappings ().get_hirid (); - TyTy::BaseType *ty = nullptr; - bool ok = query_type (tyid, &ty); - rust_assert (ok); - - PathProbeCandidate::ImplItemCandidate impl_item_candidate{&constant, - current_impl}; - PathProbeCandidate candidate{ - PathProbeCandidate::CandidateType::IMPL_CONST, ty, - constant.get_locus (), impl_item_candidate}; - candidates.insert (std::move (candidate)); - } - } - - void visit (HIR::Function &function) override - { - Identifier name = function.get_function_name (); - if (search.as_string ().compare (name) == 0) - { - HirId tyid = function.get_mappings ().get_hirid (); - TyTy::BaseType *ty = nullptr; - bool ok = query_type (tyid, &ty); - rust_assert (ok); - - PathProbeCandidate::ImplItemCandidate impl_item_candidate{&function, - current_impl}; - PathProbeCandidate candidate{ - PathProbeCandidate::CandidateType::IMPL_FUNC, ty, - function.get_locus (), impl_item_candidate}; - candidates.insert (std::move (candidate)); - } - } + void visit (HIR::TypeAlias &alias) override; + void visit (HIR::ConstantItem &constant) override; + void visit (HIR::Function &function) override; protected: - void process_enum_item_for_candiates (const TyTy::ADTType *adt) - { - if (specific_trait_id != UNKNOWN_DEFID) - return; - - TyTy::VariantDef *v; - if (!adt->lookup_variant (search.as_string (), &v)) - return; - - PathProbeCandidate::EnumItemCandidate enum_item_candidate{adt, v}; - PathProbeCandidate candidate{ - PathProbeCandidate::CandidateType::ENUM_VARIANT, receiver->clone (), - mappings->lookup_location (adt->get_ty_ref ()), enum_item_candidate}; - candidates.insert (std::move (candidate)); - } + void process_enum_item_for_candiates (const TyTy::ADTType *adt); - void process_impl_items_for_candidates () - { - mappings->iterate_impl_items ([&] (HirId id, HIR::ImplItem *item, - HIR::ImplBlock *impl) mutable -> bool { - process_impl_item_candidate (id, item, impl); - return true; - }); - } + void process_impl_items_for_candidates (); void process_impl_item_candidate (HirId id, HIR::ImplItem *item, HIR::ImplBlock *impl); @@ -310,156 +182,24 @@ protected: void process_associated_trait_for_candidates (const TraitReference *trait_ref, HIR::ImplBlock *impl, - bool ignore_mandatory_trait_items) - { - const TraitItemReference *trait_item_ref = nullptr; - if (!trait_ref->lookup_trait_item (search.as_string (), &trait_item_ref)) - return; - - bool trait_item_needs_implementation = !trait_item_ref->is_optional (); - if (ignore_mandatory_trait_items && trait_item_needs_implementation) - return; - - PathProbeCandidate::CandidateType candidate_type; - switch (trait_item_ref->get_trait_item_type ()) - { - case TraitItemReference::TraitItemType::FN: - candidate_type = PathProbeCandidate::CandidateType::TRAIT_FUNC; - break; - case TraitItemReference::TraitItemType::CONST: - candidate_type = PathProbeCandidate::CandidateType::TRAIT_ITEM_CONST; - break; - case TraitItemReference::TraitItemType::TYPE: - candidate_type = PathProbeCandidate::CandidateType::TRAIT_TYPE_ALIAS; - break; - - case TraitItemReference::TraitItemType::ERROR: - default: - gcc_unreachable (); - break; - } - - TyTy::BaseType *trait_item_tyty = trait_item_ref->get_tyty (); - - // we can substitute the Self with the receiver here - if (trait_item_tyty->get_kind () == TyTy::TypeKind::FNDEF) - { - TyTy::FnType *fn = static_cast (trait_item_tyty); - TyTy::SubstitutionParamMapping *param = nullptr; - for (auto ¶m_mapping : fn->get_substs ()) - { - const HIR::TypeParam &type_param - = param_mapping.get_generic_param (); - if (type_param.get_type_representation ().compare ("Self") == 0) - { - param = ¶m_mapping; - break; - } - } - rust_assert (param != nullptr); - - std::vector mappings; - mappings.push_back (TyTy::SubstitutionArg (param, receiver->clone ())); - - Location locus; // FIXME - TyTy::SubstitutionArgumentMappings args (std::move (mappings), {}, - locus); - trait_item_tyty = SubstMapperInternal::Resolve (trait_item_tyty, args); - } - - PathProbeCandidate::TraitItemCandidate trait_item_candidate{trait_ref, - trait_item_ref, - impl}; - - PathProbeCandidate candidate{candidate_type, trait_item_tyty, - trait_item_ref->get_locus (), - trait_item_candidate}; - candidates.insert (std::move (candidate)); - } + bool ignore_mandatory_trait_items); void process_predicate_for_candidates (const TyTy::TypeBoundPredicate &predicate, - bool ignore_mandatory_trait_items) - { - const TraitReference *trait_ref = predicate.get (); - - TyTy::TypeBoundPredicateItem item - = predicate.lookup_associated_item (search.as_string ()); - if (item.is_error ()) - return; - - if (ignore_mandatory_trait_items && item.needs_implementation ()) - return; - - const TraitItemReference *trait_item_ref = item.get_raw_item (); - PathProbeCandidate::CandidateType candidate_type; - switch (trait_item_ref->get_trait_item_type ()) - { - case TraitItemReference::TraitItemType::FN: - candidate_type = PathProbeCandidate::CandidateType::TRAIT_FUNC; - break; - case TraitItemReference::TraitItemType::CONST: - candidate_type = PathProbeCandidate::CandidateType::TRAIT_ITEM_CONST; - break; - case TraitItemReference::TraitItemType::TYPE: - candidate_type = PathProbeCandidate::CandidateType::TRAIT_TYPE_ALIAS; - break; - - case TraitItemReference::TraitItemType::ERROR: - default: - gcc_unreachable (); - break; - } - - TyTy::BaseType *trait_item_tyty = item.get_tyty_for_receiver (receiver); - PathProbeCandidate::TraitItemCandidate trait_item_candidate{trait_ref, - trait_item_ref, - nullptr}; - PathProbeCandidate candidate{candidate_type, trait_item_tyty, - trait_item_ref->get_locus (), - trait_item_candidate}; - candidates.insert (std::move (candidate)); - } + bool ignore_mandatory_trait_items); protected: PathProbeType (const TyTy::BaseType *receiver, - const HIR::PathIdentSegment &query, DefId specific_trait_id) - : TypeCheckBase (), receiver (receiver), search (query), - current_impl (nullptr), specific_trait_id (specific_trait_id) - {} + const HIR::PathIdentSegment &query, DefId specific_trait_id); std::vector> union_bounds ( const std::vector> a, const std::vector> b) - const - { - std::map> mapper; - for (auto &ref : a) - { - mapper.insert ({ref.first->get_mappings ().get_defid (), ref}); - } - for (auto &ref : b) - { - mapper.insert ({ref.first->get_mappings ().get_defid (), ref}); - } - - std::vector> union_set; - for (auto it = mapper.begin (); it != mapper.end (); it++) - { - union_set.push_back ({it->second.first, it->second.second}); - } - return union_set; - } + const; - bool is_reciever_generic () const - { - const TyTy::BaseType *root = receiver->get_root (); - bool receiver_is_type_param = root->get_kind () == TyTy::TypeKind::PARAM; - bool receiver_is_dyn = root->get_kind () == TyTy::TypeKind::DYNAMIC; - return receiver_is_type_param || receiver_is_dyn; - } + bool is_reciever_generic () const; const TyTy::BaseType *receiver; const HIR::PathIdentSegment &search; @@ -489,24 +229,14 @@ public: static std::set Probe (const TyTy::BaseType *receiver, const HIR::PathIdentSegment &segment_name, - const TraitReference *trait_reference) - { - PathProbeImplTrait probe (receiver, segment_name, trait_reference); - // iterate all impls for this trait and receiver - // then search for possible candidates using base class behaviours - probe.process_trait_impl_items_for_candidates (); - return probe.candidates; - } + const TraitReference *trait_reference); private: - void process_trait_impl_items_for_candidates (); - PathProbeImplTrait (const TyTy::BaseType *receiver, const HIR::PathIdentSegment &query, - const TraitReference *trait_reference) - : PathProbeType (receiver, query, UNKNOWN_DEFID), - trait_reference (trait_reference) - {} + const TraitReference *trait_reference); + + void process_trait_impl_items_for_candidates (); const TraitReference *trait_reference; }; diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc index 85cad8e9c21..19f95ca4488 100644 --- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc +++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc @@ -594,27 +594,5 @@ TraitItemReference::is_object_safe () const return false; } -// rust-hir-path-probe.h - -void -PathProbeImplTrait::process_trait_impl_items_for_candidates () -{ - mappings->iterate_impl_items ( - [&] (HirId id, HIR::ImplItem *item, HIR::ImplBlock *impl) mutable -> bool { - // just need to check if this is an impl block for this trait the next - // function checks the receiver - if (!impl->has_trait_ref ()) - return true; - - TraitReference *resolved - = TraitResolver::Lookup (*(impl->get_trait_ref ().get ())); - if (!trait_reference->is_equal (*resolved)) - return true; - - process_impl_item_candidate (id, item, impl); - return true; - }); -} - } // namespace Resolver } // namespace Rust From patchwork Wed Apr 5 14:03: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: 79685 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp353789vqo; Wed, 5 Apr 2023 07:33:41 -0700 (PDT) X-Google-Smtp-Source: AKy350YLIWzxzsEdkXsXnDq9Pl0SSSrIorBqhf0Y+QUsOY9bhAgxizcgbLjCJcYvHFEbRFbB8XID X-Received: by 2002:a17:906:9bd1:b0:8b1:bab0:aa3d with SMTP id de17-20020a1709069bd100b008b1bab0aa3dmr3090043ejc.8.1680705221476; Wed, 05 Apr 2023 07:33:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705221; cv=none; d=google.com; s=arc-20160816; b=GOHyixJKd8gnaR1wMRL0gqDelBdPeeSbn7u3cFUumKGcXXhFAE8K/yy9nqEbzkY+UQ ZzgUF8I5Ianza3uGZ7pWqV112IuUIqTyGkwKhbpGOZuDlL6o6hZx+E3clGRZOgK0InxG cOrfnfL73izsgyTD7589x2j+nZhP28fiE0ZFsp8RVzY25z7K5ToEo/tTYaUAHp2t3cDk Ct8oPryFji012/SxhUQevgAz6yUdrSFqc4ZDCzwnfYuWIljDZ0iaWiZzAFW4TNAW7G7d 0kaeUCyXSgMs20kxkO9uTlqr9O4f9gMNXfBF7EmsyFwFCZfhTFT79L/GbVRPXr7kqCZr 3M9Q== 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=PnkP2UgVFA7Tq7DGt8tHOjPew0CkHxnAWM1bV1pNAwE=; b=Xjbucmgo/2tvFov8QCtLKrVYk50ZcP9jgteDbO4omUfqkvwkwQgnZHpdlknVEd0g5O v30qjB3n2lmINsTSKk/eJpaSpd4KcwHj6m7Dtf2b7a9xPf0ebTik3vjndtK6OlsHHFsF 5nRx3o0mhj895pz6LJwnOiINOb0DKGELFHpVyQDmZ8P1BRQTozyy93rymqpLzf3xJtIb aqCnwsXUxOsU2WK5q23+utQf9peXmcySH0R77aNXycmAcJAi1A84SyrZh8VcvQg0+Mcc tyA5xmkKbzfeHh+qarmh+o/EMOjBgu2Qv87vguRTRTIkOTFSak6HwyWQX8kRyY6/gvUQ xLYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=dicAOXYU; 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 lz11-20020a170906fb0b00b00933a8c2308dsi2794291ejb.255.2023.04.05.07.33.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:33:41 -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=dicAOXYU; 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 C7AFD388C5D5 for ; Wed, 5 Apr 2023 14:13:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 05D5E385020E for ; Wed, 5 Apr 2023 14:05:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 05D5E385020E 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-x331.google.com with SMTP id i5-20020a05600c354500b003edd24054e0so23810219wmq.4 for ; Wed, 05 Apr 2023 07:05:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703558; 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=PnkP2UgVFA7Tq7DGt8tHOjPew0CkHxnAWM1bV1pNAwE=; b=dicAOXYU2+9EM19EQxFpb7wKQ2UnHY3+rMjPIH3JyR5rk9HQnUC4tNyM2cXliz8il6 iRrgNk01iIOOsrPjDeDKpQxg6lQ7JHeCDIo5+99WCLFq9ZqSyWt3aejKXhHElIHKAKcn rpIlHpflbiQLErxPcsPC0+gguMCcOt+DDrWU3l5aD8THediSeLKwoTSug2fwwt4Aqfa8 Nf1lEOOROs270xbwzq0UWrEGmShDwwgHkfx79rrzMjGzLsP7cKZQSouaYdnplUwhRsYd kPzOJR16rW+5rCMBlus349Yn8O1lLz5BiP/1EQ2Ywxk1Y7qrHcd9HC7WFhIoneL/coZ/ TCjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703558; 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=PnkP2UgVFA7Tq7DGt8tHOjPew0CkHxnAWM1bV1pNAwE=; b=nuUFt1NTbVqpH68DawQrTUZVNK184fkrpRV3xBlgADitnOVrtzY7yHT4ticGikV8R+ 1MPd7OuN9TEYd9nJ4LU0ClcTHfC8ETFLBqtqetXYAuiER5ysoLb9nEsaenCBNpuwokE0 5O545JBgb7ghpAgPmXocLQ+7hiNRnyMQhWOrSqA5pj49tIG+fdUy4E3BBenPcFabiOIj wZLFRr/DENb5Gj5YsGfDNNLZmehyR0Ipe2dUVffWGdt7iUH0l3TOHKqz6Ab0X9Fgcrc1 yBqNuEbGFCkXzAEGOye5Bz+zAHP816lUl4f8Jg8A5koVLtK0V9R6y1iyeqMeD7Sk6KWF CMCw== X-Gm-Message-State: AAQBX9c3wvOvZBATK+Xuv513i1+/B2pP2PA4IwZaMlmMkQvEIQFb1ZMI xs1N3N7wLLSy2XHhhxMMyFfCrX6CPtki4Q14lg== X-Received: by 2002:a1c:7406:0:b0:3ed:ff92:dd2a with SMTP id p6-20020a1c7406000000b003edff92dd2amr4937490wmc.12.1680703558306; Wed, 05 Apr 2023 07:05:58 -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.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:58 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 42/88] gccrs: Refactor PathProbeType code into CC file Date: Wed, 5 Apr 2023 16:03:26 +0200 Message-Id: <20230405140411.3016563-43-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.6 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?1762347158125780756?= X-GMAIL-MSGID: =?utf-8?q?1762347158125780756?= From: Philip Herron Signed-off-by: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-hir-path-probe.cc (PathProbeCandidate::Candidate::Candidate): refactor (PathProbeCandidate::PathProbeCandidate): likewise (PathProbeCandidate::as_string): likewise (PathProbeCandidate::is_enum_candidate): likewise (PathProbeCandidate::is_impl_candidate): likewise (PathProbeCandidate::is_trait_candidate): likewise (PathProbeCandidate::is_full_trait_item_candidate): likewise (PathProbeCandidate::get_error): likewise (PathProbeCandidate::is_error): likewise (PathProbeCandidate::get_defid): likewise (PathProbeCandidate::operator<): likewise * typecheck/rust-hir-path-probe.h (struct PathProbeCandidate): likewise --- gcc/rust/typecheck/rust-hir-path-probe.cc | 109 ++++++++++++++++++++++ gcc/rust/typecheck/rust-hir-path-probe.h | 82 +++------------- 2 files changed, 124 insertions(+), 67 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-path-probe.cc b/gcc/rust/typecheck/rust-hir-path-probe.cc index 06d8920d2eb..be89ceb8645 100644 --- a/gcc/rust/typecheck/rust-hir-path-probe.cc +++ b/gcc/rust/typecheck/rust-hir-path-probe.cc @@ -23,6 +23,115 @@ namespace Rust { namespace Resolver { +// PathProbeCandidate + +PathProbeCandidate::Candidate::Candidate (EnumItemCandidate enum_field) + : enum_field (enum_field) +{} + +PathProbeCandidate::Candidate::Candidate (ImplItemCandidate impl) : impl (impl) +{} + +PathProbeCandidate::Candidate::Candidate (TraitItemCandidate trait) + : trait (trait) +{} + +PathProbeCandidate::PathProbeCandidate (CandidateType type, TyTy::BaseType *ty, + Location locus, + EnumItemCandidate enum_field) + : type (type), ty (ty), locus (locus), item (enum_field) +{} + +PathProbeCandidate::PathProbeCandidate (CandidateType type, TyTy::BaseType *ty, + Location locus, ImplItemCandidate impl) + : type (type), ty (ty), locus (locus), item (impl) +{} + +PathProbeCandidate::PathProbeCandidate (CandidateType type, TyTy::BaseType *ty, + Location locus, + TraitItemCandidate trait) + : type (type), ty (ty), locus (locus), item (trait) +{} + +std::string +PathProbeCandidate::as_string () const +{ + return "PathProbe candidate TODO - as_string"; +} + +bool +PathProbeCandidate::is_enum_candidate () const +{ + return type == ENUM_VARIANT; +} + +bool +PathProbeCandidate::is_impl_candidate () const +{ + return type == IMPL_CONST || type == IMPL_TYPE_ALIAS || type == IMPL_FUNC; +} + +bool +PathProbeCandidate::is_trait_candidate () const +{ + return type == TRAIT_ITEM_CONST || type == TRAIT_TYPE_ALIAS + || type == TRAIT_FUNC; +} + +bool +PathProbeCandidate::is_full_trait_item_candidate () const +{ + return is_trait_candidate () && item.trait.impl == nullptr; +} + +PathProbeCandidate +PathProbeCandidate::get_error () +{ + return PathProbeCandidate (ERROR, nullptr, Location (), + ImplItemCandidate{nullptr, nullptr}); +} + +bool +PathProbeCandidate::is_error () const +{ + return type == ERROR; +} + +DefId +PathProbeCandidate::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 +PathProbeCandidate::operator< (const PathProbeCandidate &c) const +{ + return get_defid () < c.get_defid (); +} + // PathProbeType PathProbeType::PathProbeType (const TyTy::BaseType *receiver, diff --git a/gcc/rust/typecheck/rust-hir-path-probe.h b/gcc/rust/typecheck/rust-hir-path-probe.h index 783282a0dc9..dd511ac4184 100644 --- a/gcc/rust/typecheck/rust-hir-path-probe.h +++ b/gcc/rust/typecheck/rust-hir-path-probe.h @@ -73,89 +73,37 @@ struct PathProbeCandidate ImplItemCandidate impl; TraitItemCandidate trait; - Candidate (EnumItemCandidate enum_field) : enum_field (enum_field) {} - Candidate (ImplItemCandidate impl) : impl (impl) {} - Candidate (TraitItemCandidate trait) : trait (trait) {} + Candidate (EnumItemCandidate enum_field); + Candidate (ImplItemCandidate impl); + Candidate (TraitItemCandidate trait); } item; PathProbeCandidate (CandidateType type, TyTy::BaseType *ty, Location locus, - EnumItemCandidate enum_field) - : type (type), ty (ty), locus (locus), item (enum_field) - {} + EnumItemCandidate enum_field); PathProbeCandidate (CandidateType type, TyTy::BaseType *ty, Location locus, - ImplItemCandidate impl) - : type (type), ty (ty), locus (locus), item (impl) - {} + ImplItemCandidate impl); PathProbeCandidate (CandidateType type, TyTy::BaseType *ty, Location locus, - TraitItemCandidate trait) - : type (type), ty (ty), locus (locus), item (trait) - {} + TraitItemCandidate trait); - std::string as_string () const - { - return "PathProbe candidate TODO - as_string"; - } + std::string as_string () const; - bool is_enum_candidate () const { return type == ENUM_VARIANT; } + bool is_enum_candidate () const; - bool is_impl_candidate () const - { - return type == IMPL_CONST || type == IMPL_TYPE_ALIAS || type == IMPL_FUNC; - } + bool is_impl_candidate () const; - bool is_trait_candidate () const - { - return type == TRAIT_ITEM_CONST || type == TRAIT_TYPE_ALIAS - || type == TRAIT_FUNC; - } + bool is_trait_candidate () const; - bool is_full_trait_item_candidate () const - { - return is_trait_candidate () && item.trait.impl == nullptr; - } + bool is_full_trait_item_candidate () const; - static PathProbeCandidate get_error () - { - return PathProbeCandidate (ERROR, nullptr, Location (), - ImplItemCandidate{nullptr, nullptr}); - } + static PathProbeCandidate get_error (); - bool is_error () const { return type == ERROR; } + bool is_error () const; - 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; - } + DefId get_defid () const; - bool operator<(const PathProbeCandidate &c) const - { - return get_defid () < c.get_defid (); - } + bool operator< (const PathProbeCandidate &c) const; }; class PathProbeType : public TypeCheckBase, public HIR::HIRImplVisitor From patchwork Wed Apr 5 14:03: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: 79701 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp358473vqo; Wed, 5 Apr 2023 07:40:26 -0700 (PDT) X-Google-Smtp-Source: AKy350a1HiLoCcWLoliDFZNpuWBxEW4vFR3a+hN+quUM3Xoo6qwCQjfpdBkkvklmqXD1bPh2RjAF X-Received: by 2002:a05:6402:10c3:b0:4ac:bde4:ff14 with SMTP id p3-20020a05640210c300b004acbde4ff14mr1880592edu.42.1680705626319; Wed, 05 Apr 2023 07:40:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705626; cv=none; d=google.com; s=arc-20160816; b=xu0Ecrex3FMP1msxumg8uHpmwCWy/RL21rCpJI3ksX+H+hRGOYtzuJRXZu2bhFNuDs yF2BFPG6T+HI3IhzM/d1TcFSbRS2pMatFXPFbvjUKE7xO5Ukhs9iSMPKKfvAOCy35SDS bnVnDGESg5byVwYRZUnr8o/mGSysisWd+bZ8omLyPaf4QN0vawsWFYlwsbT1QYDMY3Wi 0a0Bihyz8tzYTDiEVrPpo0AprD1Q9B6n7VuNgoUUc0sWJeeXAWnXbZOHrFN91ODu6pGA sMRAcQyvt+s1DLyK9FWBTrk8eTWklHqHF0dYKRQfWfSJzpAbITXsDxiY2zyIzWWMdtHe zY1w== 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=64E1C2AfWq3zwFBLOxWZQzWW/3rvPpOdDm+MiYWclwA=; b=lqVHxWo1pOAaROS5VbuvwDOX5rwPJD1T5ict9m2h29KkdXvxXCavlWFYvd3rRnPPKC rh60SHr9h0UrexbAtl5doPm9EhMgGV3+QAcL/SxL2QHeQkZyEz5XXdyoOFSCWDbbtsaa O8EM/lf9p4yArh+AnT11aBGfamYOSI46p1dVjW8kubTYd9dVo4kMpSQ1yTsKvxpBoNBK RzwXQFB2CUzLM7TAG/hPjTfyhLeZzgIYiyP04Grblt+sNL0XHyBnPy54khoR4P3SeeEx WQ/QI5qCq40SKrCbP9kJltzSq+8uqVb/xyFosYtVxoHKa1aq8onNV+mloPXx0S9TH2kz 5GbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Pt2oDN5A; 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 i19-20020a50fc13000000b004fd23c8cf1esi1236596edr.52.2023.04.05.07.40.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:40:26 -0700 (PDT) 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=Pt2oDN5A; 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 CAE7D39DEC18 for ; Wed, 5 Apr 2023 14:14:48 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 963F03852744 for ; Wed, 5 Apr 2023 14:06:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 963F03852744 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-x329.google.com with SMTP id l10-20020a05600c1d0a00b003f04bd3691eso7160778wms.5 for ; Wed, 05 Apr 2023 07:06:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703560; 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=64E1C2AfWq3zwFBLOxWZQzWW/3rvPpOdDm+MiYWclwA=; b=Pt2oDN5AtjkqSfXmMS8ppYEfj6ChYOjMk9SIMtHtwH9EUgwTUOv1po501hwWQ1TGzc 6a6M0LqEhiAFLhY+LV9utegQfbj9eaRGYOL8doVTglmkSR5QSXT95+7YFEpkpCqxj37u Ku2Zt2roTSxG08OHlEtNFe+k3C6Ub3ZQq6EsXAuZYlPDFlbeKrvHpGZdmJax3NNw8Jlg SuZu+Z3lN15jcpV1MgaPMLuFrfE3cN/zeg2cg7Fla/Zn8EtjFvDUyThtGpS/yDdqlQri HLjLx8TYCGeY53DVPhxQyVNn9egz0VASf+0/f6bvVo4kKzQmrQEoVIc8e7SK+aPICBvb N2tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703560; 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=64E1C2AfWq3zwFBLOxWZQzWW/3rvPpOdDm+MiYWclwA=; b=PX6Fg4OnZ8oY2Q957e19KFulvE7sVACa7Am79vaqJUqG/vFDAsBROUY4SgHdZcZJ43 SeJwlTw058NyQ4VSIre00KMZ6GxEjdJCPgOZojPtNJks26bKFxNzK8HqPwIUM1cV03Mc CItediV7eNq34DZ6SHPPJL2f+vUS9O+jgJhH2b2EKoIbujtc8bRIJE8BmIq6PMB6Sayv NURFCSyX7pwUtFUyymrBjOfq82yE783Ao2eQmchsCFVxVOrtnEgmhAjpTuaY1WwZJDHA Ew/2G2mtt6rPkvdKFI2wf2y6Em1t/BO9PtLbPGPPsxxhgXirhseMHHEq/ovfQusGLubH mtaA== X-Gm-Message-State: AAQBX9fuLQglSVYSkfoHsKrhS23zZ1F3f1z6mI3Cgx0Rthmyhu/vLErS mEDvjSMtmMQlxLfMG4CqNBJfnkarHdtsr+iOEg== X-Received: by 2002:a7b:c852:0:b0:3eb:5ab3:b6d0 with SMTP id c18-20020a7bc852000000b003eb5ab3b6d0mr4627165wml.6.1680703559043; Wed, 05 Apr 2023 07:05:59 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:58 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 43/88] gccrs: Refactor all code out of the rust-tyty.h header Date: Wed, 5 Apr 2023 16:03:27 +0200 Message-Id: <20230405140411.3016563-44-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.6 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?1762347583133144782?= X-GMAIL-MSGID: =?utf-8?q?1762347583133144782?= From: Philip Herron Signed-off-by: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-hir-type-check.h: refactor * typecheck/rust-tyctx.cc (TypeCheckContext::iterate): refactor (TypeCheckContext::have_loop_context): likewise (TypeCheckContext::push_new_loop_context): likewise (TypeCheckContext::push_new_while_loop_context): likewise (TypeCheckContext::peek_loop_context): likewise (TypeCheckContext::pop_loop_context): likewise (TypeCheckContext::swap_head_loop_context): likewise (TypeCheckContext::insert_trait_reference): likewise (TypeCheckContext::lookup_trait_reference): likewise (TypeCheckContext::insert_receiver): likewise (TypeCheckContext::lookup_receiver): likewise (TypeCheckContext::insert_associated_type_mapping): likewise (TypeCheckContext::clear_associated_type_mapping): likewise (TypeCheckContext::lookup_associated_type_mapping): likewise (TypeCheckContext::insert_variant_definition): likewise (TypeCheckContext::lookup_variant_definition): likewise (TypeCheckContext::insert_operator_overload): likewise (TypeCheckContext::lookup_operator_overload): likewise (TypeCheckContext::insert_unconstrained_check_marker): likewise (TypeCheckContext::have_checked_for_unconstrained): likewise (TypeCheckContext::insert_resolved_predicate): likewise (TypeCheckContext::lookup_predicate): likewise (TypeCheckContext::insert_query): likewise (TypeCheckContext::query_completed): likewise (TypeCheckContext::query_in_progress): likewise (TypeCheckContext::insert_trait_query): likewise (TypeCheckContext::trait_query_completed): likewise (TypeCheckContext::trait_query_in_progress): likewise (TypeCheckContextItem::Item::Item): likewise (TypeCheckContextItem::TypeCheckContextItem): likewise (TypeCheckContextItem::get_item): likewise (TypeCheckContextItem::get_impl_item): likewise (TypeCheckContextItem::get_trait_item): likewise (TypeCheckContextItem::get_type): likewise * typecheck/rust-tyty.cc (StructFieldType::StructFieldType): likewise (StructFieldType::get_ref): likewise (StructFieldType::get_name): likewise (StructFieldType::get_field_type): likewise (StructFieldType::set_field_type): likewise (StructFieldType::is_concrete): likewise (StructFieldType::debug): likewise (StructFieldType::get_locus): likewise (VariantDef::variant_type_string): likewise (VariantDef::VariantDef): likewise (VariantDef::operator=): likewise (VariantDef::get_error_node): likewise (VariantDef::is_error): likewise (VariantDef::get_id): likewise (VariantDef::get_defid): likewise (VariantDef::get_variant_type): likewise (VariantDef::is_data_variant): likewise (VariantDef::is_dataless_variant): likewise (VariantDef::get_identifier): likewise (VariantDef::num_fields): likewise (VariantDef::get_field_at_index): likewise (VariantDef::get_fields): likewise (VariantDef::lookup_field): likewise (VariantDef::get_discriminant): likewise (VariantDef::as_string): likewise (VariantDef::is_equal): likewise (VariantDef::clone): likewise (VariantDef::monomorphized_clone): likewise (VariantDef::get_ident): likewise (TupleType::TupleType): likewise (TupleType::get_unit_type): likewise (TupleType::is_unit): likewise (TupleType::num_fields): likewise (TupleType::is_concrete): likewise (TupleType::get_fields): likewise (BoolType::BoolType): likewise (BoolType::get_name): likewise (BoolType::is_concrete): likewise (IntType::IntType): likewise (IntType::get_name): likewise (IntType::get_int_kind): likewise (IntType::is_concrete): likewise (UintType::UintType): likewise (UintType::get_name): likewise (UintType::get_uint_kind): likewise (UintType::is_concrete): likewise (FloatType::FloatType): likewise (FloatType::get_name): likewise (FloatType::get_float_kind): likewise (FloatType::is_concrete): likewise (USizeType::USizeType): likewise (USizeType::get_name): likewise (USizeType::is_concrete): likewise (ISizeType::ISizeType): likewise (ISizeType::get_name): likewise (ISizeType::is_concrete): likewise (CharType::CharType): likewise (CharType::is_concrete): likewise (CharType::get_name): likewise (ReferenceType::ReferenceType): likewise (ReferenceType::is_concrete): likewise (ReferenceType::mutability): likewise (ReferenceType::is_mutable): likewise (ReferenceType::is_dyn_object): likewise (ReferenceType::is_dyn_slice_type): likewise (ReferenceType::is_dyn_str_type): likewise (PointerType::PointerType): likewise (PointerType::is_concrete): likewise (PointerType::mutability): likewise (PointerType::is_mutable): likewise (PointerType::is_const): likewise (PointerType::is_dyn_object): likewise (PointerType::is_dyn_slice_type): likewise (PointerType::is_dyn_str_type): likewise (ParamType::ParamType): likewise (ParamType::get_generic_param): likewise (ParamType::can_resolve): likewise (ParamType::is_concrete): likewise (StrType::StrType): likewise (StrType::get_name): likewise (StrType::is_concrete): likewise (NeverType::NeverType): likewise (NeverType::get_name): likewise (NeverType::is_unit): likewise (NeverType::is_concrete): likewise (PlaceholderType::PlaceholderType): likewise (PlaceholderType::get_name): likewise (PlaceholderType::is_unit): likewise (PlaceholderType::get_symbol): likewise (PlaceholderType::is_concrete): likewise (ProjectionType::is_unit): likewise (ProjectionType::get_name): likewise (ProjectionType::needs_generic_substitutions): likewise (ProjectionType::supports_substitutions): likewise (ProjectionType::has_subsititions_defined): likewise (ProjectionType::get): likewise (ProjectionType::is_concrete): likewise (DynamicObjectType::is_concrete): likewise * typecheck/rust-tyty.h: likewise --- gcc/rust/typecheck/rust-hir-type-check.h | 332 ++------ gcc/rust/typecheck/rust-tyctx.cc | 379 +++++++++ gcc/rust/typecheck/rust-tyty.cc | 960 ++++++++++++++++++++++- gcc/rust/typecheck/rust-tyty.h | 667 +++------------- 4 files changed, 1508 insertions(+), 830 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-type-check.h b/gcc/rust/typecheck/rust-hir-type-check.h index adec2f91961..d1eb750a621 100644 --- a/gcc/rust/typecheck/rust-hir-type-check.h +++ b/gcc/rust/typecheck/rust-hir-type-check.h @@ -38,37 +38,17 @@ public: TRAIT_ITEM, }; - TypeCheckContextItem (HIR::Function *item) - : type (ItemType::ITEM), item (item) - {} + TypeCheckContextItem (HIR::Function *item); + TypeCheckContextItem (HIR::ImplBlock *impl_block, HIR::Function *item); + TypeCheckContextItem (HIR::TraitItemFunc *trait_item); - TypeCheckContextItem (HIR::ImplBlock *impl_block, HIR::Function *item) - : type (ItemType::IMPL_ITEM), item (impl_block, item) - {} + ItemType get_type () const; - TypeCheckContextItem (HIR::TraitItemFunc *trait_item) - : type (ItemType::TRAIT_ITEM), item (trait_item) - {} + HIR::Function *get_item (); - ItemType get_type () const { return type; } + std::pair &get_impl_item (); - HIR::Function *get_item () - { - rust_assert (get_type () == ItemType::ITEM); - return item.item; - } - - std::pair &get_impl_item () - { - rust_assert (get_type () == ItemType::IMPL_ITEM); - return item.impl_item; - }; - - HIR::TraitItemFunc *get_trait_item () - { - rust_assert (get_type () == ItemType::TRAIT_ITEM); - return item.trait_item; - } + HIR::TraitItemFunc *get_trait_item (); TyTy::FnType *get_context_type (); @@ -79,13 +59,9 @@ private: std::pair impl_item; HIR::TraitItemFunc *trait_item; - Item (HIR::Function *item) : item (item) {} - - Item (HIR::ImplBlock *impl_block, HIR::Function *item) - : impl_item ({impl_block, item}) - {} - - Item (HIR::TraitItemFunc *trait_item) : trait_item (trait_item) {} + Item (HIR::Function *item); + Item (HIR::ImplBlock *impl_block, HIR::Function *item); + Item (HIR::TraitItemFunc *trait_item); }; ItemType type; @@ -118,283 +94,71 @@ public: void push_return_type (TypeCheckContextItem item, TyTy::BaseType *return_type); void pop_return_type (); + void iterate (std::function cb); - void iterate (std::function cb) - { - for (auto it = resolved.begin (); it != resolved.end (); it++) - { - if (!cb (it->first, it->second)) - return; - } - } - - bool have_loop_context () const { return !loop_type_stack.empty (); } - - void push_new_loop_context (HirId id, Location locus) - { - TyTy::BaseType *infer_var - = new TyTy::InferType (id, TyTy::InferType::InferTypeKind::GENERAL, - locus); - loop_type_stack.push_back (infer_var); - } - - void push_new_while_loop_context (HirId id) - { - TyTy::BaseType *infer_var = new TyTy::ErrorType (id); - loop_type_stack.push_back (infer_var); - } - - TyTy::BaseType *peek_loop_context () { return loop_type_stack.back (); } - - TyTy::BaseType *pop_loop_context () - { - auto back = peek_loop_context (); - loop_type_stack.pop_back (); - return back; - } - - void swap_head_loop_context (TyTy::BaseType *val) - { - loop_type_stack.pop_back (); - loop_type_stack.push_back (val); - } - - void insert_trait_reference (DefId id, TraitReference &&ref) - { - rust_assert (trait_context.find (id) == trait_context.end ()); - trait_context.emplace (id, std::move (ref)); - } - - bool lookup_trait_reference (DefId id, TraitReference **ref) - { - auto it = trait_context.find (id); - if (it == trait_context.end ()) - return false; + bool have_loop_context () const; + void push_new_loop_context (HirId id, Location locus); + void push_new_while_loop_context (HirId id); + TyTy::BaseType *peek_loop_context (); + TyTy::BaseType *pop_loop_context (); - *ref = &it->second; - return true; - } - - void insert_receiver (HirId id, TyTy::BaseType *t) - { - receiver_context[id] = t; - } + void swap_head_loop_context (TyTy::BaseType *val); - bool lookup_receiver (HirId id, TyTy::BaseType **ref) - { - auto it = receiver_context.find (id); - if (it == receiver_context.end ()) - return false; + void insert_trait_reference (DefId id, TraitReference &&ref); + bool lookup_trait_reference (DefId id, TraitReference **ref); - *ref = it->second; - return true; - } + void insert_receiver (HirId id, TyTy::BaseType *t); + bool lookup_receiver (HirId id, TyTy::BaseType **ref); - void insert_associated_trait_impl (HirId id, AssociatedImplTrait &&associated) - { - rust_assert (associated_impl_traits.find (id) - == associated_impl_traits.end ()); - associated_impl_traits.emplace (id, std::move (associated)); - } + void insert_associated_trait_impl (HirId id, + AssociatedImplTrait &&associated); + bool lookup_associated_trait_impl (HirId id, + AssociatedImplTrait **associated); - bool lookup_associated_trait_impl (HirId id, AssociatedImplTrait **associated) - { - auto it = associated_impl_traits.find (id); - if (it == associated_impl_traits.end ()) - return false; - - *associated = &it->second; - return true; - } - - void insert_associated_type_mapping (HirId id, HirId mapping) - { - associated_type_mappings[id] = mapping; - } - - void clear_associated_type_mapping (HirId id) - { - auto it = associated_type_mappings.find (id); - if (it != associated_type_mappings.end ()) - associated_type_mappings.erase (it); - } + void insert_associated_type_mapping (HirId id, HirId mapping); + void clear_associated_type_mapping (HirId id); // lookup any associated type mappings, the out parameter of mapping is // allowed to be nullptr which allows this interface to do a simple does exist // check - bool lookup_associated_type_mapping (HirId id, HirId *mapping) - { - auto it = associated_type_mappings.find (id); - if (it == associated_type_mappings.end ()) - return false; - - if (mapping != nullptr) - *mapping = it->second; - - return true; - } + bool lookup_associated_type_mapping (HirId id, HirId *mapping); void insert_associated_impl_mapping (HirId trait_id, const TyTy::BaseType *impl_type, - HirId impl_id) - { - auto it = associated_traits_to_impls.find (trait_id); - if (it == associated_traits_to_impls.end ()) - { - associated_traits_to_impls[trait_id] = {}; - } - - associated_traits_to_impls[trait_id].push_back ({impl_type, impl_id}); - } - + HirId impl_id); bool lookup_associated_impl_mapping_for_self (HirId trait_id, const TyTy::BaseType *self, - HirId *mapping) - { - auto it = associated_traits_to_impls.find (trait_id); - if (it == associated_traits_to_impls.end ()) - return false; - - for (auto &item : it->second) - { - if (item.first->can_eq (self, false)) - { - *mapping = item.second; - return true; - } - } - return false; - } + HirId *mapping); void insert_autoderef_mappings (HirId id, - std::vector &&adjustments) - { - rust_assert (autoderef_mappings.find (id) == autoderef_mappings.end ()); - autoderef_mappings.emplace (id, std::move (adjustments)); - } - + std::vector &&adjustments); bool lookup_autoderef_mappings (HirId id, - std::vector **adjustments) - { - auto it = autoderef_mappings.find (id); - if (it == autoderef_mappings.end ()) - return false; - - *adjustments = &it->second; - return true; - } + std::vector **adjustments); void insert_cast_autoderef_mappings (HirId id, - std::vector &&adjustments) - { - rust_assert (cast_autoderef_mappings.find (id) - == cast_autoderef_mappings.end ()); - cast_autoderef_mappings.emplace (id, std::move (adjustments)); - } - + std::vector &&adjustments); bool lookup_cast_autoderef_mappings (HirId id, - std::vector **adjustments) - { - auto it = cast_autoderef_mappings.find (id); - if (it == cast_autoderef_mappings.end ()) - return false; + std::vector **adjustments); - *adjustments = &it->second; - return true; - } + void insert_variant_definition (HirId id, HirId variant); + bool lookup_variant_definition (HirId id, HirId *variant); - void insert_variant_definition (HirId id, HirId variant) - { - auto it = variants.find (id); - rust_assert (it == variants.end ()); + void insert_operator_overload (HirId id, TyTy::FnType *call_site); + bool lookup_operator_overload (HirId id, TyTy::FnType **call); - variants[id] = variant; - } + void insert_unconstrained_check_marker (HirId id, bool status); + bool have_checked_for_unconstrained (HirId id, bool *result); - bool lookup_variant_definition (HirId id, HirId *variant) - { - auto it = variants.find (id); - if (it == variants.end ()) - return false; + void insert_resolved_predicate (HirId id, TyTy::TypeBoundPredicate predicate); + bool lookup_predicate (HirId id, TyTy::TypeBoundPredicate *result); - *variant = it->second; - return true; - } - - void insert_operator_overload (HirId id, TyTy::FnType *call_site) - { - auto it = operator_overloads.find (id); - rust_assert (it == operator_overloads.end ()); - - operator_overloads[id] = call_site; - } - - bool lookup_operator_overload (HirId id, TyTy::FnType **call) - { - auto it = operator_overloads.find (id); - if (it == operator_overloads.end ()) - return false; - - *call = it->second; - return true; - } + void insert_query (HirId id); + void query_completed (HirId id); + bool query_in_progress (HirId id) const; - void insert_unconstrained_check_marker (HirId id, bool status) - { - unconstrained[id] = status; - } - - bool have_checked_for_unconstrained (HirId id, bool *result) - { - auto it = unconstrained.find (id); - bool found = it != unconstrained.end (); - if (!found) - return false; - - *result = it->second; - return true; - } - - void insert_resolved_predicate (HirId id, TyTy::TypeBoundPredicate predicate) - { - auto it = predicates.find (id); - rust_assert (it == predicates.end ()); - - predicates.insert ({id, predicate}); - } - - bool lookup_predicate (HirId id, TyTy::TypeBoundPredicate *result) - { - auto it = predicates.find (id); - bool found = it != predicates.end (); - if (!found) - return false; - - *result = it->second; - 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 (); - } - - 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 (); - } + void insert_trait_query (DefId id); + void trait_query_completed (DefId id); + bool trait_query_in_progress (DefId id) const; private: TypeCheckContext (); diff --git a/gcc/rust/typecheck/rust-tyctx.cc b/gcc/rust/typecheck/rust-tyctx.cc index 886842b0623..27ff96986dc 100644 --- a/gcc/rust/typecheck/rust-tyctx.cc +++ b/gcc/rust/typecheck/rust-tyctx.cc @@ -154,8 +154,387 @@ TypeCheckContext::peek_context () return return_type_stack.back ().first; } +void +TypeCheckContext::iterate (std::function cb) +{ + for (auto it = resolved.begin (); it != resolved.end (); it++) + { + if (!cb (it->first, it->second)) + return; + } +} + +bool +TypeCheckContext::have_loop_context () const +{ + return !loop_type_stack.empty (); +} + +void +TypeCheckContext::push_new_loop_context (HirId id, Location locus) +{ + TyTy::BaseType *infer_var + = new TyTy::InferType (id, TyTy::InferType::InferTypeKind::GENERAL, locus); + loop_type_stack.push_back (infer_var); +} + +void +TypeCheckContext::push_new_while_loop_context (HirId id) +{ + TyTy::BaseType *infer_var = new TyTy::ErrorType (id); + loop_type_stack.push_back (infer_var); +} + +TyTy::BaseType * +TypeCheckContext::peek_loop_context () +{ + return loop_type_stack.back (); +} + +TyTy::BaseType * +TypeCheckContext::pop_loop_context () +{ + auto back = peek_loop_context (); + loop_type_stack.pop_back (); + return back; +} + +void +TypeCheckContext::swap_head_loop_context (TyTy::BaseType *val) +{ + loop_type_stack.pop_back (); + loop_type_stack.push_back (val); +} + +void +TypeCheckContext::insert_trait_reference (DefId id, TraitReference &&ref) +{ + rust_assert (trait_context.find (id) == trait_context.end ()); + trait_context.emplace (id, std::move (ref)); +} + +bool +TypeCheckContext::lookup_trait_reference (DefId id, TraitReference **ref) +{ + auto it = trait_context.find (id); + if (it == trait_context.end ()) + return false; + + *ref = &it->second; + return true; +} + +void +TypeCheckContext::insert_receiver (HirId id, TyTy::BaseType *t) +{ + receiver_context[id] = t; +} + +bool +TypeCheckContext::lookup_receiver (HirId id, TyTy::BaseType **ref) +{ + auto it = receiver_context.find (id); + if (it == receiver_context.end ()) + return false; + + *ref = it->second; + return true; +} + +void +TypeCheckContext::insert_associated_trait_impl ( + HirId id, AssociatedImplTrait &&associated) +{ + rust_assert (associated_impl_traits.find (id) + == associated_impl_traits.end ()); + associated_impl_traits.emplace (id, std::move (associated)); +} + +bool +TypeCheckContext::lookup_associated_trait_impl ( + HirId id, AssociatedImplTrait **associated) +{ + auto it = associated_impl_traits.find (id); + if (it == associated_impl_traits.end ()) + return false; + + *associated = &it->second; + return true; +} + +void +TypeCheckContext::insert_associated_type_mapping (HirId id, HirId mapping) +{ + associated_type_mappings[id] = mapping; +} + +void +TypeCheckContext::clear_associated_type_mapping (HirId id) +{ + auto it = associated_type_mappings.find (id); + if (it != associated_type_mappings.end ()) + associated_type_mappings.erase (it); +} + +// lookup any associated type mappings, the out parameter of mapping is +// allowed to be nullptr which allows this interface to do a simple does exist +// check +bool +TypeCheckContext::lookup_associated_type_mapping (HirId id, HirId *mapping) +{ + auto it = associated_type_mappings.find (id); + if (it == associated_type_mappings.end ()) + return false; + + if (mapping != nullptr) + *mapping = it->second; + + return true; +} + +void +TypeCheckContext::insert_associated_impl_mapping ( + HirId trait_id, const TyTy::BaseType *impl_type, HirId impl_id) +{ + auto it = associated_traits_to_impls.find (trait_id); + if (it == associated_traits_to_impls.end ()) + { + associated_traits_to_impls[trait_id] = {}; + } + + associated_traits_to_impls[trait_id].push_back ({impl_type, impl_id}); +} + +bool +TypeCheckContext::lookup_associated_impl_mapping_for_self ( + HirId trait_id, const TyTy::BaseType *self, HirId *mapping) +{ + auto it = associated_traits_to_impls.find (trait_id); + if (it == associated_traits_to_impls.end ()) + return false; + + for (auto &item : it->second) + { + if (item.first->can_eq (self, false)) + { + *mapping = item.second; + return true; + } + } + return false; +} + +void +TypeCheckContext::insert_autoderef_mappings ( + HirId id, std::vector &&adjustments) +{ + rust_assert (autoderef_mappings.find (id) == autoderef_mappings.end ()); + autoderef_mappings.emplace (id, std::move (adjustments)); +} + +bool +TypeCheckContext::lookup_autoderef_mappings ( + HirId id, std::vector **adjustments) +{ + auto it = autoderef_mappings.find (id); + if (it == autoderef_mappings.end ()) + return false; + + *adjustments = &it->second; + return true; +} + +void +TypeCheckContext::insert_cast_autoderef_mappings ( + HirId id, std::vector &&adjustments) +{ + rust_assert (cast_autoderef_mappings.find (id) + == cast_autoderef_mappings.end ()); + cast_autoderef_mappings.emplace (id, std::move (adjustments)); +} + +bool +TypeCheckContext::lookup_cast_autoderef_mappings ( + HirId id, std::vector **adjustments) +{ + auto it = cast_autoderef_mappings.find (id); + if (it == cast_autoderef_mappings.end ()) + return false; + + *adjustments = &it->second; + return true; +} + +void +TypeCheckContext::insert_variant_definition (HirId id, HirId variant) +{ + auto it = variants.find (id); + rust_assert (it == variants.end ()); + + variants[id] = variant; +} + +bool +TypeCheckContext::lookup_variant_definition (HirId id, HirId *variant) +{ + auto it = variants.find (id); + if (it == variants.end ()) + return false; + + *variant = it->second; + return true; +} + +void +TypeCheckContext::insert_operator_overload (HirId id, TyTy::FnType *call_site) +{ + auto it = operator_overloads.find (id); + rust_assert (it == operator_overloads.end ()); + + operator_overloads[id] = call_site; +} + +bool +TypeCheckContext::lookup_operator_overload (HirId id, TyTy::FnType **call) +{ + auto it = operator_overloads.find (id); + if (it == operator_overloads.end ()) + return false; + + *call = it->second; + return true; +} + +void +TypeCheckContext::insert_unconstrained_check_marker (HirId id, bool status) +{ + unconstrained[id] = status; +} + +bool +TypeCheckContext::have_checked_for_unconstrained (HirId id, bool *result) +{ + auto it = unconstrained.find (id); + bool found = it != unconstrained.end (); + if (!found) + return false; + + *result = it->second; + return true; +} + +void +TypeCheckContext::insert_resolved_predicate (HirId id, + TyTy::TypeBoundPredicate predicate) +{ + auto it = predicates.find (id); + rust_assert (it == predicates.end ()); + + predicates.insert ({id, predicate}); +} + +bool +TypeCheckContext::lookup_predicate (HirId id, TyTy::TypeBoundPredicate *result) +{ + auto it = predicates.find (id); + bool found = it != predicates.end (); + if (!found) + return false; + + *result = it->second; + return true; +} + +void +TypeCheckContext::insert_query (HirId id) +{ + querys_in_progress.insert (id); +} + +void +TypeCheckContext::query_completed (HirId id) +{ + querys_in_progress.erase (id); +} + +bool +TypeCheckContext::query_in_progress (HirId id) const +{ + return querys_in_progress.find (id) != querys_in_progress.end (); +} + +void +TypeCheckContext::insert_trait_query (DefId id) +{ + trait_queries_in_progress.insert (id); +} + +void +TypeCheckContext::trait_query_completed (DefId id) +{ + trait_queries_in_progress.erase (id); +} + +bool +TypeCheckContext::trait_query_in_progress (DefId id) const +{ + return trait_queries_in_progress.find (id) + != trait_queries_in_progress.end (); +} + // TypeCheckContextItem +TypeCheckContextItem::Item::Item (HIR::Function *item) : item (item) {} + +TypeCheckContextItem::Item::Item (HIR::ImplBlock *impl_block, + HIR::Function *item) + : impl_item ({impl_block, item}) +{} + +TypeCheckContextItem::Item::Item (HIR::TraitItemFunc *trait_item) + : trait_item (trait_item) +{} + +TypeCheckContextItem::TypeCheckContextItem (HIR::Function *item) + : type (ItemType::ITEM), item (item) +{} + +TypeCheckContextItem::TypeCheckContextItem (HIR::ImplBlock *impl_block, + HIR::Function *item) + : type (ItemType::IMPL_ITEM), item (impl_block, item) +{} + +TypeCheckContextItem::TypeCheckContextItem (HIR::TraitItemFunc *trait_item) + : type (ItemType::TRAIT_ITEM), item (trait_item) +{} + +HIR::Function * +TypeCheckContextItem::get_item () +{ + rust_assert (get_type () == ItemType::ITEM); + return item.item; +} + +std::pair & +TypeCheckContextItem::get_impl_item () +{ + rust_assert (get_type () == ItemType::IMPL_ITEM); + return item.impl_item; +} + +HIR::TraitItemFunc * +TypeCheckContextItem::get_trait_item () +{ + rust_assert (get_type () == ItemType::TRAIT_ITEM); + return item.trait_item; +} + +TypeCheckContextItem::ItemType +TypeCheckContextItem::get_type () const +{ + return type; +} + TyTy::FnType * TypeCheckContextItem::get_context_type () { diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index 079055e870d..61c02a85c53 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -17,17 +17,22 @@ // . #include "rust-tyty.h" -#include "rust-tyty-visitor.h" -#include "rust-tyty-call.h" + #include "rust-hir-type-check-expr.h" #include "rust-hir-type-check-type.h" -#include "rust-tyty-rules.h" -#include "rust-tyty-cmp.h" +#include "rust-tyty-visitor.h" +#include "rust-tyty-call.h" #include "rust-hir-map.h" +#include "rust-location.h" +#include "rust-linemap.h" + #include "rust-substitution-mapper.h" #include "rust-hir-trait-ref.h" #include "rust-hir-type-bounds.h" #include "rust-hir-trait-resolve.h" +#include "rust-tyty-rules.h" +#include "rust-tyty-cmp.h" + #include "options.h" namespace Rust { @@ -658,6 +663,53 @@ ErrorType::monomorphized_clone () const // Struct Field type +StructFieldType::StructFieldType (HirId ref, std::string name, BaseType *ty, + Location locus) + : ref (ref), name (name), ty (ty), locus (locus) +{} + +HirId +StructFieldType::get_ref () const +{ + return ref; +} + +std::string +StructFieldType::get_name () const +{ + return name; +} + +BaseType * +StructFieldType::get_field_type () const +{ + return ty; +} + +void +StructFieldType::set_field_type (BaseType *fty) +{ + ty = fty; +} + +bool +StructFieldType::is_concrete () const +{ + return ty->is_concrete (); +} + +void +StructFieldType::debug () const +{ + rust_debug ("%s", as_string ().c_str ()); +} + +Location +StructFieldType::get_locus () const +{ + return locus; +} + std::string StructFieldType::as_string () const { @@ -695,6 +747,241 @@ StructFieldType::monomorphized_clone () const get_field_type ()->monomorphized_clone (), locus); } +// VariantDef + +std::string +VariantDef::variant_type_string (VariantType type) +{ + switch (type) + { + case NUM: + return "enumeral"; + case TUPLE: + return "tuple"; + case STRUCT: + return "struct"; + } + gcc_unreachable (); + return ""; +} + +VariantDef::VariantDef (HirId id, DefId defid, std::string identifier, + RustIdent ident, HIR::Expr *discriminant) + : id (id), defid (defid), identifier (identifier), ident (ident), + discriminant (discriminant) + +{ + type = VariantType::NUM; + fields = {}; +} + +VariantDef::VariantDef (HirId id, DefId defid, std::string identifier, + RustIdent ident, VariantType type, + HIR::Expr *discriminant, + std::vector fields) + : id (id), defid (defid), identifier (identifier), ident (ident), type (type), + discriminant (discriminant), fields (fields) +{ + rust_assert ((type == VariantType::NUM && fields.empty ()) + || (type == VariantType::TUPLE || type == VariantType::STRUCT)); +} + +VariantDef::VariantDef (const VariantDef &other) + : id (other.id), defid (other.defid), identifier (other.identifier), + ident (other.ident), type (other.type), discriminant (other.discriminant), + fields (other.fields) +{} + +VariantDef & +VariantDef::operator= (const VariantDef &other) +{ + id = other.id; + identifier = other.identifier; + type = other.type; + discriminant = other.discriminant; + fields = other.fields; + ident = other.ident; + + return *this; +} + +VariantDef & +VariantDef::get_error_node () +{ + static VariantDef node + = VariantDef (UNKNOWN_HIRID, UNKNOWN_DEFID, "", + {Resolver::CanonicalPath::create_empty (), + Linemap::unknown_location ()}, + nullptr); + + return node; +} + +bool +VariantDef::is_error () const +{ + return get_id () == UNKNOWN_HIRID; +} + +HirId +VariantDef::get_id () const +{ + return id; +} + +DefId +VariantDef::get_defid () const +{ + return defid; +} + +VariantDef::VariantType +VariantDef::get_variant_type () const +{ + return type; +} + +bool +VariantDef::is_data_variant () const +{ + return type != VariantType::NUM; +} + +bool +VariantDef::is_dataless_variant () const +{ + return type == VariantType::NUM; +} + +std::string +VariantDef::get_identifier () const +{ + return identifier; +} + +size_t +VariantDef::num_fields () const +{ + return fields.size (); +} + +StructFieldType * +VariantDef::get_field_at_index (size_t index) +{ + rust_assert (index < fields.size ()); + return fields.at (index); +} + +std::vector & +VariantDef::get_fields () +{ + rust_assert (type != NUM); + return fields; +} + +bool +VariantDef::lookup_field (const std::string &lookup, + StructFieldType **field_lookup, size_t *index) const +{ + size_t i = 0; + for (auto &field : fields) + { + if (field->get_name ().compare (lookup) == 0) + { + if (index != nullptr) + *index = i; + + if (field_lookup != nullptr) + *field_lookup = field; + + return true; + } + i++; + } + return false; +} + +HIR::Expr * +VariantDef::get_discriminant () const +{ + rust_assert (discriminant != nullptr); + return discriminant; +} + +std::string +VariantDef::as_string () const +{ + if (type == VariantType::NUM) + return identifier + " = " + discriminant->as_string (); + + std::string buffer; + for (size_t i = 0; i < fields.size (); ++i) + { + buffer += fields.at (i)->as_string (); + if ((i + 1) < fields.size ()) + buffer += ", "; + } + + if (type == VariantType::TUPLE) + return identifier + " (" + buffer + ")"; + else + return identifier + " {" + buffer + "}"; +} + +bool +VariantDef::is_equal (const VariantDef &other) const +{ + if (type != other.type) + return false; + + if (identifier.compare (other.identifier) != 0) + return false; + + if (discriminant != other.discriminant) + return false; + + if (fields.size () != other.fields.size ()) + return false; + + for (size_t i = 0; i < fields.size (); i++) + { + if (!fields.at (i)->is_equal (*other.fields.at (i))) + return false; + } + + return true; +} + +VariantDef * +VariantDef::clone () const +{ + std::vector cloned_fields; + for (auto &f : fields) + cloned_fields.push_back ((StructFieldType *) f->clone ()); + + return new VariantDef (id, defid, identifier, ident, type, discriminant, + cloned_fields); +} + +VariantDef * +VariantDef::monomorphized_clone () const +{ + std::vector cloned_fields; + for (auto &f : fields) + cloned_fields.push_back ((StructFieldType *) f->monomorphized_clone ()); + + return new VariantDef (id, defid, identifier, ident, type, discriminant, + cloned_fields); +} + +const RustIdent & +VariantDef::get_ident () const +{ + return ident; +} + +// ADTType + void ADTType::accept_vis (TyVisitor &vis) { @@ -892,6 +1179,57 @@ ADTType::handle_substitions (SubstitutionArgumentMappings subst_mappings) return adt; } +// TupleType + +TupleType::TupleType (HirId ref, Location locus, std::vector fields, + std::set refs) + : BaseType (ref, ref, TypeKind::TUPLE, + {Resolver::CanonicalPath::create_empty (), locus}, refs), + fields (fields) +{} + +TupleType::TupleType (HirId ref, HirId ty_ref, Location locus, + std::vector fields, std::set refs) + : BaseType (ref, ty_ref, TypeKind::TUPLE, + {Resolver::CanonicalPath::create_empty (), locus}, refs), + fields (fields) +{} + +TupleType * +TupleType::get_unit_type (HirId ref) +{ + return new TupleType (ref, Linemap::predeclared_location ()); +} + +bool +TupleType::is_unit () const +{ + return this->fields.empty (); +} + +size_t +TupleType::num_fields () const +{ + return fields.size (); +} + +bool +TupleType::is_concrete () const +{ + for (size_t i = 0; i < num_fields (); i++) + { + if (!get_field (i)->is_concrete ()) + return false; + } + return true; +} + +const std::vector & +TupleType::get_fields () const +{ + return fields; +} + void TupleType::accept_vis (TyVisitor &vis) { @@ -1622,6 +1960,34 @@ SliceType::handle_substitions (SubstitutionArgumentMappings mappings) return ref; } +// BoolType + +BoolType::BoolType (HirId ref, std::set refs) + : BaseType (ref, ref, TypeKind::BOOL, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs) +{} + +BoolType::BoolType (HirId ref, HirId ty_ref, std::set refs) + : BaseType (ref, ty_ref, TypeKind::BOOL, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs) +{} + +std::string +BoolType::get_name () const +{ + return as_string (); +} + +bool +BoolType::is_concrete () const +{ + return true; +} + void BoolType::accept_vis (TyVisitor &vis) { @@ -1666,6 +2032,36 @@ BoolType::monomorphized_clone () const return clone (); } +// IntType + +IntType::IntType (HirId ref, IntKind kind, std::set refs) + : BaseType (ref, ref, TypeKind::INT, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + int_kind (kind) +{} + +IntType::IntType (HirId ref, HirId ty_ref, IntKind kind, std::set refs) + : BaseType (ref, ty_ref, TypeKind::INT, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + int_kind (kind) +{} + +std::string +IntType::get_name () const +{ + return as_string (); +} + +IntType::IntKind +IntType::get_int_kind () const +{ + return int_kind; +} + void IntType::accept_vis (TyVisitor &vis) { @@ -1735,6 +2131,43 @@ IntType::is_equal (const BaseType &other) const return get_int_kind () == o.get_int_kind (); } +bool +IntType::is_concrete () const +{ + return true; +} + +// UintType + +UintType::UintType (HirId ref, UintKind kind, std::set refs) + : BaseType (ref, ref, TypeKind::UINT, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + uint_kind (kind) +{} + +UintType::UintType (HirId ref, HirId ty_ref, UintKind kind, + std::set refs) + : BaseType (ref, ty_ref, TypeKind::UINT, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + uint_kind (kind) +{} + +std::string +UintType::get_name () const +{ + return as_string (); +} + +UintType::UintKind +UintType::get_uint_kind () const +{ + return uint_kind; +} + void UintType::accept_vis (TyVisitor &vis) { @@ -1804,6 +2237,49 @@ UintType::is_equal (const BaseType &other) const return get_uint_kind () == o.get_uint_kind (); } +bool +UintType::is_concrete () const +{ + return true; +} + +// FloatType + +FloatType::FloatType (HirId ref, FloatKind kind, std::set refs) + : BaseType (ref, ref, TypeKind::FLOAT, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + float_kind (kind) +{} + +FloatType::FloatType (HirId ref, HirId ty_ref, FloatKind kind, + std::set refs) + : BaseType (ref, ty_ref, TypeKind::FLOAT, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + float_kind (kind) +{} + +std::string +FloatType::get_name () const +{ + return as_string (); +} + +FloatType::FloatKind +FloatType::get_float_kind () const +{ + return float_kind; +} + +bool +FloatType::is_concrete () const +{ + return true; +} + void FloatType::accept_vis (TyVisitor &vis) { @@ -1867,6 +2343,34 @@ FloatType::is_equal (const BaseType &other) const return get_float_kind () == o.get_float_kind (); } +// UsizeType + +USizeType::USizeType (HirId ref, std::set refs) + : BaseType (ref, ref, TypeKind::USIZE, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs) +{} + +USizeType::USizeType (HirId ref, HirId ty_ref, std::set refs) + : BaseType (ref, ty_ref, TypeKind::USIZE, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs) +{} + +std::string +USizeType::get_name () const +{ + return as_string (); +} + +bool +USizeType::is_concrete () const +{ + return true; +} + void USizeType::accept_vis (TyVisitor &vis) { @@ -1911,6 +2415,34 @@ USizeType::monomorphized_clone () const return clone (); } +// ISizeType + +ISizeType::ISizeType (HirId ref, std::set refs) + : BaseType (ref, ref, TypeKind::ISIZE, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs) +{} + +ISizeType::ISizeType (HirId ref, HirId ty_ref, std::set refs) + : BaseType (ref, ty_ref, TypeKind::ISIZE, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs) +{} + +std::string +ISizeType::get_name () const +{ + return as_string (); +} + +bool +ISizeType::is_concrete () const +{ + return true; +} + void ISizeType::accept_vis (TyVisitor &vis) { @@ -1955,6 +2487,34 @@ ISizeType::monomorphized_clone () const return clone (); } +// Char Type + +CharType::CharType (HirId ref, std::set refs) + : BaseType (ref, ref, TypeKind::CHAR, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs) +{} + +CharType::CharType (HirId ref, HirId ty_ref, std::set refs) + : BaseType (ref, ty_ref, TypeKind::CHAR, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs) +{} + +bool +CharType::is_concrete () const +{ + return true; +} + +std::string +CharType::get_name () const +{ + return as_string (); +} + void CharType::accept_vis (TyVisitor &vis) { @@ -1999,6 +2559,76 @@ CharType::monomorphized_clone () const return clone (); } +// Reference Type + +ReferenceType::ReferenceType (HirId ref, TyVar base, Mutability mut, + std::set refs) + : BaseType (ref, ref, TypeKind::REF, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + base (base), mut (mut) +{} + +ReferenceType::ReferenceType (HirId ref, HirId ty_ref, TyVar base, + Mutability mut, std::set refs) + : BaseType (ref, ty_ref, TypeKind::REF, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + base (base), mut (mut) +{} + +bool +ReferenceType::is_concrete () const +{ + return get_base ()->is_concrete (); +} + +Mutability +ReferenceType::mutability () const +{ + return mut; +} + +bool +ReferenceType::is_mutable () const +{ + return mut == Mutability::Mut; +} + +bool +ReferenceType::is_dyn_object () const +{ + return is_dyn_slice_type () || is_dyn_str_type (); +} + +bool +ReferenceType::is_dyn_slice_type (const TyTy::SliceType **slice) const +{ + const TyTy::BaseType *element = get_base ()->destructure (); + if (element->get_kind () != TyTy::TypeKind::SLICE) + return false; + if (slice == nullptr) + return true; + + *slice = static_cast (element); + return true; +} + +bool +ReferenceType::is_dyn_str_type (const TyTy::StrType **str) const +{ + const TyTy::BaseType *element = get_base ()->destructure (); + if (element->get_kind () != TyTy::TypeKind::STR) + return false; + if (str == nullptr) + return true; + + *str = static_cast (element); + return true; +} + void ReferenceType::accept_vis (TyVisitor &vis) { @@ -2089,6 +2719,82 @@ ReferenceType::handle_substitions (SubstitutionArgumentMappings mappings) return ref; } +// PointerType + +PointerType::PointerType (HirId ref, TyVar base, Mutability mut, + std::set refs) + : BaseType (ref, ref, TypeKind::POINTER, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + base (base), mut (mut) +{} + +PointerType::PointerType (HirId ref, HirId ty_ref, TyVar base, Mutability mut, + std::set refs) + : BaseType (ref, ty_ref, TypeKind::POINTER, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + base (base), mut (mut) +{} + +bool +PointerType::is_concrete () const +{ + return get_base ()->is_concrete (); +} + +Mutability +PointerType::mutability () const +{ + return mut; +} + +bool +PointerType::is_mutable () const +{ + return mut == Mutability::Mut; +} + +bool +PointerType::is_const () const +{ + return mut == Mutability::Imm; +} + +bool +PointerType::is_dyn_object () const +{ + return is_dyn_slice_type () || is_dyn_str_type (); +} + +bool +PointerType::is_dyn_slice_type (const TyTy::SliceType **slice) const +{ + const TyTy::BaseType *element = get_base ()->destructure (); + if (element->get_kind () != TyTy::TypeKind::SLICE) + return false; + if (slice == nullptr) + return true; + + *slice = static_cast (element); + return true; +} + +bool +PointerType::is_dyn_str_type (const TyTy::StrType **str) const +{ + const TyTy::BaseType *element = get_base ()->destructure (); + if (element->get_kind () != TyTy::TypeKind::STR) + return false; + if (str == nullptr) + return true; + + *str = static_cast (element); + return true; +} + void PointerType::accept_vis (TyVisitor &vis) { @@ -2179,6 +2885,52 @@ PointerType::handle_substitions (SubstitutionArgumentMappings mappings) return ref; } +// PARAM Type + +ParamType::ParamType (std::string symbol, Location locus, HirId ref, + HIR::GenericParam ¶m, + std::vector specified_bounds, + std::set refs) + : BaseType (ref, ref, TypeKind::PARAM, + {Resolver::CanonicalPath::new_seg (UNKNOWN_NODEID, symbol), + locus}, + specified_bounds, refs), + symbol (symbol), param (param) +{} + +ParamType::ParamType (std::string symbol, Location locus, HirId ref, + HirId ty_ref, HIR::GenericParam ¶m, + std::vector specified_bounds, + std::set refs) + : BaseType (ref, ty_ref, TypeKind::PARAM, + {Resolver::CanonicalPath::new_seg (UNKNOWN_NODEID, symbol), + locus}, + specified_bounds, refs), + symbol (symbol), param (param) +{} + +HIR::GenericParam & +ParamType::get_generic_param () +{ + return param; +} + +bool +ParamType::can_resolve () const +{ + return get_ref () != get_ty_ref (); +} + +bool +ParamType::is_concrete () const +{ + auto r = resolve (); + if (r == this) + return false; + + return r->is_concrete (); +} + void ParamType::accept_vis (TyVisitor &vis) { @@ -2320,6 +3072,34 @@ ParamType::handle_substitions (SubstitutionArgumentMappings subst_mappings) return p; } +// StrType + +StrType::StrType (HirId ref, std::set refs) + : BaseType (ref, ref, TypeKind::STR, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs) +{} + +StrType::StrType (HirId ref, HirId ty_ref, std::set refs) + : BaseType (ref, ty_ref, TypeKind::STR, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs) +{} + +std::string +StrType::get_name () const +{ + return as_string (); +} + +bool +StrType::is_concrete () const +{ + return true; +} + BaseType * StrType::clone () const { @@ -2370,6 +3150,40 @@ StrType::is_equal (const BaseType &other) const return get_kind () == other.get_kind (); } +// Never Type + +NeverType::NeverType (HirId ref, std::set refs) + : BaseType (ref, ref, TypeKind::NEVER, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs) +{} + +NeverType::NeverType (HirId ref, HirId ty_ref, std::set refs) + : BaseType (ref, ty_ref, TypeKind::NEVER, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs) +{} + +std::string +NeverType::get_name () const +{ + return as_string (); +} + +bool +NeverType::is_unit () const +{ + return true; +} + +bool +NeverType::is_concrete () const +{ + return true; +} + void NeverType::accept_vis (TyVisitor &vis) { @@ -2416,6 +3230,52 @@ NeverType::monomorphized_clone () const // placeholder type +PlaceholderType::PlaceholderType (std::string symbol, HirId ref, + std::set refs) + : BaseType (ref, ref, TypeKind::PLACEHOLDER, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + symbol (symbol) +{} + +PlaceholderType::PlaceholderType (std::string symbol, HirId ref, HirId ty_ref, + std::set refs) + : BaseType (ref, ty_ref, TypeKind::PLACEHOLDER, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + symbol (symbol) +{} + +std::string +PlaceholderType::get_name () const +{ + return as_string (); +} + +bool +PlaceholderType::is_unit () const +{ + rust_assert (can_resolve ()); + return resolve ()->is_unit (); +} + +std::string +PlaceholderType::get_symbol () const +{ + return symbol; +} + +bool +PlaceholderType::is_concrete () const +{ + if (!can_resolve ()) + return true; + + return resolve ()->is_concrete (); +} + void PlaceholderType::accept_vis (TyVisitor &vis) { @@ -2515,6 +3375,78 @@ PlaceholderType::is_equal (const BaseType &other) const // Projection type +ProjectionType::ProjectionType ( + HirId ref, BaseType *base, const Resolver::TraitReference *trait, DefId item, + std::vector subst_refs, + SubstitutionArgumentMappings generic_arguments, std::set refs) + : BaseType (ref, ref, TypeKind::PROJECTION, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + SubstitutionRef (std::move (subst_refs), std::move (generic_arguments)), + base (base), trait (trait), item (item) +{} + +ProjectionType::ProjectionType ( + HirId ref, HirId ty_ref, BaseType *base, + const Resolver::TraitReference *trait, DefId item, + std::vector subst_refs, + SubstitutionArgumentMappings generic_arguments, std::set refs) + : BaseType (ref, ty_ref, TypeKind::PROJECTION, + {Resolver::CanonicalPath::create_empty (), + Linemap::predeclared_location ()}, + refs), + SubstitutionRef (std::move (subst_refs), std::move (generic_arguments)), + base (base), trait (trait), item (item) +{} + +bool +ProjectionType::is_unit () const +{ + return false; +} + +std::string +ProjectionType::get_name () const +{ + return as_string (); +} + +bool +ProjectionType::needs_generic_substitutions () const +{ + return needs_substitution (); +} + +bool +ProjectionType::supports_substitutions () const +{ + return true; +} + +bool +ProjectionType::has_subsititions_defined () const +{ + return has_substitutions (); +} + +const BaseType * +ProjectionType::get () const +{ + return base; +} +BaseType * +ProjectionType::get () +{ + return base; +} + +bool +ProjectionType::is_concrete () const +{ + return base->is_concrete (); +} + void ProjectionType::accept_vis (TyVisitor &vis) { @@ -2631,6 +3563,26 @@ ProjectionType::handle_substitions (SubstitutionArgumentMappings subst_mappings) return projection; } +// DynObjectType + +DynamicObjectType::DynamicObjectType ( + HirId ref, RustIdent ident, std::vector specified_bounds, + std::set refs) + : BaseType (ref, ref, TypeKind::DYNAMIC, ident, specified_bounds, refs) +{} + +DynamicObjectType::DynamicObjectType ( + HirId ref, HirId ty_ref, RustIdent ident, + std::vector specified_bounds, std::set refs) + : BaseType (ref, ty_ref, TypeKind::DYNAMIC, ident, specified_bounds, refs) +{} + +bool +DynamicObjectType::is_concrete () const +{ + return true; +} + void DynamicObjectType::accept_vis (TyVisitor &vis) { diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index 1a6bac3f864..85b3a3b7abc 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -20,11 +20,9 @@ #define RUST_TYTY #include "rust-hir-map.h" -#include "rust-hir-full.h" -#include "rust-diagnostics.h" -#include "rust-abi.h" #include "rust-common.h" #include "rust-identifier.h" +#include "rust-abi.h" #include "rust-tyty-bounds.h" #include "rust-tyty-util.h" #include "rust-tyty-subst.h" @@ -274,24 +272,12 @@ public: ParamType (std::string symbol, Location locus, HirId ref, HIR::GenericParam ¶m, std::vector specified_bounds, - std::set refs = std::set ()) - : BaseType (ref, ref, TypeKind::PARAM, - {Resolver::CanonicalPath::new_seg (UNKNOWN_NODEID, symbol), - locus}, - specified_bounds, refs), - symbol (symbol), param (param) - {} + std::set refs = std::set ()); ParamType (std::string symbol, Location locus, HirId ref, HirId ty_ref, HIR::GenericParam ¶m, std::vector specified_bounds, - std::set refs = std::set ()) - : BaseType (ref, ty_ref, TypeKind::PARAM, - {Resolver::CanonicalPath::new_seg (UNKNOWN_NODEID, symbol), - locus}, - specified_bounds, refs), - symbol (symbol), param (param) - {} + std::set refs = std::set ()); void accept_vis (TyVisitor &vis) override; void accept_vis (TyConstVisitor &vis) const override; @@ -306,9 +292,9 @@ public: std::string get_symbol () const; - HIR::GenericParam &get_generic_param () { return param; } + HIR::GenericParam &get_generic_param (); - bool can_resolve () const { return get_ref () != get_ty_ref (); } + bool can_resolve () const; BaseType *resolve () const; @@ -316,14 +302,7 @@ public: bool is_equal (const BaseType &other) const override; - bool is_concrete () const override final - { - auto r = resolve (); - if (r == this) - return false; - - return r->is_concrete (); - } + bool is_concrete () const override final; ParamType *handle_substitions (SubstitutionArgumentMappings mappings); @@ -335,31 +314,25 @@ private: class StructFieldType { public: - StructFieldType (HirId ref, std::string name, BaseType *ty, Location locus) - : ref (ref), name (name), ty (ty), locus (locus) - {} - - HirId get_ref () const { return ref; } + StructFieldType (HirId ref, std::string name, BaseType *ty, Location locus); - std::string as_string () const; + HirId get_ref () const; bool is_equal (const StructFieldType &other) const; - std::string get_name () const { return name; } - - BaseType *get_field_type () const { return ty; } + std::string get_name () const; - void set_field_type (BaseType *fty) { ty = fty; } + BaseType *get_field_type () const; + void set_field_type (BaseType *fty); StructFieldType *clone () const; - StructFieldType *monomorphized_clone () const; - bool is_concrete () const { return ty->is_concrete (); } - - void debug () const { rust_debug ("%s", as_string ().c_str ()); } + bool is_concrete () const; - Location get_locus () const { return locus; } + void debug () const; + Location get_locus () const; + std::string as_string () const; private: HirId ref; @@ -373,29 +346,18 @@ class TupleType : public BaseType public: TupleType (HirId ref, Location locus, std::vector fields = std::vector (), - std::set refs = std::set ()) - : BaseType (ref, ref, TypeKind::TUPLE, - {Resolver::CanonicalPath::create_empty (), locus}, refs), - fields (fields) - {} + std::set refs = std::set ()); TupleType (HirId ref, HirId ty_ref, Location locus, std::vector fields = std::vector (), - std::set refs = std::set ()) - : BaseType (ref, ty_ref, TypeKind::TUPLE, - {Resolver::CanonicalPath::create_empty (), locus}, refs), - fields (fields) - {} + std::set refs = std::set ()); - static TupleType *get_unit_type (HirId ref) - { - return new TupleType (ref, Linemap::predeclared_location ()); - } + static TupleType *get_unit_type (HirId ref); void accept_vis (TyVisitor &vis) override; void accept_vis (TyConstVisitor &vis) const override; - bool is_unit () const override { return this->fields.empty (); } + bool is_unit () const override; std::string as_string () const override; @@ -404,24 +366,16 @@ public: bool is_equal (const BaseType &other) const override; - size_t num_fields () const { return fields.size (); } + size_t num_fields () const; BaseType *get_field (size_t index) const; BaseType *clone () const final override; BaseType *monomorphized_clone () const final override; - bool is_concrete () const override final - { - for (size_t i = 0; i < num_fields (); i++) - { - if (!get_field (i)->is_concrete ()) - return false; - } - return true; - } + bool is_concrete () const override final; - const std::vector &get_fields () const { return fields; } + const std::vector &get_fields () const; std::string get_name () const override final; @@ -507,185 +461,48 @@ public: STRUCT }; - static std::string variant_type_string (VariantType type) - { - switch (type) - { - case NUM: - return "enumeral"; - case TUPLE: - return "tuple"; - case STRUCT: - return "struct"; - } - gcc_unreachable (); - return ""; - } + static std::string variant_type_string (VariantType type); VariantDef (HirId id, DefId defid, std::string identifier, RustIdent ident, - HIR::Expr *discriminant) - : id (id), defid (defid), identifier (identifier), ident (ident), - discriminant (discriminant) - - { - type = VariantType::NUM; - fields = {}; - } + HIR::Expr *discriminant); VariantDef (HirId id, DefId defid, std::string identifier, RustIdent ident, VariantType type, HIR::Expr *discriminant, - std::vector fields) - : id (id), defid (defid), identifier (identifier), ident (ident), - type (type), discriminant (discriminant), fields (fields) - { - rust_assert ( - (type == VariantType::NUM && fields.empty ()) - || (type == VariantType::TUPLE || type == VariantType::STRUCT)); - } + std::vector fields); - VariantDef (const VariantDef &other) - : id (other.id), defid (other.defid), identifier (other.identifier), - ident (other.ident), type (other.type), discriminant (other.discriminant), - fields (other.fields) - {} + VariantDef (const VariantDef &other); - VariantDef &operator= (const VariantDef &other) - { - id = other.id; - identifier = other.identifier; - type = other.type; - discriminant = other.discriminant; - fields = other.fields; - ident = other.ident; - - return *this; - } + VariantDef &operator= (const VariantDef &other); - static VariantDef &get_error_node () - { - static VariantDef node - = VariantDef (UNKNOWN_HIRID, UNKNOWN_DEFID, "", - {Resolver::CanonicalPath::create_empty (), - Linemap::unknown_location ()}, - nullptr); + static VariantDef &get_error_node (); + bool is_error () const; - return node; - } + HirId get_id () const; + DefId get_defid () const; - bool is_error () const { return get_id () == UNKNOWN_HIRID; } + VariantType get_variant_type () const; + bool is_data_variant () const; + bool is_dataless_variant () const; - HirId get_id () const { return id; } - DefId get_defid () const { return defid; } + std::string get_identifier () const; - VariantType get_variant_type () const { return type; } - bool is_data_variant () const { return type != VariantType::NUM; } - bool is_dataless_variant () const { return type == VariantType::NUM; } + size_t num_fields () const; + StructFieldType *get_field_at_index (size_t index); - std::string get_identifier () const { return identifier; } - - size_t num_fields () const { return fields.size (); } - StructFieldType *get_field_at_index (size_t index) - { - rust_assert (index < fields.size ()); - return fields.at (index); - } - - std::vector &get_fields () - { - rust_assert (type != NUM); - return fields; - } + std::vector &get_fields (); bool lookup_field (const std::string &lookup, StructFieldType **field_lookup, - size_t *index) const - { - size_t i = 0; - for (auto &field : fields) - { - if (field->get_name ().compare (lookup) == 0) - { - if (index != nullptr) - *index = i; - - if (field_lookup != nullptr) - *field_lookup = field; - - return true; - } - i++; - } - return false; - } - - HIR::Expr *get_discriminant () const - { - rust_assert (discriminant != nullptr); - return discriminant; - } - - std::string as_string () const - { - if (type == VariantType::NUM) - return identifier + " = " + discriminant->as_string (); - - std::string buffer; - for (size_t i = 0; i < fields.size (); ++i) - { - buffer += fields.at (i)->as_string (); - if ((i + 1) < fields.size ()) - buffer += ", "; - } - - if (type == VariantType::TUPLE) - return identifier + " (" + buffer + ")"; - else - return identifier + " {" + buffer + "}"; - } - - bool is_equal (const VariantDef &other) const - { - if (type != other.type) - return false; - - if (identifier.compare (other.identifier) != 0) - return false; + size_t *index) const; - if (discriminant != other.discriminant) - return false; - - if (fields.size () != other.fields.size ()) - return false; - - for (size_t i = 0; i < fields.size (); i++) - { - if (!fields.at (i)->is_equal (*other.fields.at (i))) - return false; - } - - return true; - } - - VariantDef *clone () const - { - std::vector cloned_fields; - for (auto &f : fields) - cloned_fields.push_back ((StructFieldType *) f->clone ()); + HIR::Expr *get_discriminant () const; - return new VariantDef (id, defid, identifier, ident, type, discriminant, - cloned_fields); - } + std::string as_string () const; - VariantDef *monomorphized_clone () const - { - std::vector cloned_fields; - for (auto &f : fields) - cloned_fields.push_back ((StructFieldType *) f->monomorphized_clone ()); + bool is_equal (const VariantDef &other) const; + VariantDef *clone () const; + VariantDef *monomorphized_clone () const; - return new VariantDef (id, defid, identifier, ident, type, discriminant, - cloned_fields); - } - - const RustIdent &get_ident () const { return ident; } + const RustIdent &get_ident () const; private: HirId id; @@ -1262,33 +1079,22 @@ private: class BoolType : public BaseType { public: - BoolType (HirId ref, std::set refs = std::set ()) - : BaseType (ref, ref, TypeKind::BOOL, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs) - {} - - BoolType (HirId ref, HirId ty_ref, std::set refs = std::set ()) - : BaseType (ref, ty_ref, TypeKind::BOOL, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs) - {} + BoolType (HirId ref, std::set refs = std::set ()); + BoolType (HirId ref, HirId ty_ref, std::set refs = std::set ()); void accept_vis (TyVisitor &vis) override; void accept_vis (TyConstVisitor &vis) const override; std::string as_string () const override; - std::string get_name () const override final { return as_string (); } + std::string get_name () const override final; BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; BaseType *clone () const final override; BaseType *monomorphized_clone () const final override; - bool is_concrete () const override final { return true; } + bool is_concrete () const override final; }; class IntType : public BaseType @@ -1303,40 +1109,27 @@ public: I128 }; - IntType (HirId ref, IntKind kind, std::set refs = std::set ()) - : BaseType (ref, ref, TypeKind::INT, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs), - int_kind (kind) - {} - + IntType (HirId ref, IntKind kind, std::set refs = std::set ()); IntType (HirId ref, HirId ty_ref, IntKind kind, - std::set refs = std::set ()) - : BaseType (ref, ty_ref, TypeKind::INT, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs), - int_kind (kind) - {} + std::set refs = std::set ()); void accept_vis (TyVisitor &vis) override; void accept_vis (TyConstVisitor &vis) const override; std::string as_string () const override; - std::string get_name () const override final { return as_string (); } + std::string get_name () const override final; BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; - IntKind get_int_kind () const { return int_kind; } + IntKind get_int_kind () const; BaseType *clone () const final override; BaseType *monomorphized_clone () const final override; bool is_equal (const BaseType &other) const override; - bool is_concrete () const override final { return true; } + bool is_concrete () const override final; private: IntKind int_kind; @@ -1354,40 +1147,28 @@ public: U128 }; - UintType (HirId ref, UintKind kind, std::set refs = std::set ()) - : BaseType (ref, ref, TypeKind::UINT, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs), - uint_kind (kind) - {} - + UintType (HirId ref, UintKind kind, + std::set refs = std::set ()); UintType (HirId ref, HirId ty_ref, UintKind kind, - std::set refs = std::set ()) - : BaseType (ref, ty_ref, TypeKind::UINT, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs), - uint_kind (kind) - {} + std::set refs = std::set ()); void accept_vis (TyVisitor &vis) override; void accept_vis (TyConstVisitor &vis) const override; std::string as_string () const override; - std::string get_name () const override final { return as_string (); } + std::string get_name () const override final; BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; - UintKind get_uint_kind () const { return uint_kind; } + UintKind get_uint_kind () const; BaseType *clone () const final override; BaseType *monomorphized_clone () const final override; bool is_equal (const BaseType &other) const override; - bool is_concrete () const override final { return true; } + bool is_concrete () const override final; private: UintKind uint_kind; @@ -1403,40 +1184,26 @@ public: }; FloatType (HirId ref, FloatKind kind, - std::set refs = std::set ()) - : BaseType (ref, ref, TypeKind::FLOAT, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs), - float_kind (kind) - {} - + std::set refs = std::set ()); FloatType (HirId ref, HirId ty_ref, FloatKind kind, - std::set refs = std::set ()) - : BaseType (ref, ty_ref, TypeKind::FLOAT, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs), - float_kind (kind) - {} + std::set refs = std::set ()); void accept_vis (TyVisitor &vis) override; void accept_vis (TyConstVisitor &vis) const override; std::string as_string () const override; - - std::string get_name () const override final { return as_string (); } + std::string get_name () const override final; BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; - FloatKind get_float_kind () const { return float_kind; } + FloatKind get_float_kind () const; BaseType *clone () const final override; BaseType *monomorphized_clone () const final override; bool is_equal (const BaseType &other) const override; - bool is_concrete () const override final { return true; } + bool is_concrete () const override final; private: FloatKind float_kind; @@ -1445,117 +1212,72 @@ private: class USizeType : public BaseType { public: - USizeType (HirId ref, std::set refs = std::set ()) - : BaseType (ref, ref, TypeKind::USIZE, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs) - {} - - USizeType (HirId ref, HirId ty_ref, std::set refs = std::set ()) - : BaseType (ref, ty_ref, TypeKind::USIZE, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs) - {} + USizeType (HirId ref, std::set refs = std::set ()); + USizeType (HirId ref, HirId ty_ref, + std::set refs = std::set ()); void accept_vis (TyVisitor &vis) override; void accept_vis (TyConstVisitor &vis) const override; std::string as_string () const override; - - std::string get_name () const override final { return as_string (); } + std::string get_name () const override final; BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; BaseType *clone () const final override; BaseType *monomorphized_clone () const final override; - bool is_concrete () const override final { return true; } + bool is_concrete () const override final; }; class ISizeType : public BaseType { public: - ISizeType (HirId ref, std::set refs = std::set ()) - : BaseType (ref, ref, TypeKind::ISIZE, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs) - {} - - ISizeType (HirId ref, HirId ty_ref, std::set refs = std::set ()) - : BaseType (ref, ty_ref, TypeKind::ISIZE, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs) - {} + ISizeType (HirId ref, std::set refs = std::set ()); + ISizeType (HirId ref, HirId ty_ref, + std::set refs = std::set ()); void accept_vis (TyVisitor &vis) override; void accept_vis (TyConstVisitor &vis) const override; std::string as_string () const override; - - std::string get_name () const override final { return as_string (); } + std::string get_name () const override final; BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; BaseType *clone () const final override; BaseType *monomorphized_clone () const final override; - bool is_concrete () const override final { return true; } + bool is_concrete () const override final; }; class CharType : public BaseType { public: - CharType (HirId ref, std::set refs = std::set ()) - : BaseType (ref, ref, TypeKind::CHAR, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs) - {} - - CharType (HirId ref, HirId ty_ref, std::set refs = std::set ()) - : BaseType (ref, ty_ref, TypeKind::CHAR, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs) - {} + CharType (HirId ref, std::set refs = std::set ()); + CharType (HirId ref, HirId ty_ref, std::set refs = std::set ()); void accept_vis (TyVisitor &vis) override; void accept_vis (TyConstVisitor &vis) const override; std::string as_string () const override; - - std::string get_name () const override final { return as_string (); } + std::string get_name () const override final; BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; BaseType *clone () const final override; BaseType *monomorphized_clone () const final override; - bool is_concrete () const override final { return true; } + bool is_concrete () const override final; }; class StrType : public BaseType { public: - StrType (HirId ref, std::set refs = std::set ()) - : BaseType (ref, ref, TypeKind::STR, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs) - {} - - StrType (HirId ref, HirId ty_ref, std::set refs = std::set ()) - : BaseType (ref, ty_ref, TypeKind::STR, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs) - {} + StrType (HirId ref, std::set refs = std::set ()); + StrType (HirId ref, HirId ty_ref, std::set refs = std::set ()); - std::string get_name () const override final { return as_string (); } + std::string get_name () const override final; void accept_vis (TyVisitor &vis) override; void accept_vis (TyConstVisitor &vis) const override; @@ -1569,29 +1291,16 @@ public: BaseType *clone () const final override; BaseType *monomorphized_clone () const final override; - bool is_concrete () const override final { return true; } + bool is_concrete () const override final; }; class ReferenceType : public BaseType { public: ReferenceType (HirId ref, TyVar base, Mutability mut, - std::set refs = std::set ()) - : BaseType (ref, ref, TypeKind::REF, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs), - base (base), mut (mut) - {} - + std::set refs = std::set ()); ReferenceType (HirId ref, HirId ty_ref, TyVar base, Mutability mut, - std::set refs = std::set ()) - : BaseType (ref, ty_ref, TypeKind::REF, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs), - base (base), mut (mut) - {} + std::set refs = std::set ()); BaseType *get_base () const; @@ -1610,45 +1319,19 @@ public: BaseType *clone () const final override; BaseType *monomorphized_clone () const final override; - bool is_concrete () const override final - { - return get_base ()->is_concrete (); - } + bool is_concrete () const override final; ReferenceType *handle_substitions (SubstitutionArgumentMappings mappings); - Mutability mutability () const { return mut; } + Mutability mutability () const; - bool is_mutable () const { return mut == Mutability::Mut; } + bool is_mutable () const; - bool is_dyn_object () const - { - return is_dyn_slice_type () || is_dyn_str_type (); - } + bool is_dyn_object () const; - bool is_dyn_slice_type (const TyTy::SliceType **slice = nullptr) const - { - const TyTy::BaseType *element = get_base ()->destructure (); - if (element->get_kind () != TyTy::TypeKind::SLICE) - return false; - if (slice == nullptr) - return true; + bool is_dyn_slice_type (const TyTy::SliceType **slice = nullptr) const; - *slice = static_cast (element); - return true; - } - - bool is_dyn_str_type (const TyTy::StrType **str = nullptr) const - { - const TyTy::BaseType *element = get_base ()->destructure (); - if (element->get_kind () != TyTy::TypeKind::STR) - return false; - if (str == nullptr) - return true; - - *str = static_cast (element); - return true; - } + bool is_dyn_str_type (const TyTy::StrType **str = nullptr) const; private: TyVar base; @@ -1659,22 +1342,9 @@ class PointerType : public BaseType { public: PointerType (HirId ref, TyVar base, Mutability mut, - std::set refs = std::set ()) - : BaseType (ref, ref, TypeKind::POINTER, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs), - base (base), mut (mut) - {} - + std::set refs = std::set ()); PointerType (HirId ref, HirId ty_ref, TyVar base, Mutability mut, - std::set refs = std::set ()) - : BaseType (ref, ty_ref, TypeKind::POINTER, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs), - base (base), mut (mut) - {} + std::set refs = std::set ()); BaseType *get_base () const; @@ -1692,47 +1362,17 @@ public: BaseType *clone () const final override; BaseType *monomorphized_clone () const final override; - bool is_concrete () const override final - { - return get_base ()->is_concrete (); - } + bool is_concrete () const override final; PointerType *handle_substitions (SubstitutionArgumentMappings mappings); - Mutability mutability () const { return mut; } - - bool is_mutable () const { return mut == Mutability::Mut; } - - bool is_const () const { return mut == Mutability::Imm; } - - bool is_dyn_object () const - { - return is_dyn_slice_type () || is_dyn_str_type (); - } - - bool is_dyn_slice_type (const TyTy::SliceType **slice = nullptr) const - { - const TyTy::BaseType *element = get_base ()->destructure (); - if (element->get_kind () != TyTy::TypeKind::SLICE) - return false; - if (slice == nullptr) - return true; + Mutability mutability () const; + bool is_mutable () const; + bool is_const () const; + bool is_dyn_object () const; - *slice = static_cast (element); - return true; - } - - bool is_dyn_str_type (const TyTy::StrType **str = nullptr) const - { - const TyTy::BaseType *element = get_base ()->destructure (); - if (element->get_kind () != TyTy::TypeKind::STR) - return false; - if (str == nullptr) - return true; - - *str = static_cast (element); - return true; - } + bool is_dyn_slice_type (const TyTy::SliceType **slice = nullptr) const; + bool is_dyn_str_type (const TyTy::StrType **str = nullptr) const; private: TyVar base; @@ -1752,19 +1392,9 @@ private: class NeverType : public BaseType { public: - NeverType (HirId ref, std::set refs = std::set ()) - : BaseType (ref, ref, TypeKind::NEVER, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs) - {} - - NeverType (HirId ref, HirId ty_ref, std::set refs = std::set ()) - : BaseType (ref, ty_ref, TypeKind::NEVER, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs) - {} + NeverType (HirId ref, std::set refs = std::set ()); + NeverType (HirId ref, HirId ty_ref, + std::set refs = std::set ()); void accept_vis (TyVisitor &vis) override; void accept_vis (TyConstVisitor &vis) const override; @@ -1777,10 +1407,10 @@ public: BaseType *clone () const final override; BaseType *monomorphized_clone () const final override; - std::string get_name () const override final { return as_string (); } + std::string get_name () const override final; - bool is_unit () const override { return true; } - bool is_concrete () const override final { return true; } + bool is_unit () const override; + bool is_concrete () const override final; }; // used at the type in associated types in traits @@ -1789,22 +1419,9 @@ class PlaceholderType : public BaseType { public: PlaceholderType (std::string symbol, HirId ref, - std::set refs = std::set ()) - : BaseType (ref, ref, TypeKind::PLACEHOLDER, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs), - symbol (symbol) - {} - + std::set refs = std::set ()); PlaceholderType (std::string symbol, HirId ref, HirId ty_ref, - std::set refs = std::set ()) - : BaseType (ref, ty_ref, TypeKind::PLACEHOLDER, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs), - symbol (symbol) - {} + std::set refs = std::set ()); void accept_vis (TyVisitor &vis) override; void accept_vis (TyConstVisitor &vis) const override; @@ -1817,15 +1434,11 @@ public: BaseType *clone () const final override; BaseType *monomorphized_clone () const final override; - std::string get_name () const override final { return as_string (); } + std::string get_name () const override final; - bool is_unit () const override - { - rust_assert (can_resolve ()); - return resolve ()->is_unit (); - } + bool is_unit () const override; - std::string get_symbol () const { return symbol; } + std::string get_symbol () const; void set_associated_type (HirId ref); @@ -1837,13 +1450,7 @@ public: bool is_equal (const BaseType &other) const override; - bool is_concrete () const override final - { - if (!can_resolve ()) - return true; - - return resolve ()->is_concrete (); - } + bool is_concrete () const override final; private: std::string symbol; @@ -1857,28 +1464,14 @@ public: std::vector subst_refs, SubstitutionArgumentMappings generic_arguments = SubstitutionArgumentMappings::error (), - std::set refs = std::set ()) - : BaseType (ref, ref, TypeKind::PROJECTION, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs), - SubstitutionRef (std::move (subst_refs), std::move (generic_arguments)), - base (base), trait (trait), item (item) - {} + std::set refs = std::set ()); ProjectionType (HirId ref, HirId ty_ref, BaseType *base, const Resolver::TraitReference *trait, DefId item, std::vector subst_refs, SubstitutionArgumentMappings generic_arguments = SubstitutionArgumentMappings::error (), - std::set refs = std::set ()) - : BaseType (ref, ty_ref, TypeKind::PROJECTION, - {Resolver::CanonicalPath::create_empty (), - Linemap::predeclared_location ()}, - refs), - SubstitutionRef (std::move (subst_refs), std::move (generic_arguments)), - base (base), trait (trait), item (item) - {} + std::set refs = std::set ()); void accept_vis (TyVisitor &vis) override; void accept_vis (TyConstVisitor &vis) const override; @@ -1891,26 +1484,20 @@ public: BaseType *clone () const final override; BaseType *monomorphized_clone () const final override; - std::string get_name () const override final { return as_string (); } + std::string get_name () const override final; - bool is_unit () const override { return false; } + bool is_unit () const override; - bool needs_generic_substitutions () const override final - { - return needs_substitution (); - } + bool needs_generic_substitutions () const override final; - bool supports_substitutions () const override final { return true; } + bool supports_substitutions () const override final; - bool has_subsititions_defined () const override final - { - return has_substitutions (); - } + bool has_subsititions_defined () const override final; - const BaseType *get () const { return base; } - BaseType *get () { return base; } + const BaseType *get () const; + BaseType *get (); - bool is_concrete () const override final { return base->is_concrete (); } + bool is_concrete () const override final; ProjectionType * handle_substitions (SubstitutionArgumentMappings mappings) override final; @@ -1926,15 +1513,11 @@ class DynamicObjectType : public BaseType public: DynamicObjectType (HirId ref, RustIdent ident, std::vector specified_bounds, - std::set refs = std::set ()) - : BaseType (ref, ref, TypeKind::DYNAMIC, ident, specified_bounds, refs) - {} + std::set refs = std::set ()); DynamicObjectType (HirId ref, HirId ty_ref, RustIdent ident, std::vector specified_bounds, - std::set refs = std::set ()) - : BaseType (ref, ty_ref, TypeKind::DYNAMIC, ident, specified_bounds, refs) - {} + std::set refs = std::set ()); void accept_vis (TyVisitor &vis) override; void accept_vis (TyConstVisitor &vis) const override; @@ -1951,7 +1534,7 @@ public: std::string get_name () const override final; - bool is_concrete () const override final { return true; } + bool is_concrete () const override final; // this returns a flat list of items including super trait bounds const std::vector< From patchwork Wed Apr 5 14:03: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: 79689 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp354760vqo; Wed, 5 Apr 2023 07:35:02 -0700 (PDT) X-Google-Smtp-Source: AKy350ZjYjYKZ1jM1rUdfTtrbnUxlaCLqalGnHrUUxw1xLwr7iLjY2u2deWZKnrQXZKFE2RiLgJw X-Received: by 2002:a17:907:2cf8:b0:932:e368:fbe7 with SMTP id hz24-20020a1709072cf800b00932e368fbe7mr2817306ejc.29.1680705302469; Wed, 05 Apr 2023 07:35:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705302; cv=none; d=google.com; s=arc-20160816; b=NmttDzZUFCPaGIDBb8HKJ1lbEE8LHAz6HcF2X2TAjtryrLmZZnGTuDnJsdWboNa8pJ ZR6c7j4/lAMiyD6u+t6nemxsBBNyxCqMlhlBdLis5XbPgr1Zva70ATeL+qh+PoGD3r7y KEdHuXPOIsp6h2pv6G5K2o614HhoH7YrofJg47XEs7F9tilxnaNU6o/3macnXypSKa1k pmjNKvCC1KxqpDk3KNM7iU24Xv4MyAe3GRshy7S1zDXyOejv2gZV3iGBI/ATaVUuWG9V zwEKxs55u6b9XTMJjYzQyVW+4kyM3vPfy0/ismi1kIQZ2ULxLG67nmJDnpCqHHF4WxIv oP9A== 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=GaV2r/moO8+nscLVde6LquB+xCK+EBuSFh3tkU/IXN4=; b=eiBft8et6fDEDNFqijzE1jH/hRRn3PDaRwcKppZHEh3odvkwIPFkVIOpT2fsQ4S1ug yhe11ck4Z81QPMvLoONaxuPioehCNfLnRkajiV0Gazfl0z5vgy24kusQjB9M+MmwOy1+ 255kes9aCjzj6k+nUsZD7kMffRLJ5S1JE4OHHob3MENmNIJcyhnr8ZBuEvdhTkDo8VMY GECONJCVtae8a4P31r6x/7qfqBlxoN2bu7ipzdYeqYdSHweJ7k2gM9KHw+//6ZHUik1N g5EA5CvLIst9h0tJU1LNtTGNolKzMUzeM5VMRo6csLroyscfcOYenT/vaVU6SA6v/621 1PGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=JfRWED+E; 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 gf4-20020a170906e20400b008b6e649a975si4601772ejb.559.2023.04.05.07.35.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:35:02 -0700 (PDT) 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=JfRWED+E; 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 C00AE3988C33 for ; Wed, 5 Apr 2023 14:13:28 +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 2C45238708C6 for ; Wed, 5 Apr 2023 14:06:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2C45238708C6 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 i5-20020a05600c354500b003edd24054e0so23810261wmq.4 for ; Wed, 05 Apr 2023 07:06:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703559; 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=GaV2r/moO8+nscLVde6LquB+xCK+EBuSFh3tkU/IXN4=; b=JfRWED+EtdzUIQNtjAyYcSUrb7c9ztMoK7zCtKIZdPofWUCagay2W68FCPKCHaHoJQ LEz1gY4zTRjHvMMKBY+drIt0eaak+2T3Z1rS2mZi7/N2d24jx51JAu2A8C1iTiURn+Dw sEtTR6qb6YhQJ3OAtbTXmetmv9SiXWzI3lgF4n+4CGc1ZKEn+Mtgv48HtOaTxDiju5JI 26F3V8efgLsohS5rLaSMXAsb+llaIIxWHGydGCE1JWDlXwy1kWsGb4OtQmUUWg2H5EKl tguESZ7pberDCv4zUBid0vDI5ieUE0FDy2Af/JRdRDVhatXxbm4N+9lxtkHXhVJbxwkF DUKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703559; 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=GaV2r/moO8+nscLVde6LquB+xCK+EBuSFh3tkU/IXN4=; b=6RZLpFo44jXnryU/Zfia5uPB7SmnE8k0DaHuDDyxiwFJo/0mmxPjDC5mPiR8Sp3LAx Gf6GVyJ2PmocM/sKBI9iXxDzrIVjmcnEIDYrUX8fC7crqgkgBc1r+EM0VWRfMznezy3c QCrQeKewuWyWWtVdZomOpnLo4hXAiRp+tLpnfiRJGbPIJlItFeElRM6kWhc+QfSAOsyz LkdhmEPn/8XVdOWvY8es8KcAjdnQrjDWWxmZ305Nexp/1Vv78PLDYJDQqLJKM4av3xlT PI+qQ52Sf3Us7PJECgwO0j3adHZlszntR6JLwkWeqHYA/ZWV+2Iu6z4amKWHYIJCVwVt OGtg== X-Gm-Message-State: AAQBX9fHPL/PfwZ9+g82F4v8dPauFIR/s7O5A7vFKcssr+jFmmNag519 YUMRdEb9zTtpcY/1kOIkarBd/cu/aU7VTWlt2Q== X-Received: by 2002:a1c:790b:0:b0:3ed:2b49:1571 with SMTP id l11-20020a1c790b000000b003ed2b491571mr4552234wme.20.1680703559501; Wed, 05 Apr 2023 07:05:59 -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.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:59 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 44/88] gccrs: Rename rust-tyctx.cc to rust-typecheck-context.cc Date: Wed, 5 Apr 2023 16:03:28 +0200 Message-Id: <20230405140411.3016563-45-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.6 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?1762347243075035094?= X-GMAIL-MSGID: =?utf-8?q?1762347243075035094?= From: Philip Herron Signed-off-by: Philip Herron gcc/rust/ChangeLog: * Make-lang.in: update name * typecheck/rust-tyctx.cc: Moved to... * typecheck/rust-typecheck-context.cc: ...here. --- gcc/rust/Make-lang.in | 2 +- gcc/rust/typecheck/{rust-tyctx.cc => rust-typecheck-context.cc} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename gcc/rust/typecheck/{rust-tyctx.cc => rust-typecheck-context.cc} (100%) diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index 5e173f1d2dc..4752bb83562 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -118,7 +118,7 @@ GRS_OBJS = \ rust/rust-tyty-util.o \ rust/rust-tyty-call.o \ rust/rust-tyty-subst.o \ - rust/rust-tyctx.o \ + rust/rust-typecheck-context.o \ rust/rust-tyty-bounds.o \ rust/rust-hir-type-check-util.o \ rust/rust-hir-trait-resolve.o \ diff --git a/gcc/rust/typecheck/rust-tyctx.cc b/gcc/rust/typecheck/rust-typecheck-context.cc similarity index 100% rename from gcc/rust/typecheck/rust-tyctx.cc rename to gcc/rust/typecheck/rust-typecheck-context.cc From patchwork Wed Apr 5 14:03: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: 79706 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp359137vqo; Wed, 5 Apr 2023 07:41:33 -0700 (PDT) X-Google-Smtp-Source: AKy350ZOt1a8A8vzwDnlSInqh3E57R5mBjXsTN2u4RPIIHN2EaFfn3cP4kdVnOTKoipULDDB7YXi X-Received: by 2002:aa7:d501:0:b0:502:9887:13e8 with SMTP id y1-20020aa7d501000000b00502988713e8mr2293170edq.2.1680705693575; Wed, 05 Apr 2023 07:41:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705693; cv=none; d=google.com; s=arc-20160816; b=LBirFttHgqvo6fNpeO3qvJQtComPiICSUBj0vkwMPy18KsQxI9lYLX0CI5t4tqecK6 s2KXGRIw8+LO3gCMeTykqrHgSeeI707yxwdOhO7MZb/ivhtzYtU6QDYtJWATjMc60gfJ dCOmukfcFmXCDnAnJ3YTIoUvpil+9r5Q9Xo73jz56G9x5SV45rEXfFT1ljyK3MUeQDEl W/FHWELepR8Nfq6ZcwLopAh+02KO22pMjdRW39RSAVPXSVAlgW2OQ4syonNIV5rEiHpd x3jEdLclZBlb4RDXKMIUkrME1RbZO1Pix2ggigiokCwxaR2s0k6tg45bfJAwwB6ne2hG q8tw== 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=8/xIvDtYrUqtcbhn4l7mUfHym4tc/4Xfd9TM/B/rF+0=; b=dTMQWP5LGVPmGwSNI08k3kLJFJo1FIT6fVCbEZEQtuRqqmnuSxZkvUZu+CO6q8AWed E25+ZZqUwK6403wm2w0H03m+aY5pI1MSgE7ODdWIz4zQLk4elZR+wEXT6VRwOINp+Ro8 JdBCuCOrc0o17ue8i14sNwhJQIkhPMthhgPNrdRTUNff7UHiOoEwth5tWqEtZFXVmwAu KZUkTn5BwFMGppxg9FzYGWS3BqeFBBHZLH0WO/TwZGVDt5O9cVR0aO0HHKE/lFF7P5wl OgTm/DIKLFs3YBgF0a2y3vFh1PykzAQhD1l9pAywrXynTUrJ0ZibUg+Mcx30f59Q+z2B Ay4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=L1iLi14u; 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 x23-20020aa7d397000000b004c461474e86si12250658edq.152.2023.04.05.07.41.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:41:33 -0700 (PDT) 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=L1iLi14u; 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 A401D3875DF7 for ; Wed, 5 Apr 2023 14:15:05 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id 830DF38708F2 for ; Wed, 5 Apr 2023 14:06:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 830DF38708F2 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-x335.google.com with SMTP id i5-20020a05600c354500b003edd24054e0so23810283wmq.4 for ; Wed, 05 Apr 2023 07:06:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703560; 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=8/xIvDtYrUqtcbhn4l7mUfHym4tc/4Xfd9TM/B/rF+0=; b=L1iLi14uLmMvXpxCPfwFGpEhrZTNOkiK9mMPZvaMnhopZSPoV736x7rJ/JG2kr6dTI ilAqREK9NV0F2oVhh2Tvl7BBQkLBaErgm5EopuIt1Tia2B+4qN3wmppzvjJtamvnl7NU 7C5XCrXXVebmIAHg5s60yBprkrQPuPx3i6bQwW+NNFa7I9IYkWvvD6HRJg3bSo7bKNgy m7fOnnSawQ+bLeaseXaew6Kugqvm3KIQpKiogjPlkde5OB3wPiJ+Ori0EaREvp0oLN3i dvW17gxiHC6RD6omqURcnDM785QMw/W8IDKhUInyiXBeoHMeGnTjt9Ip9zpXZMeY6Oy9 d2kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703560; 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=8/xIvDtYrUqtcbhn4l7mUfHym4tc/4Xfd9TM/B/rF+0=; b=g9fwjesRucYxNil5t8D1alfAib4jpcGhNLpA0lL9CGbX31lb2njGKiGZsN/Rj3awp6 HtEoK7U5jsEz6djiY5VMGEg3WWQo6ZfYYi+VRL9PF7ABdUqdWxyQSqTnjV/hpKKKqK/1 F+B5gR/nZYqC0ND9hV+XHnzVqAEmicW7zyP77aPYRZm5S8p/OqwrwDLW3iXo0rLf9x1y +HRcMYibXlohzmN2fe13AmvzL7u4eNTkPCEl8sMlJhqG/wlgnfo8k1Jmwlhcfzq+4j/z 4JRszgvBDCVHJinC9a+mxzwmFGKedBVQeTReWVZfVup96gltz9qYOsRtn+ugQHeNGF+n eYDw== X-Gm-Message-State: AAQBX9fxt0PDpC0P61DtpCaW8F4dqqjc3T9L6RuAds+woVd8KYLCdiJB K0PIqJxXVKjCY1+BlW6fazS+R9Z/rDQyU//Jmw== X-Received: by 2002:a1c:6a04:0:b0:3ee:da1:1346 with SMTP id f4-20020a1c6a04000000b003ee0da11346mr4789907wmc.36.1680703560238; Wed, 05 Apr 2023 07:06:00 -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.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:00 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 45/88] gccrs: Rename header rust-hir-trait-ref.h to rust-hir-trait-reference.h Date: Wed, 5 Apr 2023 16:03:29 +0200 Message-Id: <20230405140411.3016563-46-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?1762347652963718626?= X-GMAIL-MSGID: =?utf-8?q?1762347652963718626?= From: Philip Herron Signed-off-by: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-hir-trait-ref.h: Moved to... * typecheck/rust-hir-trait-reference.h: ...here. * typecheck/rust-hir-trait-resolve.cc: refactor * typecheck/rust-hir-trait-resolve.h (RUST_HIR_TRAIT_RESOLVE_H): likewise * typecheck/rust-hir-type-check.h: likewise * typecheck/rust-tyty.cc: likewise --- ...rust-hir-trait-ref.h => rust-hir-trait-reference.h} | 0 gcc/rust/typecheck/rust-hir-trait-resolve.cc | 10 ++++++++++ gcc/rust/typecheck/rust-hir-trait-resolve.h | 9 +-------- gcc/rust/typecheck/rust-hir-type-check.h | 2 +- gcc/rust/typecheck/rust-tyty.cc | 2 +- 5 files changed, 13 insertions(+), 10 deletions(-) rename gcc/rust/typecheck/{rust-hir-trait-ref.h => rust-hir-trait-reference.h} (100%) diff --git a/gcc/rust/typecheck/rust-hir-trait-ref.h b/gcc/rust/typecheck/rust-hir-trait-reference.h similarity index 100% rename from gcc/rust/typecheck/rust-hir-trait-ref.h rename to gcc/rust/typecheck/rust-hir-trait-reference.h diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc index 19f95ca4488..e2d0cf2d7a2 100644 --- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc +++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc @@ -22,6 +22,16 @@ namespace Rust { namespace Resolver { +TraitItemReference +ResolveTraitItemToRef::Resolve ( + HIR::TraitItem &item, TyTy::BaseType *self, + std::vector substitutions) +{ + ResolveTraitItemToRef resolver (self, std::move (substitutions)); + item.accept_vis (resolver); + return std::move (resolver.resolved); +} + void ResolveTraitItemToRef::visit (HIR::TraitItemType &type) { diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.h b/gcc/rust/typecheck/rust-hir-trait-resolve.h index ca23d48c3dd..da8e2c0b838 100644 --- a/gcc/rust/typecheck/rust-hir-trait-resolve.h +++ b/gcc/rust/typecheck/rust-hir-trait-resolve.h @@ -19,9 +19,7 @@ #ifndef RUST_HIR_TRAIT_RESOLVE_H #define RUST_HIR_TRAIT_RESOLVE_H -#include "rust-hir-type-check-base.h" #include "rust-hir-type-check-type.h" -#include "rust-hir-trait-ref.h" namespace Rust { namespace Resolver { @@ -32,12 +30,7 @@ class ResolveTraitItemToRef : public TypeCheckBase, public: static TraitItemReference Resolve (HIR::TraitItem &item, TyTy::BaseType *self, - std::vector substitutions) - { - ResolveTraitItemToRef resolver (self, std::move (substitutions)); - item.accept_vis (resolver); - return std::move (resolver.resolved); - } + std::vector substitutions); void visit (HIR::TraitItemType &type) override; diff --git a/gcc/rust/typecheck/rust-hir-type-check.h b/gcc/rust/typecheck/rust-hir-type-check.h index d1eb750a621..512453947a6 100644 --- a/gcc/rust/typecheck/rust-hir-type-check.h +++ b/gcc/rust/typecheck/rust-hir-type-check.h @@ -22,7 +22,7 @@ #include "rust-hir-full-decls.h" #include "rust-hir-map.h" #include "rust-tyty.h" -#include "rust-hir-trait-ref.h" +#include "rust-hir-trait-reference.h" #include "rust-autoderef.h" namespace Rust { diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index 61c02a85c53..4c324c66c16 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -27,7 +27,7 @@ #include "rust-linemap.h" #include "rust-substitution-mapper.h" -#include "rust-hir-trait-ref.h" +#include "rust-hir-trait-reference.h" #include "rust-hir-type-bounds.h" #include "rust-hir-trait-resolve.h" #include "rust-tyty-rules.h" From patchwork Wed Apr 5 14:03: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: 79694 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp356086vqo; Wed, 5 Apr 2023 07:37:00 -0700 (PDT) X-Google-Smtp-Source: AKy350Zl2TJAiod/6Rl4Mpe6Q6jkcldwF5eeM76QhTxve6k/TGslvV35Qd7YTSaafSgcjf1nwvjM X-Received: by 2002:a17:906:a409:b0:92b:f8ce:4e75 with SMTP id l9-20020a170906a40900b0092bf8ce4e75mr3257669ejz.72.1680705420395; Wed, 05 Apr 2023 07:37:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705420; cv=none; d=google.com; s=arc-20160816; b=prsEGj/kLJtrVy8osSpwgiOt0AymcIGp9sl/0uhk7RqZ61W7QRMdreb85ZW9finexE fQSZy+xSPvw+kftH44ohHkxAztHZPob14BqB/+xSDcKl4lwhdAr8KeO5XQT+9Q1vY+/1 IPhisHSEdTVNznCkpGMbzNrjvcHuEdN3QQOJMCrxQygNFEAgnQn6DaVLK0hIbWdC/j80 TgCt86PGYKGezOTgWmUqdQ71tDQUpvcIJj89aCF1nVWt1VRqmkbWXnoXaMZIaiun43AW RVPPwcGKloniJ9yWBMMKfk2NNsnyTXShGEY01F0DXWKGxUH+LhEBreXlrHI6DrT+/H9W Jlgg== 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=iXqjus6/FsO2Nkxo1n686g5RhNiMOGUPKH7j5mkojD4=; b=lbSUDIBpR6FonrT8mxtoirDIFgix8Tc19hCxdL5GKxqMC6P/SJ6qrYII3QvGPNyAP5 fVZkn4kfZI6kQGBbS+2EMzat9LUg7yK5i+TMKzuXfBbKJmMJM3wDOSNT99VOpCv6+Kmj IEYIhyyIFOA7mQOcOSZvB8p6bm/qMEdCAmqwwnt/OV0P1K56eLnmxXDhEL90gIQkjVqO XOrrqiSEzhqpPGaL840YHVYl0IxwLv+qddSPIUDHwCjnigFekvX+45JjuwwqF2CRMkKq BK0rM3lU9g+RDA2vXtMSSIRomfn0PoUT6DChsACArBuBEvEwb4pTdcTXgwvIQKAlv5Dg vCOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=WD5rm9Ta; 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 rl3-20020a170907216300b00946f79be789si4141882ejb.985.2023.04.05.07.37.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:37:00 -0700 (PDT) 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=WD5rm9Ta; 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 71EA83952017 for ; Wed, 5 Apr 2023 14:14:00 +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 8309038708F1 for ; Wed, 5 Apr 2023 14:06:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8309038708F1 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 l12so36316149wrm.10 for ; Wed, 05 Apr 2023 07:06:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703561; 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=iXqjus6/FsO2Nkxo1n686g5RhNiMOGUPKH7j5mkojD4=; b=WD5rm9TajimmNg+zYV1xppepWtId6Qc1jyvv3JUXoWL2BMKO5mviMmKlTCeSGVydSO W0Gtkm1x2+nnAqPqniPC0PAESMgdRMASZ/sahXxM5DNrDlCb1Y9HgJBFlUL+met+Ymvg 3KdO9wHXV7SVgxqNrMSpxhrsQvFgpCOOSz0JP6xqKfAa37yhf1SQGeNlcAtTgwpYQh0v N1vooHcwkYBtiXHj5DY0TSWBdeQZqMHY+TvP+a836VMy0ilxUofXcB2ZAS9c7Dg4PLr7 cDXNf+XeuqLkfjzdMjKCZWUeebXU3MCXyiIMz1TVIJ9OMm1SaSiaXS65QvpHWeLj3M0V S0OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703561; 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=iXqjus6/FsO2Nkxo1n686g5RhNiMOGUPKH7j5mkojD4=; b=Hc4HuN11EtsZu32aLW0TlXtEVk51U9J6EPemKGReNLQ05sA+zPkjUItXS0tVQO0UU4 7Onlva2k5vKG1IeTptqbDglEgDI64oWjksOicO/gFDbLAKiOnbV2Qzn84jTyXnpvJ6dp PH6uF6y9Mbgwjfpb9gdHcnjSbDbKo62E20ud+7iq/sE3sz+Qar/+Rzx8pBHD0Ph2xhU0 nBl2nxDj76eOmDWLDBNrH1OVQ0KQUbU4SyEDupTOhPxisFhmJ0Ggp4ZnMJSaX8d2ayaI Se+A+TzuQizPqfMuEQJ5cAb8wT1+4iFNyfnbs21Q2th7Yuxlx9EEgTw+n5HB5lvDDZ97 UKKQ== X-Gm-Message-State: AAQBX9fEGcp5Stg1kR+6pauf4ubHPOG8B+M1RfibaK3PofDkdcw7sFfK 2TDRSFq9/k0kMdhA1rUl+v69eptbWu5t8OMwcw== X-Received: by 2002:a05:6000:11ce:b0:2e6:bff9:2634 with SMTP id i14-20020a05600011ce00b002e6bff92634mr3928628wrx.56.1680703561022; Wed, 05 Apr 2023 07:06:01 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:00 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 46/88] gccrs: Refactor handle_substitutions to take a reference Date: Wed, 5 Apr 2023 16:03:30 +0200 Message-Id: <20230405140411.3016563-47-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?1762347367088086492?= X-GMAIL-MSGID: =?utf-8?q?1762347367088086492?= From: Philip Herron This patch changes the recusive substitution code to take a reference instead of a copy. This is important as the callback field is going to be made non-copyable in a future patch and this pipeline is for recursive substitutions so its ok to reuse the same mappings here. Signed-off-by: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-tyty-bounds.cc: refactor to take a reference * typecheck/rust-tyty-subst.cc: likewise (SubstitutionRef::get_substitution_arguments): likewise (SubstitutionRef::infer_substitions): likewise * typecheck/rust-tyty-subst.h: likewise * typecheck/rust-tyty.cc (ADTType::handle_substitions): likewise (TupleType::handle_substitions): likewise (FnType::handle_substitions): likewise (ClosureType::handle_substitions): likewise (ArrayType::handle_substitions): likewise (SliceType::handle_substitions): likewise (ReferenceType::handle_substitions): likewise (PointerType::handle_substitions): likewise (ParamType::handle_substitions): likewise (ProjectionType::handle_substitions): likewise * typecheck/rust-tyty.h: likewise --- gcc/rust/typecheck/rust-tyty-bounds.cc | 2 +- gcc/rust/typecheck/rust-tyty-subst.cc | 10 ++++++++-- gcc/rust/typecheck/rust-tyty-subst.h | 5 +++-- gcc/rust/typecheck/rust-tyty.cc | 21 +++++++++++---------- gcc/rust/typecheck/rust-tyty.h | 22 +++++++++++----------- 5 files changed, 34 insertions(+), 26 deletions(-) diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc b/gcc/rust/typecheck/rust-tyty-bounds.cc index e7eb9a760f5..b14e0c68e5a 100644 --- a/gcc/rust/typecheck/rust-tyty-bounds.cc +++ b/gcc/rust/typecheck/rust-tyty-bounds.cc @@ -444,7 +444,7 @@ TypeBoundPredicate::is_error () const BaseType * TypeBoundPredicate::handle_substitions ( - SubstitutionArgumentMappings subst_mappings) + SubstitutionArgumentMappings &subst_mappings) { for (auto &sub : get_substs ()) { diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc b/gcc/rust/typecheck/rust-tyty-subst.cc index aceed29ff03..a5d738744fc 100644 --- a/gcc/rust/typecheck/rust-tyty-subst.cc +++ b/gcc/rust/typecheck/rust-tyty-subst.cc @@ -488,7 +488,13 @@ SubstitutionRef::was_substituted () const return !needs_substitution (); } -SubstitutionArgumentMappings +SubstitutionArgumentMappings & +SubstitutionRef::get_substitution_arguments () +{ + return used_arguments; +} + +const SubstitutionArgumentMappings & SubstitutionRef::get_substitution_arguments () const { return used_arguments; @@ -697,7 +703,7 @@ SubstitutionRef::infer_substitions (Location locus) SubstitutionArgumentMappings infer_arguments (std::move (args), {} /* binding_arguments */, locus); - return handle_substitions (std::move (infer_arguments)); + return handle_substitions (infer_arguments); } SubstitutionArgumentMappings diff --git a/gcc/rust/typecheck/rust-tyty-subst.h b/gcc/rust/typecheck/rust-tyty-subst.h index 4d09a3013e7..039eb36589e 100644 --- a/gcc/rust/typecheck/rust-tyty-subst.h +++ b/gcc/rust/typecheck/rust-tyty-subst.h @@ -199,7 +199,8 @@ public: bool was_substituted () const; - SubstitutionArgumentMappings get_substitution_arguments () const; + SubstitutionArgumentMappings &get_substitution_arguments (); + const SubstitutionArgumentMappings &get_substitution_arguments () const; // this is the count of type params that are not substituted fuly size_t num_required_substitutions () const; @@ -301,7 +302,7 @@ public: bool monomorphize (); // TODO comment - virtual BaseType *handle_substitions (SubstitutionArgumentMappings mappings) + virtual BaseType *handle_substitions (SubstitutionArgumentMappings &mappings) = 0; SubstitutionArgumentMappings get_used_arguments () const; diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index 4c324c66c16..a3271eb0d1a 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -1148,7 +1148,7 @@ handle_substitions (SubstitutionArgumentMappings &subst_mappings, } ADTType * -ADTType::handle_substitions (SubstitutionArgumentMappings subst_mappings) +ADTType::handle_substitions (SubstitutionArgumentMappings &subst_mappings) { ADTType *adt = static_cast (clone ()); adt->set_ty_ref (mappings->get_next_hir_id ()); @@ -1333,7 +1333,7 @@ TupleType::monomorphized_clone () const } TupleType * -TupleType::handle_substitions (SubstitutionArgumentMappings mappings) +TupleType::handle_substitions (SubstitutionArgumentMappings &mappings) { auto mappings_table = Analysis::Mappings::get (); @@ -1474,7 +1474,7 @@ FnType::monomorphized_clone () const } FnType * -FnType::handle_substitions (SubstitutionArgumentMappings subst_mappings) +FnType::handle_substitions (SubstitutionArgumentMappings &subst_mappings) { FnType *fn = static_cast (clone ()); fn->set_ty_ref (mappings->get_next_hir_id ()); @@ -1742,7 +1742,7 @@ ClosureType::monomorphized_clone () const } ClosureType * -ClosureType::handle_substitions (SubstitutionArgumentMappings mappings) +ClosureType::handle_substitions (SubstitutionArgumentMappings &mappings) { gcc_unreachable (); return nullptr; @@ -1862,7 +1862,7 @@ ArrayType::monomorphized_clone () const } ArrayType * -ArrayType::handle_substitions (SubstitutionArgumentMappings mappings) +ArrayType::handle_substitions (SubstitutionArgumentMappings &mappings) { auto mappings_table = Analysis::Mappings::get (); @@ -1945,7 +1945,7 @@ SliceType::monomorphized_clone () const } SliceType * -SliceType::handle_substitions (SubstitutionArgumentMappings mappings) +SliceType::handle_substitions (SubstitutionArgumentMappings &mappings) { auto mappings_table = Analysis::Mappings::get (); @@ -2704,7 +2704,7 @@ ReferenceType::monomorphized_clone () const } ReferenceType * -ReferenceType::handle_substitions (SubstitutionArgumentMappings mappings) +ReferenceType::handle_substitions (SubstitutionArgumentMappings &mappings) { auto mappings_table = Analysis::Mappings::get (); @@ -2870,7 +2870,7 @@ PointerType::monomorphized_clone () const } PointerType * -PointerType::handle_substitions (SubstitutionArgumentMappings mappings) +PointerType::handle_substitions (SubstitutionArgumentMappings &mappings) { auto mappings_table = Analysis::Mappings::get (); @@ -3047,7 +3047,7 @@ ParamType::is_equal (const BaseType &other) const } ParamType * -ParamType::handle_substitions (SubstitutionArgumentMappings subst_mappings) +ParamType::handle_substitions (SubstitutionArgumentMappings &subst_mappings) { SubstitutionArg arg = SubstitutionArg::error (); bool ok = subst_mappings.get_argument_for_symbol (this, &arg); @@ -3492,7 +3492,8 @@ ProjectionType::monomorphized_clone () const } ProjectionType * -ProjectionType::handle_substitions (SubstitutionArgumentMappings subst_mappings) +ProjectionType::handle_substitions ( + SubstitutionArgumentMappings &subst_mappings) { // // do we really need to substitute this? // if (base->needs_generic_substitutions () || base->contains_type_parameters diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index 85b3a3b7abc..1cf7131c1cb 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -304,7 +304,7 @@ public: bool is_concrete () const override final; - ParamType *handle_substitions (SubstitutionArgumentMappings mappings); + ParamType *handle_substitions (SubstitutionArgumentMappings &mappings); private: std::string symbol; @@ -379,7 +379,7 @@ public: std::string get_name () const override final; - TupleType *handle_substitions (SubstitutionArgumentMappings mappings); + TupleType *handle_substitions (SubstitutionArgumentMappings &mappings); private: std::vector fields; @@ -427,7 +427,7 @@ public: // WARNING THIS WILL ALWAYS RETURN NULLPTR BaseType * - handle_substitions (SubstitutionArgumentMappings mappings) override final; + handle_substitions (SubstitutionArgumentMappings &mappings) override final; bool is_error () const; @@ -682,7 +682,7 @@ public: } ADTType * - handle_substitions (SubstitutionArgumentMappings mappings) override final; + handle_substitions (SubstitutionArgumentMappings &mappings) override final; private: std::string identifier; @@ -815,7 +815,7 @@ public: } FnType * - handle_substitions (SubstitutionArgumentMappings mappings) override final; + handle_substitions (SubstitutionArgumentMappings &mappings) override final; ABI get_abi () const { return abi; } @@ -965,7 +965,7 @@ public: } ClosureType * - handle_substitions (SubstitutionArgumentMappings mappings) override final; + handle_substitions (SubstitutionArgumentMappings &mappings) override final; TyTy::TupleType &get_parameters () const { return *parameters; } TyTy::BaseType &get_result_type () const { return *result_type.get_tyty (); } @@ -1024,7 +1024,7 @@ public: HIR::Expr &get_capacity_expr () const { return capacity_expr; } - ArrayType *handle_substitions (SubstitutionArgumentMappings mappings); + ArrayType *handle_substitions (SubstitutionArgumentMappings &mappings); private: TyVar element_type; @@ -1070,7 +1070,7 @@ public: return get_element_type ()->is_concrete (); } - SliceType *handle_substitions (SubstitutionArgumentMappings mappings); + SliceType *handle_substitions (SubstitutionArgumentMappings &mappings); private: TyVar element_type; @@ -1321,7 +1321,7 @@ public: bool is_concrete () const override final; - ReferenceType *handle_substitions (SubstitutionArgumentMappings mappings); + ReferenceType *handle_substitions (SubstitutionArgumentMappings &mappings); Mutability mutability () const; @@ -1364,7 +1364,7 @@ public: bool is_concrete () const override final; - PointerType *handle_substitions (SubstitutionArgumentMappings mappings); + PointerType *handle_substitions (SubstitutionArgumentMappings &mappings); Mutability mutability () const; bool is_mutable () const; @@ -1500,7 +1500,7 @@ public: bool is_concrete () const override final; ProjectionType * - handle_substitions (SubstitutionArgumentMappings mappings) override final; + handle_substitions (SubstitutionArgumentMappings &mappings) override final; private: BaseType *base; From patchwork Wed Apr 5 14:03: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: 79695 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp356651vqo; Wed, 5 Apr 2023 07:37:44 -0700 (PDT) X-Google-Smtp-Source: AKy350Zq/HY0P23+hbVLEsfUhtsF4wHp4aQEmTbRb39t5rVmES/9ejDR51ojQal/2pf2oxgAeRi2 X-Received: by 2002:a17:906:368d:b0:8b1:7ead:7d43 with SMTP id a13-20020a170906368d00b008b17ead7d43mr2735294ejc.50.1680705464414; Wed, 05 Apr 2023 07:37:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705464; cv=none; d=google.com; s=arc-20160816; b=uE5JHZsyVWc+9deRxgNwn3AFPxc/B5Eyj7aLsvM2zqF4c0nIXBF+cp5KrDSLebzmza qbNDpYGMMEbEexSYxZvTEFchG4RyMtDvFgODhY1bmtFM41IFj+W2wkqLwD87otDwHOH+ mO180Kg9yrGeiNAykXxkSMELbaqiXE78JXHMo4tm7o8PcdXkyA0Pcg5ccx/8xb+O+ebC lHyw7sVFHklPsOG+XNVm8cuni4/VZZns1EsfVyG74aotRsF05KCpvxNW3kehwkUK7xAc OTTTEkkw6rOVZELkXPrO8KfHFI1bUk/RrfagR2Bk2KPL3ek4ojxv86Sv3hWl9/QeKf1O Noew== 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=n74sdHS4RZyf/z/uHtJkJ4OHdmNcbh3i7u3F9PddgvI=; b=yk385Hc4TokMfgfYXupZVlj64b8uat6dIs8u30EurwoCt3ZkUQjrZlnDntqwFyFY02 3W0p5YBK4rxVXdP7FXhtVST/mPLbFTQOjRmYY8r9T1qv61xkJzwIreVCDHLhqIaohrNy ujqaxaD88dX5uYUUJcH8p2pSwGcsYMyFVWYaXn7w+wAtx0QoPTmb9TCZCmgAAz7FtgZa oKDeDl/sHL2B9c5ePXki/Ud9pfxowNE682qYYEGl83GhnY3UKpfx+Mm3yp3euNd4dCfb sioFWJpBhk5g587KalXrLAidJZDRSg6qzDJUNFzF2j/MycKk/+QZ7TED1f9edUextL/A GHtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=OxZYSnVU; 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 l19-20020a170906645300b00946a18bb2dfsi12898437ejn.986.2023.04.05.07.37.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:37:44 -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=OxZYSnVU; 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 0513238CBDA6 for ; Wed, 5 Apr 2023 14:14:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 831AD3854173 for ; Wed, 5 Apr 2023 14:06:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 831AD3854173 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-x331.google.com with SMTP id n10-20020a05600c4f8a00b003ee93d2c914so23482595wmq.2 for ; Wed, 05 Apr 2023 07:06:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703562; 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=n74sdHS4RZyf/z/uHtJkJ4OHdmNcbh3i7u3F9PddgvI=; b=OxZYSnVU7+I0z89DcsrOHDvXZ9WZQlgaj1LF9hfm4nfoYx0Jkd4l1bw7cGzAAV4yjt DIB6i0NFp2qtTipTyb2Z6RiKWMWhZ/6t2OmKo8/Uy1glSwV0VIucDIGRfSOfCmKOgbGz b59G3x7oQO3xi4/8XFtkm9sCSOJAF7lYqx7edXb6Z/kBJz90yNBY//iOkr0RLuRWnk4O JjLtZjIVfR15IhkzTyN1ZESKTjfVbXladoG8b/3AtxYf2WNu3AGAYNuDWCL881uDkpo7 iZLiSZrkoWPJ9X/jrdfEd+1QrmnA5GAAnM5mzKCVXTCv7O+je74O1Boyc5eLCn0OUXcE rRGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703562; 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=n74sdHS4RZyf/z/uHtJkJ4OHdmNcbh3i7u3F9PddgvI=; b=VW/6Q7F9eB8Uk2PG5W86siIdmb/1cLX3qNjJoIbVI+lM7pjatlp5v/+jBZXZzEPIsm GSFjDv3ZMy0KkQGORFOjNaPEj0XfGFwCCT6pBrboXsOemeXFPNksBUL0UnJI9PD/zm5E UvfL/QIoRrM+f+3c5dp+9xf7scMJ8+Z5KPjQGYGobBadrDajI1xNHw+Ce6Bclu+7efGb 7btCYyk30yG5kWaWsRp/Y7EKdzxKQcAUg4NComZkNgx4OpHG4vpB5RMlKm9K9ij1FaFg FLcY2SYLQ2RXYwVhpj9cZ8eGZ3UsxY/Ga8+4nP4inMAqE0/TpoGGw5DPp0lQtETZIX7j u/UQ== X-Gm-Message-State: AAQBX9eVRn1Kllzoujo/tMBO3RVHyavmajENTyAliOHJpXvXynPlB57o 6wA50ENBgLOofCVHWEmhxatj255anneq1B9YQg== X-Received: by 2002:a1c:4c09:0:b0:3ee:289a:3c3a with SMTP id z9-20020a1c4c09000000b003ee289a3c3amr4998761wmf.30.1680703561750; Wed, 05 Apr 2023 07:06:01 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:01 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 47/88] gccrs: Clear the substitution callbacks when copying ArgumentMappings Date: Wed, 5 Apr 2023 16:03:31 +0200 Message-Id: <20230405140411.3016563-48-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.6 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?1762347413261228730?= X-GMAIL-MSGID: =?utf-8?q?1762347413261228730?= From: Philip Herron When we set the callback on substitutions this is not safe to be copied around since we store the used argument mappings and can reuse them in different contexts. This clears the callback on copy's to make it safer. Signed-off-by: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-tyty-subst.cc: update copy constructors --- gcc/rust/typecheck/rust-tyty-subst.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc b/gcc/rust/typecheck/rust-tyty-subst.cc index a5d738744fc..0e181efb359 100644 --- a/gcc/rust/typecheck/rust-tyty-subst.cc +++ b/gcc/rust/typecheck/rust-tyty-subst.cc @@ -241,7 +241,7 @@ SubstitutionArgumentMappings::SubstitutionArgumentMappings ( SubstitutionArgumentMappings::SubstitutionArgumentMappings ( const SubstitutionArgumentMappings &other) : mappings (other.mappings), binding_args (other.binding_args), - locus (other.locus), param_subst_cb (other.param_subst_cb), + locus (other.locus), param_subst_cb (nullptr), trait_item_flag (other.trait_item_flag) {} @@ -252,7 +252,7 @@ SubstitutionArgumentMappings::operator= ( mappings = other.mappings; binding_args = other.binding_args; locus = other.locus; - param_subst_cb = other.param_subst_cb; + param_subst_cb = nullptr; trait_item_flag = other.trait_item_flag; return *this; From patchwork Wed Apr 5 14:03: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: 79711 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp360491vqo; Wed, 5 Apr 2023 07:43:47 -0700 (PDT) X-Google-Smtp-Source: AKy350bosZ5m6y/qcZVxOfqIxuzCp311LPQ0TIrniRrWhpxGuI6rIv3wjBgDcG/mcXYJjKuOcweG X-Received: by 2002:a05:6402:654:b0:502:3ff1:2fcc with SMTP id u20-20020a056402065400b005023ff12fccmr2242300edx.35.1680705826846; Wed, 05 Apr 2023 07:43:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705826; cv=none; d=google.com; s=arc-20160816; b=UFLuJb4K6JIz2speb2aFl9+DlY3hVeTHKpst7a4iMATJH/vQ5Wg2EyPEV8Fuwu9DXp 32tM90rccRXorSIk913tsYD+MUbInShW8Was7QeEu1keQhXC2b2u3Ds+tkmBPoCJLgEj B0aJ3vFIZZymWL4xOdXSpcifwD5QOgGZx6vy9CPHZLMxJ6Znd+9AwRcaB/67vAow0XrY s2OgRb4Mcr+qZSwzrmZu8F9MTzYjQKRm+HJ5J/nu+6/NWscuyomaPtI6YdQbI0SyP46A PJUjaRANPK0xzmo/0fA/7b+hl++FLZ+MSMiZ8tg3AWuiUMR8mN6V0kW8TZzL03Yq+SKf h5lg== 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=Mb5qvdVslh7GngkFDLyFsB3O6jm5Rm0uvdDwzPQkvXY=; b=n55kftgXp4HGaU0OmJvPXe5xgRtjej2FsLD+vXsp5mDSBl2PzlcXROmMxH3egP448r Avm+LrcDIRiUOfic1yipShZ/IU51DxeziBWc9pj9xasKb/ErVbgKIOPcyTbEoszBciwO jD9xfnQaWCKE4ekc7m03x//pxy63cvswOz4RfYJHRHZZktU8ZvRof72LAEyMeC6G6kHr eeLMqZ0GP6LO+6196AMvwit4trJSah0POhDU7OoJt5iNwjMrTvUrIJKoMrqU+pkDlwj3 XXj8Am3izxJTs6yVGqZz5BF7eqAkarlNEwvAPFqH/1zU/OpixfeunL8ZZCv7BWGdxLB2 AB3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=MrxeTN41; 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 d21-20020a50fb15000000b0050245e74178si4945564edq.541.2023.04.05.07.43.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:43:46 -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=MrxeTN41; 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 4DB6539579C1 for ; Wed, 5 Apr 2023 14:15:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id 0679E3850417 for ; Wed, 5 Apr 2023 14:06:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0679E3850417 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-x32c.google.com with SMTP id s13so20939968wmr.4 for ; Wed, 05 Apr 2023 07:06:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703562; 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=Mb5qvdVslh7GngkFDLyFsB3O6jm5Rm0uvdDwzPQkvXY=; b=MrxeTN41UukDiD/bGIQYq47p6T2UonxbST7aCbSKSykbvacc49oeHV8ZGuDj6r4W4d LP6U/Wy5e2FI8DBErx/0yzLVw4ZINrdMDpN9M4wczSBQvnSkjJUi7e2q+rZla2AmxSuQ 4dq8eOXDiCet2nYCKwCPCH8NXHB4icqNIlJcjJ9lOLfHNgym03YfRKvTtlICpAH0Ftfm e4TcSia4zMquCEfd3ye1KlayxWfhlmZbpTrgDJJf+w1aqUmAqebCYztY76uECG/BIQ0I MZyi6zLwhAnUk2Hs3Sv78bFll/jMzIKt2Z0dEQOOJZwdMWkXNemuRhYW5HDqT1KB0QGw HAnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703562; 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=Mb5qvdVslh7GngkFDLyFsB3O6jm5Rm0uvdDwzPQkvXY=; b=IGfYCh9OKn0PzOnNZVckOO2l8IJ88WPBFlKYViyUQfptvfTCU7eDUMQdBNnBgJ2BPW 9xRGt4BakGog+i8fv5eMG/2laH3aIo6DjOquMT+2RQsA5FQWodbeP0e0UWlqJEqrDFVm kEFzhK3F8sHh4kAMTub3f1Zeg5tkDX8RpI/mOt/ucjoHTka3Saz4tKzCp1BIvHllwh7Y WJpGbnMglxcmU4exPbr7wZ0MG6AUaBGfCsCFLC77X/POCI7gtrrkCvY2xdcfZ1lWQmyQ yvHBrEnwuHClQ9qNDC6q3Tx3cIGaXq/XEWyAWAP+K3+7zTaVsFHVxtrG30vL8tOY5xbr 4apg== X-Gm-Message-State: AAQBX9c5QXRUVtBU2WlIKaN6Fp8rwy7E1MLmyyTzvoNdRmn3K3b1CZ5H ATyZTyvLkra9w/MubYpQlolqXzFTj79Oz4epcg== X-Received: by 2002:a05:600c:290b:b0:3ed:4627:ed09 with SMTP id i11-20020a05600c290b00b003ed4627ed09mr4584920wmd.28.1680703562436; Wed, 05 Apr 2023 07:06:02 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:02 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 48/88] gccrs: Add missing param subst callback Date: Wed, 5 Apr 2023 16:03:32 +0200 Message-Id: <20230405140411.3016563-49-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.6 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?1762347793473211242?= X-GMAIL-MSGID: =?utf-8?q?1762347793473211242?= From: Philip Herron Signed-off-by: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-tyty-subst.cc: add missing callback --- gcc/rust/typecheck/rust-tyty-subst.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc b/gcc/rust/typecheck/rust-tyty-subst.cc index 0e181efb359..7f5bb22687d 100644 --- a/gcc/rust/typecheck/rust-tyty-subst.cc +++ b/gcc/rust/typecheck/rust-tyty-subst.cc @@ -141,6 +141,7 @@ SubstitutionParamMapping::fill_param_ty ( bound.handle_substitions (subst_mappings); param->set_ty_ref (type.get_ref ()); + subst_mappings.on_param_subst (*param, arg); } return true; From patchwork Wed Apr 5 14:03: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: 79698 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp357572vqo; Wed, 5 Apr 2023 07:39:10 -0700 (PDT) X-Google-Smtp-Source: AKy350Y6rzu6B++yojuMjk/kepFXT0E+LF3ESBCy75VII/dmYl6ILdZ3CD4ycljfObYaO7pU8m2L X-Received: by 2002:a05:6402:160f:b0:502:9c52:4482 with SMTP id f15-20020a056402160f00b005029c524482mr2276419edv.6.1680705550662; Wed, 05 Apr 2023 07:39:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705550; cv=none; d=google.com; s=arc-20160816; b=GB5vNBXXit27EE9vzxa/WN5Msx6XLNZONhRoXArS08x8yR1kvwYVkmb9nMuAoZcGV8 9AkgkeJewUOtXXYZHx4P3ZI3gy8SIS/P8SU6Jg4Zffi7A1f2iJQ64OCeoZK5YimC9lRF hItLe2WLF8IIAmu2uTShXx+6whwDJGRD6rzWVvbSZcaFfp54/lsoPq8iVid4xy3sOgKb /5amS998586oMlj754ysLyN1zz3/Bcfgr1scXs619hLW04q7awg2V1i82XNXc5Zis78U WNtEUBen+1n3vT4Lx5lJSeKYl5mNrhhl36EIY2tTQgU0kURiNRrabZ2sQTt9Pe/L4YeZ I90g== 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=V7WX+KkTwVqPGkhibX5iqKa4Qqgwekjer3Rw/oVeLRc=; b=SmFGKIELpH3APxPDp3gcZLXFIHCraqma32LjGpDU5Wm0X4ack9y7uInMU0PZp7Nb1U rh+1uqzf/HKEg/2kqMKeLW8FN/Nf06u9EURgkGrjO3VrWCS4QVYt7B0roiVpj3UrZpaB Y+sJL9xjs/DBMMO2YwTM1kqV4L4L67cRApiCxssh1h7Yi35fD1gQYrowEXxPiplc6isE 6yqXV1JpcE/BcUkF1o/GCKwx7IJdsl0J8rHNavh815Du744CANWVFn8gTAGbkLO1uSHB ktZGNI1Dj7lf6/WKqGxKVrcbD8qXa/xy5C8P25LuLLwEqW2DP0wyXheiE5dNvC/NAXBW 9XnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=V8jxkL+c; 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 v7-20020aa7d647000000b004c0abff5545si8713636edr.614.2023.04.05.07.39.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:39:10 -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=V8jxkL+c; 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 690F839AFFE5 for ; Wed, 5 Apr 2023 14:14:31 +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 B22313870D53 for ; Wed, 5 Apr 2023 14:06:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B22313870D53 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 s13so20940006wmr.4 for ; Wed, 05 Apr 2023 07:06:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703563; 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=V7WX+KkTwVqPGkhibX5iqKa4Qqgwekjer3Rw/oVeLRc=; b=V8jxkL+camAKVaCEwCJpeVfvKnYHa1c4NTdATa+ZBn4d78ru8cXPA8IQMn6LPN6dxO FX9caVTIB9YEccWQUHxdSHgfk2QxUkipUHcNCvCSFVEpBPq1wI7R1wjtzTSs4XpiY7WF jOy36B6q7bc2tYrG24chmERPApx2mD+N1Uy3w3/TDJjQqV9AzULzHp2YeeDx7bxjsbRf EeqDGCNFIlwevkp+t9f+9m1Tmwmv14G733aj/Cs2c39InQDp8HCotqGMom2qnG9sDWDP JmMcnQe+SjwFNbmuoIp7j1aUzmIqCcFAYZ3ucQt3WnUHF+UYdeh8Zwk++SmrEC7BrFJ9 LOSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703563; 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=V7WX+KkTwVqPGkhibX5iqKa4Qqgwekjer3Rw/oVeLRc=; b=iM1t7LVCxvXjQZbtT0kpE/W3H2NCAyzl9+g5XLIAkFeFQmLG/VTsYGI5PSYRkxGRo/ NXOdZQ1MFYi+OSa6aOdEca47fcflBVgCYB02VKtKT9j3xd4/8b6bd4tfSoZo9dEKygBa JVvUv28lvW//p0p2+3WrV/ScLauGjSZBWwJ/te10ed4PnfKuJwd6C2GsDjrIRKa6Hysb LkyCV7U6oXjafO1TQzwxfVf0GHa5YQ79XIGkG1wmic+J+C/G2xi28FUGMR9/A+kYv08m mhfck4BHDgfAIJDN9l+mTnP2LveSWVdfRbJLB/eZ21d4gRpxeEclu8+X50kgyKd8JPj3 M17g== X-Gm-Message-State: AAQBX9fFpZn7Z8tw56BHYY9H/pbT+pc2kSz99SA6Y/X3ifgOiASp0Cn2 sfkTIcoW9dK8m/Oss6cpDU7Ad38lRhWoFvPbNw== X-Received: by 2002:a7b:c384:0:b0:3e9:f15b:935b with SMTP id s4-20020a7bc384000000b003e9f15b935bmr4677664wmj.32.1680703563004; Wed, 05 Apr 2023 07:06:03 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:02 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 49/88] gccrs: Remove monomorphization hack to setup possible associated types Date: Wed, 5 Apr 2023 16:03:33 +0200 Message-Id: <20230405140411.3016563-50-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.6 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?1762347503546891369?= X-GMAIL-MSGID: =?utf-8?q?1762347503546891369?= From: Philip Herron During CallExpr argument type checking we may be calling a default implementation of a trait function this will require any possible associated types to be resolved and setup. This monomoprhization call does this but it will premtivly do extra unification of types which will throw off type checking later on. This fix is required for my work into type bounds checking. Fixes #1773 Signed-off-by: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-hir-trait-reference.h: change interface to return self * typecheck/rust-hir-trait-resolve.cc: likewise * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): likewise * typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): remove monomorphization hack gcc/testsuite/ChangeLog: * rust/compile/issue-1773.rs: New test. --- gcc/rust/typecheck/rust-hir-trait-reference.h | 5 +-- gcc/rust/typecheck/rust-hir-trait-resolve.cc | 10 +++--- .../typecheck/rust-hir-type-check-path.cc | 36 ++++++++++++++----- gcc/rust/typecheck/rust-tyty-call.cc | 1 - gcc/testsuite/rust/compile/issue-1773.rs | 20 +++++++++++ 5 files changed, 56 insertions(+), 16 deletions(-) create mode 100644 gcc/testsuite/rust/compile/issue-1773.rs diff --git a/gcc/rust/typecheck/rust-hir-trait-reference.h b/gcc/rust/typecheck/rust-hir-trait-reference.h index 0df35265959..9b4461b9f18 100644 --- a/gcc/rust/typecheck/rust-hir-trait-reference.h +++ b/gcc/rust/typecheck/rust-hir-trait-reference.h @@ -497,8 +497,9 @@ public: TyTy::BaseType *get_self () { return self; } - void setup_associated_types (const TyTy::BaseType *self, - const TyTy::TypeBoundPredicate &bound); + TyTy::BaseType * + setup_associated_types (const TyTy::BaseType *self, + const TyTy::TypeBoundPredicate &bound); void reset_associated_types (); diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc index e2d0cf2d7a2..6e23093eceb 100644 --- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc +++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc @@ -377,13 +377,10 @@ TraitItemReference::associated_type_reset () const placeholder->clear_associated_type (); } -void +TyTy::BaseType * AssociatedImplTrait::setup_associated_types ( const TyTy::BaseType *self, const TyTy::TypeBoundPredicate &bound) { - if (!bound.contains_associated_types ()) - return; - // compute the constrained impl block generic arguments based on self and the // higher ranked trait bound TyTy::BaseType *receiver = self->clone (); @@ -486,6 +483,7 @@ AssociatedImplTrait::setup_associated_types ( TyTy::TyWithLocation (receiver), TyTy::TyWithLocation (impl_self_infer), impl_predicate.get_locus ()); rust_assert (result->get_kind () != TyTy::TypeKind::ERROR); + TyTy::BaseType *self_result = result; // unify the bounds arguments std::vector hrtb_bound_arguments; @@ -500,7 +498,7 @@ AssociatedImplTrait::setup_associated_types ( } if (impl_trait_predicate_args.size () != hrtb_bound_arguments.size ()) - return; + return self_result; for (size_t i = 0; i < impl_trait_predicate_args.size (); i++) { @@ -554,6 +552,8 @@ AssociatedImplTrait::setup_associated_types ( resolved_trait_item->associated_type_set (substituted); }); iter.go (); + + return self_result; } void diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc index 6f1fd416c19..9d9b2949944 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-path.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc @@ -379,16 +379,36 @@ TypeCheckExpr::resolve_segments (NodeId root_resolved_node_id, if (associated_impl_block != nullptr) { - // get the type of the parent Self - HirId impl_ty_id - = associated_impl_block->get_type ()->get_mappings ().get_hirid (); + // associated types + HirId impl_block_id + = associated_impl_block->get_mappings ().get_hirid (); + + AssociatedImplTrait *associated = nullptr; + bool found_impl_trait + = context->lookup_associated_trait_impl (impl_block_id, + &associated); TyTy::BaseType *impl_block_ty = nullptr; - bool ok = query_type (impl_ty_id, &impl_block_ty); - rust_assert (ok); + if (found_impl_trait) + { + TyTy::TypeBoundPredicate predicate (*associated->get_trait (), + seg.get_locus ()); + impl_block_ty + = associated->setup_associated_types (prev_segment, predicate); + } + else + { + // get the type of the parent Self + HirId impl_ty_id = associated_impl_block->get_type () + ->get_mappings () + .get_hirid (); - if (impl_block_ty->needs_generic_substitutions ()) - impl_block_ty - = SubstMapper::InferSubst (impl_block_ty, seg.get_locus ()); + bool ok = query_type (impl_ty_id, &impl_block_ty); + rust_assert (ok); + + if (impl_block_ty->needs_generic_substitutions ()) + impl_block_ty + = SubstMapper::InferSubst (impl_block_ty, seg.get_locus ()); + } prev_segment = unify_site (seg.get_mappings ().get_hirid (), TyTy::TyWithLocation (prev_segment), diff --git a/gcc/rust/typecheck/rust-tyty-call.cc b/gcc/rust/typecheck/rust-tyty-call.cc index d520b595e43..4c6442e2d82 100644 --- a/gcc/rust/typecheck/rust-tyty-call.cc +++ b/gcc/rust/typecheck/rust-tyty-call.cc @@ -85,7 +85,6 @@ TypeCheckCallExpr::visit (ADTType &type) void TypeCheckCallExpr::visit (FnType &type) { - type.monomorphize (); if (call.num_params () != type.num_params ()) { if (type.is_varadic ()) diff --git a/gcc/testsuite/rust/compile/issue-1773.rs b/gcc/testsuite/rust/compile/issue-1773.rs new file mode 100644 index 00000000000..c627ac09cec --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-1773.rs @@ -0,0 +1,20 @@ +trait Foo { + type A; + + fn test(a: Self::A) -> Self::A { + a + } +} + +struct Bar(T); +impl Foo for Bar { + type A = T; +} + +fn main() { + let a; + a = Bar(123); + + let b; + b = Bar::test(a.0); +} From patchwork Wed Apr 5 14:03: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: 79715 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp362038vqo; Wed, 5 Apr 2023 07:46:13 -0700 (PDT) X-Google-Smtp-Source: AKy350ay/MnySfOBjnsVm9cGrCeePqMjt1LvSrFv9sDVKaXOdjEQWV61Jw5b9CfUKZKliQQIHv/g X-Received: by 2002:a17:906:6d6:b0:8f6:5a70:cccc with SMTP id v22-20020a17090606d600b008f65a70ccccmr3400686ejb.66.1680705973698; Wed, 05 Apr 2023 07:46:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705973; cv=none; d=google.com; s=arc-20160816; b=JJL0dnfk1N12FO60zGCSZ3g/km6MHskJxv+cPz3K0/VkF5i70TrwZ4fs3NZzF9f4I0 lohUmSxrTT3A59Z2vaCpooibqN4KZlN4fODNuqhJRcpnXGopeOspdBo95SnRqc0lzFOp rvDeu3S2MU+DXTTRU2u+0vrqsDeSEX0YWu0l0UIRHA/ti5vvAN5e6mbMUqkh9gNKUHW0 Zckka3y9xT47YFx/MoWoUt78jC/TlPgRwCGBqHPaX9KdSW154WX8Wtjw05x0rHro/cP9 SYguYhB2/OezQ4gbbXIYvL8pF94PMT9HJP5SReoisDuEv287DNByuneIVjVtUvgJ8Lyx plcg== 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=TPAVMNhi8KIDS5nM/JlCR+qN8Hui31lYY30a4DrlLWg=; b=sm2XbpwQbtRDq7IwO0Wq3ncwGZnRzy9wch2Kzp3/FT2cHT3T6GCpAcMjc2dVJjIkqw gb218pnqVhFXGYwckgw0gKcXp8yJkZ+5LNawnRqwCfgeglfo0BlfQgL+VUHXgXBWEiHS iBGCPRA317WbsZy5tAcv3ZebzNYddcU/fTDkBdRRsPIp98Y7wkdGV253Oe1DwC47ipM1 bGNESEKm+Y9rXiszEdSZGGo3B2HD6I2O8aWNVxjALQDUxtRTIqirXNTTWEch/Fpb8UoI qMyIxsIqijBvyQIi0W6j+SjYTMf2tnq2iZGmkoFPoUR9noNlq7RdQ6CaeoNQf1KfjLbO cc+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Fj7y0DQO; 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 hh9-20020a170906a94900b00939c3d2329csi638902ejb.396.2023.04.05.07.46.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:46:13 -0700 (PDT) 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=Fj7y0DQO; 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 444DE39E33E2 for ; Wed, 5 Apr 2023 14:16:36 +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 E128C3877039 for ; Wed, 5 Apr 2023 14:06:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E128C3877039 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 p34so20958592wms.3 for ; Wed, 05 Apr 2023 07:06:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703565; 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=TPAVMNhi8KIDS5nM/JlCR+qN8Hui31lYY30a4DrlLWg=; b=Fj7y0DQOz/mxkflaMT3GvbEfPUXt8DZUNvTL/XOSKkPwVTPTSbI8PVr9p1UF/FVpT3 0QsNcT6FYE1aCmq5q2uEInnJJZCv++ifCMa7+YpcrCYKNt5G7Bd+kvIId4XBnLg5F2j2 manbUm+CXjQt8lwpJTm1nFV+pwS/neWVz4xlhFREwW/+onENcokUuW6yVHtcPXlxvuvR QrkMMBCpj8qfSn2qDAKP4ClFphTwv6PVzz5AABIAce3N5SPMjfC2WYYEJV8TfjhCxCy4 81jwWJjuYtl9tR8vSOAhPS52Rx5mx318SyxL9r1rufwVeKS2k9Vz6C3kl90EkIS4hS3u HOKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703565; 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=TPAVMNhi8KIDS5nM/JlCR+qN8Hui31lYY30a4DrlLWg=; b=mRl12JeXfVIZvvBmRsXzJRrh6pEgI1IaBVCne4h8ryMhqtmrnuMHzYFwKgK14nN2k+ LkcyqFAg+hOahreAZneCQerQdi0MF2u2JAE3x+enYHgvopLlmhF0TbpkY2q1WERh/4C/ osrNisIpp3PSuLKUx/4QlVR3pxfGk6TEQ91VYpVy9rdxyh4SrxVuv3e8YIcCYRBqMr6i W4ng/FR6c/mLmks66pbU1qvh5yMZdyfD0ibbqC91In/E45/VkOSefEYk2DsIql9QbKy1 U4H8CJr2pBGKo/jqgQM6dGe2D6ctW81Rlgw365wfk/z9a9gwwRIJS6x1PKlt6w50IWxS hBww== X-Gm-Message-State: AAQBX9cFpYK3Gv/16jlN0ErYqYAmDr6rN6tF+a1L9DY1Tc018kHFdQFU LhvceLjDWwf5zhALM9zR/enxFhSMFfo3IAcBXQ== X-Received: by 2002:a05:600c:2909:b0:3ef:d6be:897a with SMTP id i9-20020a05600c290900b003efd6be897amr4697816wmd.16.1680703563734; Wed, 05 Apr 2023 07:06:03 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:03 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 50/88] gccrs: Refactor the type unification code Date: Wed, 5 Apr 2023 16:03:34 +0200 Message-Id: <20230405140411.3016563-51-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.6 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?1762347946788094086?= X-GMAIL-MSGID: =?utf-8?q?1762347946788094086?= From: Philip Herron This refactors the unification systems to be a consistent interface using switch statements and simple functions instead of the old clunky visitor system. This is more maintainable as it is harder to miss cases when we can take advantages of switch statements. Signed-off-by: Philip Herron gcc/rust/ChangeLog: * Make-lang.in: update names * backend/rust-compile-expr.cc (CompileExpr::resolve_method_address): update to use new interface * typecheck/rust-coercion.cc (TypeCoercionRules::coerce_borrowed_pointer): likewise * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::unify_site): likewise * typecheck/rust-tyty.cc (BaseType::destructure): likewise (InferType::unify): removed old unify interface (ErrorType::unify): likewise (ADTType::unify): likewise (TupleType::unify): likewise (FnType::unify): likewise (FnPtr::unify): likewise (ClosureType::unify): likewise (ArrayType::unify): likewise (SliceType::unify): likewise (BoolType::unify): likewise (IntType::unify): likewise (UintType::unify): likewise (FloatType::unify): likewise (USizeType::unify): likewise (ISizeType::unify): likewise (CharType::unify): likewise (ReferenceType::unify): likewise (PointerType::unify): likewise (ParamType::unify): likewise (StrType::unify): likewise (NeverType::unify): likewise (PlaceholderType::unify): likewise (ProjectionType::unify): likewise (DynamicObjectType::unify): likewise * typecheck/rust-tyty.h: update destructure interface * typecheck/rust-tyty-rules.h: Removed. * typecheck/rust-unify.cc: New file. * typecheck/rust-unify.h: New file. gcc/testsuite/ChangeLog: * rust/compile/never_type_err1.rs: Moved to... * rust/compile/never_type1.rs: ...here. It now works --- gcc/rust/Make-lang.in | 1 + gcc/rust/backend/rust-compile-expr.cc | 6 +- gcc/rust/typecheck/rust-coercion.cc | 6 +- .../typecheck/rust-hir-type-check-base.cc | 15 +- gcc/rust/typecheck/rust-tyty-rules.h | 1406 -------------- gcc/rust/typecheck/rust-tyty.cc | 229 +-- gcc/rust/typecheck/rust-tyty.h | 31 +- gcc/rust/typecheck/rust-unify.cc | 1640 +++++++++++++++++ gcc/rust/typecheck/rust-unify.h | 91 + .../{never_type_err1.rs => never_type1.rs} | 3 +- 10 files changed, 1807 insertions(+), 1621 deletions(-) delete mode 100644 gcc/rust/typecheck/rust-tyty-rules.h create mode 100644 gcc/rust/typecheck/rust-unify.cc create mode 100644 gcc/rust/typecheck/rust-unify.h rename gcc/testsuite/rust/compile/{never_type_err1.rs => never_type1.rs} (52%) diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index 4752bb83562..1d2f34d7919 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -134,6 +134,7 @@ GRS_OBJS = \ rust/rust-hir-path-probe.o \ rust/rust-coercion.o \ rust/rust-casts.o \ + rust/rust-unify.o \ rust/rust-hir-type-check-base.o \ rust/rust-autoderef.o \ rust/rust-substitution-mapper.o \ diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index c26f6f440ec..d7945dbf26b 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -26,6 +26,7 @@ #include "rust-compile-block.h" #include "rust-compile-implitem.h" #include "rust-constexpr.h" +#include "rust-unify.h" #include "rust-gcc.h" #include "fold-const.h" @@ -2006,7 +2007,10 @@ CompileExpr::resolve_method_address (TyTy::FnType *fntype, HirId ref, { TyTy::BaseType *infer_impl_call = candidate_call->infer_substitions (expr_locus); - monomorphized = infer_impl_call->unify (fntype); + monomorphized = Resolver::UnifyRules::Resolve ( + TyTy::TyWithLocation (infer_impl_call), + TyTy::TyWithLocation (fntype), expr_locus, true /* commit */, + true /* emit_errors */); } return CompileInherentImplItem::Compile (impl_item, ctx, monomorphized); diff --git a/gcc/rust/typecheck/rust-coercion.cc b/gcc/rust/typecheck/rust-coercion.cc index fdf8eb95a33..bea40840fbf 100644 --- a/gcc/rust/typecheck/rust-coercion.cc +++ b/gcc/rust/typecheck/rust-coercion.cc @@ -18,6 +18,7 @@ #include "rust-hir-type-check-base.h" #include "rust-coercion.h" +#include "rust-unify.h" namespace Rust { namespace Resolver { @@ -218,7 +219,10 @@ TypeCoercionRules::coerce_borrowed_pointer (TyTy::BaseType *receiver, // we might be able to replace this with a can_eq because we default // back to a final unity anyway rust_debug ("coerce_borrowed_pointer -- unify"); - TyTy::BaseType *result = receiver->unify (expected); + TyTy::BaseType *result + = UnifyRules::Resolve (TyTy::TyWithLocation (receiver), + TyTy::TyWithLocation (expected), locus, + true /* commit */, true /* emit_errors */); return CoercionResult{{}, result}; } } diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc b/gcc/rust/typecheck/rust-hir-type-check-base.cc index 85826aec8fe..6e42b7b7b23 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-base.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc @@ -22,6 +22,7 @@ #include "rust-hir-type-check-expr.h" #include "rust-hir-type-check-implitem.h" #include "rust-coercion.h" +#include "rust-unify.h" #include "rust-casts.h" namespace Rust { @@ -359,18 +360,8 @@ TypeCheckBase::unify_site (HirId id, TyTy::TyWithLocation lhs, rust_debug ("unify_site id={%u} expected={%s} expr={%s}", id, expected->debug_str ().c_str (), expr->debug_str ().c_str ()); - TyTy::BaseType *unified = expected->unify (expr); - if (unified->get_kind () == TyTy::TypeKind::ERROR) - { - RichLocation r (unify_locus); - r.add_range (lhs.get_locus ()); - r.add_range (rhs.get_locus ()); - rust_error_at (r, "expected %<%s%> got %<%s%>", - expected->get_name ().c_str (), - expr->get_name ().c_str ()); - } - - return unified; + return UnifyRules::Resolve (lhs, rhs, unify_locus, true /*commit*/, + true /*emit_error*/); } TyTy::BaseType * diff --git a/gcc/rust/typecheck/rust-tyty-rules.h b/gcc/rust/typecheck/rust-tyty-rules.h deleted file mode 100644 index cfe269221bd..00000000000 --- a/gcc/rust/typecheck/rust-tyty-rules.h +++ /dev/null @@ -1,1406 +0,0 @@ -// Copyright (C) 2020-2023 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_TYTY_RULES -#define RUST_TYTY_RULES - -#include "rust-diagnostics.h" -#include "rust-tyty.h" -#include "rust-tyty-visitor.h" -#include "rust-hir-map.h" -#include "rust-hir-type-check.h" - -namespace Rust { -namespace TyTy { - -/* Rules specify how to unify two Ty. For example, the result of unifying the - two tuples (u64, A) and (B, i64) would be (u64, i64). - - Performing a unification requires a double dispatch. To illustrate, suppose - we want to unify `ty1` and `ty2`. Here's what it looks like: - 1. The caller calls `ty1.unify(ty2)`. This is the first dispatch. - 2. `ty1` creates a rule specific to its type(e.g. TupleRules). - 3. The rule calls `ty2.accept_vis(rule)`. This is the second dispatch. - 4. `ty2` calls `rule.visit(*this)`, which will method-overload to the - correct implementation at compile time. - - The nice thing about Rules is that they seperate unification logic from the - representation of Ty. To support unifying a new Ty, implement its - `accept_vis` and `unify` method to pass the unification request to Rules. - Then, create a new `XXXRules` class and implement one `visit` method for - every Ty it can unify with. */ -class BaseRules : public TyVisitor -{ -public: - virtual ~BaseRules () {} - - /* Unify two ty. Returns a pointer to the newly-created unified ty, or nullptr - if the two types cannot be unified. The caller is responsible for releasing - the memory of the returned ty. - - This method is meant to be used internally by Ty. If you're trying to unify - two ty, you can simply call `unify` on ty themselves. */ - virtual BaseType *unify (BaseType *other) - { - if (other->get_kind () == TypeKind::PARAM) - { - ParamType *p = static_cast (other); - other = p->resolve (); - } - else if (other->get_kind () == TypeKind::PLACEHOLDER) - { - PlaceholderType *p = static_cast (other); - if (p->can_resolve ()) - { - other = p->resolve (); - return get_base ()->unify (other); - } - } - else if (other->get_kind () == TypeKind::PROJECTION) - { - ProjectionType *p = static_cast (other); - other = p->get (); - return get_base ()->unify (other); - } - - other->accept_vis (*this); - if (resolved->get_kind () == TyTy::TypeKind::ERROR) - return resolved; - - resolved->append_reference (get_base ()->get_ref ()); - resolved->append_reference (other->get_ref ()); - for (auto ref : get_base ()->get_combined_refs ()) - resolved->append_reference (ref); - for (auto ref : other->get_combined_refs ()) - resolved->append_reference (ref); - - other->append_reference (resolved->get_ref ()); - other->append_reference (get_base ()->get_ref ()); - get_base ()->append_reference (resolved->get_ref ()); - get_base ()->append_reference (other->get_ref ()); - - bool result_resolved = resolved->get_kind () != TyTy::TypeKind::INFER; - bool result_is_infer_var = resolved->get_kind () == TyTy::TypeKind::INFER; - bool results_is_non_general_infer_var - = (result_is_infer_var - && (static_cast (resolved))->get_infer_kind () - != TyTy::InferType::GENERAL); - if (result_resolved || results_is_non_general_infer_var) - { - for (auto &ref : resolved->get_combined_refs ()) - { - TyTy::BaseType *ref_tyty = nullptr; - bool ok = context->lookup_type (ref, &ref_tyty); - if (!ok) - continue; - - // if any of the types are inference variables lets fix them - if (ref_tyty->get_kind () == TyTy::TypeKind::INFER) - { - context->insert_type ( - Analysis::NodeMapping (mappings->get_current_crate (), - UNKNOWN_NODEID, ref, - UNKNOWN_LOCAL_DEFID), - resolved->clone ()); - } - } - } - return resolved; - } - - virtual void visit (TupleType &) override {} - - virtual void visit (ADTType &) override {} - - virtual void visit (InferType &) override {} - - virtual void visit (FnType &) override {} - - virtual void visit (FnPtr &) override {} - - virtual void visit (ArrayType &) override {} - - virtual void visit (SliceType &) override {} - - virtual void visit (BoolType &) override {} - - virtual void visit (IntType &) override {} - - virtual void visit (UintType &) override {} - - virtual void visit (USizeType &) override {} - - virtual void visit (ISizeType &) override {} - - virtual void visit (FloatType &) override {} - - virtual void visit (ErrorType &) override {} - - virtual void visit (CharType &) override {} - - virtual void visit (ReferenceType &) override {} - - virtual void visit (PointerType &) override {} - - virtual void visit (ParamType &) override {} - - virtual void visit (StrType &) override {} - - virtual void visit (NeverType &) override {} - - virtual void visit (PlaceholderType &) override {} - - virtual void visit (ProjectionType &) override {} - - virtual void visit (DynamicObjectType &) override {} - - virtual void visit (ClosureType &) override {} - -protected: - BaseRules (BaseType *base) - : mappings (Analysis::Mappings::get ()), - context (Resolver::TypeCheckContext::get ()), - resolved (new ErrorType (base->get_ref (), base->get_ref ())) - {} - - Analysis::Mappings *mappings; - Resolver::TypeCheckContext *context; - - /* Temporary storage for the result of a unification. - We could return the result directly instead of storing it in the rule - object, but that involves modifying the visitor pattern to accommodate - the return value, which is too complex. */ - BaseType *resolved; - -private: - /* Returns a pointer to the ty that created this rule. */ - virtual BaseType *get_base () = 0; -}; - -class InferRules : public BaseRules -{ - using Rust::TyTy::BaseRules::visit; - -public: - InferRules (InferType *base) : BaseRules (base), base (base) {} - - void visit (BoolType &type) override - { - bool is_valid - = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL); - if (is_valid) - { - resolved = type.clone (); - return; - } - - BaseRules::visit (type); - } - - void visit (IntType &type) override - { - bool is_valid - = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL) - || (base->get_infer_kind () - == TyTy::InferType::InferTypeKind::INTEGRAL); - if (is_valid) - { - resolved = type.clone (); - return; - } - - BaseRules::visit (type); - } - - void visit (UintType &type) override - { - bool is_valid - = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL) - || (base->get_infer_kind () - == TyTy::InferType::InferTypeKind::INTEGRAL); - if (is_valid) - { - resolved = type.clone (); - return; - } - - BaseRules::visit (type); - } - - void visit (USizeType &type) override - { - bool is_valid - = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL) - || (base->get_infer_kind () - == TyTy::InferType::InferTypeKind::INTEGRAL); - if (is_valid) - { - resolved = type.clone (); - return; - } - - BaseRules::visit (type); - } - - void visit (ISizeType &type) override - { - bool is_valid - = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL) - || (base->get_infer_kind () - == TyTy::InferType::InferTypeKind::INTEGRAL); - if (is_valid) - { - resolved = type.clone (); - return; - } - - BaseRules::visit (type); - } - - void visit (FloatType &type) override - { - bool is_valid - = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL) - || (base->get_infer_kind () == TyTy::InferType::InferTypeKind::FLOAT); - if (is_valid) - { - resolved = type.clone (); - return; - } - - BaseRules::visit (type); - } - - void visit (ArrayType &type) override - { - bool is_valid - = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL); - if (is_valid) - { - resolved = type.clone (); - return; - } - - BaseRules::visit (type); - } - - void visit (SliceType &type) override - { - bool is_valid - = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL); - if (is_valid) - { - resolved = type.clone (); - return; - } - - BaseRules::visit (type); - } - - void visit (ADTType &type) override - { - bool is_valid - = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL); - if (is_valid) - { - resolved = type.clone (); - return; - } - - BaseRules::visit (type); - } - - void visit (TupleType &type) override - { - bool is_valid - = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL); - if (is_valid) - { - resolved = type.clone (); - return; - } - - BaseRules::visit (type); - } - - void visit (InferType &type) override - { - switch (base->get_infer_kind ()) - { - case InferType::InferTypeKind::GENERAL: - resolved = type.clone (); - return; - - case InferType::InferTypeKind::INTEGRAL: { - if (type.get_infer_kind () == InferType::InferTypeKind::INTEGRAL) - { - resolved = type.clone (); - return; - } - else if (type.get_infer_kind () == InferType::InferTypeKind::GENERAL) - { - resolved = base->clone (); - return; - } - } - break; - - case InferType::InferTypeKind::FLOAT: { - if (type.get_infer_kind () == InferType::InferTypeKind::FLOAT) - { - resolved = type.clone (); - return; - } - else if (type.get_infer_kind () == InferType::InferTypeKind::GENERAL) - { - resolved = base->clone (); - return; - } - } - break; - } - - BaseRules::visit (type); - } - - void visit (CharType &type) override - { - { - bool is_valid - = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL); - if (is_valid) - { - resolved = type.clone (); - return; - } - - BaseRules::visit (type); - } - } - - void visit (ReferenceType &type) override - { - bool is_valid - = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL); - if (is_valid) - { - resolved = type.clone (); - return; - } - - BaseRules::visit (type); - } - - void visit (PointerType &type) override - { - bool is_valid - = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL); - if (is_valid) - { - resolved = type.clone (); - return; - } - - BaseRules::visit (type); - } - - void visit (ParamType &type) override - { - bool is_valid - = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL); - if (is_valid) - { - resolved = type.clone (); - return; - } - - BaseRules::visit (type); - } - - void visit (DynamicObjectType &type) override - { - bool is_valid - = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL); - if (is_valid) - { - resolved = type.clone (); - return; - } - - BaseRules::visit (type); - } - - void visit (ClosureType &type) override - { - bool is_valid - = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL); - if (is_valid) - { - resolved = type.clone (); - return; - } - - BaseRules::visit (type); - } - -private: - BaseType *get_base () override { return base; } - - InferType *base; -}; - -class FnRules : public BaseRules -{ - using Rust::TyTy::BaseRules::visit; - -public: - FnRules (FnType *base) : BaseRules (base), base (base) {} - - 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 (FnType &type) override - { - if (base->num_params () != type.num_params ()) - { - BaseRules::visit (type); - return; - } - - for (size_t i = 0; i < base->num_params (); i++) - { - auto a = base->param_at (i).second; - auto b = type.param_at (i).second; - - auto unified_param = a->unify (b); - if (unified_param == nullptr) - { - BaseRules::visit (type); - return; - } - } - - auto unified_return - = base->get_return_type ()->unify (type.get_return_type ()); - if (unified_return == nullptr) - { - BaseRules::visit (type); - return; - } - - resolved = base->clone (); - resolved->set_ref (type.get_ref ()); - } - -private: - BaseType *get_base () override { return base; } - - FnType *base; -}; - -class FnptrRules : public BaseRules -{ - using Rust::TyTy::BaseRules::visit; - -public: - FnptrRules (FnPtr *base) : BaseRules (base), base (base) {} - - 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 (FnPtr &type) override - { - auto this_ret_type = base->get_return_type (); - auto other_ret_type = type.get_return_type (); - auto unified_result = this_ret_type->unify (other_ret_type); - if (unified_result == nullptr - || unified_result->get_kind () == TypeKind::ERROR) - { - BaseRules::visit (type); - return; - } - - if (base->num_params () != type.num_params ()) - { - BaseRules::visit (type); - return; - } - - for (size_t i = 0; i < base->num_params (); i++) - { - auto this_param = base->param_at (i); - auto other_param = type.param_at (i); - auto unified_param = this_param->unify (other_param); - if (unified_param == nullptr - || unified_param->get_kind () == TypeKind::ERROR) - { - BaseRules::visit (type); - return; - } - } - - resolved = base->clone (); - resolved->set_ref (type.get_ref ()); - } - - void visit (FnType &type) override - { - auto this_ret_type = base->get_return_type (); - auto other_ret_type = type.get_return_type (); - auto unified_result = this_ret_type->unify (other_ret_type); - if (unified_result == nullptr - || unified_result->get_kind () == TypeKind::ERROR) - { - BaseRules::visit (type); - return; - } - - if (base->num_params () != type.num_params ()) - { - BaseRules::visit (type); - return; - } - - for (size_t i = 0; i < base->num_params (); i++) - { - auto this_param = base->param_at (i); - auto other_param = type.param_at (i).second; - auto unified_param = this_param->unify (other_param); - if (unified_param == nullptr - || unified_param->get_kind () == TypeKind::ERROR) - { - BaseRules::visit (type); - return; - } - } - - resolved = base->clone (); - resolved->set_ref (type.get_ref ()); - } - -private: - BaseType *get_base () override { return base; } - - FnPtr *base; -}; - -class ClosureRules : public BaseRules -{ - using Rust::TyTy::BaseRules::visit; - -public: - ClosureRules (ClosureType *base) : BaseRules (base), base (base) {} - - 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; } - - ClosureType *base; -}; - -class ArrayRules : public BaseRules -{ - using Rust::TyTy::BaseRules::visit; - -public: - ArrayRules (ArrayType *base) : BaseRules (base), base (base) {} - - void visit (ArrayType &type) override - { - // check base type - auto base_resolved - = base->get_element_type ()->unify (type.get_element_type ()); - if (base_resolved == nullptr) - { - BaseRules::visit (type); - return; - } - - resolved - = new ArrayType (type.get_ref (), type.get_ty_ref (), - type.get_ident ().locus, type.get_capacity_expr (), - TyVar (base_resolved->get_ref ())); - } - - 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 ()); - } - -private: - BaseType *get_base () override { return base; } - - ArrayType *base; -}; - -class SliceRules : public BaseRules -{ - using Rust::TyTy::BaseRules::visit; - -public: - SliceRules (SliceType *base) : BaseRules (base), base (base) {} - - void visit (SliceType &type) override - { - // check base type - auto base_resolved - = base->get_element_type ()->unify (type.get_element_type ()); - if (base_resolved == nullptr) - { - BaseRules::visit (type); - return; - } - - resolved = new SliceType (type.get_ref (), type.get_ty_ref (), - type.get_ident ().locus, - TyVar (base_resolved->get_ref ())); - } - - 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 ()); - } - -private: - BaseType *get_base () override { return base; } - - SliceType *base; -}; - -class BoolRules : public BaseRules -{ - using Rust::TyTy::BaseRules::visit; - -public: - BoolRules (BoolType *base) : BaseRules (base), base (base) {} - - void visit (BoolType &type) override - { - resolved = new BoolType (type.get_ref (), type.get_ty_ref ()); - } - - void visit (InferType &type) override - { - switch (type.get_infer_kind ()) - { - case InferType::InferTypeKind::GENERAL: - resolved = base->clone (); - break; - - default: - BaseRules::visit (type); - break; - } - } - -private: - BaseType *get_base () override { return base; } - - BoolType *base; -}; - -class IntRules : public BaseRules -{ - using Rust::TyTy::BaseRules::visit; - -public: - IntRules (IntType *base) : BaseRules (base), base (base) {} - - void visit (InferType &type) override - { - // cant assign a float inference variable - if (type.get_infer_kind () == InferType::InferTypeKind::FLOAT) - { - BaseRules::visit (type); - return; - } - - resolved = base->clone (); - resolved->set_ref (type.get_ref ()); - } - - void visit (IntType &type) override - { - if (type.get_int_kind () != base->get_int_kind ()) - { - BaseRules::visit (type); - return; - } - - resolved - = new IntType (type.get_ref (), type.get_ty_ref (), type.get_int_kind ()); - } - -private: - BaseType *get_base () override { return base; } - - IntType *base; -}; - -class UintRules : public BaseRules -{ - using Rust::TyTy::BaseRules::visit; - -public: - UintRules (UintType *base) : BaseRules (base), base (base) {} - - void visit (InferType &type) override - { - // cant assign a float inference variable - if (type.get_infer_kind () == InferType::InferTypeKind::FLOAT) - { - BaseRules::visit (type); - return; - } - - resolved = base->clone (); - resolved->set_ref (type.get_ref ()); - } - - void visit (UintType &type) override - { - if (type.get_uint_kind () != base->get_uint_kind ()) - { - BaseRules::visit (type); - return; - } - - resolved = new UintType (type.get_ref (), type.get_ty_ref (), - type.get_uint_kind ()); - } - -private: - BaseType *get_base () override { return base; } - - UintType *base; -}; - -class FloatRules : public BaseRules -{ - using Rust::TyTy::BaseRules::visit; - -public: - FloatRules (FloatType *base) : BaseRules (base), base (base) {} - - void visit (InferType &type) override - { - if (type.get_infer_kind () == InferType::InferTypeKind::INTEGRAL) - { - BaseRules::visit (type); - return; - } - - resolved = base->clone (); - resolved->set_ref (type.get_ref ()); - } - - void visit (FloatType &type) override - { - if (type.get_float_kind () != base->get_float_kind ()) - { - BaseRules::visit (type); - return; - } - - resolved = new FloatType (type.get_ref (), type.get_ty_ref (), - type.get_float_kind ()); - } - -private: - BaseType *get_base () override { return base; } - - FloatType *base; -}; - -class ADTRules : public BaseRules -{ - using Rust::TyTy::BaseRules::visit; - -public: - ADTRules (ADTType *base) : BaseRules (base), base (base) {} - - void visit (ADTType &type) override - { - if (base->get_adt_kind () != type.get_adt_kind ()) - { - BaseRules::visit (type); - return; - } - - if (base->get_identifier ().compare (type.get_identifier ()) != 0) - { - BaseRules::visit (type); - return; - } - - if (base->number_of_variants () != type.number_of_variants ()) - { - BaseRules::visit (type); - return; - } - - for (size_t i = 0; i < type.number_of_variants (); ++i) - { - TyTy::VariantDef *a = base->get_variants ().at (i); - TyTy::VariantDef *b = type.get_variants ().at (i); - - if (a->num_fields () != b->num_fields ()) - { - BaseRules::visit (type); - return; - } - - for (size_t j = 0; j < a->num_fields (); j++) - { - TyTy::StructFieldType *base_field = a->get_field_at_index (j); - TyTy::StructFieldType *other_field = b->get_field_at_index (j); - - TyTy::BaseType *this_field_ty = base_field->get_field_type (); - TyTy::BaseType *other_field_ty = other_field->get_field_type (); - - BaseType *unified_ty = this_field_ty->unify (other_field_ty); - if (unified_ty->get_kind () == TyTy::TypeKind::ERROR) - return; - } - } - - // generic args for the unit-struct case - if (type.is_unit () && base->is_unit ()) - { - rust_assert (type.get_num_substitutions () - == base->get_num_substitutions ()); - - for (size_t i = 0; i < type.get_num_substitutions (); i++) - { - auto &a = base->get_substs ().at (i); - auto &b = type.get_substs ().at (i); - - auto pa = a.get_param_ty (); - auto pb = b.get_param_ty (); - - auto res = pa->unify (pb); - if (res->get_kind () == TyTy::TypeKind::ERROR) - { - return; - } - } - } - - resolved = type.clone (); - } - - 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 ()); - } - -private: - BaseType *get_base () override { return base; } - - ADTType *base; -}; - -class TupleRules : public BaseRules -{ - using Rust::TyTy::BaseRules::visit; - -public: - TupleRules (TupleType *base) : BaseRules (base), base (base) {} - - void visit (TupleType &type) override - { - if (base->num_fields () != type.num_fields ()) - { - BaseRules::visit (type); - return; - } - - std::vector fields; - for (size_t i = 0; i < base->num_fields (); i++) - { - BaseType *bo = base->get_field (i); - BaseType *fo = type.get_field (i); - - BaseType *unified_ty = bo->unify (fo); - if (unified_ty->get_kind () == TyTy::TypeKind::ERROR) - return; - - fields.push_back (TyVar (unified_ty->get_ref ())); - } - - resolved = new TyTy::TupleType (type.get_ref (), type.get_ty_ref (), - type.get_ident ().locus, fields); - } - - 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 ()); - } - -private: - BaseType *get_base () override { return base; } - - TupleType *base; -}; - -class USizeRules : public BaseRules -{ - using Rust::TyTy::BaseRules::visit; - -public: - USizeRules (USizeType *base) : BaseRules (base), base (base) {} - - void visit (InferType &type) override - { - // cant assign a float inference variable - if (type.get_infer_kind () == InferType::InferTypeKind::FLOAT) - { - BaseRules::visit (type); - return; - } - - resolved = base->clone (); - resolved->set_ref (type.get_ref ()); - } - - void visit (USizeType &type) override { resolved = type.clone (); } - -private: - BaseType *get_base () override { return base; } - - USizeType *base; -}; - -class ISizeRules : public BaseRules -{ - using Rust::TyTy::BaseRules::visit; - -public: - ISizeRules (ISizeType *base) : BaseRules (base), base (base) {} - - void visit (InferType &type) override - { - // cant assign a float inference variable - if (type.get_infer_kind () == InferType::InferTypeKind::FLOAT) - { - BaseRules::visit (type); - return; - } - - resolved = base->clone (); - resolved->set_ref (type.get_ref ()); - } - - void visit (ISizeType &type) override { resolved = type.clone (); } - -private: - BaseType *get_base () override { return base; } - - ISizeType *base; -}; - -class CharRules : public BaseRules -{ - using Rust::TyTy::BaseRules::visit; - -public: - CharRules (CharType *base) : BaseRules (base), base (base) {} - - 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 (CharType &type) override { resolved = type.clone (); } - -private: - BaseType *get_base () override { return base; } - - CharType *base; -}; - -class ReferenceRules : public BaseRules -{ - using Rust::TyTy::BaseRules::visit; - -public: - ReferenceRules (ReferenceType *base) : BaseRules (base), base (base) {} - - void visit (ReferenceType &type) override - { - auto base_type = base->get_base (); - auto other_base_type = type.get_base (); - - TyTy::BaseType *base_resolved = base_type->unify (other_base_type); - if (base_resolved == nullptr - || base_resolved->get_kind () == TypeKind::ERROR) - { - BaseRules::visit (type); - return; - } - - // 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 (!mutability_ok) - { - BaseRules::visit (type); - return; - } - - resolved = new ReferenceType (base->get_ref (), base->get_ty_ref (), - TyVar (base_resolved->get_ref ()), - base->mutability ()); - } - - 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 ()); - } - -private: - BaseType *get_base () override { return base; } - - ReferenceType *base; -}; - -class PointerRules : public BaseRules -{ - using Rust::TyTy::BaseRules::visit; - -public: - PointerRules (PointerType *base) : BaseRules (base), base (base) {} - - void visit (PointerType &type) override - { - auto base_type = base->get_base (); - auto other_base_type = type.get_base (); - - TyTy::BaseType *base_resolved = base_type->unify (other_base_type); - if (base_resolved == nullptr - || base_resolved->get_kind () == TypeKind::ERROR) - { - BaseRules::visit (type); - return; - } - - // 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 (!mutability_ok) - { - BaseRules::visit (type); - return; - } - - resolved = new PointerType (base->get_ref (), base->get_ty_ref (), - TyVar (base_resolved->get_ref ()), - base->mutability ()); - } - - 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 ()); - } - -private: - BaseType *get_base () override { return base; } - - PointerType *base; -}; - -class ParamRules : public BaseRules -{ - using Rust::TyTy::BaseRules::visit; - -public: - ParamRules (ParamType *base) : BaseRules (base), base (base) {} - - // param types are a placeholder we shouldn't have cases where we unify - // against it. eg: struct foo { a: T }; When we invoke it we can do either: - // - // foo{ a: 123 }. - // Then this enforces the i32 type to be referenced on the - // field via an hirid. - // - // rust also allows for a = foo{a:123}; Where we can use an Inference Variable - // to handle the typing of the struct - BaseType *unify (BaseType *other) override final - { - if (!base->can_resolve ()) - return BaseRules::unify (other); - - auto lookup = base->resolve (); - return lookup->unify (other); - } - - void visit (ParamType &type) override - { - if (base->get_symbol ().compare (type.get_symbol ()) != 0) - { - BaseRules::visit (type); - return; - } - - resolved = type.clone (); - } - - void visit (InferType &type) override - { - if (type.get_infer_kind () != InferType::InferTypeKind::GENERAL) - { - BaseRules::visit (type); - return; - } - - resolved = base->clone (); - } - -private: - BaseType *get_base () override { return base; } - - ParamType *base; -}; - -class StrRules : public BaseRules -{ - // FIXME we will need a enum for the StrType like ByteBuf etc.. - using Rust::TyTy::BaseRules::visit; - -public: - StrRules (StrType *base) : BaseRules (base), base (base) {} - - void visit (StrType &type) override { resolved = type.clone (); } - -private: - BaseType *get_base () override { return base; } - - StrType *base; -}; - -class NeverRules : public BaseRules -{ - using Rust::TyTy::BaseRules::visit; - -public: - NeverRules (NeverType *base) : BaseRules (base), base (base) {} - - void visit (NeverType &type) override { resolved = type.clone (); } - -private: - BaseType *get_base () override { return base; } - - NeverType *base; -}; - -class PlaceholderRules : public BaseRules -{ - using Rust::TyTy::BaseRules::visit; - -public: - PlaceholderRules (PlaceholderType *base) : BaseRules (base), base (base) {} - - BaseType *unify (BaseType *other) override final - { - if (!base->can_resolve ()) - return BaseRules::unify (other); - - BaseType *lookup = base->resolve (); - return lookup->unify (other); - } - - void visit (PlaceholderType &type) override - { - if (base->get_symbol ().compare (type.get_symbol ()) != 0) - { - BaseRules::visit (type); - return; - } - - resolved = type.clone (); - } - - void visit (InferType &type) override - { - if (type.get_infer_kind () != InferType::InferTypeKind::GENERAL) - { - BaseRules::visit (type); - return; - } - - resolved = base->clone (); - } - -private: - BaseType *get_base () override { return base; } - - PlaceholderType *base; -}; - -class DynamicRules : public BaseRules -{ - using Rust::TyTy::BaseRules::visit; - -public: - DynamicRules (DynamicObjectType *base) : BaseRules (base), base (base) {} - - void visit (InferType &type) override - { - if (type.get_infer_kind () != InferType::InferTypeKind::GENERAL) - { - BaseRules::visit (type); - return; - } - - resolved = base->clone (); - } - - void visit (DynamicObjectType &type) override - { - if (base->num_specified_bounds () != type.num_specified_bounds ()) - { - BaseRules::visit (type); - return; - } - - Location ref_locus = mappings->lookup_location (type.get_ref ()); - if (!base->bounds_compatible (type, ref_locus, true)) - { - BaseRules::visit (type); - return; - } - - resolved = base->clone (); - } - -private: - BaseType *get_base () override { return base; } - - DynamicObjectType *base; -}; - -} // namespace TyTy -} // namespace Rust - -#endif // RUST_TYTY_RULES diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index a3271eb0d1a..fe5aa2b059c 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -30,7 +30,6 @@ #include "rust-hir-trait-reference.h" #include "rust-hir-type-bounds.h" #include "rust-hir-trait-resolve.h" -#include "rust-tyty-rules.h" #include "rust-tyty-cmp.h" #include "options.h" @@ -376,6 +375,58 @@ BaseType::get_root () const return root; } +BaseType * +BaseType::destructure () +{ + int recurisve_ops = 0; + BaseType *x = this; + while (true) + { + if (recurisve_ops++ >= rust_max_recursion_depth) + { + rust_error_at ( + Location (), + "% count exceeds limit of %i (use " + "% to increase the limit)", + rust_max_recursion_depth); + return new ErrorType (get_ref ()); + } + + switch (x->get_kind ()) + { + case TyTy::TypeKind::PARAM: { + TyTy::ParamType *p = static_cast (x); + TyTy::BaseType *pr = p->resolve (); + if (pr == x) + return pr; + + x = pr; + } + break; + + case TyTy::TypeKind::PLACEHOLDER: { + TyTy::PlaceholderType *p = static_cast (x); + if (!p->can_resolve ()) + return p; + + x = p->resolve (); + } + break; + + case TyTy::TypeKind::PROJECTION: { + TyTy::ProjectionType *p = static_cast (x); + x = p->get (); + } + break; + + default: + return x; + } + } + + return x; +} + const BaseType * BaseType::destructure () const { @@ -397,14 +448,20 @@ BaseType::destructure () const { case TyTy::TypeKind::PARAM: { const TyTy::ParamType *p = static_cast (x); - x = p->resolve (); + const TyTy::BaseType *pr = p->resolve (); + if (pr == x) + return pr; + + x = pr; } break; case TyTy::TypeKind::PLACEHOLDER: { const TyTy::PlaceholderType *p = static_cast (x); - rust_assert (p->can_resolve ()); + if (!p->can_resolve ()) + return p; + x = p->resolve (); } break; @@ -512,13 +569,6 @@ InferType::as_string () const return ""; } -BaseType * -InferType::unify (BaseType *other) -{ - InferRules r (this); - return r.unify (other); -} - bool InferType::can_eq (const BaseType *other, bool emit_errors) const { @@ -637,12 +687,6 @@ ErrorType::as_string () const return ""; } -BaseType * -ErrorType::unify (BaseType *other) -{ - return this; -} - bool ErrorType::can_eq (const BaseType *other, bool emit_errors) const { @@ -1009,13 +1053,6 @@ ADTType::as_string () const return identifier + subst_as_string () + "{" + variants_buffer + "}"; } -BaseType * -ADTType::unify (BaseType *other) -{ - ADTRules r (this); - return r.unify (other); -} - bool ADTType::can_eq (const BaseType *other, bool emit_errors) const { @@ -1278,13 +1315,6 @@ TupleType::get_field (size_t index) const return fields.at (index).get_tyty (); } -BaseType * -TupleType::unify (BaseType *other) -{ - TupleRules r (this); - return r.unify (other); -} - bool TupleType::can_eq (const BaseType *other, bool emit_errors) const { @@ -1385,13 +1415,6 @@ FnType::as_string () const return "fn" + subst_as_string () + " (" + params_str + ") -> " + ret_str; } -BaseType * -FnType::unify (BaseType *other) -{ - FnRules r (this); - return r.unify (other); -} - bool FnType::can_eq (const BaseType *other, bool emit_errors) const { @@ -1616,13 +1639,6 @@ FnPtr::as_string () const return "fnptr (" + params_str + ") -> " + get_return_type ()->as_string (); } -BaseType * -FnPtr::unify (BaseType *other) -{ - FnptrRules r (this); - return r.unify (other); -} - bool FnPtr::can_eq (const BaseType *other, bool emit_errors) const { @@ -1696,13 +1712,6 @@ ClosureType::as_string () const return "|" + params_buf + "| {" + result_type.get_tyty ()->as_string () + "}"; } -BaseType * -ClosureType::unify (BaseType *other) -{ - ClosureRules r (this); - return r.unify (other); -} - bool ClosureType::can_eq (const BaseType *other, bool emit_errors) const { @@ -1812,13 +1821,6 @@ ArrayType::as_string () const return "[" + get_element_type ()->as_string () + ":" + "CAPACITY" + "]"; } -BaseType * -ArrayType::unify (BaseType *other) -{ - ArrayRules r (this); - return r.unify (other); -} - bool ArrayType::can_eq (const BaseType *other, bool emit_errors) const { @@ -1895,13 +1897,6 @@ SliceType::as_string () const return "[" + get_element_type ()->as_string () + "]"; } -BaseType * -SliceType::unify (BaseType *other) -{ - SliceRules r (this); - return r.unify (other); -} - bool SliceType::can_eq (const BaseType *other, bool emit_errors) const { @@ -2006,13 +2001,6 @@ BoolType::as_string () const return "bool"; } -BaseType * -BoolType::unify (BaseType *other) -{ - BoolRules r (this); - return r.unify (other); -} - bool BoolType::can_eq (const BaseType *other, bool emit_errors) const { @@ -2094,13 +2082,6 @@ IntType::as_string () const return "__unknown_int_type"; } -BaseType * -IntType::unify (BaseType *other) -{ - IntRules r (this); - return r.unify (other); -} - bool IntType::can_eq (const BaseType *other, bool emit_errors) const { @@ -2200,13 +2181,6 @@ UintType::as_string () const return "__unknown_uint_type"; } -BaseType * -UintType::unify (BaseType *other) -{ - UintRules r (this); - return r.unify (other); -} - bool UintType::can_eq (const BaseType *other, bool emit_errors) const { @@ -2306,13 +2280,6 @@ FloatType::as_string () const return "__unknown_float_type"; } -BaseType * -FloatType::unify (BaseType *other) -{ - FloatRules r (this); - return r.unify (other); -} - bool FloatType::can_eq (const BaseType *other, bool emit_errors) const { @@ -2389,13 +2356,6 @@ USizeType::as_string () const return "usize"; } -BaseType * -USizeType::unify (BaseType *other) -{ - USizeRules r (this); - return r.unify (other); -} - bool USizeType::can_eq (const BaseType *other, bool emit_errors) const { @@ -2461,13 +2421,6 @@ ISizeType::as_string () const return "isize"; } -BaseType * -ISizeType::unify (BaseType *other) -{ - ISizeRules r (this); - return r.unify (other); -} - bool ISizeType::can_eq (const BaseType *other, bool emit_errors) const { @@ -2533,13 +2486,6 @@ CharType::as_string () const return "char"; } -BaseType * -CharType::unify (BaseType *other) -{ - CharRules r (this); - return r.unify (other); -} - bool CharType::can_eq (const BaseType *other, bool emit_errors) const { @@ -2655,13 +2601,6 @@ ReferenceType::get_name () const + get_base ()->get_name (); } -BaseType * -ReferenceType::unify (BaseType *other) -{ - ReferenceRules r (this); - return r.unify (other); -} - bool ReferenceType::can_eq (const BaseType *other, bool emit_errors) const { @@ -2821,13 +2760,6 @@ PointerType::get_name () const + get_base ()->get_name (); } -BaseType * -PointerType::unify (BaseType *other) -{ - PointerRules r (this); - return r.unify (other); -} - bool PointerType::can_eq (const BaseType *other, bool emit_errors) const { @@ -2964,13 +2896,6 @@ ParamType::get_name () const return resolve ()->get_name (); } -BaseType * -ParamType::unify (BaseType *other) -{ - ParamRules r (this); - return r.unify (other); -} - bool ParamType::can_eq (const BaseType *other, bool emit_errors) const { @@ -3130,13 +3055,6 @@ StrType::as_string () const return "str"; } -BaseType * -StrType::unify (BaseType *other) -{ - StrRules r (this); - return r.unify (other); -} - bool StrType::can_eq (const BaseType *other, bool emit_errors) const { @@ -3202,13 +3120,6 @@ NeverType::as_string () const return "!"; } -BaseType * -NeverType::unify (BaseType *other) -{ - NeverRules r (this); - return r.unify (other); -} - bool NeverType::can_eq (const BaseType *other, bool emit_errors) const { @@ -3295,13 +3206,6 @@ PlaceholderType::as_string () const + ">"; } -BaseType * -PlaceholderType::unify (BaseType *other) -{ - PlaceholderRules r (this); - return r.unify (other); -} - bool PlaceholderType::can_eq (const BaseType *other, bool emit_errors) const { @@ -3465,12 +3369,6 @@ ProjectionType::as_string () const return "as_string () + ">"; } -BaseType * -ProjectionType::unify (BaseType *other) -{ - return base->unify (other); -} - bool ProjectionType::can_eq (const BaseType *other, bool emit_errors) const { @@ -3602,13 +3500,6 @@ DynamicObjectType::as_string () const return "dyn [" + raw_bounds_as_string () + "]"; } -BaseType * -DynamicObjectType::unify (BaseType *other) -{ - DynamicRules r (this); - return r.unify (other); -} - bool DynamicObjectType::can_eq (const BaseType *other, bool emit_errors) const { diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index 1cf7131c1cb..d2cf5b07fc1 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -105,11 +105,6 @@ public: virtual std::string get_name () const = 0; - // Unify two types. Returns a pointer to the newly-created unified ty, or - // nullptr if the two ty cannot be unified. The caller is responsible for - // releasing the memory of the returned ty. - virtual BaseType *unify (BaseType *other) = 0; - // similar to unify but does not actually perform type unification but // determines whether they are compatible. Consider the following // @@ -177,6 +172,7 @@ public: // This will get the monomorphized type from Params, Placeholders or // Projections if available or error + BaseType *destructure (); const BaseType *destructure () const; const RustIdent &get_ident () const; @@ -221,8 +217,6 @@ public: std::string as_string () const override; - BaseType *unify (BaseType *other) override; - bool can_eq (const BaseType *other, bool emit_errors) const override final; BaseType *clone () const final override; @@ -255,7 +249,6 @@ public: std::string as_string () const override; - BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; BaseType *clone () const final override; @@ -284,7 +277,6 @@ public: std::string as_string () const override; - BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; BaseType *clone () const final override; @@ -361,7 +353,6 @@ public: std::string as_string () const override; - BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; bool is_equal (const BaseType &other) const override; @@ -598,7 +589,6 @@ public: std::string as_string () const override; - BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; bool is_equal (const BaseType &other) const override; @@ -738,7 +728,6 @@ public: std::string get_identifier () const { return identifier; } - BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; bool is_equal (const BaseType &other) const override; @@ -858,7 +847,6 @@ public: std::string as_string () const override; - BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; bool is_equal (const BaseType &other) const override; @@ -938,7 +926,6 @@ public: std::string as_string () const override; std::string get_name () const override final { return as_string (); } - BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; bool is_equal (const BaseType &other) const override; @@ -1007,7 +994,6 @@ public: std::string get_name () const override final { return as_string (); } - BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; bool is_equal (const BaseType &other) const override; @@ -1055,7 +1041,6 @@ public: std::string get_name () const override final { return as_string (); } - BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; bool is_equal (const BaseType &other) const override; @@ -1089,7 +1074,6 @@ public: std::string get_name () const override final; - BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; BaseType *clone () const final override; @@ -1120,7 +1104,6 @@ public: std::string get_name () const override final; - BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; IntKind get_int_kind () const; @@ -1159,7 +1142,6 @@ public: std::string get_name () const override final; - BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; UintKind get_uint_kind () const; @@ -1194,7 +1176,6 @@ public: std::string as_string () const override; std::string get_name () const override final; - BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; FloatKind get_float_kind () const; @@ -1222,7 +1203,6 @@ public: std::string as_string () const override; std::string get_name () const override final; - BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; BaseType *clone () const final override; @@ -1243,7 +1223,6 @@ public: std::string as_string () const override; std::string get_name () const override final; - BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; BaseType *clone () const final override; @@ -1263,7 +1242,6 @@ public: std::string as_string () const override; std::string get_name () const override final; - BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; BaseType *clone () const final override; @@ -1284,7 +1262,6 @@ public: std::string as_string () const override; - BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; bool is_equal (const BaseType &other) const override; @@ -1311,7 +1288,6 @@ public: std::string get_name () const override final; - BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; bool is_equal (const BaseType &other) const override; @@ -1354,7 +1330,6 @@ public: std::string as_string () const override; std::string get_name () const override final; - BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; bool is_equal (const BaseType &other) const override; @@ -1401,7 +1376,6 @@ public: std::string as_string () const override; - BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; BaseType *clone () const final override; @@ -1428,7 +1402,6 @@ public: std::string as_string () const override; - BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; BaseType *clone () const final override; @@ -1478,7 +1451,6 @@ public: std::string as_string () const override; - BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; BaseType *clone () const final override; @@ -1524,7 +1496,6 @@ public: std::string as_string () const override; - BaseType *unify (BaseType *other) override; bool can_eq (const BaseType *other, bool emit_errors) const override final; bool is_equal (const BaseType &other) const override; diff --git a/gcc/rust/typecheck/rust-unify.cc b/gcc/rust/typecheck/rust-unify.cc new file mode 100644 index 00000000000..072f76133bc --- /dev/null +++ b/gcc/rust/typecheck/rust-unify.cc @@ -0,0 +1,1640 @@ +// 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-unify.h" + +namespace Rust { +namespace Resolver { + +UnifyRules::UnifyRules (TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs, + Location locus, bool commit_flag, bool emit_error) + : lhs (lhs), rhs (rhs), locus (locus), commit_flag (commit_flag), + emit_error (emit_error), mappings (*Analysis::Mappings::get ()), + context (*TypeCheckContext::get ()) +{} + +TyTy::BaseType * +UnifyRules::Resolve (TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs, + Location locus, bool commit_flag, bool emit_error) +{ + UnifyRules r (lhs, rhs, locus, commit_flag, emit_error); + TyTy::BaseType *result = r.go (); + + if (r.commit_flag) + r.commit (result); + + bool failed = result->get_kind () == TyTy::TypeKind::ERROR; + if (failed && r.emit_error) + r.emit_type_mismatch (); + + return result; +} + +TyTy::BaseType * +UnifyRules::get_base () +{ + return lhs.get_ty ()->destructure (); +} + +TyTy::BaseType * +UnifyRules::get_other () +{ + return rhs.get_ty ()->destructure (); +} + +void +UnifyRules::commit (TyTy::BaseType *resolved) +{ + resolved->append_reference (get_base ()->get_ref ()); + resolved->append_reference (get_other ()->get_ref ()); + for (auto ref : get_base ()->get_combined_refs ()) + resolved->append_reference (ref); + for (auto ref : get_other ()->get_combined_refs ()) + resolved->append_reference (ref); + + get_other ()->append_reference (resolved->get_ref ()); + get_other ()->append_reference (get_base ()->get_ref ()); + get_base ()->append_reference (resolved->get_ref ()); + get_base ()->append_reference (get_other ()->get_ref ()); + + bool result_resolved = resolved->get_kind () != TyTy::TypeKind::INFER; + bool result_is_infer_var = resolved->get_kind () == TyTy::TypeKind::INFER; + bool results_is_non_general_infer_var + = (result_is_infer_var + && (static_cast (resolved))->get_infer_kind () + != TyTy::InferType::GENERAL); + if (result_resolved || results_is_non_general_infer_var) + { + for (auto &ref : resolved->get_combined_refs ()) + { + TyTy::BaseType *ref_tyty = nullptr; + bool ok = context.lookup_type (ref, &ref_tyty); + if (!ok) + continue; + + // if any of the types are inference variables lets fix them + if (ref_tyty->get_kind () == TyTy::TypeKind::INFER) + { + auto node = Analysis::NodeMapping (mappings.get_current_crate (), + UNKNOWN_NODEID, ref, + UNKNOWN_LOCAL_DEFID); + context.insert_type (node, resolved->clone ()); + } + } + } +} + +void +UnifyRules::emit_type_mismatch () const +{ + TyTy::BaseType *expected = lhs.get_ty (); + TyTy::BaseType *expr = rhs.get_ty (); + + RichLocation r (locus); + r.add_range (lhs.get_locus ()); + r.add_range (rhs.get_locus ()); + rust_error_at (r, "expected %<%s%> got %<%s%>", + expected->get_name ().c_str (), expr->get_name ().c_str ()); +} + +TyTy::BaseType * +UnifyRules::go () +{ + TyTy::BaseType *ltype = lhs.get_ty (); + TyTy::BaseType *rtype = rhs.get_ty (); + + ltype = lhs.get_ty ()->destructure (); + rtype = rhs.get_ty ()->destructure (); + + rust_debug ("unify::go ltype={%s} rtype={%s}", ltype->debug_str ().c_str (), + rtype->debug_str ().c_str ()); + + switch (ltype->get_kind ()) + { + case TyTy::INFER: + return expect_inference_variable (static_cast (ltype), + rtype); + + case TyTy::ADT: + return expect_adt (static_cast (ltype), rtype); + + case TyTy::STR: + return expect_str (static_cast (ltype), rtype); + + case TyTy::REF: + return expect_reference (static_cast (ltype), + rtype); + + case TyTy::POINTER: + return expect_pointer (static_cast (ltype), rtype); + + case TyTy::PARAM: + return expect_param (static_cast (ltype), rtype); + + case TyTy::ARRAY: + return expect_array (static_cast (ltype), rtype); + + case TyTy::SLICE: + return expect_slice (static_cast (ltype), rtype); + + case TyTy::FNDEF: + return expect_fndef (static_cast (ltype), rtype); + + case TyTy::FNPTR: + return expect_fnptr (static_cast (ltype), rtype); + + case TyTy::TUPLE: + return expect_tuple (static_cast (ltype), rtype); + + case TyTy::BOOL: + return expect_bool (static_cast (ltype), rtype); + + case TyTy::CHAR: + return expect_char (static_cast (ltype), rtype); + + case TyTy::INT: + return expect_int (static_cast (ltype), rtype); + + case TyTy::UINT: + return expect_uint (static_cast (ltype), rtype); + + case TyTy::FLOAT: + return expect_float (static_cast (ltype), rtype); + + case TyTy::USIZE: + return expect_usize (static_cast (ltype), rtype); + + case TyTy::ISIZE: + return expect_isize (static_cast (ltype), rtype); + + case TyTy::NEVER: + return expect_never (static_cast (ltype), rtype); + + case TyTy::PLACEHOLDER: + return expect_placeholder (static_cast (ltype), + rtype); + + case TyTy::PROJECTION: + return expect_projection (static_cast (ltype), + rtype); + + case TyTy::DYNAMIC: + return expect_dyn (static_cast (ltype), rtype); + + case TyTy::CLOSURE: + return expect_closure (static_cast (ltype), rtype); + + case TyTy::ERROR: + return new TyTy::ErrorType (0); + } + + return new TyTy::ErrorType (0); +} + +TyTy::BaseType * +UnifyRules::expect_inference_variable (TyTy::InferType *ltype, + TyTy::BaseType *rtype) +{ + switch (rtype->get_kind ()) + { + case TyTy::INFER: { + TyTy::InferType *r = static_cast (rtype); + switch (ltype->get_infer_kind ()) + { + case TyTy::InferType::InferTypeKind::GENERAL: + return rtype->clone (); + + case TyTy::InferType::InferTypeKind::INTEGRAL: { + bool is_valid = r->get_infer_kind () + == TyTy::InferType::InferTypeKind::INTEGRAL + || r->get_infer_kind () + == TyTy::InferType::InferTypeKind::GENERAL; + if (is_valid) + return rtype->clone (); + } + break; + + case TyTy::InferType::InferTypeKind::FLOAT: { + bool is_valid + = r->get_infer_kind () == TyTy::InferType::InferTypeKind::FLOAT + || r->get_infer_kind () + == TyTy::InferType::InferTypeKind::GENERAL; + if (is_valid) + return rtype->clone (); + } + break; + } + } + break; + + case TyTy::INT: + case TyTy::UINT: + case TyTy::USIZE: + case TyTy::ISIZE: { + bool is_valid = (ltype->get_infer_kind () + == TyTy::InferType::InferTypeKind::GENERAL) + || (ltype->get_infer_kind () + == TyTy::InferType::InferTypeKind::INTEGRAL); + if (is_valid) + return rtype->clone (); + } + break; + + case TyTy::FLOAT: { + bool is_valid = (ltype->get_infer_kind () + == TyTy::InferType::InferTypeKind::GENERAL) + || (ltype->get_infer_kind () + == TyTy::InferType::InferTypeKind::FLOAT); + if (is_valid) + return rtype->clone (); + } + break; + + case TyTy::ADT: + case TyTy::STR: + case TyTy::REF: + case TyTy::POINTER: + case TyTy::PARAM: + case TyTy::ARRAY: + case TyTy::SLICE: + case TyTy::FNDEF: + case TyTy::FNPTR: + case TyTy::TUPLE: + case TyTy::BOOL: + case TyTy::CHAR: + case TyTy::NEVER: + case TyTy::PLACEHOLDER: + case TyTy::PROJECTION: + case TyTy::DYNAMIC: + case TyTy::CLOSURE: { + bool is_valid = (ltype->get_infer_kind () + == TyTy::InferType::InferTypeKind::GENERAL); + if (is_valid) + return rtype->clone (); + } + break; + + case TyTy::ERROR: + return new TyTy::ErrorType (0); + } + + return new TyTy::ErrorType (0); +} + +TyTy::BaseType * +UnifyRules::expect_adt (TyTy::ADTType *ltype, TyTy::BaseType *rtype) +{ + switch (rtype->get_kind ()) + { + case TyTy::INFER: { + TyTy::InferType *r = static_cast (rtype); + bool is_valid + = r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL; + if (is_valid) + return ltype->clone (); + } + break; + + case TyTy::ADT: { + TyTy::ADTType &type = *static_cast (rtype); + if (ltype->get_adt_kind () != type.get_adt_kind ()) + { + return new TyTy::ErrorType (0); + } + + if (ltype->get_identifier ().compare (type.get_identifier ()) != 0) + { + return new TyTy::ErrorType (0); + } + + if (ltype->number_of_variants () != type.number_of_variants ()) + { + return new TyTy::ErrorType (0); + } + + for (size_t i = 0; i < type.number_of_variants (); ++i) + { + TyTy::VariantDef *a = ltype->get_variants ().at (i); + TyTy::VariantDef *b = type.get_variants ().at (i); + + if (a->num_fields () != b->num_fields ()) + { + return new TyTy::ErrorType (0); + } + + for (size_t j = 0; j < a->num_fields (); j++) + { + TyTy::StructFieldType *base_field = a->get_field_at_index (j); + TyTy::StructFieldType *other_field = b->get_field_at_index (j); + + TyTy::BaseType *this_field_ty = base_field->get_field_type (); + TyTy::BaseType *other_field_ty = other_field->get_field_type (); + + TyTy::BaseType *unified_ty + = UnifyRules::Resolve (TyTy::TyWithLocation (this_field_ty), + TyTy::TyWithLocation (other_field_ty), + locus, commit_flag, + false /* emit_error */); + if (unified_ty->get_kind () == TyTy::TypeKind::ERROR) + { + return new TyTy::ErrorType (0); + } + } + } + + // generic args for the unit-struct case + if (type.is_unit () && ltype->is_unit ()) + { + rust_assert (type.get_num_substitutions () + == ltype->get_num_substitutions ()); + + for (size_t i = 0; i < type.get_num_substitutions (); i++) + { + auto &a = ltype->get_substs ().at (i); + auto &b = type.get_substs ().at (i); + + auto pa = a.get_param_ty (); + auto pb = b.get_param_ty (); + + auto res + = UnifyRules::Resolve (TyTy::TyWithLocation (pa), + TyTy::TyWithLocation (pb), locus, + commit_flag, false /* emit_error */); + if (res->get_kind () == TyTy::TypeKind::ERROR) + { + return new TyTy::ErrorType (0); + } + } + } + + return type.clone (); + } + break; + + case TyTy::STR: + case TyTy::REF: + case TyTy::POINTER: + case TyTy::PARAM: + case TyTy::ARRAY: + case TyTy::SLICE: + case TyTy::FNDEF: + case TyTy::FNPTR: + case TyTy::TUPLE: + case TyTy::BOOL: + case TyTy::CHAR: + case TyTy::INT: + case TyTy::UINT: + case TyTy::FLOAT: + case TyTy::USIZE: + case TyTy::ISIZE: + case TyTy::NEVER: + case TyTy::PLACEHOLDER: + case TyTy::PROJECTION: + case TyTy::DYNAMIC: + case TyTy::CLOSURE: + case TyTy::ERROR: + return new TyTy::ErrorType (0); + } + return new TyTy::ErrorType (0); +} + +TyTy::BaseType * +UnifyRules::expect_str (TyTy::StrType *ltype, TyTy::BaseType *rtype) +{ + switch (rtype->get_kind ()) + { + case TyTy::INFER: { + TyTy::InferType *r = static_cast (rtype); + bool is_valid + = r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL; + if (is_valid) + return ltype->clone (); + } + break; + + case TyTy::STR: + return rtype->clone (); + + case TyTy::ADT: + case TyTy::REF: + case TyTy::POINTER: + case TyTy::PARAM: + case TyTy::ARRAY: + case TyTy::SLICE: + case TyTy::FNDEF: + case TyTy::FNPTR: + case TyTy::TUPLE: + case TyTy::BOOL: + case TyTy::CHAR: + case TyTy::INT: + case TyTy::UINT: + case TyTy::FLOAT: + case TyTy::USIZE: + case TyTy::ISIZE: + case TyTy::NEVER: + case TyTy::PLACEHOLDER: + case TyTy::PROJECTION: + case TyTy::DYNAMIC: + case TyTy::CLOSURE: + case TyTy::ERROR: + return new TyTy::ErrorType (0); + } + return new TyTy::ErrorType (0); +} + +TyTy::BaseType * +UnifyRules::expect_reference (TyTy::ReferenceType *ltype, TyTy::BaseType *rtype) +{ + switch (rtype->get_kind ()) + { + case TyTy::INFER: { + TyTy::InferType *r = static_cast (rtype); + bool is_valid + = r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL; + if (is_valid) + return ltype->clone (); + } + break; + + case TyTy::REF: { + TyTy::ReferenceType &type = *static_cast (rtype); + auto base_type = ltype->get_base (); + auto other_base_type = type.get_base (); + + TyTy::BaseType *base_resolved + = UnifyRules::Resolve (TyTy::TyWithLocation (base_type), + TyTy::TyWithLocation (other_base_type), locus, + commit_flag, false /* emit_error */); + if (base_resolved->get_kind () == TyTy::TypeKind::ERROR) + { + return new TyTy::ErrorType (0); + } + + // rust is permissive about mutablity here you can always go from + // mutable to immutable but not the otherway round + bool mutability_ok = ltype->is_mutable () ? type.is_mutable () : true; + if (!mutability_ok) + { + return new TyTy::ErrorType (0); + } + + return new TyTy::ReferenceType (ltype->get_ref (), ltype->get_ty_ref (), + TyTy::TyVar (base_resolved->get_ref ()), + ltype->mutability ()); + } + break; + + case TyTy::STR: + case TyTy::ADT: + case TyTy::POINTER: + case TyTy::PARAM: + case TyTy::ARRAY: + case TyTy::SLICE: + case TyTy::FNDEF: + case TyTy::FNPTR: + case TyTy::TUPLE: + case TyTy::BOOL: + case TyTy::CHAR: + case TyTy::INT: + case TyTy::UINT: + case TyTy::FLOAT: + case TyTy::USIZE: + case TyTy::ISIZE: + case TyTy::NEVER: + case TyTy::PLACEHOLDER: + case TyTy::PROJECTION: + case TyTy::DYNAMIC: + case TyTy::CLOSURE: + case TyTy::ERROR: + return new TyTy::ErrorType (0); + } + return new TyTy::ErrorType (0); +} + +TyTy::BaseType * +UnifyRules::expect_pointer (TyTy::PointerType *ltype, TyTy::BaseType *rtype) +{ + switch (rtype->get_kind ()) + { + case TyTy::INFER: { + TyTy::InferType *r = static_cast (rtype); + bool is_valid + = r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL; + if (is_valid) + return ltype->clone (); + } + break; + + case TyTy::POINTER: { + TyTy::PointerType &type = *static_cast (rtype); + auto base_type = ltype->get_base (); + auto other_base_type = type.get_base (); + + TyTy::BaseType *base_resolved + = UnifyRules::Resolve (TyTy::TyWithLocation (base_type), + TyTy::TyWithLocation (other_base_type), locus, + commit_flag, false /* emit_error */); + if (base_resolved->get_kind () == TyTy::TypeKind::ERROR) + { + return new TyTy::ErrorType (0); + } + + // rust is permissive about mutablity here you can always go from + // mutable to immutable but not the otherway round + bool mutability_ok = ltype->is_mutable () ? type.is_mutable () : true; + if (!mutability_ok) + { + return new TyTy::ErrorType (0); + } + + return new TyTy::PointerType (ltype->get_ref (), ltype->get_ty_ref (), + TyTy::TyVar (base_resolved->get_ref ()), + ltype->mutability ()); + } + break; + + case TyTy::STR: + case TyTy::ADT: + case TyTy::REF: + case TyTy::PARAM: + case TyTy::ARRAY: + case TyTy::SLICE: + case TyTy::FNDEF: + case TyTy::FNPTR: + case TyTy::TUPLE: + case TyTy::BOOL: + case TyTy::CHAR: + case TyTy::INT: + case TyTy::UINT: + case TyTy::FLOAT: + case TyTy::USIZE: + case TyTy::ISIZE: + case TyTy::NEVER: + case TyTy::PLACEHOLDER: + case TyTy::PROJECTION: + case TyTy::DYNAMIC: + case TyTy::CLOSURE: + case TyTy::ERROR: + return new TyTy::ErrorType (0); + } + return new TyTy::ErrorType (0); +} + +TyTy::BaseType * +UnifyRules::expect_param (TyTy::ParamType *ltype, TyTy::BaseType *rtype) +{ + switch (rtype->get_kind ()) + { + case TyTy::INFER: { + TyTy::InferType *r = static_cast (rtype); + bool is_valid + = r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL; + if (is_valid) + return ltype->clone (); + } + break; + + case TyTy::PARAM: { + TyTy::ParamType &type = *static_cast (rtype); + // bool symbol_matches + // = ltype->get_symbol ().compare (type.get_symbol ()) == 0; + // // TODO + // // I think rustc checks a debruinj index + // if (symbol_matches) + // { + // return type.clone (); + // } + + // matching symbol is not going to work when we mix symbol's and have + // nested generics + + // bounds match? FIXME + + return type.clone (); + } + break; + + case TyTy::POINTER: + case TyTy::STR: + case TyTy::ADT: + case TyTy::REF: + case TyTy::ARRAY: + case TyTy::SLICE: + case TyTy::FNDEF: + case TyTy::FNPTR: + case TyTy::TUPLE: + case TyTy::BOOL: + case TyTy::CHAR: + case TyTy::INT: + case TyTy::UINT: + case TyTy::FLOAT: + case TyTy::USIZE: + case TyTy::ISIZE: + case TyTy::NEVER: + case TyTy::PLACEHOLDER: + case TyTy::PROJECTION: + case TyTy::DYNAMIC: + case TyTy::CLOSURE: + case TyTy::ERROR: + return new TyTy::ErrorType (0); + } + return new TyTy::ErrorType (0); +} + +TyTy::BaseType * +UnifyRules::expect_array (TyTy::ArrayType *ltype, TyTy::BaseType *rtype) +{ + switch (rtype->get_kind ()) + { + case TyTy::INFER: { + TyTy::InferType *r = static_cast (rtype); + bool is_valid + = r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL; + if (is_valid) + return ltype->clone (); + } + break; + + case TyTy::ARRAY: { + TyTy::ArrayType &type = *static_cast (rtype); + TyTy::BaseType *element_unify = UnifyRules::Resolve ( + TyTy::TyWithLocation (ltype->get_element_type ()), + TyTy::TyWithLocation (type.get_element_type ()), locus, commit_flag, + false /* emit_error*/); + + if (element_unify->get_kind () != TyTy::TypeKind::ERROR) + { + return new TyTy::ArrayType (type.get_ref (), type.get_ty_ref (), + type.get_ident ().locus, + type.get_capacity_expr (), + TyTy::TyVar ( + element_unify->get_ref ())); + } + } + break; + + case TyTy::PARAM: + case TyTy::POINTER: + case TyTy::STR: + case TyTy::ADT: + case TyTy::REF: + case TyTy::SLICE: + case TyTy::FNDEF: + case TyTy::FNPTR: + case TyTy::TUPLE: + case TyTy::BOOL: + case TyTy::CHAR: + case TyTy::INT: + case TyTy::UINT: + case TyTy::FLOAT: + case TyTy::USIZE: + case TyTy::ISIZE: + case TyTy::NEVER: + case TyTy::PLACEHOLDER: + case TyTy::PROJECTION: + case TyTy::DYNAMIC: + case TyTy::CLOSURE: + case TyTy::ERROR: + return new TyTy::ErrorType (0); + } + return new TyTy::ErrorType (0); +} + +TyTy::BaseType * +UnifyRules::expect_slice (TyTy::SliceType *ltype, TyTy::BaseType *rtype) +{ + switch (rtype->get_kind ()) + { + case TyTy::INFER: { + TyTy::InferType *r = static_cast (rtype); + bool is_valid + = r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL; + if (is_valid) + return ltype->clone (); + } + break; + + case TyTy::SLICE: { + TyTy::SliceType &type = *static_cast (rtype); + TyTy::BaseType *element_unify = UnifyRules::Resolve ( + TyTy::TyWithLocation (ltype->get_element_type ()), + TyTy::TyWithLocation (type.get_element_type ()), locus, commit_flag, + false /* emit_error*/); + + if (element_unify->get_kind () != TyTy::TypeKind::ERROR) + { + return new TyTy::SliceType (type.get_ref (), type.get_ty_ref (), + type.get_ident ().locus, + TyTy::TyVar ( + element_unify->get_ref ())); + } + } + break; + + case TyTy::PARAM: + case TyTy::POINTER: + case TyTy::STR: + case TyTy::ADT: + case TyTy::REF: + case TyTy::ARRAY: + case TyTy::FNDEF: + case TyTy::FNPTR: + case TyTy::TUPLE: + case TyTy::BOOL: + case TyTy::CHAR: + case TyTy::INT: + case TyTy::UINT: + case TyTy::FLOAT: + case TyTy::USIZE: + case TyTy::ISIZE: + case TyTy::NEVER: + case TyTy::PLACEHOLDER: + case TyTy::PROJECTION: + case TyTy::DYNAMIC: + case TyTy::CLOSURE: + case TyTy::ERROR: + return new TyTy::ErrorType (0); + } + return new TyTy::ErrorType (0); +} + +TyTy::BaseType * +UnifyRules::expect_fndef (TyTy::FnType *ltype, TyTy::BaseType *rtype) +{ + switch (rtype->get_kind ()) + { + case TyTy::INFER: { + TyTy::InferType *r = static_cast (rtype); + bool is_valid + = r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL; + if (is_valid) + return ltype->clone (); + } + break; + + case TyTy::FNDEF: { + TyTy::FnType &type = *static_cast (rtype); + if (ltype->num_params () != type.num_params ()) + { + return new TyTy::ErrorType (0); + } + + for (size_t i = 0; i < ltype->num_params (); i++) + { + auto a = ltype->param_at (i).second; + auto b = type.param_at (i).second; + + auto unified_param + = UnifyRules::Resolve (TyTy::TyWithLocation (a), + TyTy::TyWithLocation (b), locus, + commit_flag, false /* emit_errors */); + if (unified_param->get_kind () == TyTy::TypeKind::ERROR) + { + return new TyTy::ErrorType (0); + } + } + + auto unified_return + = UnifyRules::Resolve (TyTy::TyWithLocation ( + ltype->get_return_type ()), + TyTy::TyWithLocation (type.get_return_type ()), + locus, commit_flag, false /* emit_errors */); + if (unified_return->get_kind () == TyTy::TypeKind::ERROR) + { + return new TyTy::ErrorType (0); + } + + return ltype->clone (); + } + break; + + case TyTy::TUPLE: + case TyTy::BOOL: + case TyTy::CHAR: + case TyTy::INT: + case TyTy::FLOAT: + case TyTy::ISIZE: + case TyTy::ADT: + case TyTy::STR: + case TyTy::REF: + case TyTy::POINTER: + case TyTy::PARAM: + case TyTy::ARRAY: + case TyTy::SLICE: + case TyTy::FNPTR: + case TyTy::UINT: + case TyTy::USIZE: + case TyTy::NEVER: + case TyTy::PLACEHOLDER: + case TyTy::PROJECTION: + case TyTy::DYNAMIC: + case TyTy::CLOSURE: + case TyTy::ERROR: + return new TyTy::ErrorType (0); + } + return new TyTy::ErrorType (0); +} + +TyTy::BaseType * +UnifyRules::expect_fnptr (TyTy::FnPtr *ltype, TyTy::BaseType *rtype) +{ + switch (rtype->get_kind ()) + { + case TyTy::INFER: { + TyTy::InferType *r = static_cast (rtype); + bool is_valid + = r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL; + if (is_valid) + return ltype->clone (); + } + break; + + case TyTy::FNPTR: { + TyTy::FnPtr &type = *static_cast (rtype); + if (ltype->num_params () != type.num_params ()) + { + return new TyTy::ErrorType (0); + } + + for (size_t i = 0; i < ltype->num_params (); i++) + { + auto a = ltype->param_at (i); + auto b = type.param_at (i); + + auto unified_param + = UnifyRules::Resolve (TyTy::TyWithLocation (a), + TyTy::TyWithLocation (b), locus, + commit_flag, false /* emit_errors */); + if (unified_param->get_kind () == TyTy::TypeKind::ERROR) + { + return new TyTy::ErrorType (0); + } + } + + auto unified_return + = UnifyRules::Resolve (TyTy::TyWithLocation ( + ltype->get_return_type ()), + TyTy::TyWithLocation (type.get_return_type ()), + locus, commit_flag, false /* emit_errors */); + if (unified_return->get_kind () == TyTy::TypeKind::ERROR) + { + return new TyTy::ErrorType (0); + } + + return ltype->clone (); + } + break; + + case TyTy::FNDEF: { + TyTy::FnType &type = *static_cast (rtype); + auto this_ret_type = ltype->get_return_type (); + auto other_ret_type = type.get_return_type (); + + auto unified_result + = UnifyRules::Resolve (TyTy::TyWithLocation (this_ret_type), + TyTy::TyWithLocation (other_ret_type), locus, + commit_flag, false /*emit_errors*/); + if (unified_result->get_kind () == TyTy::TypeKind::ERROR) + { + return new TyTy::ErrorType (0); + } + + if (ltype->num_params () != type.num_params ()) + { + return new TyTy::ErrorType (0); + } + + for (size_t i = 0; i < ltype->num_params (); i++) + { + auto this_param = ltype->param_at (i); + auto other_param = type.param_at (i).second; + + auto unified_param + = UnifyRules::Resolve (TyTy::TyWithLocation (this_param), + TyTy::TyWithLocation (other_param), locus, + commit_flag, false /* emit_errors */); + if (unified_param->get_kind () == TyTy::TypeKind::ERROR) + { + return new TyTy::ErrorType (0); + } + } + + return ltype->clone (); + } + break; + + case TyTy::TUPLE: + case TyTy::BOOL: + case TyTy::CHAR: + case TyTy::INT: + case TyTy::FLOAT: + case TyTy::ISIZE: + case TyTy::ADT: + case TyTy::STR: + case TyTy::REF: + case TyTy::POINTER: + case TyTy::PARAM: + case TyTy::ARRAY: + case TyTy::SLICE: + case TyTy::UINT: + case TyTy::USIZE: + case TyTy::NEVER: + case TyTy::PLACEHOLDER: + case TyTy::PROJECTION: + case TyTy::DYNAMIC: + case TyTy::CLOSURE: + case TyTy::ERROR: + return new TyTy::ErrorType (0); + } + return new TyTy::ErrorType (0); +} + +TyTy::BaseType * +UnifyRules::expect_tuple (TyTy::TupleType *ltype, TyTy::BaseType *rtype) +{ + switch (rtype->get_kind ()) + { + case TyTy::INFER: { + TyTy::InferType *r = static_cast (rtype); + bool is_valid + = r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL; + if (is_valid) + return ltype->clone (); + } + break; + + case TyTy::TUPLE: { + TyTy::TupleType &type = *static_cast (rtype); + if (ltype->num_fields () != type.num_fields ()) + { + return new TyTy::ErrorType (0); + } + + std::vector fields; + for (size_t i = 0; i < ltype->num_fields (); i++) + { + TyTy::BaseType *bo = ltype->get_field (i); + TyTy::BaseType *fo = type.get_field (i); + + TyTy::BaseType *unified_ty + = UnifyRules::Resolve (TyTy::TyWithLocation (bo), + TyTy::TyWithLocation (fo), locus, + commit_flag, false /* emit_errors */); + if (unified_ty->get_kind () == TyTy::TypeKind::ERROR) + return new TyTy::ErrorType (0); + + fields.push_back (TyTy::TyVar (unified_ty->get_ref ())); + } + + return new TyTy::TupleType (type.get_ref (), type.get_ty_ref (), + type.get_ident ().locus, fields); + } + break; + + case TyTy::BOOL: + case TyTy::CHAR: + case TyTy::INT: + case TyTy::FLOAT: + case TyTy::ISIZE: + case TyTy::ADT: + case TyTy::STR: + case TyTy::REF: + case TyTy::POINTER: + case TyTy::PARAM: + case TyTy::ARRAY: + case TyTy::SLICE: + case TyTy::FNDEF: + case TyTy::FNPTR: + case TyTy::UINT: + case TyTy::USIZE: + case TyTy::NEVER: + case TyTy::PLACEHOLDER: + case TyTy::PROJECTION: + case TyTy::DYNAMIC: + case TyTy::CLOSURE: + case TyTy::ERROR: + return new TyTy::ErrorType (0); + } + return new TyTy::ErrorType (0); +} + +TyTy::BaseType * +UnifyRules::expect_bool (TyTy::BoolType *ltype, TyTy::BaseType *rtype) +{ + switch (rtype->get_kind ()) + { + case TyTy::INFER: { + TyTy::InferType *r = static_cast (rtype); + bool is_valid + = r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL; + if (is_valid) + return ltype->clone (); + } + break; + + case TyTy::BOOL: + return rtype->clone (); + + case TyTy::CHAR: + case TyTy::INT: + case TyTy::FLOAT: + case TyTy::ISIZE: + case TyTy::ADT: + case TyTy::STR: + case TyTy::REF: + case TyTy::POINTER: + case TyTy::PARAM: + case TyTy::ARRAY: + case TyTy::SLICE: + case TyTy::FNDEF: + case TyTy::FNPTR: + case TyTy::TUPLE: + case TyTy::UINT: + case TyTy::USIZE: + case TyTy::NEVER: + case TyTy::PLACEHOLDER: + case TyTy::PROJECTION: + case TyTy::DYNAMIC: + case TyTy::CLOSURE: + case TyTy::ERROR: + return new TyTy::ErrorType (0); + } + return new TyTy::ErrorType (0); +} + +TyTy::BaseType * +UnifyRules::expect_char (TyTy::CharType *ltype, TyTy::BaseType *rtype) +{ + switch (rtype->get_kind ()) + { + case TyTy::INFER: { + TyTy::InferType *r = static_cast (rtype); + bool is_valid + = r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL; + if (is_valid) + return ltype->clone (); + } + break; + + case TyTy::CHAR: + return rtype->clone (); + + case TyTy::INT: + case TyTy::FLOAT: + case TyTy::ISIZE: + case TyTy::ADT: + case TyTy::STR: + case TyTy::REF: + case TyTy::POINTER: + case TyTy::PARAM: + case TyTy::ARRAY: + case TyTy::SLICE: + case TyTy::FNDEF: + case TyTy::FNPTR: + case TyTy::TUPLE: + case TyTy::BOOL: + case TyTy::UINT: + case TyTy::USIZE: + case TyTy::NEVER: + case TyTy::PLACEHOLDER: + case TyTy::PROJECTION: + case TyTy::DYNAMIC: + case TyTy::CLOSURE: + case TyTy::ERROR: + return new TyTy::ErrorType (0); + } + return new TyTy::ErrorType (0); +} + +TyTy::BaseType * +UnifyRules::expect_int (TyTy::IntType *ltype, TyTy::BaseType *rtype) +{ + switch (rtype->get_kind ()) + { + case TyTy::INFER: { + TyTy::InferType *r = static_cast (rtype); + bool is_valid + = r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL + || r->get_infer_kind () == TyTy::InferType::InferTypeKind::INTEGRAL; + if (is_valid) + return ltype->clone (); + } + break; + + case TyTy::INT: { + TyTy::IntType &type = *static_cast (rtype); + bool is_valid = ltype->get_int_kind () == type.get_int_kind (); + if (is_valid) + return new TyTy::IntType (type.get_ref (), type.get_ty_ref (), + type.get_int_kind ()); + } + break; + + case TyTy::FLOAT: + case TyTy::ISIZE: + case TyTy::ADT: + case TyTy::STR: + case TyTy::REF: + case TyTy::POINTER: + case TyTy::PARAM: + case TyTy::ARRAY: + case TyTy::SLICE: + case TyTy::FNDEF: + case TyTy::FNPTR: + case TyTy::TUPLE: + case TyTy::BOOL: + case TyTy::CHAR: + case TyTy::UINT: + case TyTy::USIZE: + case TyTy::NEVER: + case TyTy::PLACEHOLDER: + case TyTy::PROJECTION: + case TyTy::DYNAMIC: + case TyTy::CLOSURE: + case TyTy::ERROR: + return new TyTy::ErrorType (0); + } + return new TyTy::ErrorType (0); +} + +TyTy::BaseType * +UnifyRules::expect_uint (TyTy::UintType *ltype, TyTy::BaseType *rtype) +{ + switch (rtype->get_kind ()) + { + case TyTy::INFER: { + TyTy::InferType *r = static_cast (rtype); + bool is_valid + = r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL + || r->get_infer_kind () == TyTy::InferType::InferTypeKind::INTEGRAL; + if (is_valid) + return ltype->clone (); + } + break; + + case TyTy::UINT: { + TyTy::UintType &type = *static_cast (rtype); + bool is_valid = ltype->get_uint_kind () == type.get_uint_kind (); + if (is_valid) + return new TyTy::UintType (type.get_ref (), type.get_ty_ref (), + type.get_uint_kind ()); + } + break; + + case TyTy::FLOAT: + case TyTy::ISIZE: + case TyTy::ADT: + case TyTy::STR: + case TyTy::REF: + case TyTy::POINTER: + case TyTy::PARAM: + case TyTy::ARRAY: + case TyTy::SLICE: + case TyTy::FNDEF: + case TyTy::FNPTR: + case TyTy::TUPLE: + case TyTy::BOOL: + case TyTy::CHAR: + case TyTy::INT: + case TyTy::USIZE: + case TyTy::NEVER: + case TyTy::PLACEHOLDER: + case TyTy::PROJECTION: + case TyTy::DYNAMIC: + case TyTy::CLOSURE: + case TyTy::ERROR: + return new TyTy::ErrorType (0); + } + return new TyTy::ErrorType (0); +} + +TyTy::BaseType * +UnifyRules::expect_float (TyTy::FloatType *ltype, TyTy::BaseType *rtype) +{ + switch (rtype->get_kind ()) + { + case TyTy::INFER: { + TyTy::InferType *r = static_cast (rtype); + bool is_valid + = r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL + || r->get_infer_kind () == TyTy::InferType::InferTypeKind::FLOAT; + if (is_valid) + return ltype->clone (); + } + break; + + case TyTy::FLOAT: { + TyTy::FloatType &type = *static_cast (rtype); + bool is_valid = ltype->get_float_kind () == type.get_float_kind (); + if (is_valid) + return new TyTy::FloatType (type.get_ref (), type.get_ty_ref (), + type.get_float_kind ()); + } + break; + + case TyTy::ISIZE: + case TyTy::ADT: + case TyTy::STR: + case TyTy::REF: + case TyTy::POINTER: + case TyTy::PARAM: + case TyTy::ARRAY: + case TyTy::SLICE: + case TyTy::FNDEF: + case TyTy::FNPTR: + case TyTy::TUPLE: + case TyTy::BOOL: + case TyTy::CHAR: + case TyTy::INT: + case TyTy::UINT: + case TyTy::USIZE: + case TyTy::NEVER: + case TyTy::PLACEHOLDER: + case TyTy::PROJECTION: + case TyTy::DYNAMIC: + case TyTy::CLOSURE: + case TyTy::ERROR: + return new TyTy::ErrorType (0); + } + return new TyTy::ErrorType (0); +} + +TyTy::BaseType * +UnifyRules::expect_isize (TyTy::ISizeType *ltype, TyTy::BaseType *rtype) +{ + switch (rtype->get_kind ()) + { + case TyTy::INFER: { + TyTy::InferType *r = static_cast (rtype); + bool is_valid + = r->get_infer_kind () != TyTy::InferType::InferTypeKind::FLOAT; + if (is_valid) + return ltype->clone (); + } + break; + + case TyTy::ISIZE: + return rtype->clone (); + + case TyTy::ADT: + case TyTy::STR: + case TyTy::REF: + case TyTy::POINTER: + case TyTy::PARAM: + case TyTy::ARRAY: + case TyTy::SLICE: + case TyTy::FNDEF: + case TyTy::FNPTR: + case TyTy::TUPLE: + case TyTy::BOOL: + case TyTy::CHAR: + case TyTy::INT: + case TyTy::UINT: + case TyTy::FLOAT: + case TyTy::USIZE: + case TyTy::NEVER: + case TyTy::PLACEHOLDER: + case TyTy::PROJECTION: + case TyTy::DYNAMIC: + case TyTy::CLOSURE: + case TyTy::ERROR: + return new TyTy::ErrorType (0); + } + return new TyTy::ErrorType (0); +} + +TyTy::BaseType * +UnifyRules::expect_usize (TyTy::USizeType *ltype, TyTy::BaseType *rtype) +{ + switch (rtype->get_kind ()) + { + case TyTy::INFER: { + TyTy::InferType *r = static_cast (rtype); + bool is_valid + = r->get_infer_kind () != TyTy::InferType::InferTypeKind::FLOAT; + if (is_valid) + return ltype->clone (); + } + break; + + case TyTy::USIZE: + return rtype->clone (); + + case TyTy::ADT: + case TyTy::STR: + case TyTy::REF: + case TyTy::POINTER: + case TyTy::PARAM: + case TyTy::ARRAY: + case TyTy::SLICE: + case TyTy::FNDEF: + case TyTy::FNPTR: + case TyTy::TUPLE: + case TyTy::BOOL: + case TyTy::CHAR: + case TyTy::INT: + case TyTy::UINT: + case TyTy::FLOAT: + case TyTy::ISIZE: + case TyTy::NEVER: + case TyTy::PLACEHOLDER: + case TyTy::PROJECTION: + case TyTy::DYNAMIC: + case TyTy::CLOSURE: + case TyTy::ERROR: + return new TyTy::ErrorType (0); + } + return new TyTy::ErrorType (0); +} + +TyTy::BaseType * +UnifyRules::expect_never (TyTy::NeverType *ltype, TyTy::BaseType *rtype) +{ + switch (rtype->get_kind ()) + { + case TyTy::INFER: { + TyTy::InferType *r = static_cast (rtype); + bool is_valid + = r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL; + if (is_valid) + return ltype->clone (); + } + break; + + case TyTy::NEVER: + return rtype->clone (); + + case TyTy::PLACEHOLDER: + case TyTy::PROJECTION: + case TyTy::DYNAMIC: + case TyTy::CLOSURE: + case TyTy::SLICE: + case TyTy::PARAM: + case TyTy::POINTER: + case TyTy::STR: + case TyTy::ADT: + case TyTy::REF: + case TyTy::ARRAY: + case TyTy::FNDEF: + case TyTy::FNPTR: + case TyTy::TUPLE: + case TyTy::BOOL: + case TyTy::CHAR: + case TyTy::INT: + case TyTy::UINT: + case TyTy::FLOAT: + case TyTy::USIZE: + case TyTy::ISIZE: + case TyTy::ERROR: + return new TyTy::ErrorType (0); + } + return new TyTy::ErrorType (0); +} + +TyTy::BaseType * +UnifyRules::expect_placeholder (TyTy::PlaceholderType *ltype, + TyTy::BaseType *rtype) +{ + switch (rtype->get_kind ()) + { + case TyTy::INFER: { + TyTy::InferType *r = static_cast (rtype); + bool is_valid + = r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL; + if (is_valid) + return ltype->clone (); + } + break; + + case TyTy::PLACEHOLDER: { + TyTy::PlaceholderType &type + = *static_cast (rtype); + bool symbol_match + = ltype->get_symbol ().compare (type.get_symbol ()) == 0; + if (symbol_match) + { + return type.clone (); + } + } + break; + + case TyTy::PROJECTION: + case TyTy::DYNAMIC: + case TyTy::CLOSURE: + case TyTy::SLICE: + case TyTy::PARAM: + case TyTy::POINTER: + case TyTy::STR: + case TyTy::ADT: + case TyTy::REF: + case TyTy::ARRAY: + case TyTy::FNDEF: + case TyTy::FNPTR: + case TyTy::TUPLE: + case TyTy::BOOL: + case TyTy::CHAR: + case TyTy::INT: + case TyTy::UINT: + case TyTy::FLOAT: + case TyTy::USIZE: + case TyTy::ISIZE: + case TyTy::NEVER: + case TyTy::ERROR: + return new TyTy::ErrorType (0); + } + return new TyTy::ErrorType (0); +} + +TyTy::BaseType * +UnifyRules::expect_projection (TyTy::ProjectionType *ltype, + TyTy::BaseType *rtype) +{ + switch (rtype->get_kind ()) + { + case TyTy::INFER: { + TyTy::InferType *r = static_cast (rtype); + bool is_valid + = r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL; + if (is_valid) + return ltype->clone (); + } + break; + + // FIXME + case TyTy::PROJECTION: + gcc_unreachable (); + break; + + case TyTy::DYNAMIC: + case TyTy::CLOSURE: + case TyTy::SLICE: + case TyTy::PARAM: + case TyTy::POINTER: + case TyTy::STR: + case TyTy::ADT: + case TyTy::REF: + case TyTy::ARRAY: + case TyTy::FNDEF: + case TyTy::FNPTR: + case TyTy::TUPLE: + case TyTy::BOOL: + case TyTy::CHAR: + case TyTy::INT: + case TyTy::UINT: + case TyTy::FLOAT: + case TyTy::USIZE: + case TyTy::ISIZE: + case TyTy::NEVER: + case TyTy::PLACEHOLDER: + case TyTy::ERROR: + return new TyTy::ErrorType (0); + } + return new TyTy::ErrorType (0); +} + +TyTy::BaseType * +UnifyRules::expect_dyn (TyTy::DynamicObjectType *ltype, TyTy::BaseType *rtype) +{ + switch (rtype->get_kind ()) + { + case TyTy::INFER: { + TyTy::InferType *r = static_cast (rtype); + bool is_valid + = r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL; + if (is_valid) + return ltype->clone (); + } + break; + + case TyTy::DYNAMIC: { + TyTy::DynamicObjectType &type + = *static_cast (rtype); + if (ltype->num_specified_bounds () != type.num_specified_bounds ()) + { + return new TyTy::ErrorType (0); + } + + if (!ltype->bounds_compatible (type, locus, true)) + { + return new TyTy::ErrorType (0); + } + + return ltype->clone (); + } + break; + + case TyTy::CLOSURE: + case TyTy::SLICE: + case TyTy::PARAM: + case TyTy::POINTER: + case TyTy::STR: + case TyTy::ADT: + case TyTy::REF: + case TyTy::ARRAY: + case TyTy::FNDEF: + case TyTy::FNPTR: + case TyTy::TUPLE: + case TyTy::BOOL: + case TyTy::CHAR: + case TyTy::INT: + case TyTy::UINT: + case TyTy::FLOAT: + case TyTy::USIZE: + case TyTy::ISIZE: + case TyTy::NEVER: + case TyTy::PLACEHOLDER: + case TyTy::PROJECTION: + case TyTy::ERROR: + return new TyTy::ErrorType (0); + } + return new TyTy::ErrorType (0); +} + +TyTy::BaseType * +UnifyRules::expect_closure (TyTy::ClosureType *ltype, TyTy::BaseType *rtype) +{ + switch (rtype->get_kind ()) + { + case TyTy::INFER: { + TyTy::InferType *r = static_cast (rtype); + bool is_valid + = r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL; + if (is_valid) + return ltype->clone (); + } + break; + + case TyTy::CLOSURE: { + TyTy::ClosureType &type = *static_cast (rtype); + if (ltype->get_def_id () != type.get_def_id ()) + { + return new TyTy::ErrorType (0); + } + + TyTy::BaseType *args_res + = UnifyRules::Resolve (TyTy::TyWithLocation ( + <ype->get_parameters ()), + TyTy::TyWithLocation (&type.get_parameters ()), + locus, commit_flag, false /* emit_error */); + if (args_res->get_kind () == TyTy::TypeKind::ERROR) + { + return new TyTy::ErrorType (0); + } + + TyTy::BaseType *res = UnifyRules::Resolve ( + TyTy::TyWithLocation (<ype->get_result_type ()), + TyTy::TyWithLocation (&type.get_result_type ()), locus, commit_flag, + false /* emit_error */); + if (res == nullptr || res->get_kind () == TyTy::TypeKind::ERROR) + { + return new TyTy::ErrorType (0); + } + + return ltype->clone (); + } + break; + + case TyTy::SLICE: + case TyTy::PARAM: + case TyTy::POINTER: + case TyTy::STR: + case TyTy::ADT: + case TyTy::REF: + case TyTy::ARRAY: + case TyTy::FNDEF: + case TyTy::FNPTR: + case TyTy::TUPLE: + case TyTy::BOOL: + case TyTy::CHAR: + case TyTy::INT: + case TyTy::UINT: + case TyTy::FLOAT: + case TyTy::USIZE: + case TyTy::ISIZE: + case TyTy::NEVER: + case TyTy::PLACEHOLDER: + case TyTy::PROJECTION: + case TyTy::DYNAMIC: + case TyTy::ERROR: + return new TyTy::ErrorType (0); + } + return new TyTy::ErrorType (0); +} + +} // namespace Resolver +} // namespace Rust diff --git a/gcc/rust/typecheck/rust-unify.h b/gcc/rust/typecheck/rust-unify.h new file mode 100644 index 00000000000..6e46b9642a6 --- /dev/null +++ b/gcc/rust/typecheck/rust-unify.h @@ -0,0 +1,91 @@ +// 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_UNIFY +#define RUST_UNIFY + +#include "rust-tyty-util.h" +#include "rust-hir-type-check.h" + +namespace Rust { +namespace Resolver { + +class UnifyRules +{ +public: + static TyTy::BaseType *Resolve (TyTy::TyWithLocation lhs, + TyTy::TyWithLocation rhs, Location locus, + bool commit_flag, bool emit_error); + +protected: + TyTy::BaseType *expect_inference_variable (TyTy::InferType *ltype, + TyTy::BaseType *rtype); + TyTy::BaseType *expect_adt (TyTy::ADTType *ltype, TyTy::BaseType *rtype); + TyTy::BaseType *expect_str (TyTy::StrType *ltype, TyTy::BaseType *rtype); + TyTy::BaseType *expect_reference (TyTy::ReferenceType *ltype, + TyTy::BaseType *rtype); + TyTy::BaseType *expect_pointer (TyTy::PointerType *ltype, + TyTy::BaseType *rtype); + TyTy::BaseType *expect_param (TyTy::ParamType *ltype, TyTy::BaseType *rtype); + TyTy::BaseType *expect_array (TyTy::ArrayType *ltype, TyTy::BaseType *rtype); + TyTy::BaseType *expect_slice (TyTy::SliceType *ltype, TyTy::BaseType *rtype); + TyTy::BaseType *expect_fndef (TyTy::FnType *ltype, TyTy::BaseType *rtype); + TyTy::BaseType *expect_fnptr (TyTy::FnPtr *ltype, TyTy::BaseType *rtype); + TyTy::BaseType *expect_tuple (TyTy::TupleType *ltype, TyTy::BaseType *rtype); + TyTy::BaseType *expect_bool (TyTy::BoolType *ltype, TyTy::BaseType *rtype); + TyTy::BaseType *expect_char (TyTy::CharType *ltype, TyTy::BaseType *rtype); + TyTy::BaseType *expect_int (TyTy::IntType *ltype, TyTy::BaseType *rtype); + TyTy::BaseType *expect_uint (TyTy::UintType *ltype, TyTy::BaseType *rtype); + TyTy::BaseType *expect_float (TyTy::FloatType *ltype, TyTy::BaseType *rtype); + TyTy::BaseType *expect_isize (TyTy::ISizeType *ltype, TyTy::BaseType *rtype); + TyTy::BaseType *expect_usize (TyTy::USizeType *ltype, TyTy::BaseType *rtype); + TyTy::BaseType *expect_never (TyTy::NeverType *ltype, TyTy::BaseType *rtype); + TyTy::BaseType *expect_placeholder (TyTy::PlaceholderType *ltype, + TyTy::BaseType *rtype); + TyTy::BaseType *expect_projection (TyTy::ProjectionType *ltype, + TyTy::BaseType *rtype); + TyTy::BaseType *expect_dyn (TyTy::DynamicObjectType *ltype, + TyTy::BaseType *rtype); + TyTy::BaseType *expect_closure (TyTy::ClosureType *ltype, + TyTy::BaseType *rtype); + +private: + UnifyRules (TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs, + Location locus, bool commit_flag, bool emit_error); + + void emit_type_mismatch () const; + void commit (TyTy::BaseType *resolved); + TyTy::BaseType *go (); + + TyTy::BaseType *get_base (); + TyTy::BaseType *get_other (); + + TyTy::TyWithLocation lhs; + TyTy::TyWithLocation rhs; + Location locus; + bool commit_flag; + bool emit_error; + + Analysis::Mappings &mappings; + TypeCheckContext &context; +}; + +} // namespace Resolver +} // namespace Rust + +#endif // RUST_UNIFY diff --git a/gcc/testsuite/rust/compile/never_type_err1.rs b/gcc/testsuite/rust/compile/never_type1.rs similarity index 52% rename from gcc/testsuite/rust/compile/never_type_err1.rs rename to gcc/testsuite/rust/compile/never_type1.rs index 52b1283fadf..8d56176fee3 100644 --- a/gcc/testsuite/rust/compile/never_type_err1.rs +++ b/gcc/testsuite/rust/compile/never_type1.rs @@ -1,8 +1,7 @@ fn test() { let a; - // FIXME: Unimplemented features - a = if true { // { dg-error "expected .T.. got .!." } + a = if true { return; } else { return; From patchwork Wed Apr 5 14:03: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: 79681 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp352299vqo; Wed, 5 Apr 2023 07:31:37 -0700 (PDT) X-Google-Smtp-Source: AKy350ZD7as4f2SZ+ZxgQJD/ct8+19pb9r/0hapXXIftzF430wNOntm88SPGmoiiaYtI3vUiG768 X-Received: by 2002:a05:6402:299:b0:4fa:d2b1:9176 with SMTP id l25-20020a056402029900b004fad2b19176mr2151887edv.22.1680705097152; Wed, 05 Apr 2023 07:31:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705097; cv=none; d=google.com; s=arc-20160816; b=nlmQxyahZjWpuAnxX7l6kmM+PvNsB/wU2xkvz6y06CHaNaxXE9S7Clben63xiVjaa0 7FyykZTrw8yKuOnPSj0rtitFCMxxxoa+B8Qf6+SZ1Cvwa8aNHPDHarDJeNBAq43ooqeB qB67tzFed4gUZBHHAovX/kfvpu1rwRFEElZ8zUXv3UoFzmhScGEKt0MbWVKmllu0ej5u 6YNuZwSrC2QhBKn6zsx8gwh1aJlkvN+dOkvF/mYsshzdhRcprGKhZfqypgaC8dp+nLUW bgY1p/1VwpBN+mBqYnPqr8PbCYts0FAvijRsKO9PaP2b7u4piK/T1jg3WUJ1Y03YsvH/ beIA== 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=O2C3MPkFyXnroG9vHH/7lMQUeq/H1QA7c60IBOW3oXM=; b=wPw7UtqUepDWIafrcWfZLnQiuQHXvRmMtlXm2qyGcrDmXxhXE0a0uAklWy6a6oo88X 9GmjErOdUOagzouWsLXmjsOQNipfztSyHIze9iLV8iw1ocU0xXp884x+JiSXlZYohvag 0N5NVk317P6PVrpRiIVVpTOXZUZe8xwKruOch7PbAuAGUkXjpQGViQLjzMk+DQtqDEmv UTfI4Vt7llHS+yCCahKt/4nLd81DJEiXYHtnF7hfAh7kxV1Yx0TITDlavwsUHrp+qRkv YdQQvEz62JTgEj2NpbFyFn8bqAEuQR8OeqBUjrdMQmVrlzeZQHomHBW9kfhjV2FkjEiY qhwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b="EDks/L8h"; 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 z3-20020aa7d403000000b004fcbdc5577fsi1100192edq.59.2023.04.05.07.31.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:31:37 -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="EDks/L8h"; 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 136193881D1B for ; Wed, 5 Apr 2023 14:12:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id DDBD03876898 for ; Wed, 5 Apr 2023 14:06:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DDBD03876898 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-x32b.google.com with SMTP id l15-20020a05600c4f0f00b003ef6d684102so18506801wmq.3 for ; Wed, 05 Apr 2023 07:06:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703564; 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=O2C3MPkFyXnroG9vHH/7lMQUeq/H1QA7c60IBOW3oXM=; b=EDks/L8hosp5VOqgLD5k4dOM7KyeooqOAlGjQzKj9k8fO9g2mzjJ/tIDEq33w+x8xd RjN2McMR1UbNyzsT08NBI0TmXdSuGfAmZCt4K27YQuuh2ToJOGc8RdbruEcFtxBLVNRL jocTh4v+Ow/ZPW22bxxKoYcosTcO6VY4TmO+8isUcSL0S5GkcGXcEM2uY++oo5ub7ura Gv8S0ll6+MBVg+N2g/b+8BwocU60k9vX/k68FT1FyUMqBvAK2gp2WUW85zAT/XrlvFRS 8AsQ+nIsbWJA8vkQCF1ak23my0Zo3EH2vkuETGZNLpCk1Lv4gY5iYmRcfrYcLZ/b2Zvu G1gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703564; 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=O2C3MPkFyXnroG9vHH/7lMQUeq/H1QA7c60IBOW3oXM=; b=KoMs/ZXHrAcy3PxFD+7ur1F87nWLjpu2pr3+sTm/BIqzWj5UBY3Ejryr39yIk7GtW3 SNTw7UTQK0yLuxbybMsEEVO/wpOnYr7XR3M3XgFqI6ZvbOrIt35+3T8W7Ro65Mb/sLME yjwNsZlxy+cyHyXEsAKd9k1gb4eNxdcwSS5L1a8nbpOMEd+vp/mPw77fag+UhncwNG1/ fS3uIYpZ+HH50fjW0TvhSkeC+magBrfLtFF6wRLrIOqG1Q2Gndb2l5mo7LaQAWwaUrkR cN+uSDmIk2yGxjTCpg0rGPxhlCHqrzCJFP0+dbRT6I2kQpU52+d2SGuVfx9EaKEtEl+S TtRw== X-Gm-Message-State: AAQBX9f45tJ7m07+R9gmyb87D9Cj5umX2Uy7BEE0sXzeocEg5d/xOSDs iVcYsA8Qj0v7FKTamlVVb8OmqKDCMr8MxikcHw== X-Received: by 2002:a1c:4c09:0:b0:3ef:6fee:8057 with SMTP id z9-20020a1c4c09000000b003ef6fee8057mr4728496wmf.25.1680703564305; Wed, 05 Apr 2023 07:06:04 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:04 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 51/88] gccrs: Fix nullptr dereference Date: Wed, 5 Apr 2023 16:03:35 +0200 Message-Id: <20230405140411.3016563-52-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?1762347027952583836?= X-GMAIL-MSGID: =?utf-8?q?1762347027952583836?= From: Philip Herron When we check if this is concrete the guard checks to ensure the argument is non null but the check here is wrongly returning early when the check is non null meaning when it is null and therefore not concrete it will end up doing a null dereference. Signed-off-by: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-tyty-subst.cc (SubstitutionArg::is_conrete): fix check --- gcc/rust/typecheck/rust-tyty-subst.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc b/gcc/rust/typecheck/rust-tyty-subst.cc index 7f5bb22687d..996bbf2d885 100644 --- a/gcc/rust/typecheck/rust-tyty-subst.cc +++ b/gcc/rust/typecheck/rust-tyty-subst.cc @@ -213,8 +213,8 @@ SubstitutionArg::is_error () const bool SubstitutionArg::is_conrete () const { - if (argument != nullptr) - return true; + if (argument == nullptr) + return false; if (argument->get_kind () == TyTy::TypeKind::PARAM) return false; From patchwork Wed Apr 5 14:03: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: 79686 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp353837vqo; Wed, 5 Apr 2023 07:33:45 -0700 (PDT) X-Google-Smtp-Source: AKy350Z+MyJvkLW5ae2rtdh48ikhtrKHN9pdjWvPELrGJDVrEsCuxib+ehAro7WsoLYWIL9QETJL X-Received: by 2002:a05:6402:b33:b0:502:a6b3:6de with SMTP id bo19-20020a0564020b3300b00502a6b306demr2256507edb.17.1680705225809; Wed, 05 Apr 2023 07:33:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705225; cv=none; d=google.com; s=arc-20160816; b=EUanCN0n5MVHtqw45uvmw5h3qEQhHRRqNZnV/ZxSVEUUWrzQO7faKzfD7qh4rVCzrI SOEPQR36aagwbqS/ElIyZEps45pJktxEOTskDrJQk9TkU/Q9HeZ5TCySjfPKsNIRiWMY t+IlhmUPQIzorhk9zJONdDTfJOU2JLSrBcuB19+SaGhyp1VmaPfeUc2qCkmMrlFexmC0 8g7f/6QdgIEfP/xT+rjkDSQ1yPRW610pK22vZLaxT8a/7Sbm51UW9nQpLD5cAt98/trf SnCDi7Vxo0ONLvTrpwPokKyj6blqam5y3sOg6i65qAv+1cpnXzMsL6fbuCMVBzQ0nFeh ZXLQ== 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=0Ruhi0YVCTS0PZIDwZd2lXBkluzz5LJvgOYcNswll30=; b=iwVVuy12MgeMhVP/Tr8wZpLMjgNR/uNvsW5mrFkhBM1351kCRBTCxp0wRnk/9FDvU/ UW841im/2oejGcuc/jKh1hymUE/E4ihinmzEQtFPjypTXyB1U0xCcLGnTRyaod3/kSa7 h94YV22jELkdNZTYx9eyaMnfQK4qrcWStunje9YxvlmxTclpkQ2G5uCeRq45FFPf4k5G VUfLq+Wgeblti/jnUIlcFeK/j2DVHhuGUiwoWv/5K1fgPR2NtdqSpO5eh4xhR3g/js45 tjwz9+vRVtHBnLMLa3TDuMbnPNJxALoM30hHiJVIgOnJ1m0x6whcndoRWvEE+6S5cMCn Nogg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=XsrWV1+h; 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 gq15-20020a170906e24f00b00928b3b7d509si4990451ejb.90.2023.04.05.07.33.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:33:45 -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=XsrWV1+h; 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 BF122388D721 for ; Wed, 5 Apr 2023 14:13:10 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 87BFA38708EC for ; Wed, 5 Apr 2023 14:06:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 87BFA38708EC 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-x331.google.com with SMTP id v6-20020a05600c470600b003f034269c96so11821917wmo.4 for ; Wed, 05 Apr 2023 07:06:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703565; 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=0Ruhi0YVCTS0PZIDwZd2lXBkluzz5LJvgOYcNswll30=; b=XsrWV1+h/XFd5S2uGcpIRHK+YJ/iKkVR1AHNpAHpZVgDv2vacaNuyhYxJVDBKPHrgK Dce1AIYP5/TwZcTgbHYhYHx+Ge3L4ZQFv4LM3MgImySL+jWIQ+hkvSAFuDb+QarOH89E /Pyz9ddEcQyg/K+CN9uwKtXWyzDl0k50rIvvMnN0v3+sIzclC/vbi0NcHclhfOBx6fTa zi4lPGXMAfynvmPJ/CrbOqme3DlSf8+xVXuxX8Rv1hS1UTc7/MMeO3XbH0MC7nVhNeVC bvo12pRntAuMdp/wstYkTY4AKbUYV3TIo7012PXiPzp54DMsAIpG7vYfWDRIB9lhPcF+ gGOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703565; 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=0Ruhi0YVCTS0PZIDwZd2lXBkluzz5LJvgOYcNswll30=; b=Ql5UOu/gOWFsuHR+GNZcVpO9Plj8HhIAs7CdtlYHilSSPy25NVFWUQwBn3uZdnWzWV TWYQlHHRL2S4y91bYy1S/D6JBcLx5f54MG8QCPxPHNlqJ7qw+x5UWTGwckbOR35I0g5z tg9y6x9DdEec92vYpZJQpik/pUsQDY2dsk4zcq3BiiB5YpkQh7CsbjhgP6aYxAf1t08n kLn4DIzSy7v7jNPwMAWtKnWw5pJAFCFG7XijSsA2lT92UQAVcx8GA6A2CO1Yws5kV55O CB/z9EkobDAEzHXHVPpJ4bRKk8IxZYkyI2zbAX/FAtx46CPmoQ5y4IeB+vgzTAuVIfW0 0xMQ== X-Gm-Message-State: AAQBX9cZZ0MmMjcq0PNrTi4voqCETIPLL+V2M3N1weCRFRZIj8O7VqX4 2VCjnAfMkjIYe1Tn4aTxSutXweW0b19dxUGFlw== X-Received: by 2002:a7b:cbcc:0:b0:3ed:2eb5:c2e8 with SMTP id n12-20020a7bcbcc000000b003ed2eb5c2e8mr5301927wmi.10.1680703564926; Wed, 05 Apr 2023 07:06:04 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:04 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 52/88] gccrs: Add missing Sized, Copy and Clone lang item mappings Date: Wed, 5 Apr 2023 16:03:36 +0200 Message-Id: <20230405140411.3016563-53-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?1762347162920218711?= X-GMAIL-MSGID: =?utf-8?q?1762347162920218711?= From: Philip Herron We need these lang items to be defined and later down the line the mappings will be used to implement proper copy and clone logic. Fixes #1786 Signed-off-by: Philip Herron gcc/rust/ChangeLog: * util/rust-lang-item.h: gcc/testsuite/ChangeLog: * rust/compile/issue-1786.rs: New test. --- gcc/rust/util/rust-lang-item.h | 24 ++++++++++++++++++++++++ gcc/testsuite/rust/compile/issue-1786.rs | 23 +++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 gcc/testsuite/rust/compile/issue-1786.rs diff --git a/gcc/rust/util/rust-lang-item.h b/gcc/rust/util/rust-lang-item.h index 29c364bad61..c5ef6200fb4 100644 --- a/gcc/rust/util/rust-lang-item.h +++ b/gcc/rust/util/rust-lang-item.h @@ -80,6 +80,12 @@ public: FN_ONCE, FN_ONCE_OUTPUT, + // markers + COPY, + CLONE, + SIZED, + + // delimiter UNKNOWN, }; @@ -237,6 +243,18 @@ public: { return ItemType::FN_ONCE_OUTPUT; } + else if (item.compare ("copy") == 0) + { + return ItemType::COPY; + } + else if (item.compare ("clone") == 0) + { + return ItemType::CLONE; + } + else if (item.compare ("sized") == 0) + { + return ItemType::SIZED; + } return ItemType::UNKNOWN; } @@ -321,6 +339,12 @@ public: return "fn_once"; case FN_ONCE_OUTPUT: return "fn_once_output"; + case COPY: + return "copy"; + case CLONE: + return "clone"; + case SIZED: + return "sized"; case UNKNOWN: return ""; diff --git a/gcc/testsuite/rust/compile/issue-1786.rs b/gcc/testsuite/rust/compile/issue-1786.rs new file mode 100644 index 00000000000..f73b63d0cb6 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-1786.rs @@ -0,0 +1,23 @@ +#[lang = "clone"] +trait Clone { + fn clone(&self) -> Self; + + fn clone_from(&mut self, source: &Self) { + *self = source.clone() + } +} + +#[lang = "copy"] +pub trait Copy: Clone { + // Empty. +} + +mod impls { + use super::Clone; + + impl Clone for char { + fn clone(&self) -> Self { + *self + } + } +} From patchwork Wed Apr 5 14:03: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: 79708 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp359342vqo; Wed, 5 Apr 2023 07:41:52 -0700 (PDT) X-Google-Smtp-Source: AKy350Ycsh6G/ACkMADDosVN3PWqIpeIEz8U687QMocP/Zr/MvwxxbfPoGLlPqaMcylnHxpg7VNb X-Received: by 2002:a17:906:f988:b0:931:6b2b:a671 with SMTP id li8-20020a170906f98800b009316b2ba671mr2996374ejb.65.1680705712177; Wed, 05 Apr 2023 07:41:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705712; cv=none; d=google.com; s=arc-20160816; b=Q1JwTHw7W11hvjF6Iui5kJ+us1rBqpURAocMmG1AjI1XVUvOUyU1If2uAPLvqJczHt SeNfRTJvnBB2p2evObVLOP7L7Ou4mbRh/rPfQes8FLY/3OuYBISb7+nut6PGKGmNoFNh zm6DqRjXmzSpmhobz0dWrTLkz537Qy4aHo2V901w+xYBEEkfl6OdXbbdfqcwUBkH5oAR fukodkwWBJnUG29QLUZJ+4BbhKxwkpniUh/ZpPFPZPIaMhz1Bs/1gVVtqw8v0vHas1Kt APlDMI/EKeTuXa5H57U/xAgAuo6ndVt78f+VsqsYBYWmCqp5KOb+iolNjauGr5UwQzlp gW1A== 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=JdMuYAAo+JLXDSgsw/5eSKXlrKv4TUSMTCWd93BaoCY=; b=ym4kTCANK2gTtpCdW4YhTWPS1PbGiVAKVaVGKKmtdQ6WSfrYVVIZzPHBtTU0HQqr7h TCMBW06CEn5yvEi2zeTeZ7+FJ7kv9bJQnDKIC6TECZruuy1wCDHirIb+6lFpxMpiUPQ3 KvsxbCQWdNCoNxxBt4LQELmqKEN46did4K33/lWFFXmNnLDoN9qgCCrXsmnvdAbAEf/K Yrs6ouAyzq4FjRLU8A/NBMa1mETrjgFt22EGADjIcijrN7N6iSwpCq12h/RHj1nOWHXQ jTSG5u0s9fSipeZmwaQ3VhFMr8SindNNRritKqNL5CxA+tyqb1N/NTgZT/IpN2UO8elW LKgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=GjbUnohL; 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 zm9-20020a170906994900b00930943f134esi2146293ejb.8.2023.04.05.07.41.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:41:52 -0700 (PDT) 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=GjbUnohL; 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 51E413A61B99 for ; Wed, 5 Apr 2023 14:15:10 +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 4AC003834685 for ; Wed, 5 Apr 2023 14:06:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4AC003834685 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 n19-20020a05600c501300b003f064936c3eso1252596wmr.0 for ; Wed, 05 Apr 2023 07:06:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703565; 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=JdMuYAAo+JLXDSgsw/5eSKXlrKv4TUSMTCWd93BaoCY=; b=GjbUnohLK3AiKljmXdBEXrR3StmFATLbNO5qfh4N7aFBuRAFBotrwqoK+FI/iLOlmp AsqBzSMu8mqAABbXI/WkRw7lJKldVDacRAOmhOUoF6kwzxo4bIzx59DTeZ+xO4un/bdp xXi3KjebhOX6UCpwLsW+0IZJQtDHIbp1gRZsq8DVwDYmV22fmsd7Xz4EaWXSylT37gKR GkPPMnnoAL5oKJXc2z06J8mhDp3zgUCVpfT37hwor7pVqyfal61l6L4pdDwgcBvtIl/z q+E15DD8Q/0YD/Oc1AkNa32qLN6bycTdta4YIa89GXjjrxv2CLCaRibh5m5JogV7iGVp hzVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703565; 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=JdMuYAAo+JLXDSgsw/5eSKXlrKv4TUSMTCWd93BaoCY=; b=ZBLFOcyOXZb1xTNbTMvQboIV58ST0qn3Ff5sWrIfu+TrJTyKRYiigWvAnKPhFgE9zN CGA1XYxDumAmWF6kzLSjzLFjb1Ci29MnfsJP03raPp36VFe80IiJHJHq1HQWbhnIBtNk UPcZGXWYb9APnQkN27td/26HKkVof4HEtHdi9WKd+5ff5snTuS0Fsule7WmG8pS6RFiO q10P2WocTPsoCSskSIHZ0U3JHYnURsch3ufCWXUoDKe3QcfEVIr4eUZ50+I8y2Yrc4bG Q47c+X9L+7Q3cL6PfAinQOOHobdOdPtbvdqhBVz+zHlxB2gJdAfCm21aW5WGdVRnpqEW tofg== X-Gm-Message-State: AAQBX9c7FAtDxfwoDzjYwLuWohRhXAbmwbQF6g2Npcnm5dYLCvzsyXhV eMX+QlxK9VlaUwARSUHivt+kFhN7w8uG0ypPvA== X-Received: by 2002:a1c:6a13:0:b0:3df:e468:17dc with SMTP id f19-20020a1c6a13000000b003dfe46817dcmr4632970wmc.40.1680703565577; Wed, 05 Apr 2023 07:06:05 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:05 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 53/88] gccrs: Fix higher ranked trait bounds computation of self Date: Wed, 5 Apr 2023 16:03:37 +0200 Message-Id: <20230405140411.3016563-54-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?1762347673329426028?= X-GMAIL-MSGID: =?utf-8?q?1762347673329426028?= From: Philip Herron This updates the higher ranked trait bounds computation to handle ambigious cases. When we have a slice for example: let slice = &a[1..3]; This works by reusing the Index operator overload from libcore, so when the index range of 1..3 is computed, the type system needs to compute what the types of index are; this works by integer inference variables Range<> that need to be unified with the impl Index for Range which computes the real type of usize for the index. This is fine but what happens when we have the Copy and Clone traits bounds which have implementations for all the primitive types i8, i16, i32, i64... which is valid for any integer inference variable so the code prior to this patch would have grabbed the first impl it would have found and used it which is incorrect. When we have integer or float inference variables we need to look for their respective defaults or emit an ambigious type bound error. Signed-off-by: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-hir-trait-reference.h: add const infterface * typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::get_generic_param): make const (SubstitutionRef::monomorphize): fix issue * typecheck/rust-tyty-subst.h: constify interface --- gcc/rust/typecheck/rust-hir-trait-reference.h | 1 + gcc/rust/typecheck/rust-tyty-subst.cc | 107 ++++++++++++++++-- gcc/rust/typecheck/rust-tyty-subst.h | 2 +- 3 files changed, 102 insertions(+), 8 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-trait-reference.h b/gcc/rust/typecheck/rust-hir-trait-reference.h index 9b4461b9f18..adb63b468d1 100644 --- a/gcc/rust/typecheck/rust-hir-trait-reference.h +++ b/gcc/rust/typecheck/rust-hir-trait-reference.h @@ -496,6 +496,7 @@ public: HIR::ImplBlock *get_impl_block () { return impl; } TyTy::BaseType *get_self () { return self; } + const TyTy::BaseType *get_self () const { return self; } TyTy::BaseType * setup_associated_types (const TyTy::BaseType *self, diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc b/gcc/rust/typecheck/rust-tyty-subst.cc index 996bbf2d885..3dfe95873bc 100644 --- a/gcc/rust/typecheck/rust-tyty-subst.cc +++ b/gcc/rust/typecheck/rust-tyty-subst.cc @@ -65,7 +65,7 @@ SubstitutionParamMapping::get_param_ty () const } const HIR::TypeParam & -SubstitutionParamMapping::get_generic_param () +SubstitutionParamMapping::get_generic_param () const { return generic; } @@ -892,8 +892,7 @@ SubstitutionRef::monomorphize () // setup any associated type mappings for the specified bonds and this // type auto candidates = Resolver::TypeBoundsProbe::Probe (binding); - - Resolver::AssociatedImplTrait *associated_impl_trait = nullptr; + std::vector associated_impl_traits; for (auto &probed_bound : candidates) { const Resolver::TraitReference *bound_trait_ref @@ -914,15 +913,109 @@ SubstitutionRef::monomorphize () = associated->get_self ()->can_eq (binding, false); if (found_trait && found_self) { - associated_impl_trait = associated; - break; + associated_impl_traits.push_back (associated); } } } - if (associated_impl_trait != nullptr) + if (!associated_impl_traits.empty ()) { - associated_impl_trait->setup_associated_types (binding, bound); + // This code is important when you look at slices for example when + // you have a slice such as: + // + // let slice = &array[1..3] + // + // the higher ranked bounds will end up having an Index trait + // implementation for Range so we need this code to resolve + // that we have an integer inference variable that needs to become + // a usize + // + // The other complicated issue is that we might have an intrinsic + // which requires the :Clone or Copy bound but the libcore adds + // implementations for all the integral types so when there are + // multiple candidates we need to resolve to the default + // implementation for that type otherwise its an error for + // ambiguous type bounds + + if (associated_impl_traits.size () == 1) + { + Resolver::AssociatedImplTrait *associate_impl_trait + = associated_impl_traits.at (0); + associate_impl_trait->setup_associated_types (binding, bound); + } + else + { + // if we have a non-general inference variable we need to be + // careful about the selection here + bool is_infer_var + = binding->get_kind () == TyTy::TypeKind::INFER; + bool is_integer_infervar + = is_infer_var + && static_cast (binding) + ->get_infer_kind () + == TyTy::InferType::InferTypeKind::INTEGRAL; + bool is_float_infervar + = is_infer_var + && static_cast (binding) + ->get_infer_kind () + == TyTy::InferType::InferTypeKind::FLOAT; + + Resolver::AssociatedImplTrait *associate_impl_trait = nullptr; + if (is_integer_infervar) + { + TyTy::BaseType *type = nullptr; + bool ok = context->lookup_builtin ("i32", &type); + rust_assert (ok); + + for (auto &impl : associated_impl_traits) + { + bool found = impl->get_self ()->is_equal (*type); + if (found) + { + associate_impl_trait = impl; + break; + } + } + } + else if (is_float_infervar) + { + TyTy::BaseType *type = nullptr; + bool ok = context->lookup_builtin ("f64", &type); + rust_assert (ok); + + for (auto &impl : associated_impl_traits) + { + bool found = impl->get_self ()->is_equal (*type); + if (found) + { + associate_impl_trait = impl; + break; + } + } + } + + if (associate_impl_trait == nullptr) + { + // go for the first one? or error out? + auto &mappings = *Analysis::Mappings::get (); + const auto &type_param = subst.get_generic_param (); + const auto *trait_ref = bound.get (); + + RichLocation r (type_param.get_locus ()); + r.add_range (bound.get_locus ()); + r.add_range ( + mappings.lookup_location (binding->get_ref ())); + + rust_error_at ( + r, "ambiguous type bound for trait %s and type %s", + trait_ref->get_name ().c_str (), + binding->get_name ().c_str ()); + + return false; + } + + associate_impl_trait->setup_associated_types (binding, bound); + } } } } diff --git a/gcc/rust/typecheck/rust-tyty-subst.h b/gcc/rust/typecheck/rust-tyty-subst.h index 039eb36589e..982861e9bc6 100644 --- a/gcc/rust/typecheck/rust-tyty-subst.h +++ b/gcc/rust/typecheck/rust-tyty-subst.h @@ -48,7 +48,7 @@ public: const ParamType *get_param_ty () const; - const HIR::TypeParam &get_generic_param (); + const HIR::TypeParam &get_generic_param () const; // this is used for the backend to override the HirId ref of the param to // what the concrete type is for the rest of the context From patchwork Wed Apr 5 14:03: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: 79710 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp360303vqo; Wed, 5 Apr 2023 07:43:27 -0700 (PDT) X-Google-Smtp-Source: AKy350YbO1xMgjbqOWOy8PfRySuiYxNyDuY+wMSoONsQHYX0F8EgWZzDjDUZHGI57SRSSkOZTIvV X-Received: by 2002:a17:906:53c3:b0:947:791b:fdcb with SMTP id p3-20020a17090653c300b00947791bfdcbmr2844867ejo.21.1680705807460; Wed, 05 Apr 2023 07:43:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705807; cv=none; d=google.com; s=arc-20160816; b=nrVlpwQN8A+Rrz2Siz1AGpa+bTGh1PU+jBza7arGnk+uZODY4j9bqxs2i8MoaT1TDT ZwnkO5SYA4yBEsW2a31qEiqmr2cC4ZR6qpELHzFlbYQP+cxKCPVu/Y7Ho4j/62rNxlI6 sfhTAYYU3GHqd/KthP3RoOPL4e5+yyvINhaVssSD9GyIxKj30FfRsnYjLk2fJYQdKPhc oEGLDim3A+RkyvYAxKh/3Z0YDFHlzXpmSjGTEFhQF8Rec9JVI3xKyveMFGgc0DoZiBsY MTaGC9JDoP8iOPikKUu+PlZtV5s7yHBd+0CHI8lJ8SQPpldvusX9at+B2p/57y22NXgJ ehMw== 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=PGjpvYFX4Kl/wH2pKgg62ebXRthGcemGu+cRhKKQn2U=; b=pVfIDOL982/0DNhmLaXB/Dho++4+jooEKWAh60FQv+eW6rfIAU6VPbUifENVYXi48U ss8H5OfoVYZM7Zy64PzQ6k/pVbtxD8dOClslSHNXaPxpUrkvRuf4E+pC/dYqfhdR//3E PkLEPh8fJEB5IUKbmLrENgqWDsR6WLDdNBNhHQnNQMdxawyszyD/RK0PdvkUr+ON7SP6 4XhQwLeU3e2jyoD9sFMdpGVutjjFhHbuOeICLPJiDzR7M8/U3++R+AWfRVt6SY4QvozY ksvvjB1hujFZakEdrJGTrel57fXYo/pTbba5Zp6qbw6qO4C9TRdQALmsYkdnYD5LJ/EX RMFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=M3J8ghys; 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 ky10-20020a170907778a00b00933f92e9917si12157270ejc.371.2023.04.05.07.43.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:43:27 -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=M3J8ghys; 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 D4F36392EEC3 for ; Wed, 5 Apr 2023 14:15:32 +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 B6C9C385417B for ; Wed, 5 Apr 2023 14:06:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B6C9C385417B 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 n19so20972094wms.0 for ; Wed, 05 Apr 2023 07:06:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703566; 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=PGjpvYFX4Kl/wH2pKgg62ebXRthGcemGu+cRhKKQn2U=; b=M3J8ghysnJzBHbw0ltuPPfpa8BeLrtVX6JoaY6HTEFsnrUOwtns7ICttNcFe5joegS N9mJyYHyPiosSZ2pgrs3MJhM4HwVWpmeb07RK1OERP7y4bHvFnCvA6u314N2exhGTrbc hwydkZEitz10lDzrrC7ZdCRbeqdUI728JD6vTBBBGf8awrWVQi3mSIZciAewX6bj4aTx PdEaXuh9G9HgCXujyxAQM0BuvVv15dfsZsn74AsZ/sRTu7zy34Tk1lBhOcLHzrl4brtj pLR0h4ja7u4IPTNih+EpHfKvlwRt/LanZSMKYLrOUwNaYcaXtbPf0ZV3fPK0PFO/rlsc 7k9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703566; 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=PGjpvYFX4Kl/wH2pKgg62ebXRthGcemGu+cRhKKQn2U=; b=OIotwm3HAFsLjR1HNoEuyf7toah49P6LFNrDEMVW6Po9LtFSCCixrQXyJiCOnawDuU 8anTHTBDAKcFVNs7DGP779ipVYXmRTkOgznfcA14jNznuj3DDXetpHaopwGDdXfg1Qd8 Y5WZfA7g1XKab/2ESxiwsuUY6NXCI8IQv6AR1dEcXpmb1om0OkL8bMQPjriHvEgjWcOO dOh3mnqYeoioW+1EwmgUVmHjfRV5wUd3D3nIn7glacu+bh+CaLcF5s8PU7mfy3gUmXyy +7EEEdl9VY4xFZflsrn9TvnXF5PNXo1mZxR2WWaHaeqFsoZNZbWy/Ybeh3E5RI/YKR1X 4oTQ== X-Gm-Message-State: AAQBX9e5PL0qkPglRRx9vZ7mQBCXvSRZmUkQTsV5A/tv8bGBGu7WvhcZ Cym/pljmAIBlkm4XelnRj+UeQdEZPZtpH3eoeQ== X-Received: by 2002:a7b:c4d3:0:b0:3ed:551b:b78f with SMTP id g19-20020a7bc4d3000000b003ed551bb78fmr4674244wmk.4.1680703566304; Wed, 05 Apr 2023 07:06:06 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:05 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 54/88] gccrs: Remove bad error message on checking function arguments Date: Wed, 5 Apr 2023 16:03:38 +0200 Message-Id: <20230405140411.3016563-55-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.6 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?1762347772887629617?= X-GMAIL-MSGID: =?utf-8?q?1762347772887629617?= From: Philip Herron Signed-off-by: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): remove error message gcc/testsuite/ChangeLog: * rust/compile/func3.rs: update test case --- gcc/rust/typecheck/rust-tyty-call.cc | 5 ----- gcc/testsuite/rust/compile/func3.rs | 1 - 2 files changed, 6 deletions(-) diff --git a/gcc/rust/typecheck/rust-tyty-call.cc b/gcc/rust/typecheck/rust-tyty-call.cc index 4c6442e2d82..67e2866cbce 100644 --- a/gcc/rust/typecheck/rust-tyty-call.cc +++ b/gcc/rust/typecheck/rust-tyty-call.cc @@ -140,8 +140,6 @@ TypeCheckCallExpr::visit (FnType &type) argument->get_locus ()); if (resolved_argument_type->get_kind () == TyTy::TypeKind::ERROR) { - rust_error_at (argument->get_locus (), - "Type Resolution failure on parameter"); return; } } @@ -193,8 +191,6 @@ TypeCheckCallExpr::visit (FnPtr &type) TyWithLocation (argument_expr_tyty, arg_locus), argument->get_locus ()); if (resolved_argument_type->get_kind () == TyTy::TypeKind::ERROR) { - rust_error_at (argument->get_locus (), - "Type Resolution failure on parameter"); return; } @@ -301,7 +297,6 @@ TypeCheckMethodCallExpr::check (FnType &type) TyWithLocation (argument_expr_tyty, arg_locus), arg_locus); if (resolved_argument_type->get_kind () == TyTy::TypeKind::ERROR) { - rust_error_at (arg_locus, "Type Resolution failure on parameter"); return new ErrorType (type.get_ref ()); } diff --git a/gcc/testsuite/rust/compile/func3.rs b/gcc/testsuite/rust/compile/func3.rs index 2a329476118..002e5c90ab5 100644 --- a/gcc/testsuite/rust/compile/func3.rs +++ b/gcc/testsuite/rust/compile/func3.rs @@ -5,5 +5,4 @@ fn test(a: i32, b: i32) -> i32 { fn main() { let a = test(1, true); // { dg-error "expected .i32. got .bool." "" { target *-*-* } .-1 } - // { dg-error "Type Resolution failure on parameter" "" { target *-*-* } .-2 } } From patchwork Wed Apr 5 14:03: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: 79716 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp362126vqo; Wed, 5 Apr 2023 07:46:20 -0700 (PDT) X-Google-Smtp-Source: AKy350aCEHxA5wOf45NN3UxRlsa5Kmikdg8UyPL1Kxs70ByqlmnnNrQfM2M9PStblhCGHir1pk53 X-Received: by 2002:a50:ed16:0:b0:4ac:b6b2:1233 with SMTP id j22-20020a50ed16000000b004acb6b21233mr2044575eds.30.1680705980532; Wed, 05 Apr 2023 07:46:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705980; cv=none; d=google.com; s=arc-20160816; b=UQ/pGc+P7NhvFVSi3GghYGELYuNj3rds3RddEzCDP6SHidUd/1OqhsSi2JnioL9+AC lBgevmnBDM7+omKkhc0tP4lFGok63VMwU/F8LuTfWwQlKvd1hRFACmpvgZUT38thbfPZ tP4P4NLk7JZqZ9Y6yvKDuo9Flix7Rbm0A97qKEdxyM5ZGNJmb9suqPXWcB6qccOvoSFj 6ZMFcOyS2UVi5iMObGgmqDVPsVwf3R16JKBDH6y99GGm+JmvmnUG62ekyJve84JuK3vl RxhZO6NgMrqNW4aMs1fmPCryZR6+jVovBcnixR3x/4kps/RH9ZGZgLzkRJ4VWgCSVTDh A7Sw== 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=1eRh257QnJUVYyQs1yxXT1PKV2j4Po5H5hnErHdy/Dg=; b=MUaQAoiFYAf9oth/SK2jpovQn3E84+1Z1YOqI1PCwOwAEI3JMGGqzsobWGs7KuHk+T Lnj1wfhpNALOOlMqZH89zww5dIb1svd+r8A9NgsZwhV4imQpatZFVcsDniiojFyNomV/ /9iNboVtvhh1EkCgTOBQhREUB9XxqIP3YCT2B7PKvYM5eE0XnleGpuo1bJNziXW7A/07 wmZbI5GGFkqCH8OL4ZqxFqZRzpUjcAh0tkls6vquHrOhrDDJfISmXdtaxGGz7AfCSR2J ZzU2fjqWKkRM+aWXpP/n8Nc3wPgHd4T2JUTtgRHPrmVSMs9m440SbzsmQzKDGMhOYcg1 jK/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=NxFIaQFD; 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 d15-20020a50fb0f000000b005021f0d574bsi2723123edq.658.2023.04.05.07.46.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:46:20 -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=NxFIaQFD; 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 8AF5A386E550 for ; Wed, 5 Apr 2023 14:16:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id A29633870896 for ; Wed, 5 Apr 2023 14:06:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A29633870896 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-x32c.google.com with SMTP id m8so10053028wmq.5 for ; Wed, 05 Apr 2023 07:06:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703567; 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=1eRh257QnJUVYyQs1yxXT1PKV2j4Po5H5hnErHdy/Dg=; b=NxFIaQFDPjtiXZwwRuGVKVuw9f2FPS7w/16xoIv1M2OLNNK39sKj3ZQ/8UQ3o3G4tY UVwB9cMR6zAqKUo/AX/IFNpx0q8HUc9vCZjklxItzQLfs2PI4bcMxjxJqQZU5AbV1RnP FXumMk/S10+LH+Wl2aia6TgT01imMRe0JttQWHL4/YpuRnmT792SrV20sVElk6yQp2O3 EJktjtuXId4ULk7Cn+PVCynR14oRVYNb6XZXle+xDVAnEv2d/8rx7vFW8L0Ujrp2s2jP e8P8Xl3XkYfc4SCFbnrcC9mafMW9euTYP3wvvgga1bouQhx8L1+kgsJlb9FmPUr1VuMF 0h/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703567; 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=1eRh257QnJUVYyQs1yxXT1PKV2j4Po5H5hnErHdy/Dg=; b=4P1tCCfqmxVNOcrGDgs1yW2MQ2zzqt7cPfA4CP+9qtYRLh7/0FJBDu7t/xC1pgu5LG urqKKbLTjpiz34v/G0zEfw0zE11eLkNCHVt4lRqES0QoqOWAz9Y7SSsA/LJ74WttteL1 GrPtS4P6DtEetRdmq36sgZooy/zyOMru0iaNAQVLEbmcW6OUAh22n4XOQTUiAhkmlK34 z8fDJijxCEP18CwEYmw43bZkKK+uFJ0jByDrVDMfWiBmfPhsVn3XhR26kKGBSigSskXk xyHlRZBO1qIMfa5EmbLTphv0tFZsMF2EBS/qksPGMmsTQ0JPmw8jNu2ynsixeUc7MBFr kEqw== X-Gm-Message-State: AAQBX9cRUOS+aG/d4s+f0RfNWX51WKllbBuWUowvCNTvrCmMQgMwGSU6 bx0nb3Qo47ujsXPX+w6l7pU+4m3G+upac4DU7g== X-Received: by 2002:a05:600c:211a:b0:3ea:f73e:9d8a with SMTP id u26-20020a05600c211a00b003eaf73e9d8amr4915202wml.30.1680703566968; Wed, 05 Apr 2023 07:06:06 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:06 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 55/88] gccrs: Add general TypeBounds checks Date: Wed, 5 Apr 2023 16:03:39 +0200 Message-Id: <20230405140411.3016563-56-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?1762347954613817358?= X-GMAIL-MSGID: =?utf-8?q?1762347954613817358?= From: Philip Herron Existing tests are updated to use libcore copy and clone implementation. Addresses #1725 Signed-off-by: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-unify.cc (UnifyRules::go): ensure the bounds are checked gcc/testsuite/ChangeLog: * rust/compile/torture/intrinsics-4.rs: implement Copy trait * rust/compile/torture/intrinsics-5.rs: likewise * rust/execute/torture/atomic_load.rs: likewise * rust/execute/torture/atomic_store.rs: likewise * rust/bounds1.rs: New test. --- gcc/rust/typecheck/rust-unify.cc | 11 ++++ gcc/testsuite/rust/bounds1.rs | 19 ++++++ .../rust/compile/torture/intrinsics-4.rs | 63 +++++++++++++++++- .../rust/compile/torture/intrinsics-5.rs | 66 ++++++++++++++++++- .../rust/execute/torture/atomic_load.rs | 59 ++++++++++++++++- .../rust/execute/torture/atomic_store.rs | 59 ++++++++++++++++- 6 files changed, 271 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/rust/bounds1.rs diff --git a/gcc/rust/typecheck/rust-unify.cc b/gcc/rust/typecheck/rust-unify.cc index 072f76133bc..415ffcdc6ea 100644 --- a/gcc/rust/typecheck/rust-unify.cc +++ b/gcc/rust/typecheck/rust-unify.cc @@ -124,6 +124,17 @@ UnifyRules::go () rust_debug ("unify::go ltype={%s} rtype={%s}", ltype->debug_str ().c_str (), rtype->debug_str ().c_str ()); + // check bounds + if (ltype->num_specified_bounds () > 0) + { + if (!ltype->bounds_compatible (*rtype, locus, true)) + { + // already emitted an error + emit_error = false; + return new TyTy::ErrorType (0); + } + } + switch (ltype->get_kind ()) { case TyTy::INFER: diff --git a/gcc/testsuite/rust/bounds1.rs b/gcc/testsuite/rust/bounds1.rs new file mode 100644 index 00000000000..665836088be --- /dev/null +++ b/gcc/testsuite/rust/bounds1.rs @@ -0,0 +1,19 @@ +mod core { + mod ops { + #[lang = "add"] + pub trait Add { + type Output; + + fn add(self, rhs: Rhs) -> Self::Output; + } + } +} + +pub fn foo>(a: T) -> i32 { + // { dg-error "bounds not satisfied for f32 .Add. is not satisfied" "" { target *-*-* } .-1 } + a + a +} + +pub fn main() { + foo(123f32); +} diff --git a/gcc/testsuite/rust/compile/torture/intrinsics-4.rs b/gcc/testsuite/rust/compile/torture/intrinsics-4.rs index 243d4460089..4e09f1089b0 100644 --- a/gcc/testsuite/rust/compile/torture/intrinsics-4.rs +++ b/gcc/testsuite/rust/compile/torture/intrinsics-4.rs @@ -1,10 +1,67 @@ -trait Copy {} +#[lang = "sized"] +pub trait Sized {} + +#[lang = "clone"] +pub trait Clone: Sized { + fn clone(&self) -> Self; + + fn clone_from(&mut self, source: &Self) { + *self = source.clone() + } +} + +mod impls { + use super::Clone; + + macro_rules! impl_clone { + ($($t:ty)*) => { + $( + impl Clone for $t { + fn clone(&self) -> Self { + *self + } + } + )* + } + } + + impl_clone! { + usize u8 u16 u32 u64 // u128 + isize i8 i16 i32 i64 // i128 + f32 f64 + bool char + } +} + +#[lang = "copy"] +pub trait Copy: Clone { + // Empty. +} + +mod copy_impls { + use super::Copy; + + macro_rules! impl_copy { + ($($t:ty)*) => { + $( + impl Copy for $t {} + )* + } + } + + impl_copy! { + usize u8 u16 u32 u64 // u128 + isize i8 i16 i32 i64 // i128 + f32 f64 + bool char + } +} 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); + pub fn atomic_store_unordered(dst: *mut T, val: T); } fn main() { @@ -15,6 +72,6 @@ fn main() { 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); + 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 index 7fd84dcd635..ffad0bd3a85 100644 --- a/gcc/testsuite/rust/compile/torture/intrinsics-5.rs +++ b/gcc/testsuite/rust/compile/torture/intrinsics-5.rs @@ -1,4 +1,61 @@ -trait Copy {} +#[lang = "sized"] +pub trait Sized {} + +#[lang = "clone"] +pub trait Clone: Sized { + fn clone(&self) -> Self; + + fn clone_from(&mut self, source: &Self) { + *self = source.clone() + } +} + +mod impls { + use super::Clone; + + macro_rules! impl_clone { + ($($t:ty)*) => { + $( + impl Clone for $t { + fn clone(&self) -> Self { + *self + } + } + )* + } + } + + impl_clone! { + usize u8 u16 u32 u64 // u128 + isize i8 i16 i32 i64 // i128 + f32 f64 + bool char + } +} + +#[lang = "copy"] +pub trait Copy: Clone { + // Empty. +} + +mod copy_impls { + use super::Copy; + + macro_rules! impl_copy { + ($($t:ty)*) => { + $( + impl Copy for $t {} + )* + } + } + + impl_copy! { + usize u8 u16 u32 u64 // u128 + isize i8 i16 i32 i64 // i128 + f32 f64 + bool char + } +} extern "rust-intrinsic" { pub fn atomic_store_seqcst(dst: *mut T, value: T); @@ -24,6 +81,13 @@ impl VeryLargeType { } } +impl Clone for VeryLargeType { + fn clone(&self) -> Self { + *self + } +} +impl Copy for VeryLargeType {} + fn main() { let mut dst = VeryLargeType::new(0); let mut b = false; diff --git a/gcc/testsuite/rust/execute/torture/atomic_load.rs b/gcc/testsuite/rust/execute/torture/atomic_load.rs index 28ed8ae78f1..6e7383aa7e9 100644 --- a/gcc/testsuite/rust/execute/torture/atomic_load.rs +++ b/gcc/testsuite/rust/execute/torture/atomic_load.rs @@ -1,4 +1,61 @@ -trait Copy {} +#[lang = "sized"] +pub trait Sized {} + +#[lang = "clone"] +pub trait Clone: Sized { + fn clone(&self) -> Self; + + fn clone_from(&mut self, source: &Self) { + *self = source.clone() + } +} + +mod impls { + use super::Clone; + + macro_rules! impl_clone { + ($($t:ty)*) => { + $( + impl Clone for $t { + fn clone(&self) -> Self { + *self + } + } + )* + } + } + + impl_clone! { + usize u8 u16 u32 u64 // u128 + isize i8 i16 i32 i64 // i128 + f32 f64 + bool char + } +} + +#[lang = "copy"] +pub trait Copy: Clone { + // Empty. +} + +mod copy_impls { + use super::Copy; + + macro_rules! impl_copy { + ($($t:ty)*) => { + $( + impl Copy for $t {} + )* + } + } + + impl_copy! { + usize u8 u16 u32 u64 // u128 + isize i8 i16 i32 i64 // i128 + f32 f64 + bool char + } +} extern "rust-intrinsic" { pub fn atomic_load_seqcst(src: *const T) -> T; diff --git a/gcc/testsuite/rust/execute/torture/atomic_store.rs b/gcc/testsuite/rust/execute/torture/atomic_store.rs index 9f248b4f823..46960a7a186 100644 --- a/gcc/testsuite/rust/execute/torture/atomic_store.rs +++ b/gcc/testsuite/rust/execute/torture/atomic_store.rs @@ -1,4 +1,61 @@ -trait Copy {} +#[lang = "sized"] +pub trait Sized {} + +#[lang = "clone"] +pub trait Clone: Sized { + fn clone(&self) -> Self; + + fn clone_from(&mut self, source: &Self) { + *self = source.clone() + } +} + +mod impls { + use super::Clone; + + macro_rules! impl_clone { + ($($t:ty)*) => { + $( + impl Clone for $t { + fn clone(&self) -> Self { + *self + } + } + )* + } + } + + impl_clone! { + usize u8 u16 u32 u64 // u128 + isize i8 i16 i32 i64 // i128 + f32 f64 + bool char + } +} + +#[lang = "copy"] +pub trait Copy: Clone { + // Empty. +} + +mod copy_impls { + use super::Copy; + + macro_rules! impl_copy { + ($($t:ty)*) => { + $( + impl Copy for $t {} + )* + } + } + + impl_copy! { + usize u8 u16 u32 u64 // u128 + isize i8 i16 i32 i64 // i128 + f32 f64 + bool char + } +} extern "rust-intrinsic" { pub fn atomic_store_seqcst(dst: *mut T, val: T); From patchwork Wed Apr 5 14:03: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: 79712 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp360680vqo; Wed, 5 Apr 2023 07:44:04 -0700 (PDT) X-Google-Smtp-Source: AKy350ZPYCHjv2KdAclKyUCherxF/jelWCmTA5fcBtJFbR5CuNgTDhVoR/KwM0pg4sCMpcplsfGE X-Received: by 2002:a17:906:f988:b0:931:6b2b:a671 with SMTP id li8-20020a170906f98800b009316b2ba671mr3002750ejb.65.1680705844248; Wed, 05 Apr 2023 07:44:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705844; cv=none; d=google.com; s=arc-20160816; b=chrjmg1nrxxrilI8592XHYAp6QfuUzGrjdo6Y9m+BD4kxs1a+P5biEYWcCX7QDPIFD UebEsG7ILGQByJ/JgHlxsL4olds6MgdRJ6QN5cdATYrYlWotwXbWdKzWRTEd/ASuXz3Z 4XpGsmTJ7Fm3EEtyoXZGyfGrW4JxnmN6OZ++f+K5NlLHOzCOXw6um/p5S2FCTi23fWg3 2uCCAep8fsxUautadBAISp/PTPps+zG5gXhji8iE47C+9Cdu6n7/btr5IZgD7VqzfyKm ffSyYD2Xj4YwBZrwDkFjfNwQ24qMROHU0P+7+ncThBrfL2EYHhEn6HAsXrU+fPLu4CJy juUw== 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=9UBQ+p1jT9qA5jvv44LEn9QBEyXI/JebO71l2/u1D2U=; b=zpcKN9/oymvblh/FCr/yjsz226JY4u1Aa9O5tBUFW0GNCBmt4ntK3aIeqYDmEcE79V t+UyrF6yJnfgOeGt4+cuHvcjEJnS6xL6IsPLiiHPEPEyBsJ7vbMP9++MM2HY4SJPAmF6 ps7NLwtwipE6bYJ2gPMd+v1OJJT3n3RV0CWvaAMzWXKsGtiGsOQOhiQCnoRpmGulzbRo z5mebFP60WVkkUqReqCwZP1CX/Nx01INbnFIectkwYodk96NKHo9WI22rELvjc2HA34c 2oBI4tgMJDRDsMIvzRsKb7M7JRsUXZC0Yeb+U73q8Q4tA7Y5HReDoHO8d7jhtY6wISCT Wbqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Hoo+zdcC; 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 bn17-20020a170906c0d100b008b179adfaf5si7883048ejb.466.2023.04.05.07.44.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:44:04 -0700 (PDT) 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=Hoo+zdcC; 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 19FC8384F39F for ; Wed, 5 Apr 2023 14:15:44 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 4367C385B53B for ; Wed, 5 Apr 2023 14:06:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4367C385B53B 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-x331.google.com with SMTP id v6-20020a05600c470600b003f034269c96so11822012wmo.4 for ; Wed, 05 Apr 2023 07:06:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703568; 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=9UBQ+p1jT9qA5jvv44LEn9QBEyXI/JebO71l2/u1D2U=; b=Hoo+zdcCDnarqncmlDQYN5uaB///zIAMxmplhhem3+OntQdUudkVQkmvBhRJBVlVSL F8ebn7sG1kHoHcYZ42Rt37hfNAGfbMaCbpBeqAsTwNvBfCtoVSRyP0GWmQMB8YxsHFjm IJr7aaEUtPkp8QQnM8DJ4MRihfCXxoFbNIVZa20JyYfgdrh/ildRnXMYDNNXRyghT2vL YEifFBncfLfDAm1Pr+qLO+gYmkDA45wJ87qsU4LbITgLIVo+450lK4ledMR7HXGf8bgH WsSaItDok2nuAG3PYmcLBnY4ylEY+gMpJUzFcIC7DRp2aarhiqxeJHZOfRkjfCl690mk NkPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703568; 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=9UBQ+p1jT9qA5jvv44LEn9QBEyXI/JebO71l2/u1D2U=; b=hZwi6W4tLwpfSV8XzmNBHjfIW9Tqwl84bmE8oHeKJ6gZ7fgPDvz/Un6Ieq8RPSAUe5 O8r5ZZaZKqxCEtuhziY8E306q/qNCi2WnLrCgjBg5SxFUMhL3NQBds602jMjnnTq4zsf bUhcCYAUBnKbsXYBg4C6oBtP0k93EbJt2nOKIIgcu2p6SccPQFcWyigV53Ex+EmQrOvC XVAbAXX4zR/oLe42PKmDObdLE8xJdzpg5151Zk/e5Lik34qTSKkNjHvpJVmpZV2T2MJR dswOLjWPjc06Aly8SdrtA1utCdPKKB/EoqI8LtowEbFWVygD3WLClkFHwrhkOHTXRkDd VWZQ== X-Gm-Message-State: AAQBX9e+mjar2yB6oLbx/XYC78qZ6xtjTuUjgTPJ5Mh7Lb9XMLTpjC2J Lm1cocIIB2takwJQ2W6D+7LiJgaRGh9g3ADowg== X-Received: by 2002:a05:600c:2189:b0:3ed:a07b:c59d with SMTP id e9-20020a05600c218900b003eda07bc59dmr4969543wme.21.1680703567668; Wed, 05 Apr 2023 07:06:07 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:07 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [committed 56/88] gccrs: Add support for TuplePattern in let statements Date: Wed, 5 Apr 2023 16:03:40 +0200 Message-Id: <20230405140411.3016563-57-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.6 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?1762347811473764374?= X-GMAIL-MSGID: =?utf-8?q?1762347811473764374?= From: Owen Avery gcc/rust/ChangeLog: * hir/tree/rust-hir-pattern.h (TuplePatternItemsRanged::get_lower_patterns): Add method. (TuplePatternItemsRanged::get_upper_patterns): Add method. * backend/rust-compile-pattern.cc (CompilePatternLet::visit): Implement TuplePattern visitor. * backend/rust-compile-pattern.h (CompilePatternLet::visit): Move TuplePattern visitor out of header file. gcc/testsuite/ChangeLog: * rust/execute/torture/let-pattern-1.rs: New test. Signed-off-by: Owen Avery --- gcc/rust/backend/rust-compile-pattern.cc | 87 +++++++++++++++++++ gcc/rust/backend/rust-compile-pattern.h | 7 +- gcc/rust/hir/tree/rust-hir-pattern.h | 18 ++++ .../rust/execute/torture/let-pattern-1.rs | 4 + 4 files changed, 110 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/rust/execute/torture/let-pattern-1.rs diff --git a/gcc/rust/backend/rust-compile-pattern.cc b/gcc/rust/backend/rust-compile-pattern.cc index bad98be44d0..cb4b082f9c8 100644 --- a/gcc/rust/backend/rust-compile-pattern.cc +++ b/gcc/rust/backend/rust-compile-pattern.cc @@ -387,5 +387,92 @@ CompilePatternLet::visit (HIR::WildcardPattern &pattern) } } +void +CompilePatternLet::visit (HIR::TuplePattern &pattern) +{ + rust_assert (pattern.has_tuple_pattern_items ()); + + tree tuple_type = TyTyResolveCompile::compile (ctx, ty); + tree init_stmt; + Bvariable *tmp_var + = ctx->get_backend ()->temporary_variable (ctx->peek_fn ().fndecl, + NULL_TREE, tuple_type, init_expr, + false, pattern.get_locus (), + &init_stmt); + tree access_expr + = ctx->get_backend ()->var_expression (tmp_var, pattern.get_locus ()); + ctx->add_statement (init_stmt); + + switch (pattern.get_items ()->get_pattern_type ()) + { + case HIR::TuplePatternItems::TuplePatternItemType::RANGED: { + size_t tuple_idx = 0; + auto &items + = static_cast (*pattern.get_items ()); + + auto &items_lower = items.get_lower_patterns (); + auto &items_upper = items.get_upper_patterns (); + + for (auto &sub : items_lower) + { + TyTy::BaseType *ty_sub = nullptr; + HirId pattern_id = pattern.get_pattern_mappings ().get_hirid (); + bool ok = ctx->get_tyctx ()->lookup_type (pattern_id, &ty_sub); + rust_assert (ok); + + tree sub_init = ctx->get_backend ()->struct_field_expression ( + access_expr, tuple_idx, sub->get_locus ()); + CompilePatternLet::Compile (sub.get (), sub_init, ty_sub, + rval_locus, ctx); + tuple_idx++; + } + + rust_assert (ty->get_kind () == TyTy::TypeKind::TUPLE); + tuple_idx = static_cast (*ty).num_fields () + - items_upper.size (); + + for (auto &sub : items_upper) + { + TyTy::BaseType *ty_sub = nullptr; + HirId pattern_id = pattern.get_pattern_mappings ().get_hirid (); + bool ok = ctx->get_tyctx ()->lookup_type (pattern_id, &ty_sub); + rust_assert (ok); + + tree sub_init = ctx->get_backend ()->struct_field_expression ( + access_expr, tuple_idx, sub->get_locus ()); + CompilePatternLet::Compile (sub.get (), sub_init, ty_sub, + rval_locus, ctx); + tuple_idx++; + } + + return; + } + case HIR::TuplePatternItems::TuplePatternItemType::MULTIPLE: { + size_t tuple_idx = 0; + auto &items = static_cast ( + *pattern.get_items ()); + + for (auto &sub : items.get_patterns ()) + { + TyTy::BaseType *ty_sub = nullptr; + HirId pattern_id = pattern.get_pattern_mappings ().get_hirid (); + bool ok = ctx->get_tyctx ()->lookup_type (pattern_id, &ty_sub); + rust_assert (ok); + + tree sub_init = ctx->get_backend ()->struct_field_expression ( + access_expr, tuple_idx, sub->get_locus ()); + CompilePatternLet::Compile (sub.get (), sub_init, ty_sub, + rval_locus, ctx); + tuple_idx++; + } + + return; + } + default: { + gcc_unreachable (); + } + } +} + } // namespace Compile } // namespace Rust diff --git a/gcc/rust/backend/rust-compile-pattern.h b/gcc/rust/backend/rust-compile-pattern.h index ddf5b14265e..8f44b7b5dbb 100644 --- a/gcc/rust/backend/rust-compile-pattern.h +++ b/gcc/rust/backend/rust-compile-pattern.h @@ -101,6 +101,7 @@ public: void visit (HIR::IdentifierPattern &) override; void visit (HIR::WildcardPattern &) override; + void visit (HIR::TuplePattern &) override; // check for unimplemented Pattern HIR nodes. void visit (HIR::LiteralPattern &pattern) override @@ -146,12 +147,6 @@ public: "struct pattern let statements not supported"); } - void visit (HIR::TuplePattern &pattern) override - { - rust_sorry_at (pattern.get_locus (), - "tuple pattern let statements not supported"); - } - void visit (HIR::TupleStructPattern &pattern) override { rust_sorry_at (pattern.get_locus (), diff --git a/gcc/rust/hir/tree/rust-hir-pattern.h b/gcc/rust/hir/tree/rust-hir-pattern.h index 83b041d2770..1b08ab88a34 100644 --- a/gcc/rust/hir/tree/rust-hir-pattern.h +++ b/gcc/rust/hir/tree/rust-hir-pattern.h @@ -1142,6 +1142,24 @@ public: return TuplePatternItemType::RANGED; } + std::vector > &get_lower_patterns () + { + return lower_patterns; + } + const std::vector > &get_lower_patterns () const + { + return lower_patterns; + } + + std::vector > &get_upper_patterns () + { + return upper_patterns; + } + const std::vector > &get_upper_patterns () const + { + return upper_patterns; + } + protected: /* Use covariance to implement clone function as returning this object rather * than base */ diff --git a/gcc/testsuite/rust/execute/torture/let-pattern-1.rs b/gcc/testsuite/rust/execute/torture/let-pattern-1.rs new file mode 100644 index 00000000000..107d819a69f --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/let-pattern-1.rs @@ -0,0 +1,4 @@ +fn main() -> i32 { + let (x, y, z) = (2, 3, 6); + x * y - z +} From patchwork Wed Apr 5 14:03: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: 79721 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp363710vqo; Wed, 5 Apr 2023 07:48:51 -0700 (PDT) X-Google-Smtp-Source: AKy350bjW6o0HyQQKEFcUEep9xXX7kjqeQIYFs78vWXTO/+Sl0f4JFuUUrKqikTIUPl/DAQ0XWIx X-Received: by 2002:a17:906:f10d:b0:8eb:d3a5:b9f0 with SMTP id gv13-20020a170906f10d00b008ebd3a5b9f0mr3096709ejb.67.1680706131596; Wed, 05 Apr 2023 07:48:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706131; cv=none; d=google.com; s=arc-20160816; b=FrD0QVcnSF3gZUcMW0JWLQ7RzIFXCeuWeViDK2gkjEfkeJ5lh2rJIkwg/ZEn/oAA9A 1LC6vRBxO9ambLxbN4PbKpLqb3xwy9sDDFWZYxUpvH2q0js5aVN6lzr1zZxbsRmVMeHV ufwUZHyOxQ4sXr3gV40/G1HuAu82rIkPvrroyIzGwUp/GiERiKAjOj4tMYimhxplDQjU AO8vjaVOMTTnHTieUD2YbMHcZ08ZTbh9oJ+wtqef+B8dnXTA9FNqYXeh+jFWiYB4ITs8 tUcpnt1pvx0yTfoqNrig3uH038IWgluxkEujEVz3HKf7kWcftJCK+frdCQfkmGHipjf9 /i+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=YQt1VzdknakxWtmv6fQvcSdTZ/2tdcwjslN8FHS7ldI=; b=D2pzeF4rAxaIqj5IHs4AvIHSjdLtSQ3OFJD3rNfuuvbka0ZwzZi/0nvAIWE9fGipDe GzxFGAPb3swVhbYWYMFJAVGhHhvSQAMCEn/09akGd1bhqQ/m6X3eReGveZCmlhtbi1wH 1WykM8Yv3kiTXKYuFdMNHaluKLurd3q0MKnV9JIfyM7P0oVti6iyxeGuEXjwMD/ik2gh 1ttIRf2Z8kFqwtFMUxrV8RQy4t8qjm2JIof8IqQjTAwhpxVoSo34TsIc8U44Ua7clRPw 1b3CKcIP7DkA3orU63m4sM+WvPYfyVLescFCBe9FkYZqjLSnMDRaPMi2JrKTRr6IUd+2 t2NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=ae2iu1it; 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 m26-20020a1709066d1a00b009309c7f5650si4423315ejr.23.2023.04.05.07.48.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:48:51 -0700 (PDT) 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=ae2iu1it; 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 9926A39706FB for ; Wed, 5 Apr 2023 14:17:43 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id C484838555BD for ; Wed, 5 Apr 2023 14:06:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C484838555BD 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-x32a.google.com with SMTP id l10-20020a05600c1d0a00b003f04bd3691eso7161019wms.5 for ; Wed, 05 Apr 2023 07:06:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703568; 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=YQt1VzdknakxWtmv6fQvcSdTZ/2tdcwjslN8FHS7ldI=; b=ae2iu1itEaETemudjBiVPkssuCrYsvlo/caVu822pR46mbzvv8+NTMLJ2rl4rgYs3O Jx8VJFcspdH3dgZYpuIuXZ0OGnq6ktMdQz/ZyQYAnCHHyjRuZeNA+eordazIXU2T/9gG 1i3nPaFyE0adI71L8bSpa6I3FuqfW/gB5feVz4VmZ0kaZwdE3SwmOsnZuHES7cV/th1l 0NDrp58dQB4UuPlb5REiMtfztvo652qFOa/eTQmO6a2c/y5m26k8KMmLpjbTBx5Faqq9 +Z2TicSBYXy01APaSW/J13WZNCBiZIbClNeOERbO9zDsOdbFBfrkLnpMqt0td6FFCuuc dhRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703568; 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=YQt1VzdknakxWtmv6fQvcSdTZ/2tdcwjslN8FHS7ldI=; b=3iKaLcmC9+ZNNrnPkwZq2UxjrzxWn8tMZnr+gU1hAgErTFzD7QBlxQN9ZIDyQo+sWW t39Ikm7nWq5LrknKqnNL9+nK1hDcIeufvx20FVqLmFStOgIqlFYkOnt7Ze5NAAxKdBEW QFXl3MnFi8L5jZXNLBfgPGlGUhGHD961uyh0U2s+dZ4YE3jusG7RxEmBsPQ8WZY9aSh3 v1ka9cmAepjpb6f0f0JVwhufJ6X3mTAv7/fXiG/VMA3rufuqxnMmzKirr8cCgtnYlJCG 0WpQTBBok9/LJavTDnk5fXZgsApqSxH+24/hL7126GU+gOxkTLRldqhRBrCb7dcRiMov EJxw== X-Gm-Message-State: AAQBX9fkIXh8q1md7p8+jHxpQjKDHGySnw1qbNCmrPtoOM4X/1ampWBk gXSweakzAGu/kKxgtVf7vdWALKQAF2iqUjbZBQ== X-Received: by 2002:a7b:c3ce:0:b0:3f0:310c:e3cf with SMTP id t14-20020a7bc3ce000000b003f0310ce3cfmr4670008wmj.37.1680703568175; Wed, 05 Apr 2023 07:06:08 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:07 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 57/88] gccrs: rust-item: include rust-expr.h Date: Wed, 5 Apr 2023 16:03:41 +0200 Message-Id: <20230405140411.3016563-58-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.6 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?1762348112542329990?= X-GMAIL-MSGID: =?utf-8?q?1762348112542329990?= From: Arthur Cohen gcc/rust/ChangeLog: * ast/rust-item.h (class BlockExpr): Remove forward declaration of class `BlockExpr`. --- gcc/rust/ast/rust-item.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 37ed2beabfc..51ed815c700 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -22,11 +22,11 @@ #include "rust-ast.h" #include "rust-path.h" #include "rust-common.h" +#include "rust-expr.h" namespace Rust { namespace AST { // forward decls -class BlockExpr; class TypePath; // TODO: inline? From patchwork Wed Apr 5 14:03: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: 79717 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp362150vqo; Wed, 5 Apr 2023 07:46:22 -0700 (PDT) X-Google-Smtp-Source: AKy350YS3fohfmrGZfTDNHSXw7FhUr7cn9xRGYR/nTkhA8nEx+O0B4SVAyDW1EkOnA1F5QX8sYgX X-Received: by 2002:a05:6402:b06:b0:4fb:78a0:eabf with SMTP id bm6-20020a0564020b0600b004fb78a0eabfmr2302837edb.29.1680705982461; Wed, 05 Apr 2023 07:46:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705982; cv=none; d=google.com; s=arc-20160816; b=Zjpk81BoBxSzWIWpmHPefsgj9vON75Y63b4X6bkYCnxp2Tf1JRjXF5peYgMdwu3sJ6 cIJS7EQNaBbgG6c4K7md1MailEhZyhwoDEnCho4PGop89bJaWEu/dMGf0OqlQHLPs+I6 JfU7mMgq9om8uyzfqwGA2s27Y6tBf1mdsMSHEt05ReIlJxVtnbF0NsY1XfcpuTcaK6/H SOo1XEvB9Fn59QSNRW4D/JuGEa713PEWMcNZaYtgkFIAMhXevTaN1hJfzPWB8NehDdgI wznngt6vdWdjS503/jIbExHLVaN8ItMOWL3fNp7KGBwPk5MObW6JH2/3oVt+8VA9dmjN RN/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=WSqYmkte5u9pqv+soWRIa2V+eHcy+SIQqFOzOXqBFEA=; b=ePugjKdcnyQdtPAoRjVUF1mwfWfi8oLtxjgAZw4uKt4DBc0+LUuN2uYeQ6m5W1BH1r DF13RBnuof8nbtVFVn5GQNUt1Jv7CDEOhe+5VpTnpeRWZ7G/E0vOSgqUl3s2dR2iCxJX UXRwi49S0VeKqiJIoWFAbWkjcu6Oq0j1wpVgLFaFpA5dGBdMIxCfLTfh0HeCHWifOVta CwALU5PEJxUBYhXM0LRIS3X+T5fefTsVAOQGqATJtocjBr74nEMhQUTh4iPzzRxo6kDt 1nLhGZp7m3OTDvLzFiLjgBBk+huBYvqeN+Pz8L1qOLfb3LeoVbaufXs7hX246wzc6FAE zPNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b="e7y/QuTi"; 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 bm10-20020a0564020b0a00b004af6a805793si11394394edb.601.2023.04.05.07.46.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:46:22 -0700 (PDT) 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="e7y/QuTi"; 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 B1555386E55A for ; Wed, 5 Apr 2023 14:16:39 +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 7AE7E38555AB for ; Wed, 5 Apr 2023 14:06:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7AE7E38555AB 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 d11-20020a05600c3acb00b003ef6e6754c5so18372172wms.5 for ; Wed, 05 Apr 2023 07:06:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703569; 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=WSqYmkte5u9pqv+soWRIa2V+eHcy+SIQqFOzOXqBFEA=; b=e7y/QuTiasFDfMUkyVnAOZOqFl3TRB9aSD0nqjEzDT+FspZYIJ/avbxdLhwiMEnZVa HEXvR6fNiuJNSlfKUjXgCea+H8cgCjW6hoHsycCQJ7wal7jYEnaRs85Fgmk9bd1SXO4y 2cwu7YniYBNP/eDV+V5Q0JXCtBSQ6TTcnNORK6L3Zq7o2Bz0WYs5q3ibMg+WeRts1whS qqpbtZ+ibI8t8BqnRC+06Ayv36w8pKfPUaXejASX5iqx3q7R86JHf5l144492ryruziC UESGL7hFtf1i+XNGbzDNirJslZ/nQf5BKEH4H4fLSP3e3rYYUz2RCtlRk9AWWgZ7Kmtk VPmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703569; 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=WSqYmkte5u9pqv+soWRIa2V+eHcy+SIQqFOzOXqBFEA=; b=C+I5OEq+urXD8esTwgNuHu7z6e6N94R2Nlg1YlnE+SyLHt67kC5cA/b0/vivpiK1h0 WY4l3d3NkK7NzQonQ4caB89dp7zZGsf3ozcQmSRpOfoLSKyootTeKkD34I7XDLdShVqv 43Th3j5diTAq5EZot1je87VWYPVsbRG9YtjiEJZfTcCCTiI+lHUnf8NLviFhVH81X12e FviYTm+cpvfqNdTdM0twh4Qdjn15CbucqFU2jxXuprMEywrHQgLKEi704raw6lk/ayZr bcs3bzgVrujh7ypkuc1Gea2gd7V+bHaDL08YDZu2wc7c2GGcKE/V74tx1/UfTGAz/ml2 uIWQ== X-Gm-Message-State: AAQBX9c8wXD7CXG5wIUTMu90zqeNCewHyysRJ9+B2c+IiGTP4Arai7iQ f5SsZN7BFtPKmnBI81webtZIB/RhwjkFVFUSXw== X-Received: by 2002:a7b:cd87:0:b0:3ea:e4bb:340c with SMTP id y7-20020a7bcd87000000b003eae4bb340cmr4868425wmj.18.1680703568800; Wed, 05 Apr 2023 07:06:08 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:08 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 58/88] gccrs: parser: Expose parse_macro_invocation as public API Date: Wed, 5 Apr 2023 16:03:42 +0200 Message-Id: <20230405140411.3016563-59-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?1762347955913454417?= X-GMAIL-MSGID: =?utf-8?q?1762347955913454417?= From: Arthur Cohen gcc/rust/ChangeLog: * parse/rust-parse.h: Move `parse_macro_invocation` to public API. --- gcc/rust/parse/rust-parse.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index 2f767bb2a53..a4b65c50221 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -150,6 +150,8 @@ public: std::unique_ptr parse_token_tree (); AST::Attribute parse_attribute_body (); AST::AttrVec parse_inner_attributes (); + std::unique_ptr + parse_macro_invocation (AST::AttrVec outer_attrs); private: void skip_after_semicolon (); @@ -201,8 +203,6 @@ private: parse_decl_macro_def (AST::Visibility vis, AST::AttrVec outer_attrs); std::unique_ptr parse_macro_invocation_semi (AST::AttrVec outer_attrs); - std::unique_ptr - parse_macro_invocation (AST::AttrVec outer_attrs); AST::MacroRule parse_macro_rule (); AST::MacroMatcher parse_macro_matcher (); std::unique_ptr parse_macro_match (); From patchwork Wed Apr 5 14:03: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: 79720 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp363670vqo; Wed, 5 Apr 2023 07:48:48 -0700 (PDT) X-Google-Smtp-Source: AKy350bKUkj4rbu+NhjVaoalanOtm9IdSu+uBTCOvqGygcbuZAl/fLyxthkCBuu4eDmX5qbHPZHE X-Received: by 2002:a17:907:d603:b0:931:af6a:ad08 with SMTP id wd3-20020a170907d60300b00931af6aad08mr3513515ejc.57.1680706128218; Wed, 05 Apr 2023 07:48:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706128; cv=none; d=google.com; s=arc-20160816; b=EOPlXENCoP0IPk9pL3198jezQeKngDKW3vjqB2KDrmgLOcJunRxZLOy1RumHWSHubV x0d9pVMU1WOWhNNvfMGJtxHeDAEu/Wwj2Y/Q158NNvJlOHjgrArJWD48DNMSTOPJM3oB So5EAC4ldeSQXpAbX/TaSG5lRNMTgeJ2NS/oJjedTJmRRIUm+nwEIyY2ckVZpSvYH7fK hwUwUERYBS0zqMM8l6MTIwUZUQ0enD2lKrcADqyjf297kEC+siv2Bn4nasL2RDEAlQqQ 1F3BTApqoIpZ7YsioVsao+CxfDxg7Tu0lsxveSXx02AyldvCxuD/N0c7qskr7DJrITYT yOeQ== 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=Wo1xvsr0lThgNUep0EPVvbCx0o8feDezVrKYU1Cu0UY=; b=g+zB1aCrdwv6eNkIAKy5i8xOYvqnAA/xKxdZXgpQtUqLR8pzP0Ve9lgQUZVyYilbmr yCMwiNU/I4oZb9cV+b4DRDSXhepmTYq6Gu/JXY+LxpLfSs+ephTcS37YBSKD+V5PWjSX 6ANonVsEaiuM+umzzEzsYqmA449Rj2eQTCBec457yInmIUtMfMBclSMIpvquYh6xR+oD wuVwkPwediSguvHbOBzDhlbvHGLt//ZjgZnPvIRkBNxFRy8TOcB9Fa7BLd69Lt4Fxh4J FDUX/5ULs24B7fRvFxSfu4ULuUzGc2qqoM0gH0FnRB6UEyFkM35MtEyAIBEgDHN7DOgV TENw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Wna9hKCr; 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 hs3-20020a1709073e8300b009269fbb187csi14089124ejc.304.2023.04.05.07.48.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:48:48 -0700 (PDT) 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=Wna9hKCr; 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 3010E386DE9A for ; Wed, 5 Apr 2023 14:17:42 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 2D40F3856DD4 for ; Wed, 5 Apr 2023 14:06:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2D40F3856DD4 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-x42d.google.com with SMTP id j24so36393424wrd.0 for ; Wed, 05 Apr 2023 07:06:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703569; 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=Wo1xvsr0lThgNUep0EPVvbCx0o8feDezVrKYU1Cu0UY=; b=Wna9hKCreUiVK3h3+9Zka5cRD6KjNFv3N/DRZjeK8cN9BoS8MGLzytLxlu5l8panJg 9kzMEhLuFKAiNO5eln1251m8kYknC3JHv4U2yYEQLBF9i7f8rOlxm+nBPxU4htaifIwV AuOnK/8ahgchasHXGXf2vh/7iexJYYT4zYuQqlVTNzp/HAzv5do9aEqH+7B3m161hOJ+ Klsk3GFkp1+0jVPHUq+2QXNeqgLlg5SNIJvmIPWXakuAJeao0ZrhzTcEW2VudU+KKItW Dg/0gmRgi1NtK8o/wLr4of5uwFSedXkcvD6Q04V3SzhTlrCM69D2RDeuwLEGHeipF5MZ QC6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703569; 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=Wo1xvsr0lThgNUep0EPVvbCx0o8feDezVrKYU1Cu0UY=; b=fa6JWKndjxwwNuQYkQ+Cuop6gzxB/4HuPjZc98KwrO2kqWGizgz0TMaqtCgHUcMGYT fQUscecJ5HU0MM+uu8wYa4+M22zeqwtZy4iQ0nBprUKFCtsgh8IycTBnUdW0FFBgBbs+ k8PKvGy89PCiTcmt1XdhmC+w0EMx/jswYmQwN/pWP8ibNQu0cnWViwePVjlgKhOOnHCV iIuC64l+n8Rb/qqAV659KbcymLKhJW6AjZkaVxa2XYpZTyEcHrRwy1Yk3+knF+09GV44 zh+/nsHvBVnRXl4f5pMg2MaVa/33jS94luJ8pwa/+XF/UmOVqVMh/VQu22sCkEJRy922 652w== X-Gm-Message-State: AAQBX9eFfwNvuSESr845m5mNn+1Xvqe0mTdRU1dxEBTUpfoHFH7ytJLQ Euf4KumVKq61MerzQ+gJ7+NAv13RcGDMvQbfXA== X-Received: by 2002:a5d:510c:0:b0:2cf:eb86:bd90 with SMTP id s12-20020a5d510c000000b002cfeb86bd90mr4039432wrt.63.1680703569457; Wed, 05 Apr 2023 07:06:09 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:09 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 59/88] gccrs: expansion: Add `get_token_slice` to `MacroInvocLexer` class Date: Wed, 5 Apr 2023 16:03:43 +0200 Message-Id: <20230405140411.3016563-60-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.6 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?1762348108805094757?= X-GMAIL-MSGID: =?utf-8?q?1762348108805094757?= From: Arthur Cohen gcc/rust/ChangeLog: * expand/rust-macro-invoc-lexer.cc (MacroInvocLexer::get_token_slice): Add API to retrieve token slices when lexing macro expansions. * expand/rust-macro-invoc-lexer.h: Declare `get_token_slice`. --- gcc/rust/expand/rust-macro-invoc-lexer.cc | 14 ++++++++++++++ gcc/rust/expand/rust-macro-invoc-lexer.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/gcc/rust/expand/rust-macro-invoc-lexer.cc b/gcc/rust/expand/rust-macro-invoc-lexer.cc index 8a43d29e0d1..321f0f97a76 100644 --- a/gcc/rust/expand/rust-macro-invoc-lexer.cc +++ b/gcc/rust/expand/rust-macro-invoc-lexer.cc @@ -26,4 +26,18 @@ MacroInvocLexer::split_current_token (TokenId new_left __attribute__ ((unused)), // FIXME gcc_unreachable (); } + +std::vector> +MacroInvocLexer::get_token_slice (size_t start_idx, size_t end_idx) const +{ + std::vector> slice; + + rust_assert (end_idx < token_stream.size ()); + + for (size_t i = start_idx; i < end_idx; i++) + slice.emplace_back (token_stream[i]->clone_token ()); + + return slice; +} + } // namespace Rust diff --git a/gcc/rust/expand/rust-macro-invoc-lexer.h b/gcc/rust/expand/rust-macro-invoc-lexer.h index a0d30164850..0923c18c84d 100644 --- a/gcc/rust/expand/rust-macro-invoc-lexer.h +++ b/gcc/rust/expand/rust-macro-invoc-lexer.h @@ -55,6 +55,9 @@ public: size_t get_offs () const { return offs; } + std::vector> + get_token_slice (size_t start_idx, size_t end_idx) const; + private: size_t offs; std::vector> token_stream; From patchwork Wed Apr 5 14:03: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: 79722 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp364762vqo; Wed, 5 Apr 2023 07:50:35 -0700 (PDT) X-Google-Smtp-Source: AKy350YpZ4MNCyaQjZh914uX4keT0v4j5rdGh0o6MzQA6OHgD6J1EGF6jpLUqPdMOCOL52laZ2AE X-Received: by 2002:a05:6402:1519:b0:502:4c82:6cc0 with SMTP id f25-20020a056402151900b005024c826cc0mr1883588edw.40.1680706235440; Wed, 05 Apr 2023 07:50:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706235; cv=none; d=google.com; s=arc-20160816; b=v51SH0SF9Zln3bkkQMg6HGWPTH4K1hQ7zzRCDTBCWrEErhqjRBqWimOOQ0Gqkxn5ns kVE6X4gV0/PPaGSDBDOwDjCqWBrsabWzF1xmQR3WzJFLr0GrqC2MrKAD4Z8DVxQFfKZJ taei/XQCp+llWXMVq3YokzCqb7yLQBCpZU9SCMAtMAwXryTdFRzKxCs7v4oj6XUCpILb YwfwcuHw2effhCmpKJMscR/m/ewp/mVb4/nae/lRi50jd3Ec0jg4wYKg7/g60OHNMGl9 b+cROIxVuX3wQIq/aoimX2cRI8d7ESPmgrNELDRkeBQt1g8tRiFDAe2b92vbWC8lSVTR o2jQ== 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=BFRw9jduqQljzYZKjgJyCUpSYsm1043CrNve5le6dCg=; b=wfYZlQJ1vFaQL/soHfZMItlh2u1wI0vyU9n9DEuP+F3wDry2Sf5QifDIwQDM4eHGv1 sOfdSDSStBg9c6+DxRiXGZOOOjox9PbPveVAE1OT+ja6mgZSJU9KiHZuQinvcGZOtvxC CA2YErBw3plgcNr6Ti4X/vu8GGsjAaxdBOWKiYqfcXp7NQrqJESdbxvnIn1/qmT+b3cp WY4goQrRgu44LK4wLY+iSueaZ8+r3DEAIDRa6mlbPlq4BStNWF7B2PlqlbZ9DUcDVX/p OnkK7rKz2HbpE3e7BqS30Ezajy4VvyZ2afrrnLcCcMHJz6rXS3GSHwabDVqisOvNpuez vPTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=INIfqitT; 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 f13-20020aa7d84d000000b004fc9c7986c5si12765584eds.530.2023.04.05.07.50.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:50:35 -0700 (PDT) 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=INIfqitT; 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 4092A3927B17 for ; Wed, 5 Apr 2023 14:18:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id E555F3854155 for ; Wed, 5 Apr 2023 14:06:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E555F3854155 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-x32b.google.com with SMTP id d11-20020a05600c3acb00b003ef6e6754c5so18372237wms.5 for ; Wed, 05 Apr 2023 07:06:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703571; 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=BFRw9jduqQljzYZKjgJyCUpSYsm1043CrNve5le6dCg=; b=INIfqitTxBNYVffPOoK5QRbig3lAW8Jc54dBUPO5bW8PQ7YzsekpxluCn1hIrdO3v2 lD0zbJedGTrNcWzT/2Bri7Ys7a4Ao27+a5JRMDZ4FcV6vfCumP0B2tcn23OV+8f17edE dJh0rw0nbJtYm2vZWKpeEpBUqnWHwQ/biBuE3j9QPIghAZNOibeSz/nHdgniNvsMBV3Z QbXd/eLPpcgPq+DWGbM8ZIKt9xuF+kOjLPbhrdhn99sMm0Pfbi2VJJck72G8QCzJz2aW Hj3edNaxewYAhVyq1HhSZE8CryLl4btlOKlW6bdD/07uxiKbBldw0Jsqv3vTHSsTLa+u +bog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703571; 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=BFRw9jduqQljzYZKjgJyCUpSYsm1043CrNve5le6dCg=; b=FcgqQv31iQI5E6n1pHeodG/tT437y3/MqC6mwtYr0OcECx3dlPgQ6exunzIk9HCW5P NBO91xXsPf2wVfYkxrwBCNr2lepBnUqyGZobEa91i9u9/ODM7bopkdxaCe+xqy/qFfmt R+7LWYmNKgTFSiJj8Bz53lWGMQnDZZKVF6qbCQSJrrYrzHT2vTL5Vp7amP3u9B52ry0L ljJ+A4DtmuXxfx4iJ3zLINIvThVKYHrYeJnQmo/tg4Ss5XbxaLbiTvPWwkQxeZWh//It SAxknTsEsaf/QX6p5uj37kWlVSkdlb8dmjz3bkAirILiIed7BPxQjl2mRxWvFFV46Ibi VOfA== X-Gm-Message-State: AAQBX9f8GRS8XQCK4DdLGz4ADYu/fZrLKkYjGCzp+YWype7PykwdYl35 jwOEkLlbkP8b2eeDCw4BplMLJDbjAaS/ke3Gmw== X-Received: by 2002:a1c:f20d:0:b0:3ea:e582:48dd with SMTP id s13-20020a1cf20d000000b003eae58248ddmr4799146wmc.34.1680703570184; Wed, 05 Apr 2023 07:06:10 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:09 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 60/88] gccrs: macros: Perform macro expansion in a fixed-point fashion. Date: Wed, 5 Apr 2023 16:03:44 +0200 Message-Id: <20230405140411.3016563-61-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.6 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?1762348221760267662?= X-GMAIL-MSGID: =?utf-8?q?1762348221760267662?= From: Arthur Cohen This commit changes our macro expansion system from an eager and recursive macro expansion to a fixed-point like system. Instead of, when seeing a macro invocation, expanding it and all of the macros within it, we now perform multiple passes of expansion on the entire crate. This, however, leads to a problem. Rust macros are expanded lazily, but Rust builtin macros should be expanded eagerly. Due to this, we must work around the lazy expansion in builtin macros and perform eager expansion for each pass of the fixed-point, before finally expanding the builtin when there are no longer any inner macro invocations. To perform proper macro scoping, the ENR now keeps track of the current scope (`current_scope` member) and resolves macros accordingly. This is done through the use of the `scoped` method, which creates a new scope, runs a specified lambda and then exits the scope. This prevents pushing/popping errors that we've seen happen already in similar contexts. We might think about generalizing it to other classes, providing a `Scoped` class or similar gcc/rust/ChangeLog: * ast/rust-macro.cc: New file. * Make-lang.in: Add `rust-macro.o` object * ast/rust-ast-fragment.cc (Fragment::Fragment): Change API around the construction of AST fragments. (Fragment::operator=): Correct `Fragment::operator=` to take into account the fragment tokens. (Fragment::create_error): Use new constructor. (Fragment::complete): Remove in favor of new constructor. (Fragment::unexpanded): Remove as that Fragment type is no longer used or possible. (Fragment::get_tokens): Add helper to access a fragment's tokens. * ast/rust-ast-fragment.h (enum class): Remove `FragmentKind::Unused` * ast/rust-ast.cc (MacroInvocation::as_string): Display builtin macro invocations properly. * ast/rust-ast.h: Fix `DelimTokenTree` class copy constructors and handling of its token vector. * ast/rust-macro.h (class MacroMatcher): Format. (class MetaItemSeq): Likewise. (builtin_macro_from_string): Get a `BuiltinMacroKind` from a given string, i.e the name of the macro (`assert!`, `cfg!` and so on). * expand/rust-attribute-visitor.cc (AttrVisitor::visit): Do not expand macros recursively anymore. (AttrVisitor::maybe_expand_expr): Likewise. (AttrVisitor::maybe_expand_type): Likewise. * expand/rust-attribute-visitor.h: Likewise, and remove `expand_macro_fragment_recursively` function. * expand/rust-macro-builtins.cc (make_token): Add shorthand for returning `std::unique_ptr`s. (make_macro_invocation): Add shorthand for returning fragments containing builtin macro invocations. (try_expand_macro_expression): Do not expand macros recursively. (try_expand_single_string_literal): Likewise. (try_expand_many_expr): Likewise. (parse_single_string_literal): Error out more appropriately. (MacroBuiltin::compile_error_handler): Add explanation for eager invocation (MacroBuiltin::file_handler): Return the proper tokens associated with macro invocation, and builtin macros in the case of necessary eager expansion. (MacroBuiltin::column_handler): Likewise. (MacroBuiltin::include_bytes_handler): Likewise. (MacroBuiltin::include_str_handler): Likewise. (MacroBuiltin::concat_handler): Likewise. (MacroBuiltin::env_handler): Likewise. (MacroBuiltin::cfg_handler): Likewise. (MacroBuiltin::include_handler): Likewise. (MacroBuiltin::line_handler): Likewise. * expand/rust-macro-expand.cc (MacroExpander::expand_eager_invocations): Add function to expand eager invocations *once* in the fixed point pipeline. (MacroExpander::expand_invoc): Call into `expand_eager_invocations` for builtin macro invocations. (MacroExpander::expand_crate): Use new `AttrVisitor` API. (parse_many): Return tokens in `AST::Fragment`. (transcribe_expression): Likewise. (transcribe_type): Likewise. * expand/rust-macro-expand.h (struct MacroExpander): Add `has_changed` flag for fixed point checking. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::EarlyNameResolver): Keep track of the current macro scope. (EarlyNameResolver::go): Use `scoped` API. (EarlyNameResolver::visit): Likewise. * resolve/rust-early-name-resolver.h: Add `scoped` API. * rust-session-manager.cc (Session::expansion): Perform macro expansion in a fixed-point fashion. gcc/testsuite/ChangeLog: * rust/compile/macro17.rs: Fix testsuite for new recursion errors. * rust/compile/macro44.rs: Fix invalid testcase assertions. * rust/compile/builtin_macro_recurse.rs: Fix invalid test. * rust/compile/builtin_macro_recurse2.rs: New test. * rust/compile/macro46.rs: New test. --- gcc/rust/Make-lang.in | 1 + gcc/rust/ast/rust-ast-fragment.cc | 42 ++- gcc/rust/ast/rust-ast-fragment.h | 23 +- gcc/rust/ast/rust-ast.cc | 16 ++ gcc/rust/ast/rust-ast.h | 5 + gcc/rust/ast/rust-macro.cc | 64 +++++ gcc/rust/ast/rust-macro.h | 101 +++++-- gcc/rust/expand/rust-attribute-visitor.cc | 8 +- gcc/rust/expand/rust-attribute-visitor.h | 36 +-- gcc/rust/expand/rust-macro-builtins.cc | 256 +++++++++++++----- gcc/rust/expand/rust-macro-expand.cc | 138 +++++++++- gcc/rust/expand/rust-macro-expand.h | 63 ++--- gcc/rust/resolve/rust-early-name-resolver.cc | 127 ++++++--- gcc/rust/resolve/rust-early-name-resolver.h | 65 +++++ gcc/rust/rust-session-manager.cc | 35 ++- ...cro_recurse.rs => builtin_macro_eager1.rs} | 0 .../rust/compile/builtin_macro_eager2.rs | 16 ++ .../rust/compile/builtin_macro_recurse2.rs | 20 ++ gcc/testsuite/rust/compile/macro17.rs | 6 +- gcc/testsuite/rust/compile/macro44.rs | 6 +- gcc/testsuite/rust/compile/macro46.rs | 19 ++ 21 files changed, 813 insertions(+), 234 deletions(-) create mode 100644 gcc/rust/ast/rust-macro.cc rename gcc/testsuite/rust/compile/{builtin_macro_recurse.rs => builtin_macro_eager1.rs} (100%) create mode 100644 gcc/testsuite/rust/compile/builtin_macro_eager2.rs create mode 100644 gcc/testsuite/rust/compile/builtin_macro_recurse2.rs create mode 100644 gcc/testsuite/rust/compile/macro46.rs diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index 1d2f34d7919..d9bc40945c3 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -90,6 +90,7 @@ GRS_OBJS = \ rust/rust-hir-map.o \ rust/rust-attributes.o \ rust/rust-abi.o \ + rust/rust-macro.o \ rust/rust-ast-lower.o \ rust/rust-ast-lower-base.o \ rust/rust-ast-lower-pattern.o \ diff --git a/gcc/rust/ast/rust-ast-fragment.cc b/gcc/rust/ast/rust-ast-fragment.cc index c4916093fc6..fba629c0119 100644 --- a/gcc/rust/ast/rust-ast-fragment.cc +++ b/gcc/rust/ast/rust-ast-fragment.cc @@ -21,8 +21,9 @@ namespace Rust { namespace AST { -Fragment::Fragment (FragmentKind kind, std::vector nodes) - : kind (kind), nodes (std::move (nodes)) +Fragment::Fragment (FragmentKind kind, std::vector nodes, + std::vector> tokens) + : kind (kind), nodes (std::move (nodes)), tokens (std::move (tokens)) {} Fragment::Fragment (Fragment const &other) : kind (other.get_kind ()) @@ -33,13 +34,17 @@ Fragment::Fragment (Fragment const &other) : kind (other.get_kind ()) Fragment & Fragment::operator= (Fragment const &other) { + kind = other.get_kind (); + nodes.clear (); nodes.reserve (other.nodes.size ()); - kind = other.get_kind (); for (auto &n : other.nodes) - { - nodes.push_back (n); - } + nodes.push_back (n); + + tokens.clear (); + tokens.reserve (other.tokens.size ()); + for (auto &t : other.tokens) + tokens.emplace_back (t->clone_token ()); return *this; } @@ -47,19 +52,20 @@ Fragment::operator= (Fragment const &other) Fragment Fragment::create_error () { - return Fragment (FragmentKind::Error, {}); + return Fragment (FragmentKind::Error, {}, {}); } -Fragment -Fragment::complete (std::vector nodes) -{ - return Fragment (FragmentKind::Complete, std::move (nodes)); -} +Fragment::Fragment (std::vector nodes, + std::vector> tokens) + : kind (FragmentKind::Complete), nodes (std::move (nodes)), + tokens (std::move (tokens)) +{} -Fragment -Fragment::unexpanded () +Fragment::Fragment (std::vector nodes, + std::unique_ptr token) + : kind (FragmentKind::Complete), nodes (std::move (nodes)) { - return Fragment (FragmentKind::Unexpanded, {}); + tokens.emplace_back (std::move (token)); } std::vector & @@ -68,6 +74,12 @@ Fragment::get_nodes () return nodes; } +std::vector> & +Fragment::get_tokens () +{ + return tokens; +} + FragmentKind Fragment::get_kind () const { diff --git a/gcc/rust/ast/rust-ast-fragment.h b/gcc/rust/ast/rust-ast-fragment.h index 3ef4ba16dce..22e99090b25 100644 --- a/gcc/rust/ast/rust-ast-fragment.h +++ b/gcc/rust/ast/rust-ast-fragment.h @@ -27,11 +27,6 @@ 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. @@ -68,15 +63,18 @@ public: /** * Create a complete AST fragment */ - static Fragment complete (std::vector nodes); + Fragment (std::vector nodes, + std::vector> tokens); /** - * Create a fragment which contains unexpanded nodes + * Create a complete AST fragment made of a single token */ - static Fragment unexpanded (); + Fragment (std::vector nodes, + std::unique_ptr tok); FragmentKind get_kind () const; std::vector &get_nodes (); + std::vector> &get_tokens (); bool is_error () const; bool should_expand () const; @@ -90,7 +88,8 @@ public: void accept_vis (ASTVisitor &vis); private: - Fragment (FragmentKind kind, std::vector nodes); + Fragment (FragmentKind kind, std::vector nodes, + std::vector> tokens); FragmentKind kind; @@ -104,6 +103,12 @@ private: */ std::vector nodes; + /** + * The tokens associated with an AST fragment. This vector represents the + * actual tokens of the various nodes that are part of the fragment. + */ + std::vector> tokens; + /** * We need to make a special case for Expression and Type fragments as only * one Node will be extracted from the `nodes` vector diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index 60a9f01e17f..972cba2e7bb 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -1323,6 +1323,12 @@ std::string MacroInvocation::as_string () const { std::string str = "MacroInvocation: "; + auto is_builtin = kind == InvocKind::Builtin; + + if (is_builtin) + str += "[builtin] "; + else + str += "[regular] "; str += append_attributes (outer_attrs, OUTER); @@ -1331,6 +1337,16 @@ MacroInvocation::as_string () const str += "\n has semicolon: "; str += has_semicolon () ? "true" : "false"; + if (is_builtin) + { + str += "[PENDING EAGER INVOCATIONS]: "; + for (auto &pending : pending_eager_invocs) + { + str += pending->as_string (); + str += "\n"; + } + } + return str; } diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index d30e6d494f2..d986fdf9368 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -773,6 +773,7 @@ public: DelimTokenTree (DelimTokenTree const &other) : delim_type (other.delim_type), locus (other.locus) { + token_trees.clear (); token_trees.reserve (other.token_trees.size ()); for (const auto &e : other.token_trees) token_trees.push_back (e->clone_token_tree ()); @@ -784,6 +785,7 @@ public: delim_type = other.delim_type; locus = other.locus; + token_trees.clear (); token_trees.reserve (other.token_trees.size ()); for (const auto &e : other.token_trees) token_trees.push_back (e->clone_token_tree ()); @@ -1523,6 +1525,9 @@ public: DelimTokenTree &get_delim_tok_tree () { return token_tree; } const DelimTokenTree &get_delim_tok_tree () const { return token_tree; } + // Set the delim token tree of a macro invocation + void set_delim_tok_tree (DelimTokenTree tree) { token_tree = tree; } + // TODO: this mutable getter seems kinda dodgy SimplePath &get_path () { return path; } const SimplePath &get_path () const { return path; } diff --git a/gcc/rust/ast/rust-macro.cc b/gcc/rust/ast/rust-macro.cc new file mode 100644 index 00000000000..b90cc15898e --- /dev/null +++ b/gcc/rust/ast/rust-macro.cc @@ -0,0 +1,64 @@ +// 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-macro.h" + +namespace Rust { +namespace AST { + +BuiltinMacro +builtin_macro_from_string (const std::string &identifier) +{ + if (identifier == "assert") + return BuiltinMacro::Assert; + + if (identifier == "file") + return BuiltinMacro::File; + + if (identifier == "line") + return BuiltinMacro::Line; + + if (identifier == "column") + return BuiltinMacro::Column; + + if (identifier == "include_bytes") + return BuiltinMacro::IncludeBytes; + + if (identifier == "include_str") + return BuiltinMacro::IncludeStr; + + if (identifier == "compile_error") + return BuiltinMacro::CompileError; + + if (identifier == "concat") + return BuiltinMacro::Concat; + + if (identifier == "env") + return BuiltinMacro::Env; + + if (identifier == "cfg") + return BuiltinMacro::Cfg; + + if (identifier == "include") + return BuiltinMacro::Include; + + gcc_unreachable (); +} + +} // namespace AST +} // namespace Rust diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h index 68dd7d660d3..1a1a32da34c 100644 --- a/gcc/rust/ast/rust-macro.h +++ b/gcc/rust/ast/rust-macro.h @@ -222,7 +222,7 @@ public: }; private: - std::vector > matches; + std::vector> matches; MacroRepOp op; // bool has_sep; @@ -235,7 +235,7 @@ public: // Returns whether macro match repetition has separator token. bool has_sep () const { return sep != nullptr; } - MacroMatchRepetition (std::vector > matches, + MacroMatchRepetition (std::vector> matches, MacroRepOp op, std::unique_ptr sep, Location locus) : matches (std::move (matches)), op (op), sep (std::move (sep)), @@ -290,8 +290,8 @@ public: MacroRepOp get_op () const { return op; } const std::unique_ptr &get_sep () const { return sep; } - std::vector > &get_matches () { return matches; } - const std::vector > &get_matches () const + std::vector> &get_matches () { return matches; } + const std::vector> &get_matches () const { return matches; } @@ -309,7 +309,7 @@ protected: class MacroMatcher : public MacroMatch { DelimType delim_type; - std::vector > matches; + std::vector> matches; Location locus; // TODO: think of way to mark invalid that doesn't take up more space @@ -317,7 +317,7 @@ class MacroMatcher : public MacroMatch public: MacroMatcher (DelimType delim_type, - std::vector > matches, + std::vector> matches, Location locus) : delim_type (delim_type), matches (std::move (matches)), locus (locus), is_invalid (false) @@ -369,8 +369,8 @@ public: } DelimType get_delim_type () const { return delim_type; } - std::vector > &get_matches () { return matches; } - const std::vector > &get_matches () const + std::vector> &get_matches () { return matches; } + const std::vector> &get_matches () const { return matches; } @@ -596,6 +596,9 @@ enum class BuiltinMacro Include }; +BuiltinMacro +builtin_macro_from_string (const std::string &identifier); + /* AST node of a macro invocation, which is replaced by the macro result at * compile time. This is technically a sum-type/tagged-union, which represents * both classic macro invocations and builtin macro invocations. Regular macro @@ -634,7 +637,8 @@ public: { return std::unique_ptr ( new MacroInvocation (InvocKind::Regular, Optional::none (), - invoc_data, outer_attrs, locus, is_semi_coloned)); + invoc_data, outer_attrs, locus, is_semi_coloned, + {})); } /** @@ -642,15 +646,18 @@ public: * name-resolution and within the macro expander, so unless you're modifying * these visitors, you probably do not want to use this function. */ - static std::unique_ptr - Builtin (BuiltinMacro kind, MacroInvocData invoc_data, - std::vector outer_attrs, Location locus, - bool is_semi_coloned = false) + static std::unique_ptr Builtin ( + BuiltinMacro kind, MacroInvocData invoc_data, + std::vector outer_attrs, Location locus, + std::vector> &&pending_eager_invocations + = {}, + bool is_semi_coloned = false) { return std::unique_ptr ( new MacroInvocation (InvocKind::Builtin, Optional::some (kind), invoc_data, - outer_attrs, locus, is_semi_coloned)); + outer_attrs, locus, is_semi_coloned, + std::move (pending_eager_invocations))); } Location get_locus () const override final { return locus; } @@ -688,18 +695,53 @@ public: InvocKind get_kind () const { return kind; } Optional get_builtin_kind () const { return builtin_kind; } + /** + * Turn the current MacroInvocation into a builtin macro invocation + */ + void map_to_builtin (BuiltinMacro macro) + { + kind = InvocKind::Builtin; + builtin_kind = Optional::some (macro); + } + + /** + * Get the list of pending macro invcations within the builtin macro + * invocation that should get expanded eagerly. + */ + std::vector> & + get_pending_eager_invocations () + { + rust_assert (kind == InvocKind::Builtin); + + return pending_eager_invocs; + } + private: /* Full constructor */ - MacroInvocation (InvocKind kind, Optional builtin_kind, - MacroInvocData invoc_data, - std::vector outer_attrs, Location locus, - bool is_semi_coloned) + MacroInvocation ( + InvocKind kind, Optional builtin_kind, + MacroInvocData invoc_data, std::vector outer_attrs, + Location locus, bool is_semi_coloned, + std::vector> &&pending_eager_invocs) : outer_attrs (std::move (outer_attrs)), locus (locus), node_id (Analysis::Mappings::get ()->get_next_node_id ()), invoc_data (std::move (invoc_data)), is_semi_coloned (is_semi_coloned), - kind (kind), builtin_kind (builtin_kind) + kind (kind), builtin_kind (builtin_kind), + pending_eager_invocs (std::move (pending_eager_invocs)) {} + MacroInvocation (const MacroInvocation &other) + : outer_attrs (other.outer_attrs), locus (other.locus), + node_id (other.node_id), invoc_data (other.invoc_data), + is_semi_coloned (other.is_semi_coloned), kind (other.kind), + builtin_kind (other.builtin_kind) + { + if (other.kind == InvocKind::Builtin) + for (auto &pending : other.pending_eager_invocs) + pending_eager_invocs.emplace_back ( + pending->clone_macro_invocation_impl ()); + } + std::vector outer_attrs; Location locus; NodeId node_id; @@ -716,6 +758,16 @@ private: /* If it is a builtin macro, which one */ Optional builtin_kind = Optional::none (); + /** + * Pending invocations within a builtin macro invocation. This vector is empty + * and should not be accessed for a regular macro invocation. The macro + * invocations within should be name resolved and expanded before the builtin + * macro invocation get expanded again. It is then the role of the expander to + * insert these new tokens properly in the delimited token tree and try the + * builtin transcriber once again. + */ + std::vector> pending_eager_invocs; + protected: /* Use covariance to implement clone function as returning this object rather * than base */ @@ -817,11 +869,10 @@ protected: class MetaItemSeq : public MetaItem { SimplePath path; - std::vector > seq; + std::vector> seq; public: - MetaItemSeq (SimplePath path, - std::vector > seq) + MetaItemSeq (SimplePath path, std::vector> seq) : path (std::move (path)), seq (std::move (seq)) {} @@ -1024,18 +1075,18 @@ struct AttributeParser { private: // TODO: might as well rewrite to use lexer tokens - std::vector > token_stream; + std::vector> token_stream; int stream_pos; public: - AttributeParser (std::vector > token_stream, + AttributeParser (std::vector> token_stream, int stream_start_pos = 0) : token_stream (std::move (token_stream)), stream_pos (stream_start_pos) {} ~AttributeParser () = default; - std::vector > parse_meta_item_seq (); + std::vector> parse_meta_item_seq (); private: // Parses a MetaItemInner. diff --git a/gcc/rust/expand/rust-attribute-visitor.cc b/gcc/rust/expand/rust-attribute-visitor.cc index 6bceed62096..9abec9221ab 100644 --- a/gcc/rust/expand/rust-attribute-visitor.cc +++ b/gcc/rust/expand/rust-attribute-visitor.cc @@ -389,8 +389,6 @@ AttrVisitor::visit (AST::ConstGenericParam &) void AttrVisitor::visit (AST::MacroInvocation ¯o_invoc) { - // FIXME: Probably need to check macro_invoc.kind - // initial strip test based on outer attrs expander.expand_cfg_attrs (macro_invoc.get_outer_attrs ()); if (expander.fails_cfg_with_expand (macro_invoc.get_outer_attrs ())) @@ -1124,7 +1122,7 @@ AttrVisitor::visit (AST::CallExpr &expr) stmt->accept_vis (*this); - auto final_fragment = expand_macro_fragment_recursive (); + auto final_fragment = expander.take_expanded_fragment (); if (final_fragment.should_expand ()) { // Remove the current expanded invocation @@ -3423,7 +3421,7 @@ AttrVisitor::visit (AST::BareFunctionType &type) void AttrVisitor::maybe_expand_expr (std::unique_ptr &expr) { - auto final_fragment = expand_macro_fragment_recursive (); + auto final_fragment = expander.take_expanded_fragment (); if (final_fragment.should_expand () && final_fragment.is_expression_fragment ()) expr = final_fragment.take_expression_fragment (); @@ -3432,7 +3430,7 @@ AttrVisitor::maybe_expand_expr (std::unique_ptr &expr) void AttrVisitor::maybe_expand_type (std::unique_ptr &type) { - auto final_fragment = expand_macro_fragment_recursive (); + auto final_fragment = expander.take_expanded_fragment (); if (final_fragment.should_expand () && final_fragment.is_type_fragment ()) type = final_fragment.take_type_fragment (); } diff --git a/gcc/rust/expand/rust-attribute-visitor.h b/gcc/rust/expand/rust-attribute-visitor.h index cbddc163da7..9b0e315fc08 100644 --- a/gcc/rust/expand/rust-attribute-visitor.h +++ b/gcc/rust/expand/rust-attribute-visitor.h @@ -43,39 +43,6 @@ public: void expand_trait_function_decl (AST::TraitFunctionDecl &decl); void expand_trait_method_decl (AST::TraitMethodDecl &decl); - /** - * Expand The current macro fragment recursively until it could not be - * expanded further. - * - * The return value checking works because correctly - * expanded fragment can never be an error (if the fragment can not be - * expanded, a stand-in error fragment will be returned; for fragments that - * could not be further expanded: the fragment prior to the expansion failure - * will be returned). - * - * @return Either the expanded fragment or an empty errored-out fragment - * indicating an expansion failure. - */ - AST::Fragment expand_macro_fragment_recursive () - { - auto fragment = expander.take_expanded_fragment (*this); - unsigned int original_depth = expander.expansion_depth; - auto final_fragment = AST::Fragment::create_error (); - - while (fragment.should_expand ()) - { - final_fragment = std::move (fragment); - expander.expansion_depth++; - // further expand the previously expanded macro fragment - auto new_fragment = expander.take_expanded_fragment (*this); - if (new_fragment.is_error ()) - break; - fragment = std::move (new_fragment); - } - expander.expansion_depth = original_depth; - return final_fragment; - } - /** * Expand a set of values, erasing them if they are marked for strip, and * replacing them with expanded macro nodes if necessary. @@ -101,8 +68,7 @@ public: // mark for stripping if required value->accept_vis (*this); - // recursively expand the children - auto final_fragment = expand_macro_fragment_recursive (); + auto final_fragment = expander.take_expanded_fragment (); if (final_fragment.should_expand ()) { diff --git a/gcc/rust/expand/rust-macro-builtins.cc b/gcc/rust/expand/rust-macro-builtins.cc index 11334409fe3..e594a2500d0 100644 --- a/gcc/rust/expand/rust-macro-builtins.cc +++ b/gcc/rust/expand/rust-macro-builtins.cc @@ -29,6 +29,16 @@ namespace Rust { namespace { + +/** + * Shorthand function for creating unique_ptr tokens + */ +static std::unique_ptr +make_token (const TokenPtr tok) +{ + return std::unique_ptr (new AST::Token (tok)); +} + std::unique_ptr make_string (Location locus, std::string value) { @@ -37,8 +47,64 @@ make_string (Location locus, std::string value) PrimitiveCoreType::CORETYPE_STR, {}, locus)); } -/* Match the end token of a macro given the start delimiter of the macro */ +// TODO: Is this correct? +static AST::Fragment +make_eager_builtin_invocation ( + AST::BuiltinMacro kind, Location locus, AST::DelimTokenTree arguments, + std::vector> &&pending_invocations) +{ + std::string path_str; + switch (kind) + { + // TODO: Should this be a table lookup? + case AST::BuiltinMacro::Assert: + path_str = "assert"; + break; + case AST::BuiltinMacro::File: + path_str = "file"; + break; + case AST::BuiltinMacro::Line: + path_str = "line"; + break; + case AST::BuiltinMacro::Column: + path_str = "column"; + break; + case AST::BuiltinMacro::IncludeBytes: + path_str = "include_bytes"; + break; + case AST::BuiltinMacro::IncludeStr: + path_str = "include_str"; + break; + case AST::BuiltinMacro::CompileError: + path_str = "compile_error"; + break; + case AST::BuiltinMacro::Concat: + path_str = "concat"; + break; + case AST::BuiltinMacro::Env: + path_str = "env"; + break; + case AST::BuiltinMacro::Cfg: + path_str = "cfg"; + break; + case AST::BuiltinMacro::Include: + path_str = "include"; + break; + } + + std::unique_ptr node = AST::MacroInvocation::Builtin ( + kind, + AST::MacroInvocData (AST::SimplePath ( + {AST::SimplePathSegment (path_str, locus)}), + std::move (arguments)), + {}, locus, std::move (pending_invocations)); + + return AST::Fragment ({AST::SingleASTNode (std::move (node))}, + arguments.to_token_stream ()); +} + +/* Match the end token of a macro given the start delimiter of the macro */ static inline TokenId macro_end_token (AST::DelimTokenTree &invoc_token_tree, Parser &parser) @@ -64,22 +130,7 @@ macro_end_token (AST::DelimTokenTree &invoc_token_tree, return last_token_id; } -/* Expand and extract an expression from the macro */ - -static inline AST::Fragment -try_expand_macro_expression (AST::Expr *expr, MacroExpander *expander) -{ - rust_assert (expander); - - 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 */ - static std::unique_ptr try_extract_string_literal_from_fragment (const Location &parent_locus, std::unique_ptr &node) @@ -97,22 +148,6 @@ try_extract_string_literal_from_fragment (const Location &parent_locus, static_cast (node->clone_expr ().release ())); } -static std::unique_ptr -try_expand_single_string_literal (AST::Expr *input_expr, - MacroExpander *expander) -{ - auto nodes = try_expand_macro_expression (input_expr, expander); - if (nodes.is_error () || nodes.is_expression_fragment ()) - { - rust_error_at (input_expr->get_locus (), - "argument must be a string literal"); - return nullptr; - } - auto expr = nodes.take_expression_fragment (); - return try_extract_string_literal_from_fragment (input_expr->get_locus (), - expr); -} - static std::vector> try_expand_many_expr (Parser &parser, const TokenId last_token_id, MacroExpander *expander, @@ -140,22 +175,7 @@ try_expand_many_expr (Parser &parser, auto expr = parser.parse_expr (AST::AttrVec (), restrictions); // something must be so wrong that the expression could not be parsed rust_assert (expr); - auto nodes = try_expand_macro_expression (expr.get (), expander); - if (nodes.is_error ()) - { - // not macro - result.push_back (std::move (expr)); - } - else if (!nodes.is_expression_fragment ()) - { - rust_error_at (expr->get_locus (), "expected expression"); - has_error = true; - return empty_expr; - } - else - { - result.push_back (nodes.take_expression_fragment ()); - } + result.push_back (std::move (expr)); auto next_token = parser.peek_current_token (); if (!parser.skip_token (COMMA) && next_token->get_id () != last_token_id) @@ -199,12 +219,7 @@ parse_single_string_literal (AST::DelimTokenTree &invoc_token_tree, else if (parser.peek_current_token ()->get_id () == last_token_id) rust_error_at (invoc_locus, "macro takes 1 argument"); else - { - // 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 (), expander); - } + rust_error_at (invoc_locus, "argument must be a string literal"); parser.skip_token (last_token_id); @@ -276,8 +291,10 @@ MacroBuiltin::file_handler (Location invoc_locus, AST::MacroInvocData &) auto current_file = Session::get_instance ().linemap->location_file (invoc_locus); auto file_str = AST::SingleASTNode (make_string (invoc_locus, current_file)); + auto str_token + = make_token (Token::make_string (invoc_locus, std::move (current_file))); - return AST::Fragment::complete ({file_str}); + return AST::Fragment ({file_str}, std::move (str_token)); } AST::Fragment @@ -286,11 +303,13 @@ MacroBuiltin::column_handler (Location invoc_locus, AST::MacroInvocData &) auto current_column = Session::get_instance ().linemap->location_to_column (invoc_locus); + auto column_tok = make_token ( + Token::make_int (invoc_locus, std::to_string (current_column))); auto column_no = AST::SingleASTNode (std::unique_ptr ( new AST::LiteralExpr (std::to_string (current_column), AST::Literal::INT, PrimitiveCoreType::CORETYPE_U32, {}, invoc_locus))); - return AST::Fragment::complete ({column_no}); + return AST::Fragment ({column_no}, std::move (column_tok)); } /* Expand builtin macro include_bytes!("filename"), which includes the contents @@ -316,14 +335,25 @@ MacroBuiltin::include_bytes_handler (Location invoc_locus, /* Is there a more efficient way to do this? */ std::vector> elts; + + // We create the tokens for a borrow expression of a byte array, so + // & [ , , ... ] + std::vector> toks; + toks.emplace_back (make_token (Token::make (AMP, invoc_locus))); + toks.emplace_back (make_token (Token::make (LEFT_SQUARE, invoc_locus))); + for (uint8_t b : bytes) { elts.emplace_back ( new AST::LiteralExpr (std::string (1, (char) b), AST::Literal::BYTE, PrimitiveCoreType::CORETYPE_U8, {} /* outer_attrs */, invoc_locus)); + toks.emplace_back (make_token (Token::make_byte_char (invoc_locus, b))); + toks.emplace_back (make_token (Token::make (COMMA, invoc_locus))); } + toks.emplace_back (make_token (Token::make (RIGHT_SQUARE, invoc_locus))); + auto elems = std::unique_ptr ( new AST::ArrayElemsValues (std::move (elts), invoc_locus)); @@ -334,8 +364,9 @@ MacroBuiltin::include_bytes_handler (Location invoc_locus, new AST::BorrowExpr (std::move (array), false, false, {}, invoc_locus)); auto node = AST::SingleASTNode (std::move (borrow)); - return AST::Fragment::complete ({node}); -} + + return AST::Fragment ({node}, std::move (toks)); +} // namespace Rust /* 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 @@ -362,7 +393,10 @@ MacroBuiltin::include_str_handler (Location invoc_locus, std::string str ((const char *) &bytes[0], bytes.size ()); auto node = AST::SingleASTNode (make_string (invoc_locus, str)); - return AST::Fragment::complete ({node}); + auto str_tok = make_token (Token::make_string (invoc_locus, std::move (str))); + + // FIXME: Do not return an empty token vector here + return AST::Fragment ({node}, std::move (str_tok)); } /* Expand builtin macro compile_error!("error"), which forces a compile error @@ -383,9 +417,62 @@ MacroBuiltin::compile_error_handler (Location invoc_locus, return AST::Fragment::create_error (); } +static std::vector> +check_for_eager_invocations ( + std::vector> &expressions) +{ + std::vector> pending; + + for (auto &expr : expressions) + if (expr->get_ast_kind () == AST::Kind::MACRO_INVOCATION) + pending.emplace_back (std::unique_ptr ( + static_cast (expr->clone_expr ().release ()))); + + return pending; +} + /* Expand builtin macro concat!(), which joins all the literal parameters into a string with no delimiter. */ +// This is a weird one. We want to do something where, if something cannot be +// expanded yet (i.e. macro invocation?) we return the whole MacroInvocation +// node again but expanded as much as possible. +// Is that possible? How do we do that? +// +// Let's take a few examples: +// +// 1. concat!(1, 2, true); +// 2. concat!(a!(), 2, true); +// 3. concat!(concat!(1, false), 2, true); +// 4. concat!(concat!(1, a!()), 2, true); +// +// 1. We simply want to return the new fragment: "12true" +// 2. We want to return `concat!(a_expanded, 2, true)` as a fragment +// 3. We want to return `concat!(1, false, 2, true)` +// 4. We want to return `concat!(concat!(1, a_expanded), 2, true); +// +// How do we do that? +// +// For each (un)expanded fragment: we check if it is expanded fully +// +// 1. What is expanded fully? +// 2. How to check? +// +// If it is expanded fully and not a literal, then we error out. +// Otherwise we simply emplace it back and keep going. +// +// In the second case, we must mark that this concat invocation still has some +// expansion to do: This allows us to return a `MacroInvocation { ... }` as an +// AST fragment, instead of a completed string. +// +// This means that we must change all the `try_expand_many_*` APIs and so on to +// return some sort of index or way to signify that we might want to reuse some +// bits and pieces of the original token tree. +// +// Now, before that: How do we resolve the names used in a builtin macro +// invocation? +// Do we split the two passes of parsing the token tree and then expanding it? +// Can we do that easily? AST::Fragment MacroBuiltin::concat_handler (Location invoc_locus, AST::MacroInvocData &invoc) { @@ -398,12 +485,25 @@ MacroBuiltin::concat_handler (Location invoc_locus, AST::MacroInvocData &invoc) auto last_token_id = macro_end_token (invoc_token_tree, parser); + auto start = lex.get_offs (); /* NOTE: concat! could accept no argument, so we don't have any checks here */ auto expanded_expr = try_expand_many_expr (parser, last_token_id, invoc.get_expander (), has_error); + auto end = lex.get_offs (); + + auto tokens = lex.get_token_slice (start, end); + + auto pending_invocations = check_for_eager_invocations (expanded_expr); + if (!pending_invocations.empty ()) + return make_eager_builtin_invocation (AST::BuiltinMacro::Concat, + invoc_locus, + invoc.get_delim_tok_tree (), + std::move (pending_invocations)); + for (auto &expr : expanded_expr) { - if (!expr->is_literal ()) + if (!expr->is_literal () + && expr->get_ast_kind () != AST::MACRO_INVOCATION) { has_error = true; rust_error_at (expr->get_locus (), "expected a literal"); @@ -431,12 +531,13 @@ MacroBuiltin::concat_handler (Location invoc_locus, AST::MacroInvocData &invoc) return AST::Fragment::create_error (); auto node = AST::SingleASTNode (make_string (invoc_locus, str)); - return AST::Fragment::complete ({node}); + auto str_tok = make_token (Token::make_string (invoc_locus, std::move (str))); + + return AST::Fragment ({node}, std::move (str_tok)); } /* Expand builtin macro env!(), which inspects an environment variable at compile time. */ - AST::Fragment MacroBuiltin::env_handler (Location invoc_locus, AST::MacroInvocData &invoc) { @@ -449,10 +550,22 @@ MacroBuiltin::env_handler (Location invoc_locus, AST::MacroInvocData &invoc) std::unique_ptr lit_expr = nullptr; bool has_error = false; + auto start = lex.get_offs (); auto expanded_expr = try_expand_many_expr (parser, last_token_id, invoc.get_expander (), has_error); + auto end = lex.get_offs (); + + auto tokens = lex.get_token_slice (start, end); + if (has_error) return AST::Fragment::create_error (); + + auto pending = check_for_eager_invocations (expanded_expr); + if (!pending.empty ()) + return make_eager_builtin_invocation (AST::BuiltinMacro::Env, invoc_locus, + invoc_token_tree, + std::move (pending)); + if (expanded_expr.size () < 1 || expanded_expr.size () > 2) { rust_error_at (invoc_locus, "env! takes 1 or 2 arguments"); @@ -492,7 +605,11 @@ MacroBuiltin::env_handler (Location invoc_locus, AST::MacroInvocData &invoc) } auto node = AST::SingleASTNode (make_string (invoc_locus, env_value)); - return AST::Fragment::complete ({node}); + auto tok + = make_token (Token::make_string (invoc_locus, std::move (env_value))); + + // FIXME: Do not return an empty token vector here + return AST::Fragment ({node}, std::move (tok)); } AST::Fragment @@ -527,8 +644,11 @@ MacroBuiltin::cfg_handler (Location invoc_locus, AST::MacroInvocData &invoc) auto literal_exp = AST::SingleASTNode (std::unique_ptr ( new AST::LiteralExpr (result ? "true" : "false", AST::Literal::BOOL, PrimitiveCoreType::CORETYPE_BOOL, {}, invoc_locus))); + auto tok = make_token ( + Token::make (result ? TRUE_LITERAL : FALSE_LITERAL, invoc_locus)); - return AST::Fragment::complete ({literal_exp}); + // FIXME: Do not return an empty token vector here + return AST::Fragment ({literal_exp}, std::move (tok)); } /* Expand builtin macro include!(), which includes a source file at the current @@ -585,7 +705,8 @@ MacroBuiltin::include_handler (Location invoc_locus, AST::MacroInvocData &invoc) nodes.push_back (node); } - return AST::Fragment::complete (nodes); + // FIXME: Do not return an empty token vector here + return AST::Fragment (nodes, nullptr); } AST::Fragment @@ -597,8 +718,11 @@ MacroBuiltin::line_handler (Location invoc_locus, AST::MacroInvocData &) auto line_no = AST::SingleASTNode (std::unique_ptr ( new AST::LiteralExpr (std::to_string (current_line), AST::Literal::INT, PrimitiveCoreType::CORETYPE_U32, {}, invoc_locus))); + auto tok + = make_token (Token::make_int (invoc_locus, std::to_string (current_line))); - return AST::Fragment::complete ({line_no}); + // FIXME: Do not return an empty token vector here + return AST::Fragment ({line_no}, std::move (tok)); } } // namespace Rust diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc index bf914ee19e3..0ff849dc85d 100644 --- a/gcc/rust/expand/rust-macro-expand.cc +++ b/gcc/rust/expand/rust-macro-expand.cc @@ -110,6 +110,114 @@ MacroExpander::expand_decl_macro (Location invoc_locus, semicolon, peek_context ()); } +void +MacroExpander::expand_eager_invocations (AST::MacroInvocation &invoc) +{ + if (invoc.get_pending_eager_invocations ().empty ()) + return; + + // We have to basically create a new delimited token tree which contains the + // result of one step of expansion. In the case of builtin macros called with + // other macro invocations, such as `concat!("h", 'a', a!())`, we need to + // expand `a!()` before expanding the concat macro. + // This will, ideally, give us a new token tree containing the various + // existing tokens + the result of the expansion of a!(). + // To do this, we "parse" the given token tree to find anything that "looks + // like a macro invocation". Then, we get the corresponding macro invocation + // from the `pending_eager_invocations` vector and expand it. + // Because the `pending_eager_invocations` vector is created in the same order + // that the DelimTokenTree is parsed, we know that the first macro invocation + // within the DelimTokenTree corresponds to the first element in + // `pending_eager_invocations`. The idea is thus to: + // 1. Find a macro invocation in the token tree, noting the index of the start + // token and of the end token + // 2. Get its associated invocation in `pending_eager_invocations` + // 3. Expand that element + // 4. Get the token tree associated with that AST fragment + // 5. Replace the original tokens corresponding to the invocation with the new + // tokens from the fragment + // pseudo-code: + // + // i = 0; + // for tok in dtt: + // if tok is identifier && tok->next() is !: + // start = index(tok); + // l_delim = tok->next()->next(); + // tok = skip_until_r_delim(); + // end = index(tok); + // + // new_tt = expand_eager_invoc(eagers[i++]); + // old_tt[start..end] = new_tt; + + auto dtt = invoc.get_invoc_data ().get_delim_tok_tree (); + auto stream = dtt.to_token_stream (); + std::vector> new_stream; + size_t current_pending = 0; + + // we need to create a clone of the delimited token tree as the lexer + // expects ownership of the tokens + std::vector> dtt_clone; + for (auto &tok : stream) + dtt_clone.emplace_back (tok->clone_token ()); + + MacroInvocLexer lex (std::move (dtt_clone)); + Parser parser (lex); + + // we want to build a substitution map - basically, associating a `start` and + // `end` index for each of the pending macro invocations + std::map, std::unique_ptr &> + substitution_map; + + for (size_t i = 0; i < stream.size (); i++) + { + // FIXME: Can't these offsets be figure out when we actually parse the + // pending_eager_invocation in the first place? + auto invocation = parser.parse_macro_invocation ({}); + + // if we've managed to parse a macro invocation, we look at the current + // offset and store them in the substitution map. Otherwise, we skip one + // token and try parsing again + if (invocation) + substitution_map.insert ( + {{i, parser.get_token_source ().get_offs ()}, + invoc.get_pending_eager_invocations ()[current_pending++]}); + else + parser.skip_token (stream[i]->get_id ()); + } + + size_t current_idx = 0; + for (auto kv : substitution_map) + { + auto &to_expand = kv.second; + expand_invoc (*to_expand, false); + + auto fragment = take_expanded_fragment (); + auto &new_tokens = fragment.get_tokens (); + + auto start = kv.first.first; + auto end = kv.first.second; + + // TODO: Add doc + for (size_t i = current_idx; i < start; i++) + new_stream.emplace_back (stream[i]->clone_token ()); + + // TODO: Add doc + for (auto &tok : new_tokens) + new_stream.emplace_back (tok->clone_token ()); + + current_idx = end; + } + // TODO: Add doc + for (size_t i = current_idx; i < stream.size (); i++) + new_stream.emplace_back (stream[i]->clone_token ()); + + auto new_dtt + = AST::DelimTokenTree (dtt.get_delim_type (), std::move (new_stream)); + + invoc.get_pending_eager_invocations ().clear (); + invoc.get_invoc_data ().set_delim_tok_tree (new_dtt); +} + void MacroExpander::expand_invoc (AST::MacroInvocation &invoc, bool has_semicolon) { @@ -119,6 +227,9 @@ MacroExpander::expand_invoc (AST::MacroInvocation &invoc, bool has_semicolon) return; } + if (invoc.get_kind () == AST::MacroInvocation::InvocKind::Builtin) + expand_eager_invocations (invoc); + AST::MacroInvocData &invoc_data = invoc.get_invoc_data (); // ?? @@ -151,6 +262,11 @@ MacroExpander::expand_invoc (AST::MacroInvocation &invoc, bool has_semicolon) if (!ok) return; + // We store the last expanded invocation and macro definition for error + // reporting in case the recursion limit is reached + last_invoc = &invoc; + last_def = rules_def; + if (rules_def->is_builtin ()) fragment = rules_def->get_builtin_transcriber () (invoc.get_locus (), invoc_data); @@ -292,7 +408,7 @@ MacroExpander::expand_crate () // mark for stripping if required item->accept_vis (attr_visitor); - auto fragment = take_expanded_fragment (attr_visitor); + auto fragment = take_expanded_fragment (); if (fragment.should_expand ()) { // Remove the current expanded invocation @@ -711,6 +827,9 @@ static AST::Fragment parse_many (Parser &parser, TokenId &delimiter, std::function parse_fn) { + auto &lexer = parser.get_token_source (); + auto start = lexer.get_offs (); + std::vector nodes; while (true) { @@ -728,8 +847,9 @@ parse_many (Parser &parser, TokenId &delimiter, nodes.emplace_back (std::move (node)); } + auto end = lexer.get_offs (); - return AST::Fragment::complete (std::move (nodes)); + return AST::Fragment (std::move (nodes), lexer.get_token_slice (start, end)); } /** @@ -838,11 +958,16 @@ transcribe_many_stmts (Parser &parser, TokenId &delimiter) static AST::Fragment transcribe_expression (Parser &parser) { + auto &lexer = parser.get_token_source (); + auto start = lexer.get_offs (); + auto expr = parser.parse_expr (); if (expr == nullptr) return AST::Fragment::create_error (); - return AST::Fragment::complete ({std::move (expr)}); + auto end = lexer.get_offs (); + + return AST::Fragment ({std::move (expr)}, lexer.get_token_slice (start, end)); } /** @@ -853,11 +978,16 @@ transcribe_expression (Parser &parser) static AST::Fragment transcribe_type (Parser &parser) { + auto &lexer = parser.get_token_source (); + auto start = lexer.get_offs (); + auto type = parser.parse_type (true); for (auto err : parser.get_errors ()) err.emit_error (); - return AST::Fragment::complete ({std::move (type)}); + auto end = lexer.get_offs (); + + return AST::Fragment ({std::move (type)}, lexer.get_token_slice (start, end)); } static AST::Fragment diff --git a/gcc/rust/expand/rust-macro-expand.h b/gcc/rust/expand/rust-macro-expand.h index bf761c1b199..94714169971 100644 --- a/gcc/rust/expand/rust-macro-expand.h +++ b/gcc/rust/expand/rust-macro-expand.h @@ -231,7 +231,7 @@ struct MacroExpander : cfg (cfg), crate (crate), session (session), sub_stack (SubstitutionScope ()), expanded_fragment (AST::Fragment::create_error ()), - resolver (Resolver::Resolver::get ()), + has_changed_flag (false), resolver (Resolver::Resolver::get ()), mappings (Analysis::Mappings::get ()) {} @@ -240,6 +240,12 @@ struct MacroExpander // Expands all macros in the crate passed in. void expand_crate (); + /** + * Expand the eager invocations contained within a builtin macro invocation. + * Called by `expand_invoc` when expanding builtin invocations. + */ + void expand_eager_invocations (AST::MacroInvocation &invoc); + /* Expands a macro invocation - possibly make both * have similar duck-typed interface and use templates?*/ // should this be public or private? @@ -315,49 +321,44 @@ struct MacroExpander void set_expanded_fragment (AST::Fragment &&fragment) { + if (!fragment.is_error ()) + has_changed_flag = true; + expanded_fragment = std::move (fragment); } - AST::Fragment take_expanded_fragment (AST::ASTVisitor &vis) + AST::Fragment take_expanded_fragment () { - AST::Fragment old_fragment = std::move (expanded_fragment); - auto accumulator = std::vector (); + auto fragment = std::move (expanded_fragment); expanded_fragment = AST::Fragment::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 - if (expanded_fragment.is_error ()) - accumulator.push_back (node); // if expansion fails, there might be a - // non-macro expression we need to keep - else - { - // if expansion succeeded, then we need to merge the fragment with - // the contents in the accumulator, so that our final expansion - // result will contain non-macro nodes as it should - auto new_nodes = expanded_fragment.get_nodes (); - std::move (new_nodes.begin (), new_nodes.end (), - std::back_inserter (accumulator)); - expanded_fragment = AST::Fragment::complete (accumulator); - } - expansion_depth--; - } - - return old_fragment; + + return fragment; } + /** + * Has the MacroExpander expanded a macro since its state was last reset? + */ + bool has_changed () const { return has_changed_flag; } + + /** + * Reset the expander's "changed" state. This function should be executed at + * each iteration in a fixed point loop + */ + void reset_changed_state () { has_changed_flag = false; } + + AST::MacroRulesDefinition *get_last_definition () { return last_def; } + AST::MacroInvocation *get_last_invocation () { return last_invoc; } + private: AST::Crate &crate; Session &session; SubstitutionScope sub_stack; std::vector context; AST::Fragment expanded_fragment; + bool has_changed_flag; + + AST::MacroRulesDefinition *last_def; + AST::MacroInvocation *last_invoc; public: Resolver::Resolver *resolver; diff --git a/gcc/rust/resolve/rust-early-name-resolver.cc b/gcc/rust/resolve/rust-early-name-resolver.cc index 8100564dc78..60d6c8abc4d 100644 --- a/gcc/rust/resolve/rust-early-name-resolver.cc +++ b/gcc/rust/resolve/rust-early-name-resolver.cc @@ -24,20 +24,17 @@ namespace Rust { namespace Resolver { EarlyNameResolver::EarlyNameResolver () - : resolver (*Resolver::get ()), mappings (*Analysis::Mappings::get ()) + : current_scope (UNKNOWN_NODEID), 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? + scoped (crate.get_node_id (), [&crate, this] () { + for (auto &item : crate.items) + item->accept_vis (*this); + }); } void @@ -335,11 +332,13 @@ EarlyNameResolver::visit (AST::ClosureExprInner &expr) void EarlyNameResolver::visit (AST::BlockExpr &expr) { - for (auto &stmt : expr.get_statements ()) - stmt->accept_vis (*this); + scoped (expr.get_node_id (), [&expr, this] () { + for (auto &stmt : expr.get_statements ()) + stmt->accept_vis (*this); - if (expr.has_tail_expr ()) - expr.get_tail_expr ()->accept_vis (*this); + if (expr.has_tail_expr ()) + expr.get_tail_expr ()->accept_vis (*this); + }); } void @@ -434,8 +433,11 @@ EarlyNameResolver::visit (AST::WhileLetLoopExpr &expr) void EarlyNameResolver::visit (AST::ForLoopExpr &expr) { - expr.get_iterator_expr ()->accept_vis (*this); - expr.get_loop_block ()->accept_vis (*this); + scoped (expr.get_node_id (), [&expr, this] () { + expr.get_pattern ()->accept_vis (*this); + expr.get_iterator_expr ()->accept_vis (*this); + expr.get_loop_block ()->accept_vis (*this); + }); } void @@ -473,7 +475,9 @@ void EarlyNameResolver::visit (AST::IfLetExpr &expr) { expr.get_value_expr ()->accept_vis (*this); - expr.get_if_block ()->accept_vis (*this); + + scoped (expr.get_node_id (), + [&expr, this] () { expr.get_if_block ()->accept_vis (*this); }); } void @@ -504,16 +508,21 @@ 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); + scoped (expr.get_node_id (), [&expr, this] () { + for (auto &arm : expr.get_match_cases ()) + { + scoped (arm.get_node_id (), [&arm, this] () { + if (arm.get_arm ().has_match_arm_guard ()) + arm.get_arm ().get_guard_expr ()->accept_vis (*this); - match_arm.get_expr ()->accept_vis (*this); - } + for (auto &pattern : arm.get_arm ().get_patterns ()) + pattern->accept_vis (*this); + + arm.get_expr ()->accept_vis (*this); + }); + } + }); } void @@ -571,8 +580,10 @@ EarlyNameResolver::visit (AST::Method &method) void EarlyNameResolver::visit (AST::Module &module) { - for (auto &item : module.get_items ()) - item->accept_vis (*this); + scoped (module.get_node_id (), [&module, this] () { + for (auto &item : module.get_items ()) + item->accept_vis (*this); + }); } void @@ -722,8 +733,13 @@ EarlyNameResolver::visit (AST::TraitItemType &) void EarlyNameResolver::visit (AST::Trait &trait) { - for (auto &item : trait.get_trait_items ()) - item->accept_vis (*this); + for (auto &generic : trait.get_generic_params ()) + generic->accept_vis (*this); + + scoped (trait.get_node_id (), [&trait, this] () { + for (auto &item : trait.get_trait_items ()) + item->accept_vis (*this); + }); } void @@ -734,8 +750,10 @@ EarlyNameResolver::visit (AST::InherentImpl &impl) for (auto &generic : impl.get_generic_params ()) generic->accept_vis (*this); - for (auto &item : impl.get_impl_items ()) - item->accept_vis (*this); + scoped (impl.get_node_id (), [&impl, this] () { + for (auto &item : impl.get_impl_items ()) + item->accept_vis (*this); + }); } void @@ -746,8 +764,10 @@ EarlyNameResolver::visit (AST::TraitImpl &impl) for (auto &generic : impl.get_generic_params ()) generic->accept_vis (*this); - for (auto &item : impl.get_impl_items ()) - item->accept_vis (*this); + scoped (impl.get_node_id (), [&impl, this] () { + for (auto &item : impl.get_impl_items ()) + item->accept_vis (*this); + }); } void @@ -772,8 +792,10 @@ EarlyNameResolver::visit (AST::ExternalFunctionItem &item) void EarlyNameResolver::visit (AST::ExternBlock &block) { - for (auto &item : block.get_extern_items ()) - item->accept_vis (*this); + scoped (block.get_node_id (), [&block, this] () { + for (auto &item : block.get_extern_items ()) + item->accept_vis (*this); + }); } void @@ -795,6 +817,15 @@ EarlyNameResolver::visit (AST::MacroRulesDefinition &rules_def) rules_def.get_rule_name ()); resolver.get_macro_scope ().insert (path, rules_def.get_node_id (), rules_def.get_locus ()); + + /* Since the EarlyNameResolver runs multiple time (fixed point algorithm) + * we could be inserting the same macro def over and over again until we + * implement some optimizations */ + // FIXME: ARTHUR: Remove that lookup and add proper optimizations instead + AST::MacroRulesDefinition *tmp = nullptr; + if (mappings.lookup_macro_def (rules_def.get_node_id (), &tmp)) + return; + mappings.insert_macro_def (&rules_def); rust_debug_loc (rules_def.get_locus (), "inserting macro def: [%s]", path.get ().c_str ()); @@ -806,6 +837,10 @@ EarlyNameResolver::visit (AST::MacroInvocation &invoc) auto &invoc_data = invoc.get_invoc_data (); auto has_semicolon = invoc.has_semicolon (); + if (invoc.get_kind () == AST::MacroInvocation::InvocKind::Builtin) + for (auto &pending_invoc : invoc.get_pending_eager_invocations ()) + pending_invoc->accept_vis (*this); + // ?? // switch on type of macro: // - '!' syntax macro (inner switch) @@ -847,6 +882,30 @@ EarlyNameResolver::visit (AST::MacroInvocation &invoc) bool ok = mappings.lookup_macro_def (resolved_node, &rules_def); rust_assert (ok); + auto &outer_attrs = rules_def->get_outer_attrs (); + bool is_builtin + = std::any_of (outer_attrs.begin (), outer_attrs.end (), + [] (AST::Attribute attr) { + return attr.get_path () == "rustc_builtin_macro"; + }); + + if (is_builtin) + { + auto builtin_kind + = AST::builtin_macro_from_string (rules_def->get_rule_name ()); + invoc.map_to_builtin (builtin_kind); + } + + auto attributes = rules_def->get_outer_attrs (); + + /* Since the EarlyNameResolver runs multiple time (fixed point algorithm) + * we could be inserting the same macro def over and over again until we + * implement some optimizations */ + // FIXME: ARTHUR: Remove that lookup and add proper optimizations instead + AST::MacroRulesDefinition *tmp_def = nullptr; + if (mappings.lookup_macro_invocation (invoc, &tmp_def)) + return; + mappings.insert_macro_invocation (invoc, rules_def); } diff --git a/gcc/rust/resolve/rust-early-name-resolver.h b/gcc/rust/resolve/rust-early-name-resolver.h index c53ab9f3d6a..c74c452ecaf 100644 --- a/gcc/rust/resolve/rust-early-name-resolver.h +++ b/gcc/rust/resolve/rust-early-name-resolver.h @@ -35,6 +35,71 @@ public: void go (AST::Crate &crate); private: + /** + * Execute a lambda within a scope. This is equivalent to calling + * `enter_scope` before your code and `exit_scope` after. This ensures + * no errors can be committed + */ + void scoped (NodeId scope_id, std::function fn) + { + auto old_scope = current_scope; + current_scope = scope_id; + resolver.get_macro_scope ().push (scope_id); + resolver.push_new_macro_rib (resolver.get_macro_scope ().peek ()); + + fn (); + + resolver.get_macro_scope ().pop (); + current_scope = old_scope; + } + + /** + * The "scope" we are currently in. + * + * This involves lexical scopes: + * + * ```rust + * // current_scope = crate_id; + * macro_rules! foo { () => {} ) + * + * { + * // current_scope = current_block_id; + * macro_rules! foo { () => { something!(); } } + * } + * // current_scope = crate_id; + * ``` + * + * as well as any sort of scope-like structure that might impact import name + * resolution or macro name resolution: + * + * ```rust + * macro_rules! foo { + * () => { fn empty() {} } + * } + * + * + * trait Foo { + * fn foo() { + * fn inner_foo() { + * macro_rules! foo { () => {} ) + * + * foo!(); + * } + * + * foo!(); + * } + * + * foo!(); + * } + * + * foo!(); + * ``` + */ + NodeId current_scope; + + /* The crate's scope */ + NodeId crate_scope; + Resolver &resolver; Analysis::Mappings &mappings; diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc index 28ac2ba4a53..0f460e2d2f4 100644 --- a/gcc/rust/rust-session-manager.cc +++ b/gcc/rust/rust-session-manager.cc @@ -821,9 +821,6 @@ 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 @@ -833,11 +830,41 @@ Session::expansion (AST::Crate &crate) // if not, would at least have to configure recursion_limit ExpansionCfg cfg; + auto fixed_point_reached = false; + unsigned iterations = 0; + // create extctxt? from parse session, cfg, and resolver? /* expand by calling cxtctxt object's monotonic_expander's expand_crate * method. */ MacroExpander expander (crate, cfg, *this); - expander.expand_crate (); + + while (!fixed_point_reached && iterations < cfg.recursion_limit) + { + /* We need to name resolve macros and imports here */ + Resolver::EarlyNameResolver ().go (crate); + + expander.expand_crate (); + + fixed_point_reached = !expander.has_changed (); + expander.reset_changed_state (); + iterations++; + + if (saw_errors ()) + break; + } + + if (iterations == cfg.recursion_limit) + { + auto last_invoc = expander.get_last_invocation (); + auto last_def = expander.get_last_definition (); + + rust_assert (last_def && last_invoc); + + RichLocation range (last_invoc->get_locus ()); + range.add_range (last_def->get_locus ()); + + rust_error_at (range, "reached recursion limit"); + } // error reporting - check unused macros, get missing fragment specifiers diff --git a/gcc/testsuite/rust/compile/builtin_macro_recurse.rs b/gcc/testsuite/rust/compile/builtin_macro_eager1.rs similarity index 100% rename from gcc/testsuite/rust/compile/builtin_macro_recurse.rs rename to gcc/testsuite/rust/compile/builtin_macro_eager1.rs diff --git a/gcc/testsuite/rust/compile/builtin_macro_eager2.rs b/gcc/testsuite/rust/compile/builtin_macro_eager2.rs new file mode 100644 index 00000000000..21bf95c7829 --- /dev/null +++ b/gcc/testsuite/rust/compile/builtin_macro_eager2.rs @@ -0,0 +1,16 @@ +#[rustc_builtin_macro] +macro_rules! env { + () => {}; +} + +macro_rules! a { + () => { + "__undefined__" + }; +} + +fn main() { + let _ = env!(a!()); // { dg-error "environment variable .__undefined__. not defined" } + let _ = env!(a!(), "custom"); // { dg-error "custom" } + let _ = env!(a!(), a!()); // { dg-error "__undefined__" } +} diff --git a/gcc/testsuite/rust/compile/builtin_macro_recurse2.rs b/gcc/testsuite/rust/compile/builtin_macro_recurse2.rs new file mode 100644 index 00000000000..d8599208624 --- /dev/null +++ b/gcc/testsuite/rust/compile/builtin_macro_recurse2.rs @@ -0,0 +1,20 @@ +// { dg-additional-options "-fdump-tree-gimple" } + +#[rustc_builtin_macro] +macro_rules! concat { + () => {}; +} + +macro_rules! a { + () => { + "hey" + }; + ($($t:tt)*) => { + "ho" + }; +} + +fn main() { + // { dg-final { scan-tree-dump-times {"abheyho"} 1 gimple } } + let _ = concat!("a", 'b', a!(), a!(b c d e f a!()), '\0'); +} diff --git a/gcc/testsuite/rust/compile/macro17.rs b/gcc/testsuite/rust/compile/macro17.rs index 743216529b7..b50afbece41 100644 --- a/gcc/testsuite/rust/compile/macro17.rs +++ b/gcc/testsuite/rust/compile/macro17.rs @@ -1,7 +1,7 @@ macro_rules! rep { - ($a:literal) => { $a }; // { dg-error "reached recursion limit" } - ($a:literal $(, $e:literal)*) => { // { dg-error "reached recursion limit" } - $a + rep!(0 $(, $e)*) // { dg-error "Failed to match" } + ($a:literal) => { $a }; + ($a:literal $(, $e:literal)*) => { + $a + rep!(0 $(, $e)*) // { dg-error "reached recursion limit" } } } diff --git a/gcc/testsuite/rust/compile/macro44.rs b/gcc/testsuite/rust/compile/macro44.rs index 84b2cdbb506..dabac6f7844 100644 --- a/gcc/testsuite/rust/compile/macro44.rs +++ b/gcc/testsuite/rust/compile/macro44.rs @@ -11,12 +11,12 @@ mod foo { () => {{}}; } - fn foo_f() { // { dg-warning "function is never used" } + fn foo_f() { foo!(); } - fn bar_f() { // { dg-warning "function is never used" } - baz!(); + fn bar_f() { + baz!(); // { dg-error "unknown macro" } } } diff --git a/gcc/testsuite/rust/compile/macro46.rs b/gcc/testsuite/rust/compile/macro46.rs new file mode 100644 index 00000000000..3ef811aeab5 --- /dev/null +++ b/gcc/testsuite/rust/compile/macro46.rs @@ -0,0 +1,19 @@ +fn foo() {} + +fn main() { + macro_rules! a { + () => { + foo(); + }; + } + + { + macro_rules! a { + () => { + bar(); + }; + } + } + + a!(); +} From patchwork Wed Apr 5 14:03: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: 79691 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp355380vqo; Wed, 5 Apr 2023 07:35:53 -0700 (PDT) X-Google-Smtp-Source: AKy350YzBAksrk6db2qbBEb6+piXMq9YKR2dRxz+G0tUn68+y6KgDMM+IpexUy/YH1/51sHdEXhe X-Received: by 2002:a17:906:e1b:b0:87b:d3f3:dcf3 with SMTP id l27-20020a1709060e1b00b0087bd3f3dcf3mr2916302eji.35.1680705353595; Wed, 05 Apr 2023 07:35:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705353; cv=none; d=google.com; s=arc-20160816; b=r5kkK1SepS+qCOHPx9WAPgf3Fn99l6sZ8k20i8weeW+kaSCiXonyFmgdk5syFWlNrj 3hJ+RBrMERu6srGR+HfZyab8IuNRQlJe08KzHeD6xWNXtMrlNtrEzj7d+kDLbCpc27wG wEf7QEYaeqifADI2/JIx7FNLFs5AVAkyAvBwWZVjI1EdG1VTaEDyIJ32UJe64GUgP0om h/CE8sfPKPBAevzGwR2uS54gq6d3yt77r9IAAx+9KlWa00GQyQ7HNmHbLCutQSJRQdf8 ZcIPte/Wb2XzMe1NCw4LN2cXr9QY/8pQuZvzaoPqduGXdJ40DLrrQb4H2rzQxemaO/4c tTpQ== 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=8b32RuoybSkyTRQ0LtyuiJsCvJja3So0VmvYcWED2Vc=; b=E25tstX8s1IT0rU62VKRm3vgabOF9aTyt7WKJr5aB1RnI7DiAEkt4m2d/At2uG4SEV 2DAhd7JU/XNm4ZXU8QhNt23qRyNIzEAwxYOMqsxGv6xcrNflsUj+SC2/ZpnmxgG1TMAK vjAACWkRnlIAnoPFN7LGrVq1tocafsCMxl9PNvoDT0Bzz7Oz5f+naOpDqPRpCJNZTosi qXLaKbjGdRKAxucv0hiGlMHjYsG//eyBS91SLV+9uQohAjZWBy4MPUyCaj0dYunpAb1a 2BaOnSOiNcyzlpF3lUK+5d56qfwptZ/23y2MyF72IP5WA6l3/oiD7cD9sVWh+fHuhdlr dAJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=DLUuNkn7; 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 q17-20020a170906145100b0094779d354efsi526253ejc.941.2023.04.05.07.35.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:35:53 -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=DLUuNkn7; 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 997E438DCF2B for ; Wed, 5 Apr 2023 14:13:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id 617973857006 for ; Wed, 5 Apr 2023 14:06:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 617973857006 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-x32c.google.com with SMTP id i5-20020a05600c354500b003edd24054e0so23810660wmq.4 for ; Wed, 05 Apr 2023 07:06:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703570; 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=8b32RuoybSkyTRQ0LtyuiJsCvJja3So0VmvYcWED2Vc=; b=DLUuNkn7v03y0w2TAT6sIXa4PnmIhp/XmtvJYzO1ajYjjmwJLDOYXHh1zMLDNR8n75 Cpqv8UBvl42xvBP8Qlh/mrTzUGeQuKqAT+V/HRcVs3bYjXR96ha1J/U9BPQezG8fVSyP TnBqb56Os5AKpGEpL4BO/sqvz+Fqwnx/xZfyg7XSQjKZ5eFdgay3cyojJAdp/TAOoL2d G1wmtNErz67zNiA02tf0yI0vXO1S+89gakZmwpRkvYxqZK7vUS+RaKMOtdJL5YAQxaA1 /hyp3J2qwAjQOkS2XdG394PxRI280bv8dwjkIjJ3j1bLf+8IB2VVKfyRbMpTBb6as3DS WSzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703570; 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=8b32RuoybSkyTRQ0LtyuiJsCvJja3So0VmvYcWED2Vc=; b=LuqOkje+vwi+8F6wPuSnWk6fZk3Dmx7t7+OSrysnomBJ/RWzzu7f8iL0k+rTQPsOgL jaAhIj/ORCGNJEjZX2TUzo7RCN9bbzIZjm0y7p+4iFK6eJVT78XMVnO2OB0hYaKBoAsm 3PxqDzB9/9vMwD9yzC38iR2Pg2vzMcXKzY8k5OaQCP7dsuJWB/s96A5NEvoiYqv34353 RwsaVIZt/tFMS8f0h1oBLxAsrvE0iLgbvAeTubCGouI8RuE8gqWdluwzvjebikEPegil TXq2GmLkazhUdWP5CEJoofHJe/Kyln7r/9jA1K0aNdeB31LPXEhEYqzVliJY6OgX5OQh C+GQ== X-Gm-Message-State: AAQBX9foMP2nUWtnqo+VUb3Gk67HG3fUD9ZAbDmLSoMWFDC5+pkXgK7t Kh67WrQJajuIhObxoZfueQv1zUh5x3PX/SSwEA== X-Received: by 2002:a1c:f218:0:b0:3ef:6eeb:c25a with SMTP id s24-20020a1cf218000000b003ef6eebc25amr4700855wmc.6.1680703570741; Wed, 05 Apr 2023 07:06:10 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:10 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 61/88] gccrs: expander: Add documentation for `expand_eager_invocations` Date: Wed, 5 Apr 2023 16:03:45 +0200 Message-Id: <20230405140411.3016563-62-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.6 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?1762347296801380915?= X-GMAIL-MSGID: =?utf-8?q?1762347296801380915?= From: Arthur Cohen gcc/rust/ChangeLog: * expand/rust-macro-expand.cc (MacroExpander::expand_eager_invocations): Add documentation explaining the algorithm. --- gcc/rust/expand/rust-macro-expand.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc index 0ff849dc85d..4b494490424 100644 --- a/gcc/rust/expand/rust-macro-expand.cc +++ b/gcc/rust/expand/rust-macro-expand.cc @@ -197,17 +197,25 @@ MacroExpander::expand_eager_invocations (AST::MacroInvocation &invoc) auto start = kv.first.first; auto end = kv.first.second; - // TODO: Add doc + // We're now going to re-add the tokens to the invocation's token tree. + // 1. Basically, what we want to do is insert all tokens up until the + // beginning of the macro invocation (start). + // 2. Then, we'll insert all of the tokens resulting from the macro + // expansion: These are in `new_tokens`. + // 3. Finally, we'll do that again from + // the end of macro and go back to 1. + for (size_t i = current_idx; i < start; i++) new_stream.emplace_back (stream[i]->clone_token ()); - // TODO: Add doc for (auto &tok : new_tokens) new_stream.emplace_back (tok->clone_token ()); current_idx = end; } - // TODO: Add doc + + // Once all of that is done, we copy the last remaining tokens from the + // original stream for (size_t i = current_idx; i < stream.size (); i++) new_stream.emplace_back (stream[i]->clone_token ()); From patchwork Wed Apr 5 14:03: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: 79719 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp363505vqo; Wed, 5 Apr 2023 07:48:29 -0700 (PDT) X-Google-Smtp-Source: AKy350Ywx5n/lm+/AdQVMgThlwGim2bIl3A4qtAytF2U8/+r36C3kIzdXv86zRjpjOgS00icxHfx X-Received: by 2002:a05:6402:1001:b0:501:d43e:d1e5 with SMTP id c1-20020a056402100100b00501d43ed1e5mr2124068edu.2.1680706109305; Wed, 05 Apr 2023 07:48:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706109; cv=none; d=google.com; s=arc-20160816; b=dkxXL5qFJQm+mJj64bb1JvXvYxBvEAHmwrAfq59KAVGKf6N/lTX67gBeHmhkkLHozZ BWT0BAkeKxelzdvwIIIDHd+yJ+HX56AXMyYLW91aNbkPwd+7CkIZ8ekPJEaVozcCs+2l sXoWrok0Dmx7dDg99DjQuCxgN3WXyOLkrmqE3jij6aXG2DUn3uGXRWcEAXWKd6LkAlgW GcZQbI6csSpM7SS9ZZn8vgWMXAp28EnMxmIHs1Ry1hMzi+HTFhx7/X5PheuQ98vqzMmd HuJCzJ6XSZAA9+4tHUiccyRsS8AMU27bKOQcL4vvA6xmF6fOwWJI+5HSv5BKmTVdFFc3 saLg== 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=j1NLDYkRbuWIXzNb2zmpxuFjBYQWc3xeAMCclQeuYEg=; b=tZylU8A56C70MhCsNBUXo7bGudld21YWqLY/gJr49dtfkl6pT25hDWV9wKBCO7eBsm WJalHaEDKgXV2ZbgYSndlcBIRDco6pQdY+Jtp4wq2bUETLcQedPHuMjInVLIwnLrG381 gJxBhRD8Y6aOaKfNnKD+dR2b0bLYQYAvZ8WX9XIFgGm4p22mnVHku2ad53m8VoCRu7dl TlCwOarXnp+WheCZMrJxdF+SwH3fBCJBy3abMezSmwK1RSh74u5bkn/ywWgxasf/CsXF TS+sR/oJYlXYwbCF1VaO6AaFbRi6/jJXCoX7PWNwpuEozm7ga2catK3HZjWWkOu6ZCIf xXoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Rp9oEUes; 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 b2-20020a170906150200b009476f7e3d4csi1917418ejd.234.2023.04.05.07.48.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:48:29 -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=Rp9oEUes; 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 86582395A00E for ; Wed, 5 Apr 2023 14:17:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id 0C9933855585 for ; Wed, 5 Apr 2023 14:06:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0C9933855585 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-x32c.google.com with SMTP id v6-20020a05600c470600b003f034269c96so11822145wmo.4 for ; Wed, 05 Apr 2023 07:06:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703571; 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=j1NLDYkRbuWIXzNb2zmpxuFjBYQWc3xeAMCclQeuYEg=; b=Rp9oEUesphhzfsdNh03JZdf5CvyaoYur6a5Y31HO3Qo85j/gEnravLPbm1KGjXQs+R YtgNg50hayoF0/4W2lQMRzyKZfXz90lVE6PgUATt8AAZefEJn1BNbDvHUQ3IxYCxJBi/ x2om2oFW1icwqywaLd7DECWcFDuPbVtMv3m41kRbpz/QprXEchDQlqNL5C0k6xau4MRf kmUeHTMI33fZgeNiM3Udqrx5Xd98tCwZVJJtHKX3+XyTVS7TETbUVkfUU4gqZrtxFSIt 8kt2pFVdapaMaKKlDR3np3EzP30ScXMqmi/Ik3iLhODVKy74BP8tWWbQDzyjr6lf1nhn sQZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703571; 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=j1NLDYkRbuWIXzNb2zmpxuFjBYQWc3xeAMCclQeuYEg=; b=0InbXEeqDfuiZXzRVH102RTJXIWmLP5/8S8fHDsJ5UZJK91SQQDXg8QrqIejpy+Yfs PKBsvgxuoeZUMV2LlQr9wPuX6CjSTWjOBebGqSS4Gl4eaGA4ZeDyCjq/x/R+bYlT8imN 4GvE2P+PCSVW4yUTJ10BN+Lj61k6aQdDCP9zzGZhcwxhMe777AdaejUze9gWaHg9cxRx LnUxzRgDGfQv7lycWJ5RubEYB4dX8b6d+QEoSZKajrAz6gSL/cLabfKX/O4fBxpTawFX YCCACh9mk63zqoQIwsDtP9AsTURsUNaLiD8zBBsRVDs/DWKGoA4C3llNaLGVNfV5GkEu 9zsA== X-Gm-Message-State: AAQBX9cvdVSwEuChPLvyG7A4HPY+HXFFKnee4+dUfof1wMaL/s+gesGI xGnxz55cYarSBiR2pTB35b+ZXLB24awqqHdZ8A== X-Received: by 2002:a7b:c4c6:0:b0:3eb:3945:d3fd with SMTP id g6-20020a7bc4c6000000b003eb3945d3fdmr4838365wmk.14.1680703571406; Wed, 05 Apr 2023 07:06:11 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:10 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [committed 62/88] gccrs: typecheck: Refactor rust-hir-trait-reference.h Date: Wed, 5 Apr 2023 16:03:46 +0200 Message-Id: <20230405140411.3016563-63-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.6 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?1762348089002670045?= X-GMAIL-MSGID: =?utf-8?q?1762348089002670045?= From: Pierre-Emmanuel Patry Move function body to their own cc file instead of keeping them in the header file. gcc/rust/ChangeLog: * Make-lang.in: Add `rust-hir-trait-reference.o`. * typecheck/rust-hir-trait-reference.h: Remove multiple function body. * typecheck/rust-hir-trait-reference.cc: Add multiple function body. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/Make-lang.in | 1 + .../typecheck/rust-hir-trait-reference.cc | 463 ++++++++++++++++++ gcc/rust/typecheck/rust-hir-trait-reference.h | 343 ++----------- 3 files changed, 510 insertions(+), 297 deletions(-) create mode 100644 gcc/rust/typecheck/rust-hir-trait-reference.cc diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index d9bc40945c3..09bbe450bd5 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -123,6 +123,7 @@ GRS_OBJS = \ rust/rust-tyty-bounds.o \ rust/rust-hir-type-check-util.o \ rust/rust-hir-trait-resolve.o \ + rust/rust-hir-trait-reference.o \ rust/rust-hir-type-check-item.o \ rust/rust-hir-type-check-type.o \ rust/rust-hir-type-check-struct.o \ diff --git a/gcc/rust/typecheck/rust-hir-trait-reference.cc b/gcc/rust/typecheck/rust-hir-trait-reference.cc new file mode 100644 index 00000000000..651c55abc82 --- /dev/null +++ b/gcc/rust/typecheck/rust-hir-trait-reference.cc @@ -0,0 +1,463 @@ +// 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-hir-trait-reference.h" + +namespace Rust { +namespace Resolver { + +std::string +TraitItemReference::as_string () const +{ + return "(" + trait_item_type_as_string (type) + " " + identifier + " " + ")"; +} + +bool +TraitItemReference::is_error () const +{ + return type == ERROR; +} + +bool +TraitItemReference::is_optional () const +{ + return optional_flag; +}; + +std::string +TraitItemReference::get_identifier () const +{ + return identifier; +} + +TraitItemReference::TraitItemType +TraitItemReference::get_trait_item_type () const +{ + return type; +} + +HIR::TraitItem * +TraitItemReference::get_hir_trait_item () const +{ + return hir_trait_item; +} + +Location +TraitItemReference::get_locus () const +{ + return locus; +} + +const Analysis::NodeMapping +TraitItemReference::get_mappings () const +{ + return hir_trait_item->get_mappings (); +} + +TyTy::BaseType * +TraitItemReference::get_tyty () const +{ + rust_assert (hir_trait_item != nullptr); + + switch (type) + { + case CONST: + return get_type_from_constant ( + static_cast (*hir_trait_item)); + break; + + case TYPE: + return get_type_from_typealias ( + static_cast (*hir_trait_item)); + + case FN: + return get_type_from_fn ( + static_cast (*hir_trait_item)); + break; + + default: + return get_error (); + } + + gcc_unreachable (); + return get_error (); +} + +TyTy::ErrorType * +TraitItemReference::get_error () const +{ + return new TyTy::ErrorType (get_mappings ().get_hirid ()); +} + +TraitReference::TraitReference ( + const HIR::Trait *hir_trait_ref, std::vector item_refs, + std::vector super_traits, + std::vector substs) + : hir_trait_ref (hir_trait_ref), item_refs (item_refs), + super_traits (super_traits) +{ + trait_substs.clear (); + trait_substs.reserve (substs.size ()); + for (const auto &p : substs) + trait_substs.push_back (p.clone ()); +} + +TraitReference::TraitReference (TraitReference const &other) + : hir_trait_ref (other.hir_trait_ref), item_refs (other.item_refs), + super_traits (other.super_traits) +{ + trait_substs.clear (); + trait_substs.reserve (other.trait_substs.size ()); + for (const auto &p : other.trait_substs) + trait_substs.push_back (p.clone ()); +} + +TraitReference & +TraitReference::operator= (TraitReference const &other) +{ + hir_trait_ref = other.hir_trait_ref; + item_refs = other.item_refs; + super_traits = other.super_traits; + + trait_substs.clear (); + trait_substs.reserve (other.trait_substs.size ()); + for (const auto &p : other.trait_substs) + trait_substs.push_back (p.clone ()); + + return *this; +} + +bool +TraitReference::is_error () const +{ + return hir_trait_ref == nullptr; +} + +Location +TraitReference::get_locus () const +{ + return hir_trait_ref->get_locus (); +} + +std::string +TraitReference::get_name () const +{ + rust_assert (!is_error ()); + return hir_trait_ref->get_name (); +} + +std::string +TraitReference::as_string () const +{ + if (is_error ()) + return ""; + + std::string item_buf; + for (auto &item : item_refs) + { + item_buf += item.as_string () + ", "; + } + return "HIR Trait: " + get_name () + "->" + + hir_trait_ref->get_mappings ().as_string () + " [" + item_buf + "]"; +} + +const HIR::Trait * +TraitReference::get_hir_trait_ref () const +{ + return hir_trait_ref; +} + +const Analysis::NodeMapping & +TraitReference::get_mappings () const +{ + return hir_trait_ref->get_mappings (); +} + +DefId +TraitReference::get_defid () const +{ + return get_mappings ().get_defid (); +} + +bool +TraitReference::lookup_hir_trait_item (const HIR::TraitItem &item, + TraitItemReference **ref) +{ + return lookup_trait_item (item.trait_identifier (), ref); +} + +bool +TraitReference::lookup_trait_item (const std::string &ident, + TraitItemReference **ref) +{ + for (auto &item : item_refs) + { + if (ident.compare (item.get_identifier ()) == 0) + { + *ref = &item; + return true; + } + } + return false; +} + +bool +TraitReference::lookup_trait_item_by_type ( + const std::string &ident, TraitItemReference::TraitItemType type, + TraitItemReference **ref) +{ + for (auto &item : item_refs) + { + if (item.get_trait_item_type () != type) + continue; + + if (ident.compare (item.get_identifier ()) == 0) + { + *ref = &item; + return true; + } + } + return false; +} + +bool +TraitReference::lookup_trait_item_by_type ( + const std::string &ident, TraitItemReference::TraitItemType type, + const TraitItemReference **ref) const +{ + for (auto &item : item_refs) + { + if (item.get_trait_item_type () != type) + continue; + + if (ident.compare (item.get_identifier ()) == 0) + { + *ref = &item; + return true; + } + } + return false; +} + +bool +TraitReference::lookup_hir_trait_item (const HIR::TraitItem &item, + const TraitItemReference **ref) const +{ + return lookup_trait_item (item.trait_identifier (), ref); +} + +bool +TraitReference::lookup_trait_item (const std::string &ident, + const TraitItemReference **ref) const +{ + for (auto &item : item_refs) + { + if (ident.compare (item.get_identifier ()) == 0) + { + *ref = &item; + 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; +} + +const TraitItemReference * +TraitReference::lookup_trait_item (const std::string &ident, + TraitItemReference::TraitItemType type) const +{ + for (auto &item : item_refs) + { + if (item.get_trait_item_type () != type) + continue; + + 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 (); +} + +size_t +TraitReference::size () const +{ + return item_refs.size (); +} + +const std::vector & +TraitReference::get_trait_items () const +{ + return item_refs; +} + +void +TraitReference::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 +TraitReference::on_resolved () +{ + for (auto &item : item_refs) + { + item.on_resolved (); + } +} + +void +TraitReference::clear_associated_types () +{ + for (auto &item : item_refs) + { + bool is_assoc_type = item.get_trait_item_type () + == TraitItemReference::TraitItemType::TYPE; + if (is_assoc_type) + item.associated_type_reset (); + } +} + +bool +TraitReference::is_equal (const TraitReference &other) const +{ + DefId this_id = get_mappings ().get_defid (); + DefId other_id = other.get_mappings ().get_defid (); + return this_id == other_id; +} + +const std::vector +TraitReference::get_super_traits () const +{ + return super_traits; +} + +bool +TraitReference::is_object_safe (bool emit_error, Location locus) const +{ + // https: // doc.rust-lang.org/reference/items/traits.html#object-safety + std::vector non_object_super_traits; + for (auto &item : super_traits) + { + if (!item->is_object_safe (false, Location ())) + non_object_super_traits.push_back (item); + } + + std::vector non_object_safe_items; + for (auto &item : get_trait_items ()) + { + if (!item.is_object_safe ()) + non_object_safe_items.push_back (&item); + } + + bool is_safe + = non_object_super_traits.empty () && non_object_safe_items.empty (); + if (emit_error && !is_safe) + { + RichLocation r (locus); + for (auto &item : non_object_super_traits) + r.add_range (item->get_locus ()); + for (auto &item : non_object_safe_items) + r.add_range (item->get_locus ()); + + rust_error_at (r, "trait bound is not object safe"); + } + + return is_safe; +} + +bool +TraitReference::trait_has_generics () const +{ + return !trait_substs.empty (); +} + +std::vector +TraitReference::get_trait_substs () const +{ + return trait_substs; +} + +bool +TraitReference::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; +} + +AssociatedImplTrait::AssociatedImplTrait (TraitReference *trait, + HIR::ImplBlock *impl, + TyTy::BaseType *self, + Resolver::TypeCheckContext *context) + : trait (trait), impl (impl), self (self), context (context) +{} + +TraitReference * +AssociatedImplTrait::get_trait () +{ + return trait; +} + +HIR::ImplBlock * +AssociatedImplTrait::get_impl_block () +{ + return impl; +} + +TyTy::BaseType * +AssociatedImplTrait::get_self () +{ + return self; +} +const TyTy::BaseType * +AssociatedImplTrait::get_self () const +{ + return self; +} + +} // namespace Resolver +} // namespace Rust diff --git a/gcc/rust/typecheck/rust-hir-trait-reference.h b/gcc/rust/typecheck/rust-hir-trait-reference.h index adb63b468d1..f3703efcced 100644 --- a/gcc/rust/typecheck/rust-hir-trait-reference.h +++ b/gcc/rust/typecheck/rust-hir-trait-reference.h @@ -20,8 +20,8 @@ #define RUST_HIR_TRAIT_REF_H #include "rust-hir-full.h" -#include "rust-tyty-visitor.h" #include "rust-hir-type-check-util.h" +#include "rust-tyty-visitor.h" namespace Rust { namespace Resolver { @@ -61,13 +61,9 @@ public: return error; } - bool is_error () const { return type == ERROR; } + bool is_error () const; - std::string as_string () const - { - return "(" + trait_item_type_as_string (type) + " " + identifier + " " - + ")"; - } + std::string as_string () const; static std::string trait_item_type_as_string (TraitItemType ty) { @@ -85,53 +81,24 @@ public: return "ERROR"; } - bool is_optional () const { return optional_flag; } - - std::string get_identifier () const { return identifier; } - - TraitItemType get_trait_item_type () const { return type; } - - HIR::TraitItem *get_hir_trait_item () const { return hir_trait_item; } + bool is_optional () const; - Location get_locus () const { return locus; } + std::string get_identifier () const; - const Analysis::NodeMapping get_mappings () const - { - return hir_trait_item->get_mappings (); - } + TraitItemType get_trait_item_type () const; - TyTy::BaseType *get_tyty () const - { - rust_assert (hir_trait_item != nullptr); + HIR::TraitItem *get_hir_trait_item () const; - switch (type) - { - case CONST: - return get_type_from_constant ( - static_cast (*hir_trait_item)); - break; + Location get_locus () const; - case TYPE: - return get_type_from_typealias ( - static_cast (*hir_trait_item)); + const Analysis::NodeMapping get_mappings () const; - case FN: - return get_type_from_fn ( - static_cast (*hir_trait_item)); - break; - - default: - return get_error (); - } - - gcc_unreachable (); - return get_error (); - } + TyTy::BaseType *get_tyty () const; Analysis::NodeMapping get_parent_trait_mappings () const; - // this is called when the trait is completed resolution and gives the items a - // chance to run their specific type resolution passes. If we call their + // this is called when the trait is completed resolution and gives the items + // a chance to run their specific type resolution passes. If we call their // resolution on construction it can lead to a case where the trait being // resolved recursively trying to resolve the trait itself infinitely since // the trait will not be stored in its own map yet @@ -144,10 +111,7 @@ public: bool is_object_safe () const; private: - TyTy::ErrorType *get_error () const - { - return new TyTy::ErrorType (get_mappings ().get_hirid ()); - } + TyTy::ErrorType *get_error () const; TyTy::BaseType *get_type_from_typealias (/*const*/ HIR::TraitItemType &type) const; @@ -182,39 +146,11 @@ public: TraitReference (const HIR::Trait *hir_trait_ref, std::vector item_refs, std::vector super_traits, - std::vector substs) - : hir_trait_ref (hir_trait_ref), item_refs (item_refs), - super_traits (super_traits) - { - trait_substs.clear (); - trait_substs.reserve (substs.size ()); - for (const auto &p : substs) - trait_substs.push_back (p.clone ()); - } - - TraitReference (TraitReference const &other) - : hir_trait_ref (other.hir_trait_ref), item_refs (other.item_refs), - super_traits (other.super_traits) - { - trait_substs.clear (); - trait_substs.reserve (other.trait_substs.size ()); - for (const auto &p : other.trait_substs) - trait_substs.push_back (p.clone ()); - } - - TraitReference &operator= (TraitReference const &other) - { - hir_trait_ref = other.hir_trait_ref; - item_refs = other.item_refs; - super_traits = other.super_traits; + std::vector substs); - trait_substs.clear (); - trait_substs.reserve (other.trait_substs.size ()); - for (const auto &p : other.trait_substs) - trait_substs.push_back (p.clone ()); + TraitReference (TraitReference const &other); - return *this; - } + TraitReference &operator= (TraitReference const &other); TraitReference (TraitReference &&other) = default; TraitReference &operator= (TraitReference &&other) = default; @@ -224,7 +160,7 @@ public: return TraitReference (nullptr, {}, {}, {}); } - bool is_error () const { return hir_trait_ref == nullptr; } + bool is_error () const; static TraitReference &error_node () { @@ -232,248 +168,63 @@ public: return trait_error_node; } - Location get_locus () const { return hir_trait_ref->get_locus (); } + Location get_locus () const; - std::string get_name () const - { - rust_assert (!is_error ()); - return hir_trait_ref->get_name (); - } + std::string get_name () const; - std::string as_string () const - { - if (is_error ()) - return ""; - - std::string item_buf; - for (auto &item : item_refs) - { - item_buf += item.as_string () + ", "; - } - return "HIR Trait: " + get_name () + "->" - + hir_trait_ref->get_mappings ().as_string () + " [" + item_buf - + "]"; - } + std::string as_string () const; - const HIR::Trait *get_hir_trait_ref () const { return hir_trait_ref; } + const HIR::Trait *get_hir_trait_ref () const; - const Analysis::NodeMapping &get_mappings () const - { - return hir_trait_ref->get_mappings (); - } + const Analysis::NodeMapping &get_mappings () const; - DefId get_defid () const { return get_mappings ().get_defid (); } + DefId get_defid () const; bool lookup_hir_trait_item (const HIR::TraitItem &item, - TraitItemReference **ref) - { - return lookup_trait_item (item.trait_identifier (), ref); - } + TraitItemReference **ref); - bool lookup_trait_item (const std::string &ident, TraitItemReference **ref) - { - for (auto &item : item_refs) - { - if (ident.compare (item.get_identifier ()) == 0) - { - *ref = &item; - return true; - } - } - return false; - } + bool lookup_trait_item (const std::string &ident, TraitItemReference **ref); bool lookup_trait_item_by_type (const std::string &ident, TraitItemReference::TraitItemType type, - TraitItemReference **ref) - { - for (auto &item : item_refs) - { - if (item.get_trait_item_type () != type) - continue; - - if (ident.compare (item.get_identifier ()) == 0) - { - *ref = &item; - return true; - } - } - return false; - } + TraitItemReference **ref); bool lookup_trait_item_by_type (const std::string &ident, TraitItemReference::TraitItemType type, - const TraitItemReference **ref) const - { - for (auto &item : item_refs) - { - if (item.get_trait_item_type () != type) - continue; - - if (ident.compare (item.get_identifier ()) == 0) - { - *ref = &item; - return true; - } - } - return false; - } + const TraitItemReference **ref) const; bool lookup_hir_trait_item (const HIR::TraitItem &item, - const TraitItemReference **ref) const - { - return lookup_trait_item (item.trait_identifier (), ref); - } + const TraitItemReference **ref) const; bool lookup_trait_item (const std::string &ident, - const TraitItemReference **ref) const - { - for (auto &item : item_refs) - { - if (ident.compare (item.get_identifier ()) == 0) - { - *ref = &item; - 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; - } + const TraitItemReference **ref) const; const TraitItemReference * lookup_trait_item (const std::string &ident, - TraitItemReference::TraitItemType type) const - { - for (auto &item : item_refs) - { - if (item.get_trait_item_type () != type) - continue; + TraitItemReference::TraitItemType type) const; - if (ident.compare (item.get_identifier ()) == 0) - return &item; - } + size_t size () const; - // 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 (); - } - - size_t size () const { return item_refs.size (); } - - const std::vector &get_trait_items () const - { - return item_refs; - } + const std::vector &get_trait_items () const; 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) - { - item.on_resolved (); - } - } - - void clear_associated_types () - { - for (auto &item : item_refs) - { - bool is_assoc_type = item.get_trait_item_type () - == TraitItemReference::TraitItemType::TYPE; - if (is_assoc_type) - item.associated_type_reset (); - } - } - - bool is_equal (const TraitReference &other) const - { - DefId this_id = get_mappings ().get_defid (); - DefId other_id = other.get_mappings ().get_defid (); - return this_id == other_id; - } - - const std::vector get_super_traits () const - { - return super_traits; - } - - bool is_object_safe (bool emit_error, Location locus) const - { - // https: // doc.rust-lang.org/reference/items/traits.html#object-safety - std::vector non_object_super_traits; - for (auto &item : super_traits) - { - if (!item->is_object_safe (false, Location ())) - non_object_super_traits.push_back (item); - } + std::vector &result) const; - std::vector non_object_safe_items; - for (auto &item : get_trait_items ()) - { - if (!item.is_object_safe ()) - non_object_safe_items.push_back (&item); - } + void on_resolved (); - bool is_safe - = non_object_super_traits.empty () && non_object_safe_items.empty (); - if (emit_error && !is_safe) - { - RichLocation r (locus); - for (auto &item : non_object_super_traits) - r.add_range (item->get_locus ()); - for (auto &item : non_object_safe_items) - r.add_range (item->get_locus ()); + void clear_associated_types (); - rust_error_at (r, "trait bound is not object safe"); - } + bool is_equal (const TraitReference &other) const; - return is_safe; - } + const std::vector get_super_traits () const; - bool trait_has_generics () const { return !trait_substs.empty (); } + bool is_object_safe (bool emit_error, Location locus) const; - std::vector get_trait_substs () const - { - return trait_substs; - } - - bool satisfies_bound (const TraitReference &reference) const - { - if (is_equal (reference)) - return true; + bool trait_has_generics () const; - for (const auto &super_trait : super_traits) - { - if (super_trait->satisfies_bound (reference)) - return true; - } + std::vector get_trait_substs () const; - return false; - } + bool satisfies_bound (const TraitReference &reference) const; private: const HIR::Trait *hir_trait_ref; @@ -487,16 +238,14 @@ class AssociatedImplTrait public: AssociatedImplTrait (TraitReference *trait, HIR::ImplBlock *impl, TyTy::BaseType *self, - Resolver::TypeCheckContext *context) - : trait (trait), impl (impl), self (self), context (context) - {} + Resolver::TypeCheckContext *context); - TraitReference *get_trait () { return trait; } + TraitReference *get_trait (); - HIR::ImplBlock *get_impl_block () { return impl; } + HIR::ImplBlock *get_impl_block (); - TyTy::BaseType *get_self () { return self; } - const TyTy::BaseType *get_self () const { return self; } + TyTy::BaseType *get_self (); + const TyTy::BaseType *get_self () const; TyTy::BaseType * setup_associated_types (const TyTy::BaseType *self, From patchwork Wed Apr 5 14:03: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: 79723 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp364877vqo; Wed, 5 Apr 2023 07:50:46 -0700 (PDT) X-Google-Smtp-Source: AKy350bDcelGkLvHjVjcAWui8bxTHV48UI6ApY8zdFrYteBxqSTvpIEluB8Q4KG5NW9EulP51ck/ X-Received: by 2002:a17:906:46c8:b0:932:c1e2:998b with SMTP id k8-20020a17090646c800b00932c1e2998bmr3482980ejs.15.1680706246633; Wed, 05 Apr 2023 07:50:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706246; cv=none; d=google.com; s=arc-20160816; b=cewxw21eG0t+B1tHEU3J51b8BbmEyu5+j3dXbwIqS22s6j813r1oBNVNkbwP8ftCde U3fH/HDf6KABDYjDIu4h7Ix32qVRpvyK5fTMoqRFCowLPHj36MB4vtVXWCZk57BTO0gT RlTVj5myeKV1f8MUJdhAB8AxKAVc1z96wCb40fq550grwg6Xp18djcfK2OGBS02nKzvW iuqVTTipiMgugB55UjkyQZJgmeYYwnRf16zywbXv6hf8lKIcYZIfVgGu5IeYwsBkqBkH H1gWNPmHt8iBy25upRXzgXiVNSertgmjMuVSBeZ7h83eCfZ52LP7xlwIZYeVvtn8ZCHV kYWw== 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=5/XmpcEFr4jFkR/ls+o1KaQHIyrs6HUKdSVEF7H+v54=; b=YhmG6ENIYdLUqV7+418TivlENtvaGyaahw4Wh+4eCR8R04ByX9ft+yTMUSST+cw2Vz QestzNm3Rt2Akg5As4fxPbYLd7m2PhnFYOy03hNxKoZcSo20V7PmeLgmZ1JSJKmozDBa f7WtTW4+auwlWpMEoxjH48CQiBGrCzAt2OStHD72PSeFQs6cg3tDsRZ/T14SR0QoiuvH BbgHGMtEaU/MHLcYLzFuvHnaqU3JNB8T/Nby+55LIXd7R9D5MnWeNwmf27xEDqRTh3FO dGJAwYrFn7UbH+zq2n10Nushurb6NJd5RkPs6wQGRwRhyHAg1SwHN8Evzb8lh5VdqG92 wRbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=g1ToCz1Y; 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 g12-20020a170906348c00b00933b668c967si1659060ejb.477.2023.04.05.07.50.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:50:46 -0700 (PDT) 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=g1ToCz1Y; 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 F10FD39AFFD0 for ; Wed, 5 Apr 2023 14:18:29 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id E8353385B516 for ; Wed, 5 Apr 2023 14:06:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E8353385B516 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-x335.google.com with SMTP id v20-20020a05600c471400b003ed8826253aso2319188wmo.0 for ; Wed, 05 Apr 2023 07:06:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703572; 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=5/XmpcEFr4jFkR/ls+o1KaQHIyrs6HUKdSVEF7H+v54=; b=g1ToCz1YEQbL9YINutZR6YdAf+EPWmhvyVv000MeD+fprtbjxANdvvok7xWRiSyw9C M2TrblKtN8t/pgZqxRnZfdpNdccpEvXuuxse0+4k50J4MPKS3y1sDEjzKf4PWTKf19B+ +AiDKQr8SnV5tMkOiAAUTuvYn5TZkNEK+ZQpRJRnZa9gjFDYrAiqxytOsjuq3zsNm5XA 3qAt47HhucXsfj3Mmx/1KnyMwnYYGxJPmIAfaWzD+MWQbTgxs+HrVkI4z+AgjXoNesw3 Q1vodf4AFHNi4BP/AfgN7eebtNhci2R+HqdBWweXj61I19bVUEJ1JgwyrQKvKQRvxT9z Bb9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703572; 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=5/XmpcEFr4jFkR/ls+o1KaQHIyrs6HUKdSVEF7H+v54=; b=1MZXnpgo8+GFpPth4dd7U5kZyW0BHSXb9n1cpqAJ/I5sf4S+dX8zcnK4HsM2T83M42 sr7b+GTp3JO578jqCId8XEhDTBkviSLXZdHGTHcUGFDPtNmTsingE9ibvSwhsV7k26hv HZpMrf2Ywf0WUwJk1GHbRqXPdoa0Pbr+Yww3WislnD989ss5YCiCS03NXmum8AhxvvUw qLf0wiQJRKYvLJ/7FaXKI6I4d9+YfnUw94NsnHiRabm+2P2ZYfL0k+aXZF7gw0/wVblw loidTrdd0Mc2g7gBmFaDVjJiPlDBL50fxWQjIlyh8m3sEEfNozuScaTFScMGmngn/tSx kM6Q== X-Gm-Message-State: AAQBX9dgjVn0O4QbZTmcAQvTaGs4XVwu54gMMlwdqyTW19Ia+jq2PaTc hbz8Iv25sv5d/FAT0eRHyLT/UdM9NCkvi2QzLQ== X-Received: by 2002:a7b:ce08:0:b0:3ef:d386:1a2b with SMTP id m8-20020a7bce08000000b003efd3861a2bmr4342265wmc.41.1680703572246; Wed, 05 Apr 2023 07:06:12 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:11 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [committed 63/88] gccrs: cli: Update safety warning message Date: Wed, 5 Apr 2023 16:03:47 +0200 Message-Id: <20230405140411.3016563-64-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?1762348232998520551?= X-GMAIL-MSGID: =?utf-8?q?1762348232998520551?= From: Pierre-Emmanuel Patry The compiler's warning message about the safety flag did not match cargo-gccrs environment variable name anymore. gcc/rust/ChangeLog: * rust-session-manager.cc (Session::compile_crate): Update the environment variable name. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/rust-session-manager.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc index 0f460e2d2f4..a086f83a3d0 100644 --- a/gcc/rust/rust-session-manager.cc +++ b/gcc/rust/rust-session-manager.cc @@ -441,7 +441,7 @@ Session::compile_crate (const char *filename) "defining the following environment variable (any value will " "do)\n\nGCCRS_INCOMPLETE_AND_EXPERIMENTAL_COMPILER_DO_NOT_USE\n\nFor " "cargo-gccrs, this means passing\n\n" - "GCCRS_EXTRA_FLAGS=\"-frust-incomplete-and-experimental-compiler-do-not-" + "GCCRS_EXTRA_ARGS=\"-frust-incomplete-and-experimental-compiler-do-not-" "use\"\n\nas an environment variable."); RAIIFile file_wrap (filename); From patchwork Wed Apr 5 14:03: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: 79724 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp365035vqo; Wed, 5 Apr 2023 07:51:01 -0700 (PDT) X-Google-Smtp-Source: AKy350anNtgS/1kjaOBJXzhhdHvwbIMRfs2psiU5e93zQ+qYXaAH1bRYJ/MJdGh9m8qyAszgpfcS X-Received: by 2002:aa7:cac9:0:b0:501:cde5:4cc9 with SMTP id l9-20020aa7cac9000000b00501cde54cc9mr1972093edt.39.1680706261569; Wed, 05 Apr 2023 07:51:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706261; cv=none; d=google.com; s=arc-20160816; b=ZyzKIqyYRKf8sidt9xt8eKLtkLem+vTWsFKXeovQQ/anPGh6WTkkS4zi9znYShlxcm 1gE78GGg6WUWbDxBUGUQEP3FIm2I+n2RsHX7GuyMnBm0OAbu9Og+LM9TwT2LHlt4v8w/ 61PlL5ny3zAPpWBZGaH6FucdUHz1zGieFrPmC7bBjTCFh8o5F4rY74/q+AUXsXLgg6fz JTLH3y+xbKf42j9v27vdsvrwncvjZ9gYXEJDfwqA/ByRvmmdZrzW4Qky4QvwcPa9tbUV 0uK56hzHJgYWDYjPNGp4XeZzaVyj4BpwyYgx2Go6i6JGx15DCeVVjA8w34lv4B+u5kuk 9cbA== 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=X48yogM7TqKNY+8VOo0lPEhYkPL70VLpTPjpfCGWwnc=; b=WUr3SmGa8DBUT49PPt4H5oJngEWYJkBC3hVFnsguNFrVxg1rtctdVPsW6ugvgpjhPK eA9bzbiX96kBynemy4mDFgZgoQPboqaDxViusxXIC/z83+kO+m2clvkGIDQacOWGHxX1 NTRkxy/ZmVFkE3Zp88Xyv4jATcQVzCmPCg7hlfv74WBW7cWRZPm49QZ3spUu2B6WbRJ6 XEsW/BJYTXBlzqX3EA0VesAZeedaBuhE54Y+sHeSsvnhd3YMPIqnCguLUiK4mDsh0fO8 QDjgw7WfSkmMsBQWOt2ZHUk774b/GtU3vvYQiTtc814gzaO1qNgQNUeRvw+brljXljYV 9IRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=beA4MmX9; 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 i26-20020aa7dd1a000000b004fce4843227si13524299edv.328.2023.04.05.07.51.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:51:01 -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=beA4MmX9; 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 AE4663932426 for ; Wed, 5 Apr 2023 14:18:36 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id A2AB03876894 for ; Wed, 5 Apr 2023 14:06:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A2AB03876894 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-x331.google.com with SMTP id l10-20020a05600c1d0a00b003f04bd3691eso7161184wms.5 for ; Wed, 05 Apr 2023 07:06:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703573; 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=X48yogM7TqKNY+8VOo0lPEhYkPL70VLpTPjpfCGWwnc=; b=beA4MmX9hbhPRK0vy+8PGvHWPc7nuo1cRRlGgQRI5nDsDyyVsKrm66tyXJvSA9xNfo gB19E9nBikAVe2Q8/FLedghGRdKy6LQbbyaLaDP8iRaUR9fo6wv8Hc6pjMDX7N6/U2hq W0ZlD8GdcQZhVF2CGHhq1M2UjW9LGMwoR7qDtjZ8wXOYVvExzf3yZr/LEuqI17mMPINa 5yb9S3iFrsyRxQdAPoTM5w+wQRJgRyoIHtsMhlscuLN8SCuqVSj1Zh07d0V1Lm/McpwK xBADo4v1BzthOi/IdQoUfxPFmGOfob9Yu87qa48L5AIq44RLYT6yx8vJ5vIb6ZQu1fv7 xizg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703573; 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=X48yogM7TqKNY+8VOo0lPEhYkPL70VLpTPjpfCGWwnc=; b=V9F9Gsj1QmUylYvwTmuI/KaNbsrm2X/DevkXUPO+kCrDGMsZYTqOrkuODAOh3/o1li r+ktWoR/uJSttydF27HurWJgnDk1B+DYNTbkJELGB9S7d1vfqesZtiKXwLJRiPpF6FRo 5uLTVeAjtLK5TNlIWQfaog/mSNK81jtbmiMyz6sfZF2/CoRyI6+7OU/hhQf2hJ777Wkk trbyxcuRs5L2qsW0eiSEKG4QuFFVuTBpr48zhWS/vyInRq/ZiPsReejvJ8XMVzQeKnJX y+znns8pPngA7wG/YWPwXEQP9fr5osR9iXfgYl8wh7whWwajKnh8YqXZKMY4+CtRylkK GRIQ== X-Gm-Message-State: AAQBX9cjgmL07hNCwMY8Sqdks3Swar3RRgNrE6RoUCi/SBeTKdjURHcl MW1FRpOpYbjgMIFJJCVc2K3ak6AFpAmo1I2v0Q== X-Received: by 2002:a7b:c7cd:0:b0:3df:e6bb:768 with SMTP id z13-20020a7bc7cd000000b003dfe6bb0768mr4708624wmk.24.1680703572842; Wed, 05 Apr 2023 07:06:12 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:12 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Thomas Schwinge Subject: [committed 64/88] gccrs: Update copyright years. Date: Wed, 5 Apr 2023 16:03:48 +0200 Message-Id: <20230405140411.3016563-65-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.6 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?1762348248906368645?= X-GMAIL-MSGID: =?utf-8?q?1762348248906368645?= From: Thomas Schwinge gcc/rust/ChangeLog: * ast/rust-ast-fragment.cc: Update copyright years. * ast/rust-ast-fragment.h: Likewise. * ast/rust-macro.cc: Likewise. * checks/errors/rust-feature-gate.cc: Likewise. * checks/errors/rust-feature-gate.h: Likewise. * checks/errors/rust-feature.cc: Likewise. * checks/errors/rust-feature.h: Likewise. * hir/rust-ast-lower-expr.cc: Likewise. * hir/rust-ast-lower-type.cc: Likewise. * resolve/rust-early-name-resolver.cc: Likewise. * resolve/rust-early-name-resolver.h: Likewise. * rust-gcc.h: Likewise. * typecheck/rust-hir-path-probe.cc: Likewise. * typecheck/rust-hir-trait-reference.cc: Likewise. * typecheck/rust-tyty-bounds.h: Likewise. * typecheck/rust-tyty-subst.cc: Likewise. * typecheck/rust-tyty-subst.h: Likewise. * typecheck/rust-tyty-util.cc: Likewise. * typecheck/rust-tyty-util.h: Likewise. * typecheck/rust-unify.cc: Likewise. * typecheck/rust-unify.h: Likewise. * util/rust-inline-visitor.h: Likewise. --- gcc/rust/ast/rust-ast-fragment.cc | 2 +- gcc/rust/ast/rust-ast-fragment.h | 2 +- gcc/rust/ast/rust-macro.cc | 2 +- gcc/rust/checks/errors/rust-feature-gate.cc | 2 +- gcc/rust/checks/errors/rust-feature-gate.h | 2 +- gcc/rust/checks/errors/rust-feature.cc | 2 +- gcc/rust/checks/errors/rust-feature.h | 2 +- gcc/rust/hir/rust-ast-lower-expr.cc | 2 +- gcc/rust/hir/rust-ast-lower-type.cc | 2 +- gcc/rust/resolve/rust-early-name-resolver.cc | 2 +- gcc/rust/resolve/rust-early-name-resolver.h | 2 +- gcc/rust/rust-gcc.h | 2 +- gcc/rust/typecheck/rust-hir-path-probe.cc | 2 +- gcc/rust/typecheck/rust-hir-trait-reference.cc | 2 +- gcc/rust/typecheck/rust-tyty-bounds.h | 2 +- gcc/rust/typecheck/rust-tyty-subst.cc | 2 +- gcc/rust/typecheck/rust-tyty-subst.h | 2 +- gcc/rust/typecheck/rust-tyty-util.cc | 2 +- gcc/rust/typecheck/rust-tyty-util.h | 2 +- gcc/rust/typecheck/rust-unify.cc | 2 +- gcc/rust/typecheck/rust-unify.h | 2 +- gcc/rust/util/rust-inline-visitor.h | 2 +- 22 files changed, 22 insertions(+), 22 deletions(-) diff --git a/gcc/rust/ast/rust-ast-fragment.cc b/gcc/rust/ast/rust-ast-fragment.cc index fba629c0119..a9dc4747d51 100644 --- a/gcc/rust/ast/rust-ast-fragment.cc +++ b/gcc/rust/ast/rust-ast-fragment.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2022 Free Software Foundation, Inc. +// Copyright (C) 2020-2023 Free Software Foundation, Inc. // This file is part of GCC. diff --git a/gcc/rust/ast/rust-ast-fragment.h b/gcc/rust/ast/rust-ast-fragment.h index 22e99090b25..41f5a287756 100644 --- a/gcc/rust/ast/rust-ast-fragment.h +++ b/gcc/rust/ast/rust-ast-fragment.h @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2022 Free Software Foundation, Inc. +// Copyright (C) 2020-2023 Free Software Foundation, Inc. // This file is part of GCC. diff --git a/gcc/rust/ast/rust-macro.cc b/gcc/rust/ast/rust-macro.cc index b90cc15898e..b6f8f6c059a 100644 --- a/gcc/rust/ast/rust-macro.cc +++ b/gcc/rust/ast/rust-macro.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2022 Free Software Foundation, Inc. +// Copyright (C) 2020-2023 Free Software Foundation, Inc. // This file is part of GCC. diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc b/gcc/rust/checks/errors/rust-feature-gate.cc index cd26f8a17f5..31ce3679ee1 100644 --- a/gcc/rust/checks/errors/rust-feature-gate.cc +++ b/gcc/rust/checks/errors/rust-feature-gate.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2022 Free Software Foundation, Inc. +// Copyright (C) 2020-2023 Free Software Foundation, Inc. // This file is part of GCC. diff --git a/gcc/rust/checks/errors/rust-feature-gate.h b/gcc/rust/checks/errors/rust-feature-gate.h index 080c15ccd23..dc95c6b3879 100644 --- a/gcc/rust/checks/errors/rust-feature-gate.h +++ b/gcc/rust/checks/errors/rust-feature-gate.h @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2022 Free Software Foundation, Inc. +// Copyright (C) 2020-2023 Free Software Foundation, Inc. // This file is part of GCC. diff --git a/gcc/rust/checks/errors/rust-feature.cc b/gcc/rust/checks/errors/rust-feature.cc index b87b4ca38ef..81689d9302b 100644 --- a/gcc/rust/checks/errors/rust-feature.cc +++ b/gcc/rust/checks/errors/rust-feature.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2022 Free Software Foundation, Inc. +// Copyright (C) 2020-2023 Free Software Foundation, Inc. // This file is part of GCC. diff --git a/gcc/rust/checks/errors/rust-feature.h b/gcc/rust/checks/errors/rust-feature.h index bf93b090af5..1425e26cd9a 100644 --- a/gcc/rust/checks/errors/rust-feature.h +++ b/gcc/rust/checks/errors/rust-feature.h @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2022 Free Software Foundation, Inc. +// Copyright (C) 2020-2023 Free Software Foundation, Inc. // This file is part of GCC. diff --git a/gcc/rust/hir/rust-ast-lower-expr.cc b/gcc/rust/hir/rust-ast-lower-expr.cc index df4ba9d2911..50c2eaeb0ff 100644 --- a/gcc/rust/hir/rust-ast-lower-expr.cc +++ b/gcc/rust/hir/rust-ast-lower-expr.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2022 Free Software Foundation, Inc. +// Copyright (C) 2020-2023 Free Software Foundation, Inc. // This file is part of GCC. diff --git a/gcc/rust/hir/rust-ast-lower-type.cc b/gcc/rust/hir/rust-ast-lower-type.cc index 92a14f4dacf..9ea22b01f32 100644 --- a/gcc/rust/hir/rust-ast-lower-type.cc +++ b/gcc/rust/hir/rust-ast-lower-type.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2022 Free Software Foundation, Inc. +// Copyright (C) 2020-2023 Free Software Foundation, Inc. // This file is part of GCC. diff --git a/gcc/rust/resolve/rust-early-name-resolver.cc b/gcc/rust/resolve/rust-early-name-resolver.cc index 60d6c8abc4d..5f11ae239bd 100644 --- a/gcc/rust/resolve/rust-early-name-resolver.cc +++ b/gcc/rust/resolve/rust-early-name-resolver.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2022 Free Software Foundation, Inc. +// Copyright (C) 2020-2023 Free Software Foundation, Inc. // This file is part of GCC. diff --git a/gcc/rust/resolve/rust-early-name-resolver.h b/gcc/rust/resolve/rust-early-name-resolver.h index c74c452ecaf..21b92e9b7a4 100644 --- a/gcc/rust/resolve/rust-early-name-resolver.h +++ b/gcc/rust/resolve/rust-early-name-resolver.h @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2022 Free Software Foundation, Inc. +// Copyright (C) 2020-2023 Free Software Foundation, Inc. // This file is part of GCC. diff --git a/gcc/rust/rust-gcc.h b/gcc/rust/rust-gcc.h index 085c16d0f3b..0db81949270 100644 --- a/gcc/rust/rust-gcc.h +++ b/gcc/rust/rust-gcc.h @@ -1,5 +1,5 @@ // rust-gcc.cc -- Rust frontend to gcc IR. -// Copyright (C) 2011-2022 Free Software Foundation, Inc. +// Copyright (C) 2011-2023 Free Software Foundation, Inc. // Contributed by Ian Lance Taylor, Google. // forked from gccgo diff --git a/gcc/rust/typecheck/rust-hir-path-probe.cc b/gcc/rust/typecheck/rust-hir-path-probe.cc index be89ceb8645..dae4c014d02 100644 --- a/gcc/rust/typecheck/rust-hir-path-probe.cc +++ b/gcc/rust/typecheck/rust-hir-path-probe.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2022 Free Software Foundation, Inc. +// Copyright (C) 2020-2023 Free Software Foundation, Inc. // This file is part of GCC. diff --git a/gcc/rust/typecheck/rust-hir-trait-reference.cc b/gcc/rust/typecheck/rust-hir-trait-reference.cc index 651c55abc82..8574988fb0b 100644 --- a/gcc/rust/typecheck/rust-hir-trait-reference.cc +++ b/gcc/rust/typecheck/rust-hir-trait-reference.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2022 Free Software Foundation, Inc. +// Copyright (C) 2020-2023 Free Software Foundation, Inc. // This file is part of GCC. diff --git a/gcc/rust/typecheck/rust-tyty-bounds.h b/gcc/rust/typecheck/rust-tyty-bounds.h index 44839bd0b40..624048022ee 100644 --- a/gcc/rust/typecheck/rust-tyty-bounds.h +++ b/gcc/rust/typecheck/rust-tyty-bounds.h @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2022 Free Software Foundation, Inc. +// Copyright (C) 2020-2023 Free Software Foundation, Inc. // This file is part of GCC. diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc b/gcc/rust/typecheck/rust-tyty-subst.cc index 3dfe95873bc..e4fe30e00ea 100644 --- a/gcc/rust/typecheck/rust-tyty-subst.cc +++ b/gcc/rust/typecheck/rust-tyty-subst.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2022 Free Software Foundation, Inc. +// Copyright (C) 2020-2023 Free Software Foundation, Inc. // This file is part of GCC. diff --git a/gcc/rust/typecheck/rust-tyty-subst.h b/gcc/rust/typecheck/rust-tyty-subst.h index 982861e9bc6..fd5826102b3 100644 --- a/gcc/rust/typecheck/rust-tyty-subst.h +++ b/gcc/rust/typecheck/rust-tyty-subst.h @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2022 Free Software Foundation, Inc. +// Copyright (C) 2020-2023 Free Software Foundation, Inc. // This file is part of GCC. diff --git a/gcc/rust/typecheck/rust-tyty-util.cc b/gcc/rust/typecheck/rust-tyty-util.cc index 5037f68cb3f..32b94f04511 100644 --- a/gcc/rust/typecheck/rust-tyty-util.cc +++ b/gcc/rust/typecheck/rust-tyty-util.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2022 Free Software Foundation, Inc. +// Copyright (C) 2020-2023 Free Software Foundation, Inc. // This file is part of GCC. diff --git a/gcc/rust/typecheck/rust-tyty-util.h b/gcc/rust/typecheck/rust-tyty-util.h index eccbb4423d5..6b28379345f 100644 --- a/gcc/rust/typecheck/rust-tyty-util.h +++ b/gcc/rust/typecheck/rust-tyty-util.h @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2022 Free Software Foundation, Inc. +// Copyright (C) 2020-2023 Free Software Foundation, Inc. // This file is part of GCC. diff --git a/gcc/rust/typecheck/rust-unify.cc b/gcc/rust/typecheck/rust-unify.cc index 415ffcdc6ea..cbbff8c4420 100644 --- a/gcc/rust/typecheck/rust-unify.cc +++ b/gcc/rust/typecheck/rust-unify.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2022 Free Software Foundation, Inc. +// Copyright (C) 2020-2023 Free Software Foundation, Inc. // This file is part of GCC. diff --git a/gcc/rust/typecheck/rust-unify.h b/gcc/rust/typecheck/rust-unify.h index 6e46b9642a6..75fb884385e 100644 --- a/gcc/rust/typecheck/rust-unify.h +++ b/gcc/rust/typecheck/rust-unify.h @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2022 Free Software Foundation, Inc. +// Copyright (C) 2020-2023 Free Software Foundation, Inc. // This file is part of GCC. diff --git a/gcc/rust/util/rust-inline-visitor.h b/gcc/rust/util/rust-inline-visitor.h index 105a67b8c5c..9240627b354 100644 --- a/gcc/rust/util/rust-inline-visitor.h +++ b/gcc/rust/util/rust-inline-visitor.h @@ -1,4 +1,4 @@ -// Copyright (C) 2021-2022 Free Software Foundation, Inc. +// Copyright (C) 2021-2023 Free Software Foundation, Inc. // This file is part of GCC. From patchwork Wed Apr 5 14:03:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 79725 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp365829vqo; Wed, 5 Apr 2023 07:52:22 -0700 (PDT) X-Google-Smtp-Source: AKy350bFeEKwN8bX/F/Sb/pc0EI86j7v6b//yCEjHrkarkxTG9PTlhGP+mzRwvoNtAv4HW3nN6HZ X-Received: by 2002:a05:6402:442:b0:501:dc02:1956 with SMTP id p2-20020a056402044200b00501dc021956mr2122632edw.29.1680706341989; Wed, 05 Apr 2023 07:52:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706341; cv=none; d=google.com; s=arc-20160816; b=MrFeC93HFSmL0D8/lGS1OqGCfc3llBgmvDRuzxwIUFgmN/Y0nYKU8HNn/MMgdAZeXZ F4zsYTDYwOboQNQR2XYTgsTbqhcMZKHhNGYEwgwvqXMEm+R8e70hwGUB4XOj1ZmqfB0C cPqJZD4ylgY1YdiIUp61DMGDsB8Tg/ltHqRvKTNRt1nCm5wui9kejvPPd17ZZRH3F+IO pdsprl/n7e6HiEV1GChe/X2lAR2VTOR9kekIb/qE7AwpMICUwgCQmru/D3b36+4YZHLw ali8L7257ieCKkc5F5A9CQIK/WBU8qBmhQK8laE3mK9foi+NhkV2h56pwVtCZDKwae0q ZogQ== 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=LPBWNpCpv+85wCt5oQoD8EZthjcKjmhIHvBdxXmvHsg=; b=j2dVDDpTAw//xhuc/eIjb+WePAgauPX8spTCIu4hGXJNezMlPbUEUtQ9hLM0UGDHRA HKAjTJs0sUBUyYMk3TCKv3E2tV7oyF9OnRa2NHjiOgc310PvVEOdXLR0e6Knsh79xyqC WwuP2UC75WP9R1yE43sNi02A2dAoxQl1F5B0cQ6FBBUNfsvQH7uZOhyEIRKItmmOC9Vo IHn6iBmlVLbf8u8pbDfWctfJJ2nvjQbcgyUfi+BHzAAp4Dr7Hl3UdyNqencfBTA1Zfhe wqQkaT/7nCCp7J08/MuwESQVX5kKbrnds2ZHUkR+G8gAabBOeq/mGNgZwdmi448YAY9b Xvgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=E47mG3K0; 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 n11-20020aa7c44b000000b0050229538ebcsi989111edr.509.2023.04.05.07.52.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:52:21 -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=E47mG3K0; 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 348BA392E47F for ; Wed, 5 Apr 2023 14:19:14 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id E6A75385695E for ; Wed, 5 Apr 2023 14:06:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E6A75385695E 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-x331.google.com with SMTP id i5-20020a05600c354500b003edd24054e0so23810801wmq.4 for ; Wed, 05 Apr 2023 07:06:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703574; 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=LPBWNpCpv+85wCt5oQoD8EZthjcKjmhIHvBdxXmvHsg=; b=E47mG3K0WSO0hALwtUbtjJ7hX/CDyDXLef90+m2IYc1qTAvmf6g5yjWmWMjI1yAVKa aArp6pUHfO3kvi+A9+807GxjJtQculAVp+h1105sajNnc8sTfTmXS0f1BkQaOLP6vbAw il22+TdeJ/gJYqSTJwb8n2QVW1vbWZ+N3nr+DCIi6ahsVLkp4vZmKYDNniTsx51OB0gC EhQObCSaCv7rGLRSVRxraVvjnviZ3KF8S1m4XWWh9NDBF44QZCSEgHzuIj2RfVnXE5Q5 uBsRXKXt4DqHKou75zo25R94S/MjMSzWpC25ysNRnTJhYjmhZSP2cBd5wRXsMI359yuO 3gSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703574; 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=LPBWNpCpv+85wCt5oQoD8EZthjcKjmhIHvBdxXmvHsg=; b=6J0tTYYY7Q7J6eWAPhp9F0G4cFuu+x749mO0+DbcXkATKLFz7uuive18bUubr1kNLc +vgFHWz696XljNiVxo5SRvea2AaEC4uig3U+PZ2ZgNizLpxgEcV7RnWjZ3bU92T6MwPc uSWIqQ54jyEFeU0gHyQA0uBO2drdo7ZceeC/gn9GB0ZkQJwPXC1siiPg5/wiQOsCmi0g mMTrh+AcrBTT1iRnFzuAgo1oESo0WNv/79tbsczue6TMTf7T6MteqCmhi9OOFFeC09eU 6jYd3PNgprVSGV21LfREh/43vKLDpLTYRp4ZIbepGeRNntdxi7kmgOwiQ8/2tNKz5z/A 7aeA== X-Gm-Message-State: AAQBX9ecexH6+OjbmWkxBxNQ8+TqMUiIBtjTmkCYhCmHLzJ/vIebO8zg 11+X7HNBIJMJfrbC+XIduYQk8v5CiINCznmAvg== X-Received: by 2002:a05:600c:212:b0:3f0:4428:9445 with SMTP id 18-20020a05600c021200b003f044289445mr4997101wmi.14.1680703573851; Wed, 05 Apr 2023 07:06:13 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:13 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, mxlol233 Subject: [committed 65/88] gccrs: Add feature gate for "rust-intrinsic". Date: Wed, 5 Apr 2023 16:03:49 +0200 Message-Id: <20230405140411.3016563-66-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.5 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?1762348333448348131?= X-GMAIL-MSGID: =?utf-8?q?1762348333448348131?= From: mxlol233 This commit implemented a feature gate to check `intrinsics`. gcc/rust/ChangeLog: * checks/errors/rust-feature-gate.cc: Add implementation for `void FeatureGate::visit (AST::ExternBlock &block)`. Add `valid_feature` construction process in `FeatureGate::check`. * checks/errors/rust-feature-gate.h: Add declaration for `void FeatureGate::visit (AST::ExternBlock &block)`. Add private variable `valid_feature`. * checks/errors/rust-feature.h: Change `issue` to `m_issue`. gcc/testsuite/ChangeLog: * rust/compile/const-issue1440.rs: Add crate feature: `intrinsics`. * rust/compile/feature_intrinsics.rs: New file. * rust/compile/issue-1031.rs: Add crate feature: `intrinsics`. * rust/compile/issue-1130.rs: Add crate feature: `intrinsics`. * rust/compile/issue-1131.rs: Add crate feature: `intrinsics`. * rust/compile/issue-1237.rs: Add crate feature: `intrinsics`. * rust/compile/issue-1289.rs: Add crate feature: `intrinsics`. * rust/compile/rust-const-blog-issue.rs: Add crate feature: `intrinsics`. * rust/compile/torture/intrinsics-3.rs: Add crate feature: `intrinsics`. * rust/compile/torture/intrinsics-4.rs: Add crate feature: `intrinsics`. * rust/compile/torture/intrinsics-5.rs: Add crate feature: `intrinsics`. * rust/compile/torture/intrinsics-6.rs: Add crate feature: `intrinsics`. * rust/compile/torture/intrinsics-7.rs: Add crate feature: `intrinsics`. * rust/compile/torture/issue-1024.rs: Add crate feature: `intrinsics`. * rust/compile/torture/issue-1075.rs: Add crate feature: `intrinsics`. * rust/compile/torture/issue-1432.rs: Add crate feature: `intrinsics`. * rust/compile/unsafe10.rs: Add crate feature: `intrinsics`. * rust/execute/torture/atomic_load.rs: Add crate feature: `intrinsics`. * rust/execute/torture/atomic_store.rs: Add crate feature: `intrinsics`. * rust/execute/torture/copy_nonoverlapping1.rs: Add crate feature: `intrinsics`. * rust/execute/torture/issue-1120.rs: Add crate feature: `intrinsics`. * rust/execute/torture/issue-1133.rs: Add crate feature: `intrinsics`. * rust/execute/torture/issue-1232.rs: Add crate feature: `intrinsics`. * rust/execute/torture/slice-magic.rs: Add crate feature: `intrinsics`. * rust/execute/torture/slice-magic2.rs: Add crate feature: `intrinsics`. * rust/execute/torture/str-layout1.rs: Add crate feature: `intrinsics`. * rust/execute/torture/transmute1.rs: Add crate feature: `intrinsics`. * rust/execute/torture/wrapping_op1.rs: Add crate feature: `intrinsics`. * rust/execute/torture/wrapping_op2.rs: Add crate feature: `intrinsics`. Signed-off-by: Xiao Ma --- gcc/rust/checks/errors/rust-feature-gate.cc | 61 ++++++++++++++++--- gcc/rust/checks/errors/rust-feature-gate.h | 7 ++- gcc/rust/checks/errors/rust-feature.h | 5 +- gcc/testsuite/rust/compile/const-issue1440.rs | 1 + .../rust/compile/feature_intrinsics.rs | 7 +++ gcc/testsuite/rust/compile/issue-1031.rs | 2 + gcc/testsuite/rust/compile/issue-1130.rs | 2 + gcc/testsuite/rust/compile/issue-1131.rs | 2 + gcc/testsuite/rust/compile/issue-1237.rs | 2 + gcc/testsuite/rust/compile/issue-1289.rs | 2 + .../rust/compile/rust-const-blog-issue.rs | 2 + .../rust/compile/torture/intrinsics-3.rs | 2 + .../rust/compile/torture/intrinsics-4.rs | 2 + .../rust/compile/torture/intrinsics-5.rs | 2 + .../rust/compile/torture/intrinsics-6.rs | 2 + .../rust/compile/torture/intrinsics-7.rs | 2 + .../rust/compile/torture/issue-1024.rs | 2 + .../rust/compile/torture/issue-1075.rs | 2 + .../rust/compile/torture/issue-1432.rs | 1 + gcc/testsuite/rust/compile/unsafe10.rs | 2 + .../rust/execute/torture/atomic_load.rs | 2 + .../rust/execute/torture/atomic_store.rs | 2 + .../execute/torture/copy_nonoverlapping1.rs | 2 + .../rust/execute/torture/issue-1120.rs | 2 + .../rust/execute/torture/issue-1133.rs | 2 + .../rust/execute/torture/issue-1232.rs | 2 + .../rust/execute/torture/slice-magic.rs | 2 + .../rust/execute/torture/slice-magic2.rs | 2 + .../rust/execute/torture/str-layout1.rs | 2 + .../rust/execute/torture/transmute1.rs | 1 + .../rust/execute/torture/wrapping_op1.rs | 2 + .../rust/execute/torture/wrapping_op2.rs | 2 + 32 files changed, 122 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/rust/compile/feature_intrinsics.rs diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc b/gcc/rust/checks/errors/rust-feature-gate.cc index 31ce3679ee1..bd01b52c7ff 100644 --- a/gcc/rust/checks/errors/rust-feature-gate.cc +++ b/gcc/rust/checks/errors/rust-feature-gate.cc @@ -17,14 +17,15 @@ // . #include "rust-feature-gate.h" -#include "rust-feature.h" +#include "rust-abi.h" namespace Rust { void FeatureGate::check (AST::Crate &crate) { - std::vector valid_features; + valid_features.clear (); + for (const auto &attr : crate.inner_attrs) { if (attr.get_path ().as_string () == "feature") @@ -39,20 +40,22 @@ FeatureGate::check (AST::Crate &crate) option.parse_to_meta_item ()); for (const auto &item : meta_item->get_items ()) { - const auto &name = item->as_string (); - auto tname = Feature::as_name (name); + const auto &name_str = item->as_string (); + auto tname = Feature::as_name (name_str); if (!tname.is_none ()) - valid_features.push_back (Feature::create (tname.get ())); + { + auto name = tname.get (); + valid_features.insert (name); + } + else rust_error_at (item->get_locus (), "unknown feature '%s'", - name.c_str ()); + name_str.c_str ()); } } } } - valid_features.shrink_to_fit (); - // TODO (mxlol233): add the real feature gate stuff. auto &items = crate.items; for (auto it = items.begin (); it != items.end (); it++) { @@ -60,4 +63,46 @@ FeatureGate::check (AST::Crate &crate) item->accept_vis (*this); } } + +void +FeatureGate::gate (Feature::Name name, Location loc, + const std::string &error_msg) +{ + if (!valid_features.count (name)) + { + auto feature = Feature::create (name); + auto issue = feature.issue (); + if (issue > 0) + { + const char *fmt_str + = "%s. see issue %ld " + " for more " + "information. add `#![feature(%s)]` to the crate attributes to " + "enable."; + rust_error_at (loc, fmt_str, error_msg.c_str (), issue, issue, + feature.as_string ().c_str ()); + } + else + { + const char *fmt_str + = "%s. add `#![feature(%s)]` to the crate attributes to enable."; + rust_error_at (loc, fmt_str, error_msg.c_str (), + feature.as_string ().c_str ()); + } + } +} + +void +FeatureGate::visit (AST::ExternBlock &block) +{ + if (block.has_abi ()) + { + const auto abi = block.get_abi (); + + if (get_abi_from_string (abi) == ABI::INTRINSIC) + gate (Feature::Name::INTRINSICS, block.get_locus (), + "intrinsics are subject to change"); + } +} + } // namespace Rust \ No newline at end of file diff --git a/gcc/rust/checks/errors/rust-feature-gate.h b/gcc/rust/checks/errors/rust-feature-gate.h index dc95c6b3879..6768c4c2498 100644 --- a/gcc/rust/checks/errors/rust-feature-gate.h +++ b/gcc/rust/checks/errors/rust-feature-gate.h @@ -21,6 +21,7 @@ #include "rust-ast-visitor.h" #include "rust-ast-full.h" +#include "rust-feature.h" namespace Rust { @@ -136,7 +137,7 @@ public: void visit (AST::TraitImpl &impl) override {} void visit (AST::ExternalStaticItem &item) override {} void visit (AST::ExternalFunctionItem &item) override {} - void visit (AST::ExternBlock &block) override {} + void visit (AST::ExternBlock &block) override; void visit (AST::MacroMatchFragment &match) override {} void visit (AST::MacroMatchRepetition &match) override {} void visit (AST::MacroMatcher &matcher) override {} @@ -186,6 +187,10 @@ public: void visit (AST::SliceType &type) override {} void visit (AST::InferredType &type) override {} void visit (AST::BareFunctionType &type) override {} + +private: + void gate (Feature::Name name, Location loc, const std::string &error_msg); + std::set valid_features; }; } // namespace Rust #endif \ No newline at end of file diff --git a/gcc/rust/checks/errors/rust-feature.h b/gcc/rust/checks/errors/rust-feature.h index 1425e26cd9a..7bd76c093f2 100644 --- a/gcc/rust/checks/errors/rust-feature.h +++ b/gcc/rust/checks/errors/rust-feature.h @@ -47,6 +47,7 @@ public: Name name () { return m_name; } const std::string &description () { return m_description; } State state () { return m_state; } + uint64_t issue () { return m_issue; } static Optional as_name (const std::string &name); static Feature create (Name name); @@ -57,7 +58,7 @@ private: const Optional &edition, const char *description) : m_state (state), m_name (name), m_name_str (name_str), - m_rustc_since (rustc_since), issue (issue_number), edition (edition), + m_rustc_since (rustc_since), m_issue (issue_number), edition (edition), m_description (description) {} @@ -65,7 +66,7 @@ private: Name m_name; std::string m_name_str; std::string m_rustc_since; - uint64_t issue; + uint64_t m_issue; Optional edition; std::string m_description; diff --git a/gcc/testsuite/rust/compile/const-issue1440.rs b/gcc/testsuite/rust/compile/const-issue1440.rs index 9b974b96bbb..9ad76a96b2a 100644 --- a/gcc/testsuite/rust/compile/const-issue1440.rs +++ b/gcc/testsuite/rust/compile/const-issue1440.rs @@ -1,4 +1,5 @@ // { dg-additional-options "-w" } +#![feature(intrinsics)] mod intrinsics { extern "rust-intrinsic" { diff --git a/gcc/testsuite/rust/compile/feature_intrinsics.rs b/gcc/testsuite/rust/compile/feature_intrinsics.rs new file mode 100644 index 00000000000..5eb7ffed864 --- /dev/null +++ b/gcc/testsuite/rust/compile/feature_intrinsics.rs @@ -0,0 +1,7 @@ + +extern "rust-intrinsic" { //{ dg-error "intrinsics are subject to change." "" { target *-*-* } } + pub fn sqrtf32(x: f32) -> f32; +} + +fn main() { +} diff --git a/gcc/testsuite/rust/compile/issue-1031.rs b/gcc/testsuite/rust/compile/issue-1031.rs index 5ba8f7a267b..a9049de96fb 100644 --- a/gcc/testsuite/rust/compile/issue-1031.rs +++ b/gcc/testsuite/rust/compile/issue-1031.rs @@ -1,3 +1,5 @@ +#![feature(intrinsics)] + extern "rust-intrinsic" { #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")] pub fn offset(dst: *const T, offset: isize) -> *const T; diff --git a/gcc/testsuite/rust/compile/issue-1130.rs b/gcc/testsuite/rust/compile/issue-1130.rs index 92200c7cd5f..6d265cb6044 100644 --- a/gcc/testsuite/rust/compile/issue-1130.rs +++ b/gcc/testsuite/rust/compile/issue-1130.rs @@ -1,4 +1,6 @@ // { dg-additional-options "-w" } +#![feature(intrinsics)] + mod mem { extern "rust-intrinsic" { fn size_of() -> usize; diff --git a/gcc/testsuite/rust/compile/issue-1131.rs b/gcc/testsuite/rust/compile/issue-1131.rs index fd158abc700..5cb9caf81f0 100644 --- a/gcc/testsuite/rust/compile/issue-1131.rs +++ b/gcc/testsuite/rust/compile/issue-1131.rs @@ -1,3 +1,5 @@ +#![feature(intrinsics)] + extern "rust-intrinsic" { fn size_of() -> usize; fn offset(dst: *const T, offset: isize) -> *const T; diff --git a/gcc/testsuite/rust/compile/issue-1237.rs b/gcc/testsuite/rust/compile/issue-1237.rs index 542be897949..54a51df156f 100644 --- a/gcc/testsuite/rust/compile/issue-1237.rs +++ b/gcc/testsuite/rust/compile/issue-1237.rs @@ -1,4 +1,6 @@ // { dg-additional-options "-w" } +#![feature(intrinsics)] + mod intrinsics { extern "rust-intrinsic" { pub fn offset(ptr: *const T, count: isize) -> *const T; diff --git a/gcc/testsuite/rust/compile/issue-1289.rs b/gcc/testsuite/rust/compile/issue-1289.rs index eb41af0a75b..3d7716a1d8c 100644 --- a/gcc/testsuite/rust/compile/issue-1289.rs +++ b/gcc/testsuite/rust/compile/issue-1289.rs @@ -1,3 +1,5 @@ +#![feature(intrinsics)] + extern "C" { fn printf(s: *const i8, ...); } diff --git a/gcc/testsuite/rust/compile/rust-const-blog-issue.rs b/gcc/testsuite/rust/compile/rust-const-blog-issue.rs index a5ea2ebacb9..679a2ae8c2b 100644 --- a/gcc/testsuite/rust/compile/rust-const-blog-issue.rs +++ b/gcc/testsuite/rust/compile/rust-const-blog-issue.rs @@ -1,4 +1,6 @@ // { dg-excess-errors "accessing value of" } +#![feature(intrinsics)] + mod mem { extern "rust-intrinsic" { #[rustc_const_stable(feature = "const_transmute", since = "1.46.0")] diff --git a/gcc/testsuite/rust/compile/torture/intrinsics-3.rs b/gcc/testsuite/rust/compile/torture/intrinsics-3.rs index 5c131bd8aa2..1601ab6d5b7 100644 --- a/gcc/testsuite/rust/compile/torture/intrinsics-3.rs +++ b/gcc/testsuite/rust/compile/torture/intrinsics-3.rs @@ -1,3 +1,5 @@ +#![feature(intrinsics)] + extern "rust-intrinsic" { fn not_an_intrinsic(); } diff --git a/gcc/testsuite/rust/compile/torture/intrinsics-4.rs b/gcc/testsuite/rust/compile/torture/intrinsics-4.rs index 4e09f1089b0..1f6c0d6608a 100644 --- a/gcc/testsuite/rust/compile/torture/intrinsics-4.rs +++ b/gcc/testsuite/rust/compile/torture/intrinsics-4.rs @@ -1,3 +1,5 @@ +#![feature(intrinsics)] + #[lang = "sized"] pub trait Sized {} diff --git a/gcc/testsuite/rust/compile/torture/intrinsics-5.rs b/gcc/testsuite/rust/compile/torture/intrinsics-5.rs index ffad0bd3a85..7a62cca280c 100644 --- a/gcc/testsuite/rust/compile/torture/intrinsics-5.rs +++ b/gcc/testsuite/rust/compile/torture/intrinsics-5.rs @@ -1,3 +1,5 @@ +#![feature(intrinsics)] + #[lang = "sized"] pub trait Sized {} diff --git a/gcc/testsuite/rust/compile/torture/intrinsics-6.rs b/gcc/testsuite/rust/compile/torture/intrinsics-6.rs index 143b62a2b27..4e510e11087 100644 --- a/gcc/testsuite/rust/compile/torture/intrinsics-6.rs +++ b/gcc/testsuite/rust/compile/torture/intrinsics-6.rs @@ -1,3 +1,5 @@ +#![feature(intrinsics)] + extern "rust-intrinsic" { pub fn unchecked_add(x: T, y: T) -> T; pub fn unchecked_sub(x: T, y: T) -> T; diff --git a/gcc/testsuite/rust/compile/torture/intrinsics-7.rs b/gcc/testsuite/rust/compile/torture/intrinsics-7.rs index 8e8c5fe0cdf..da85fff5cd6 100644 --- a/gcc/testsuite/rust/compile/torture/intrinsics-7.rs +++ b/gcc/testsuite/rust/compile/torture/intrinsics-7.rs @@ -1,3 +1,5 @@ +#![feature(intrinsics)] + 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 } diff --git a/gcc/testsuite/rust/compile/torture/issue-1024.rs b/gcc/testsuite/rust/compile/torture/issue-1024.rs index 109540934a8..a8503cebf53 100644 --- a/gcc/testsuite/rust/compile/torture/issue-1024.rs +++ b/gcc/testsuite/rust/compile/torture/issue-1024.rs @@ -1,3 +1,5 @@ +#![feature(intrinsics)] + extern "rust-intrinsic" { pub fn size_of() -> usize; } diff --git a/gcc/testsuite/rust/compile/torture/issue-1075.rs b/gcc/testsuite/rust/compile/torture/issue-1075.rs index 7c0a0434262..201a241d45d 100644 --- a/gcc/testsuite/rust/compile/torture/issue-1075.rs +++ b/gcc/testsuite/rust/compile/torture/issue-1075.rs @@ -1,4 +1,6 @@ // { dg-additional-options "-w" } +#![feature(intrinsics)] + extern "rust-intrinsic" { #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")] pub fn offset(dst: *const T, offset: isize) -> *const T; diff --git a/gcc/testsuite/rust/compile/torture/issue-1432.rs b/gcc/testsuite/rust/compile/torture/issue-1432.rs index 083a369d16f..822ca41c5ad 100644 --- a/gcc/testsuite/rust/compile/torture/issue-1432.rs +++ b/gcc/testsuite/rust/compile/torture/issue-1432.rs @@ -1,4 +1,5 @@ // { dg-additional-options "-w" } +#![feature(intrinsics)] mod intrinsics { extern "rust-intrinsic" { #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")] diff --git a/gcc/testsuite/rust/compile/unsafe10.rs b/gcc/testsuite/rust/compile/unsafe10.rs index 6b6be06b908..927e69728c9 100644 --- a/gcc/testsuite/rust/compile/unsafe10.rs +++ b/gcc/testsuite/rust/compile/unsafe10.rs @@ -1,3 +1,5 @@ +#![feature(intrinsics)] + extern "rust-intrinsic" { pub fn rotate_left(l: T, r: T) -> T; } diff --git a/gcc/testsuite/rust/execute/torture/atomic_load.rs b/gcc/testsuite/rust/execute/torture/atomic_load.rs index 6e7383aa7e9..b66c4641424 100644 --- a/gcc/testsuite/rust/execute/torture/atomic_load.rs +++ b/gcc/testsuite/rust/execute/torture/atomic_load.rs @@ -1,3 +1,5 @@ +#![feature(intrinsics)] + #[lang = "sized"] pub trait Sized {} diff --git a/gcc/testsuite/rust/execute/torture/atomic_store.rs b/gcc/testsuite/rust/execute/torture/atomic_store.rs index 46960a7a186..dcbb2a90f19 100644 --- a/gcc/testsuite/rust/execute/torture/atomic_store.rs +++ b/gcc/testsuite/rust/execute/torture/atomic_store.rs @@ -1,3 +1,5 @@ +#![feature(intrinsics)] + #[lang = "sized"] pub trait Sized {} diff --git a/gcc/testsuite/rust/execute/torture/copy_nonoverlapping1.rs b/gcc/testsuite/rust/execute/torture/copy_nonoverlapping1.rs index 2ae7a0869e3..39afd3424a4 100644 --- a/gcc/testsuite/rust/execute/torture/copy_nonoverlapping1.rs +++ b/gcc/testsuite/rust/execute/torture/copy_nonoverlapping1.rs @@ -1,3 +1,5 @@ +#![feature(intrinsics)] + extern "rust-intrinsic" { pub fn copy_nonoverlapping(src: *const T, dst: *mut T, count: usize); } diff --git a/gcc/testsuite/rust/execute/torture/issue-1120.rs b/gcc/testsuite/rust/execute/torture/issue-1120.rs index 242c94b5cb6..59792b29a29 100644 --- a/gcc/testsuite/rust/execute/torture/issue-1120.rs +++ b/gcc/testsuite/rust/execute/torture/issue-1120.rs @@ -1,4 +1,6 @@ // { dg-additional-options "-w" } +#![feature(intrinsics)] + extern "rust-intrinsic" { #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")] pub fn offset(dst: *const T, offset: isize) -> *const T; diff --git a/gcc/testsuite/rust/execute/torture/issue-1133.rs b/gcc/testsuite/rust/execute/torture/issue-1133.rs index f2080a6e072..8679bb93224 100644 --- a/gcc/testsuite/rust/execute/torture/issue-1133.rs +++ b/gcc/testsuite/rust/execute/torture/issue-1133.rs @@ -1,4 +1,6 @@ // { dg-additional-options "-w" } +#![feature(intrinsics)] + extern "rust-intrinsic" { #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")] pub fn offset(dst: *const T, offset: isize) -> *const T; diff --git a/gcc/testsuite/rust/execute/torture/issue-1232.rs b/gcc/testsuite/rust/execute/torture/issue-1232.rs index 9215efdba6c..ce53da2d033 100644 --- a/gcc/testsuite/rust/execute/torture/issue-1232.rs +++ b/gcc/testsuite/rust/execute/torture/issue-1232.rs @@ -1,5 +1,7 @@ // { dg-additional-options "-w" } // { dg-output "slice_access=3\r*\n" } +#![feature(intrinsics)] + extern "rust-intrinsic" { #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")] fn offset(dst: *const T, offset: isize) -> *const T; diff --git a/gcc/testsuite/rust/execute/torture/slice-magic.rs b/gcc/testsuite/rust/execute/torture/slice-magic.rs index d1132989ddb..b52aa3df510 100644 --- a/gcc/testsuite/rust/execute/torture/slice-magic.rs +++ b/gcc/testsuite/rust/execute/torture/slice-magic.rs @@ -1,4 +1,6 @@ // { dg-additional-options "-w" } +#![feature(intrinsics)] + extern "rust-intrinsic" { #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")] pub fn offset(dst: *const T, offset: isize) -> *const T; diff --git a/gcc/testsuite/rust/execute/torture/slice-magic2.rs b/gcc/testsuite/rust/execute/torture/slice-magic2.rs index 64a566185fa..cdc39f3dcca 100644 --- a/gcc/testsuite/rust/execute/torture/slice-magic2.rs +++ b/gcc/testsuite/rust/execute/torture/slice-magic2.rs @@ -1,4 +1,6 @@ // { dg-additional-options "-w" } +#![feature(intrinsics)] + extern "rust-intrinsic" { #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")] pub fn offset(dst: *const T, offset: isize) -> *const T; diff --git a/gcc/testsuite/rust/execute/torture/str-layout1.rs b/gcc/testsuite/rust/execute/torture/str-layout1.rs index 39c1e38d77b..c9bcf1631e2 100644 --- a/gcc/testsuite/rust/execute/torture/str-layout1.rs +++ b/gcc/testsuite/rust/execute/torture/str-layout1.rs @@ -1,5 +1,7 @@ // { dg-additional-options "-w" } // { dg-output "t1sz=5 t2sz=10\r*" } +#![feature(intrinsics)] + mod mem { extern "rust-intrinsic" { #[rustc_const_stable(feature = "const_transmute", since = "1.46.0")] diff --git a/gcc/testsuite/rust/execute/torture/transmute1.rs b/gcc/testsuite/rust/execute/torture/transmute1.rs index b9ec38ca618..40dcfdee0b3 100644 --- a/gcc/testsuite/rust/execute/torture/transmute1.rs +++ b/gcc/testsuite/rust/execute/torture/transmute1.rs @@ -1,4 +1,5 @@ // { dg-additional-options "-w" } +#![feature(intrinsics)] extern "rust-intrinsic" { fn transmute(value: T) -> U; diff --git a/gcc/testsuite/rust/execute/torture/wrapping_op1.rs b/gcc/testsuite/rust/execute/torture/wrapping_op1.rs index 64b37085ab7..ab4afd7ddde 100644 --- a/gcc/testsuite/rust/execute/torture/wrapping_op1.rs +++ b/gcc/testsuite/rust/execute/torture/wrapping_op1.rs @@ -1,3 +1,5 @@ +#![feature(intrinsics)] + extern "rust-intrinsic" { pub fn wrapping_add(l: T, r: T) -> T; } diff --git a/gcc/testsuite/rust/execute/torture/wrapping_op2.rs b/gcc/testsuite/rust/execute/torture/wrapping_op2.rs index f9990157894..b24ebce56f1 100644 --- a/gcc/testsuite/rust/execute/torture/wrapping_op2.rs +++ b/gcc/testsuite/rust/execute/torture/wrapping_op2.rs @@ -1,3 +1,5 @@ +#![feature(intrinsics)] + extern "rust-intrinsic" { pub fn wrapping_add(l: T, r: T) -> T; pub fn wrapping_sub(l: T, r: T) -> T; From patchwork Wed Apr 5 14:03: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: 79697 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp357156vqo; Wed, 5 Apr 2023 07:38:28 -0700 (PDT) X-Google-Smtp-Source: AKy350agVWwjWunGWWr6+Tog0Hfz5fzUOd6gGGh/lS4PI//WqUqFiZeT8Awz5gpWVQPF2HpkKRYl X-Received: by 2002:aa7:c583:0:b0:501:d18f:af83 with SMTP id g3-20020aa7c583000000b00501d18faf83mr2043132edq.8.1680705508719; Wed, 05 Apr 2023 07:38:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705508; cv=none; d=google.com; s=arc-20160816; b=Fjg6HCHYADGWTr0eT0ysSdOOIsnZMW/joLsNfl98/sF+FtOAZg4pAO9IRi6TnD17Xf w8mJ+5gCyGRFdDT0R72fuq7jiBvv/mok+6JBuktDLssEcGzxyO+KoJgfz8amREzszPIo 4nDddz9XBLwoOj2N6ENlov9Q36lATaQr2K2XaLejHFQ8oRq3PiAkp9DAgn0FONmKRXeB m0JybzJHwPFfRhCm0nV6sUhGojan6uAMligNjWTPCrpoZj6qJN8N7gDspoZqJbi4vOTx RMH+s5mZtGS+Aa3xYIX5Awd5BoKEHUQO1wHIiNLNwoAEO7Kswl9QqYxS8pa9hgdPkpBG Z4HA== 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=62Q4BK9iHnz4xCrdVNcfpSpma623JkkizKxhTXvFuxo=; b=azSDeSuZpOQRhnuqnouzhIKvAHpGrOUshyUVYv3r9t79mBujSR7wOrpFc/l4Uj3spD PmM5mIookDobe0BRWo2wanvY09Y5l7cDdi09oMRfyFkOCbDLXkaYEQoFTqd2HuTqRkFR PmAXKRjAvdKqN2vHmNZw+pK2KcghdKMB+ubmi8K/39kwa5okmiiM+btXWgQWjDfKa86S 55yhn+YRWOCtiNirwNJ+QRzueR33D2c3IsDe4F/I2GORcogHsarEfQiy29Y/k6itVyAc bo3BVGikziv2BNIKLwRSc91oorLVdcWwp+ULPkAYifHrIvr0pehTSgcbpynMYMRpipfL HYmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=TKhepjF1; 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 r9-20020aa7cb89000000b00502961db46dsi8498128edt.268.2023.04.05.07.38.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:38:28 -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=TKhepjF1; 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 B48BD382AA69 for ; Wed, 5 Apr 2023 14:14:21 +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 2431C3856DE5 for ; Wed, 5 Apr 2023 14:06:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2431C3856DE5 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 n19so20972379wms.0 for ; Wed, 05 Apr 2023 07:06:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703574; 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=62Q4BK9iHnz4xCrdVNcfpSpma623JkkizKxhTXvFuxo=; b=TKhepjF1ERAILhB8LqATk8ENojVhYm3fpTy1t5t+VTWEnYaR338J8Jk07fjbjbW/p0 5YP3qg6wAc9epRF9xbFeLUJxCRsI4QnIa5KZaeYeSbr83baMUkjIOuYYHeEhAnjyaBVu ANciYsgGcR6ZlKTLrxyoUndiETrY3vvO3EDMcEYxd0tN1Ki4I3ArWQIB+ZtTrKzK+Q8e sWU8js4Fi6hwGOYWbaYAZKTA2gnXIMe9r8LHaI46fOQghAWzKuK5DYSy5Ha8WuNYAYF2 CVP7aKWmwe1pp0YqO+w/UX3xe/mEZG9+kS0V06Zb0M9g/i7qQiCwvFzrzcSRnBqnbCz7 z7dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703574; 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=62Q4BK9iHnz4xCrdVNcfpSpma623JkkizKxhTXvFuxo=; b=Gi0I2KA42jc2GhNyYCtimHTzGL6sstpFnk6fNpKP7jQJfbCZ+KJaSdz6u/49qh3sSK lYr8MEWUkgJIIcis2TAO5bDsazK2cgllD+FFkCHk2d4ADAkW779Wpdc4CPdxcfeXZnoR k29JWv2FWEm1mXRt3IuSdT91NfuTPcAhjhdlT66qBDYxwN+77kra3kcI02+dMaf9k2zl fWhihvjvVTahrEkcyOx5aUn3/en7AZMGVYPv8vg9CZ3CNlzc1JhbcnrdKj6MUVgfseQa jREue2+AUFp0aYMP/nNp7frHVEFKpMHBiccTd11P9+oWIl5vmAIybnGPFVVwATgN54uQ 7vYg== X-Gm-Message-State: AAQBX9deWL5zpp7BG7ycpIchjwwl+xJy3ifZ4FcDHZZWeS1suUCMrZwz AAjQ0p6NWJzSY1RxLUqkvgUOwTWteNyeJQewIw== X-Received: by 2002:a7b:c38a:0:b0:3ea:e834:d0d1 with SMTP id s10-20020a7bc38a000000b003eae834d0d1mr4863077wmj.36.1680703574368; Wed, 05 Apr 2023 07:06:14 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:14 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [committed 66/88] gccrs: Add variadic argument type checking Date: Wed, 5 Apr 2023 16:03:50 +0200 Message-Id: <20230405140411.3016563-67-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.6 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?1762347459290061542?= X-GMAIL-MSGID: =?utf-8?q?1762347459290061542?= From: Owen Avery gcc/rust/ChangeLog: * typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Add variadic argument type checking. (TypeCheckCallExpr::visit): Fix comment spelling ("varadic"). gcc/testsuite/ChangeLog: * rust/execute/torture/overflow1.rs: Fix test. Signed-off-by: Owen Avery --- gcc/rust/typecheck/rust-tyty-call.cc | 56 ++++++++++++++++++- .../rust/execute/torture/overflow1.rs | 2 +- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/gcc/rust/typecheck/rust-tyty-call.cc b/gcc/rust/typecheck/rust-tyty-call.cc index 67e2866cbce..f0846ae25ec 100644 --- a/gcc/rust/typecheck/rust-tyty-call.cc +++ b/gcc/rust/typecheck/rust-tyty-call.cc @@ -122,7 +122,7 @@ TypeCheckCallExpr::visit (FnType &type) return; } - // it might be a varadic function + // it might be a variadic function if (i < type.num_params ()) { auto fnparam = type.param_at (i); @@ -143,6 +143,60 @@ TypeCheckCallExpr::visit (FnType &type) return; } } + else + { + switch (argument_expr_tyty->get_kind ()) + { + case TyTy::TypeKind::ERROR: + return; + case TyTy::TypeKind::INT: { + auto &int_ty + = static_cast (*argument_expr_tyty); + if ((int_ty.get_int_kind () == TyTy::IntType::IntKind::I8) + || (int_ty.get_int_kind () == TyTy::IntType::IntKind::I16)) + { + rust_error_at (arg_locus, + "expected % variadic argument"); + return; + } + break; + } + case TyTy::TypeKind::UINT: { + auto &uint_ty + = static_cast (*argument_expr_tyty); + if ((uint_ty.get_uint_kind () == TyTy::UintType::UintKind::U8) + || (uint_ty.get_uint_kind () + == TyTy::UintType::UintKind::U16)) + { + rust_error_at (arg_locus, + "expected % variadic argument"); + return; + } + break; + } + case TyTy::TypeKind::FLOAT: { + if (static_cast (*argument_expr_tyty) + .get_float_kind () + == TyTy::FloatType::FloatKind::F32) + { + rust_error_at (arg_locus, + "expected % variadic argument"); + return; + } + break; + } + case TyTy::TypeKind::BOOL: + rust_error_at (arg_locus, "expected % variadic argument"); + return; + case TyTy::TypeKind::FNDEF: + rust_error_at (arg_locus, + "unexpected function definition type as variadic " + "argument - cast to function pointer"); + return; + default: + break; + } + } i++; } diff --git a/gcc/testsuite/rust/execute/torture/overflow1.rs b/gcc/testsuite/rust/execute/torture/overflow1.rs index 57a0824ce0a..c4ccab1a133 100644 --- a/gcc/testsuite/rust/execute/torture/overflow1.rs +++ b/gcc/testsuite/rust/execute/torture/overflow1.rs @@ -16,5 +16,5 @@ fn main() { // { dg-final { scan-tree-dump ADD_OVERFLOW original } } let c = a + b; - unsafe { printf("%d\n\0" as *const str as *const i8, c) } + unsafe { printf("%d\n\0" as *const str as *const i8, c as i32) } } From patchwork Wed Apr 5 14:03: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: 79726 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp365889vqo; Wed, 5 Apr 2023 07:52:27 -0700 (PDT) X-Google-Smtp-Source: AKy350a/9Sjx1wHkqrPdJIjGeqD6Ev2Whcc+7okQLZ2YYk3JwxEcO8kY6pLffvKNzP+W0/l+klE+ X-Received: by 2002:a17:906:81d3:b0:930:6e31:3c11 with SMTP id e19-20020a17090681d300b009306e313c11mr3034934ejx.70.1680706346933; Wed, 05 Apr 2023 07:52:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706346; cv=none; d=google.com; s=arc-20160816; b=n7B4lr4sKYPa36ugDo7IDwrDS/f6pCQL4RMUueaW1fnDMqoV6P6Mr7722lPtZsx0Zr d46l1Zzu0zu9KxCAAmH37P5rDxSvLLoD1e5dJ6nLecdtfCo7i7/9xUlL97uG2Q1+NUjY zoiSLpjGeRl9NJi3SEuCpL+VdogbPdsen4vioy5OChF0EJEGDDpEekehenubNqSXEIAJ RPcfAhIayqzkzH/7xRYH6w0VO/3LdX2plOszGeRGSuecamtUzOagUdAoxhQH1moX49oo g6hBqskVgbs9mZSMCoPceeEog3aC7SpiDLPg7JyKu8UJ5dT5iB4YIsSaGq4AsJ5UoaP8 2Xgw== 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=blJz/1ESmD5l5WkSR4B0frgiju5qzCk067o2GbVyt38=; b=rQDEIT2E9E3fTN+wndUDQa0mQLhF+qvuVb7m//qg7JEHFDAe6ENOgPqUDnon8lqSBN iGHphoDwpahtvCNOO4+750I+AqhXOjMTX/W/vQ7vTfbwfm5x0HuthZYzuZHZiNBrk4LM VsKb1LePb6WqNtSPKPjxH3NjljgyaP4i5Ie6rli0g9fv1gl0kH7G5lsc31/8a+/25sV0 U4U78pM0kwMBWE+dqPxtwg3LjtzEQlCTREr6xKtUni7gNhHo3zClEbQXJ9Ub0r+6dCrA jWlr4QP65sh48y/mjzFbkcXXb2FffqAhZylayBadkHlpuwlpOVnhMgO/C4wCScKoCM1r v4mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=GQKUom+3; 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 e3-20020a170906374300b0093deb6d10a0si264014ejc.757.2023.04.05.07.52.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:52:26 -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=GQKUom+3; 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 A40213936F3D for ; Wed, 5 Apr 2023 14:19:14 +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 25B723853803 for ; Wed, 5 Apr 2023 14:06:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 25B723853803 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 n19-20020a05600c501300b003f064936c3eso1252902wmr.0 for ; Wed, 05 Apr 2023 07:06:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703575; 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=blJz/1ESmD5l5WkSR4B0frgiju5qzCk067o2GbVyt38=; b=GQKUom+3NIxyYm7wDGScOY+zRThgP3jhIWFBone02TRg11Td2M7lVr6iFtgB3HvJHF OxRxwe70wc0MqF2MMF4OJJ0/Q2ATTyuiRVzPh8R0I7oqlx7vxQjGj0GeF5T1D3VXNAKk NxVpwlymmvc5slNFNNxjJWjXMxfCSbW6111XdR1B4JjY2DEZM0mPkdCxkdyW5t3GBKJ8 3q6uQ71YFMeehsMnGYiabt0LMYVKknQVp4ZxaIvAUrMhWfCDxJbQnZ1lXyy8+RD9C6DQ jKyoCg+kLYp5fwQv86aIHe4whNZ9Zow/zkVgkqrKX1AShe+Fr9Szy9u7r8W7yD54M6az OeSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703575; 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=blJz/1ESmD5l5WkSR4B0frgiju5qzCk067o2GbVyt38=; b=2vyODzBEE/i7nwohJGpe+mM9ivp95qurixo9hBxeR93iptfUp+/C192Qhf7hNGw7C4 yndTwIuZ1OMnF4YL1ITQn9YmQBJMTm3Jv5KkjUSOQEtRBa+I6mtP4AFLri7gzbLzKBOF c8sRt1RUAAgRyCo6n64lBb+p2ouaI5HmhWanhVgtsr2/1TGFsz2TdH3nUV6l5rk99DIu u0OUc9jCWoaJRT2Kq1zG1VSIvTvYdCcIZa3laMD+vYkGUSRnLgALV6QDVf6Ktm8LpcMf Zy9jHsl6uPcoU4IAtknalEdpTZ3Lg6peqm0iasS0OkuEJ4Sf92PCaS8KHE4ksqLLhjpF Jo1g== X-Gm-Message-State: AAQBX9f6mrcKnb2hScj4r+0vCCp03LbW6RMTUEPUmPVuT4yiI+vAw7VS PEF5eSB1r6mpZfgYMS5M9ZqRb+FTu04Cm97+3A== X-Received: by 2002:a7b:c8c4:0:b0:3ee:5519:fae1 with SMTP id f4-20020a7bc8c4000000b003ee5519fae1mr4775134wml.12.1680703575396; Wed, 05 Apr 2023 07:06:15 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:15 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [committed 67/88] gccrs: Add test Date: Wed, 5 Apr 2023 16:03:51 +0200 Message-Id: <20230405140411.3016563-68-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.6 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?1762348338131870652?= X-GMAIL-MSGID: =?utf-8?q?1762348338131870652?= From: Owen Avery gcc/testsuite/ChangeLog: * rust/compile/variadic.rs: New test. Signed-off-by: Owen Avery --- gcc/testsuite/rust/compile/variadic.rs | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 gcc/testsuite/rust/compile/variadic.rs diff --git a/gcc/testsuite/rust/compile/variadic.rs b/gcc/testsuite/rust/compile/variadic.rs new file mode 100644 index 00000000000..886341b088c --- /dev/null +++ b/gcc/testsuite/rust/compile/variadic.rs @@ -0,0 +1,8 @@ +extern "C" { + fn printf(s: *const i8, ...); +} + +fn main() { + // { dg-error "expected .c_int. variadic argument" "" { target *-*-* } .+1 } + printf("%d\n" as *const str as *const i8, 1i8); +} From patchwork Wed Apr 5 14:03: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: 79728 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp366809vqo; Wed, 5 Apr 2023 07:53:52 -0700 (PDT) X-Google-Smtp-Source: AKy350bn7vSnFiYfNX/OvL+QSrdRQ56cgkeE7PMv9cepDRBB9VmWqg7UpIuDpj3dU3NnZGngm214 X-Received: by 2002:a17:906:829a:b0:93d:425a:b935 with SMTP id h26-20020a170906829a00b0093d425ab935mr3564550ejx.25.1680706432744; Wed, 05 Apr 2023 07:53:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706432; cv=none; d=google.com; s=arc-20160816; b=Veh0KFLWDEzCFlJajzBxue3kc7XnqtJjqx70VJzagSuaM6GVxOO1FgdjPyvqqToO65 NAUbIoB5y10Fg9HKggnKgiz73RICRaywKIDGl9jNSS+Ot0NnQeqzJKOrDIJOPEEFSuzt orzHS36lZenNUHk9ed1QxRJWmWOwqodhFuVgVQfvahZ7Ec8equ+oAXa2lJM9XkgmpF+d HLM3cMVbw70258kfEmrXlF3QkR5PWQqB6Ag3KBfYQ7y6p3+n5ivFJQdxWRpgBy5gqlIK O0CLTTLKeFl88H8LG8DDM7WTOm+YeXzfXpeYMI5fuCANVbASrvCKuIZb8gbAAiq1n8Wv PSvw== 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=LO8GaK0iLh8Yqa2+6+UtDHiI7SCb03gtz2TCCuQHamk=; b=krkX2ZaeZEnl90iJ6BhsbRTuvTcIVW58Sc1IVJHnfTI/9Pxc6zTro2PM/sPl4TSPiZ Mi5Kt8h5NMPUDysalxfZOYjQP4VgIiRvvwzPPJ1164rB2BjMc63exyOZDOyEdcT4Te9i E6oLlY1hjYev7nzjQEUSQzHbciH0+Fn6N66UxhS4pP57NwPut6iaKaJHBgHo2femfXQN hBvdgloxbwABmBTtsff+iTi33yy6UjUqPZ8kezBpr47F9jaoYvL0hEnPqYzuUJHA0/GP PcuplMKlUsJpG0jmqXmYsMZXl5EK7L/XsL7yPLKg5NFTPj4HVqAJSviF14V8zri11NwG zAGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=bnPzD3ja; 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 ot3-20020a170906ccc300b00945552ee129si11895144ejb.616.2023.04.05.07.53.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:53:52 -0700 (PDT) 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=bnPzD3ja; 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 57331397E045 for ; Wed, 5 Apr 2023 14:19:53 +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 03E1E3881D3E for ; Wed, 5 Apr 2023 14:06:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 03E1E3881D3E 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 m8so10053366wmq.5 for ; Wed, 05 Apr 2023 07:06:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703576; 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=LO8GaK0iLh8Yqa2+6+UtDHiI7SCb03gtz2TCCuQHamk=; b=bnPzD3ja61x4brCLcMD2gCmh2dVwPcy24Ts5hhJ3QAFtwvXKiLZTZfqNm5k7bGz3ql mBVIFNor5yTkz6TDeRziFKEOqW3ZJHc1cN/r2bUqhz77YJ7RAYmYerG4v2pY/WeYGFP+ YBq9kQLhtS5zWNcs4irWto7crQtPPZBYKG10yU6GyJ5cq78dxdKYcp5aPbhsMo1d2fP/ SSYTaxe0opBxFGfBFickOHGC04+CUGzxNPV1Z5tE2pO8EBCmaMbqv56VIp10dCahMnk+ JBYin7+Z3lx5ZQvwZ05Z39hkAJDpb2rp8GYtMUpAVcmJYTSPmsxfaNb7jUXkB5KT2+P3 twew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703576; 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=LO8GaK0iLh8Yqa2+6+UtDHiI7SCb03gtz2TCCuQHamk=; b=r0d0uSfXZ2fHqf0eHEzRfc3XREfmbCdZIkjGMpaa8ufVSIT7SM7+ZEUoAutHLpubRS 0MDiToR2nELlHBnz+00hVv1SyR8bHDms8yU8bmpIFdoukXycMAuqmIhX6UN834jApI4Q K8m1BAf9BdCOx6oSuryrkXgTbIT82pjeep9aCCrE4JsR2YGlpYAuJZ9E6MIZOxEwRsOH IacJNZPNqtp47zgd6uLRcge753cUFdwJ53khcOQWwPn+RjhyCn+me3ztQIblCl261rAH gN4YhFxXd/hl39TMQLhf61xQlGjsXnyf7op2ePgktIFP0DPMuUSDI0PiSS3juqOVe0uI K5bQ== X-Gm-Message-State: AAQBX9fFEZARzfSteCv9DjToGdSalOg2QkFiysfNQZNyWgaL1nqwh0fj QnkWqvl2hW7wWXe6DFtR1o2ikakHXCX4KX57mg== X-Received: by 2002:a7b:c7c5:0:b0:3ea:ed4d:38eb with SMTP id z5-20020a7bc7c5000000b003eaed4d38ebmr4979883wmk.24.1680703576343; Wed, 05 Apr 2023 07:06:16 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:15 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [committed 68/88] gccrs: Simplify WildcardPattern let statement handling Date: Wed, 5 Apr 2023 16:03:52 +0200 Message-Id: <20230405140411.3016563-69-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.5 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?1762348428629531278?= X-GMAIL-MSGID: =?utf-8?q?1762348428629531278?= From: Owen Avery gcc/rust/ChangeLog: * backend/rust-compile-pattern.cc (CompilePatternLet::visit): Simplify WildcardPattern compilation for let statements. * backend/rust-compile-var-decl.h: (CompileVarDecl::visit): Remove variable declaration for WildcardPattern. * resolve/rust-ast-resolve-pattern.h: (PatternDeclaration::visit): Remove name resolution for WildcardPattern. Signed-off-by: Owen Avery --- gcc/rust/backend/rust-compile-pattern.cc | 28 +++++---------------- gcc/rust/backend/rust-compile-var-decl.h | 16 +----------- gcc/rust/resolve/rust-ast-resolve-pattern.h | 7 ------ 3 files changed, 7 insertions(+), 44 deletions(-) diff --git a/gcc/rust/backend/rust-compile-pattern.cc b/gcc/rust/backend/rust-compile-pattern.cc index cb4b082f9c8..d98f7beb0e8 100644 --- a/gcc/rust/backend/rust-compile-pattern.cc +++ b/gcc/rust/backend/rust-compile-pattern.cc @@ -361,30 +361,14 @@ CompilePatternLet::visit (HIR::IdentifierPattern &pattern) void CompilePatternLet::visit (HIR::WildcardPattern &pattern) { - Bvariable *var = nullptr; - rust_assert ( - ctx->lookup_var_decl (pattern.get_pattern_mappings ().get_hirid (), &var)); - - auto fnctx = ctx->peek_fn (); - if (ty->is_unit ()) - { - ctx->add_statement (init_expr); + tree init_stmt = NULL; + tree stmt_type = TyTyResolveCompile::compile (ctx, ty); - tree stmt_type = TyTyResolveCompile::compile (ctx, ty); + ctx->get_backend ()->temporary_variable (ctx->peek_fn ().fndecl, NULL_TREE, + stmt_type, init_expr, false, + pattern.get_locus (), &init_stmt); - auto unit_type_init_expr - = ctx->get_backend ()->constructor_expression (stmt_type, false, {}, -1, - rval_locus); - auto s = ctx->get_backend ()->init_statement (fnctx.fndecl, var, - unit_type_init_expr); - ctx->add_statement (s); - } - else - { - auto s - = ctx->get_backend ()->init_statement (fnctx.fndecl, var, init_expr); - ctx->add_statement (s); - } + ctx->add_statement (init_stmt); } void diff --git a/gcc/rust/backend/rust-compile-var-decl.h b/gcc/rust/backend/rust-compile-var-decl.h index 9e07999f273..13b429d41e1 100644 --- a/gcc/rust/backend/rust-compile-var-decl.h +++ b/gcc/rust/backend/rust-compile-var-decl.h @@ -53,21 +53,6 @@ public: locals.push_back (var); } - void visit (HIR::WildcardPattern &pattern) override - { - translated_type = ctx->get_backend ()->immutable_type (translated_type); - - 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, var); - - locals.push_back (var); - } - // Empty visit for unused Pattern HIR nodes. void visit (HIR::LiteralPattern &) override {} void visit (HIR::PathInExpression &) override {} @@ -78,6 +63,7 @@ public: void visit (HIR::StructPattern &) override {} void visit (HIR::TuplePattern &) override {} void visit (HIR::TupleStructPattern &) override {} + void visit (HIR::WildcardPattern &) override {} private: CompileVarDecl (Context *ctx, tree fndecl, tree translated_type, diff --git a/gcc/rust/resolve/rust-ast-resolve-pattern.h b/gcc/rust/resolve/rust-ast-resolve-pattern.h index 3e74f0a4cc6..4c7d13a16d0 100644 --- a/gcc/rust/resolve/rust-ast-resolve-pattern.h +++ b/gcc/rust/resolve/rust-ast-resolve-pattern.h @@ -70,13 +70,6 @@ public: 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 (), type); - } - void visit (AST::GroupedPattern &pattern) override { pattern.get_pattern_in_parens ()->accept_vis (*this); From patchwork Wed Apr 5 14:03: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: 79702 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp358624vqo; Wed, 5 Apr 2023 07:40:43 -0700 (PDT) X-Google-Smtp-Source: AKy350bMyANJ/tfrpYikRJB4yz0/CCTfp0J8Nt0fvOyDNPmoIBmcZzUY1boFSk8xZflqIDWfFHuq X-Received: by 2002:a17:907:174a:b0:949:1e89:8fd4 with SMTP id lf10-20020a170907174a00b009491e898fd4mr3034548ejc.69.1680705643324; Wed, 05 Apr 2023 07:40:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705643; cv=none; d=google.com; s=arc-20160816; b=fQLYZjEC3vlitMavktML/KEvl64D3uIcRrhzsDHWeRa01tR2P2XAqLMkcheEBNQA4e XBYpP90Gm3lztL32HyS0WD8hUpGQfHmUoBIFP03/75fBxG6EqMCVsmyWeqHFbvg/QY5e ZUFjOq5O+APIJiYsp16CJa/0V6VI1tMMXehDG0+EinhRo6wpRd0feGD5qgAiMZX9Q+X+ TAUb7YLPhClBqwEcc/ri9p5j+5JlsnWr2QlPdy54yIP+vx122JOYD4J4AbnVot1B4IK2 bf8yS5RoqaZo2jPAQkVH7U5kGgIUegbu9Dclewg3QoOGWArWTs+OUX6gZdLotyAjz3v2 eW1g== 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=2JYPPufBm17C8gJ68C7axxWbue6wBAVF6i2JaVFRM8c=; b=ROmFTYJxVBrRFvMbIZgq/pci3lM7thYf1d7dPjvi9KvDKY65hMGSMkkRyncXw0f/1y hak5MxKUbUckPHoAvVGgFJuzp8J1lMwkp6aIuotfDFwEeYSK/yayB4fj3jlySG7mVc3E SbifTSmncFnD8K8dVVlAa0pQzFsEkjruU3IpE5h8hHQmMYih5SuUowHrws20VNCHj5dV +Fnlmuc3AuXUls2e5o6bbQkJs+ruX/Vy50v/3wnAOguNL4d2YmOUVAf7Ck2Hx0CcDE8F 6FacyZotyYFfQ6yXMsDG+D05Xjfcw6cKlHXo6b+yuyMljXMPEdv8ghs6tppuHOPVZPGw k9+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=eLtRHGR1; 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 d1-20020a170906304100b00947a7291940si1067689ejd.618.2023.04.05.07.40.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:40:43 -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=eLtRHGR1; 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 885E039F9F6D for ; Wed, 5 Apr 2023 14:14:52 +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 C0ADB388201B for ; Wed, 5 Apr 2023 14:06:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C0ADB388201B 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 v1so36337667wrv.1 for ; Wed, 05 Apr 2023 07:06:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703577; 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=2JYPPufBm17C8gJ68C7axxWbue6wBAVF6i2JaVFRM8c=; b=eLtRHGR1fenvlfTi8zZqV2a2aOuZIATRQANX+TNU5tQV6H3ZDQJWIbRN2Rq9a3dcxL VLvggh2rUKRws+jL2CkI8BOnDDRH0az6JMaXfGuMx3+V23L/xRbE8N5W1k1kEYUaItf/ Z77vLxn5b8Qk6/LManz2Jt/Bh1xbcOKcevkfjjwJna15DM3kmeNdQF2OUNpYEe7KQyhX lUjZEWhzEiGRGgn8miWOFTsBUWZe2H+qe66Hqyoio4ludz9eUm+emPZm1UVMwiO2w7En tlPzioK8hNboTUsHV739Vyuk+q51yIqh48fREB9CJeyWlllPwbfUnYKSfqLi+51hJz9G O4XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703577; 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=2JYPPufBm17C8gJ68C7axxWbue6wBAVF6i2JaVFRM8c=; b=IBaHzDOp+VtCiNF7QaB6PzBG90peDvfJZm2W4b1XcXhtySL2V4haZJ9VpPViOV4GIO 9axL77MEi+QgYlhR42RyAdhpxpQHYn/AWvZmbXUCra7M0XJA3r5X9YhNPXo0FG2r3UEU WYGjE+7BVdoWSOqE77y9F3bomTdYN07+ifIOBhg/9oX5XquyQHsTq4s0vhAzKUKWe2Ah Ko2Ax5Q0/dzPJPFLk8on+mNteOLEb3UE22sFh9j7WGoUCqeiJaqF7nX20r1p4ZCamTZy QydTvxCLdQhT9mcGNyBKBOQzW7LBgLY+YUgyxJLFs4oqOGRCiBT8YAU2OKTB6Jqw10Q2 kwxA== X-Gm-Message-State: AAQBX9f2JHooxLumf/D1xq/a5AJ7nz5iUcqoP4fa2BwrxpJctWYAJWnO Xh5ogn0LrBdt+d1gHdJaHKDPgnyej7kqu9L9QQ== X-Received: by 2002:a5d:4ac5:0:b0:2cb:d8f1:1d31 with SMTP id y5-20020a5d4ac5000000b002cbd8f11d31mr3978374wrs.18.1680703577180; Wed, 05 Apr 2023 07:06:17 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:16 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [committed 69/88] gccrs: lex: Prevent directories in RAIIFile Date: Wed, 5 Apr 2023 16:03:53 +0200 Message-Id: <20230405140411.3016563-70-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.5 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?1762347600589506536?= X-GMAIL-MSGID: =?utf-8?q?1762347600589506536?= From: Pierre-Emmanuel Patry RAIIFile constructor was accepting directory filename. This lead to unattended directory opening in some part of the code (load_file_bytes) wich resulted in ice. Since RAIIFile are used for the lexer, removing the ability to open directories with RAIIFile fixes those issues and prevent future mistakes. gcc/rust/ChangeLog: * lex/rust-lex.h: Add file type check. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/lex/rust-lex.h | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/gcc/rust/lex/rust-lex.h b/gcc/rust/lex/rust-lex.h index 2dd60b365ef..50424713df9 100644 --- a/gcc/rust/lex/rust-lex.h +++ b/gcc/rust/lex/rust-lex.h @@ -38,13 +38,37 @@ private: fclose (file); } + static bool allowed_filetype (const struct stat &statbuf) + { + // The file could be either + // - a regular file + // - a char device (/dev/null...) + return S_ISREG (statbuf.st_mode) || S_ISCHR (statbuf.st_mode); + } + public: RAIIFile (const char *filename) : filename (filename) { if (strcmp (filename, "-") == 0) - file = stdin; + { + file = stdin; + } else - file = fopen (filename, "r"); + { + struct stat statbuf; + if (!(file = fopen (filename, "r"))) + { + return; + } + + if (-1 == fstat (fileno (file), &statbuf) + || !allowed_filetype (statbuf)) + { + fclose (file); + file = nullptr; + errno = EISDIR; + } + } } /** From patchwork Wed Apr 5 14:03: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: 79709 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp359908vqo; Wed, 5 Apr 2023 07:42:49 -0700 (PDT) X-Google-Smtp-Source: AKy350Y01W9n6COvtr4CVo1Mo+NiDMCYjIZW1Xy1vKE6JKCGUsYIP5gW3inek1MBF/uZB9P3xZqP X-Received: by 2002:a17:906:693:b0:932:8cd:1021 with SMTP id u19-20020a170906069300b0093208cd1021mr3187121ejb.33.1680705769627; Wed, 05 Apr 2023 07:42:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705769; cv=none; d=google.com; s=arc-20160816; b=W3BYMvn+YiT2pZhQt0Py+A7Pd4T64G2T78W64fLN3wcDCCH1mPwIQYaLdsTW0BRSv/ 3+I+2b18CM0bRgFmyN/lg8z33ecvrUKYEEreIYQ0GlYCfOU3ubVRJlFKq2BzqU3ZwvZ3 kOmz69CH95wbdoinPIIIlwWZGBQ5J6uQyvuMVpBSp9dIK2XGG5PyxOc4Q3OGqJoUyaS+ Zw++wE+i4/rB+mmUka9qLe2+yejaDSV8YTleX2/xlDrevvTaDNaDBlzPBtxkWxShXtWT dUncHOWUR1hb3QaCHkr6RG4NXkwTmrkkEbZyn4+ODmdix6fsS6wXLOmoK7ZqMuExuQPl 2AdA== 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=WlN7u7RgXQgZZ2m1GFUQeOAOSGxK7KPIDiB1VOchWFQ=; b=Rvk1GptLGPctUEEAAn32HB4q7jp0NBnmGHyeKxAZofC6rDxJLns5nDwG3GuOalVsBO QBPRJvhL4a8bsA1XgHC3nytoiCe7L4IG51q5YCo01ByE+elveCUlG/xeYiuMGbf9LSwR KcjvOqHbKdElD5Fr710y8RXiQAYShXhIv0hhlDGBytcAoHrZMTD5DadljzDJ2mJn+wGk JqegIXI9f911r0iF9RxhvNv32pUg7Qz2IA2UmfmnHasRcRaa5jGWnrPPXx9RsWOnre7g +qAMAKzHnnEb5OkG61J4HgpvEYcqeqs9NoRVd2+zT4dlFIlEvL6H87HHTCLzzUSBtg5S XhcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=BCuwXFYI; 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 f7-20020a170906738700b0092a3709e877si4809914ejl.679.2023.04.05.07.42.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:42:49 -0700 (PDT) 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=BCuwXFYI; 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 325043A47F7C for ; Wed, 5 Apr 2023 14:15:24 +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 84230388203F for ; Wed, 5 Apr 2023 14:06:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 84230388203F 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 n19so20972530wms.0 for ; Wed, 05 Apr 2023 07:06:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703577; 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=WlN7u7RgXQgZZ2m1GFUQeOAOSGxK7KPIDiB1VOchWFQ=; b=BCuwXFYI33yifzstpObYDE74UG2IcRtReu5Ey7sZgFWvUP+jehJEYHLDIQHj8URlc1 ZRLzjv6Z1NatFYylmJi13NKnnCOqdXX2PRj/b7riZxMEhrDkyl9WMy9dfTRZ6axgFQIv 9UYiyI1eHxCTTcAuEibCI3hmDRRcyzdpWMO93YNqMlQS6L5iOlL7uWEfTOBxgqahYV4b JbDlsuXTwwey158Tmxr8Lgd7F729elgYIAG1ZSSmG3SOPiVagVhU2+TqOahSDiZ7k0Un rFj8zqhYWVlaot5Tz2sEvXqdFNNx39LB/vDnoLTh/kG1vcai8NtVr/n6S3yylPs+eA4y me3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703577; 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=WlN7u7RgXQgZZ2m1GFUQeOAOSGxK7KPIDiB1VOchWFQ=; b=C+aCXtc45nuvNpTs+TnjMONgf6Ih867GBL78LLXCH9/Vga49w4MxSOT6GUnKHS8qYD jCF3RmgcfIwWpp6iv/JfjEKICcw3taIq3kdktM2WKD4Kov63Mo1q5OkXnkfeabYMSTpq Gx7nYskHjrebA0LKrCuy7F6kyLmbpEOaUoQiIxb421pOJ6TDPfv/OAlR0MiO+ucEO0lI mx8ezPYsD13KB2uaRYj+VjkVaiXyLsH6/O76m+EScdmV9m6KlzBk2LuvR+s1wGxNYivD LdE6etVE16vOoV7Sb3l88mS7HPGmGCJ8E0k4wL9p4ECZd9iy9GdSoPkRPyNiidDQoM3Y knfw== X-Gm-Message-State: AAQBX9cphYmOLNlC5w9RSbmgAExYXWPOgmDV22LPOBEcPAa8ZZuEb4q8 zJjQiQIje7POM0RjsA+5PmdPmmAJQzAEgBtZIw== X-Received: by 2002:a05:600c:b4f:b0:3ed:d64f:ec30 with SMTP id k15-20020a05600c0b4f00b003edd64fec30mr4624309wmr.33.1680703577763; Wed, 05 Apr 2023 07:06:17 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:17 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [committed 70/88] gccrs: testsuite: Add empty string macro test Date: Wed, 5 Apr 2023 16:03:54 +0200 Message-Id: <20230405140411.3016563-71-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.2 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?1762347733219613971?= X-GMAIL-MSGID: =?utf-8?q?1762347733219613971?= From: Pierre-Emmanuel Patry Add two new tests with empty string for include_str and include_bytes macros. gcc/testsuite/ChangeLog: * rust/compile/issue-1830_bytes.rs: New test. * rust/compile/issue-1830_str.rs: New test. Signed-off-by: Pierre-Emmanuel Patry --- gcc/testsuite/rust/compile/issue-1830_bytes.rs | 8 ++++++++ gcc/testsuite/rust/compile/issue-1830_str.rs | 8 ++++++++ 2 files changed, 16 insertions(+) create mode 100644 gcc/testsuite/rust/compile/issue-1830_bytes.rs create mode 100644 gcc/testsuite/rust/compile/issue-1830_str.rs diff --git a/gcc/testsuite/rust/compile/issue-1830_bytes.rs b/gcc/testsuite/rust/compile/issue-1830_bytes.rs new file mode 100644 index 00000000000..dcc53b73b19 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-1830_bytes.rs @@ -0,0 +1,8 @@ +#[rustc_builtin_macro] +macro_rules! include_bytes { + () => {{}}; +} + +fn main() { + include_bytes!(""); // { dg-excess-errors "Is a directory" } +} diff --git a/gcc/testsuite/rust/compile/issue-1830_str.rs b/gcc/testsuite/rust/compile/issue-1830_str.rs new file mode 100644 index 00000000000..6cf835ba9bd --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-1830_str.rs @@ -0,0 +1,8 @@ +#[rustc_builtin_macro] +macro_rules! include_str { + () => {{}}; +} + +fn main() { + include_str!(""); // { dg-excess-errors "Is a directory" } +} From patchwork Wed Apr 5 14:03: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: 79727 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp366346vqo; Wed, 5 Apr 2023 07:53:06 -0700 (PDT) X-Google-Smtp-Source: AKy350byOdcajG+Gaseg0bh1Z0FADvDOWdOj6hpIK/WOBqUioMNNyS753UIMfcchpWJhLe1XSUz6 X-Received: by 2002:aa7:cc98:0:b0:501:cf67:97f3 with SMTP id p24-20020aa7cc98000000b00501cf6797f3mr1832772edt.25.1680706386166; Wed, 05 Apr 2023 07:53:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706386; cv=none; d=google.com; s=arc-20160816; b=hkwdjPJGmdf6XSelRMVEmkZI+sCpoi4ZilROOIqdsGK5NVCHhDu4ykrmdO+H+hhdhm Msv+ZstZ71lNB8CHALTbgAcbpkOSFZvmma89SSCCfESVd2D2Qe39vzfUoKrOKYQdqT+X tYs4zSRVaDhe1WK7UTc3OEZwJBKVOQ/eUGnoz/R3OBgMtp8cQqmEABHSkiexEp5O5p2B gkf5SlptCF53VYznP7AU/z7auKlsi1nmk/vV+T0tVSr5hFK7UA1satvdWJaGh/Sk/zhM qqINkW+BT0WrQuPmudREnj8Q/w0tCrfo/9Y8msmBNmau3U+pOsAXVyqBulQNZsJRC2Xr BJtg== 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=krf/8l0AgriaRegJytwFoqtZEhTeVlcAd3ZbvcFM/Zo=; b=SEHh1j015hTEqEjiLSaBLcxwsxc9+eZM7J4UlMcTytPeVx+xIHQCLDPRoUPrzRCZk7 JPY+X290BRi/Xm2eUVzXINNdxQiFN8vnPmdKnLCGxTjvGWZcJlnZgaFKI9wd+8uUMf47 FUz8CCWwA8hoc3jAVAkpYzXaK2oGcVgW5Ok1GPMiJI2iRfwZt1BvkFUQaTbLuMZwnae2 kjuzkFHsVyocFMhaE7JdIKsBi34bGtQDyNbvBfdIsHATScRS2tpnOQZ1hvM7wQh0xbIz /QvwwnunMoESLurk8FGTk03jzFBx74f8gAKjWnFXzGqij/A6Rd5s4W+APcmuYn+JYhTn AclA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Ii1TjqxK; 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 c7-20020aa7d607000000b0050295f8cff8si752691edr.366.2023.04.05.07.53.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:53:06 -0700 (PDT) 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=Ii1TjqxK; 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 3922F3A4A6F2 for ; Wed, 5 Apr 2023 14:19:32 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id 0A5EE3851C31 for ; Wed, 5 Apr 2023 14:06:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0A5EE3851C31 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-x335.google.com with SMTP id hg25-20020a05600c539900b003f05a99a841so4128512wmb.3 for ; Wed, 05 Apr 2023 07:06:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703578; 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=krf/8l0AgriaRegJytwFoqtZEhTeVlcAd3ZbvcFM/Zo=; b=Ii1TjqxK3IC3fiaRWwNsNhpzgYRUBqsUCGkZ1ZW53mT3Z/UhUcrfNfqNTiKAQdi5UY PMwiTbV8FjMTJjq2Ee5EIhvPwLw4o5+oFe5ySE2zMN1+OK/YlEi5Es2pa+z2Gf67v8r/ ML5Hd+Ln9UzP6tvltYYE+h5m6zT+0iitWk9Ub6FwAXh6zkMhwuOmqGes+waMunWw+bBF DyYScMDj00tm5d+XIN/PW5jVOv+qvTmBzEzuP+oWjVd1BjZ53VzGFyLjPTfnTbi6vYcN bOkJLot5J0hxPneiVrlOV64XOY3V9v0KtMDfKtMt44mV7XbqveptHdvHHxe6Bly2NcT5 wvgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703578; 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=krf/8l0AgriaRegJytwFoqtZEhTeVlcAd3ZbvcFM/Zo=; b=E7PSwyNOUSkINFMRJi62hDwbgZxr2nBOFBYjnIMOrudTKJi1OGjKO4EIIrhBOqFWcm Fo4k3iOE/CQJiDDged/k6F6tP9nfAahtcIMa+u49gUI/olx285d1hQybZCbqOX7sF+a1 R0JlJSNZSkX8SYCUrZpVmdXF0m2qwVg+38S1AFYMnD6GprIgfTyICLLh14jbEYGarZem vSQvLi/Avfrmf35gf8qc6KCysrNkBJauO3md2peBKxBcky0rcsKd+Q/qz+1bQ1K/EG/E GEaqMHJGgS8VDFeQy4dyGuii2Z5M4eNCWRRIR3Ds4v3SRMRLiMq4T6bzqv1aMI45Y2Da Fg1Q== X-Gm-Message-State: AAQBX9dMR9ys80RqQ+dFglV3s9DcPijed21izPO6394/ILYeEugfFFtj 7YJ8M9S8bn90RXHwX1Y/XRpC0E9gNKEz9xLWfg== X-Received: by 2002:a05:600c:3658:b0:3ef:4138:9eef with SMTP id y24-20020a05600c365800b003ef41389eefmr4855498wmq.36.1680703578519; Wed, 05 Apr 2023 07:06:18 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:17 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [committed 71/88] gccrs: Add support for parsing empty tuple patterns. Date: Wed, 5 Apr 2023 16:03:55 +0200 Message-Id: <20230405140411.3016563-72-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.5 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?1762348379843909326?= X-GMAIL-MSGID: =?utf-8?q?1762348379843909326?= From: Owen Avery gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_grouped_or_tuple_pattern): Add support for empty tuple patterns. gcc/testsuite/ChangeLog: * rust/compile/parse_empty_tuple_pattern.rs: New test. Signed-off-by: Owen Avery --- gcc/rust/parse/rust-parse-impl.h | 9 +++++++++ gcc/testsuite/rust/compile/parse_empty_tuple_pattern.rs | 3 +++ 2 files changed, 12 insertions(+) create mode 100644 gcc/testsuite/rust/compile/parse_empty_tuple_pattern.rs diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 4ceb978f7f4..cc5436cff63 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -10926,6 +10926,15 @@ Parser::parse_grouped_or_tuple_pattern () return std::unique_ptr ( new AST::TuplePattern (std::move (items), paren_locus)); } + else if (lexer.peek_token ()->get_id () == RIGHT_PAREN) + { + skip_token (RIGHT_PAREN); + auto items = std::unique_ptr ( + new AST::TuplePatternItemsMultiple ( + std::vector> ())); + return std::unique_ptr ( + new AST::TuplePattern (std::move (items), paren_locus)); + } // parse initial pattern (required) std::unique_ptr initial_pattern = parse_pattern (); diff --git a/gcc/testsuite/rust/compile/parse_empty_tuple_pattern.rs b/gcc/testsuite/rust/compile/parse_empty_tuple_pattern.rs new file mode 100644 index 00000000000..d974d31b8ba --- /dev/null +++ b/gcc/testsuite/rust/compile/parse_empty_tuple_pattern.rs @@ -0,0 +1,3 @@ +fn main() { + let () = (); +} From patchwork Wed Apr 5 14:03: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: 79729 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp367496vqo; Wed, 5 Apr 2023 07:55:05 -0700 (PDT) X-Google-Smtp-Source: AKy350YTNoPAKSoZDRQvaL4Jd8CEnzqMLmDaZAhVxrI7xSHnzRsPuAjZ5Qu+dJQVXYjmq9EUUPeH X-Received: by 2002:a17:906:bfc9:b0:93d:b767:9fea with SMTP id us9-20020a170906bfc900b0093db7679feamr3328601ejb.31.1680706505452; Wed, 05 Apr 2023 07:55:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706505; cv=none; d=google.com; s=arc-20160816; b=kgc80QfcAZK89oSGlE85VhFzrR0GMBbs3Jpz6yqn9CX+Q6dAcgU1LlltsUZDznvAzq r2HF+kJkn3ajoMXqQeIjH3e4vYC/OjoSgnUJJFeRzLkyTbw47qdhRAP0Ma4trBSg65/O btkTL9nuBaVIOhO0lDyslDO6jFiiQ+zSm587nRxe/SHszn3gqkxv1q2m3NMXotiyBWlL jFezMuLxt8PShXuPZ5LgzNXRHxGcLX2qVQjToTE0sKIc95grvO/H4tykSoL4aUgaLkLU ByATeEYMU/RcbVyQP162f1riAgp+aqcg2RSpI2/vFYnfM6ZotTQ3D20eUfzv1J2g/14M NHpw== 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=pCfVERjAiIkTnxQujMkOHgn7E1ET95+MyREJa4QaQhE=; b=mlNF40k4h1G5pKaXIdEQY0KafvECG+VD78RqV/A1xn7rtZ3hz7arPT6uKU0Ij0RyN2 obQoBh6LeLidwfrpgH0Nf9Yy26nqHs3kl5OKJDhFL3hWoOec++XbWWZGNfzKGxlGGoBW 2NR37vGh8X+0XLzjYv+RtL15Ek+1fA2vUbEg2MO3QjGZ12o4prQELV4ENa8E9+xeH3ME IJOlUWPToKk9iUiPDt7e7WH4nGufc7at83UWMCNbVqT3Ut46u7VMFOl3QPMRLlvLhE4y eKm4CraW8dx+98+X8GoiXTxK5C6Mc/9ATqDux35+Gdvw689CXSc3/gWRD3Pj5aYT0TBt vI6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=JiI41H70; 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 n7-20020aa7d047000000b004fd18a8023asi2418523edo.495.2023.04.05.07.55.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:55:05 -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=JiI41H70; 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 7BF923870886 for ; Wed, 5 Apr 2023 14:20:27 +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 AF42A388206C for ; Wed, 5 Apr 2023 14:06:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AF42A388206C 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 m8so10053534wmq.5 for ; Wed, 05 Apr 2023 07:06:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703580; 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=pCfVERjAiIkTnxQujMkOHgn7E1ET95+MyREJa4QaQhE=; b=JiI41H70BT1Im6J0DIjLuVMJpjPwwFZf07wzkwVgGWXBvM5QoBljnORIyTxgbAu1Zh EmYPxyt+jf5Y+EV2IG0x8amhbBpORPuI7rozis66tidqP2FhTYrWtKdhnlNbr6+BsZuX PYIv67wJ4RDCXqhWedyVlwMsK49VSaApxup6MfVnZK8ipMzVv20vAPWTaHNJoRMw04eF hFJsXkDcjradBQUoYAA/rVr3nLopt4hsIB+7+WOGdNKeEjSEW7qKsCghRS0rLFgMMTWH CMd7/WcLYwQmJHlTxt2b/EyU16yl60I35I+ayQntLPSk0i1hOqTzkwpQx8zD3C80LiCx 5juQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703580; 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=pCfVERjAiIkTnxQujMkOHgn7E1ET95+MyREJa4QaQhE=; b=O/npUrixNW+CuB0PaLc8ZqMn7AJyGuUxTO1R5lx9ZEx5ES1H8YQ7Bp/RVbGFJ0fhQt hTx5igeVRfGvN+Hyf4gti0XUPGLhafqdKtawLEorIL1HyZWNavQGOWijoVYvGaceyc9D 1QKgtkgruwP+6SQwXeoxmdYngKMrsy8p7f5i9mz2V4oP+//A6cOzwc+J77bElyl3D8OX Ht0+bE1Ytkup7/qfrtLOeeqYdEq3BZFztjKUVAC1By+MDLYMUb9JAyrxFyx1awMV9Dbn 2ULQAvrGADCa73hKQ3NyrzTwD7Vs3HdSaSi8gUS8zf07GS5gv88HzMKINhCYV0RZ9JmL 088g== X-Gm-Message-State: AAQBX9d9gqZnN/CI2GdZkBWuZIia9sLaKhNa95j7DlSoFaNFoskW6O+c 2+6EMcSQP1dQIhzec8Br/a5czI5w3EZcT76P5g== X-Received: by 2002:a7b:cbd2:0:b0:3f0:5519:9049 with SMTP id n18-20020a7bcbd2000000b003f055199049mr5301601wmi.8.1680703579956; Wed, 05 Apr 2023 07:06:19 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:19 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 73/88] gccrs: Extract query_type from TypeCheckBase to be a simple extern Date: Wed, 5 Apr 2023 16:03:57 +0200 Message-Id: <20230405140411.3016563-74-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.2 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?1762348504728078025?= X-GMAIL-MSGID: =?utf-8?q?1762348504728078025?= From: Philip Herron Signed-off-by: Philip Herron gcc/rust/ChangeLog: * Make-lang.in: add new dependancy * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::query_type): refactor * typecheck/rust-hir-type-check-base.h: refactor * typecheck/rust-hir-type-check.h (RUST_HIR_TYPE_CHECK): refactor * typecheck/rust-type-util.cc: New file. * typecheck/rust-type-util.h: New file. --- gcc/rust/Make-lang.in | 1 + .../typecheck/rust-hir-type-check-base.cc | 73 ------------ gcc/rust/typecheck/rust-hir-type-check-base.h | 2 - gcc/rust/typecheck/rust-hir-type-check.h | 1 + gcc/rust/typecheck/rust-type-util.cc | 108 ++++++++++++++++++ gcc/rust/typecheck/rust-type-util.h | 38 ++++++ 6 files changed, 148 insertions(+), 75 deletions(-) create mode 100644 gcc/rust/typecheck/rust-type-util.cc create mode 100644 gcc/rust/typecheck/rust-type-util.h diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index 09bbe450bd5..06f64a01dce 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -134,6 +134,7 @@ GRS_OBJS = \ rust/rust-hir-type-check-implitem.o \ rust/rust-hir-dot-operator.o \ rust/rust-hir-path-probe.o \ + rust/rust-type-util.o \ rust/rust-coercion.o \ rust/rust-casts.o \ rust/rust-unify.o \ diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc b/gcc/rust/typecheck/rust-hir-type-check-base.cc index 6e42b7b7b23..e302e27f4ab 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-base.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc @@ -483,78 +483,5 @@ 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; - } - - HirId parent_impl_id = UNKNOWN_HIRID; - HIR::ImplItem *impl_item - = mappings->lookup_hir_implitem (reference, &parent_impl_id); - if (impl_item != nullptr) - { - HIR::ImplBlock *impl_block - = mappings->lookup_hir_impl_block (parent_impl_id); - rust_assert (impl_block != nullptr); - - // found an impl item - rust_debug_loc (impl_item->get_locus (), "resolved impl-item {%u} to", - reference); - - *result = TypeCheckItem::ResolveImplItem (*impl_block, *impl_item); - context->query_completed (reference); - return true; - } - - // is it an impl_type? - HIR::ImplBlock *impl_block_by_type = nullptr; - bool found_impl_block_type - = mappings->lookup_impl_block_type (reference, &impl_block_by_type); - if (found_impl_block_type) - { - *result = TypeCheckItem::ResolveImplBlockSelf (*impl_block_by_type); - context->query_completed (reference); - return true; - } - - // is it an extern item? - HirId parent_extern_block_id = UNKNOWN_HIRID; - HIR::ExternalItem *extern_item - = mappings->lookup_hir_extern_item (reference, &parent_extern_block_id); - if (extern_item != nullptr) - { - HIR::ExternBlock *block - = mappings->lookup_hir_extern_block (parent_extern_block_id); - rust_assert (block != nullptr); - - *result = TypeCheckTopLevelExternItem::Resolve (extern_item, *block); - context->query_completed (reference); - return true; - } - - // more? - 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; -} - } // namespace Resolver } // namespace Rust diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.h b/gcc/rust/typecheck/rust-hir-type-check-base.h index 335014339f3..b8ff2cf6dc9 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-base.h +++ b/gcc/rust/typecheck/rust-hir-type-check-base.h @@ -69,8 +69,6 @@ protected: const std::vector> &generic_params, std::vector &substitutions); - bool query_type (HirId reference, TyTy::BaseType **result); - Analysis::Mappings *mappings; Resolver *resolver; TypeCheckContext *context; diff --git a/gcc/rust/typecheck/rust-hir-type-check.h b/gcc/rust/typecheck/rust-hir-type-check.h index 512453947a6..6d4b9b8a62f 100644 --- a/gcc/rust/typecheck/rust-hir-type-check.h +++ b/gcc/rust/typecheck/rust-hir-type-check.h @@ -19,6 +19,7 @@ #ifndef RUST_HIR_TYPE_CHECK #define RUST_HIR_TYPE_CHECK +#include "rust-type-util.h" #include "rust-hir-full-decls.h" #include "rust-hir-map.h" #include "rust-tyty.h" diff --git a/gcc/rust/typecheck/rust-type-util.cc b/gcc/rust/typecheck/rust-type-util.cc new file mode 100644 index 00000000000..4e38826686b --- /dev/null +++ b/gcc/rust/typecheck/rust-type-util.cc @@ -0,0 +1,108 @@ +// 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-type-util.h" +#include "rust-diagnostics.h" +#include "rust-hir-type-check.h" +#include "rust-name-resolver.h" +#include "rust-hir-visitor.h" +#include "rust-hir-map.h" +#include "rust-hir-type-check-item.h" +#include "rust-hir-type-check-implitem.h" + +namespace Rust { +namespace Resolver { + +bool +query_type (HirId reference, TyTy::BaseType **result) +{ + Analysis::Mappings *mappings = Analysis::Mappings::get (); + TypeCheckContext *context = TypeCheckContext::get (); + + 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; + } + + HirId parent_impl_id = UNKNOWN_HIRID; + HIR::ImplItem *impl_item + = mappings->lookup_hir_implitem (reference, &parent_impl_id); + if (impl_item != nullptr) + { + HIR::ImplBlock *impl_block + = mappings->lookup_hir_impl_block (parent_impl_id); + rust_assert (impl_block != nullptr); + + // found an impl item + rust_debug_loc (impl_item->get_locus (), "resolved impl-item {%u} to", + reference); + + *result = TypeCheckItem::ResolveImplItem (*impl_block, *impl_item); + context->query_completed (reference); + return true; + } + + // is it an impl_type? + HIR::ImplBlock *impl_block_by_type = nullptr; + bool found_impl_block_type + = mappings->lookup_impl_block_type (reference, &impl_block_by_type); + if (found_impl_block_type) + { + *result = TypeCheckItem::ResolveImplBlockSelf (*impl_block_by_type); + context->query_completed (reference); + return true; + } + + // is it an extern item? + HirId parent_extern_block_id = UNKNOWN_HIRID; + HIR::ExternalItem *extern_item + = mappings->lookup_hir_extern_item (reference, &parent_extern_block_id); + if (extern_item != nullptr) + { + HIR::ExternBlock *block + = mappings->lookup_hir_extern_block (parent_extern_block_id); + rust_assert (block != nullptr); + + *result = TypeCheckTopLevelExternItem::Resolve (extern_item, *block); + context->query_completed (reference); + return true; + } + + // more? + 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; +} + +} // namespace Resolver +} // namespace Rust diff --git a/gcc/rust/typecheck/rust-type-util.h b/gcc/rust/typecheck/rust-type-util.h new file mode 100644 index 00000000000..a3f9efc003b --- /dev/null +++ b/gcc/rust/typecheck/rust-type-util.h @@ -0,0 +1,38 @@ +// 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_TYPE_UTIL +#define RUST_TYPE_UTIL + +#include "rust-mapping-common.h" + +namespace Rust { + +namespace TyTy { +class BaseType; +} + +namespace Resolver { + +extern bool +query_type (HirId reference, TyTy::BaseType **result); + +} // namespace Resolver +} // namespace Rust + +#endif // RUST_TYPE_UTIL From patchwork Wed Apr 5 14:03: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: 79714 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp361333vqo; Wed, 5 Apr 2023 07:45:07 -0700 (PDT) X-Google-Smtp-Source: AKy350b6YNxV5u2W6O/yUHE+allAdM2FxlA2x+BNnfGd5T0T7kyxV7UhbRdEWKTZy3UasJo4qslT X-Received: by 2002:a17:906:b1d6:b0:923:c55d:efd2 with SMTP id bv22-20020a170906b1d600b00923c55defd2mr2853372ejb.68.1680705907424; Wed, 05 Apr 2023 07:45:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705907; cv=none; d=google.com; s=arc-20160816; b=AGvn8Dnlf6QurG4daweUPMRNmvQE3BF3a9s+DKLmsfnUg25IuielRo/Df34zMEo+74 DZ/4ERkqlAkYWR8GLYzXOGJUzXYmUiOYbiAo5ei322dl1I2U97G4skO4bqMYmuZnoHhq s10BHO2EKK98sgfRAermhA1rVXdHkM0rcw2z6PdJkRUBgZDMiSaspQbm7EfiL6EQEfS4 1TR6bgmnlDVFUXavJM7hPV2zt79hUcqecpTLXQlGr23qNF1y25t2EMxDynrGMnEjSBRO j59eyynR9UXv2/jYh5w47t7+SCrzmEOLBUpSgMvwVcb8AdAac7v1NirOh/EheWgPLZ14 3puw== 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=z+/TB1DTi/dzWqWqIPxcanvy0VOcpbktvMfQnu3W9PA=; b=kSZ3btLe9whJsngY8oJ+4C0/9Uc9Ge932b7edU3TVqriVo+yOPTVwEXZbuVaZzxxNF a4ftiZGtD1DpY9x7Kt2r+6i2zIYG8NPPo/6Y1SpUn2oGj+MlMlylxb1oj1kn2Eod0gss WC1irvQvu8MhPQreFkh+jmBMqMxdOc8cpP+KupyFsZ5T3a8ehBrKEl7cVKZf+2MWMZ1+ b2o/j8jeWudKTQp3+K6FsUS1FEGk/pseZLeot4OZJk9b2C1so04egYYGSEQpBcsvHibX 1YyLd1SwfGqeQsE9oOEdMJpNTBMbfZm3KCulmtbfkcCXLlKwy/Qtp21tQ82SGT479YH4 zA4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=O7lmjTJ3; 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 b20-20020aa7cd14000000b005021f2d34e0si1298766edw.351.2023.04.05.07.45.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:45:07 -0700 (PDT) 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=O7lmjTJ3; 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 7197638555BA for ; Wed, 5 Apr 2023 14:16:07 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 0C89A3882155 for ; Wed, 5 Apr 2023 14:06:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0C89A3882155 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-x329.google.com with SMTP id l10-20020a05600c1d0a00b003f04bd3691eso7161488wms.5 for ; Wed, 05 Apr 2023 07:06:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703580; 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=z+/TB1DTi/dzWqWqIPxcanvy0VOcpbktvMfQnu3W9PA=; b=O7lmjTJ3mAGRyKey3ltVuxmFyc69zfZYTcdJYR7oETrxTHBrlhh0X58AfOCywV9A7z rRE1NryLOYapWFjU+lNjCzmvEss5sebrZJG1vBmaQ53Bq+zOYwVha5uGJ3M0kFCnPOkd ehEvD2qC5oE1Qt6R9rpsdwrdYfHUvP9heLRk8iBbFpADEDwpc/2F2+hajpvO1mjCTTnA TmeS2QztWK71eZpk5Ql+4RclBxAv6mZZmJdNVPIxSfgqtlTtXclkg37SKzwHdTcQzEZq gvmZwzPdrhwcxvX9JAaPHCKcK4nRf+JhgsLbnCHXUjntidg23E4NsKzI0kFIGVrcrGX1 Q3mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703580; 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=z+/TB1DTi/dzWqWqIPxcanvy0VOcpbktvMfQnu3W9PA=; b=wCS14x2pZX+AErQXP8QInyyc2wBJGFhidRXgz37oCiSZhgY+sDrfdrD/dNIxJELQHz gF/fKD99LVodCTzqAj81+IzEC71Tnwwem/o9N5sHvvxV/3w03D8+I7y7v0JFD1XHzIm6 Fuyp2DoX+PwQR3ROn2KrBLtCEo7zs6Bg7lAqDdogKdkWZ3sqf1OvOFjin70iOiOWFiIl HEcl8VmCd3Tt2+e6l9u5teFztKrCc6HRYUVOxLGGS4RVAKC4WeJUSWxJQNIOq2TOuP/S lOEc7JaQLicpbqNuxcYJHt+9Y215IFU0Z/YJ/X1pyZetGz4umwgpvDG7Eyjd0UymsI2x JjaA== X-Gm-Message-State: AAQBX9e9PuiEBC7VhUjCTRqJ1UxGrJTJ73Bfmh1enaTwXIQvNTrCQ17e BzpVm89H+Y9ASdG2x/9QSMswicquCpi6w76LSQ== X-Received: by 2002:a1c:7406:0:b0:3ee:18e:a1ef with SMTP id p6-20020a1c7406000000b003ee018ea1efmr4459883wmc.1.1680703580364; Wed, 05 Apr 2023 07:06:20 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:20 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 74/88] gccrs: Add new virtual function HIR::ImplItem::get_impl_item_name Date: Wed, 5 Apr 2023 16:03:58 +0200 Message-Id: <20230405140411.3016563-75-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.5 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?1762347877878296585?= X-GMAIL-MSGID: =?utf-8?q?1762347877878296585?= From: Philip Herron Signed-off-by: Philip Herron gcc/rust/ChangeLog: * hir/tree/rust-hir-item.h: implement virtual function * hir/tree/rust-hir.h: add virtual function --- gcc/rust/hir/tree/rust-hir-item.h | 17 ++++++++++++++++- gcc/rust/hir/tree/rust-hir.h | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h index f7bf1f879c8..03e1f71abb5 100644 --- a/gcc/rust/hir/tree/rust-hir-item.h +++ b/gcc/rust/hir/tree/rust-hir-item.h @@ -1226,6 +1226,11 @@ public: SelfParam &get_self_param () { return self; } + std::string get_impl_item_name () const override final + { + return get_function_name (); + } + protected: /* Use covariance to implement clone function as returning this object * rather than base */ @@ -1345,6 +1350,11 @@ public: return get_mappings (); }; + std::string get_impl_item_name () const override final + { + return get_new_type_name (); + } + protected: /* Use covariance to implement clone function as returning this object * rather than base */ @@ -2116,7 +2126,7 @@ public: Expr *get_expr () { return const_expr.get (); } - std::string get_identifier () { return identifier; } + std::string get_identifier () const { return identifier; } Analysis::NodeMapping get_impl_mappings () const override { @@ -2130,6 +2140,11 @@ public: ItemKind get_item_kind () const override { return ItemKind::Constant; } + std::string get_impl_item_name () const override final + { + return get_identifier (); + } + protected: /* Use covariance to implement clone function as returning this object * rather than base */ diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h index 314aafb32d3..28f1f21a6bb 100644 --- a/gcc/rust/hir/tree/rust-hir.h +++ b/gcc/rust/hir/tree/rust-hir.h @@ -839,6 +839,8 @@ public: virtual ImplItemType get_impl_item_type () const = 0; + virtual std::string get_impl_item_name () const = 0; + protected: // Clone function implementation as pure virtual method virtual ImplItem *clone_inherent_impl_item_impl () const = 0; From patchwork Wed Apr 5 14:03: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: 79738 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp370447vqo; Wed, 5 Apr 2023 08:00:13 -0700 (PDT) X-Google-Smtp-Source: AKy350Z9KOWcbuGVjsxRHQdBvFM5aU7A7u9XZv+1h6PVsZFGji1h9oQFmBkXsdimXCjXo76IDvzQ X-Received: by 2002:a17:906:c01:b0:8f6:88b7:73a7 with SMTP id s1-20020a1709060c0100b008f688b773a7mr2542159ejf.7.1680706813728; Wed, 05 Apr 2023 08:00:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706813; cv=none; d=google.com; s=arc-20160816; b=GkDzDvL6cKTYBVcRfuaztWh4JuEB+pycMeKXj4R05K9KmicXnN14RuYK3B0sI1PXO8 dI/HOMIM0mqrG4tYjmqYm+70fb+tBLg/wuuKwV8tPjymmcGuPS5zoGYBBf11bmq5cNdw r/miLXm+UIigjrdEsv3KMdE7TT/qrlY82XdAVU4yGRF1Ur+Rj2qc1jF9bnADRh3trQex Oh46P68H8MWLv8CGo74EzBZ2TlREK1TKqCXxnM9uidtr85N8soZcjLa6vVq/ANExvyUL 2L2xSmSc1C9ywMt0f4wSZYdMg5+GOq4f11gj6epDrXu+Caw/+wDNIzP8i5qhwcBKxZE4 2Gtw== 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=nd4LBzR7/WMT6jIjUOgFhfMAMTK0EPcYfwEIqXgyk0g=; b=Nr/Ru5WD9WRhQUPm/goNeU1XDT/JMQ8Tt0xaDMOuZUTE9FMdc6phCfW2tabfm3Lhxl LVi3Se9Q1SQ2MsGGuJczLen+CBT+ASlDgy8PKsfC856URc10aKRm2cCi5nMrw+0LlrUr GD9OY4rJ9GP4K74qhuHygsdpE6f/AAC4JaUkNnnS9DwmhfTx3FKFibeXRa0hqlidmBcf eaEHDwOnWgoZv079WDU0Bju3iFLTOBpVCSBFOf7kkkPslJCzefTnO60FSdbIcbMDTNFc MON/LS6IRlBvOqEm4ObaFL/8EKuWYTroHi5/CU0zgaS5g1Ur+D3ESbk7BfyW+TTufNyF WOVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=euTDJBZD; 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 dt4-20020a170907728400b00947c1a1170bsi2485187ejc.717.2023.04.05.08.00.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 08:00:13 -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=euTDJBZD; 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 240BF38C22C8 for ; Wed, 5 Apr 2023 14:22:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id EDCF03857008 for ; Wed, 5 Apr 2023 14:06:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EDCF03857008 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-x329.google.com with SMTP id d11-20020a05600c3acb00b003ef6e6754c5so18372585wms.5 for ; Wed, 05 Apr 2023 07:06:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703581; 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=nd4LBzR7/WMT6jIjUOgFhfMAMTK0EPcYfwEIqXgyk0g=; b=euTDJBZD+y4mkoV3bavIkPqx3QqEh15iaPwGOLShKDQxZMExJ0pHsokyXF++s+cX5J gQvcHyGBgQshpIWkFeIGO8PXmJXGioWbw9plVdhJAog+qBHiDmWeWlX2Qe+/RAbFoI9v BB+V9P/xsBBiTF/vH8xSPwtKMT3hXlTuWvpnV2kJY46lXiAyC8n6B53kskJFC5C3shzW Dqd82iLH+2TZVhPVRDHdNCnnOo5UYS7kc1rZiXFGnPoJ/c5VaDCSJFqVRGf8+pqPJOao hctIPma5+bA0saRCeSOyMlfjPsfzjhPuMEomlifIQQUWhzTb3ihVrMOjxIXg4T0YkuWy N1sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703581; 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=nd4LBzR7/WMT6jIjUOgFhfMAMTK0EPcYfwEIqXgyk0g=; b=czwUBf8e0jJglncnzcnJKtUljqtc9PAs1tE8uJ5l4tQ8QFz8BcYmaYne8qmbjObk6J ND93hAZxadFfiaEFb9/uwRO4t/b76vAQgVL3r0ukJddg3ZGCmwfjfk9zQclHWASbRqIe pUzJ2Inv8WeXOTqzDiSNZvAXP+xELDbKxcBzY/qYWbjFUho0rFl66prVQgR56fPCs1Ix WlPgwoZuclTRiylm3ylOkCfUgg2YENTZb86KiYXmVRaLjmOkQ1PRKoGEQ0bo+yESGJrN SgdGODJDZ5EyMHzN6KSS7dDq0eaTJYsFIKh9XX3zdWNRr2siU69OcttyqGGnUCt5p8Vy iHIA== X-Gm-Message-State: AAQBX9fs/sQJRCVhyXRCimYJsuFINeT0pEuyBio8CezVJAhSkRSwhgpr 2iYLn2Rn4mlD7Uh2pB791IrH69ywMOENRDLI+w== X-Received: by 2002:a05:600c:2216:b0:3e2:1dac:b071 with SMTP id z22-20020a05600c221600b003e21dacb071mr1909965wml.13.1680703581025; Wed, 05 Apr 2023 07:06:21 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:20 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 75/88] gccrs: Support for Sized builtin marker trait Date: Wed, 5 Apr 2023 16:03:59 +0200 Message-Id: <20230405140411.3016563-76-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.5 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, 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?1762348827974735127?= X-GMAIL-MSGID: =?utf-8?q?1762348827974735127?= From: Philip Herron When implementing general bounds checking as part of unify calls, we did not check associated types on bounds which lead to alot of missed error checking. This now recursively checks the bounds and the associated types with a decent error message. This also required us to implement the Sized marker trait to keep existing test-cases happy. Fixes #1725 Signed-off-by: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-hir-trait-reference.cc (TraitReference::clear_associated_types): make const (TraitReference::clear_associated_type_projections): new interface * typecheck/rust-hir-trait-reference.h: * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): refactor (TraitItemReference::associated_type_reset): reset projections * typecheck/rust-hir-type-bounds.h: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): fix bounds * typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::TypeBoundsProbe): refactor into cc file (TypeBoundsProbe::Probe): refactor (TypeBoundsProbe::is_bound_satisfied_for_type): likewise (TypeBoundsProbe::assemble_sized_builtin): add builtin for Sized (TypeCheckBase::get_predicate_from_bound): refactor (TypeBoundPredicate::lookup_associated_type): refactor * typecheck/rust-tyty-subst.cc (SubstitutionRef::lookup_associated_impl) (SubstitutionRef::prepare_higher_ranked_bounds): new interface to clear hanging bounds (SubstitutionRef::monomorphize): refactor * typecheck/rust-tyty-subst.h: * typecheck/rust-tyty.cc (BaseType::get_locus): helper (BaseType::satisfies_bound): ensure bounds are satisfied and assoicated types (ParamType::ParamType): new field in constructor (ParamType::clone): update clone (ParamType::set_implicit_self_trait): new interface (ParamType::is_implicit_self_trait): likewise * typecheck/rust-tyty.h: cleanup * util/rust-hir-map.cc (Mappings::Mappings): builtin marker (Mappings::~Mappings): delete marker (Mappings::lookup_builtin_marker): lookup * util/rust-hir-map.h: update header gcc/testsuite/ChangeLog: * rust/compile/issue-1725-1.rs: New test. * rust/compile/issue-1725-2.rs: New test. --- .../typecheck/rust-hir-trait-reference.cc | 18 +- gcc/rust/typecheck/rust-hir-trait-reference.h | 6 +- gcc/rust/typecheck/rust-hir-trait-resolve.cc | 27 +- gcc/rust/typecheck/rust-hir-type-bounds.h | 34 +- .../typecheck/rust-hir-type-check-expr.cc | 6 + gcc/rust/typecheck/rust-tyty-bounds.cc | 111 ++++++- gcc/rust/typecheck/rust-tyty-subst.cc | 291 ++++++++++-------- gcc/rust/typecheck/rust-tyty-subst.h | 12 +- gcc/rust/typecheck/rust-tyty.cc | 82 ++++- gcc/rust/typecheck/rust-tyty.h | 8 +- gcc/rust/util/rust-hir-map.cc | 17 +- gcc/rust/util/rust-hir-map.h | 3 + gcc/testsuite/rust/compile/issue-1725-1.rs | 19 ++ gcc/testsuite/rust/compile/issue-1725-2.rs | 28 ++ 14 files changed, 476 insertions(+), 186 deletions(-) create mode 100644 gcc/testsuite/rust/compile/issue-1725-1.rs create mode 100644 gcc/testsuite/rust/compile/issue-1725-2.rs diff --git a/gcc/rust/typecheck/rust-hir-trait-reference.cc b/gcc/rust/typecheck/rust-hir-trait-reference.cc index 8574988fb0b..a1229adc06c 100644 --- a/gcc/rust/typecheck/rust-hir-trait-reference.cc +++ b/gcc/rust/typecheck/rust-hir-trait-reference.cc @@ -343,14 +343,26 @@ TraitReference::on_resolved () } void -TraitReference::clear_associated_types () +TraitReference::clear_associated_types () const { - for (auto &item : item_refs) + for (const auto &item : item_refs) + { + bool is_assoc_type = item.get_trait_item_type () + == TraitItemReference::TraitItemType::TYPE; + if (is_assoc_type) + item.associated_type_reset (false); + } +} + +void +TraitReference::clear_associated_type_projections () const +{ + for (const auto &item : item_refs) { bool is_assoc_type = item.get_trait_item_type () == TraitItemReference::TraitItemType::TYPE; if (is_assoc_type) - item.associated_type_reset (); + item.associated_type_reset (true); } } diff --git a/gcc/rust/typecheck/rust-hir-trait-reference.h b/gcc/rust/typecheck/rust-hir-trait-reference.h index f3703efcced..d20b2952e5b 100644 --- a/gcc/rust/typecheck/rust-hir-trait-reference.h +++ b/gcc/rust/typecheck/rust-hir-trait-reference.h @@ -106,7 +106,7 @@ public: void associated_type_set (TyTy::BaseType *ty) const; - void associated_type_reset () const; + void associated_type_reset (bool only_projections) const; bool is_object_safe () const; @@ -212,7 +212,9 @@ public: void on_resolved (); - void clear_associated_types (); + void clear_associated_types () const; + + void clear_associated_type_projections () const; bool is_equal (const TraitReference &other) const; diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc index 6e23093eceb..2d7985703cf 100644 --- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc +++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc @@ -161,6 +161,9 @@ TraitResolver::resolve_trait (HIR::Trait *trait_reference) TraitQueryGuard guard (trait_id); TyTy::BaseType *self = nullptr; std::vector substitutions; + + // FIXME + // this should use the resolve_generic_params like everywhere else for (auto &generic_param : trait_reference->get_generic_params ()) { switch (generic_param.get ()->get_kind ()) @@ -182,7 +185,11 @@ TraitResolver::resolve_trait (HIR::Trait *trait_reference) if (typaram.get_type_representation ().compare ("Self") == 0) { - self = param_type; + rust_assert (param_type->get_kind () == TyTy::TypeKind::PARAM); + TyTy::ParamType *p + = static_cast (param_type); + p->set_implicit_self_trait (); + self = p; } } break; @@ -365,7 +372,7 @@ TraitItemReference::associated_type_set (TyTy::BaseType *ty) const } void -TraitItemReference::associated_type_reset () const +TraitItemReference::associated_type_reset (bool only_projections) const { rust_assert (get_trait_item_type () == TraitItemType::TYPE); @@ -374,7 +381,21 @@ TraitItemReference::associated_type_reset () const TyTy::PlaceholderType *placeholder = static_cast (item_ty); - placeholder->clear_associated_type (); + if (!only_projections) + { + placeholder->clear_associated_type (); + } + else + { + if (!placeholder->can_resolve ()) + return; + + const TyTy::BaseType *r = placeholder->resolve (); + if (r->get_kind () == TyTy::TypeKind::PROJECTION) + { + placeholder->clear_associated_type (); + } + } } TyTy::BaseType * diff --git a/gcc/rust/typecheck/rust-hir-type-bounds.h b/gcc/rust/typecheck/rust-hir-type-bounds.h index 4e8c58344de..628bba5da20 100644 --- a/gcc/rust/typecheck/rust-hir-type-bounds.h +++ b/gcc/rust/typecheck/rust-hir-type-bounds.h @@ -30,42 +30,18 @@ class TypeBoundsProbe : public TypeCheckBase { public: static std::vector> - Probe (const TyTy::BaseType *receiver) - { - TypeBoundsProbe probe (receiver); - probe.scan (); - return probe.trait_references; - } + Probe (const TyTy::BaseType *receiver); static bool is_bound_satisfied_for_type (TyTy::BaseType *receiver, - TraitReference *ref) - { - for (auto &bound : receiver->get_specified_bounds ()) - { - const TraitReference *b = bound.get (); - if (b->is_equal (*ref)) - return true; - } - - std::vector> bounds - = Probe (receiver); - for (auto &bound : bounds) - { - const TraitReference *b = bound.first; - if (b->is_equal (*ref)) - return true; - } - - return false; - } + TraitReference *ref); private: void scan (); + void assemble_sized_builtin (); + void assemble_builtin_candidate (Analysis::RustLangItem::ItemType item); private: - TypeBoundsProbe (const TyTy::BaseType *receiver) - : TypeCheckBase (), receiver (receiver) - {} + TypeBoundsProbe (const TyTy::BaseType *receiver); const TyTy::BaseType *receiver; std::vector> trait_references; diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc index 46a14eb6e92..d4eea7ae954 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc @@ -1095,6 +1095,7 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr) return; } + fn->prepare_higher_ranked_bounds (); auto root = receiver_tyty->get_root (); if (root->get_kind () == TyTy::TypeKind::ADT) { @@ -1659,6 +1660,11 @@ TypeCheckExpr::resolve_operator_overload ( TyTy::FnType *fn = static_cast (lookup); rust_assert (fn->is_method ()); + fn->prepare_higher_ranked_bounds (); + rust_debug_loc (expr.get_locus (), "resolved operator overload to: {%u} {%s}", + candidate.candidate.ty->get_ref (), + candidate.candidate.ty->debug_str ().c_str ()); + auto root = lhs->get_root (); if (root->get_kind () == TyTy::TypeKind::ADT) { diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc b/gcc/rust/typecheck/rust-tyty-bounds.cc index b14e0c68e5a..76d2eeff8ef 100644 --- a/gcc/rust/typecheck/rust-tyty-bounds.cc +++ b/gcc/rust/typecheck/rust-tyty-bounds.cc @@ -23,6 +23,41 @@ namespace Rust { namespace Resolver { +TypeBoundsProbe::TypeBoundsProbe (const TyTy::BaseType *receiver) + : TypeCheckBase (), receiver (receiver) +{} + +std::vector> +TypeBoundsProbe::Probe (const TyTy::BaseType *receiver) +{ + TypeBoundsProbe probe (receiver); + probe.scan (); + return probe.trait_references; +} + +bool +TypeBoundsProbe::is_bound_satisfied_for_type (TyTy::BaseType *receiver, + TraitReference *ref) +{ + for (auto &bound : receiver->get_specified_bounds ()) + { + const TraitReference *b = bound.get (); + if (b->is_equal (*ref)) + return true; + } + + std::vector> bounds + = Probe (receiver); + for (auto &bound : bounds) + { + const TraitReference *b = bound.first; + if (b->is_equal (*ref)) + return true; + } + + return false; +} + void TypeBoundsProbe::scan () { @@ -57,6 +92,75 @@ TypeBoundsProbe::scan () if (!trait_ref->is_error ()) trait_references.push_back ({trait_ref, path.second}); } + + // marker traits... + assemble_sized_builtin (); +} + +void +TypeBoundsProbe::assemble_sized_builtin () +{ + const TyTy::BaseType *raw = receiver->destructure (); + + // does this thing actually implement sized? + switch (raw->get_kind ()) + { + case TyTy::ADT: + case TyTy::STR: + case TyTy::REF: + case TyTy::POINTER: + case TyTy::PARAM: + case TyTy::ARRAY: + case TyTy::SLICE: + case TyTy::FNDEF: + case TyTy::FNPTR: + case TyTy::TUPLE: + case TyTy::BOOL: + case TyTy::CHAR: + case TyTy::INT: + case TyTy::UINT: + case TyTy::FLOAT: + case TyTy::USIZE: + case TyTy::ISIZE: + assemble_builtin_candidate (Analysis::RustLangItem::SIZED); + break; + + // not-sure about this.... FIXME + case TyTy::INFER: + case TyTy::NEVER: + case TyTy::PLACEHOLDER: + case TyTy::PROJECTION: + case TyTy::DYNAMIC: + case TyTy::CLOSURE: + case TyTy::ERROR: + break; + } +} + +void +TypeBoundsProbe::assemble_builtin_candidate ( + Analysis::RustLangItem::ItemType lang_item) +{ + DefId id; + bool found_lang_item = mappings->lookup_lang_item (lang_item, &id); + if (!found_lang_item) + return; + + HIR::Item *item = mappings->lookup_defid (id); + if (item == nullptr) + return; + + rust_assert (item->get_item_kind () == HIR::Item::ItemKind::Trait); + HIR::Trait *trait = static_cast (item); + const TyTy::BaseType *raw = receiver->destructure (); + + // assemble the reference + TraitReference *trait_ref = TraitResolver::Resolve (*trait); + trait_references.push_back ({trait_ref, mappings->lookup_builtin_marker ()}); + + rust_debug ("Added builtin lang_item: %s for %s", + Analysis::RustLangItem::ToString (lang_item).c_str (), + raw->get_name ().c_str ()); } TraitReference * @@ -101,7 +205,8 @@ TypeCheckBase::get_predicate_from_bound (HIR::TypePath &type_path) = 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 + // 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, @@ -514,8 +619,8 @@ TypeBoundPredicate::lookup_associated_type (const std::string &search) { TypeBoundPredicateItem item = lookup_associated_item (search); - // only need to check that it is infact an associated type because other wise - // if it was not found it will just be an error node anyway + // only need to check that it is infact an associated type because other + // wise if it was not found it will just be an error node anyway if (!item.is_error ()) { const auto raw = item.get_raw_item (); diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc b/gcc/rust/typecheck/rust-tyty-subst.cc index e4fe30e00ea..d2f6cf607d1 100644 --- a/gcc/rust/typecheck/rust-tyty-subst.cc +++ b/gcc/rust/typecheck/rust-tyty-subst.cc @@ -119,11 +119,6 @@ SubstitutionParamMapping::fill_param_ty ( { type.inherit_bounds (*param); } - else - { - if (!param->bounds_compatible (type, locus, true)) - return false; - } if (type.get_kind () == TypeKind::PARAM) { @@ -133,8 +128,15 @@ SubstitutionParamMapping::fill_param_ty ( else { // check the substitution is compatible with bounds - if (!param->bounds_compatible (type, locus, true)) - return false; + rust_debug_loc (locus, + "fill_param_ty bounds_compatible: param %s type %s", + param->get_name ().c_str (), type.get_name ().c_str ()); + + if (!param->is_implicit_self_trait ()) + { + if (!param->bounds_compatible (type, locus, true)) + return false; + } // recursively pass this down to all HRTB's for (auto &bound : param->get_specified_bounds ()) @@ -870,10 +872,149 @@ SubstitutionRef::solve_missing_mappings_from_this (SubstitutionRef &ref, return SubstitutionArgumentMappings (resolved_mappings, {}, locus); } +Resolver::AssociatedImplTrait * +SubstitutionRef::lookup_associated_impl (const SubstitutionParamMapping &subst, + const TypeBoundPredicate &bound, + const TyTy::BaseType *binding, + bool *error_flag) const +{ + auto context = Resolver::TypeCheckContext::get (); + const Resolver::TraitReference *specified_bound_ref = bound.get (); + + // setup any associated type mappings for the specified bonds and this + // type + auto candidates = Resolver::TypeBoundsProbe::Probe (binding); + std::vector associated_impl_traits; + for (auto &probed_bound : candidates) + { + const Resolver::TraitReference *bound_trait_ref = probed_bound.first; + const HIR::ImplBlock *associated_impl = probed_bound.second; + + HirId impl_block_id = associated_impl->get_mappings ().get_hirid (); + Resolver::AssociatedImplTrait *associated = nullptr; + bool found_impl_trait + = context->lookup_associated_trait_impl (impl_block_id, &associated); + if (found_impl_trait) + { + bool found_trait = specified_bound_ref->is_equal (*bound_trait_ref); + bool found_self = associated->get_self ()->can_eq (binding, false); + if (found_trait && found_self) + { + associated_impl_traits.push_back (associated); + } + } + } + + if (associated_impl_traits.empty ()) + return nullptr; + + // This code is important when you look at slices for example when + // you have a slice such as: + // + // let slice = &array[1..3] + // + // the higher ranked bounds will end up having an Index trait + // implementation for Range so we need this code to resolve + // that we have an integer inference variable that needs to become + // a usize + // + // The other complicated issue is that we might have an intrinsic + // which requires the :Clone or Copy bound but the libcore adds + // implementations for all the integral types so when there are + // multiple candidates we need to resolve to the default + // implementation for that type otherwise its an error for + // ambiguous type bounds + + // if we have a non-general inference variable we need to be + // careful about the selection here + bool is_infer_var = binding->get_kind () == TyTy::TypeKind::INFER; + bool is_integer_infervar + = is_infer_var + && static_cast (binding)->get_infer_kind () + == TyTy::InferType::InferTypeKind::INTEGRAL; + bool is_float_infervar + = is_infer_var + && static_cast (binding)->get_infer_kind () + == TyTy::InferType::InferTypeKind::FLOAT; + + Resolver::AssociatedImplTrait *associate_impl_trait = nullptr; + if (associated_impl_traits.size () == 1) + { + // just go for it + associate_impl_trait = associated_impl_traits.at (0); + } + else if (is_integer_infervar) + { + TyTy::BaseType *type = nullptr; + bool ok = context->lookup_builtin ("i32", &type); + rust_assert (ok); + + for (auto &impl : associated_impl_traits) + { + bool found = impl->get_self ()->is_equal (*type); + if (found) + { + associate_impl_trait = impl; + break; + } + } + } + else if (is_float_infervar) + { + TyTy::BaseType *type = nullptr; + bool ok = context->lookup_builtin ("f64", &type); + rust_assert (ok); + + for (auto &impl : associated_impl_traits) + { + bool found = impl->get_self ()->is_equal (*type); + if (found) + { + associate_impl_trait = impl; + break; + } + } + } + + if (associate_impl_trait == nullptr) + { + // go for the first one? or error out? + auto &mappings = *Analysis::Mappings::get (); + const auto &type_param = subst.get_generic_param (); + const auto *trait_ref = bound.get (); + + RichLocation r (type_param.get_locus ()); + r.add_range (bound.get_locus ()); + r.add_range (mappings.lookup_location (binding->get_ref ())); + + rust_error_at (r, "ambiguous type bound for trait %s and type %s", + trait_ref->get_name ().c_str (), + binding->get_name ().c_str ()); + + *error_flag = true; + return nullptr; + } + + return associate_impl_trait; +} + +void +SubstitutionRef::prepare_higher_ranked_bounds () +{ + for (const auto &subst : get_substs ()) + { + const TyTy::ParamType *pty = subst.get_param_ty (); + for (const auto &bound : pty->get_specified_bounds ()) + { + const auto ref = bound.get (); + ref->clear_associated_type_projections (); + } + } +} + bool SubstitutionRef::monomorphize () { - auto context = Resolver::TypeCheckContext::get (); for (const auto &subst : get_substs ()) { const TyTy::ParamType *pty = subst.get_param_ty (); @@ -887,136 +1028,16 @@ SubstitutionRef::monomorphize () for (const auto &bound : pty->get_specified_bounds ()) { - const Resolver::TraitReference *specified_bound_ref = bound.get (); - - // setup any associated type mappings for the specified bonds and this - // type - auto candidates = Resolver::TypeBoundsProbe::Probe (binding); - std::vector associated_impl_traits; - for (auto &probed_bound : candidates) + bool error_flag = false; + auto associated + = lookup_associated_impl (subst, bound, binding, &error_flag); + if (associated != nullptr) { - const Resolver::TraitReference *bound_trait_ref - = probed_bound.first; - const HIR::ImplBlock *associated_impl = probed_bound.second; - - HirId impl_block_id - = associated_impl->get_mappings ().get_hirid (); - Resolver::AssociatedImplTrait *associated = nullptr; - bool found_impl_trait - = context->lookup_associated_trait_impl (impl_block_id, - &associated); - if (found_impl_trait) - { - bool found_trait - = specified_bound_ref->is_equal (*bound_trait_ref); - bool found_self - = associated->get_self ()->can_eq (binding, false); - if (found_trait && found_self) - { - associated_impl_traits.push_back (associated); - } - } + associated->setup_associated_types (binding, bound); } - if (!associated_impl_traits.empty ()) - { - // This code is important when you look at slices for example when - // you have a slice such as: - // - // let slice = &array[1..3] - // - // the higher ranked bounds will end up having an Index trait - // implementation for Range so we need this code to resolve - // that we have an integer inference variable that needs to become - // a usize - // - // The other complicated issue is that we might have an intrinsic - // which requires the :Clone or Copy bound but the libcore adds - // implementations for all the integral types so when there are - // multiple candidates we need to resolve to the default - // implementation for that type otherwise its an error for - // ambiguous type bounds - - if (associated_impl_traits.size () == 1) - { - Resolver::AssociatedImplTrait *associate_impl_trait - = associated_impl_traits.at (0); - associate_impl_trait->setup_associated_types (binding, bound); - } - else - { - // if we have a non-general inference variable we need to be - // careful about the selection here - bool is_infer_var - = binding->get_kind () == TyTy::TypeKind::INFER; - bool is_integer_infervar - = is_infer_var - && static_cast (binding) - ->get_infer_kind () - == TyTy::InferType::InferTypeKind::INTEGRAL; - bool is_float_infervar - = is_infer_var - && static_cast (binding) - ->get_infer_kind () - == TyTy::InferType::InferTypeKind::FLOAT; - - Resolver::AssociatedImplTrait *associate_impl_trait = nullptr; - if (is_integer_infervar) - { - TyTy::BaseType *type = nullptr; - bool ok = context->lookup_builtin ("i32", &type); - rust_assert (ok); - - for (auto &impl : associated_impl_traits) - { - bool found = impl->get_self ()->is_equal (*type); - if (found) - { - associate_impl_trait = impl; - break; - } - } - } - else if (is_float_infervar) - { - TyTy::BaseType *type = nullptr; - bool ok = context->lookup_builtin ("f64", &type); - rust_assert (ok); - - for (auto &impl : associated_impl_traits) - { - bool found = impl->get_self ()->is_equal (*type); - if (found) - { - associate_impl_trait = impl; - break; - } - } - } - - if (associate_impl_trait == nullptr) - { - // go for the first one? or error out? - auto &mappings = *Analysis::Mappings::get (); - const auto &type_param = subst.get_generic_param (); - const auto *trait_ref = bound.get (); - - RichLocation r (type_param.get_locus ()); - r.add_range (bound.get_locus ()); - r.add_range ( - mappings.lookup_location (binding->get_ref ())); - - rust_error_at ( - r, "ambiguous type bound for trait %s and type %s", - trait_ref->get_name ().c_str (), - binding->get_name ().c_str ()); - - return false; - } - - associate_impl_trait->setup_associated_types (binding, bound); - } - } + if (error_flag) + return false; } } diff --git a/gcc/rust/typecheck/rust-tyty-subst.h b/gcc/rust/typecheck/rust-tyty-subst.h index fd5826102b3..365fdb6c042 100644 --- a/gcc/rust/typecheck/rust-tyty-subst.h +++ b/gcc/rust/typecheck/rust-tyty-subst.h @@ -298,7 +298,13 @@ public: // TODO comment BaseType *infer_substitions (Location locus); - // TODO comment + // this clears any possible projections from higher ranked trait bounds which + // could be hanging around from a previous resolution + void prepare_higher_ranked_bounds (); + + // FIXME + // this is bad name for this, i think it should be something like + // compute-higher-ranked-bounds bool monomorphize (); // TODO comment @@ -308,6 +314,10 @@ public: SubstitutionArgumentMappings get_used_arguments () const; protected: + Resolver::AssociatedImplTrait *lookup_associated_impl ( + const SubstitutionParamMapping &subst, const TypeBoundPredicate &bound, + const TyTy::BaseType *binding, bool *error_flag) const; + std::vector substitutions; SubstitutionArgumentMappings used_arguments; }; diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index fe5aa2b059c..d0d36ac0a11 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -31,6 +31,7 @@ #include "rust-hir-type-bounds.h" #include "rust-hir-trait-resolve.h" #include "rust-tyty-cmp.h" +#include "rust-type-util.h" #include "options.h" @@ -266,6 +267,7 @@ BaseType::get_locus () const return ident.locus; } +// FIXME this is missing locus bool BaseType::satisfies_bound (const TypeBoundPredicate &predicate) const { @@ -277,12 +279,67 @@ BaseType::satisfies_bound (const TypeBoundPredicate &predicate) const return true; } + bool satisfied = false; auto probed = Resolver::TypeBoundsProbe::Probe (this); for (const auto &b : probed) { const Resolver::TraitReference *bound = b.first; if (bound->satisfies_bound (*query)) + { + satisfied = true; + break; + } + } + + if (!satisfied) + return false; + + for (const auto &b : probed) + { + const Resolver::TraitReference *bound = b.first; + if (!bound->is_equal (*query)) + continue; + + // builtin ones have no impl-block this needs fixed and use a builtin node + // of somekind + if (b.second == nullptr) return true; + + // need to check that associated types can match as well + const HIR::ImplBlock &impl = *(b.second); + for (const auto &item : impl.get_impl_items ()) + { + TyTy::BaseType *impl_item_ty = nullptr; + Analysis::NodeMapping i = item->get_impl_mappings (); + bool query_ok = Resolver::query_type (i.get_hirid (), &impl_item_ty); + if (!query_ok) + return false; + + std::string item_name = item->get_impl_item_name (); + TypeBoundPredicateItem lookup + = predicate.lookup_associated_item (item_name); + if (lookup.is_error ()) + return false; + + const auto *item_ref = lookup.get_raw_item (); + TyTy::BaseType *bound_ty = item_ref->get_tyty (); + + // compare the types + if (!bound_ty->can_eq (impl_item_ty, false)) + { + RichLocation r (mappings->lookup_location (get_ref ())); + r.add_range (predicate.get_locus ()); + r.add_range (mappings->lookup_location (i.get_hirid ())); + + rust_error_at ( + r, "expected %<%s%> got %<%s%>", + bound_ty->destructure ()->get_name ().c_str (), + impl_item_ty->destructure ()->get_name ().c_str ()); + return false; + } + } + + return true; } return false; @@ -2827,18 +2884,18 @@ ParamType::ParamType (std::string symbol, Location locus, HirId ref, {Resolver::CanonicalPath::new_seg (UNKNOWN_NODEID, symbol), locus}, specified_bounds, refs), - symbol (symbol), param (param) + is_trait_self (false), symbol (symbol), param (param) {} -ParamType::ParamType (std::string symbol, Location locus, HirId ref, - HirId ty_ref, HIR::GenericParam ¶m, +ParamType::ParamType (bool is_trait_self, std::string symbol, Location locus, + HirId ref, HirId ty_ref, HIR::GenericParam ¶m, std::vector specified_bounds, std::set refs) : BaseType (ref, ty_ref, TypeKind::PARAM, {Resolver::CanonicalPath::new_seg (UNKNOWN_NODEID, symbol), locus}, specified_bounds, refs), - symbol (symbol), param (param) + is_trait_self (is_trait_self), symbol (symbol), param (param) {} HIR::GenericParam & @@ -2906,8 +2963,9 @@ ParamType::can_eq (const BaseType *other, bool emit_errors) const BaseType * ParamType::clone () const { - return new ParamType (get_symbol (), ident.locus, get_ref (), get_ty_ref (), - param, get_specified_bounds (), get_combined_refs ()); + return new ParamType (is_trait_self, get_symbol (), ident.locus, get_ref (), + get_ty_ref (), param, get_specified_bounds (), + get_combined_refs ()); } BaseType * @@ -2997,6 +3055,18 @@ ParamType::handle_substitions (SubstitutionArgumentMappings &subst_mappings) return p; } +void +ParamType::set_implicit_self_trait () +{ + is_trait_self = true; +} + +bool +ParamType::is_implicit_self_trait () const +{ + return is_trait_self; +} + // StrType StrType::StrType (HirId ref, std::set refs) diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index d2cf5b07fc1..64b9379a1c0 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -267,8 +267,8 @@ public: std::vector specified_bounds, std::set refs = std::set ()); - ParamType (std::string symbol, Location locus, HirId ref, HirId ty_ref, - HIR::GenericParam ¶m, + ParamType (bool is_trait_self, std::string symbol, Location locus, HirId ref, + HirId ty_ref, HIR::GenericParam ¶m, std::vector specified_bounds, std::set refs = std::set ()); @@ -298,7 +298,11 @@ public: ParamType *handle_substitions (SubstitutionArgumentMappings &mappings); + void set_implicit_self_trait (); + bool is_implicit_self_trait () const; + private: + bool is_trait_self; std::string symbol; HIR::GenericParam ¶m; }; diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index 1fc32038d19..a9687040144 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -96,9 +96,16 @@ static const HirId kDefaultCrateNumBegin = 0; Mappings::Mappings () : crateNumItr (kDefaultCrateNumBegin), currentCrateNum (UNKNOWN_CREATENUM), hirIdIter (kDefaultHirIdBegin), nodeIdIter (kDefaultNodeIdBegin) -{} +{ + Analysis::NodeMapping node (0, 0, 0, 0); + builtinMarker + = new HIR::ImplBlock (node, {}, {}, nullptr, nullptr, HIR::WhereClause ({}), + Positive, + HIR::Visibility (HIR::Visibility::VisType::PUBLIC), + {}, {}, Location ()); +} -Mappings::~Mappings () {} +Mappings::~Mappings () { delete builtinMarker; } Mappings * Mappings::get () @@ -1035,5 +1042,11 @@ Mappings::lookup_ast_item (NodeId id, AST::Item **result) return true; } +HIR::ImplBlock * +Mappings::lookup_builtin_marker () +{ + return builtinMarker; +} + } // namespace Analysis } // namespace Rust diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h index 13cae717031..9d6affa27e0 100644 --- a/gcc/rust/util/rust-hir-map.h +++ b/gcc/rust/util/rust-hir-map.h @@ -296,6 +296,8 @@ public: void insert_ast_item (AST::Item *item); bool lookup_ast_item (NodeId id, AST::Item **result); + HIR::ImplBlock *lookup_builtin_marker (); + private: Mappings (); @@ -304,6 +306,7 @@ private: HirId hirIdIter; NodeId nodeIdIter; std::map localIdIter; + HIR::ImplBlock *builtinMarker; std::map crate_node_to_crate_num; std::map ast_crate_mappings; diff --git a/gcc/testsuite/rust/compile/issue-1725-1.rs b/gcc/testsuite/rust/compile/issue-1725-1.rs new file mode 100644 index 00000000000..1ace9fbbf30 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-1725-1.rs @@ -0,0 +1,19 @@ +mod core { + mod ops { + #[lang = "add"] + pub trait Add { + type Output; + + fn add(self, rhs: Rhs) -> Self::Output; + } + } +} + +pub fn foo>(a: T) -> i32 { + a + a +} + +pub fn main() { + foo(123f32); + // { dg-error "bounds not satisfied for f32 .Add. is not satisfied" "" { target *-*-* } .-1 } +} diff --git a/gcc/testsuite/rust/compile/issue-1725-2.rs b/gcc/testsuite/rust/compile/issue-1725-2.rs new file mode 100644 index 00000000000..8bfd0bbd924 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-1725-2.rs @@ -0,0 +1,28 @@ +mod core { + mod ops { + #[lang = "add"] + pub trait Add { + type Output; + + fn add(self, rhs: Rhs) -> Self::Output; + } + } +} + +impl core::ops::Add for f32 { + type Output = f32; + + fn add(self, rhs: Self) -> Self::Output { + self + rhs + } +} + +pub fn foo>(a: T) -> i32 { + a + a +} + +pub fn main() { + foo(123f32); + // { dg-error "expected .i32. got .f32." "" { target *-*-* } .-1 } + // { dg-error "bounds not satisfied for f32 .Add. is not satisfied" "" { target *-*-* } .-2 } +} From patchwork Wed Apr 5 14:04: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: 79732 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp368427vqo; Wed, 5 Apr 2023 07:56:42 -0700 (PDT) X-Google-Smtp-Source: AKy350bDKSVHaxxBE/XXWfrN5tHbuFRWnUMUqbPg7tlif8Z9bQL2//6z0b1Vt6QrcSHHedAD/I+j X-Received: by 2002:a17:906:a107:b0:93f:50c7:2f5f with SMTP id t7-20020a170906a10700b0093f50c72f5fmr3540207ejy.63.1680706601912; Wed, 05 Apr 2023 07:56:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706601; cv=none; d=google.com; s=arc-20160816; b=OyAXlHtZIHK3x0H1+rXl3VMGG3pkXoF8+LYbD7hIvsdEdJZPPqeMdDXHyjhRoIOD52 8KseUMCDWVFiYkIawW0OH8ZQLuoI99PAofwmwuRhbSDfF+AFi7uQPb4G5KB06vA5NEA9 mC/uXN/PbWKCkNgeQZHGNFi4FOwSeC8vH/LeHuiq2q+2KSTvebJPAiBOfxGdGMl5nEYG Z78UDh3ZMIHQtO0cVtjSt+UiUF9hNlC/nrW7060msrUsYw1fAYyFNl8RvE+4iRpaDve0 b4ItfAo0mAWeYJ8DTHCS2ecOfPWRmf0M5XbDf7cBHJuO4Ro0vExoOgWu2FZYxtjsXYgK Rt6A== 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=pd1LW5kF+OVTppK0uwtkvuvfwUqH2Okyajo7DuJVbXA=; b=nLtR5FatLdTDk/MNpjPWHIAXVwttxI9wmOmuCZ5OXavI16uj2vjCD+fQu0QDX/mJWV Q4WIWWQYTKz+gfSIZf7cYKRAJY40uL2u1XO0reNn4ga1GeZL0WbpN5uWHjE50sVmx7hP LFD7Ko3TGgPizzVhkr3JnWq094wGyjMqkMJdfyGIAZ4pqTWxPKtYrAXxEtufHU7KySlW VGqvoPMGd4F/brFqQ0diqS6zmbXfyodzEH/3Tm/Wr6cgx0qVswTZ/pVuD3nRxz/eBUP6 qs8Il6zryJaUbSGfCZUnJ8CLHlxM0fM+PwPgBiFwaP1a895whNBfYmp0M8zXe4K9qyNY pAgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=ZSq6VViO; 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 y22-20020a50e616000000b004c007c7905asi1080511edm.484.2023.04.05.07.56.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:56:41 -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=ZSq6VViO; 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 6668538E2EAA for ; Wed, 5 Apr 2023 14:21:07 +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 293493853828 for ; Wed, 5 Apr 2023 14:06:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 293493853828 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 n19-20020a05600c501300b003f064936c3eso1253142wmr.0 for ; Wed, 05 Apr 2023 07:06:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703581; 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=pd1LW5kF+OVTppK0uwtkvuvfwUqH2Okyajo7DuJVbXA=; b=ZSq6VViO9uSf9di2sUDQCykYTBXD9UvR2UN9aFfMfyg3X5TSX3MH5bYgZcQEtE2ZtD gKChfbP+opxTBonqKrq+GtcEn+xHq/5dE3iUCeHfHdZ09olwieZKitdHZ5xA1g4NycLn v2BnIjzaOfbqz5K54xDXM3swQH9+sDGeWS94OrhHUmQfbA4DeLnwNZn0QsAsYhXJtQVF juKCkx6yVVi03B/zfT4NTHjk0N52Fob23XNzw3z4UzbckDitFuTENhtqkf78XPuK9SRb u2L4JXyCHgOpNF1V8CVi/bypU4CQUONIDnMIjzMYvc6RSKf5kzzqGTaoRF4N9a4EiGhG eRZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703581; 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=pd1LW5kF+OVTppK0uwtkvuvfwUqH2Okyajo7DuJVbXA=; b=I7u8o3vNVtZu+5bWukEUtkRLj5joSLCRnr9v2ELmWqEi9BO6nj3rnfD5olVyu8/wmm Esb/S74c09l95rSLV7EVKg+jc5D0j3Z1tf/kNsxr4Fc5iUSfh/4wXyC7j/Rv9VoQoXeS lTD6omBiAfW6Lgu1GiFtvnDg5/BfMSHWI0/aVIuU0yRrT2nekAmTpbsyOktbHHoAW33s URsJBskfsFwapjCmaB+QT+b1HADqPXs7Pf2vmi+fPzo2mZ1ECM8/LHYnTg8Hy5mSwjWb nuEP3UNTYClQlRKDSCHASsHw9hcL3YpcOTZEgG/GobZdIzWSR3nbax8to4f3upEP2S4C bCVQ== X-Gm-Message-State: AAQBX9eb52pGkDy7CCDaYm5anzntqwQs/cTYVo1l6RhGMvQgDEH20Skh u6wR+g8h6k3WJV4P0+xSynq25F+2a1Fwe7fBUw== X-Received: by 2002:a05:600c:215:b0:3eb:f5a2:2d67 with SMTP id 21-20020a05600c021500b003ebf5a22d67mr4837584wmi.33.1680703581421; Wed, 05 Apr 2023 07:06:21 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:21 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 76/88] gccrs: Fix regression in testcase Date: Wed, 5 Apr 2023 16:04:00 +0200 Message-Id: <20230405140411.3016563-77-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.5 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?1762348605349261918?= X-GMAIL-MSGID: =?utf-8?q?1762348605349261918?= From: Philip Herron Fixes #776 Signed-off-by: Philip Herron gcc/testsuite/ChangeLog: * rust/compile/torture/traits10.rs: Fix test-case --- .../rust/compile/torture/traits10.rs | 64 ++++++++++++++++++- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/rust/compile/torture/traits10.rs b/gcc/testsuite/rust/compile/torture/traits10.rs index a02927007b3..4cf36e3c6f1 100644 --- a/gcc/testsuite/rust/compile/torture/traits10.rs +++ b/gcc/testsuite/rust/compile/torture/traits10.rs @@ -1,5 +1,65 @@ -trait Foo // where -// Self: Sized, +#[lang = "sized"] +pub trait Sized {} + +#[lang = "clone"] +pub trait Clone: Sized { + fn clone(&self) -> Self; + + fn clone_from(&mut self, source: &Self) { + *self = source.clone() + } +} + +mod impls { + use super::Clone; + + macro_rules! impl_clone { + ($($t:ty)*) => { + $( + impl Clone for $t { + fn clone(&self) -> Self { + *self + } + } + )* + } + } + + impl_clone! { + usize u8 u16 u32 u64 // u128 + isize i8 i16 i32 i64 // i128 + f32 f64 + bool char + } +} + +#[lang = "copy"] +pub trait Copy: Clone { + // Empty. +} + +mod copy_impls { + use super::Copy; + + macro_rules! impl_copy { + ($($t:ty)*) => { + $( + impl Copy for $t {} + )* + } + } + + impl_copy! { + usize u8 u16 u32 u64 // u128 + isize i8 i16 i32 i64 // i128 + f32 f64 + bool char + } +} + +trait Foo +where + Self: Sized, { fn get(self) -> i32; From patchwork Wed Apr 5 14:04: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: 79731 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp368249vqo; Wed, 5 Apr 2023 07:56:23 -0700 (PDT) X-Google-Smtp-Source: AKy350YebkMvsuS5eftC/KdliANxQT6+3jGP3qRXrfUbT6sNSKm+zvQiChoD6LUzXcSDB7ATgwpu X-Received: by 2002:a05:6402:6c5:b0:4fc:782c:dca3 with SMTP id n5-20020a05640206c500b004fc782cdca3mr2217611edy.28.1680706583135; Wed, 05 Apr 2023 07:56:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706583; cv=none; d=google.com; s=arc-20160816; b=kpehrBUhtG64xqIrpDij9DnrGcSkT25V7bMMyy0OhSyaBjl9rm6jzL3xZDkBWciPVZ TF1gLqepiW0w/T0ViKyRfjey6iiir4rxdlhXRIXQbonDQNpSu6XvYCx043z+OcCf4sNq BPd1WG+2o1Gi6WCGZsIEDGOUi6nZt8RZYuYlmVgQ253bP05vVBMvur+E72OO0mvzdJly ZWcfQ0K2pl2pxcm4dF5xxIIKAOfabAUybEmC5nn2oocfylndYbH0U5MevcJpbiE8YEUF diyTcoS9aAnYEv19M/eR+omsbWNh2DHzBfs5NNBWaFrM5qGayjo4dUZM06boJQZFp1cs Pd7Q== 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=3zDr2w7pk1cslRSvMIj2yHzE8LzV/97G4xc1EVkXTqk=; b=BnpAZ3ByH5vTUpBgGQ6IHIBD73dph1vmTz7Y76lXgVDZW6SEI8lIrX6V+j8JwTsaxB bHAzOpZ3s6WoRBEpkk4JnueGSlxoY/+e9yR24lH1GsUxzHG25/2RWT/VXVTyUXmeowf0 iqd/nc04Bm3oI4souvO1Z6pGHhGTsmYMNFc2LJtCYM0FMjVcf2Z3kuKnvsNk1BlRNRDX Okcov/MQiT2Kwttyd411nuLfKlX034bIE1Hr0xpkMoi4Q+HpbmQYa7xBU4w8QlKY/s6E LS//63/vv+wE9DWGxD3fB8H7pfvVJX3ZTIYZenm1PqbhXL3VcQ6o19REsNZlihKuf3bc id7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=f9RfKgn0; 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 t11-20020aa7d70b000000b00501d48232ecsi2590212edq.404.2023.04.05.07.56.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:56:23 -0700 (PDT) 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=f9RfKgn0; 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 3825838DCFDD for ; Wed, 5 Apr 2023 14:20:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id 9457A388202A for ; Wed, 5 Apr 2023 14:06:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9457A388202A 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-x335.google.com with SMTP id n9-20020a05600c4f8900b003f05f617f3cso2915897wmq.2 for ; Wed, 05 Apr 2023 07:06:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703582; 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=3zDr2w7pk1cslRSvMIj2yHzE8LzV/97G4xc1EVkXTqk=; b=f9RfKgn0SIPeQeXhf6b8Ie2+hy3DXWRabQVFRyvjXeC3n2IUDRIhFKp6gFQ0ReGnaz f+NMn0HuTcvbRqOnydm4JZfZHP1wrlWcPhTg+9fN6KxaQ9OFIojGgbv1HwSvd0SksDOw DnkUt2OubxjOt85AoB6nbS3As6/2eftSVHkPLOPHaNDkTWrBqlJ/2eJJp4zyFqWiFNRf p2P6ERXs3bP6673sms3OtyJyE5J1TCwbow77R+/bensHo+S8H/DfKVaRbbHanEZygLHS 1PEFv3cxJIqHhd01lhAdm959miiPpb/8fMWftlDymPomVaaw1yicYEAss982VTLsxw+9 bYNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703582; 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=3zDr2w7pk1cslRSvMIj2yHzE8LzV/97G4xc1EVkXTqk=; b=1+5vYFdYb5uVbVQXqSxmA6zibaroPhj1zELXXo1w0rPH8rnD0EoSMcNp1Bpj9GgMyo f6mOMaSbnm0EenjKTWtldNi31N44bpohRHFD8WZjF3uDYWv6c4y2A+6qtpbDwt72cP8F RsNNFaacgv+tsAE9kEg7hE2AeYrBherXdgR3fG/Swl8lg9Jp2Ru1z5JZvEymjqVW+1oj cB1Nq0Qb5XjbbcdehGEUaBIj67cRNHBID6AXD/rR1mXjD0/Qd+FLCzQt4EHm0s0WK2GY lAij+njfrZnoqsDPtibEmxbyB1iGpVkOU4+cfne5t1FvH6S4iKCQ68QoUY7D7YtduhVL OzJw== X-Gm-Message-State: AAQBX9eXZq7Xk6SgwERzf8nJ+HPeYmr62ccoB0JxCgXOdy0F92Xw1EoV kV31GcJ5KOCyZz6UWAcu0gPtQnD9pWvoStrCvA== X-Received: by 2002:a7b:cbcc:0:b0:3ed:2eb5:c2e8 with SMTP id n12-20020a7bcbcc000000b003ed2eb5c2e8mr5302949wmi.10.1680703582282; Wed, 05 Apr 2023 07:06:22 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:22 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [committed 77/88] gccrs: Add trailing newline Date: Wed, 5 Apr 2023 16:04:01 +0200 Message-Id: <20230405140411.3016563-78-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.5 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?1762348586146269005?= X-GMAIL-MSGID: =?utf-8?q?1762348586146269005?= From: Owen Avery gcc/rust/ChangeLog: * checks/errors/rust-feature-gate.h: Add trailing newline before EOF. Signed-off-by: Owen Avery --- gcc/rust/checks/errors/rust-feature-gate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/rust/checks/errors/rust-feature-gate.h b/gcc/rust/checks/errors/rust-feature-gate.h index 6768c4c2498..05789cf4751 100644 --- a/gcc/rust/checks/errors/rust-feature-gate.h +++ b/gcc/rust/checks/errors/rust-feature-gate.h @@ -193,4 +193,4 @@ private: std::set valid_features; }; } // namespace Rust -#endif \ No newline at end of file +#endif From patchwork Wed Apr 5 14:04: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: 79730 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp367837vqo; Wed, 5 Apr 2023 07:55:40 -0700 (PDT) X-Google-Smtp-Source: AKy350asDizo+MXzUQ+ttR7kiTNdIfYaB2gUX0p3J6IxavPLZKwebNK55NpFoo3aaQ1ZS3GxvWcL X-Received: by 2002:a17:906:198e:b0:92f:de0d:104b with SMTP id g14-20020a170906198e00b0092fde0d104bmr3277002ejd.9.1680706539927; Wed, 05 Apr 2023 07:55:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706539; cv=none; d=google.com; s=arc-20160816; b=HjlfILFgKxMqoOrAH9vfA+b51n64evdGQAdm1yyXK4betFNzb+9jg+pA4RvY3dK1Qp kpo7Wia5Qza3D1LBw1qwUFUn5H8aDscsjJ0rtN8OmDNlmCEigQXVDQwbIabK80FPcbuO Pf/pg8KUbzF73suyEXclMkHj1C6qEZNFB5TABMAHXT0moDibJD4wRTJcAR6BijeaXuvA 01O+DPxk8G8hpJNHTssW/bN7siqQsP8ITIcTFCQThBlsGfclTF9weXJuivb33C+K1C3e 6C/dtL3w6x4zivUGsK0HARk0XHS69ukHSjbvQsyv/X8w+nDSM/TML2l23zSqbooSsm0l bNnA== 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=ZJGzI+1+8dpVv/ULvDh1J2DnRrWjTQOcHB2rF70bhBw=; b=aRyx6MfTZefN/kT4UTf3a3ZP+4sHsUDPWhjlgQtEqHcugeMFKa1kFBsKfuGJzBComj ZTx55ZW4Pbr3g2217f+UnpiVj0QhdzV/onyWmwI6sAvQF1I5FjCiT9joWa41anK/VcCs QVstGSOQ1yxEBJ0x5IgKyk6eafdVOY3VjTplvJd8cFUdWjYRjWgu/IcjYgdUiyRZdWtY DilD1j3lEw38tWftjSeF0HKF8JHaKZli60IAbL9syGoakHqLAjPFMycSyGbe+hWbgD79 9ih5NQkp7sMLAttr6nUT2Uv9cOzV+i+crfx3C4yNX5Xm0iB+QqV0j3gJtZaVSUwlo04i xA3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=GVpKDNxL; 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 r16-20020a170906a21000b0092be4b3c198si12221512ejy.662.2023.04.05.07.55.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:55:39 -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=GVpKDNxL; 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 8E031382C15D for ; Wed, 5 Apr 2023 14:20: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 61465388203D for ; Wed, 5 Apr 2023 14:06:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 61465388203D 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 v1so36338008wrv.1 for ; Wed, 05 Apr 2023 07:06:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703583; 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=ZJGzI+1+8dpVv/ULvDh1J2DnRrWjTQOcHB2rF70bhBw=; b=GVpKDNxLoimU7ID2QG4rZHqSaf2otqDhgXmXvtNFuv9tSmEBIERuB6dfaTpGNtn/wh lgK6afjAPrrXLDIch2/PAT+FQuL/lyOsP2OCG0E8mpSlIty7IKb8G9CVtrihqDLkpOuL BBYAQ1uFjwG7SVS6gqY4IZzvtUEpxGPSgvb5extuRKV4qdom69vnVbLUzk9EpSK2RqZP zC7YuaQ1nGOWDn2mwQHQevonPLPBXLaoycPR2aB8LFFcwYn3r+OL5V75PUs1CmWENwZC msK6WzO5ZOHt/2rNKRb0ONRyhEr5GaT9HMVC6DVmdfEUo7qHasi0BNqz3DldqPBqrWFT mp0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703583; 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=ZJGzI+1+8dpVv/ULvDh1J2DnRrWjTQOcHB2rF70bhBw=; b=ykee2g0NnXvWNjebsj0aHWa/yaGVk2FafryU6ez7ruiLuMnqeHSBRTXhPPFvEIihFX aNQPZXh37RGwKstc3wJ5ybCemRSSkuS2c/kKL7n8fU1st/zqyePeicvPNtjO1A+Qtwuk YRIa6x90KfmAHcQMIZn2jQMLuLZlDgz7irHi9emoTZBkNUbPG9vTF9OLYWKLpJTb1h+8 P/arqK8lIj1o/s+Sti4NUp2ikzMDhirt8unSp6J1Ysc68BpykAZmo8r6sXavqewR6Cju GSu2wusE42mzpaw0eirbu2OgSFjYIH8FvENMOZFYkwyAABx9q2SoVd2RUJEVvOG+i1Qu Otlg== X-Gm-Message-State: AAQBX9cjS5AgKNQ8x5NjQ12ejUyPqgymAYv4GahXW2PvAGDqPu8K05Ch ES1UmbLFo4zn2ZkAJDOlcSEVLxXjRSyVh0obNg== X-Received: by 2002:adf:cf09:0:b0:2d6:adfe:cea5 with SMTP id o9-20020adfcf09000000b002d6adfecea5mr4067907wrj.68.1680703582853; Wed, 05 Apr 2023 07:06:22 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:22 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 78/88] gccrs: builtins: Return empty list of tokens instead of nullptr Date: Wed, 5 Apr 2023 16:04:02 +0200 Message-Id: <20230405140411.3016563-79-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.2 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?1762348540631065633?= X-GMAIL-MSGID: =?utf-8?q?1762348540631065633?= From: Arthur Cohen gcc/rust/ChangeLog: * expand/rust-macro-builtins.cc (MacroBuiltin::include_handler): Do not return nullptr token in expansion of `include!()` gcc/testsuite/ChangeLog: * rust/compile/empty.in: New test. * rust/compile/include_empty.rs: New test. --- gcc/rust/expand/rust-macro-builtins.cc | 15 +++++++++++++-- gcc/testsuite/rust/compile/empty.in | 1 + gcc/testsuite/rust/compile/include_empty.rs | 8 ++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/rust/compile/empty.in create mode 100644 gcc/testsuite/rust/compile/include_empty.rs diff --git a/gcc/rust/expand/rust-macro-builtins.cc b/gcc/rust/expand/rust-macro-builtins.cc index 3b6f69bbd69..97594921dec 100644 --- a/gcc/rust/expand/rust-macro-builtins.cc +++ b/gcc/rust/expand/rust-macro-builtins.cc @@ -752,8 +752,19 @@ MacroBuiltin::include_handler (Location invoc_locus, AST::MacroInvocData &invoc) nodes.push_back (node); } - // FIXME: Do not return an empty token vector here - return AST::Fragment (nodes, nullptr); + // FIXME: This returns an empty vector of tokens and works fine, but is that + // the expected behavior? `include` macros are a bit harder to reason about + // since they include tokens. Furthermore, our lexer has no easy way to return + // a slice of tokens like the MacroInvocLexer. So it gets even harder to + // extrac tokens from here. For now, let's keep it that way and see if it + // eventually breaks, but I don't expect it to cause many issues since the + // list of tokens is only used when a macro invocation mixes eager + // macro invocations and already expanded tokens. Think + // `concat!(a!(), 15, b!())`. We need to be able to expand a!(), expand b!(), + // and then insert the `15` token in between. In the case of `include!()`, we + // only have one argument. So it's either going to be a macro invocation or a + // string literal. + return AST::Fragment (nodes, std::vector> ()); } AST::Fragment diff --git a/gcc/testsuite/rust/compile/empty.in b/gcc/testsuite/rust/compile/empty.in new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/gcc/testsuite/rust/compile/empty.in @@ -0,0 +1 @@ + diff --git a/gcc/testsuite/rust/compile/include_empty.rs b/gcc/testsuite/rust/compile/include_empty.rs new file mode 100644 index 00000000000..28e940fa0ac --- /dev/null +++ b/gcc/testsuite/rust/compile/include_empty.rs @@ -0,0 +1,8 @@ +#[rustc_builtin_macro] +macro_rules! include { + () => {}; +} + +include!("empty.in"); + +fn main() {} From patchwork Wed Apr 5 14:04: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: 79735 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp369498vqo; Wed, 5 Apr 2023 07:58:39 -0700 (PDT) X-Google-Smtp-Source: AKy350bqGzYCqTGIaSR5QAe6TUYnrONV/b2GPYqYsg1P01bOrPuhug8afQCzzxO2gdpxkJXs8bK3 X-Received: by 2002:a05:6402:3da:b0:4fb:6357:f393 with SMTP id t26-20020a05640203da00b004fb6357f393mr1964646edw.1.1680706719578; Wed, 05 Apr 2023 07:58:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706719; cv=none; d=google.com; s=arc-20160816; b=fs2HlxFn5tPqvaAX2OOUIS6Jd3VD0tFvpGRF1uicT6Z+rNJPa2UI1twu/kDZexoTHf Hfp5Hy3ZjeA8oGOOoAgRBXsap3TTuCHLat3MyGo9urazdUxxiClWwLhl4bgVcTFplmDC GrbL4JJPoHCRqBThNYOgRmBPUnvMbaxa9IdYmsSh3ZW/G1iPtDPXijSlqCc5OKWNHX8g uxht5OM5MdwHbrCsnIymPs/hLqHcnEQ3uIata/LI1712HnvUFJdN0VlHWErPCg6m3p3g Ro+/tEA7OuKwBY3mcRj6Wm1ZOW2JqxGpIK/0PhxfMTb8GvrzZndfn83i/i4+lNHsVACl EGbA== 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=kLznMUDJawxqb6N37scjNOdNKXOyNzghs6Adhm0FgLY=; b=S4GljMk49eZaJ66Spd9bNFPNKdCgYGgRSi+bXkuLK26AyLB+k5YekyQL/n687vAKyX qRAfNm+362pa7jHvWKgsjyk6IaI+qAetint+9aWAl/NdSPaNM1VHLPFNKucey+BQ3dfU 9LvrSgmvs4rHwhkKY4S8yKFiVYoM0w9Y5YxyrjYDsrSIZghqtzJDYM+GVrStyuoMhWhV zawA2eBxiDS+0fOOmlQNVNQur+H0jDsnxEwytPE6OPbRkcyTKntyKLWqTbEp31e4Fgp7 aBYReYnWW37A5WlXwBXPI90gYrUvRNaNh9u88DrGI0RBaZCe3dMBiOE0EGpg6Up1KGJ9 44+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=YL0UXBe4; 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 y22-20020a50e616000000b004c007c7905asi1083516edm.484.2023.04.05.07.58.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:58:39 -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=YL0UXBe4; 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 4565F38CA3D9 for ; Wed, 5 Apr 2023 14:21:56 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id 6143B3877020 for ; Wed, 5 Apr 2023 14:06:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6143B3877020 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-x32c.google.com with SMTP id p34so20959298wms.3 for ; Wed, 05 Apr 2023 07:06:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703583; 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=kLznMUDJawxqb6N37scjNOdNKXOyNzghs6Adhm0FgLY=; b=YL0UXBe4rI0jOTOj7itvZ1+xA+P+XfVGpiqTXQN8uhcWU17t8lNql2pmpeIsdDbN0v VrhD438aMuBFpTVd7x5Bm/TPeEuWy5AvT1ouycGswr+KDNP42TS8hBfJz45JihGEZ/jm KiZXdd0Ipr4SN8tKDQKYnTXqQQgvUua6EbfcKgIYLLE/KWefg1eOOi/v227arJFLCX/7 Cl9EiGgALyePuIVJ8kN9dbZs0dAWStNg+pG4TBxIFR0otT92xNQRsUdUPPnNFdec657R 7EhjJ5vI/i17xK1ZZ1sliU1iAdI5iB93vMLGSUlAc6cwLCpDqfjV9DFz6IshxUh/IBle 8e0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703583; 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=kLznMUDJawxqb6N37scjNOdNKXOyNzghs6Adhm0FgLY=; b=qPuHShkbRDURyLYcVxDlKqsSmm+HmU1aeWtiRyYzOYfSVzn1RW3K4S7AEFpXl0oTHf 42xx1qMH4nf9AFl54G5UefEVFJ/Wjj3KSXkMpm7rQyQSw8khzP4omlDRYwP8/tu5BXgn 0oZ/UHWLBnHKgCtsSeWeVdPtkzE02w/cBSiAt3AAyjIoLODqp1ac3zd4exH7ncw1+dPf DKHdNfTBz8BdPdcerRfc/If8CHZQ0AYPGJEuDtHAP44aEubVAGvBV3Dw1VVJu22v/tZ3 lkM1O3qHGzzpmzXX/Omt/shK1AIuhsESEmC5SVueWmBa5U92iREhYevPoR/2KTlq3Kie FEYg== X-Gm-Message-State: AAQBX9fi3Ytbr4dVT4j481JNtrrk9pVyBy+RHkaROOSN106kb4F+B0Ke t2gaBH0hoQqhr/Q9pD33tYSc5nZCTppy0ID3EQ== X-Received: by 2002:a7b:cb97:0:b0:3ed:5d41:f9a7 with SMTP id m23-20020a7bcb97000000b003ed5d41f9a7mr5103611wmi.2.1680703583661; Wed, 05 Apr 2023 07:06:23 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:23 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [committed 79/88] gccrs: Fix formatting Date: Wed, 5 Apr 2023 16:04:03 +0200 Message-Id: <20230405140411.3016563-80-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.2 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?1762348729306859147?= X-GMAIL-MSGID: =?utf-8?q?1762348729306859147?= From: Owen Avery gcc/rust/ChangeLog: * ast/rust-pattern.h: Fix formatting. Signed-off-by: Owen Avery --- gcc/rust/ast/rust-pattern.h | 70 ++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/gcc/rust/ast/rust-pattern.h b/gcc/rust/ast/rust-pattern.h index cf5d2ead10d..0e2f56e3216 100644 --- a/gcc/rust/ast/rust-pattern.h +++ b/gcc/rust/ast/rust-pattern.h @@ -763,7 +763,7 @@ struct StructPatternElements { private: // bool has_struct_pattern_fields; - std::vector > fields; + std::vector> fields; bool has_struct_pattern_etc; std::vector struct_pattern_etc_attrs; @@ -788,7 +788,7 @@ public: // Constructor for StructPatternElements with both (potentially) StructPatternElements ( - std::vector > fields, + std::vector> fields, std::vector etc_attrs) : fields (std::move (fields)), has_struct_pattern_etc (true), struct_pattern_etc_attrs (std::move (etc_attrs)) @@ -796,7 +796,7 @@ public: // Constructor for StructPatternElements with no StructPatternEtc StructPatternElements ( - std::vector > fields) + std::vector> fields) : fields (std::move (fields)), has_struct_pattern_etc (false), struct_pattern_etc_attrs () {} @@ -832,18 +832,17 @@ public: static StructPatternElements create_empty () { return StructPatternElements ( - std::vector > ()); + std::vector> ()); } std::string as_string () const; // TODO: seems kinda dodgy. Think of better way. - std::vector > & - get_struct_pattern_fields () + std::vector> &get_struct_pattern_fields () { return fields; } - const std::vector > & + const std::vector> & get_struct_pattern_fields () const { return fields; @@ -956,10 +955,10 @@ protected: // Class for non-ranged tuple struct pattern patterns class TupleStructItemsNoRange : public TupleStructItems { - std::vector > patterns; + std::vector> patterns; public: - TupleStructItemsNoRange (std::vector > patterns) + TupleStructItemsNoRange (std::vector> patterns) : patterns (std::move (patterns)) {} @@ -991,8 +990,8 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: seems kinda dodgy. Think of better way. - std::vector > &get_patterns () { return patterns; } - const std::vector > &get_patterns () const + std::vector> &get_patterns () { return patterns; } + const std::vector> &get_patterns () const { return patterns; } @@ -1011,12 +1010,12 @@ protected: // Class for ranged tuple struct pattern patterns class TupleStructItemsRange : public TupleStructItems { - std::vector > lower_patterns; - std::vector > upper_patterns; + std::vector> lower_patterns; + std::vector> upper_patterns; public: - TupleStructItemsRange (std::vector > lower_patterns, - std::vector > upper_patterns) + TupleStructItemsRange (std::vector> lower_patterns, + std::vector> upper_patterns) : lower_patterns (std::move (lower_patterns)), upper_patterns (std::move (upper_patterns)) {} @@ -1056,21 +1055,21 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: seems kinda dodgy. Think of better way. - std::vector > &get_lower_patterns () + std::vector> &get_lower_patterns () { return lower_patterns; } - const std::vector > &get_lower_patterns () const + const std::vector> &get_lower_patterns () const { return lower_patterns; } // TODO: seems kinda dodgy. Think of better way. - std::vector > &get_upper_patterns () + std::vector> &get_upper_patterns () { return upper_patterns; } - const std::vector > &get_upper_patterns () const + const std::vector> &get_upper_patterns () const { return upper_patterns; } @@ -1233,10 +1232,10 @@ TuplePatternItemsSingle(*this); // Class representing TuplePattern patterns where there are multiple patterns class TuplePatternItemsMultiple : public TuplePatternItems { - std::vector > patterns; + std::vector> patterns; public: - TuplePatternItemsMultiple (std::vector > patterns) + TuplePatternItemsMultiple (std::vector> patterns) : patterns (std::move (patterns)) {} @@ -1268,8 +1267,8 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: seems kinda dodgy. Think of better way. - std::vector > &get_patterns () { return patterns; } - const std::vector > &get_patterns () const + std::vector> &get_patterns () { return patterns; } + const std::vector> &get_patterns () const { return patterns; } @@ -1291,13 +1290,12 @@ protected: // Class representing TuplePattern patterns where there are a range of patterns class TuplePatternItemsRanged : public TuplePatternItems { - std::vector > lower_patterns; - std::vector > upper_patterns; + std::vector> lower_patterns; + std::vector> upper_patterns; public: - TuplePatternItemsRanged ( - std::vector > lower_patterns, - std::vector > upper_patterns) + TuplePatternItemsRanged (std::vector> lower_patterns, + std::vector> upper_patterns) : lower_patterns (std::move (lower_patterns)), upper_patterns (std::move (upper_patterns)) {} @@ -1338,21 +1336,21 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: seems kinda dodgy. Think of better way. - std::vector > &get_lower_patterns () + std::vector> &get_lower_patterns () { return lower_patterns; } - const std::vector > &get_lower_patterns () const + const std::vector> &get_lower_patterns () const { return lower_patterns; } // TODO: seems kinda dodgy. Think of better way. - std::vector > &get_upper_patterns () + std::vector> &get_upper_patterns () { return upper_patterns; } - const std::vector > &get_upper_patterns () const + const std::vector> &get_upper_patterns () const { return upper_patterns; } @@ -1503,14 +1501,14 @@ protected: // AST node representing patterns that can match slices and arrays class SlicePattern : public Pattern { - std::vector > items; + std::vector> items; Location locus; NodeId node_id; public: std::string as_string () const override; - SlicePattern (std::vector > items, Location locus) + SlicePattern (std::vector> items, Location locus) : items (std::move (items)), locus (locus), node_id (Analysis::Mappings::get ()->get_next_node_id ()) {} @@ -1546,8 +1544,8 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: seems kinda dodgy. Think of better way. - std::vector > &get_items () { return items; } - const std::vector > &get_items () const + std::vector> &get_items () { return items; } + const std::vector> &get_items () const { return items; } From patchwork Wed Apr 5 14:04: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: 79734 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp369290vqo; Wed, 5 Apr 2023 07:58:17 -0700 (PDT) X-Google-Smtp-Source: AKy350bmGU6ewLyHh00zTb+IWCvHmvQEHAddFxB83aZacKCgZtWe8QjCsXBWEik9FGxmUHNTy3B1 X-Received: by 2002:a17:906:ccc6:b0:8b1:2c37:ae97 with SMTP id ot6-20020a170906ccc600b008b12c37ae97mr2744994ejb.43.1680706697004; Wed, 05 Apr 2023 07:58:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706696; cv=none; d=google.com; s=arc-20160816; b=Qj7Ya8LxSH65tDpxMQutHOOJPGq8pHshuB+ekdM9dUyx3CnpNv7GQhZXWNiZQrqDcS pABuFyDx7FOQte0kNhUVGiZEioNRARxBwnRpYknSkszu7Sq/JdLfc4Fa9coShVJgts8o Z5G7pVwUDx1QpV0rNVQROKnaq5ZRgSOaOzpQQGYAp9Ql3rjaLsEX0P2EGBE/+lOK1Tjw Tcncc3WnTnS0BnLZaNxPKxBbsozXHTLPrnRFcjZvRuvy9Mf+ZBeXj7oyD+akkNzt66ih WvCuB+yc02d3jm1iAlwOS7sALGBzQJdsTiEQUI6ZMVMxKrP/6OSeIS4TQ/KDaGo5bRZk gWaw== 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=Frv8N//+9CHKGSSr17XaGIK5vrIich+zp+eoq5pK8vM=; b=eJEYNtlroXKUPBolhYxiwd4iSfi/ixmeq2VLcDMcYNQ3KtlSZm2/Xdx+QmNu+U8jk+ 6HenUhyWkwFAVlEIz7JWTcE3kt2z9eT9ER491Fy9pQoYXVKNA5LgR4sUxGVJge3PqSFw pvVsUIgGLkZMUix+VDdiunm7K0WL8y0PvC9GcbgPpqi0NvBGW/vMvnHPZuFFttx+gSuX 7nsDE5d5j4WoBbUw/CG1hEHG4Tj7g9eFWoM+bUf9a4BuWlEVGSvlBIb9noXKds7zQFXy YkUAxevGBZkiGnQg0Jtnyq5vWbQGOMlPnpH0y1tlYJMXkUgeMEyXp8TbCMpMNAvCldd1 onXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=W1dG7XYK; 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 hd13-20020a170907968d00b00947d5dd48e3si2784236ejc.574.2023.04.05.07.58.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:58:16 -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=W1dG7XYK; 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 4656739960F3 for ; Wed, 5 Apr 2023 14:21:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id 146F4385354E for ; Wed, 5 Apr 2023 14:06:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 146F4385354E 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-x335.google.com with SMTP id hg25-20020a05600c539900b003f05a99a841so4128682wmb.3 for ; Wed, 05 Apr 2023 07:06:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703584; 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=Frv8N//+9CHKGSSr17XaGIK5vrIich+zp+eoq5pK8vM=; b=W1dG7XYK3rYGZlDLlmnRajgPzIY+CiiLXcsMLK3O93CsXxL9A7xNW1nD/Y8bTubsdB l67167hyQY2kfexYtIVWfpJloTgeBPILbd22ZAGvQNCHnDwgCmJiLpN2/MzRlhIs2XYB 6GF4Bl0fcTt6e7KwdELHaR2kJcYG1/BJPtyLGVloCGdqZaH0hLVuTBecja7gpnXMkAP1 SYLHH5BTZN5UiMOHDGiJrp5W+rFsdIXZH233iO0YUN52WvvWoD03e1URy74/lRQCn5t0 zepatFy/39/1Bm9Gmpn30pFNBPuO0M6pE1E1yK2dVm7hWSYc9oAse42TVhgxzAl+H3+V KXxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703584; 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=Frv8N//+9CHKGSSr17XaGIK5vrIich+zp+eoq5pK8vM=; b=jhVaxsH0cbWrfVZ5Ea5GKcPizC2YM5Oqt4hULKJ47Z3jteqlqeRhOwHs7ez3fcqhGA 64dg/coZHHK30vphpvVjSgD+h1bSuOXyOtzNDfZxhcIwSgi1a+fZOL+ywqtWmhMbkch9 6OJALeIKkxDOhLuchp2SGv8dsJ4kx6gM9OhXu+GMdGd5GOkCWnV8nAu6HUfr0m52N+su ngEIsOs0FuzRwWulYTkv22C8auA6h4VAgSDwhzFEF39IFZH8xVXJZhj6ghccEx9swrw7 WAyCLqwC1qm3t5kCihRSWa4JG25n9AN5JOLh0OVsZj6V3uHeLwy9wai5lf8F5+rrEqBg LzgA== X-Gm-Message-State: AAQBX9f01mtidH9cmqyghM8lve56s1QgqnUvAxF053wZQO4BXPoNkzzZ l6OeaKRTYEWlTiVFsEFrAIsu7C2qRCxeeBnXGg== X-Received: by 2002:a7b:c8d3:0:b0:3f0:3d41:bda2 with SMTP id f19-20020a7bc8d3000000b003f03d41bda2mr4636655wml.39.1680703584370; Wed, 05 Apr 2023 07:06:24 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:23 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [committed 80/88] gccrs: Add AST::AltPattern class Date: Wed, 5 Apr 2023 16:04:04 +0200 Message-Id: <20230405140411.3016563-81-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.5 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?1762348705730353161?= X-GMAIL-MSGID: =?utf-8?q?1762348705730353161?= From: Owen Avery gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add AltPattern visitor. * ast/rust-ast-dump.h: (Dump::visit): Add AltPattern visitor. * ast/rust-ast-full-decls.h (class AltPattern): Add declaration. * ast/rust-ast-visitor.h: (ASTVisitor::visit): Add AltPattern visitor. * ast/rust-ast.cc (AltPattern::as_string): Add definition. (AltPattern::accept_vis): Add definition. * ast/rust-pattern.h (class AltPattern): Add declaration. * checks/errors/rust-feature-gate.h: (FeatureGate::visit) Add AltPattern visitor * expand/rust-attribute-visitor.cc (AttrVisitor::visit): Add AltPattern visitor. * expand/rust-attribute-visitor.h: (AttrVisitor::visit): Add AltPattern visitor. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Add AltPattern visitor. * hir/rust-ast-lower-base.h: (ASTLoweringBase::visit): Add AltPattern visitor. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Add AltPattern visitor. * resolve/rust-ast-resolve-base.h: (ResolverBase::visit): Add AltPattern visitor. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Add AltPattern visitor. * resolve/rust-early-name-resolver.h: (EarlyNameResolver::visit): Add AltPattern visitor. * util/rust-attributes.cc (AttributeChecker::visit): Add AltPattern visitor. * util/rust-attributes.h: (AttributeChecker::visit): Add AltPattern visitor. Signed-off-by: Owen Avery --- gcc/rust/ast/rust-ast-dump.cc | 4 ++ gcc/rust/ast/rust-ast-dump.h | 1 + gcc/rust/ast/rust-ast-full-decls.h | 1 + gcc/rust/ast/rust-ast-visitor.h | 1 + gcc/rust/ast/rust-ast.cc | 17 +++++ gcc/rust/ast/rust-pattern.h | 66 ++++++++++++++++++++ gcc/rust/checks/errors/rust-feature-gate.h | 1 + gcc/rust/expand/rust-attribute-visitor.cc | 14 +++++ gcc/rust/expand/rust-attribute-visitor.h | 1 + gcc/rust/hir/rust-ast-lower-base.cc | 3 + gcc/rust/hir/rust-ast-lower-base.h | 1 + gcc/rust/resolve/rust-ast-resolve-base.cc | 4 ++ gcc/rust/resolve/rust-ast-resolve-base.h | 1 + gcc/rust/resolve/rust-early-name-resolver.cc | 7 +++ gcc/rust/resolve/rust-early-name-resolver.h | 1 + gcc/rust/util/rust-attributes.cc | 4 ++ gcc/rust/util/rust-attributes.h | 1 + 17 files changed, 128 insertions(+) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 58eb35ad1db..10fb313c2c7 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1678,6 +1678,10 @@ void Dump::visit (SlicePattern &) {} +void +Dump::visit (AltPattern &) +{} + // rust-stmt.h void Dump::visit (EmptyStmt &) diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h index 56918f5fc98..dfe6db0dd96 100644 --- a/gcc/rust/ast/rust-ast-dump.h +++ b/gcc/rust/ast/rust-ast-dump.h @@ -293,6 +293,7 @@ private: void visit (TuplePattern &pattern); void visit (GroupedPattern &pattern); void visit (SlicePattern &pattern); + void visit (AltPattern &pattern); // rust-stmt.h void visit (EmptyStmt &stmt); diff --git a/gcc/rust/ast/rust-ast-full-decls.h b/gcc/rust/ast/rust-ast-full-decls.h index 58b12a1be0e..9d7b00ac5a2 100644 --- a/gcc/rust/ast/rust-ast-full-decls.h +++ b/gcc/rust/ast/rust-ast-full-decls.h @@ -249,6 +249,7 @@ class TuplePatternItemsRanged; class TuplePattern; class GroupedPattern; class SlicePattern; +class AltPattern; // rust-type.h class TraitBound; diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h index aa59a115ee6..1083e834770 100644 --- a/gcc/rust/ast/rust-ast-visitor.h +++ b/gcc/rust/ast/rust-ast-visitor.h @@ -203,6 +203,7 @@ public: virtual void visit (TuplePattern &pattern) = 0; virtual void visit (GroupedPattern &pattern) = 0; virtual void visit (SlicePattern &pattern) = 0; + virtual void visit (AltPattern &pattern) = 0; // rust-stmt.h virtual void visit (EmptyStmt &stmt) = 0; diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index 972cba2e7bb..07983b7da06 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -2704,6 +2704,17 @@ SlicePattern::as_string () const return str; } +std::string +AltPattern::as_string () const +{ + std::string str ("AltPattern: "); + + for (const auto &pattern : alts) + str += "\n " + pattern->as_string (); + + return str; +} + std::string TuplePatternItemsMultiple::as_string () const { @@ -5649,6 +5660,12 @@ SlicePattern::accept_vis (ASTVisitor &vis) vis.visit (*this); } +void +AltPattern::accept_vis (ASTVisitor &vis) +{ + vis.visit (*this); +} + void EmptyStmt::accept_vis (ASTVisitor &vis) { diff --git a/gcc/rust/ast/rust-pattern.h b/gcc/rust/ast/rust-pattern.h index 0e2f56e3216..a62e9b98d93 100644 --- a/gcc/rust/ast/rust-pattern.h +++ b/gcc/rust/ast/rust-pattern.h @@ -1563,6 +1563,72 @@ protected: } }; +// AST node for alternate patterns +// joins together what are technically 'PatternNoTopAlt's +class AltPattern : public Pattern +{ + std::vector> alts; + Location locus; + NodeId node_id; + +public: + std::string as_string () const override; + + AltPattern (std::vector> alts, Location locus) + : alts (std::move (alts)), locus (locus), + node_id (Analysis::Mappings::get ()->get_next_node_id ()) + {} + + // Copy constructor with vector clone + AltPattern (AltPattern const &other) : locus (other.locus) + { + node_id = other.node_id; + alts.reserve (other.alts.size ()); + for (const auto &e : other.alts) + alts.push_back (e->clone_pattern ()); + } + + // Overloaded assignment operator to vector clone + AltPattern &operator= (AltPattern const &other) + { + locus = other.locus; + node_id = other.node_id; + + alts.reserve (other.alts.size ()); + for (const auto &e : other.alts) + alts.push_back (e->clone_pattern ()); + + return *this; + } + + // move constructors + AltPattern (AltPattern &&other) = default; + AltPattern &operator= (AltPattern &&other) = default; + + Location get_locus () const override final { return locus; } + + void accept_vis (ASTVisitor &vis) override; + + // TODO: seems kinda dodgy. Think of better way. + std::vector> &get_alts () { return alts; } + const std::vector> &get_alts () const + { + return alts; + } + + NodeId get_node_id () const { return node_id; } + + NodeId get_pattern_node_id () const override final { return node_id; } + +protected: + /* Use covariance to implement clone function as returning this object rather + * than base */ + AltPattern *clone_pattern_impl () const override + { + return new AltPattern (*this); + } +}; + // Moved definition to rust-path.h class PathPattern; diff --git a/gcc/rust/checks/errors/rust-feature-gate.h b/gcc/rust/checks/errors/rust-feature-gate.h index 05789cf4751..20af14719bb 100644 --- a/gcc/rust/checks/errors/rust-feature-gate.h +++ b/gcc/rust/checks/errors/rust-feature-gate.h @@ -169,6 +169,7 @@ public: void visit (AST::TuplePattern &pattern) override {} void visit (AST::GroupedPattern &pattern) override {} void visit (AST::SlicePattern &pattern) override {} + void visit (AST::AltPattern &pattern) override {} void visit (AST::EmptyStmt &stmt) override {} void visit (AST::LetStmt &stmt) override {} void visit (AST::ExprStmtWithoutBlock &stmt) override {} diff --git a/gcc/rust/expand/rust-attribute-visitor.cc b/gcc/rust/expand/rust-attribute-visitor.cc index 9abec9221ab..3a94699558d 100644 --- a/gcc/rust/expand/rust-attribute-visitor.cc +++ b/gcc/rust/expand/rust-attribute-visitor.cc @@ -3152,6 +3152,20 @@ AttrVisitor::visit (AST::SlicePattern &pattern) // TODO: quit stripping now? or keep going? } } +void +AttrVisitor::visit (AST::AltPattern &pattern) +{ + // can't strip individual patterns, only sub-patterns + for (auto &alt : pattern.get_alts ()) + { + alt->accept_vis (*this); + + if (alt->is_marked_for_strip ()) + rust_error_at (alt->get_locus (), + "cannot strip pattern in this position"); + // TODO: quit stripping now? or keep going? + } +} void AttrVisitor::visit (AST::EmptyStmt &) diff --git a/gcc/rust/expand/rust-attribute-visitor.h b/gcc/rust/expand/rust-attribute-visitor.h index 9b0e315fc08..2d10735436f 100644 --- a/gcc/rust/expand/rust-attribute-visitor.h +++ b/gcc/rust/expand/rust-attribute-visitor.h @@ -258,6 +258,7 @@ public: void visit (AST::TuplePattern &pattern) override; void visit (AST::GroupedPattern &pattern) override; void visit (AST::SlicePattern &pattern) override; + void visit (AST::AltPattern &pattern) override; void visit (AST::EmptyStmt &) override; void visit (AST::LetStmt &stmt) override; diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc index 33795726b2f..5d7b5d21340 100644 --- a/gcc/rust/hir/rust-ast-lower-base.cc +++ b/gcc/rust/hir/rust-ast-lower-base.cc @@ -461,6 +461,9 @@ ASTLoweringBase::visit (AST::GroupedPattern &) void ASTLoweringBase::visit (AST::SlicePattern &) {} +void +ASTLoweringBase::visit (AST::AltPattern &) +{} // rust-stmt.h void diff --git a/gcc/rust/hir/rust-ast-lower-base.h b/gcc/rust/hir/rust-ast-lower-base.h index 1af44aa239f..85343aacdab 100644 --- a/gcc/rust/hir/rust-ast-lower-base.h +++ b/gcc/rust/hir/rust-ast-lower-base.h @@ -231,6 +231,7 @@ public: virtual void visit (AST::TuplePattern &pattern); virtual void visit (AST::GroupedPattern &pattern); virtual void visit (AST::SlicePattern &pattern); + virtual void visit (AST::AltPattern &pattern); // rust-stmt.h virtual void visit (AST::EmptyStmt &stmt); diff --git a/gcc/rust/resolve/rust-ast-resolve-base.cc b/gcc/rust/resolve/rust-ast-resolve-base.cc index 0a78d26bcd4..5b3f4a0ae11 100644 --- a/gcc/rust/resolve/rust-ast-resolve-base.cc +++ b/gcc/rust/resolve/rust-ast-resolve-base.cc @@ -582,6 +582,10 @@ void ResolverBase::visit (AST::SlicePattern &) {} +void +ResolverBase::visit (AST::AltPattern &) +{} + void ResolverBase::visit (AST::EmptyStmt &) {} diff --git a/gcc/rust/resolve/rust-ast-resolve-base.h b/gcc/rust/resolve/rust-ast-resolve-base.h index 9d88f8fd5d3..aab1324c454 100644 --- a/gcc/rust/resolve/rust-ast-resolve-base.h +++ b/gcc/rust/resolve/rust-ast-resolve-base.h @@ -178,6 +178,7 @@ public: void visit (AST::TuplePattern &); void visit (AST::GroupedPattern &); void visit (AST::SlicePattern &); + void visit (AST::AltPattern &); void visit (AST::EmptyStmt &); void visit (AST::LetStmt &); diff --git a/gcc/rust/resolve/rust-early-name-resolver.cc b/gcc/rust/resolve/rust-early-name-resolver.cc index 5f11ae239bd..f5054f964c7 100644 --- a/gcc/rust/resolve/rust-early-name-resolver.cc +++ b/gcc/rust/resolve/rust-early-name-resolver.cc @@ -1052,6 +1052,13 @@ EarlyNameResolver::visit (AST::SlicePattern &pattern) item->accept_vis (*this); } +void +EarlyNameResolver::visit (AST::AltPattern &pattern) +{ + for (auto &alt : pattern.get_alts ()) + alt->accept_vis (*this); +} + void EarlyNameResolver::visit (AST::EmptyStmt &) {} diff --git a/gcc/rust/resolve/rust-early-name-resolver.h b/gcc/rust/resolve/rust-early-name-resolver.h index 21b92e9b7a4..84ee518e23b 100644 --- a/gcc/rust/resolve/rust-early-name-resolver.h +++ b/gcc/rust/resolve/rust-early-name-resolver.h @@ -249,6 +249,7 @@ private: virtual void visit (AST::TuplePattern &pattern); virtual void visit (AST::GroupedPattern &pattern); virtual void visit (AST::SlicePattern &pattern); + virtual void visit (AST::AltPattern &pattern); virtual void visit (AST::EmptyStmt &stmt); virtual void visit (AST::LetStmt &stmt); virtual void visit (AST::ExprStmtWithoutBlock &stmt); diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc index 0458f6902b7..4f63dd09dac 100644 --- a/gcc/rust/util/rust-attributes.cc +++ b/gcc/rust/util/rust-attributes.cc @@ -767,6 +767,10 @@ void AttributeChecker::visit (AST::SlicePattern &) {} +void +AttributeChecker::visit (AST::AltPattern &) +{} + // rust-stmt.h void AttributeChecker::visit (AST::EmptyStmt &) diff --git a/gcc/rust/util/rust-attributes.h b/gcc/rust/util/rust-attributes.h index c08378cf774..805e3a8f40a 100644 --- a/gcc/rust/util/rust-attributes.h +++ b/gcc/rust/util/rust-attributes.h @@ -242,6 +242,7 @@ private: void visit (AST::TuplePattern &pattern); void visit (AST::GroupedPattern &pattern); void visit (AST::SlicePattern &pattern); + void visit (AST::AltPattern &pattern); // rust-stmt.h void visit (AST::EmptyStmt &stmt); From patchwork Wed Apr 5 14:04: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: 79718 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp363239vqo; Wed, 5 Apr 2023 07:48:00 -0700 (PDT) X-Google-Smtp-Source: AKy350b83xUgcHRECF1+1ggLHaVdGH5hqcaC3lecYuvjEeZR+SfEf0j14AsVGPtDByUGmq/MdkAd X-Received: by 2002:a17:906:3b4e:b0:932:fc34:88f with SMTP id h14-20020a1709063b4e00b00932fc34088fmr2998552ejf.11.1680706080713; Wed, 05 Apr 2023 07:48:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706080; cv=none; d=google.com; s=arc-20160816; b=m68d2wsQJMZVjvbRr8zeJ9UmUuXVbtu37UvNZmT9NsP5e/492es3mPz8X9fj3AxNL9 1rUSrBdknkuKdmCJm8tRT1yV4BYYooOSQ05mJ3dIMRSkXjrxi6SfSDcxd+BHwRjctNtc 7o1k06pXjzXLR3zaDfQRSkKuaa/G7fq8Q8e5HEPAVpcXaWeT9eSwypyCWivd97cIDI/k KDv39TzcxfZwUSTBwcMvPXm6IcftGaeTrdJqkzJmeyZpsRDJZiMPuBNE20cJ2GsdQFeF V3s1e0gy3sUXFYQ2RgTNFFRSVQMGDL/J1S4IhBkUaLLpBeubG7TUomluty6EhpMalr2n 4Wrw== 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=zCZC3xHACqHMlCWfqnr+JlV98oSyoB9gbvAMgMf9+VE=; b=ZjGlAQReezHum0M50YbrcjOh8/9g4WL5LF1/0cp1xaN+K/oSEAb0GEqIV2QAVkjA2E kSKtVFGQI172gk1YXIgTz0aC12zQi4+R+p1DLZx4OVN3PHWLGRDdl4h+nknxtbE01Dyy EvI37288MMCP0PwrqXSbHyvjJkotxLCvlHx209IudfmKpy+Yv/UUOmOy4xymmsYW/sK2 jHZcHd2nJoRLYIOSmir6goZOgVFHP8eSZPKyvnkkTMT5yA1KobLUFPYBqqNnd4ftOTOm SXJkcBIAfy+AXn8+oJEOCXWg59PZxD5yXc1r2dzCXoFwGUEm8cEiBnzZxHMARfSV8kMf mSsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@embecosm.com header.s=google header.b=eyNmOq16; 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 y10-20020a1709064b0a00b008c1d4ed00d3si696174eju.792.2023.04.05.07.48.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:48:00 -0700 (PDT) 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=eyNmOq16; 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 AF6FD38C90C2 for ; Wed, 5 Apr 2023 14:17:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id B4DF0388266A for ; Wed, 5 Apr 2023 14:06:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B4DF0388266A 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-x331.google.com with SMTP id n10-20020a05600c4f8a00b003ee93d2c914so23483429wmq.2 for ; Wed, 05 Apr 2023 07:06:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703585; 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=zCZC3xHACqHMlCWfqnr+JlV98oSyoB9gbvAMgMf9+VE=; b=eyNmOq16VwK6d0kwD7Ay8wsTKgy/Tjq358KXESB426Dg4lMyBlm8MiSfi5zMayiHJU O8WpsBjtbgp61JXZePw4Al3qH07LTlpMTWlXYYh/XHZqraVN7upzgtDXUZbuc2pbAydi J4oJZ2oI88Ung2f/cVUeSMcg/PwFGrho+XO3WjYDduCcZBHyHXlrIsevxAHZb7+8JZZh 4ADfph/ippywHFJ64Mc31dcDORlhp15fgKA9CelFmVfXbuxuYQi88uI4RTw/Mi5XOKxz Xu0lBMoVWDBYZr4AFFO1R4h0GxBlGqx6nABiH7aGruu6tDFTd2Yaxmyn+pxt8kF5LRzb 0I8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703585; 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=zCZC3xHACqHMlCWfqnr+JlV98oSyoB9gbvAMgMf9+VE=; b=PhJPC4NyH27VmDTw0HWFyMd1OmtT78ChF36mnvmGg6VfplFWnK3HEb9zC4HAh13f3V DO4D6Q5zpr2fI6SGxou58An+vm+c/bBIqyufdMnr1kMebgXwQ3h8mBzrxlTKTw6iMKnS EWEavuB09khI3LnXOwLIL5xXamqXmAyUwUFbxSeO1t4R5ojTAGvfIwgKiwosXd8dShon 0vp9ti4EXJEBex43HWmIcUfXWMPWjaIMgKnTjQ1iljNyOsv5V8t+STYpDXHAkQvUVKdx 5miOJQbG8q2UwLk8slUxD5knXdHnJ7yLU8ZyW8a+IqrTV6tJZC+Ym2Qr6E8ZtVye+JQk P03g== X-Gm-Message-State: AAQBX9cX6levzsAeQ2KHKF4ln36I7tgPZhkBoYczAmKfVxx6KCWTqdq1 r4dXngolz6fS/r+IZZmcZXWlwxgeat1g7PyA/g== X-Received: by 2002:a7b:c5cd:0:b0:3ea:d611:f8 with SMTP id n13-20020a7bc5cd000000b003ead61100f8mr4903692wmk.38.1680703585074; Wed, 05 Apr 2023 07:06:25 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:24 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Thomas Schwinge Subject: [committed 81/88] gccrs: Fix up DejaGnu directives in 'rust/compile/issue-1830_{bytes, str}.rs' test cases [#1838] Date: Wed, 5 Apr 2023 16:04:05 +0200 Message-Id: <20230405140411.3016563-82-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.2 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?1762348059196948560?= X-GMAIL-MSGID: =?utf-8?q?1762348059196948560?= From: Thomas Schwinge 'dg-excess-errors' "indicates that the test is expected to fail due to compiler messages that are not handled by 'dg-error', [etc.]". It's argument doesn't specify the message to match but just just a comment. Here, however, we'd like to match specific compiler messages, so we should use 'dg-error', etc. Use the magic line number zero as the compiler error diagnostic doesn't tell which line the error occurred on (separate issue to resolve). This gives us: -XFAIL: rust/compile/issue-1830_str.rs (test for excess errors) +PASS: rust/compile/issue-1830_bytes.rs at line 8 (test for errors, line ) +PASS: rust/compile/issue-1830_bytes.rs (test for excess errors) -XFAIL: rust/compile/issue-1830_bytes.rs (test for excess errors) +PASS: rust/compile/issue-1830_str.rs at line 8 (test for errors, line ) +PASS: rust/compile/issue-1830_str.rs (test for excess errors) Fix-up for recent GCC/Rust master branch #1838 commit cf9ed4001eec6a22686d19a13f7de8ac94f9cb2a "testsuite: Add empty string macro test". gcc/testsuite/ * rust/compile/issue-1830_bytes.rs: Fix up DejaGnu directives. * rust/compile/issue-1830_str.rs: Likewise. --- gcc/testsuite/rust/compile/issue-1830_bytes.rs | 3 ++- gcc/testsuite/rust/compile/issue-1830_str.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/rust/compile/issue-1830_bytes.rs b/gcc/testsuite/rust/compile/issue-1830_bytes.rs index dcc53b73b19..997d4ca0cdc 100644 --- a/gcc/testsuite/rust/compile/issue-1830_bytes.rs +++ b/gcc/testsuite/rust/compile/issue-1830_bytes.rs @@ -4,5 +4,6 @@ macro_rules! include_bytes { } fn main() { - include_bytes!(""); // { dg-excess-errors "Is a directory" } + include_bytes!(""); + // { dg-error {cannot open filename [^\n\r]+: Is a directory} {} { target *-*-* } 0 } } diff --git a/gcc/testsuite/rust/compile/issue-1830_str.rs b/gcc/testsuite/rust/compile/issue-1830_str.rs index 6cf835ba9bd..fcf2dc988d3 100644 --- a/gcc/testsuite/rust/compile/issue-1830_str.rs +++ b/gcc/testsuite/rust/compile/issue-1830_str.rs @@ -4,5 +4,6 @@ macro_rules! include_str { } fn main() { - include_str!(""); // { dg-excess-errors "Is a directory" } + include_str!(""); + // { dg-error {cannot open filename [^\n\r]+: Is a directory} {} { target *-*-* } 0 } } From patchwork Wed Apr 5 14:04: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: 79737 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp370338vqo; Wed, 5 Apr 2023 08:00:05 -0700 (PDT) X-Google-Smtp-Source: AKy350bJEGiXW6QSsrD3roQwVUdkjGARuLYVFaBylrdo5clKRaLzz4rvglyRR93orM/YObAXOWYK X-Received: by 2002:a17:906:b852:b0:92b:34cf:16a with SMTP id ga18-20020a170906b85200b0092b34cf016amr2905519ejb.52.1680706805247; Wed, 05 Apr 2023 08:00:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706805; cv=none; d=google.com; s=arc-20160816; b=Z0bwgUNx7m2527MKqNEpKfCc4LPiTfvYxN9f20lUx+jTNeusfYz5Jx2vqlJvDD2aRA WQAKO49qcIIpWtrQkxXm/iOwJhu20tg0IcIyn8jKLqz4jBPmcBDl3Jug0W/MsIni1neE PXVtSV/1I/TL1F6HE9l3Ty4PaKNtPTGjK9foWewPZ43YXJdiEOY0Ogavk6s1Ru7vWwTQ hQH+YbX+vxF/TDv2hveAEAp4UYUKsbRnWW+n5dx3/pJeJbUxenN3OJ1ySYLYgnpCozjz Ezx4bYH/UtX0jo+PSeFnm1MV81Q17a2gO0TNnI7b8BvHX6n9/qgcHEO0ooFIBeSHGiqS Y/7A== 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=EJKj0OiP57/QFDp2NaE0NMVgLiOm8ahCDUSXGS1CdzA=; b=Pt1DaA/GtV7tBsYczpyE8+FTFGpCpfuTvbnl2/rdpulVeLJdisMSMkFlzXJwED1aHr 7z2KFs7Eu1cUyh69uY1o9wJXVjTlpH51N3AW+bmI5/P/rcP+8XAEtWnriLMcZQI6ZRg3 b1CBEy1J0V2/YY900zNuucH6E/o6HXC4BO5rswWPcAszkM9g1LHN6LLrGZNvI7d4SKjJ PvGcGGHyIEXdJEUyhJxCWw2f9YQzB3TDlMvOBi8OemTtTx2JpLT4cx3qPY57Gms57ELo 85maNe9rhINgrV57IsQV/nSPJTaFoOzu2EJJuqboxcJ+2ZKjMla7u0pTnWMgBItZtI9o R4TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=hYXZnRdh; 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 q1-20020a170906144100b009332b99a1d0si902464ejc.857.2023.04.05.08.00.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 08:00:05 -0700 (PDT) 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=hYXZnRdh; 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 1847B3915EEE for ; Wed, 5 Apr 2023 14:22:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id 9F6AE3882678 for ; Wed, 5 Apr 2023 14:06:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9F6AE3882678 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-x32b.google.com with SMTP id l15-20020a05600c4f0f00b003ef6d684102so18507548wmq.3 for ; Wed, 05 Apr 2023 07:06:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703585; 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=EJKj0OiP57/QFDp2NaE0NMVgLiOm8ahCDUSXGS1CdzA=; b=hYXZnRdhD+/WCMHbB5tsTBplXP00kF7gB8NdodenqPXr4LBUz9vKIW3HwxeOOTYTQs 2FgKjUZ40ZLtaR4GIsUJLX+0u2vdGcfYLnIvO5V3ZccAzOQwrevjr7f5Ev8oESs4jCkZ ptT/5590IH9sFkk42WelMEC3AakPVfsvT0OpXqbte2cbftjfzYSJUlQ1CuuRLo/XfW4T 4LlIQAE6/9uXbxtghW/DBHwU9dVjLSnJ9RQrqFWxBSXCy83myBXIERwKa0K84Kv2wUSn oq04x3FSt2du9AImtdy2dEn/p89oX5ygT5lrlNdoCFW9Vj0ErkfoKx1mWLy0Yxp2YWXJ nJNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703585; 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=EJKj0OiP57/QFDp2NaE0NMVgLiOm8ahCDUSXGS1CdzA=; b=IC5oTe4T+T0dS3Ybsbe5mr3obnh8VKHAFYLKFb7nfPT6sKoyXTyGKJaE+y1mdqhWJb fXi3OfTesisEXH5hLs3A5JRv0fsj/2Ot/RCpSjynDZtA+KDUbiqBV+gqLaVE5cNoAdeQ qcPqookw3QwXZxcTIlRZIAt3B/f/dajJXO2P/b6TGv5kvbT+0HsOSvfu7K4s4TUuDCId rAXcg7Ll4GNjXMJOAkHPstLRAOrdlGYdsbHvu/xZiavK55jYRlIlxyywQrZFWqgCMuV8 oCFX5QJM9KdzqNYhlbU098P/GbLs/7Fu9E+NNcssmK1gl36NK+tT646KEGEtRd3qZsfU lqyA== X-Gm-Message-State: AAQBX9fMYdIXWD/avYHt/CUPcpdChr9xpaoQu9vxgzi0sn75X0nm5E/M PdK6EwgSUyQG++guiCj/sO6zwxe/e5t46x1B7g== X-Received: by 2002:a05:600c:2312:b0:3f0:310c:e3ce with SMTP id 18-20020a05600c231200b003f0310ce3cemr4609810wmo.17.1680703585709; Wed, 05 Apr 2023 07:06:25 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:25 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, SainiAditya1 Subject: [committed 82/88] gccrs: rename rust-hir-full-tests.cc Date: Wed, 5 Apr 2023 16:04:06 +0200 Message-Id: <20230405140411.3016563-83-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.2 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, TVD_SPACE_RATIO, 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?1762348819006291958?= X-GMAIL-MSGID: =?utf-8?q?1762348819006291958?= From: SainiAditya1 gcc/rust/Changelog: * hir/tree/rust-hir-full-test.cc: Moved to... * hir/tree/rust-hir.cc: ...here. * Make-lang.in: Rename rust-hir-full-test. Signed-off-by: SainiAditya1 --- gcc/rust/Make-lang.in | 2 +- gcc/rust/hir/tree/{rust-hir-full-test.cc => rust-hir.cc} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename gcc/rust/hir/tree/{rust-hir-full-test.cc => rust-hir.cc} (100%) diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index 06f64a01dce..3ed0c09e0e7 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -86,7 +86,7 @@ GRS_OBJS = \ rust/rust-macro-invoc-lexer.o \ rust/rust-macro-substitute-ctx.o \ rust/rust-macro-builtins.o \ - rust/rust-hir-full-test.o \ + rust/rust-hir.o \ rust/rust-hir-map.o \ rust/rust-attributes.o \ rust/rust-abi.o \ diff --git a/gcc/rust/hir/tree/rust-hir-full-test.cc b/gcc/rust/hir/tree/rust-hir.cc similarity index 100% rename from gcc/rust/hir/tree/rust-hir-full-test.cc rename to gcc/rust/hir/tree/rust-hir.cc From patchwork Wed Apr 5 14:04: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: 79740 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp371884vqo; Wed, 5 Apr 2023 08:01:43 -0700 (PDT) X-Google-Smtp-Source: AKy350YOErbyyYkr2pLngImccceEFFyep2Y2nBGc6wcWHpg6LH4trV4WYC3RuAc11Z4oS+ox+t4s X-Received: by 2002:a17:906:c407:b0:931:a321:7640 with SMTP id u7-20020a170906c40700b00931a3217640mr3119366ejz.74.1680706903500; Wed, 05 Apr 2023 08:01:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706903; cv=none; d=google.com; s=arc-20160816; b=datMY9fnUvVaIHRLompvxgjuIijASNDGZMAjUMbNFzhdPA9O2yCPeBk1IDH+l8ZjvB DOl4rZhVTOH+ii+1NZ+T7LBpMxNiqIPJvT1Jq2KYAl/aH8Srjdns6bcSk5JAQFTo8jGN ciDYzpAu1JwIKVULTQQZa+kOVungrVN2Ywu3pGDhbPJPjJOiJUJjqocDjcZT6ozfkX+1 DeTEmx1ALBJHENmW14dp4S3J+Z7pHQNvkrABEFzqh6fPc88kRs1xpzNMIEkIVnG4j+wr irP+YOoo8VeBJpgG3XPAOq0VpWdLIJSB4Dw3V0yqxQNjbquqdzlPpX8rTOmuJV73Ovh8 g+YA== 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=6dO+dsCZ3Kavj0sM3nuKp6iCDU0g9Ri1Ro/meGoQHyc=; b=pbf2jBBCzMQXtNkX346FlDqMg1dgAwYD7KhyOINdv1Dbabr93Q/KAj4OypWXqiOe40 AbwECiYEoTgQ89WqN9OuQscCchH4RNF9nJzX9yYrHaIOVpdcnsUaysvyWgtNLYfD9GZ/ qK8uMF2TcWoyyGnTQSr2ouHdTx0LZ+GVAJDLkxDtMTTSTV9F+BzfV2UT2iKjzlEcTJWg PedFUFhbxvSbajmdXvVqdVgmzo2GjjB1NICAH6vX3+FdRzb8XcIfxKeqG7ZM/2Mf1/bB 2EAcStaVllprFAkdWYhVR8xe3IGj8Y6jYmwErBXv7X0Sv67e7x2SlTyKOYwqq6dVrw5Q +hgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=eHEymP7+; 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 e3-20020a170906374300b0093deb6d10a0si281788ejc.757.2023.04.05.08.01.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 08:01:43 -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=eHEymP7+; 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 BE86838CBE96 for ; Wed, 5 Apr 2023 14:23:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id DC1873881D01 for ; Wed, 5 Apr 2023 14:06:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DC1873881D01 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-x32f.google.com with SMTP id o32so20950698wms.1 for ; Wed, 05 Apr 2023 07:06:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703586; 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=6dO+dsCZ3Kavj0sM3nuKp6iCDU0g9Ri1Ro/meGoQHyc=; b=eHEymP7+Edg62ySfPpHx3a1JEKkuvt9ybmHcerV7iniKVk/1OhYpgYti4yzKvK7y79 z1hRZQC+qApHt9o793/Jqa/lON1CH7fawKs6gZ3/tn22kuCgkc4IVpuUvOZKPQMtqKgw r9W/BTWH4lF0oNBOisoBv8PxD1OroYgja0lqX8GyEsOpNyaQSqru2o/p/JTzvAfgEyD0 3VLKZITTSFEV/ui9ilasZgQ39LF64RUXdLxga0InkEckrLfofX8+DFmgPp4bveZH4m9R GsINL2HTpMTyyU/1alzbh08mZYF82rEn3PVTR5ZBRbwJFlKWGEANAt2e8mCsQdVBF9PS rf8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703586; 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=6dO+dsCZ3Kavj0sM3nuKp6iCDU0g9Ri1Ro/meGoQHyc=; b=5L8X6xe8hIdxpVUJ8KJMj4idOthMVOi6bHcbvEqhBCyLAtAv9pov34DB3ASafyAHCZ SbrKRp6MDzuSZgsmNC1SulwRrxCZYkKCO8xa6gD0XgnKFJEVPMmYannuYh+CZLqeYH7c W/PhCIliIJtfuaF6nZ7OdHVjzdijkUMMKFUHHUlH3B4ALu/x91RwmF1RVx7GB9PVkinL 9CduNzMxggrwzVKqhDtwWffeyRWc2bpavqJnnP9z79/WgUSORZCSIEa4yG5qagbzUXBk f4gNwNmUkrqEB+F5NsCkZt6yco8EtX2EYNN+P2dUNMOCstt+krh4OzWL8eDbLdQAPnxw cfrA== X-Gm-Message-State: AAQBX9e3SSVmQ8MzBaPEsgUvhDmBw8IdsT72ElmkQmLDg+0DOAnbzwmd LWBHZbtWlP3jEUuvlShUNj4pYrjp6HGgbougCQ== X-Received: by 2002:a05:600c:d9:b0:3ed:b349:e473 with SMTP id u25-20020a05600c00d900b003edb349e473mr4768833wmm.37.1680703586302; Wed, 05 Apr 2023 07:06:26 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:25 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 83/88] gccrs: add test case to show our query-type system is working Date: Wed, 5 Apr 2023 16:04:07 +0200 Message-Id: <20230405140411.3016563-84-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.5 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?1762348921755313302?= X-GMAIL-MSGID: =?utf-8?q?1762348921755313302?= From: Philip Herron Fixes #1361 Signed-off-by: Philip Herron gcc/testsuite/ChangeLog: * rust/compile/issue-1361.rs: New test. --- gcc/testsuite/rust/compile/issue-1361.rs | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 gcc/testsuite/rust/compile/issue-1361.rs diff --git a/gcc/testsuite/rust/compile/issue-1361.rs b/gcc/testsuite/rust/compile/issue-1361.rs new file mode 100644 index 00000000000..f8909727216 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-1361.rs @@ -0,0 +1,8 @@ +// { dg-options "-w" } +fn foo() -> S { + S { a: 15 } +} + +struct S { + a: i32, +} From patchwork Wed Apr 5 14:04: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: 79733 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp368905vqo; Wed, 5 Apr 2023 07:57:29 -0700 (PDT) X-Google-Smtp-Source: AKy350bmUZBqeAUx8g5OdKEP50OedQA6yIqXdEbo418V8Wpsk3B3KaWBN6avvJxc6ZmehWa7fYVX X-Received: by 2002:a17:906:524e:b0:93b:943f:6261 with SMTP id y14-20020a170906524e00b0093b943f6261mr2861337ejm.74.1680706649575; Wed, 05 Apr 2023 07:57:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706649; cv=none; d=google.com; s=arc-20160816; b=p5cg0ycV5jG7BmwFwK7kDIShKakyXip/2YjDWQT0sRjXAwjrsemYk1VVLZPwdGeSxr TWPc1jXY1UZj8nynWswjy0w+peWVfpLLW1vISrtITJyF/sBxn1Em1o/fXImNpO9uJAhn fglqn02qW5doRK66mV0dWfDGlgaOmuL02pmT9qgwwl237EeyYc6OUJjAaxY8CU1S/Wl5 KzUxdkGwwCJ1a4AjNpdWX+ZKVN1OeJ1Nke4dHhfx6gLfjOWctHRjEv0yhGyWL/uqRfTQ +XMPIPx8DULxm+o4vXYHMRwL+EqrIRvwl6f+i6w2gIXEXrv8urQEClN9xVVPSe5v/1t5 cUHw== 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=njUcQqBimkpLKTwc8Og86EtdMLWVhaNHx6/saxnMWII=; b=xRZXNG2NdaQWBLhXo3gzjHA5gmFhCmF9TmVUD7oI1oiFkbAIbUYQ15Q7YnmD6OSIQu IdoyBKBH9nNU3IsDQaTan9RO7yZBrjgKKLClcYEbEhfCgM8fb/xHubeElQcMq4uqTpqW pWJw10WnkS1g/WGYD1SyxxXK3c5KA3DjtuTgnPiMBPEh3nAyEn4FzC4fhbQKQgkRmkvT ba09VTfpKp4zD0sP4MrLsGCQTo/myQrhJ+CCxK6kNPHzCS67Pj1AGzPatgwSHZOM8Zoh cf0ghYJeom1fKRF+HZKiZH6GS7Zt/OzWxMBsxFfmz3/HIHXcaPowAR5SbCgosfpVJxAg zFDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=IFj0sgND; 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 bx25-20020a170906a1d900b0093183fdc438si11029303ejb.104.2023.04.05.07.57.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:57:29 -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=IFj0sgND; 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 65B8B39286CE for ; Wed, 5 Apr 2023 14:21:28 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id 6E5D0385414F for ; Wed, 5 Apr 2023 14:06:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6E5D0385414F 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-x32a.google.com with SMTP id l15-20020a05600c4f0f00b003ef6d684102so18507596wmq.3 for ; Wed, 05 Apr 2023 07:06:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703587; 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=njUcQqBimkpLKTwc8Og86EtdMLWVhaNHx6/saxnMWII=; b=IFj0sgNDehhxA3xDJRGykN6oEI88GS1kNM8rKdPaMyYfFF3KjD7v4JeVneQxOci6Ju ORg0lkB9evvzIZBHl47ukWDLu0vZIQpcAE8HS4V2ZTb/EF2Wg4T5kkyZzrh1/Nx2Q4ap 7c8uSdV5k1Ol6XS7noUPRwCJZTX/41OANswGNgmwoeUrysCy6M1n/4nF56zfSx3ctK56 RnAyxU9BFa/yHceZ2qKPYoFrSEzcOCoFoMBTAEBLwwPFVz5+Kuf2S+upp7EeqFLfCnei +YG/QuEtTII1KVfn8BIB11AMUg3HFlhG2MHn/xylRKus540GqCqqE04riYPiPpvROX9P zGdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703587; 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=njUcQqBimkpLKTwc8Og86EtdMLWVhaNHx6/saxnMWII=; b=1F9faevso9Hy13pa3BU01k6K+ITUTavtJfyeeIxrJvFk5LGcvgjRvFSDzN11u+pUy8 tM9IkWjIkWr9y7u/RA3mQazj9Csv0YWrvynroxWkQgJHHTEZwaRA0CEYKCMiLBtT0BOv wX1H3Uy59OnSptpX9iTFxPRCqxjfbbi09zfhNriXqR1n2Hz5ZrNBaEp1l4Rrqj+j7vrN 3FDqP9pcAC4ipPrb2jYGHbrfKC4LNZe7XraVXcSZSj0GtHGLYYcui0dccAjsYKbeUuLc 88v6ntXB6vWnTkEhn4mVc7/6dBLAbTOpg6KheGJMAtgyRXBFfs9DC4caPkHEIDZz+JNN BY0g== X-Gm-Message-State: AAQBX9f3frvoOjMfaCfVo/DS7SqjAOgIkRfZRpzOkAQrR6Q3+cszZFqp PzQAkEMvNjVn7fj8RtZ1Ik1BhOUQ+INpKXO3cg== X-Received: by 2002:a7b:c3d9:0:b0:3ed:da74:ab0c with SMTP id t25-20020a7bc3d9000000b003edda74ab0cmr4911136wmj.19.1680703586866; Wed, 05 Apr 2023 07:06:26 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:26 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 84/88] gccrs: ast: Refactor TraitItem to keep Location info Date: Wed, 5 Apr 2023 16:04:08 +0200 Message-Id: <20230405140411.3016563-85-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.5 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?1762348655360415790?= X-GMAIL-MSGID: =?utf-8?q?1762348655360415790?= From: Arthur Cohen gcc/rust/ChangeLog: * ast/rust-ast.h: Keep location in TraitItem base class * ast/rust-item.h (class TraitItemFunc): Use base class location instead. (class TraitItemMethod): Likewise. (class TraitItemConst): Likewise. (class TraitItemType): Likewise. * ast/rust-macro.h: Likewise. --- gcc/rust/ast/rust-ast.h | 6 +++++- gcc/rust/ast/rust-item.h | 44 ++++++++++++++------------------------- gcc/rust/ast/rust-macro.h | 10 ++++----- 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index d986fdf9368..585bdb09e68 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -1358,12 +1358,15 @@ protected: class TraitItem { protected: - TraitItem () : node_id (Analysis::Mappings::get ()->get_next_node_id ()) {} + TraitItem (Location locus) + : node_id (Analysis::Mappings::get ()->get_next_node_id ()), locus (locus) + {} // Clone function implementation as pure virtual method virtual TraitItem *clone_trait_item_impl () const = 0; NodeId node_id; + Location locus; public: virtual ~TraitItem () {} @@ -1382,6 +1385,7 @@ public: virtual bool is_marked_for_strip () const = 0; NodeId get_node_id () const { return node_id; } + Location get_locus () const { return locus; } }; /* Abstract base class for items used within an inherent impl block (the impl diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 51ed815c700..16209613881 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -2908,7 +2908,6 @@ class TraitItemFunc : public TraitItem std::vector outer_attrs; TraitFunctionDecl decl; std::unique_ptr block_expr; - Location locus; public: // Returns whether function has a definition or is just a declaration. @@ -2916,14 +2915,14 @@ public: TraitItemFunc (TraitFunctionDecl decl, std::unique_ptr block_expr, std::vector outer_attrs, Location locus) - : TraitItem (), outer_attrs (std::move (outer_attrs)), - decl (std::move (decl)), block_expr (std::move (block_expr)), - locus (locus) + : TraitItem (locus), outer_attrs (std::move (outer_attrs)), + decl (std::move (decl)), block_expr (std::move (block_expr)) {} // Copy constructor with clone TraitItemFunc (TraitItemFunc const &other) - : outer_attrs (other.outer_attrs), decl (other.decl), locus (other.locus) + : TraitItem (other.locus), outer_attrs (other.outer_attrs), + decl (other.decl) { node_id = other.node_id; @@ -2956,8 +2955,6 @@ public: std::string as_string () const override; - Location get_locus () const { return locus; } - void accept_vis (ASTVisitor &vis) override; // Invalid if trait decl is empty, so base stripping on that. @@ -3128,7 +3125,6 @@ class TraitItemMethod : public TraitItem std::vector outer_attrs; TraitMethodDecl decl; std::unique_ptr block_expr; - Location locus; public: // Returns whether method has a definition or is just a declaration. @@ -3136,14 +3132,14 @@ public: TraitItemMethod (TraitMethodDecl decl, std::unique_ptr block_expr, std::vector outer_attrs, Location locus) - : TraitItem (), outer_attrs (std::move (outer_attrs)), - decl (std::move (decl)), block_expr (std::move (block_expr)), - locus (locus) + : TraitItem (locus), outer_attrs (std::move (outer_attrs)), + decl (std::move (decl)), block_expr (std::move (block_expr)) {} // Copy constructor with clone TraitItemMethod (TraitItemMethod const &other) - : outer_attrs (other.outer_attrs), decl (other.decl), locus (other.locus) + : TraitItem (other.locus), outer_attrs (other.outer_attrs), + decl (other.decl) { node_id = other.node_id; @@ -3176,8 +3172,6 @@ public: std::string as_string () const override; - Location get_locus () const { return locus; } - void accept_vis (ASTVisitor &vis) override; // Invalid if trait decl is empty, so base stripping on that. @@ -3219,8 +3213,6 @@ class TraitItemConst : public TraitItem // bool has_expression; std::unique_ptr expr; - Location locus; - public: // Whether the constant item has an associated expression. bool has_expression () const { return expr != nullptr; } @@ -3228,14 +3220,14 @@ public: TraitItemConst (Identifier name, std::unique_ptr type, std::unique_ptr expr, std::vector outer_attrs, Location locus) - : TraitItem (), outer_attrs (std::move (outer_attrs)), - name (std::move (name)), type (std::move (type)), expr (std::move (expr)), - locus (locus) + : TraitItem (locus), outer_attrs (std::move (outer_attrs)), + name (std::move (name)), type (std::move (type)), expr (std::move (expr)) {} // Copy constructor with clones TraitItemConst (TraitItemConst const &other) - : outer_attrs (other.outer_attrs), name (other.name), locus (other.locus) + : TraitItem (other.locus), outer_attrs (other.outer_attrs), + name (other.name) { node_id = other.node_id; @@ -3328,8 +3320,6 @@ class TraitItemType : public TraitItem std::vector> type_param_bounds; // inlined form - Location locus; - public: // Returns whether trait item type has type param bounds. bool has_type_param_bounds () const { return !type_param_bounds.empty (); } @@ -3337,14 +3327,14 @@ public: TraitItemType (Identifier name, std::vector> type_param_bounds, std::vector outer_attrs, Location locus) - : TraitItem (), outer_attrs (std::move (outer_attrs)), - name (std::move (name)), - type_param_bounds (std::move (type_param_bounds)), locus (locus) + : TraitItem (locus), outer_attrs (std::move (outer_attrs)), + name (std::move (name)), type_param_bounds (std::move (type_param_bounds)) {} // Copy constructor with vector clone TraitItemType (TraitItemType const &other) - : outer_attrs (other.outer_attrs), name (other.name), locus (other.locus) + : TraitItem (other.locus), outer_attrs (other.outer_attrs), + name (other.name) { node_id = other.node_id; type_param_bounds.reserve (other.type_param_bounds.size ()); @@ -3374,8 +3364,6 @@ public: std::string as_string () const override; - Location get_locus () const { return locus; } - void accept_vis (ASTVisitor &vis) override; // Invalid if name is empty, so base stripping on that. diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h index 1a1a32da34c..be8ed560913 100644 --- a/gcc/rust/ast/rust-macro.h +++ b/gcc/rust/ast/rust-macro.h @@ -723,7 +723,7 @@ private: MacroInvocData invoc_data, std::vector outer_attrs, Location locus, bool is_semi_coloned, std::vector> &&pending_eager_invocs) - : outer_attrs (std::move (outer_attrs)), locus (locus), + : TraitItem (locus), outer_attrs (std::move (outer_attrs)), locus (locus), node_id (Analysis::Mappings::get ()->get_next_node_id ()), invoc_data (std::move (invoc_data)), is_semi_coloned (is_semi_coloned), kind (kind), builtin_kind (builtin_kind), @@ -731,10 +731,10 @@ private: {} MacroInvocation (const MacroInvocation &other) - : outer_attrs (other.outer_attrs), locus (other.locus), - node_id (other.node_id), invoc_data (other.invoc_data), - is_semi_coloned (other.is_semi_coloned), kind (other.kind), - builtin_kind (other.builtin_kind) + : TraitItem (other.locus), outer_attrs (other.outer_attrs), + locus (other.locus), node_id (other.node_id), + invoc_data (other.invoc_data), is_semi_coloned (other.is_semi_coloned), + kind (other.kind), builtin_kind (other.builtin_kind) { if (other.kind == InvocKind::Builtin) for (auto &pending : other.pending_eager_invocs) From patchwork Wed Apr 5 14:04: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: 79736 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp369890vqo; Wed, 5 Apr 2023 07:59:24 -0700 (PDT) X-Google-Smtp-Source: AKy350b9u1DjDZh7XVhPAaSYIsbQTw4dmJyF/KRdqeL8KBEP74dKwmZ8WRPm2K15J8WeCJgPF69u X-Received: by 2002:a05:6402:442:b0:4fa:d75c:16cd with SMTP id p2-20020a056402044200b004fad75c16cdmr2215079edw.34.1680706764574; Wed, 05 Apr 2023 07:59:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706764; cv=none; d=google.com; s=arc-20160816; b=QFPcD+Dmj1zjYozxkt3olMXbXohjpS34L4kRdxgReHwpsa3PePAO1ANktaDmQQ9tpg maFjCg+I8DeahID4qlyTeLKVkXQtMW+p/rsu7FFwphSVJIN9nQpURJcikqJhx7d4jz47 k3f2thB1R1BUwrRaOah4Lm6F65DuYjuRT4Wofpmcab7E5Hnph9GpPQmHdP681DAmzObj mdEtdSwZp6q0RhrjqQ2hTVmT2neocAICtyDwZbLZkcjL4KupURAz2eDE3aG+K5dbVBGC P5oHehnWk+56ppANx85Sm5JZwXe5TzMKCapLBez+G5Wro6eycJf6OkcgRPcviZTIBqIw RVXg== 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=yjv8uVmOGlt5rngZpVbTyR3eaIs7Cu+1AFc8HkUT1Tw=; b=EtWI46rImSq0OgIxgUuD8ptTKFiYrttjN5IPaEd9LeMmqvmqh6PcZ3iAE6zxCyfMjk uapsojd8RLXvfkb541USkWlW9fzP+xr6WxwhbNTicllNqRoo+gDpgt1rbZhA7BbkdVQX E7XLlc4DtLhS9sYK+xAt3Mv4HWJ9dtW5inh2E+jZgttUj+Z9qWI+GVjrguQsgidvolH4 qHeOsQ/h44cDcdFY9jD4FnIBqbUGqE3/vOXX85EmUFjdK2HPlTMjDoYlBouJOtqx5uno Kyve1G5kV4dnIsVRZdFDxVsLY03t+FItUoggqH4NidQXaisy2usjrJW/Ltqh1mJSkkCD pz1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=cgGNe94t; 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 s16-20020a056402165000b004aab36d2eb8si736312edx.62.2023.04.05.07.59.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:59:24 -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=cgGNe94t; 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 55B40384C375 for ; Wed, 5 Apr 2023 14:22:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id 63DEC385696B for ; Wed, 5 Apr 2023 14:06:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 63DEC385696B 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-x32c.google.com with SMTP id s13so20940932wmr.4 for ; Wed, 05 Apr 2023 07:06:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703587; 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=yjv8uVmOGlt5rngZpVbTyR3eaIs7Cu+1AFc8HkUT1Tw=; b=cgGNe94tMRc0xrEXt9xDJwwEmLfWzYO91+0R9yFPeQB3PwIp46jzL7sL92X6L2uS+e 7dHIEylRHlqOq6sHn+U3yxaZ285qD1+i39sHw73ZYeTvm32xoLevjIRMxoLqKGa8nX+F Ur5I/2wfmHVa7yqhFmZaStr+uNUa01S68HtwISE03FXjlEGgF+llJWe1ftuvrHN6WCH4 50WqPBHYT9do6b3sfToX9qeofJMBHn2skiGltuKAVW2+/yCM2ynCQjPgtop4TwFbXFxz w9TA3EjF/4M521IBQBsVjMXDsGDrfrz7HWYHyh+KIyumALU3OJktzUkU6pq8F1s3BvVc WlEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703587; 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=yjv8uVmOGlt5rngZpVbTyR3eaIs7Cu+1AFc8HkUT1Tw=; b=w1VU5+P2NPOaFmxTkyFduT+8dPoY15s1zjim4G427wrdqj4wNrZWNRDxXWPzFGaLW4 vVZUlErJQpl1gv8Acz9kR5jdcYbUGQWMtjZO9Z1jDKrEPgbgOfH0zX2Nmu3cTdmhXSet /DhlvBzhAj5fUG5kmCtTQ+OmYaGGvtw7O3EPn/foQgeFeMm4pNp4itRFs+s+6YO4AAXB vg0jCNO4AskdAhhYSmzQ/qEQrz1qOS8qTTrlYAbBGQfItODKqGg88J5T3ELRjg/SFug6 HS9zVtGKMVq3epK4nNxfoOjPb6W/h3zRqX9rGThdCUeq4npSU/mNwAtp0MFkouFPYFvQ fNfw== X-Gm-Message-State: AAQBX9fJpKxxaE79cKT2aYABb4x2Ry2VxZ035Nv4QFunEMdG+iZaZsot yu/mY7ZRPm40j2ql1mUmwn1LcygIUjeyhUmi6g== X-Received: by 2002:a05:600c:2154:b0:3f0:49b5:f0ce with SMTP id v20-20020a05600c215400b003f049b5f0cemr4770135wml.12.1680703587653; Wed, 05 Apr 2023 07:06:27 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:27 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 85/88] gccrs: diagnostic: Refactor Error class Date: Wed, 5 Apr 2023 16:04:09 +0200 Message-Id: <20230405140411.3016563-86-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.2 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?1762348776247883262?= X-GMAIL-MSGID: =?utf-8?q?1762348776247883262?= From: Arthur Cohen The class now allows for more variants including a `Hint` one which then gets emitted by calling `rust_inform`. This allows us to display hints/tips/notes in backtracking contexts such as the parser. gcc/rust/ChangeLog: * rust-diagnostics.h (struct Error): Add new Kind enum and various new static constructors to allow for hints as well. * rust-diagnostics.cc (Error::Error): Use new `kind` field properly. * checks/errors/privacy/rust-visibility-resolver.cc (VisibilityResolver::resolve_module_path): Use new Error API. * expand/rust-macro-builtins.cc (MacroBuiltin::include_handler): Likewise. * expand/rust-macro-expand.cc (parse_many): Likewise. (transcribe_type): Likewise. * parse/rust-parse-impl.h (Parser::parse_crate): Likewise. * rust-session-manager.cc (Session::handle_crate_name): Likewise. * ast/rust-ast.cc (Module::load_items): Likewise. --- gcc/rust/ast/rust-ast.cc | 2 +- .../privacy/rust-visibility-resolver.cc | 4 +- gcc/rust/expand/rust-macro-builtins.cc | 2 +- gcc/rust/expand/rust-macro-expand.cc | 4 +- gcc/rust/parse/rust-parse-impl.h | 2 +- gcc/rust/rust-diagnostics.cc | 43 ++++++++++++-- gcc/rust/rust-diagnostics.h | 56 ++++++++++++++++--- gcc/rust/rust-session-manager.cc | 6 +- 8 files changed, 98 insertions(+), 21 deletions(-) diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index 07983b7da06..68a7dfdc662 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -4084,7 +4084,7 @@ Module::load_items () inner_attrs = parser.parse_inner_attributes (); auto parsed_items = parser.parse_items (); for (const auto &error : parser.get_errors ()) - error.emit_error (); + error.emit (); items = std::move (parsed_items); kind = ModuleKind::LOADED; diff --git a/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc b/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc index becb9fd93a7..30afaf9174e 100644 --- a/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc +++ b/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc @@ -63,7 +63,7 @@ VisibilityResolver::resolve_module_path (const HIR::SimplePath &restriction, NodeId ref_node_id = UNKNOWN_NODEID; if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id)) { - invalid_path.emit_error (); + invalid_path.emit (); return false; } // FIXME: Add a hint here if we can find the path in another scope, such as @@ -77,7 +77,7 @@ VisibilityResolver::resolve_module_path (const HIR::SimplePath &restriction, auto module = mappings.lookup_module (ref); if (!module) { - invalid_path.emit_error (); + invalid_path.emit (); return false; } diff --git a/gcc/rust/expand/rust-macro-builtins.cc b/gcc/rust/expand/rust-macro-builtins.cc index 97594921dec..cf90b384cb5 100644 --- a/gcc/rust/expand/rust-macro-builtins.cc +++ b/gcc/rust/expand/rust-macro-builtins.cc @@ -736,7 +736,7 @@ MacroBuiltin::include_handler (Location invoc_locus, AST::MacroInvocData &invoc) bool has_error = !parser.get_errors ().empty (); for (const auto &error : parser.get_errors ()) - error.emit_error (); + error.emit (); if (has_error) { diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc index 4b494490424..71aafef85b0 100644 --- a/gcc/rust/expand/rust-macro-expand.cc +++ b/gcc/rust/expand/rust-macro-expand.cc @@ -848,7 +848,7 @@ parse_many (Parser &parser, TokenId &delimiter, if (node.is_error ()) { for (auto err : parser.get_errors ()) - err.emit_error (); + err.emit (); return AST::Fragment::create_error (); } @@ -991,7 +991,7 @@ transcribe_type (Parser &parser) auto type = parser.parse_type (true); for (auto err : parser.get_errors ()) - err.emit_error (); + err.emit (); auto end = lexer.get_offs (); diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index cc5436cff63..6a98bcce654 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -444,7 +444,7 @@ Parser::parse_crate () // emit all errors for (const auto &error : error_table) - error.emit_error (); + error.emit (); return std::unique_ptr ( new AST::Crate (std::move (items), std::move (inner_attrs))); diff --git a/gcc/rust/rust-diagnostics.cc b/gcc/rust/rust-diagnostics.cc index c0f02c2831e..4e5c2ececd4 100644 --- a/gcc/rust/rust-diagnostics.cc +++ b/gcc/rust/rust-diagnostics.cc @@ -231,14 +231,49 @@ rust_debug_loc (const Location location, const char *fmt, ...) } namespace Rust { -Error::Error (const Location location, const char *fmt, ...) : locus (location) + +/** + * This function takes ownership of `args` and calls `va_end` on it + */ +static Error +va_constructor (Error::Kind kind, Location locus, const char *fmt, va_list args) + RUST_ATTRIBUTE_GCC_DIAG (3, 0); + +static Error +va_constructor (Error::Kind kind, Location locus, const char *fmt, va_list args) +{ + std::string message = expand_message (fmt, args); + message.shrink_to_fit (); + va_end (args); + + return Error (kind, locus, message); +} + +Error::Error (const Location location, const char *fmt, ...) + : kind (Kind::Err), locus (location) { va_list ap; + va_start (ap, fmt); + *this = va_constructor (Kind::Err, location, fmt, ap); +} + +Error +Error::Hint (const Location location, const char *fmt, ...) +{ + va_list ap; va_start (ap, fmt); - message = expand_message (fmt, ap); - va_end (ap); - message.shrink_to_fit (); + return va_constructor (Kind::Hint, location, fmt, ap); +} + +Error +Error::Fatal (const Location location, const char *fmt, ...) +{ + va_list ap; + va_start (ap, fmt); + + return va_constructor (Kind::FatalErr, location, fmt, ap); } + } // namespace Rust diff --git a/gcc/rust/rust-diagnostics.h b/gcc/rust/rust-diagnostics.h index 900198e72ca..43fee8baf4f 100644 --- a/gcc/rust/rust-diagnostics.h +++ b/gcc/rust/rust-diagnostics.h @@ -114,27 +114,69 @@ namespace Rust { * errors to be ignored, e.g. if backtracking. */ struct Error { + enum class Kind + { + Hint, + Err, + FatalErr, + }; + + Kind kind; Location locus; std::string message; // TODO: store more stuff? e.g. node id? - Error (Location locus, std::string message) - : locus (locus), message (std::move (message)) + Error (Kind kind, Location locus, std::string message) + : kind (kind), locus (locus), message (std::move (message)) { message.shrink_to_fit (); } + Error (Location locus, std::string message) + { + Error (Kind::Err, locus, std::move (message)); + } + + static Error Hint (Location locus, std::string message) + { + return Error (Kind::Hint, locus, std::move (message)); + } + + static Error Fatal (Location locus, std::string message) + { + return Error (Kind::FatalErr, locus, std::move (message)); + } + // TODO: the attribute part might be incorrect Error (Location locus, const char *fmt, ...) /*RUST_ATTRIBUTE_GCC_DIAG (2, 3)*/ RUST_ATTRIBUTE_GCC_DIAG (3, 4); - // Irreversibly emits the error as an error. - void emit_error () const { rust_error_at (locus, "%s", message.c_str ()); } + /** + * printf-like overload of Error::Hint + */ + static Error Hint (Location locus, const char *fmt, ...) + RUST_ATTRIBUTE_GCC_DIAG (2, 3); + + /** + * printf-like overload of Error::Fatal + */ + static Error Fatal (Location locus, const char *fmt, ...) + RUST_ATTRIBUTE_GCC_DIAG (2, 3); - // Irreversibly emits the error as a fatal error. - void emit_fatal_error () const + void emit () const { - rust_fatal_error (locus, "%s", message.c_str ()); + switch (kind) + { + case Kind::Hint: + rust_inform (locus, "%s", message.c_str ()); + break; + case Kind::Err: + rust_error_at (locus, "%s", message.c_str ()); + break; + case Kind::FatalErr: + rust_fatal_error (locus, "%s", message.c_str ()); + break; + } } }; } // namespace Rust diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc index a086f83a3d0..074bad9c5d7 100644 --- a/gcc/rust/rust-session-manager.cc +++ b/gcc/rust/rust-session-manager.cc @@ -193,7 +193,7 @@ Session::handle_option ( else { rust_assert (!error.message.empty ()); - error.emit_error (); + error.emit (); } } else @@ -391,7 +391,7 @@ Session::handle_crate_name (const AST::Crate &parsed_crate) if (!validate_crate_name (msg_str, error)) { error.locus = attr.get_locus (); - error.emit_error (); + error.emit (); continue; } @@ -412,7 +412,7 @@ Session::handle_crate_name (const AST::Crate &parsed_crate) if (!options.crate_name_set_manually && !validate_crate_name (options.crate_name, error)) { - error.emit_error (); + error.emit (); rust_inform (linemap->get_location (0), "crate name inferred from this file"); } From patchwork Wed Apr 5 14:04: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: 79744 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp373354vqo; Wed, 5 Apr 2023 08:03:05 -0700 (PDT) X-Google-Smtp-Source: AKy350aZlF1sd6qRe9UXzbEjvPJ+Sb4PhfPQHd6jz0jyUW9BKwv2wMCrp1DnDEBa/znLWH9LLOIk X-Received: by 2002:aa7:d3d5:0:b0:4fb:fd22:29c0 with SMTP id o21-20020aa7d3d5000000b004fbfd2229c0mr1828056edr.26.1680706985570; Wed, 05 Apr 2023 08:03:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706985; cv=none; d=google.com; s=arc-20160816; b=i1wSBv93eDj/7e1FaKuTERYCtLyHtCKi9Aw3cAf4nWewP6OIXV0pm/eOpWAgHJCDTU sq0FW+EYU1Rh29QEGC93+YP2XbZlRYoQZKaxl088DFZOu1aIJK+KNZwUax3nAwjyh1eO Hwaz4jIZK4+n6tqeQb7U0uKn/4EiUNToIsMuivxpwO2gd7RbvsGN+rMbKi9oRpaQGBDC 1FoPIX1cEhl7D19s4TdG49V8+Wh5P/T1Fpg8FWvFQU9KsaJPPk0AKAf6NCJSnKbuagRe CwNWdbZXzuy9zBqCbc+5bzCgf63YpBf2RBLFckEtTrWiTOhSqhmdH2qGu2aoyaue4HFv pcHQ== 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=AH5VbKw/CfE3qN4pWx4GtpMg3pQzXtQuwepFbngSu3w=; b=Lo30fIDUvNbNU0m16/o/08pESusftr/8TAbgWpY0nVMUTQkBWnb1oUdX6kR/Yu9yd+ 7AVYkc93wMORmleh//C5iP5CgtkJg7mkuD7ntMh6+HDkysLKKtj7DFXsyGdEYX7cF9rZ vZRlPl6XMfKq3CMaOGgJyciGDjglakC+HNBS7BBJnTMXSuZATWBpSPR2RWmKm4h2ESCc Mbb+K5Ru2leMgIfUi6m4GUq79KS6vUpJATAlcikgi7rIGGVws7aav84xHzUV0A8ZqtZQ nnhcjZNh1omO9fXpcAJQ1eKIJLtEEcLkn8iW5JIdsX+60ZCj4iYYVfWjg+0lAhssILac 6tGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=cxmgVpUW; 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 zb20-20020a17090687d400b0093b62d1f8e0si3357261ejb.271.2023.04.05.08.03.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 08:03:05 -0700 (PDT) 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=cxmgVpUW; 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 6CA4038E6136 for ; Wed, 5 Apr 2023 14:23:55 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id F2CF03856DCA for ; Wed, 5 Apr 2023 14:06:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F2CF03856DCA 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-x331.google.com with SMTP id n10-20020a05600c4f8a00b003ee93d2c914so23483535wmq.2 for ; Wed, 05 Apr 2023 07:06:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703588; 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=AH5VbKw/CfE3qN4pWx4GtpMg3pQzXtQuwepFbngSu3w=; b=cxmgVpUW9qLA7j6EN+FiMKkuKKgpBTmbIQ0JfSiQ2bimwR/kIJiGXtiYpHHTB7dSCI 1/ysVMJszvL3jl+cX8fskdkJ6gha2coLmVaVUR/19bmfeKozQJ78UGiVLq/WoH95Whrd 0tLgL+rq32NbZSWrZCv6mFJAjMLiW4uMalvQuF70t0Nm0b4FLwNAFJQ45zpwpLoZW5hz 59Y2Gqsd0StQbpdZzSFTiJk43KaZFeKKExv36gHF6gxRytQv+0ZW84rEu5MuMqHkmry4 Odtb1xsHylT3w3XZhSYvNOJ1CzzPxtXnubwLfg3+Zs1IwLeVuoqMFHh0xrB2ZAS9zg13 l2CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703588; 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=AH5VbKw/CfE3qN4pWx4GtpMg3pQzXtQuwepFbngSu3w=; b=N0N6sV5qPQCzypl9zpSj+SEc1goUfhKIEUAQABN2b3sK9ogmzr6IfDgZhpcxiinduG VjrjWwcQMeQePt1gPBMRY4nf+0KQ+IKb3osJhY1f9XaMaEFbVtDpNHthHpHMWRovIZxG HCIKOiggUp/94QpBc9YmgTKpG2KSuofWWddgWQdtT3i5kc9KBru3mC6Tho7/q73MmDrb CWZlY+xd6CUyhKVMbvEjPN/6FNyPlW9EuOBLfPhBvINu/sVniCUxfd4Pwj9UhD+oirfT uuhvypR1nhb9W4ryaZ9iaQs8DshR/YawCsmzG9NDgAzIT+yA0gmGL0eixSO7hyKR1GGy 2o0w== X-Gm-Message-State: AAQBX9cc2jrUkTwXrCw7QHX82C5ZtlzSwwCf+eUZ19lxAVQ8XKVd7xQk dDY4G9HmZ1+CqYnZKXfOimDBzGMdZhRULiRB9g== X-Received: by 2002:a7b:c455:0:b0:3ee:1afc:c15 with SMTP id l21-20020a7bc455000000b003ee1afc0c15mr4495247wmi.33.1680703588492; Wed, 05 Apr 2023 07:06:28 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:28 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, M V V S Manoj Kumar Subject: [committed 86/88] gccrs: Added AST Node AST::InlineAsm Date: Wed, 5 Apr 2023 16:04:10 +0200 Message-Id: <20230405140411.3016563-87-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.5 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?1762349008509011992?= X-GMAIL-MSGID: =?utf-8?q?1762349008509011992?= From: M V V S Manoj Kumar Addresses #1567 Created a AST node InlineAsm similar to the one found in rustc. As there is no Symbol struct/class in gccrs I have made every instance of Symbol a string. gcc/rust/ChangeLog: * ast/rust-ast-full-decls.h (class InlineAsm):Added class declaration. * ast/rust-expr.h (class InlineAsm):Added class definition. Signed-off-by: M V V S Manoj Kumar --- gcc/rust/ast/rust-ast-full-decls.h | 1 + gcc/rust/ast/rust-expr.h | 138 +++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) diff --git a/gcc/rust/ast/rust-ast-full-decls.h b/gcc/rust/ast/rust-ast-full-decls.h index 9d7b00ac5a2..64341d32641 100644 --- a/gcc/rust/ast/rust-ast-full-decls.h +++ b/gcc/rust/ast/rust-ast-full-decls.h @@ -149,6 +149,7 @@ struct MatchCase; class MatchExpr; class AwaitExpr; class AsyncBlockExpr; +class InlineAsm; // rust-stmt.h class EmptyStmt; diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index 3ed1885d5af..f5461848009 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -4634,6 +4634,144 @@ protected: return new AsyncBlockExpr (*this); } }; + +// Inline Assembly Node +class InlineAsm : public ExprWithoutBlock +{ + // Inline-assembly specific options + enum InlineAsmOptions + { + PURE = 1 << 0, + NOMEM = 1 << 1, + READONLY = 1 << 2, + PRESERVES_FLAGS = 1 << 3, + NORETURN = 1 << 4, + NOSTACK = 1 << 5, + ATT_SYNTAX = 1 << 6, + RAW = 1 << 7, + MAY_UNWIND = 1 << 8, + }; + + struct AnonConst + { + NodeId id; + std::unique_ptr value; + }; + + struct InlineAsmRegOrRegClass + { + enum Type + { + Reg, + RegClass, + }; + + struct Reg + { + std::string Symbol; + }; + + struct RegClass + { + std::string Symbol; + }; + + Identifier name; + Location locus; + }; + + struct InlineAsmOperand + { + enum RegisterType + { + In, + Out, + InOut, + SplitInOut, + Const, + Sym, + }; + + struct In + { + InlineAsmRegOrRegClass reg; + std::unique_ptr expr; + }; + + struct Out + { + InlineAsmRegOrRegClass reg; + bool late; + std::unique_ptr expr; // can be null + }; + + struct InOut + { + InlineAsmRegOrRegClass reg; + bool late; + std::unique_ptr expr; // this can't be null + }; + + struct SplitInOut + { + InlineAsmRegOrRegClass reg; + bool late; + std::unique_ptr in_expr; + std::unique_ptr out_expr; // could be null + }; + + struct Const + { + AnonConst anon_const; + }; + + struct Sym + { + std::unique_ptr sym; + }; + Location locus; + }; + + struct InlineAsmPlaceHolder + { + size_t operand_idx; + char modifier; // can be null + Location locus; + }; + + struct InlineAsmTemplatePiece + { + bool is_placeholder; + union + { + std::string string; + InlineAsmPlaceHolder placeholder; + }; + }; + + struct TupleClobber + { + // as gccrs still doesen't contain a symbol class I have put them as strings + std::string symbol; + Location loc; + }; + + struct TupleTemplateStr + { + // as gccrs still doesen't contain a symbol class I have put them as strings + std::string symbol; + std::string optional_symbol; + Location loc; + }; + +public: + std::vector template_; + std::vector template_strs; + std::vector operands; + TupleClobber clobber_abi; + InlineAsmOptions options; + std::vector line_spans; +}; } // namespace AST } // namespace Rust From patchwork Wed Apr 5 14:04: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: 79739 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp371332vqo; Wed, 5 Apr 2023 08:01:11 -0700 (PDT) X-Google-Smtp-Source: AKy350aE4SuC2niN5w9pme+0AKWQUduHMe4fwvnzSCBYqjhqdXehEtj9gtZKGIWUjqTtVf+nwPus X-Received: by 2002:a17:907:bb81:b0:931:c2f0:9437 with SMTP id xo1-20020a170907bb8100b00931c2f09437mr3178206ejc.8.1680706870972; Wed, 05 Apr 2023 08:01:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706870; cv=none; d=google.com; s=arc-20160816; b=C3QZIohcMawFs4ATiey9ugqb2G4TV2RDYDPStTklXcWefQ2GjnlTSBPdPDsR6xijYA 6HqyCZyniHKvv8RkAdj821OhUOMCobDFwHrscYarNIhH0dAriYWtEpAXg4Ng58ejUTpE oR5Yqpj679EYgPBnxOtfYUWAVCng1guEGmQ+LYMV/0McnbJm3eMLQXxz4j4C3wfUINzB juDL22LndBnMfDM+mHhPjW9oBZ0dv/cqESyuUSomoKslHRekETQZt13/iXY17ySqMGZE GbVOaVIT2ab68gG2x5x3Oyka4iPwqvJcREAO+LGrN+THkHVzsXc61RLWnRI/j8o855Uu 9i9w== 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=woLOcpjWfTGhRDubWXEPX+6mcHR+gOlqu5nxJymYiHQ=; b=Q9T2Ljo/hTFHHgbV+/9nxm60Y/Zs+ApxnOCEPJtxg+8FqafpDf7qe1Lo2bvWXMYkbu eLgV6z+Jihr5mTuojV7ha862iEIXM9d93fF8AqpnMlh9m5ANFQgnSI0sJ1W7OX7hvNSH 7apZgJ2dlE7b7ry/SSAF23bsFICFYd/xk8eRkIiyBIm29GaOx0Ezri/OyOqML+1hyNBi J/fObOeIqeT7HUQMVlE1Nsj/2VH9yc37Sff6AtdEXqDrNDQ6tv8/PPKTRdxOTi+pbrnQ ZltiOUibq/Tg198iBJEnsSF1EqsaF0Hh1HBLXvEhLXiXGSxWhK20vV85/P4ufihHvyPW YRKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=CkhoIs6O; 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 g18-20020a170906395200b0092127059e12si2068eje.57.2023.04.05.08.01.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 08:01:10 -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=CkhoIs6O; 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 D8FF13836BBE for ; Wed, 5 Apr 2023 14:23:01 +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 7B47B3882026 for ; Wed, 5 Apr 2023 14:06:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7B47B3882026 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 j1-20020a05600c1c0100b003f04da00d07so2155865wms.1 for ; Wed, 05 Apr 2023 07:06:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703589; 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=woLOcpjWfTGhRDubWXEPX+6mcHR+gOlqu5nxJymYiHQ=; b=CkhoIs6OwPDHc35FAuKg7qriwbMhGTcIzecAnbmGGpcQ65uRDM8RmavYph7BiWRWAH i0e/giFkACoRNxbkSBUh0/7ouiLdKBJnAkfqBjaACqH/IbmF53eJypqbJsSBHAOKkUQ/ 4UbmJY895iNtLQNy8RaT5U6MbwJrjup8C7mDWCHhfvPCFKcF4k+z2ovrJmagH56QaOGQ 0bDwxu/JkckLUUwnQoEUmQtkLuzp/v2QKDQV0fH1vshum6KQd+SyG24dhU9LVfSkZ+4o XsH4XTLtDHH2umAdZvYk5efLb3Hwda/a8ErLRK2IwQ+wIasqIEaxR7/bc2qPWc9j1laY P8VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703589; 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=woLOcpjWfTGhRDubWXEPX+6mcHR+gOlqu5nxJymYiHQ=; b=dd/KbprYSpH9H4o6zfnKx7MQvgJqoqRYAqKDPM/7wlOgvygdaCy5Zd9sXmSyhGYed5 0yz31TGz71him6YbFKRXuRItuEMoWEUUetO+bxtbS5SnLwdadNO/9c92FDer/0rTeWT5 Rq2T6HvD5UQ1dIOSH+/b6bLVLYBY6biquZ3P/D6rb/Ahn0DA1PYfyAN3W5lrHsV6yjYH KOa61phKPiyFXcHYfauioR4572MMB6LtmtM2aPHrpoS3XZR/QHICLHjXlxftfp0pXT2V 7Krkuzlm/tT79V8+N5mp0mGO3GHuBojomtHTTHH/AZI3+mpdmBrmK5FdI+tzYgEDr7ye GBEw== X-Gm-Message-State: AAQBX9fB3uoike+lnRMFQZp8Q8PorDx+R1qdjCpeEmlKPvJ9pSg3qzzY Sy60Y7SkV9mh7+RkKYuTz4LOMe03MkLTPzYKPw== X-Received: by 2002:a7b:c8c3:0:b0:3f0:5074:efa7 with SMTP id f3-20020a7bc8c3000000b003f05074efa7mr4867981wml.14.1680703588891; Wed, 05 Apr 2023 07:06:28 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:28 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [committed 87/88] gccrs: Address unsafe with/without block handling ambiguity Date: Wed, 5 Apr 2023 16:04:11 +0200 Message-Id: <20230405140411.3016563-88-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.2 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?1762348888269976296?= X-GMAIL-MSGID: =?utf-8?q?1762348888269976296?= From: Owen Avery gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_expr_stmt): Remove hypothetical unsafe + expr_stmt_without_block handling. Signed-off-by: Owen Avery --- gcc/rust/parse/rust-parse-impl.h | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 6a98bcce654..1e5b2dc85ed 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -7188,18 +7188,9 @@ Parser::parse_expr_stmt (AST::AttrVec outer_attrs, } } case UNSAFE: { - /* FIXME: are there any expressions without blocks that can have - * unsafe as their first token? Or is unsafe the only one? */ - // safe side for now - if (lexer.peek_token (1)->get_id () == LEFT_CURLY) - { - return parse_expr_stmt_with_block (std::move (outer_attrs)); - } - else - { - return parse_expr_stmt_without_block (std::move (outer_attrs), - restrictions); - } + // unsafe block + // https://doc.rust-lang.org/reference/unsafe-keyword.html + return parse_expr_stmt_with_block (std::move (outer_attrs)); } default: // not a parse expr with block, so must be expr without block From patchwork Wed Apr 5 14:04: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: 79742 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp372769vqo; Wed, 5 Apr 2023 08:02:32 -0700 (PDT) X-Google-Smtp-Source: AKy350Zzbfm1g5GKC9o/UatEXYRyOipMyesHuetUDgegeiPtUOBEJ7cOnJiObKk+6wjnwtQyqJQP X-Received: by 2002:a17:907:2bf5:b0:93b:b8f3:225d with SMTP id gv53-20020a1709072bf500b0093bb8f3225dmr3255571ejc.15.1680706952579; Wed, 05 Apr 2023 08:02:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706952; cv=none; d=google.com; s=arc-20160816; b=CWxsFU8DM4fOmdovA4C2MY9mV6jlNH623wQjR/Ma4fdK4X9gdKHaFAkUKbwnU/ca53 AA9l6mIDmxnEADAnb/qR5ZGT3pzYBOo1mgl/zZfg1mXsDA3QWoetX56rjsVqzXvUiZH/ MXoHKOO8e9QLfkbOQ1vaDuMgZKU7U9KucKnHloYqRJZYkczWfuHSLuj0EFMN1Y+XgS35 qMtE4Az3+lvS9LNfTa0AsTHTo5NGfDXbTyJ7np/hHsEfB5LgnTO3PYyOtnrD0dwqSJ+X umfDNxR09kjZJ0Wg4Btai/nn0FZwKzIuzkyoHgFGEyaII0fmcS5OlpxD0SClsj0TXIF/ /alw== 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=us33c9zBlXTuTIl37971m5lshOelpNhwhp2riFXNhko=; b=lpc5TSI5AbbDGxq+du9sC3HEtwRUDRbLR0yqdmC09L0c3h6+eyr2RcCXhVRBAb7SPa Om4ucY7OOQ5IVWBweTLu5FguHz4P7OD/Hghh3AJVJajaOzIJWbgKIR8228dS3xWbTtzB Ysph80+7lRj8NQWXiG3QQcis3n/WCTV7CD1D6vJmLtxxt0q8rlDdlLvkWKR+upDV7om3 ehSOZ5cv35Zgb0/sLs9t74/p9vx/MATNNvR3Z5XFcNzooXbLYb5KA5RLy5MZvgwt7t24 MNBd/Q2BPir3MFFSA9ch4+bTRRA44SsDUZeoY+inovYkVAsnGqGsflKwJAiGBGeB2BJX xeoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=escybUj+; 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 m26-20020a1709066d1a00b009309c7f5650si4446078ejr.23.2023.04.05.08.02.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 08:02:32 -0700 (PDT) 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=escybUj+; 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 94C3539A2545 for ; Wed, 5 Apr 2023 14:23:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 162403857023 for ; Wed, 5 Apr 2023 14:06:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 162403857023 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-x331.google.com with SMTP id l10-20020a05600c1d0a00b003f04bd3691eso7161801wms.5 for ; Wed, 05 Apr 2023 07:06:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703589; 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=us33c9zBlXTuTIl37971m5lshOelpNhwhp2riFXNhko=; b=escybUj+EKOMD7Y2XLwqWOCg60fpep69jUdJCMF03KHH5Bmx3d61u3tuwxNv3ocBOQ mmeB67jCxuuJTRKqLkhaYDl6gjyV/TYTy/w+mHUbRZ+mi8NANuH2DV5Xy0Xn7orzd7Y8 pmtRHwP72xFPp8DDN9LpQpItHN0YExJHZu8dBDcl+RCZ3BjFazt9cQAG8xPI2X+P7Ovb WyIfuWgbOUe4g8oAOv2r2ilTvdTjqWasbLqjGIFKozfv3L6XoskV5cvw7cIOv12zwb7p s6oz/ukl3M6qPhDd9T4G6b1ykcN1JOLhqeSURuRY/iVig+cKhLXE8yWtdHqsNk7RqxYu 5RuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703589; 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=us33c9zBlXTuTIl37971m5lshOelpNhwhp2riFXNhko=; b=CPraLl3Z28VPeNHVBNihaMcYT1qj/CBQBtMiRNKGikzmDBRr2oZ5e/ytIkrAWVYJeV kvQLEte3GLWkJbOmHAVmJflwV2Z6UzGfviKG/Kj1TEmErOSf2XoSrJJRGLRXXUlUcb+a VdEprsmOxvqQVlshAEurzO/7S9eg31Om1tI8ZZoEQ8hQ/BXRaWS+eV4u/g9ooEBSnVpG gGy8qBkQlFcQtkCbRKhSoftQU51MbeA9EWiyfmlhDWoSLxajEHRMJyXdncQBY/nF/ZwX fDgQtKU3HO4CbTHrIQAgYtO/NzvCj78yZOmukUro/8mjdM6I1B402lVXo/y7PYdArFU8 C6Mg== X-Gm-Message-State: AAQBX9cUhhVfJdz1jpF+2FX3y5TDShVabtubute84tpM69GKNWrQ5RAH WDGQ8/Fjvv6+Xv+/7hHpJatlzD+UUh1l3kuKmA== X-Received: by 2002:a05:600c:25a:b0:3ed:237f:3da with SMTP id 26-20020a05600c025a00b003ed237f03damr5208026wmj.22.1680703589461; Wed, 05 Apr 2023 07:06:29 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:29 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [committed 88/88] gccrs: Fix issue with parsing unsafe block expression statements Date: Wed, 5 Apr 2023 16:04:12 +0200 Message-Id: <20230405140411.3016563-89-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.5 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?1762348973556714863?= X-GMAIL-MSGID: =?utf-8?q?1762348973556714863?= From: Owen Avery gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_stmt): Handle unsafe expression statements. gcc/testsuite/ChangeLog: * rust/compile/issue-1422.rs: New test. Signed-off-by: Owen Avery --- gcc/rust/parse/rust-parse-impl.h | 10 +++++++++- gcc/testsuite/rust/compile/issue-1422.rs | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/rust/compile/issue-1422.rs diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 1e5b2dc85ed..db32803ddbe 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -6131,7 +6131,15 @@ Parser::parse_stmt (ParseRestrictions restrictions) /* if any of these (should be all possible VisItem prefixes), parse a * VisItem can't parse item because would require reparsing outer * attributes */ - return parse_vis_item (std::move (outer_attrs)); + // may also be unsafe block + if (lexer.peek_token (1)->get_id () == LEFT_CURLY) + { + return parse_expr_stmt (std::move (outer_attrs), restrictions); + } + else + { + return parse_vis_item (std::move (outer_attrs)); + } break; case SUPER: case SELF: diff --git a/gcc/testsuite/rust/compile/issue-1422.rs b/gcc/testsuite/rust/compile/issue-1422.rs new file mode 100644 index 00000000000..b178cda185e --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-1422.rs @@ -0,0 +1,7 @@ +macro_rules! test { + () => { unsafe {} }; +} + +fn main() { + test!(); +}