From patchwork Tue Feb 21 12:01: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: 60010 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1835566wrn; Tue, 21 Feb 2023 04:34:04 -0800 (PST) X-Google-Smtp-Source: AK7set/SvuNodC/nVw+KNuJeUNmuQEsWZ0YHFrYo1JZg2Sx8ylUfAhAHly7IqZPZHjrwBqmpIo2d X-Received: by 2002:a17:907:2d22:b0:8b1:4516:238 with SMTP id gs34-20020a1709072d2200b008b145160238mr11846198ejc.26.1676982844257; Tue, 21 Feb 2023 04:34:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676982844; cv=none; d=google.com; s=arc-20160816; b=c/2FjfpYzphDYsTRV+0fJOiBFpiUrBS0nAGRQMJI3fFKJYlw68XAqvKznDoHnnYvxh OrDtlgMqDaEr1w5PaJyA64A+tCbn/P36mAHFTYRTZiRhaug/hRTIFdSXYoCgYh6ZXJ/+ PXJ56JWLx0dGw4FokRftpI9gpGeNTme7dl62+vcm0KcYQiMoNXvuoPy+mfI1ftRQP6cd MhUDlr0W6DBbzRE1fh1EXLAAg3Sg5qvxffv9FFvbfowAyaFeOGVvKT+GElzHkwNYGx5O R4/UQg97FIFAst5DvSeWqhiS/VAWWIKwzZtC4p/2A39uuUacNPiYkdfJa+tS4Taphh1o BNTQ== 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=Mx4M+hOcIm/m8fLsqZd3LiXt4cjdnBO461A2GXm7wMU=; b=Ob5aRzq99kkACOh8awnUISx3VGmxoG86DA8cjmM+dNqqw7EgCnFvSSm9LB6uRefbEm blZRjzJpxPF+U5urEy3zzF0Yf0Bg745sceRWGHZnamXqCfDaF4roAKTA8e5du1zQTYqO 1ieISWSGJbdwljWw/rtVXxdxTHAyhpl0OohhUn7rjHVf+yEpvoTmz1keWnphnOUytPvK J63UpBwwDLaDRNBWkns1PRVWD4q90avViQrzQ9eI2G9UEDZfy9wVW077UX6BBvqIOaCT rAfi+FqSaSyYol60k9OfKhk6nHJPwBkBAy51Kcr8Dvz9u7eC6yU43Tt6rdlambobsgPp 44yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=QayNPtpN; 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 vs18-20020a170907139200b008cbf89a6787si7996556ejb.6.2023.02.21.04.34.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:34:04 -0800 (PST) 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=QayNPtpN; 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 C949A39192C2 for ; Tue, 21 Feb 2023 12:12:23 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 08CC6383FE01 for ; Tue, 21 Feb 2023 12:04:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 08CC6383FE01 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-x432.google.com with SMTP id bo30so3602647wrb.0 for ; Tue, 21 Feb 2023 04:04:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; 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=Mx4M+hOcIm/m8fLsqZd3LiXt4cjdnBO461A2GXm7wMU=; b=QayNPtpNaCSzCcAyz0BBiXlwyiD9ndNrAb+Lba5ODogKQb04xSKvqiyI62OpUNiJdy 1mWZTGZH8dTbOA4L0HCogbk5YKwdwPSJSmyuwLa8/ON/Y9TqH1XBqRQfgWy7jHj7/iqe rbrMgWxmubFSD+aQE28kID/XIWL3JTefydqdcvu6xM/eUdk3pCjxBea2Xw2krnChTJNO hrBshSFFsytyLziSIkilIwNic5gX66OxVYZBa/NyQPIHU0TWkcMFcVgGv0ZqJRvr/kwH GqwZVJTS50FtiA8eczBcjs2lQGb283KJBOWJYUmcDYfJiAYMYtmbUWHZs7mXQCygZH0R YNUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=Mx4M+hOcIm/m8fLsqZd3LiXt4cjdnBO461A2GXm7wMU=; b=yuKY1QEXmSBvz8k+PClrnw0icu2V1jK45pWjACij7cB3AQo8JgmVJ/zi4LD3ZI/QHo NNpF/rjn1h7sy9XCrdy3Ab8VB9+7mNcMkdM6I3HQpjyV8djxgXdxw2u6eX2owWFKzUL0 JSGoDddnU4BRWgsD72vZfy0aLHjy6Cs46u0TbD6X4hgipb2+Cf4b5/CZFUKyqECsaVXN iC3zDlfhvIHkVUXrjANu2ZEwRcmF4410jZI/DIz+YjnB44i+MVgimXfiiEY2QZr0xFFv fa5lfZJgHQkIYoCariU+io66HZJyvilMBX2OMpirok7UE608VtijVF7YasaYj/EJ3QGR MCKA== X-Gm-Message-State: AO0yUKUqvY8efnA2DZ57Kl6BmbDduO14pcITXGUuwcr2flj+rsdXR9zs eYoBXuTZLSeaqBNw+tVFdMAq8jVbXmmrn4jR0g== X-Received: by 2002:a5d:59a9:0:b0:2bf:95d6:4789 with SMTP id p9-20020a5d59a9000000b002bf95d64789mr3973049wrr.2.1676981041483; Tue, 21 Feb 2023 04:04:01 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id c15-20020adffb4f000000b002c55b0e6ef1sm5013811wrs.4.2023.02.21.04.04.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:01 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 046/103] gccrs: Add name resolution for closures Date: Tue, 21 Feb 2023 13:01:36 +0100 Message-Id: <20230221120230.596966-47-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230221120230.596966-1-arthur.cohen@embecosm.com> References: <20230221120230.596966-1-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.9 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?1758443962914319803?= X-GMAIL-MSGID: =?utf-8?q?1758443962914319803?= From: Philip Herron gcc/rust/ChangeLog: * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Visit closure properly when name resolving. (ResolveExpr::resolve_closure_param): Implement closure name resolving. * resolve/rust-ast-resolve-expr.h: Declare visitors for closure types. --- gcc/rust/resolve/rust-ast-resolve-expr.cc | 58 +++++++++++++++++++++++ gcc/rust/resolve/rust-ast-resolve-expr.h | 5 ++ 2 files changed, 63 insertions(+) diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.cc b/gcc/rust/resolve/rust-ast-resolve-expr.cc index 40d4af09444..8ece5b63b6d 100644 --- a/gcc/rust/resolve/rust-ast-resolve-expr.cc +++ b/gcc/rust/resolve/rust-ast-resolve-expr.cc @@ -565,6 +565,64 @@ ResolveExpr::visit (AST::RangeFromToInclExpr &expr) ResolveExpr::go (expr.get_to_expr ().get (), prefix, canonical_prefix); } +void +ResolveExpr::visit (AST::ClosureExprInner &expr) +{ + NodeId scope_node_id = expr.get_node_id (); + resolver->get_name_scope ().push (scope_node_id); + resolver->get_type_scope ().push (scope_node_id); + resolver->get_label_scope ().push (scope_node_id); + resolver->push_new_name_rib (resolver->get_name_scope ().peek ()); + resolver->push_new_type_rib (resolver->get_type_scope ().peek ()); + resolver->push_new_label_rib (resolver->get_type_scope ().peek ()); + + for (auto &p : expr.get_params ()) + { + resolve_closure_param (p); + } + + ResolveExpr::go (expr.get_definition_expr ().get (), prefix, + canonical_prefix); + + resolver->get_name_scope ().pop (); + resolver->get_type_scope ().pop (); + resolver->get_label_scope ().pop (); +} + +void +ResolveExpr::visit (AST::ClosureExprInnerTyped &expr) +{ + NodeId scope_node_id = expr.get_node_id (); + resolver->get_name_scope ().push (scope_node_id); + resolver->get_type_scope ().push (scope_node_id); + resolver->get_label_scope ().push (scope_node_id); + resolver->push_new_name_rib (resolver->get_name_scope ().peek ()); + resolver->push_new_type_rib (resolver->get_type_scope ().peek ()); + resolver->push_new_label_rib (resolver->get_type_scope ().peek ()); + + for (auto &p : expr.get_params ()) + { + resolve_closure_param (p); + } + + ResolveType::go (expr.get_return_type ().get ()); + ResolveExpr::go (expr.get_definition_block ().get (), prefix, + canonical_prefix); + + resolver->get_name_scope ().pop (); + resolver->get_type_scope ().pop (); + resolver->get_label_scope ().pop (); +} + +void +ResolveExpr::resolve_closure_param (AST::ClosureParam ¶m) +{ + PatternDeclaration::go (param.get_pattern ().get ()); + + if (param.has_type_given ()) + ResolveType::go (param.get_type ().get ()); +} + ResolveExpr::ResolveExpr (const CanonicalPath &prefix, const CanonicalPath &canonical_prefix) : ResolverBase (), prefix (prefix), canonical_prefix (canonical_prefix) diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.h b/gcc/rust/resolve/rust-ast-resolve-expr.h index 60ae1720811..9e3e7750119 100644 --- a/gcc/rust/resolve/rust-ast-resolve-expr.h +++ b/gcc/rust/resolve/rust-ast-resolve-expr.h @@ -75,6 +75,11 @@ public: void visit (AST::RangeToExpr &expr) override; void visit (AST::RangeFullExpr &expr) override; void visit (AST::RangeFromToInclExpr &expr) override; + void visit (AST::ClosureExprInner &expr) override; + void visit (AST::ClosureExprInnerTyped &expr) override; + +protected: + void resolve_closure_param (AST::ClosureParam ¶m); private: ResolveExpr (const CanonicalPath &prefix,