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 ()));