diff mbox series

[075/125] gccrs: Shape up name resolver for normal direct calls

Message ID 20240801145809.366388-77-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
From: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>

Direct function calls did not work anymore due to the transition to the
new resolver.

gcc/rust/ChangeLog:

	* checks/lints/rust-lint-marklive.cc (MarkLive::find_ref_node_id):
	Add code path for the resolver 2.0
	* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Remove failing
	label context resolve call.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
---
 gcc/rust/checks/lints/rust-lint-marklive.cc   | 23 +++++++++++++++----
 .../resolve/rust-late-name-resolver-2.0.cc    |  3 ++-
 2 files changed, 21 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/gcc/rust/checks/lints/rust-lint-marklive.cc b/gcc/rust/checks/lints/rust-lint-marklive.cc
index 8787a9d8550..1a0a0a2b904 100644
--- a/gcc/rust/checks/lints/rust-lint-marklive.cc
+++ b/gcc/rust/checks/lints/rust-lint-marklive.cc
@@ -20,8 +20,10 @@ 
 // from live codes are live, and everything else is dead.
 
 #include "rust-lint-marklive.h"
+#include "options.h"
 #include "rust-hir-full.h"
 #include "rust-name-resolver.h"
+#include "rust-immutable-name-resolution-context.h"
 
 namespace Rust {
 namespace Analysis {
@@ -270,12 +272,25 @@  MarkLive::mark_hir_id (HirId id)
 void
 MarkLive::find_ref_node_id (NodeId ast_node_id, NodeId &ref_node_id)
 {
-  if (!resolver->lookup_resolved_name (ast_node_id, &ref_node_id))
+  if (flag_name_resolution_2_0)
     {
-      if (!resolver->lookup_resolved_type (ast_node_id, &ref_node_id))
+      auto nr_ctx
+	= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+      nr_ctx.lookup (ast_node_id).map ([&ref_node_id] (NodeId resolved) {
+	ref_node_id = resolved;
+      });
+    }
+  else
+    {
+      if (!resolver->lookup_resolved_name (ast_node_id, &ref_node_id))
 	{
-	  bool ok = resolver->lookup_resolved_misc (ast_node_id, &ref_node_id);
-	  rust_assert (ok);
+	  if (!resolver->lookup_resolved_type (ast_node_id, &ref_node_id))
+	    {
+	      bool ok
+		= resolver->lookup_resolved_misc (ast_node_id, &ref_node_id);
+	      rust_assert (ok);
+	    }
 	}
     }
 }
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 ee06c4efc2e..68eb88a1e4c 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -196,8 +196,9 @@  Late::visit (AST::PathInExpression &expr)
   // in a function item` error here?
   // do we emit it in `get<Namespace::Labels>`?
 
-  auto label = ctx.labels.resolve_path (expr.get_segments ());
   auto value = ctx.values.resolve_path (expr.get_segments ());
+
+  ctx.map_usage (Usage (expr.get_node_id ()), Definition (*value));
 }
 
 void