From: arthur.cohen@embecosm.com
To: gcc-patches@gcc.gnu.org
Cc: gcc-rust@gcc.gnu.org, Arthur Cohen <arthur.cohen@embecosm.com>
Subject: [committed 020/103] gccrs: early-name-resolver: Add simple macro name resolution
Date: Tue, 21 Feb 2023 13:01:10 +0100 [thread overview]
Message-ID: <20230221120230.596966-21-arthur.cohen@embecosm.com> (raw)
In-Reply-To: <20230221120230.596966-1-arthur.cohen@embecosm.com>
From: Arthur Cohen <arthur.cohen@embecosm.com>
This name resolver performs the same macro name resolution as what was
previously done by the AttrVisitor visitor and macro expander.
It also resolves macro expressions in builtin-macros properly, as well
as expanded AST nodes when necessary.
gcc/rust/ChangeLog:
* Make-lang.in: Compile early name resolver.
* expand/rust-attribute-visitor.cc (AttrVisitor::visit): Move macro
name resolution.
* expand/rust-macro-builtins.cc (try_expand_macro_expression): Run ENR
when recursively expanding macros.
* expand/rust-macro-expand.cc (MacroExpander::expand_invoc): No longer
perform name resolution in `expand_invoc`.
* expand/rust-macro-expand.h (struct MacroExpander): Keep ENR within
MacroExpander.
* rust-session-manager.cc (Session::expansion): Run ENR.
* resolve/rust-early-name-resolver.cc: New file.
* resolve/rust-early-name-resolver.h: New file.
---
gcc/rust/Make-lang.in | 1 +
gcc/rust/expand/rust-attribute-visitor.cc | 10 -
gcc/rust/expand/rust-macro-builtins.cc | 9 +-
gcc/rust/expand/rust-macro-expand.cc | 30 +-
gcc/rust/expand/rust-macro-expand.h | 4 +
gcc/rust/resolve/rust-early-name-resolver.cc | 1087 ++++++++++++++++++
gcc/rust/resolve/rust-early-name-resolver.h | 210 ++++
gcc/rust/rust-session-manager.cc | 4 +
8 files changed, 1320 insertions(+), 35 deletions(-)
create mode 100644 gcc/rust/resolve/rust-early-name-resolver.cc
create mode 100644 gcc/rust/resolve/rust-early-name-resolver.h
diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index a24025cb31c..a906516bd33 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -93,6 +93,7 @@ GRS_OBJS = \
rust/rust-ast-lower-base.o \
rust/rust-ast-lower-pattern.o \
rust/rust-ast-lower-item.o \
+ rust/rust-early-name-resolver.o \
rust/rust-name-resolver.o \
rust/rust-ast-resolve.o \
rust/rust-ast-resolve-base.o \
diff --git a/gcc/rust/expand/rust-attribute-visitor.cc b/gcc/rust/expand/rust-attribute-visitor.cc
index 673f0432a30..a1895749b82 100644
--- a/gcc/rust/expand/rust-attribute-visitor.cc
+++ b/gcc/rust/expand/rust-attribute-visitor.cc
@@ -2877,16 +2877,6 @@ AttrVisitor::visit (AST::MacroRulesDefinition &rules_def)
rules_def.mark_for_strip ();
return;
}
-
- // I don't think any macro rules can be stripped in any way
-
- auto path = Resolver::CanonicalPath::new_seg (rules_def.get_node_id (),
- rules_def.get_rule_name ());
- expander.resolver->get_macro_scope ().insert (path, rules_def.get_node_id (),
- rules_def.get_locus ());
- expander.mappings->insert_macro_def (&rules_def);
- rust_debug_loc (rules_def.get_locus (), "inserting macro def: [%s]",
- path.get ().c_str ());
}
void
diff --git a/gcc/rust/expand/rust-macro-builtins.cc b/gcc/rust/expand/rust-macro-builtins.cc
index 606f33c65bc..a230ad9f2d8 100644
--- a/gcc/rust/expand/rust-macro-builtins.cc
+++ b/gcc/rust/expand/rust-macro-builtins.cc
@@ -24,6 +24,7 @@
#include "rust-macro-invoc-lexer.h"
#include "rust-lex.h"
#include "rust-parse.h"
+#include "rust-early-name-resolver.h"
#include "rust-attribute-visitor.h"
namespace Rust {
@@ -70,9 +71,11 @@ try_expand_macro_expression (AST::Expr *expr, MacroExpander *expander)
{
rust_assert (expander);
- auto vis = Rust::AttrVisitor (*expander);
- expr->accept_vis (vis);
- return expander->take_expanded_fragment (vis);
+ auto attr_visitor = Rust::AttrVisitor (*expander);
+ auto early_name_resolver = Resolver::EarlyNameResolver ();
+ expr->accept_vis (early_name_resolver);
+ expr->accept_vis (attr_visitor);
+ return expander->take_expanded_fragment (attr_visitor);
}
/* Expand and then extract a string literal from the macro */
diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc
index fbf33209c5f..d94cd118700 100644
--- a/gcc/rust/expand/rust-macro-expand.cc
+++ b/gcc/rust/expand/rust-macro-expand.cc
@@ -23,6 +23,7 @@
#include "rust-diagnostics.h"
#include "rust-parse.h"
#include "rust-attribute-visitor.h"
+#include "rust-early-name-resolver.h"
namespace Rust {
AST::ASTFragment
@@ -138,32 +139,17 @@ MacroExpander::expand_invoc (AST::MacroInvocation &invoc, bool has_semicolon)
// - else is unreachable
// - derive container macro - unreachable
- // lookup the rules for this macro
- NodeId resolved_node = UNKNOWN_NODEID;
- NodeId source_node = UNKNOWN_NODEID;
- if (has_semicolon)
- source_node = invoc.get_macro_node_id ();
- else
- source_node = invoc.get_pattern_node_id ();
- auto seg
- = Resolver::CanonicalPath::new_seg (source_node,
- invoc_data.get_path ().as_string ());
-
- bool found = resolver->get_macro_scope ().lookup (seg, &resolved_node);
- if (!found)
- {
- rust_error_at (invoc.get_locus (), "unknown macro: [%s]",
- seg.get ().c_str ());
- return;
- }
+ auto fragment = AST::ASTFragment::create_error ();
+ invoc_data.set_expander (this);
// lookup the rules
AST::MacroRulesDefinition *rules_def = nullptr;
- bool ok = mappings->lookup_macro_def (resolved_node, &rules_def);
- rust_assert (ok);
+ bool ok = mappings->lookup_macro_invocation (invoc, &rules_def);
- auto fragment = AST::ASTFragment::create_error ();
- invoc_data.set_expander (this);
+ // If there's no rule associated with the invocation, we can simply return
+ // early. The early name resolver will have already emitted an error.
+ if (!ok)
+ return;
if (rules_def->is_builtin ())
fragment
diff --git a/gcc/rust/expand/rust-macro-expand.h b/gcc/rust/expand/rust-macro-expand.h
index bef140236b3..187d79f9a28 100644
--- a/gcc/rust/expand/rust-macro-expand.h
+++ b/gcc/rust/expand/rust-macro-expand.h
@@ -25,6 +25,7 @@
#include "rust-ast.h"
#include "rust-macro.h"
#include "rust-hir-map.h"
+#include "rust-early-name-resolver.h"
#include "rust-name-resolver.h"
#include "rust-macro-invoc-lexer.h"
@@ -323,10 +324,13 @@ struct MacroExpander
AST::ASTFragment old_fragment = std::move (expanded_fragment);
auto accumulator = std::vector<AST::SingleASTNode> ();
expanded_fragment = AST::ASTFragment::create_error ();
+ auto early_name_resolver = Resolver::EarlyNameResolver ();
for (auto &node : old_fragment.get_nodes ())
{
expansion_depth++;
+
+ node.accept_vis (early_name_resolver);
node.accept_vis (vis);
// we'll decide the next move according to the outcome of the macro
// expansion
diff --git a/gcc/rust/resolve/rust-early-name-resolver.cc b/gcc/rust/resolve/rust-early-name-resolver.cc
new file mode 100644
index 00000000000..6b1f1e9c52f
--- /dev/null
+++ b/gcc/rust/resolve/rust-early-name-resolver.cc
@@ -0,0 +1,1087 @@
+// Copyright (C) 2020-2022 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "rust-early-name-resolver.h"
+#include "rust-ast-full.h"
+#include "rust-name-resolver.h"
+
+namespace Rust {
+namespace Resolver {
+
+EarlyNameResolver::EarlyNameResolver ()
+ : resolver (*Resolver::get ()), mappings (*Analysis::Mappings::get ())
+{}
+
+void
+EarlyNameResolver::go (AST::Crate &crate)
+{
+ // FIXME: Is that valid? Why is the regular name resolution doing
+ // mappings->get_next_node_id()?
+ resolver.get_macro_scope ().push (crate.get_node_id ());
+
+ for (auto &item : crate.items)
+ item->accept_vis (*this);
+
+ // FIXME: Should we pop the macro scope?
+}
+
+void
+EarlyNameResolver::resolve_generic_args (AST::GenericArgs &generic_args)
+{
+ for (auto &arg : generic_args.get_generic_args ())
+ arg.accept_vis (*this);
+
+ for (auto &arg : generic_args.get_binding_args ())
+ arg.get_type ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::resolve_qualified_path_type (AST::QualifiedPathType &path)
+{
+ path.get_type ()->accept_vis (*this);
+
+ if (path.has_as_clause ())
+ path.get_as_type_path ().accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::Token &tok)
+{}
+
+void
+EarlyNameResolver::visit (AST::DelimTokenTree &delim_tok_tree)
+{}
+
+void
+EarlyNameResolver::visit (AST::AttrInputMetaItemContainer &input)
+{}
+
+void
+EarlyNameResolver::visit (AST::IdentifierExpr &ident_expr)
+{}
+
+void
+EarlyNameResolver::visit (AST::Lifetime &lifetime)
+{}
+
+void
+EarlyNameResolver::visit (AST::LifetimeParam &lifetime_param)
+{}
+
+void
+EarlyNameResolver::visit (AST::ConstGenericParam &const_param)
+{}
+
+// FIXME: ARTHUR: Do we need to perform macro resolution for paths as well?
+// std::arch::asm!()?
+void
+EarlyNameResolver::visit (AST::PathInExpression &path)
+{
+ for (auto &segment : path.get_segments ())
+ if (segment.has_generic_args ())
+ resolve_generic_args (segment.get_generic_args ());
+}
+
+void
+EarlyNameResolver::visit (AST::TypePathSegment &segment)
+{}
+
+void
+EarlyNameResolver::visit (AST::TypePathSegmentGeneric &segment)
+{
+ if (segment.has_generic_args ())
+ resolve_generic_args (segment.get_generic_args ());
+}
+
+void
+EarlyNameResolver::visit (AST::TypePathSegmentFunction &segment)
+{
+ for (auto &type : segment.get_type_path_function ().get_params ())
+ type->accept_vis (*this);
+
+ segment.get_type_path_function ().get_return_type ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::TypePath &path)
+{
+ for (auto &seg : path.get_segments ())
+ seg->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::QualifiedPathInExpression &path)
+{
+ resolve_qualified_path_type (path.get_qualified_path_type ());
+
+ for (auto &segment : path.get_segments ())
+ if (segment.has_generic_args ())
+ resolve_generic_args (segment.get_generic_args ());
+}
+
+void
+EarlyNameResolver::visit (AST::QualifiedPathInType &path)
+{
+ resolve_qualified_path_type (path.get_qualified_path_type ());
+
+ for (auto &segment : path.get_segments ())
+ segment->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::LiteralExpr &expr)
+{}
+
+void
+EarlyNameResolver::visit (AST::AttrInputLiteral &attr_input)
+{}
+
+void
+EarlyNameResolver::visit (AST::MetaItemLitExpr &meta_item)
+{}
+
+void
+EarlyNameResolver::visit (AST::MetaItemPathLit &meta_item)
+{}
+
+void
+EarlyNameResolver::visit (AST::BorrowExpr &expr)
+{
+ expr.get_borrowed_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::DereferenceExpr &expr)
+{
+ expr.get_dereferenced_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::ErrorPropagationExpr &expr)
+{
+ expr.get_propagating_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::NegationExpr &expr)
+{
+ expr.get_negated_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::ArithmeticOrLogicalExpr &expr)
+{
+ expr.get_left_expr ()->accept_vis (*this);
+ expr.get_right_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::ComparisonExpr &expr)
+{
+ expr.get_left_expr ()->accept_vis (*this);
+ expr.get_right_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::LazyBooleanExpr &expr)
+{
+ expr.get_left_expr ()->accept_vis (*this);
+ expr.get_right_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::TypeCastExpr &expr)
+{
+ expr.get_casted_expr ()->accept_vis (*this);
+ expr.get_type_to_cast_to ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::AssignmentExpr &expr)
+{
+ expr.get_left_expr ()->accept_vis (*this);
+ expr.get_right_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::CompoundAssignmentExpr &expr)
+{
+ expr.get_left_expr ()->accept_vis (*this);
+ expr.get_right_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::GroupedExpr &expr)
+{
+ expr.get_expr_in_parens ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::ArrayElemsValues &elems)
+{
+ for (auto &expr : elems.get_values ())
+ expr->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::ArrayElemsCopied &elems)
+{
+ elems.get_elem_to_copy ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::ArrayExpr &expr)
+{
+ expr.get_array_elems ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::ArrayIndexExpr &expr)
+{
+ expr.get_array_expr ()->accept_vis (*this);
+ expr.get_index_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::TupleExpr &expr)
+{
+ for (auto &elem : expr.get_tuple_elems ())
+ elem->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::TupleIndexExpr &expr)
+{
+ expr.get_tuple_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::StructExprStruct &expr)
+{}
+
+void
+EarlyNameResolver::visit (AST::StructExprFieldIdentifier &field)
+{}
+
+void
+EarlyNameResolver::visit (AST::StructExprFieldIdentifierValue &field)
+{
+ field.get_value ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::StructExprFieldIndexValue &field)
+{
+ field.get_value ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::StructExprStructFields &expr)
+{
+ for (auto &field : expr.get_fields ())
+ field->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::StructExprStructBase &expr)
+{}
+
+void
+EarlyNameResolver::visit (AST::CallExpr &expr)
+{
+ expr.get_function_expr ()->accept_vis (*this);
+ for (auto ¶m : expr.get_params ())
+ param->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::MethodCallExpr &expr)
+{
+ expr.get_receiver_expr ()->accept_vis (*this);
+ for (auto ¶m : expr.get_params ())
+ param->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::FieldAccessExpr &expr)
+{
+ expr.get_receiver_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::ClosureExprInner &expr)
+{
+ expr.get_definition_expr ()->accept_vis (*this);
+
+ for (auto ¶m : expr.get_params ())
+ param.get_type ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::BlockExpr &expr)
+{
+ for (auto &stmt : expr.get_statements ())
+ stmt->accept_vis (*this);
+
+ if (expr.has_tail_expr ())
+ expr.get_tail_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::ClosureExprInnerTyped &expr)
+{
+ expr.get_definition_block ()->accept_vis (*this);
+
+ for (auto ¶m : expr.get_params ())
+ param.get_type ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::ContinueExpr &expr)
+{}
+
+void
+EarlyNameResolver::visit (AST::BreakExpr &expr)
+{
+ if (expr.has_break_expr ())
+ expr.get_break_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::RangeFromToExpr &expr)
+{
+ expr.get_from_expr ()->accept_vis (*this);
+ expr.get_to_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::RangeFromExpr &expr)
+{
+ expr.get_from_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::RangeToExpr &expr)
+{
+ expr.get_to_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::RangeFullExpr &expr)
+{}
+
+void
+EarlyNameResolver::visit (AST::RangeFromToInclExpr &expr)
+{
+ expr.get_from_expr ()->accept_vis (*this);
+ expr.get_to_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::RangeToInclExpr &expr)
+{
+ expr.get_to_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::ReturnExpr &expr)
+{
+ if (expr.has_returned_expr ())
+ expr.get_returned_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::UnsafeBlockExpr &expr)
+{
+ expr.get_block_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::LoopExpr &expr)
+{
+ expr.get_loop_block ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::WhileLoopExpr &expr)
+{
+ expr.get_predicate_expr ()->accept_vis (*this);
+ expr.get_loop_block ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::WhileLetLoopExpr &expr)
+{
+ expr.get_scrutinee_expr ()->accept_vis (*this);
+ expr.get_loop_block ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::ForLoopExpr &expr)
+{
+ expr.get_iterator_expr ()->accept_vis (*this);
+ expr.get_loop_block ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::IfExpr &expr)
+{
+ expr.get_condition_expr ()->accept_vis (*this);
+ expr.get_if_block ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::IfExprConseqElse &expr)
+{
+ expr.get_condition_expr ()->accept_vis (*this);
+ expr.get_if_block ()->accept_vis (*this);
+ expr.get_else_block ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::IfExprConseqIf &expr)
+{
+ expr.get_condition_expr ()->accept_vis (*this);
+ expr.get_if_block ()->accept_vis (*this);
+ expr.get_conseq_if_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::IfExprConseqIfLet &expr)
+{
+ expr.get_condition_expr ()->accept_vis (*this);
+ expr.get_if_block ()->accept_vis (*this);
+ expr.get_conseq_if_let_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::IfLetExpr &expr)
+{
+ expr.get_value_expr ()->accept_vis (*this);
+ expr.get_if_block ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::IfLetExprConseqElse &expr)
+{
+ expr.get_value_expr ()->accept_vis (*this);
+ expr.get_if_block ()->accept_vis (*this);
+ expr.get_else_block ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::IfLetExprConseqIf &expr)
+{
+ expr.get_value_expr ()->accept_vis (*this);
+ expr.get_if_block ()->accept_vis (*this);
+ expr.get_conseq_if_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::IfLetExprConseqIfLet &expr)
+{
+ expr.get_value_expr ()->accept_vis (*this);
+ expr.get_if_block ()->accept_vis (*this);
+ expr.get_conseq_if_let_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::MatchExpr &expr)
+{
+ expr.get_scrutinee_expr ()->accept_vis (*this);
+ for (auto &match_arm : expr.get_match_cases ())
+ {
+ if (match_arm.get_arm ().has_match_arm_guard ())
+ match_arm.get_arm ().get_guard_expr ()->accept_vis (*this);
+
+ for (auto &pattern : match_arm.get_arm ().get_patterns ())
+ pattern->accept_vis (*this);
+
+ match_arm.get_expr ()->accept_vis (*this);
+ }
+}
+
+void
+EarlyNameResolver::visit (AST::AwaitExpr &expr)
+{
+ expr.get_awaited_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::AsyncBlockExpr &expr)
+{
+ expr.get_block_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::TypeParam ¶m)
+{
+ for (auto &bound : param.get_type_param_bounds ())
+ bound->accept_vis (*this);
+
+ if (param.has_type ())
+ param.get_type ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::LifetimeWhereClauseItem &item)
+{}
+
+void
+EarlyNameResolver::visit (AST::TypeBoundWhereClauseItem &item)
+{
+ for (auto &bound : item.get_type_param_bounds ())
+ bound->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::Method &method)
+{
+ if (method.has_generics ())
+ for (auto &generic : method.get_generic_params ())
+ generic->accept_vis (*this);
+
+ if (method.get_self_param ().has_type ())
+ method.get_self_param ().get_type ()->accept_vis (*this);
+
+ for (auto ¶m : method.get_function_params ())
+ param.get_type ()->accept_vis (*this);
+
+ if (method.has_return_type ())
+ method.get_return_type ()->accept_vis (*this);
+
+ method.get_definition ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::Module &module)
+{
+ for (auto &item : module.get_items ())
+ item->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::ExternCrate &crate)
+{}
+
+void
+EarlyNameResolver::visit (AST::UseTreeGlob &use_tree)
+{}
+
+void
+EarlyNameResolver::visit (AST::UseTreeList &use_tree)
+{}
+
+void
+EarlyNameResolver::visit (AST::UseTreeRebind &use_tree)
+{}
+
+void
+EarlyNameResolver::visit (AST::UseDeclaration &use_decl)
+{}
+
+void
+EarlyNameResolver::visit (AST::Function &function)
+{
+ if (function.has_generics ())
+ for (auto &generic : function.get_generic_params ())
+ generic->accept_vis (*this);
+
+ for (auto ¶m : function.get_function_params ())
+ param.get_type ()->accept_vis (*this);
+
+ if (function.has_return_type ())
+ function.get_return_type ()->accept_vis (*this);
+
+ function.get_definition ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::TypeAlias &type_alias)
+{
+ type_alias.get_type_aliased ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::StructStruct &struct_item)
+{
+ for (auto &field : struct_item.get_fields ())
+ field.get_field_type ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::TupleStruct &tuple_struct)
+{
+ for (auto &field : tuple_struct.get_fields ())
+ field.get_field_type ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::EnumItem &item)
+{}
+
+void
+EarlyNameResolver::visit (AST::EnumItemTuple &item)
+{}
+
+void
+EarlyNameResolver::visit (AST::EnumItemStruct &item)
+{}
+
+void
+EarlyNameResolver::visit (AST::EnumItemDiscriminant &item)
+{}
+
+void
+EarlyNameResolver::visit (AST::Enum &enum_item)
+{}
+
+void
+EarlyNameResolver::visit (AST::Union &union_item)
+{}
+
+void
+EarlyNameResolver::visit (AST::ConstantItem &const_item)
+{
+ const_item.get_type ()->accept_vis (*this);
+ const_item.get_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::StaticItem &static_item)
+{
+ static_item.get_type ()->accept_vis (*this);
+ static_item.get_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::TraitItemFunc &item)
+{
+ auto &decl = item.get_trait_function_decl ();
+
+ if (decl.has_return_type ())
+ decl.get_return_type ()->accept_vis (*this);
+
+ for (auto &generic : decl.get_generic_params ())
+ generic->accept_vis (*this);
+
+ for (auto ¶m : decl.get_function_params ())
+ param.get_type ()->accept_vis (*this);
+
+ if (item.has_definition ())
+ item.get_definition ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::TraitItemMethod &item)
+{
+ // FIXME: Can we factor this with the above function?
+ auto &decl = item.get_trait_method_decl ();
+
+ if (decl.has_return_type ())
+ decl.get_return_type ()->accept_vis (*this);
+
+ for (auto &generic : decl.get_generic_params ())
+ generic->accept_vis (*this);
+
+ for (auto ¶m : decl.get_function_params ())
+ param.get_type ()->accept_vis (*this);
+
+ if (item.has_definition ())
+ item.get_definition ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::TraitItemConst &item)
+{
+ item.get_type ()->accept_vis (*this);
+
+ if (item.has_expr ())
+ item.get_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::TraitItemType &item)
+{}
+
+void
+EarlyNameResolver::visit (AST::Trait &trait)
+{
+ for (auto &item : trait.get_trait_items ())
+ item->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::InherentImpl &impl)
+{
+ impl.get_type ()->accept_vis (*this);
+
+ for (auto &generic : impl.get_generic_params ())
+ generic->accept_vis (*this);
+
+ for (auto &item : impl.get_impl_items ())
+ item->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::TraitImpl &impl)
+{
+ impl.get_type ()->accept_vis (*this);
+
+ for (auto &generic : impl.get_generic_params ())
+ generic->accept_vis (*this);
+
+ for (auto &item : impl.get_impl_items ())
+ item->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::ExternalStaticItem &item)
+{
+ item.get_type ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::ExternalFunctionItem &item)
+{
+ for (auto &generic : item.get_generic_params ())
+ generic->accept_vis (*this);
+
+ for (auto ¶m : item.get_function_params ())
+ param.get_type ()->accept_vis (*this);
+
+ if (item.has_return_type ())
+ item.get_return_type ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::ExternBlock &block)
+{
+ for (auto &item : block.get_extern_items ())
+ item->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::MacroMatchFragment &match)
+{}
+
+void
+EarlyNameResolver::visit (AST::MacroMatchRepetition &match)
+{}
+
+void
+EarlyNameResolver::visit (AST::MacroMatcher &matcher)
+{}
+
+void
+EarlyNameResolver::visit (AST::MacroRulesDefinition &rules_def)
+{
+ auto path = CanonicalPath::new_seg (rules_def.get_node_id (),
+ rules_def.get_rule_name ());
+ resolver.get_macro_scope ().insert (path, rules_def.get_node_id (),
+ rules_def.get_locus ());
+ mappings.insert_macro_def (&rules_def);
+ rust_debug_loc (rules_def.get_locus (), "inserting macro def: [%s]",
+ path.get ().c_str ());
+}
+
+void
+EarlyNameResolver::visit (AST::MacroInvocation &invoc)
+{
+ auto &invoc_data = invoc.get_invoc_data ();
+ auto has_semicolon = invoc.has_semicolon ();
+
+ // ??
+ // switch on type of macro:
+ // - '!' syntax macro (inner switch)
+ // - procedural macro - "A token-based function-like macro"
+ // - 'macro_rules' (by example/pattern-match) macro? or not? "an
+ // AST-based function-like macro"
+ // - else is unreachable
+ // - attribute syntax macro (inner switch)
+ // - procedural macro attribute syntax - "A token-based attribute
+ // macro"
+ // - legacy macro attribute syntax? - "an AST-based attribute macro"
+ // - non-macro attribute: mark known
+ // - else is unreachable
+ // - derive macro (inner switch)
+ // - derive or legacy derive - "token-based" vs "AST-based"
+ // - else is unreachable
+ // - derive container macro - unreachable
+
+ // lookup the rules for this macro
+ NodeId resolved_node = UNKNOWN_NODEID;
+ NodeId source_node = UNKNOWN_NODEID;
+ if (has_semicolon)
+ source_node = invoc.get_macro_node_id ();
+ else
+ source_node = invoc.get_pattern_node_id ();
+ auto seg
+ = CanonicalPath::new_seg (source_node, invoc_data.get_path ().as_string ());
+
+ bool found = resolver.get_macro_scope ().lookup (seg, &resolved_node);
+ if (!found)
+ {
+ rust_error_at (invoc.get_locus (), "unknown macro: [%s]",
+ seg.get ().c_str ());
+ return;
+ }
+
+ // lookup the rules
+ AST::MacroRulesDefinition *rules_def = nullptr;
+ bool ok = mappings.lookup_macro_def (resolved_node, &rules_def);
+ rust_assert (ok);
+
+ mappings.insert_macro_invocation (invoc, rules_def);
+}
+
+// FIXME: ARTHUR: Do we need to resolve these as well here?
+
+void
+EarlyNameResolver::visit (AST::MetaItemPath &meta_item)
+{}
+
+void
+EarlyNameResolver::visit (AST::MetaItemSeq &meta_item)
+{}
+
+void
+EarlyNameResolver::visit (AST::MetaWord &meta_item)
+{}
+
+void
+EarlyNameResolver::visit (AST::MetaNameValueStr &meta_item)
+{}
+
+void
+EarlyNameResolver::visit (AST::MetaListPaths &meta_item)
+{}
+
+void
+EarlyNameResolver::visit (AST::MetaListNameValueStr &meta_item)
+{}
+
+void
+EarlyNameResolver::visit (AST::LiteralPattern &pattern)
+{}
+
+void
+EarlyNameResolver::visit (AST::IdentifierPattern &pattern)
+{
+ if (pattern.has_pattern_to_bind ())
+ pattern.get_pattern_to_bind ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::WildcardPattern &pattern)
+{}
+
+void
+EarlyNameResolver::visit (AST::RangePatternBoundLiteral &bound)
+{}
+
+void
+EarlyNameResolver::visit (AST::RangePatternBoundPath &bound)
+{}
+
+void
+EarlyNameResolver::visit (AST::RangePatternBoundQualPath &bound)
+{}
+
+void
+EarlyNameResolver::visit (AST::RangePattern &pattern)
+{
+ pattern.get_lower_bound ()->accept_vis (*this);
+ pattern.get_upper_bound ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::ReferencePattern &pattern)
+{
+ pattern.get_referenced_pattern ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::StructPatternFieldTuplePat &field)
+{
+ field.get_index_pattern ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::StructPatternFieldIdentPat &field)
+{
+ field.get_ident_pattern ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::StructPatternFieldIdent &field)
+{}
+
+void
+EarlyNameResolver::visit (AST::StructPattern &pattern)
+{}
+
+void
+EarlyNameResolver::visit (AST::TupleStructItemsNoRange &tuple_items)
+{
+ for (auto &pattern : tuple_items.get_patterns ())
+ pattern->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::TupleStructItemsRange &tuple_items)
+{
+ for (auto &pattern : tuple_items.get_lower_patterns ())
+ pattern->accept_vis (*this);
+ for (auto &pattern : tuple_items.get_upper_patterns ())
+ pattern->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::TupleStructPattern &pattern)
+{
+ pattern.get_items ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::TuplePatternItemsMultiple &tuple_items)
+{
+ for (auto &pattern : tuple_items.get_patterns ())
+ pattern->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::TuplePatternItemsRanged &tuple_items)
+{
+ for (auto &pattern : tuple_items.get_lower_patterns ())
+ pattern->accept_vis (*this);
+ for (auto &pattern : tuple_items.get_upper_patterns ())
+ pattern->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::TuplePattern &pattern)
+{
+ pattern.get_items ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::GroupedPattern &pattern)
+{
+ pattern.get_pattern_in_parens ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::SlicePattern &pattern)
+{
+ for (auto &item : pattern.get_items ())
+ item->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::EmptyStmt &stmt)
+{}
+
+void
+EarlyNameResolver::visit (AST::LetStmt &stmt)
+{
+ if (stmt.has_type ())
+ stmt.get_type ()->accept_vis (*this);
+
+ if (stmt.has_init_expr ())
+ stmt.get_init_expr ()->accept_vis (*this);
+
+ stmt.get_pattern ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::ExprStmtWithoutBlock &stmt)
+{
+ stmt.get_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::ExprStmtWithBlock &stmt)
+{
+ stmt.get_expr ()->accept_vis (*this);
+}
+
+void
+EarlyNameResolver::visit (AST::TraitBound &bound)
+{}
+
+void
+EarlyNameResolver::visit (AST::ImplTraitType &type)
+{}
+
+void
+EarlyNameResolver::visit (AST::TraitObjectType &type)
+{}
+
+void
+EarlyNameResolver::visit (AST::ParenthesisedType &type)
+{}
+
+void
+EarlyNameResolver::visit (AST::ImplTraitTypeOneBound &type)
+{}
+
+void
+EarlyNameResolver::visit (AST::TraitObjectTypeOneBound &type)
+{}
+
+void
+EarlyNameResolver::visit (AST::TupleType &type)
+{}
+
+void
+EarlyNameResolver::visit (AST::NeverType &type)
+{}
+
+void
+EarlyNameResolver::visit (AST::RawPointerType &type)
+{}
+
+void
+EarlyNameResolver::visit (AST::ReferenceType &type)
+{}
+
+void
+EarlyNameResolver::visit (AST::ArrayType &type)
+{}
+
+void
+EarlyNameResolver::visit (AST::SliceType &type)
+{}
+
+void
+EarlyNameResolver::visit (AST::InferredType &type)
+{}
+
+void
+EarlyNameResolver::visit (AST::BareFunctionType &type)
+{
+ for (auto ¶m : type.get_function_params ())
+ param.get_type ()->accept_vis (*this);
+
+ if (type.has_return_type ())
+ type.get_return_type ()->accept_vis (*this);
+}
+
+} // namespace Resolver
+} // namespace Rust
diff --git a/gcc/rust/resolve/rust-early-name-resolver.h b/gcc/rust/resolve/rust-early-name-resolver.h
new file mode 100644
index 00000000000..c53ab9f3d6a
--- /dev/null
+++ b/gcc/rust/resolve/rust-early-name-resolver.h
@@ -0,0 +1,210 @@
+// Copyright (C) 2020-2022 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#ifndef RUST_EARLY_NAME_RESOLVER_H
+#define RUST_EARLY_NAME_RESOLVER_H
+
+#include "rust-name-resolver.h"
+#include "rust-system.h"
+#include "rust-ast.h"
+#include "rust-ast-visitor.h"
+
+namespace Rust {
+namespace Resolver {
+
+class EarlyNameResolver : public AST::ASTVisitor
+{
+public:
+ EarlyNameResolver ();
+
+ void go (AST::Crate &crate);
+
+private:
+ Resolver &resolver;
+ Analysis::Mappings &mappings;
+
+ /**
+ * Early name-resolve generic args, which can be macro invocations
+ */
+ void resolve_generic_args (AST::GenericArgs &generic_args);
+
+ /**
+ * Early name-resolve a qualified path type, which can contain macro
+ * invocations
+ */
+ void resolve_qualified_path_type (AST::QualifiedPathType &path);
+
+ virtual void visit (AST::Token &tok);
+ virtual void visit (AST::DelimTokenTree &delim_tok_tree);
+ virtual void visit (AST::AttrInputMetaItemContainer &input);
+ virtual void visit (AST::IdentifierExpr &ident_expr);
+ virtual void visit (AST::Lifetime &lifetime);
+ virtual void visit (AST::LifetimeParam &lifetime_param);
+ virtual void visit (AST::ConstGenericParam &const_param);
+ virtual void visit (AST::PathInExpression &path);
+ virtual void visit (AST::TypePathSegment &segment);
+ virtual void visit (AST::TypePathSegmentGeneric &segment);
+ virtual void visit (AST::TypePathSegmentFunction &segment);
+ virtual void visit (AST::TypePath &path);
+ virtual void visit (AST::QualifiedPathInExpression &path);
+ virtual void visit (AST::QualifiedPathInType &path);
+ virtual void visit (AST::LiteralExpr &expr);
+ virtual void visit (AST::AttrInputLiteral &attr_input);
+ virtual void visit (AST::MetaItemLitExpr &meta_item);
+ virtual void visit (AST::MetaItemPathLit &meta_item);
+ virtual void visit (AST::BorrowExpr &expr);
+ virtual void visit (AST::DereferenceExpr &expr);
+ virtual void visit (AST::ErrorPropagationExpr &expr);
+ virtual void visit (AST::NegationExpr &expr);
+ virtual void visit (AST::ArithmeticOrLogicalExpr &expr);
+ virtual void visit (AST::ComparisonExpr &expr);
+ virtual void visit (AST::LazyBooleanExpr &expr);
+ virtual void visit (AST::TypeCastExpr &expr);
+ virtual void visit (AST::AssignmentExpr &expr);
+ virtual void visit (AST::CompoundAssignmentExpr &expr);
+ virtual void visit (AST::GroupedExpr &expr);
+ virtual void visit (AST::ArrayElemsValues &elems);
+ virtual void visit (AST::ArrayElemsCopied &elems);
+ virtual void visit (AST::ArrayExpr &expr);
+ virtual void visit (AST::ArrayIndexExpr &expr);
+ virtual void visit (AST::TupleExpr &expr);
+ virtual void visit (AST::TupleIndexExpr &expr);
+ virtual void visit (AST::StructExprStruct &expr);
+ virtual void visit (AST::StructExprFieldIdentifier &field);
+ virtual void visit (AST::StructExprFieldIdentifierValue &field);
+ virtual void visit (AST::StructExprFieldIndexValue &field);
+ virtual void visit (AST::StructExprStructFields &expr);
+ virtual void visit (AST::StructExprStructBase &expr);
+ virtual void visit (AST::CallExpr &expr);
+ virtual void visit (AST::MethodCallExpr &expr);
+ virtual void visit (AST::FieldAccessExpr &expr);
+ virtual void visit (AST::ClosureExprInner &expr);
+ virtual void visit (AST::BlockExpr &expr);
+ virtual void visit (AST::ClosureExprInnerTyped &expr);
+ virtual void visit (AST::ContinueExpr &expr);
+ virtual void visit (AST::BreakExpr &expr);
+ virtual void visit (AST::RangeFromToExpr &expr);
+ virtual void visit (AST::RangeFromExpr &expr);
+ virtual void visit (AST::RangeToExpr &expr);
+ virtual void visit (AST::RangeFullExpr &expr);
+ virtual void visit (AST::RangeFromToInclExpr &expr);
+ virtual void visit (AST::RangeToInclExpr &expr);
+ virtual void visit (AST::ReturnExpr &expr);
+ virtual void visit (AST::UnsafeBlockExpr &expr);
+ virtual void visit (AST::LoopExpr &expr);
+ virtual void visit (AST::WhileLoopExpr &expr);
+ virtual void visit (AST::WhileLetLoopExpr &expr);
+ virtual void visit (AST::ForLoopExpr &expr);
+ virtual void visit (AST::IfExpr &expr);
+ virtual void visit (AST::IfExprConseqElse &expr);
+ virtual void visit (AST::IfExprConseqIf &expr);
+ virtual void visit (AST::IfExprConseqIfLet &expr);
+ virtual void visit (AST::IfLetExpr &expr);
+ virtual void visit (AST::IfLetExprConseqElse &expr);
+ virtual void visit (AST::IfLetExprConseqIf &expr);
+ virtual void visit (AST::IfLetExprConseqIfLet &expr);
+ virtual void visit (AST::MatchExpr &expr);
+ virtual void visit (AST::AwaitExpr &expr);
+ virtual void visit (AST::AsyncBlockExpr &expr);
+ virtual void visit (AST::TypeParam ¶m);
+ virtual void visit (AST::LifetimeWhereClauseItem &item);
+ virtual void visit (AST::TypeBoundWhereClauseItem &item);
+ virtual void visit (AST::Method &method);
+ virtual void visit (AST::Module &module);
+ virtual void visit (AST::ExternCrate &crate);
+ virtual void visit (AST::UseTreeGlob &use_tree);
+ virtual void visit (AST::UseTreeList &use_tree);
+ virtual void visit (AST::UseTreeRebind &use_tree);
+ virtual void visit (AST::UseDeclaration &use_decl);
+ virtual void visit (AST::Function &function);
+ virtual void visit (AST::TypeAlias &type_alias);
+ virtual void visit (AST::StructStruct &struct_item);
+ virtual void visit (AST::TupleStruct &tuple_struct);
+ virtual void visit (AST::EnumItem &item);
+ virtual void visit (AST::EnumItemTuple &item);
+ virtual void visit (AST::EnumItemStruct &item);
+ virtual void visit (AST::EnumItemDiscriminant &item);
+ virtual void visit (AST::Enum &enum_item);
+ virtual void visit (AST::Union &union_item);
+ virtual void visit (AST::ConstantItem &const_item);
+ virtual void visit (AST::StaticItem &static_item);
+ virtual void visit (AST::TraitItemFunc &item);
+ virtual void visit (AST::TraitItemMethod &item);
+ virtual void visit (AST::TraitItemConst &item);
+ virtual void visit (AST::TraitItemType &item);
+ virtual void visit (AST::Trait &trait);
+ virtual void visit (AST::InherentImpl &impl);
+ virtual void visit (AST::TraitImpl &impl);
+ virtual void visit (AST::ExternalStaticItem &item);
+ virtual void visit (AST::ExternalFunctionItem &item);
+ virtual void visit (AST::ExternBlock &block);
+ virtual void visit (AST::MacroMatchFragment &match);
+ virtual void visit (AST::MacroMatchRepetition &match);
+ virtual void visit (AST::MacroMatcher &matcher);
+ virtual void visit (AST::MacroRulesDefinition &rules_def);
+ virtual void visit (AST::MacroInvocation ¯o_invoc);
+ virtual void visit (AST::MetaItemPath &meta_item);
+ virtual void visit (AST::MetaItemSeq &meta_item);
+ virtual void visit (AST::MetaWord &meta_item);
+ virtual void visit (AST::MetaNameValueStr &meta_item);
+ virtual void visit (AST::MetaListPaths &meta_item);
+ virtual void visit (AST::MetaListNameValueStr &meta_item);
+ virtual void visit (AST::LiteralPattern &pattern);
+ virtual void visit (AST::IdentifierPattern &pattern);
+ virtual void visit (AST::WildcardPattern &pattern);
+ virtual void visit (AST::RangePatternBoundLiteral &bound);
+ virtual void visit (AST::RangePatternBoundPath &bound);
+ virtual void visit (AST::RangePatternBoundQualPath &bound);
+ virtual void visit (AST::RangePattern &pattern);
+ virtual void visit (AST::ReferencePattern &pattern);
+ virtual void visit (AST::StructPatternFieldTuplePat &field);
+ virtual void visit (AST::StructPatternFieldIdentPat &field);
+ virtual void visit (AST::StructPatternFieldIdent &field);
+ virtual void visit (AST::StructPattern &pattern);
+ virtual void visit (AST::TupleStructItemsNoRange &tuple_items);
+ virtual void visit (AST::TupleStructItemsRange &tuple_items);
+ virtual void visit (AST::TupleStructPattern &pattern);
+ virtual void visit (AST::TuplePatternItemsMultiple &tuple_items);
+ virtual void visit (AST::TuplePatternItemsRanged &tuple_items);
+ virtual void visit (AST::TuplePattern &pattern);
+ virtual void visit (AST::GroupedPattern &pattern);
+ virtual void visit (AST::SlicePattern &pattern);
+ virtual void visit (AST::EmptyStmt &stmt);
+ virtual void visit (AST::LetStmt &stmt);
+ virtual void visit (AST::ExprStmtWithoutBlock &stmt);
+ virtual void visit (AST::ExprStmtWithBlock &stmt);
+ virtual void visit (AST::TraitBound &bound);
+ virtual void visit (AST::ImplTraitType &type);
+ virtual void visit (AST::TraitObjectType &type);
+ virtual void visit (AST::ParenthesisedType &type);
+ virtual void visit (AST::ImplTraitTypeOneBound &type);
+ virtual void visit (AST::TraitObjectTypeOneBound &type);
+ virtual void visit (AST::TupleType &type);
+ virtual void visit (AST::NeverType &type);
+ virtual void visit (AST::RawPointerType &type);
+ virtual void visit (AST::ReferenceType &type);
+ virtual void visit (AST::ArrayType &type);
+ virtual void visit (AST::SliceType &type);
+ virtual void visit (AST::InferredType &type);
+ virtual void visit (AST::BareFunctionType &type);
+};
+
+} // namespace Resolver
+} // namespace Rust
+
+#endif // RUST_EARLY_NAME_RESOLVER_H
diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index 4ee7175b48b..6f51bd2e5a1 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -38,6 +38,7 @@
#include "rust-imports.h"
#include "rust-extern-crate.h"
#include "rust-attributes.h"
+#include "rust-early-name-resolver.h"
#include "diagnostic.h"
#include "input.h"
@@ -805,6 +806,9 @@ Session::injection (AST::Crate &crate)
void
Session::expansion (AST::Crate &crate)
{
+ /* We need to name resolve macros and imports here */
+ Resolver::EarlyNameResolver ().go (crate);
+
rust_debug ("started expansion");
/* rustc has a modification to windows PATH temporarily here, which may end
--
2.39.1
next prev parent reply other threads:[~2023-02-21 12:03 UTC|newest]
Thread overview: 107+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-21 12:00 Rust front-end update arthur.cohen
2023-02-21 12:00 ` [committed 001/103] gccrs: Fix missing dead code analysis ICE on local enum definition arthur.cohen
2023-02-21 12:00 ` [committed 002/103] gccrs: visibility: Rename get_public_vis_type -> get_vis_type arthur.cohen
2023-02-21 12:00 ` [committed 003/103] gccrs: dump: Emit visibility when dumping items arthur.cohen
2023-02-21 12:53 ` Update copyright years. (was: [committed 003/103] gccrs: dump: Emit visibility when dumping items) Thomas Schwinge
2023-02-21 12:00 ` [committed 004/103] gccrs: Add catch for recusive type queries arthur.cohen
2023-02-21 12:00 ` [committed 005/103] gccrs: testing: try loop in const function arthur.cohen
2023-02-21 12:00 ` [committed 006/103] gccrs: ast: dump assignment and compound assignment expr arthur.cohen
2023-02-21 12:00 ` [committed 007/103] gccrs: ast: dump If expressions arthur.cohen
2023-02-21 12:00 ` [committed 008/103] gccrs: builtins: Move implementation into source file arthur.cohen
2023-02-21 12:00 ` [committed 009/103] gccrs: Track DefId on ADT variants arthur.cohen
2023-02-21 12:01 ` [committed 010/103] gccrs: Ensure uniqueness on Path probe's arthur.cohen
2023-02-21 12:01 ` [committed 011/103] gccrs: Support looking up super traits for trait items arthur.cohen
2023-02-21 12:01 ` [committed 012/103] gccrs: ast: dump: add emit_generic_params helper arthur.cohen
2023-02-21 12:01 ` [committed 013/103] gccrs: ast: dump: add format_{tuple,struct}_field helpers arthur.cohen
2023-02-21 12:01 ` [committed 014/103] gccrs: ast: dump structs, enums and unions arthur.cohen
2023-02-21 12:01 ` [committed 015/103] gccrs: intrinsics: Add data prefetching intrinsics arthur.cohen
2023-02-21 12:01 ` [committed 016/103] gccrs: fix ICE on missing closing paren arthur.cohen
2023-02-21 12:01 ` [committed 017/103] gccrs: mappings: Add MacroInvocation -> MacroRulesDef mappings arthur.cohen
2023-02-21 12:01 ` [committed 018/103] gccrs: rust-ast-resolve-item: Add note about resolving glob uses arthur.cohen
2023-02-21 12:01 ` [committed 019/103] gccrs: ast: Add accept_vis() method to `GenericArg` arthur.cohen
2023-02-21 12:01 ` arthur.cohen [this message]
2023-02-21 12:01 ` [committed 021/103] gccrs: Support type resolution on super traits on dyn objects arthur.cohen
2023-02-21 12:01 ` [committed 022/103] gccrs: Add mappings for fn_once lang item arthur.cohen
2023-02-21 12:01 ` [committed 023/103] gccrs: Add ABI mappings for rust-call to map to ABI::RUST arthur.cohen
2023-02-21 12:01 ` [committed 024/103] gccrs: Method resolution must support multiple candidates arthur.cohen
2023-02-21 12:01 ` [committed 025/103] gccrs: ast: dump: fix extra newline in block without tail arthur.cohen
2023-02-21 12:01 ` [committed 026/103] gccrs: ast: dump: minor fixups to IfExpr formatting arthur.cohen
2023-02-21 12:01 ` [committed 027/103] gccrs: ast: dump: ComparisonExpr and LazyBooleanExpr arthur.cohen
2023-02-21 12:01 ` [committed 028/103] gccrs: ast: dump: ArrayExpr arthur.cohen
2023-02-21 12:01 ` [committed 029/103] gccrs: ast: dump: various simple Exprs arthur.cohen
2023-02-21 12:01 ` [committed 030/103] gccrs: ast: dump: RangeExprs arthur.cohen
2023-02-21 12:01 ` [committed 031/103] gccrs: Refactor TraitResolver to not require a visitor arthur.cohen
2023-02-21 12:01 ` [committed 032/103] gccrs: ast: dump TypeAlias arthur.cohen
2023-02-21 12:01 ` [committed 033/103] gccrs: Support outer attribute handling on trait items just like normal items arthur.cohen
2023-02-21 12:01 ` [committed 034/103] gccrs: dump: Emit visibility when dumping items arthur.cohen
2023-02-23 1:01 ` Gerald Pfeifer
2023-02-23 10:53 ` Arthur Cohen
2023-02-21 12:01 ` [committed 035/103] gccrs: dump: Dump items within modules arthur.cohen
2023-02-21 12:01 ` [committed 036/103] gccrs: dump: Fix module dumping arthur.cohen
2023-02-21 12:01 ` [committed 037/103] gccrs: ast: Module: unloaded module and inner attributes arthur.cohen
2023-02-21 12:01 ` [committed 038/103] gccrs: dump: Dump macro rules definition arthur.cohen
2023-02-21 12:01 ` [committed 039/103] gccrs: Add check for recursive trait cycles arthur.cohen
2023-02-21 12:01 ` [committed 040/103] gccrs: ast: Refactor ASTFragment -> Fragment class arthur.cohen
2023-02-21 12:01 ` [committed 041/103] gccrs: rust: Replace uses of ASTFragment -> Fragment arthur.cohen
2023-02-21 12:01 ` [committed 042/103] gccrs: ast: Improve Fragment API arthur.cohen
2023-02-21 12:01 ` [committed 043/103] gccrs: Add missing fn_once_output langitem arthur.cohen
2023-02-21 12:01 ` [committed 044/103] gccrs: Refactor expression hir lowering into cc file arthur.cohen
2023-02-21 12:01 ` [committed 045/103] gccrs: Formatting cleanup in HIR lowering pattern arthur.cohen
2023-02-21 12:01 ` [committed 046/103] gccrs: Add name resolution for closures arthur.cohen
2023-02-21 12:01 ` [committed 047/103] gccrs: Refactor method call type checking arthur.cohen
2023-02-21 12:01 ` [committed 048/103] gccrs: Add closures to lints and error checking arthur.cohen
2023-02-21 12:01 ` [committed 049/103] gccrs: Initial Type resolution for closures arthur.cohen
2023-02-21 12:01 ` [committed 050/103] gccrs: Closure support at CallExpr arthur.cohen
2023-02-21 12:01 ` [committed 051/103] gccrs: Add missing name resolution to Function type-path segments arthur.cohen
2023-02-21 12:01 ` [committed 052/103] gccrs: Add missing hir lowering to function " arthur.cohen
2023-02-21 12:01 ` [committed 053/103] gccrs: Add missing type resolution for function type segments arthur.cohen
2023-02-21 12:01 ` [committed 054/103] gccrs: Support Closure calls as generic trait bounds arthur.cohen
2023-02-21 12:01 ` [committed 055/103] gccrs: Implement the inline visitor arthur.cohen
2023-02-21 12:01 ` [committed 056/103] gccrs: rust: Allow gccrs to build on x86_64-apple-darwin with clang/libc++ arthur.cohen
2023-02-21 12:01 ` [committed 057/103] gccrs: builtins: Rename all bang macro handlers arthur.cohen
2023-02-21 12:01 ` [committed 058/103] gccrs: intrinsics: Add `sorry_handler` intrinsic handler arthur.cohen
2023-02-21 12:01 ` [committed 059/103] gccrs: constexpr: Add `rust_sorry_at` in places relying on init values arthur.cohen
2023-02-21 12:01 ` [committed 060/103] gccrs: intrinsics: Add early implementation for atomic_store_{seqcst, relaxed, release} arthur.cohen
2023-02-21 12:01 ` [committed 061/103] gccrs: intrinsics: Add unchecked operation intrinsics arthur.cohen
2023-02-21 12:01 ` [committed 062/103] gccrs: intrinsics: Use lambdas for wrapping_<op> intrinsics arthur.cohen
2023-02-21 12:01 ` [committed 063/103] gccrs: intrinsics: Cleanup error handling around atomic_store_* arthur.cohen
2023-02-21 12:01 ` [committed 064/103] gccrs: intrinsics: Implement atomic_load intrinsics arthur.cohen
2023-02-21 12:01 ` [committed 065/103] gccrs: ast: visitor pattern -> overload syntax compatibility layer arthur.cohen
2023-02-21 12:01 ` [committed 066/103] gccrs: ast: transform helper methods to visits and add methods to simplify repeated patterns arthur.cohen
2023-02-21 12:01 ` [committed 067/103] gccrs: ast: refer correctly to arguments in docs-strings arthur.cohen
2023-02-21 12:01 ` [committed 068/103] gccrs: ast: Dump unit struct arthur.cohen
2023-02-21 12:01 ` [committed 069/103] gccrs: add lang item "phantom_data" arthur.cohen
2023-02-21 12:02 ` [committed 070/103] gccrs: add Location to AST::Visibility arthur.cohen
2023-02-21 12:02 ` [committed 071/103] gccrs: typecheck: Fix overzealous `delete` call arthur.cohen
2023-02-21 12:02 ` [committed 072/103] gccrs: ast: add visit overload for references arthur.cohen
2023-02-21 12:02 ` [committed 073/103] gccrs: ast: Dump where clause and recursively needed nodes arthur.cohen
2023-02-21 12:02 ` [committed 074/103] gccrs: ast: Dump slice type arthur.cohen
2023-02-21 12:02 ` [committed 075/103] gccrs: ast: Dump array type arthur.cohen
2023-02-21 12:02 ` [committed 076/103] gccrs: ast: Dump raw pointer type arthur.cohen
2023-02-21 12:02 ` [committed 077/103] gccrs: ast: Dump never type arthur.cohen
2023-02-21 12:02 ` [committed 078/103] gccrs: ast: Dump tuple type arthur.cohen
2023-02-21 12:02 ` [committed 079/103] gccrs: ast: Dump inferred type arthur.cohen
2023-02-21 12:02 ` [committed 080/103] gccrs: ast: Dump bare function type arthur.cohen
2023-02-21 12:02 ` [committed 081/103] gccrs: ast: Dump impl trait type one bound arthur.cohen
2023-02-21 12:02 ` [committed 082/103] gccrs: ast: Dump impl trait type arthur.cohen
2023-02-21 12:02 ` [committed 083/103] gccrs: ast: Dump trait object type arthur.cohen
2023-02-21 12:02 ` [committed 084/103] gccrs: ast: Dump parenthesised type arthur.cohen
2023-02-21 12:02 ` [committed 085/103] gccrs: ast: Dump trait object type one bound arthur.cohen
2023-02-21 12:02 ` [committed 086/103] gccrs: ast: Dump type param type arthur.cohen
2023-02-21 12:02 ` [committed 087/103] gccrs: ast: Dump generic parameters arthur.cohen
2023-02-21 12:02 ` [committed 088/103] gccrs: ast: Remove unused include in rust-ast-dump.cc arthur.cohen
2023-02-21 12:02 ` [committed 089/103] gccrs: ast: Dump remove /* stmp */ comment to not clutter the dump arthur.cohen
2023-02-21 12:02 ` [committed 090/103] gccrs: ast: Dump no comma after self in fn params if it is the last one arthur.cohen
2023-02-21 12:02 ` [committed 091/103] gccrs: Remove default location. Add visibility location to create_* functions arthur.cohen
2023-02-21 12:02 ` [committed 092/103] gccrs: Improve lexer dump arthur.cohen
2023-02-21 12:02 ` [committed 093/103] gccrs: Get rid of make builtin macro arthur.cohen
2023-02-21 12:02 ` [committed 094/103] gccrs: Refactor name resolver to take a Rib::ItemType arthur.cohen
2023-02-21 12:02 ` [committed 095/103] gccrs: Add closure binding's tracking to name resolution arthur.cohen
2023-02-21 12:02 ` [committed 096/103] gccrs: Add capture tracking to the type info for closures arthur.cohen
2023-02-21 12:02 ` [committed 097/103] gccrs: Add initial support for argument capture of closures arthur.cohen
2023-02-21 12:02 ` [committed 098/103] gccrs: Fix undefined behaviour issues on macos arthur.cohen
2023-02-21 12:02 ` [committed 099/103] gccrs: Skip this debug test case which is failing on the latest mac-os devtools and its only for debug info arthur.cohen
2023-02-21 12:02 ` [committed 100/103] gccrs: Cleanup unused parameters to fix the bootstrap build arthur.cohen
2023-02-21 12:02 ` [committed 101/103] gccrs: Repair 'gcc/rust/lang.opt' comment arthur.cohen
2023-02-21 12:02 ` [committed 102/103] gccrs: const evaluator: Remove get_nth_callarg arthur.cohen
2023-02-21 12:02 ` [committed 103/103] gccrs: add math intrinsics arthur.cohen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230221120230.596966-21-arthur.cohen@embecosm.com \
--to=arthur.cohen@embecosm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=gcc-rust@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).