From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id 37CC33857B88 for ; Tue, 30 Jan 2024 12:11:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 37CC33857B88 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 37CC33857B88 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616700; cv=none; b=B3oLQWAaa5p3u/SzEQIFE9yJEfOyLmjmD0RUwu5sT4WjSZbpL0KhXzC6M8c80NiYP6p+aUgojMJWcwR3Zuie9IsrXKjRc6Cgh6gtQVBxZnOV+tas/g6UvHCOGFONaD5YpTvs3oRs3V7IeDfaTUcfjCFNRuqeuhQGP1gP5pcWoaI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616700; c=relaxed/simple; bh=jv9mW2DrmByg8EcGvLOpP8r8sKEJSP+WSJPCchUykLw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=vZFDlohUCm8TQsmen4DwujPKgLrIzKOLBkLMRI142rJUpFD3WuB/M3g+OQsDr9bR2z0ESzmjQcjkzECF4pmjessXdSjw59CAba6y7zeX7qBQW4U9WIjfERoP+/MUeibB1d664ToX54oXaQtMt+eL2xfhzkkts1U44omnCr/8ymU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-40faff092a2so521055e9.2 for ; Tue, 30 Jan 2024 04:11:19 -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=O9+S8eqZZhZsi4cA8H6soFz83YL/R9ts4dSSAqZY2bJh/1THUBLELcdUbam2Z1Ab5X 41ngvgf97RX7mxYwR3/R1iBfL/fMCzpTPGwfSry3Qis+AVSVlTOd+0IapDJksgd4JTPK QzH0UkmCQbr/C+H3jRfjBLKw5P0v4wVzvt6Jxj6ms5RPg69Nf78llpaasRkOjTYVaLrV sxW+aRqkfcMWKCkTOciO7rD4VeQLnUGC5pDeI383/ccS6CJJGOm5o4wHt+kVgGypu2Yj 6Euqsp8u/Vf7MQWWtQCJrTszSji1QHLDG6KvX7yRxjv5NZYTFpLbPvrpmZYgVe4zxpER TQ0Q== X-Gm-Message-State: AOJu0YwDY1FCo0ZMv8Ewrw4/jS5CgvxZonusnX9x4s2njHvcqvx3Gndb ElFcI/OyDZyv4POxo9syw7ImeHMxBzZxlhhMivYSmQjOSgE5+bXfFGabE9/4s+4JnvMepAsFI3l sFQ== 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=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: 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