From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 840213858022 for ; Tue, 30 Jan 2024 12:11:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 840213858022 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 840213858022 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::332 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616701; cv=none; b=jFzGPEHYifwP1YN6r3FBCKeZWdYqxcsirKb3GKSfkXHbCQXHh+y8eAwyBTF1pdrejJopCHa2uIAhJS8IG2YkUVGbrc+dHzJA5VerqGQVvx9EM7u0qEErQWG6COYnPcK5fRAkQp86vnh1bZE3ndjOOoXe+h5tZlwqfmUj8y9r2IU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616701; c=relaxed/simple; bh=jv9mW2DrmByg8EcGvLOpP8r8sKEJSP+WSJPCchUykLw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=PTQLJAHsmHHTLrzCmvEsmXkrOw5UVQ06/EalwwQvxAqVR5ISjj1BeILvL3Rv6o7vngHCQ3JAzJS34Typ3YzBnjLauAkOEf7kN+nJPY2O/qVmr9UGF56EUXIOWU/ma1a4/KBWKe0CovkFYacdyIyxIzRPSmaWQlqGx1V595c3COY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40e80046264so48194675e9.0 for ; Tue, 30 Jan 2024 04:11:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616677; x=1707221477; 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=uwiq8F4F7HGDALS4iVjm/n1qtQx7j9Nj3PdBnVt3h+4=; b=JnTOI/zgN/veJgysAnLJwutry8UTupkDMSsknpQ/xH2as3YoNGq/TRBis+kBBLQSMC c6JbzvjR6PKtHl1YFIgWHjCpINF3qRXHo01dkFhFCWiekRSXBLW2nPFhcRvWzq/5wfcf 4AYsn9H2uYd8lxKnbzcyDDwNhaC9d0hpJ5pGYHBpB8BBP8CGWS/lCIzONJpEcMd2rnc5 T7Pbd857IcWopSwo+BUa3RmbM74lYnitiD8zl9dNtDO1D2UQC8eJ05wgk5H261QWMNWR 3EUk4Q7Ro62/ym8vBSJar4qnMGDBZaB17fK/rLPle4z9uZyey3Kl+mrmPsNMwXOs4omw 6dKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616677; x=1707221477; 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=uwiq8F4F7HGDALS4iVjm/n1qtQx7j9Nj3PdBnVt3h+4=; b=FQWRU7WtT0e8xvCwNhmin/bAPn+pgZuRAK2P7e2SiYFjorM/JbGJDnQv+80fw9tpKG UWo0imByyiaVAMiwcOZpB4d7NncyxQeIiaLwHSjBlcrLQAtXIVs7SHBUQh0jlhqpaGNB 2f2mDbDt2jE0x2sh0WNeqn1VBa9ZGwmOcXu3iANP9V6hxgiE5Tt2DzS2vKZphgEu5M9D sL0PS1cInH8VGV35+RZsOSlFlpMm/Zd36bMBq8FQeow0+jBADhsdJuVsei+REUtGzvpi 6kaoC1YKhdTprB095WpQh6OpBL62d1remnyYfttwCMtVshhXtRb9/Qt75UptklOaGvan evNw== X-Gm-Message-State: AOJu0YxXc62Sl2LJN+v0288eZNn74g1bAJEc5uEL6u2evjdfdxBhsA2F hSwPq2JIwy/zqybHyr8+JEcIRwjnBCcTrktcWVabAAQm2HYZBnoBgkfaLQZ/VQ== X-Google-Smtp-Source: AGHT+IE6Yl/pvuur+70b3/6TNt77OPjg2V1vQtN7mpnDyBCj6JIpZelRzYyZL/AJ6rNWnMtIVO9RhA== X-Received: by 2002:a05:600c:502b:b0:40e:f9d4:2b03 with SMTP id n43-20020a05600c502b00b0040ef9d42b03mr3452305wmr.12.1706616677305; Tue, 30 Jan 2024 04:11:17 -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.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:16 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED 037/101] gccrs: late: Start setting up builtin types Date: Tue, 30 Jan 2024 13:06:53 +0100 Message-ID: <20240130121026.807464-40-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> Reply-To: arthur.cohen@embecosm.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 List-Id: From: Arthur Cohen gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::setup_builtin_types): New function. (Late::go): Setup builtin types. * resolve/rust-late-name-resolver-2.0.h: * resolve/rust-name-resolution-context.cc (NameResolutionContext::map_usage): New function. * resolve/rust-name-resolution-context.h: Likewise. --- .../resolve/rust-late-name-resolver-2.0.cc | 42 +++++++++++++++++++ .../resolve/rust-late-name-resolver-2.0.h | 2 + .../resolve/rust-name-resolution-context.cc | 9 ++++ .../resolve/rust-name-resolution-context.h | 8 +++- 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc index 352d59b0920..3236886f37d 100644 --- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc @@ -16,18 +16,60 @@ // along with GCC; see the file COPYING3. If not see // . +#include "optional.h" #include "rust-ast-full.h" #include "rust-late-name-resolver-2.0.h" #include "rust-default-resolver.h" +#include "rust-tyty.h" +#include "rust-hir-type-check.h" namespace Rust { namespace Resolver2_0 { Late::Late (NameResolutionContext &ctx) : DefaultResolver (ctx) {} +void +Late::setup_builtin_types () +{ + auto next_id = [this] () { return ctx.mappings.get_next_hir_id (); }; + + static const std::pair builtins[] = { + {"u8", new TyTy::UintType (next_id (), TyTy::UintType::U8)}, + {"u16", new TyTy::UintType (next_id (), TyTy::UintType::U16)}, + {"u32", new TyTy::UintType (next_id (), TyTy::UintType::U32)}, + {"u64", new TyTy::UintType (next_id (), TyTy::UintType::U64)}, + {"u128", new TyTy::UintType (next_id (), TyTy::UintType::U128)}, + {"i8", new TyTy::IntType (next_id (), TyTy::IntType::I8)}, + {"i16", new TyTy::IntType (next_id (), TyTy::IntType::I16)}, + {"i32", new TyTy::IntType (next_id (), TyTy::IntType::I32)}, + {"i64", new TyTy::IntType (next_id (), TyTy::IntType::I64)}, + {"i128", new TyTy::IntType (next_id (), TyTy::IntType::I128)}, + {"f32", new TyTy::FloatType (next_id (), TyTy::FloatType::F32)}, + {"f64", new TyTy::FloatType (next_id (), TyTy::FloatType::F64)}, + {"usize", new TyTy::USizeType (next_id ())}, + {"isize", new TyTy::ISizeType (next_id ())}, + // missing char, str, never, () + // does name resolution play a part for this? or is it all at typechecking? + // yeah it seems to be name resolution as well, which makes sense + }; + + for (const auto &builtin : builtins) + { + // we should be able to use `insert_at_root` or `insert` here, since we're + // at the root :) hopefully! + auto ok + = ctx.types.insert (builtin.first, builtin.second->get_ref () + /* FIXME: Invalid! This returns an *HirId* */); + + rust_assert (ok); + } +} + void Late::go (AST::Crate &crate) { + setup_builtin_types (); + for (auto &item : crate.items) item->accept_vis (*this); } diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.h b/gcc/rust/resolve/rust-late-name-resolver-2.0.h index 12540c0d220..f54bbf2eea4 100644 --- a/gcc/rust/resolve/rust-late-name-resolver-2.0.h +++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.h @@ -47,6 +47,8 @@ public: void visit (AST::PathInExpression &) override; private: + /* Setup Rust's builtin types (u8, i32, !...) in the resolver */ + void setup_builtin_types (); }; // TODO: Add missing mappings and data structures diff --git a/gcc/rust/resolve/rust-name-resolution-context.cc b/gcc/rust/resolve/rust-name-resolution-context.cc index 8bb7a9a15c1..f71ef91505b 100644 --- a/gcc/rust/resolve/rust-name-resolution-context.cc +++ b/gcc/rust/resolve/rust-name-resolution-context.cc @@ -43,6 +43,15 @@ NameResolutionContext::insert (Identifier name, NodeId id, Namespace ns) } } +void +NameResolutionContext::map_usage (NodeId usage, NodeId definition) +{ + auto inserted = resolved_nodes.emplace (usage, definition).second; + + // is that valid? + rust_assert (inserted); +} + void NameResolutionContext::scoped (Rib rib, NodeId id, std::function lambda, diff --git a/gcc/rust/resolve/rust-name-resolution-context.h b/gcc/rust/resolve/rust-name-resolution-context.h index d63ee33378b..7a1924581ab 100644 --- a/gcc/rust/resolve/rust-name-resolution-context.h +++ b/gcc/rust/resolve/rust-name-resolution-context.h @@ -19,7 +19,6 @@ #ifndef RUST_NAME_RESOLVER_2_0_H #define RUST_NAME_RESOLVER_2_0_H -#include "optional.h" #include "rust-forever-stack.h" #include "rust-hir-map.h" @@ -179,6 +178,13 @@ public: ForeverStack labels; Analysis::Mappings &mappings; + + // TODO: Rename + void map_usage (NodeId usage, NodeId definition); + +private: + /* Map of "usage" nodes which have been resolved to a "definition" node */ + std::map resolved_nodes; }; } // namespace Resolver2_0 -- 2.42.1