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 more single ident macro calls upon item collection #14800

Merged
merged 1 commit into from
May 13, 2023

Conversation

lowr
Copy link
Contributor

@lowr lowr commented May 13, 2023

Addresses #14781 (comment)

I believe this (almost) brings the number of unresolved names back to pre-#14781:

r-a version analysis-stats compiler/rustc (rust-lang/rust@69fef92)
pre-#14781 (b069eb7) exprs: 2747778, ??ty: 122236 (4%), ?ty: 107826 (3%), !ty: 728
#14781 (a7944a9) exprs: 2713080, ??ty: 139651 (5%), ?ty: 114444 (4%), !ty: 730
with this fix exprs: 2747871, ??ty: 122237 (4%), ?ty: 108171 (3%), !ty: 676

(I haven't investigated on the increase in some numbers but hopefully not too much of a problem)

This is only a temporary solution. The core problem is that we haven't fully implemented the textual scope of legacy macros. For example, we have been failing to resolve foo in the following snippet, even before #14781 or after this patch. As noted in a FIXME, we need a way to resolve names in textual scope without eager expansion during item collection.

//- /main.rs crate:main deps:lib
lib::mk_foo!();
const A: i32 = foo!();
             //^^^^^^ unresolved-macro-call

//- /lib.rs crate:lib
#[macro_export]
macro_rules! mk_foo {
    () => {
        macro_rules! foo { () => { 42 } }
    }
}

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 13, 2023

// Case 1: try to resolve in legacy scope and expand macro_rules
// FIXME: Eagerly expanding in "Case 1" is insufficient since "Case 2" may also define
Copy link
Member

Choose a reason for hiding this comment

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

Using the term eager might be a bit confusing here as there is a concept of eager vs lazy macros

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've replaced it with "immediately" as used in the comment below.

@Veykril
Copy link
Member

Veykril commented May 13, 2023

I wish we had the resources to run analysis stats on rust-lang/rust on CI tbh though I imagine r-a will take ages on that codebase

@lowr lowr force-pushed the patch/macro-subns-and-prelude branch from a0ad760 to e9ddb62 Compare May 13, 2023 18:12
@lowr
Copy link
Contributor Author

lowr commented May 13, 2023

Yeah, I've run it a few times for this PR and it took more than an hour in total, such a pain :/ (partly because I'm on a relatively old PC though). I wish we had a rust-timer-like bot dedicated to our needs...

@lowr lowr changed the title Eagerly expand more single ident macro calls upon item collection Expand more single ident macro calls upon item collection May 13, 2023
@Veykril
Copy link
Member

Veykril commented May 13, 2023

Oh, a rust-timer-like bot for this would be amazing tbh. Wouldn't hurt to bring that up in t-infra at least I guess
btw, you have bors permissions as well (not sure if you were aware of that when we gave the triage team the perms some months ago so just bringing that up)
@bors r+

@bors
Copy link
Contributor

bors commented May 13, 2023

📌 Commit e9ddb62 has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented May 13, 2023

⌛ Testing commit e9ddb62 with merge daa03b0...

@bors
Copy link
Contributor

bors commented May 13, 2023

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

@bors bors merged commit daa03b0 into rust-lang:master May 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants