Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup macro invoc #2981

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions gcc/rust/ast/rust-macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -672,18 +672,13 @@ class MacroInvocation : public TypeNoBounds,
outer_attrs = std::move (new_attrs);
}

NodeId get_node_id () const override final
{
return ExprWithoutBlock::get_node_id ();
}
NodeId get_node_id () const override final { return node_id; }

AST::Kind get_ast_kind () const override
{
return AST::Kind::MACRO_INVOCATION;
}

NodeId get_macro_node_id () const { return node_id; }

MacroInvocData &get_invoc_data () { return invoc_data; }

bool has_semicolon () const { return is_semi_coloned; }
Expand Down Expand Up @@ -719,8 +714,10 @@ class MacroInvocation : public TypeNoBounds,
MacroInvocData invoc_data, std::vector<Attribute> outer_attrs,
location_t locus, bool is_semi_coloned,
std::vector<std::unique_ptr<MacroInvocation>> &&pending_eager_invocs)
: TraitItem (locus), outer_attrs (std::move (outer_attrs)), locus (locus),
node_id (Analysis::Mappings::get ().get_next_node_id ()),
: TraitItem (locus),
ExternalItem (Analysis::Mappings::get ().get_next_node_id ()),
outer_attrs (std::move (outer_attrs)), locus (locus),
node_id (ExternalItem::get_node_id ()),
invoc_data (std::move (invoc_data)), is_semi_coloned (is_semi_coloned),
kind (kind), builtin_kind (builtin_kind),
pending_eager_invocs (std::move (pending_eager_invocs))
Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/resolve/rust-early-name-resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ EarlyNameResolver::visit (AST::MacroInvocation &invoc)
NodeId resolved_node = UNKNOWN_NODEID;
NodeId source_node = UNKNOWN_NODEID;
if (has_semicolon)
source_node = invoc.get_macro_node_id ();
source_node = invoc.get_node_id ();
else
source_node = invoc.get_node_id ();
Comment on lines 468 to 471
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see for example here we're no longer doing anything different if the macro has a semicolon or not, so we can remove the if block

Copy link
Contributor Author

@badumbatish badumbatish May 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow no idea how i missed this, thanks for the review, i'll resolve it along with new thoughts on this

auto seg
Expand Down
12 changes: 6 additions & 6 deletions gcc/rust/util/rust-hir-map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -913,17 +913,17 @@ void
Mappings::insert_macro_invocation (AST::MacroInvocation &invoc,
AST::MacroRulesDefinition *def)
{
auto it = macroInvocations.find (invoc.get_macro_node_id ());
auto it = macroInvocations.find (invoc.get_node_id ());
rust_assert (it == macroInvocations.end ());

macroInvocations[invoc.get_macro_node_id ()] = def;
macroInvocations[invoc.get_node_id ()] = def;
}

bool
Mappings::lookup_macro_invocation (AST::MacroInvocation &invoc,
AST::MacroRulesDefinition **def)
{
auto it = macroInvocations.find (invoc.get_macro_node_id ());
auto it = macroInvocations.find (invoc.get_node_id ());
if (it == macroInvocations.end ())
return false;

Expand Down Expand Up @@ -1084,16 +1084,16 @@ void
Mappings::insert_bang_proc_macro_invocation (AST::MacroInvocation &invoc,
BangProcMacro def)
{
auto it = procmacroBangInvocations.find (invoc.get_macro_node_id ());
auto it = procmacroBangInvocations.find (invoc.get_node_id ());
rust_assert (it == procmacroBangInvocations.end ());

procmacroBangInvocations[invoc.get_macro_node_id ()] = def;
procmacroBangInvocations[invoc.get_node_id ()] = def;
}

tl::optional<BangProcMacro &>
Mappings::lookup_bang_proc_macro_invocation (AST::MacroInvocation &invoc)
{
auto it = procmacroBangInvocations.find (invoc.get_macro_node_id ());
auto it = procmacroBangInvocations.find (invoc.get_node_id ());
if (it == procmacroBangInvocations.end ())
return tl::nullopt;

Expand Down
Loading