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

feat: improve support for ignored proc macros #15923

Merged
merged 3 commits into from
Feb 12, 2024

Conversation

tamasfe
Copy link
Contributor

@tamasfe tamasfe commented Nov 17, 2023

Supersedes #15117, I was having some conflicts after a rebase and since I didn't remember much of it I started clean instead.

The end result is pretty much the same as the linked PR, but instead of proc macro lookups, I marked the expanders that explicitly cannot be expanded and we shouldn't even attempt to do so.

Unresolved questions

  • I introduced a DISABLED_ID next to DUMMY_ID in hir-expand's ProcMacroExpander, that is effectively exactly the same thing with slightly different semantics, dummy macros are not (yet) expanded probably due to errors, while not expanding disabled macros is part of the usual flow. I'm not sure if it's the right way to handle this, I also thought of just adding a flag instead of replacing the macro ID, so that the disabled macro can still be expanded for any reason if needed.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 17, 2023
crates/hir-def/src/nameres/collector.rs Outdated Show resolved Hide resolved
@@ -848,6 +857,10 @@ pub(crate) fn load_proc_macro(
) -> Result<tt::Subtree, ProcMacroExpansionError> {
Ok(subtree.clone())
}

fn should_expand(&self) -> bool {
Copy link
Member

Choose a reason for hiding this comment

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

We can just combine IdentityExpander and EmptyExpander now and have the expand function return an error since they are properly ignored now, so they should enver be expanded anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so they should never be expanded anyways

Is this certain? I focused on attribute macros and a specific use-case (ignored macros) in this PR, so I don't know where else these expanders might be used. If empty or identity expansions aren't needed anywhere, I can merge them into a NoopExpander or something that will always return an error (or alternaitively identity/empty tree upon agreement).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps we could keep the IdentityExpander for unresolved macros and other unhappy paths only, and then keep regular macros as-is but also augment ignored ones so that should_expand returns false, this way we can still have the ability to expand even ignored macros on demand (e.g. via a command).

Copy link
Member

Choose a reason for hiding this comment

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

Is this certain?

Well disabled means disabled, if we still call this somewhere that's more of a bug imo

@@ -315,7 +315,13 @@ impl GlobalState {
crate_name
.as_deref()
.and_then(|crate_name| {
dummy_replacements.get(crate_name).map(|v| &**v)
ignored_proc_macros.iter().find_map(|c| {
if eq_ignore_underscore(&*c.0, crate_name) {
Copy link
Member

Choose a reason for hiding this comment

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

👍 we should've done this from the start tbh

@Veykril Veykril 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 Nov 21, 2023
@Veykril
Copy link
Member

Veykril commented Jan 10, 2024

Went ahead and rebased this on current master, I might look into bringing this over the finish line later.

@bors
Copy link
Contributor

bors commented Jan 19, 2024

☔ The latest upstream changes (presumably #16404) made this pull request unmergeable. Please resolve the merge conflicts.

@Veykril
Copy link
Member

Veykril commented Feb 12, 2024

Alright I came back to this, fixed some stuff up and should be ready to merge now.
Thanks for the work on this!
@bors r+

@bors
Copy link
Contributor

bors commented Feb 12, 2024

📌 Commit e2a985e has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Feb 12, 2024

⌛ Testing commit e2a985e with merge 47b4dd7...

@bors
Copy link
Contributor

bors commented Feb 12, 2024

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing 47b4dd7 to master...

@bors bors merged commit 47b4dd7 into rust-lang:master Feb 12, 2024
11 checks passed
@lnicola lnicola changed the title feat: ignored and disabled macro expansion feat: improve support for ignored proc macros Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants