From patchwork Tue Jan 30 12:06:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 194090 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1184128dyb; Tue, 30 Jan 2024 04:30:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IEH8QTaeCRZxtFrMK+o9pRW1DBlCvVzGnJYzi+9Ih1ky9hFDgNo0a4YqEPlPFw/gi0iNsQu X-Received: by 2002:a05:620a:4ac6:b0:784:880:6668 with SMTP id sq6-20020a05620a4ac600b0078408806668mr2215179qkn.76.1706617825964; Tue, 30 Jan 2024 04:30:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706617825; cv=pass; d=google.com; s=arc-20160816; b=VCUdUyT1hPZ3OVPEUdcDvJ97wmDD9ZW706WGZKaILEo2U7F1tSahGec248Xgu5I7mw DmSldi8i/+fbill7AGSrrnAmODS9YOv16oxEgXQ8OUxG1me6RE9JckTK1hI69aUkdsBV dPiH74DVfDfha7QQ7nHq1jS4O6WRtZ33aeKQL8CV4eFW0g+mTnENHmpEpaEM5VwLvJ9p PnPsR7i7etoQUpvhI88djiCn2+A0Gb0U7p6rwkxcmGC3AgjOPG+4YnTl6DmKWRAfJ7AM t6/ix9RjhS9a2EpjiKWKcAhU/jzzs105tI4xiOi8pmTiVVOGYhJyjJu5WeNwnskx4mcz cofA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=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:arc-filter:dmarc-filter:delivered-to; bh=5b02A3thki/rKgHoCIWOYRR6iZyiTHc+tKiC4usqP4Y=; fh=6KiXNvQww/MsyVplklPLl//mUuD+DtDm73nSHh4O4+g=; b=A9bhzzJ1Snf5rSFTPlqlgp0U5zZspqvWR1ukxYyjKWbdc3oSh8mQm3InPhIUAfuOzb c4uxIWmd9/52YDlJ5byu59WZvAp2q/OAuqr9S0I5h/zEd8Ch4vmx0j2XQZaXJfh4JHfE CP4a/HLDZixEZlFy/gq5jvwBTCyaLwHTvPr8jyXq48dVtQN8CZTAmb4+6kZcOYL4kY2d p4PeH0XcNbl/XlcKRsNPJXFaDdSLURvkMdJ7Br7Fxo2RDd+3tirc/IFU8L5dNCI9XQzV XgOjWVVPogfF9A18lrtTENkby0jCu37xOPgIBQESLTVkih93tzQmKiXOU11cKxd++z9E eo6A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=EPrbzGHf; arc=pass (i=1); 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d11-20020a05620a136b00b00783f9af3d97si5112675qkl.612.2024.01.30.04.30.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:30:25 -0800 (PST) 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=EPrbzGHf; arc=pass (i=1); 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 712B0386F450 for ; Tue, 30 Jan 2024 12:30:09 +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 6B4A23857C4B for ; Tue, 30 Jan 2024 12:11:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6B4A23857C4B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6B4A23857C4B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::334 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616696; cv=none; b=nb7+doi5CVR7yzvV83mTDkUJ+WNu5Ock5jf7OsWvkHWmXKLMSfK8sowVVx0DhlIdFjsmGV9CxEJRJDE95TLRw9CgnSrt/3+HAL6kfOG13qLTL+9PudMycdPmYmwNdOuekn1jujOSBMYR15ALADhf/s7uar5KO9yHvrS+i3yMkU8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616696; c=relaxed/simple; bh=9buXZqtaGoK/zH4RbZYZ/kqgVU2UzhcwgSt2yttomvE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=nfvJUxFzjzT0g1NrV38pB5yvpIdDmzW2wsYNrJN2oLgAJOwztHiXZgLwjACyPVPkqCuzvkVewwzeF8wUHf4pvmIJZ5Ri6AhbtIOAJkPwL6ha/zet3ziudBpYIuez1hF9DRluLL+2WWpfsiL5XFyCWfLAavBiKpSTPOa/q/iJddE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40e72a567eeso56789655e9.0 for ; Tue, 30 Jan 2024 04:11:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616676; x=1707221476; darn=gcc.gnu.org; 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=5b02A3thki/rKgHoCIWOYRR6iZyiTHc+tKiC4usqP4Y=; b=EPrbzGHfr3Y6s1yUizQXZjybhrKambNbsL6q15Cv1hGu41NM7+fW3UyTK3Ps1VDbjy P4aHtKa1EzjoZLH8g3/WRBDRIPdMcF2vBM/QGi4jYCcw0wW+gBZsuEiS0A31c1SHCj3C 6TiH8PKAjp+Hcl9AtJ3VXoD+rZvNhFEHp6SMQIw3Roh95eN/h2MUx0LphqreGFzZsnFl RqVEWtO4oRqnT4XJLti9HbZi8/UicIEHuXGH9mp/ae0QKOdAmG9mJt0OLwaggrgUTANW lYZacNqRqh99IHYmS0czUyZURokaUyjnSDRDLUqh+gb/3Q152lROVezDHIkueGx2TSt9 OxLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616676; x=1707221476; 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=5b02A3thki/rKgHoCIWOYRR6iZyiTHc+tKiC4usqP4Y=; b=BXiMWU8/qROrWA2izl2eA1FcuyqNZGvHHiG4FjIgstwaWH+6G9QUKn4siHK1UkySZj 9BJoOhk5mSs+kkBAZlx+v1rYJWYPmmwMHN9EYbXrER4eRqZRj95x4k2jma6XavYbMh3P SDcRTREa9rwAOYSGao51SOGauXMhMkQSUoNU0DEyAVn1DStDLI0mbbUAMbJZqv1Y+ugy pUHJyEhXvGg1NlTGriRQpkatBvs4zwNA1noIWLAbDExpC+aes2nOrnE9pOkOpUikYPDs smj/kqwtGDMhXDOuxsss3Fd+Bfkyf1EFCg/8/64tLN443w62HfCIV2LN2w++vfuGao47 Sm0A== X-Gm-Message-State: AOJu0YzGMq86tVbD0rLUNYhvGb+fMT+80tQ/EbXSKZGShMYruxX5oxpY Hi0tSEyKOz5I4cgrXvVnzECF4OHB8c35/pqLeqchQ+iMR2Ds/mkYvLPRkbJq3ldK9uJRLhW7Y5q osg== X-Received: by 2002:a05:600c:4754:b0:40e:a39e:461f with SMTP id w20-20020a05600c475400b0040ea39e461fmr7891402wmo.38.1706616675929; Tue, 30 Jan 2024 04:11:15 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id f9-20020a056000036900b00339307d9d31sm10569894wrf.112.2024.01.30.04.11.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:14 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED 034/101] gccrs: nr2.0: Add base for late name resolution Date: Tue, 30 Jan 2024 13:06:50 +0100 Message-ID: <20240130121026.807464-37-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20240130121026.807464-2-arthur.cohen@embecosm.com> References: <20240130121026.807464-2-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.1 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_SCC_BODY_TEXT_LINE 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.30 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789518493583834966 X-GMAIL-MSGID: 1789518493583834966 From: Arthur Cohen gcc/rust/ChangeLog: * Make-lang.in: Compile late name resolver. * resolve/rust-late-name-resolver-2.0.cc: New file. * resolve/rust-late-name-resolver-2.0.h: New file. --- gcc/rust/Make-lang.in | 1 + .../resolve/rust-late-name-resolver-2.0.cc | 105 ++++++++++++++++++ .../resolve/rust-late-name-resolver-2.0.h | 57 ++++++++++ 3 files changed, 163 insertions(+) create mode 100644 gcc/rust/resolve/rust-late-name-resolver-2.0.cc create mode 100644 gcc/rust/resolve/rust-late-name-resolver-2.0.h diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index f2cadd55eed..47cc87750be 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -116,6 +116,7 @@ GRS_OBJS = \ rust/rust-default-resolver.o \ rust/rust-toplevel-name-resolver-2.0.o \ rust/rust-early-name-resolver-2.0.o \ + rust/rust-late-name-resolver-2.0.o \ rust/rust-early-name-resolver.o \ rust/rust-name-resolver.o \ rust/rust-ast-resolve.o \ diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc new file mode 100644 index 00000000000..352d59b0920 --- /dev/null +++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc @@ -0,0 +1,105 @@ +// 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 +// . + +#include "rust-ast-full.h" +#include "rust-late-name-resolver-2.0.h" +#include "rust-default-resolver.h" + +namespace Rust { +namespace Resolver2_0 { + +Late::Late (NameResolutionContext &ctx) : DefaultResolver (ctx) {} + +void +Late::go (AST::Crate &crate) +{ + for (auto &item : crate.items) + item->accept_vis (*this); +} + +void +Late::new_label (Identifier name, NodeId id) +{ + // labels can always shadow, so `insert` should never fail. if it does, we're + // in big trouble! + auto ok = ctx.labels.insert (name, id); + + rust_assert (ok); +} + +void +Late::visit (AST::LetStmt &let) +{ + // so we don't need that method + DefaultResolver::visit (let); + + // how do we deal with the fact that `let a = blipbloup` should look for a + // label and cannot go through function ribs, but `let a = blipbloup()` can? + + // how do we insert ribs here, and only pop them when we exit the current + // function? + // keep a list of ribs to pop when a scope exits? so only for blocks? + // how do we pop ribs that need to be popped not in order? + // I think it's not important if we have shadowing, correct? + + // if we have shadowing, it should work! we'll see + + // ctx.insert(Identifier name, NodeId id, Namespace ns) + // ctx.scoped (Rib::Kind::Normal /* FIXME: Is that valid? */, + // Namespace::Labels, + // let.get_node_id (), [] () {}); +} + +void +Late::visit (AST::IdentifierPattern &identifier) +{ + // do we insert in labels or in values + // but values does not allow shadowing... since functions cannot shadow + // do we insert functions in labels as well? + new_label (identifier.get_ident (), identifier.get_node_id ()); +} + +void +Late::visit (AST::IdentifierExpr &expr) +{ + // TODO: same thing as visit(PathInExpression) here? + + auto label = ctx.labels.get (expr.get_ident ()); + auto value = ctx.values.get (expr.get_ident ()); + + rust_debug ("[ARTHUR] label: %d", label ? *label : -1); + rust_debug ("[ARTHUR] value: %d", value ? *value : -1); +} + +void +Late::visit (AST::PathInExpression &expr) +{ + // TODO: How do we have a nice error with `can't capture dynamic environment + // in a function item` error here? + // do we emit it in `get`? + + auto label = ctx.labels.resolve_path (expr.get_segments ()); + + auto value = ctx.values.resolve_path (expr.get_segments ()); + + rust_debug ("[ARTHUR] label: %d", label ? *label : -1); + rust_debug ("[ARTHUR] value: %d", value ? *value : -1); +} + +} // namespace Resolver2_0 +} // namespace Rust diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.h b/gcc/rust/resolve/rust-late-name-resolver-2.0.h new file mode 100644 index 00000000000..12540c0d220 --- /dev/null +++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.h @@ -0,0 +1,57 @@ +// 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_LATE_NAME_RESOLVER_2_0_H +#define RUST_LATE_NAME_RESOLVER_2_0_H + +#include "rust-ast-full.h" +#include "rust-default-resolver.h" + +namespace Rust { +namespace Resolver2_0 { + +class Late : public DefaultResolver +{ + using DefaultResolver::visit; + +public: + Late (NameResolutionContext &ctx); + + void go (AST::Crate &crate); + + void new_label (Identifier name, NodeId id); + + // some more label declarations + void visit (AST::LetStmt &) override; + // TODO: Do we need this? + // void visit (AST::Method &) override; + void visit (AST::IdentifierPattern &) override; + + // resolutions + void visit (AST::IdentifierExpr &) override; + void visit (AST::PathInExpression &) override; + +private: +}; + +// TODO: Add missing mappings and data structures + +} // namespace Resolver2_0 +} // namespace Rust + +#endif // ! RUST_LATE_NAME_RESOLVER_2_0_H