From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 26E6B3857029 for ; Wed, 5 Apr 2023 14:05:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 26E6B3857029 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 e18so36325934wra.9 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=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=jDJ6SDrDrsmbwB0i1kCmfPFhPtoruJfvA6E5eOfN6p5t9dHv9h5mZzw591n6svlC5y jlzwD7Y97qfG0lML7QvFHzB43hSUJqpft7HY4ozTVGo8ZKsjV7uRGfO0XBgCoWhRgE+r pmGLWRptH2l36E1h04Ch0haFLaemUv/sgaAxtxH31eQlqdHhxh8nl95sIfFEjZfq+11t FJkY7IdO+bI3Y///8g3Jd/0G21DtVMHgmjxfBtQRdFc9ZhYowi+zOlhLpJtdtUmwDlfj 35EoVlBJGlcBqJLnlsexLucbCqoy4Ng8GRah+z7vaRhHfT0Ie9K8Ra/mJPBNu0mpdBEj ADhw== X-Gm-Message-State: AAQBX9dH21pEJG/xrc1zgqqATazDjz/wA/2y1Xx7St0afiX7uUMWRNq2 Q/u+3XXvL/yGfTlaAkqyPyY0 X-Google-Smtp-Source: AKy350ZmX1wIHZ03dDoksYgLRJlFJ17Vj9SjN15CrApus5AGOuhz0pJEd524lbAraCsbPI8vAW+cuw== 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> Reply-To: arthur.cohen@embecosm.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 List-Id: 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 ())); -- 2.40.0