https://gcc.gnu.org/g:c9593a06449f5030dab77a752cf8338693532519

commit r16-6836-gc9593a06449f5030dab77a752cf8338693532519
Author: Arthur Cohen <[email protected]>
Date:   Wed Sep 10 09:39:18 2025 +0200

    gccrs: forever-stack: Add extra path resolution from a known NodeId.
    
    gcc/rust/ChangeLog:
    
            * resolve/rust-forever-stack.h: Add new resolve_path function.
            * resolve/rust-forever-stack.hxx: Implement it.

Diff:
---
 gcc/rust/resolve/rust-forever-stack.h   | 18 ++++++++++++++++-
 gcc/rust/resolve/rust-forever-stack.hxx | 35 ++++++++++++++++++++++++++++++++-
 2 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/resolve/rust-forever-stack.h 
b/gcc/rust/resolve/rust-forever-stack.h
index fb265582ad17..2a88df7b9e0b 100644
--- a/gcc/rust/resolve/rust-forever-stack.h
+++ b/gcc/rust/resolve/rust-forever-stack.h
@@ -682,6 +682,11 @@ public:
     const std::vector<S> &segments, ResolutionMode mode,
     std::function<void (const S &, NodeId)> insert_segment_resolution,
     std::vector<Error> &collect_errors);
+  template <typename S>
+  tl::optional<Rib::Definition> resolve_path (
+    const std::vector<S> &segments, ResolutionMode mode,
+    std::function<void (const S &, NodeId)> insert_segment_resolution,
+    std::vector<Error> &collect_errors, NodeId starting_point_id);
 
   // FIXME: Documentation
   tl::optional<Rib &> to_rib (NodeId rib_id);
@@ -743,9 +748,19 @@ private:
     tl::optional<Node &> parent; // `None` only if the node is a root
   };
 
-  // private overload which allows specifying a starting point
+  /**
+   * Private overloads which allow specifying a starting point
+   */
+
   tl::optional<Rib::Definition> get (Node &start, const Identifier &name);
 
+  template <typename S>
+  tl::optional<Rib::Definition> resolve_path (
+    const std::vector<S> &segments, ResolutionMode mode,
+    std::function<void (const S &, NodeId)> insert_segment_resolution,
+    std::vector<Error> &collect_errors,
+    std::reference_wrapper<Node> starting_point);
+
   /* Should we keep going upon seeing a Rib? */
   enum class KeepGoing
   {
@@ -777,6 +792,7 @@ private:
    * resolution
    */
   Node lang_prelude;
+
   /*
    * The extern prelude, used for resolving external crates
    */
diff --git a/gcc/rust/resolve/rust-forever-stack.hxx 
b/gcc/rust/resolve/rust-forever-stack.hxx
index cd13af0158df..bd35d6c4e4a7 100644
--- a/gcc/rust/resolve/rust-forever-stack.hxx
+++ b/gcc/rust/resolve/rust-forever-stack.hxx
@@ -647,6 +647,25 @@ ForeverStack<N>::resolve_final_segment (Node &final_node, 
std::string &seg_name,
   return final_node.rib.get (seg_name);
 }
 
+template <Namespace N>
+template <typename S>
+tl::optional<Rib::Definition>
+ForeverStack<N>::resolve_path (
+  const std::vector<S> &segments, ResolutionMode mode,
+  std::function<void (const S &, NodeId)> insert_segment_resolution,
+  std::vector<Error> &collect_errors, NodeId starting_point_id)
+{
+  auto starting_point = dfs_node (root, starting_point_id);
+
+  // We may have a prelude, but haven't visited it yet and thus it's not in our
+  // nodes
+  if (!starting_point)
+    return tl::nullopt;
+
+  return resolve_path (segments, mode, insert_segment_resolution,
+                      collect_errors, *starting_point);
+}
+
 template <Namespace N>
 template <typename S>
 tl::optional<Rib::Definition>
@@ -654,10 +673,24 @@ ForeverStack<N>::resolve_path (
   const std::vector<S> &segments, ResolutionMode mode,
   std::function<void (const S &, NodeId)> insert_segment_resolution,
   std::vector<Error> &collect_errors)
+{
+  std::reference_wrapper<Node> starting_point = cursor ();
+
+  return resolve_path (segments, mode, insert_segment_resolution,
+                      collect_errors, starting_point);
+}
+
+template <Namespace N>
+template <typename S>
+tl::optional<Rib::Definition>
+ForeverStack<N>::resolve_path (
+  const std::vector<S> &segments, ResolutionMode mode,
+  std::function<void (const S &, NodeId)> insert_segment_resolution,
+  std::vector<Error> &collect_errors,
+  std::reference_wrapper<Node> starting_point)
 {
   rust_assert (!segments.empty ());
 
-  std::reference_wrapper<Node> starting_point = cursor ();
   switch (mode)
     {
     case ResolutionMode::Normal:

Reply via email to