Skip to content

Commit

Permalink
gccrs: sesh: Add late name resolution 2.0
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
CohenArthur committed Aug 1, 2024
1 parent 9bf8024 commit c3b40bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 9 additions & 5 deletions gcc/rust/rust-session-manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
{
Expand All @@ -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))
{
Expand Down Expand Up @@ -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");

Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion gcc/rust/rust-session-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -413,7 +414,7 @@ struct Session
/* 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);
Expand Down

0 comments on commit c3b40bc

Please sign in to comment.