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

Fix stale symbols connected to lazy vals in macros #21559

Merged
merged 1 commit into from
Sep 23, 2024

Conversation

jchyb
Copy link
Contributor

@jchyb jchyb commented Sep 6, 2024

While bringing forward the denotation to a new run, we now check if the symbol was moved from its owner to a companion object. If so, we return NoDenotation, as that denotation seems to be a leftover from pre-MoveStatics phases in a previous run.

Fixes #21271

In the issue reproduction, we had a symbol created in the LazyVals phase, which was then later moved to a companion class in MoveStatics in the first run. In the second run, this caused the leftover denotation for pre-MoveStatics phases of the first run to be tried to brought forward (since the phaseID became valid at that point), failing to do so (because that symbol should no longer exist as a member of the initial companion object at that point).

It looks like before #19786, since this denotation was valid at a later phase, it would be visited somewhere before the MegaPhase with LazyVals and replaced with a NoDenotation (pretty much by accident), which back then ended up being cached for the latter phases as well.

So in the fix here we check for that specific MoveStatics -caused case and, if found, update the symbol with a NoDenotation (just like before, but this time, on purpose).

@jchyb jchyb marked this pull request as ready for review September 18, 2024 12:35
@jchyb jchyb changed the title Try to fix stale symbols connected to lazy vals in macros Fix stale symbols connected to lazy vals in macros Sep 18, 2024
@jchyb jchyb requested a review from odersky September 19, 2024 08:53
Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

Nice catch and quite a simple fix.

@@ -755,6 +755,11 @@ object Denotations {
}
if (!symbol.exists) return updateValidity()
if (!coveredInterval.containsPhaseId(ctx.phaseId)) return NoDenotation
// Moved to companion class, likely at a later phase (in MoveStatics)
this match {
case symd: SymDenotation if (movedToCompanionClass(symd)) => return NoDenotation
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
case symd: SymDenotation if (movedToCompanionClass(symd)) => return NoDenotation
case symd: SymDenotation if movedToCompanionClass(symd) => return NoDenotation

@dwijnand
Copy link
Member

Seems so unsatisfactory adhoc, but a fix is a fix, nicely done!

…tion

While bringing forward the denotation to a new run, check if the
symbol was moved from its owner to a companion object. If so, return
NoDenotation, as that denotation seems to be a leftover from
pre-MoveStatics phases in a previous run.
@jchyb jchyb enabled auto-merge September 23, 2024 09:03
@jchyb jchyb merged commit b8c5ecb into scala:main Sep 23, 2024
25 checks passed
@jchyb jchyb deleted the fix-stale-i21271 branch September 23, 2024 10:17
@WojciechMazur WojciechMazur added this to the 3.6.0 milestone Oct 8, 2024
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.

Compiler crashes when combining lazy val and macros
4 participants