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

Support macro annotation expansions in -Wmacros:MODE #8799

Merged
merged 1 commit into from Mar 18, 2020

Conversation

cb372
Copy link
Contributor

@cb372 cb372 commented Mar 12, 2020

From the compiler options documentation:

-Wmacros:before
Only inspect unexpanded user-written code for unused symbols.

I would argue that if we don't warn about unused symbols in trees expanded from def macros, we shouldn't warn about unused symbols in trees expanded from macro annotations either.

@scala-jenkins scala-jenkins added this to the 2.13.3 milestone Mar 12, 2020
}
object checkMacroExpandee extends UnusedPrivates {
override def traverse(t: Tree): Unit =
super.traverse(if (hasMacroExpansionAttachment(t)) macroExpandee(t) else t)
if (!(t.hasSymbol && isExpanded(t.symbol)))
super.traverse(if (hasMacroExpansionAttachment(t)) macroExpandee(t) else t)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the condition is flipped? This is the "yes, lint the expandee".

Moving the test to neg and including a Test_3 with -Wmacro:after to show the error would verify.

Copy link
Contributor

Choose a reason for hiding this comment

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

I only just glanced at the code comment in StdAttachments about "should be a better way".

Copy link
Contributor Author

@cb372 cb372 Mar 13, 2020

Choose a reason for hiding this comment

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

I agree having a "pos" test for -Wmacro:before and a "neg" test for -Wmacro:after is a good idea, but I'm a bit confused by your suggestion. Is the semantics of neg tests that all the files except the last one should compile, and the last one should not compile? So we can write both the pos and the neg parts in the same test?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it would compile A_1, then B_2, then error on C_3, and each round can use different flags. If you think that is too confusing or subtle, pos and neg tests is OK.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the clarification. I added a separate neg test as I think that's slightly clearer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not obvious from my first comment, but for "expandee" I always conflate "tree to be expanded" and "result of expansion". I would be less confused by "pre" and "post" or "original" and "expanded", etc.

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 agree, the naming in this area is mighty confusing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Some followup to my confusion in #10693 (in case I have to research the nomenclature again in future). The other naming that confuses me still is each instance of UnusedPrivates as it relates to -Wmacros settings. Maybe I only have trouble with names I didn't come up with myself. For an improved default behavior for -Wmacros, I could only come up with default.

Specifically, for `-Wmacros:none` or `-Wmacros:before`, we shouldn't
warn about unused symbols in code resulting from expansion of a macro
annotation.
@lrytz lrytz force-pushed the macro-annotations-unused-symbols branch from f167ae6 to 9b505e2 Compare March 18, 2020 09:44
@lrytz
Copy link
Member

lrytz commented Mar 18, 2020

Squashed. @som-snytt feel free to merge if LGTY.

Copy link
Contributor

@som-snytt som-snytt left a comment

Choose a reason for hiding this comment

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

I couldn't get it to lint an existing object X, even if my macro attached the original. Maybe that's just not supported.

@som-snytt som-snytt merged commit 81d6b1e into scala:2.13.x Mar 18, 2020
@dwijnand dwijnand modified the milestones: 2.13.3, 2.13.2 Mar 18, 2020
@SethTisue SethTisue added the release-notes worth highlighting in next release notes label Mar 19, 2020
@cb372 cb372 deleted the macro-annotations-unused-symbols branch March 20, 2020 09:24
@som-snytt
Copy link
Contributor

@som-snytt not sure at all what you're talking about here, but see the linked PR for an example of typer-based linting interacting with -Wmacros: -Wunused:missing-interpolator is run when typing a literal, which may consult the context; but that is before expansion; when typechecked after expansion, the literal is not re-typed, so the check is not re-run in the new context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes worth highlighting in next release notes
Projects
None yet
6 participants