diff mbox series

[065/125] gccrs: backend: Use new name resolver where necessary

Message ID 20240801145809.366388-67-arthur.cohen@embecosm.com
State New
Headers show
Series [001/125] Rust: Make 'tree'-level 'MAIN_NAME_P' work | expand

Commit Message

Arthur Cohen Aug. 1, 2024, 2:57 p.m. UTC
gcc/rust/ChangeLog:

	* backend/rust-compile-base.cc: Use new ImmutableNrCtx.
	* backend/rust-compile-context.h: Likewise.
	* backend/rust-compile-expr.cc: Likewise.
	* backend/rust-compile-item.cc: Likewise.
---
 gcc/rust/backend/rust-compile-base.cc   |  1 +
 gcc/rust/backend/rust-compile-context.h |  1 +
 gcc/rust/backend/rust-compile-expr.cc   | 22 ++++++++++++++----
 gcc/rust/backend/rust-compile-item.cc   | 31 ++++++++++++++++++++-----
 4 files changed, 44 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc
index 4d6f0275b00..584d6a03ea9 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -31,6 +31,7 @@ 
 #include "rust-type-util.h"
 #include "rust-compile-implitem.h"
 #include "rust-attribute-values.h"
+#include "rust-immutable-name-resolution-context.h"
 
 #include "fold-const.h"
 #include "stringpool.h"
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h
index 36a36e79f68..671aee196c2 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -27,6 +27,7 @@ 
 #include "rust-hir-full.h"
 #include "rust-mangle.h"
 #include "rust-tree.h"
+#include "rust-immutable-name-resolution-context.h"
 
 namespace Rust {
 namespace Compile {
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 65de24bf9d8..6a9bb73ffe0 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -2311,11 +2311,23 @@  CompileExpr::generate_closure_function (HIR::ClosureExpr &expr,
   if (is_block_expr)
     {
       auto body_mappings = function_body->get_mappings ();
-      Resolver::Rib *rib = nullptr;
-      bool ok
-	= ctx->get_resolver ()->find_name_rib (body_mappings.get_nodeid (),
-					       &rib);
-      rust_assert (ok);
+      if (flag_name_resolution_2_0)
+	{
+	  auto nr_ctx
+	    = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+	  auto candidate = nr_ctx.values.to_rib (body_mappings.get_nodeid ());
+
+	  rust_assert (candidate.has_value ());
+	}
+      else
+	{
+	  Resolver::Rib *rib = nullptr;
+	  bool ok
+	    = ctx->get_resolver ()->find_name_rib (body_mappings.get_nodeid (),
+						   &rib);
+	  rust_assert (ok);
+	}
     }
 
   tree enclosing_scope = NULL_TREE;
diff --git a/gcc/rust/backend/rust-compile-item.cc b/gcc/rust/backend/rust-compile-item.cc
index 234ad2aa59c..8feed51efa4 100644
--- a/gcc/rust/backend/rust-compile-item.cc
+++ b/gcc/rust/backend/rust-compile-item.cc
@@ -19,6 +19,7 @@ 
 #include "rust-compile-item.h"
 #include "rust-compile-implitem.h"
 #include "rust-compile-extern.h"
+#include "rust-immutable-name-resolution-context.h"
 
 namespace Rust {
 namespace Compile {
@@ -149,12 +150,30 @@  CompileItem::visit (HIR::Function &function)
 	}
     }
 
-  const Resolver::CanonicalPath *canonical_path = nullptr;
-  bool ok = ctx->get_mappings ()->lookup_canonical_path (
-    function.get_mappings ().get_nodeid (), &canonical_path);
-  rust_assert (ok);
+  Resolver::CanonicalPath canonical_path
+    = Resolver::CanonicalPath::create_empty ();
+
+  if (flag_name_resolution_2_0)
+    {
+      auto nr_ctx
+	= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+      auto path = nr_ctx.values.to_canonical_path (
+	function.get_mappings ().get_nodeid ());
+
+      canonical_path = path.value ();
+    }
+  else
+    {
+      const Resolver::CanonicalPath *path = nullptr;
+      bool ok = ctx->get_mappings ()->lookup_canonical_path (
+	function.get_mappings ().get_nodeid (), &path);
+      rust_assert (ok);
+
+      canonical_path = *path;
+    }
 
-  const std::string asm_name = ctx->mangle_item (fntype, *canonical_path);
+  const std::string asm_name = ctx->mangle_item (fntype, canonical_path);
 
   // items can be forward compiled which means we may not need to invoke this
   // code. We might also have already compiled this generic function as well.
@@ -181,7 +200,7 @@  CompileItem::visit (HIR::Function &function)
 			function.get_function_params (),
 			function.get_qualifiers (), function.get_visibility (),
 			function.get_outer_attrs (), function.get_locus (),
-			function.get_definition ().get (), canonical_path,
+			function.get_definition ().get (), &canonical_path,
 			fntype);
   reference = address_expression (fndecl, ref_locus);