Skip to content

Conversation

jchyb
Copy link
Contributor

@jchyb jchyb commented Sep 11, 2025

Fixes #23852
Closes #19426

Around a year ago a new DependencyContext value was added to the zinc api: DependencyByMacroExpansion.
It causes the recorded dependency to trigger recompilation if there is any API change in the recorded type, not just if the feudal/method member that was explicitly referenced was changed. So now, for every inline call:
macroCall[T1, T2, ...], in file call.scala, if anything changes in a TN definition, call.scala is recompiled.

Since DependencyByMacroExpansion was added later to the API, referencing it in older versions (e.g. any sbt < 1.10.0), would cause crashes. to avoid that, we use reflection to check if that field exists.

These changes do not seem to affect #23783, likely the way annotations are handled needs to be changed in zinc itself, as the APIInfo phase does successfully record the change in the annotation argument.

Related discussion: sbt/zinc#1316 (a PR adding the functionality to zinc and scala-2 plugin).

@jchyb jchyb requested a review from bishabosha September 15, 2025 09:50
@jchyb
Copy link
Contributor Author

jchyb commented Sep 15, 2025

Hi @bishabosha, would you be able to review this? If not, then I think I can ask @tgodzik, but he's more of an expert on the zinc side than the compiler side I think.

Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

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

A valuable improvement!

private def addMacroDependency(sym: Symbol)(using Context): Unit =
if (allowsDependencyByMacroExpansion) {
if (!ignoreDependency(sym)) {
if (!sym.is(Package)) {
Copy link
Member

Choose a reason for hiding this comment

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

Isn't the package test redundant, because it's already in TypeDependencyTraverser.traverse?

val traverser = new TypeDependencyTraverser {
def addDependency(symbol: Symbol) = addMacroDependency(symbol)
}
trees.foreach(tree => traverser.traverse(tree.tpe))
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this whole function should be elided when the macro dependency tracking is unavailable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Macro usage is not invalidated Test impact of macros on incremental compilation when type parameter changes
3 participants