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

commit b281eb02d4caeadf087c37c3312039aa45c75da9
Author: Arthur Cohen <arthur.co...@embecosm.com>
Date:   Fri Aug 4 11:11:13 2023 +0200

    sesh: Add late name resolution 2.0
    
    gcc/rust/ChangeLog:
    
            * rust-session-manager.cc (Session::compile_crate): Create name 
resolution
            context for Session::expansion and subsequent name resolution 
passes.
            (Session::expansion): Take name resolution context as a parameter
            instead.
            * rust-session-manager.h (Session::expansion): Fix declaration.

Diff:
---
 gcc/rust/rust-session-manager.cc | 14 +++++++++-----
 gcc/rust/rust-session-manager.h  |  3 ++-
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index ea99d019f64f..40adeb20de49 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -42,6 +42,7 @@
 #include "rust-early-name-resolver.h"
 #include "rust-name-resolution-context.h"
 #include "rust-early-name-resolver-2.0.h"
+#include "rust-late-name-resolver-2.0.h"
 #include "rust-cfg-strip.h"
 #include "rust-expand-visitor.h"
 #include "rust-unicode.h"
@@ -591,8 +592,10 @@ Session::compile_crate (const char *filename)
   if (last_step == CompileOptions::CompileStep::Expansion)
     return;
 
+  auto name_resolution_ctx = Resolver2_0::NameResolutionContext ();
   // expansion pipeline stage
-  expansion (parsed_crate);
+
+  expansion (parsed_crate, name_resolution_ctx);
   rust_debug ("\033[0;31mSUCCESSFULLY FINISHED EXPANSION \033[0m");
   if (options.dump_option_enabled (CompileOptions::EXPANSION_DUMP))
     {
@@ -617,7 +620,10 @@ Session::compile_crate (const char *filename)
     return;
 
   // resolution pipeline stage
-  Resolver::NameResolution::Resolve (parsed_crate);
+  if (flag_name_resolution_2_0)
+    Resolver2_0::Late (name_resolution_ctx).go (parsed_crate);
+  else
+    Resolver::NameResolution::Resolve (parsed_crate);
 
   if (options.dump_option_enabled (CompileOptions::RESOLUTION_DUMP))
     {
@@ -881,7 +887,7 @@ Session::injection (AST::Crate &crate)
 }
 
 void
-Session::expansion (AST::Crate &crate)
+Session::expansion (AST::Crate &crate, Resolver2_0::NameResolutionContext &ctx)
 {
   rust_debug ("started expansion");
 
@@ -908,8 +914,6 @@ Session::expansion (AST::Crate &crate)
       if (saw_errors ())
        break;
 
-      auto ctx = Resolver2_0::NameResolutionContext ();
-
       if (flag_name_resolution_2_0)
        {
          Resolver2_0::Early early (ctx);
diff --git a/gcc/rust/rust-session-manager.h b/gcc/rust/rust-session-manager.h
index 41aad6079058..9a5691f45eeb 100644
--- a/gcc/rust/rust-session-manager.h
+++ b/gcc/rust/rust-session-manager.h
@@ -24,6 +24,7 @@
 #include "rust-backend.h"
 #include "rust-hir-map.h"
 #include "safe-ctype.h"
+#include "rust-name-resolution-context.h"
 
 #include "config.h"
 #include "rust-system.h"
@@ -413,7 +414,7 @@ private:
   /* Expansion pipeline stage. TODO maybe move to another object? Expands all
    * macros, maybe build test harness in future, AST validation, maybe create
    * macro crate (if not rustdoc).*/
-  void expansion (AST::Crate &crate);
+  void expansion (AST::Crate &crate, Resolver2_0::NameResolutionContext &ctx);
 
   // handle cfg_option
   bool handle_cfg_option (std::string &data);

Reply via email to