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

expand: Refactor InvocationCollector visitor for better code reuse #92573

Merged
merged 4 commits into from
Jan 9, 2022

Conversation

petrochenkov
Copy link
Contributor

@petrochenkov petrochenkov commented Jan 5, 2022

The refactoring part of #92473.

Invocation collector visitor logic now lives in two main functions:

  • fn flat_map_node, corresponding to "one to many" expansions
  • fn visit_node, corresponding to "one to one" expansions

All specific mut visitor methods now use one of these functions.

The new InvocationCollectorNode trait implemented for all AstFragment nodes provides the necessary small pieces of functionality required to implement the (flat_map,visit)_node functions.
r? @Aaron1011

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jan 5, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 5, 2022
}
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, bool) {
unreachable!()
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Initially I tried the fn take_mac_call(self) -> Result<...> approach, but it ended up being less convenient than two separate functions due to consuming self too early (we don't want self to be consumed if there's no macro call).

.field("tag", &self.tag)
.finish()
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deriving this impl puts the Debug requirement on tag types, unfortunately.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 5, 2022
ast: Always keep a `NodeId` in `ast::Crate`

This makes it more uniform with other expanded nodes.
It makes generic code in rust-lang#92573 simpler in particular.

This is another follow-up to rust-lang#91313.
r? `@Aaron1011`
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 6, 2022
@petrochenkov
Copy link
Contributor Author

Updated.
I also removed fn filter_map_node, it turned out identical to fn flat_map_node after the generalization.

@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 6, 2022
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 7, 2022
@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 7, 2022
@Aaron1011
Copy link
Member

r=me with the commits squashed

@petrochenkov
Copy link
Contributor Author

Other commits are separate small refactorings that are weakly related to the main commit "Refactor InvocationCollector visitor", they also touch some code other than invocation collector, so I think it's reasonable to keep them separate.
@bors r=Aaron1011

@bors
Copy link
Contributor

bors commented Jan 9, 2022

📌 Commit 4523466 has been approved by Aaron1011

@bors bors removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 9, 2022
@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jan 9, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 9, 2022
…askrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#92055 (Add release notes for 1.58)
 - rust-lang#92490 (Move crate drop-down to search results page)
 - rust-lang#92510 (Don't resolve blocks in foreign functions)
 - rust-lang#92573 (expand: Refactor InvocationCollector visitor for better code reuse)
 - rust-lang#92608 (rustdoc: Introduce a resolver cache for sharing data between early doc link resolution and later passes)
 - rust-lang#92657 (Implemented const casts of raw pointers)
 - rust-lang#92671 (Make `Atomic*::from_mut` return `&mut Atomic*`)
 - rust-lang#92673 (Remove useless collapse toggle on "all items" page)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit b681dc2 into rust-lang:master Jan 9, 2022
@rustbot rustbot added this to the 1.60.0 milestone Jan 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants