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 symbol crashes in some path depended types in macro contexts #18077

Merged
merged 2 commits into from
Jun 30, 2023

Conversation

jchyb
Copy link
Contributor

@jchyb jchyb commented Jun 27, 2023

Closes #17152
Closes #17294

In general the issues stemmed from the fact that after suspending runs due to the found macros, when typing Ident of the called method, symbols from the previous run are found there. Some of them either are able to have their validity updated while returning the denotation (which those path dependent types are unable to do, since their owners now have updated decls, which do not include the stale symbol), or do not need denotation as part of a code path they rely on.

The fixes simply check if the to-be-used symbol has a valid runID, and if not then recomputes it.

The first commit fixes the minimizations from above GitHub issues. Both minimizations by design have to result in cyclic macro errors (which they now do), so they were placed in neg-macros tests.

By some experimentation, I ended up with another, slightly different stale symbol crash, with the stale symbol trying to create a denotation in different place (in withPrefix), requiring an additional fix there, included in the second commit. This minimization, unlike the previous ones, does compile successfully, without cyclic macro errors, which shows the issue was not exclusive to those.

@jchyb jchyb requested a review from nicolasstucki June 27, 2023 13:09
jchyb added 2 commits June 27, 2023 15:54
The reason for the stale symbols was the fact that they were derived
from the previous (suspended) run (by calling a method from that run),
and path depended types seem to use an optimized path utilizing initial
designator, unlike the other kinds of types, which seem to either not
need calculating denotation or the denotation there is able to update
it's own validity.

Since that is impossible to do for those path dependent types, if they
are invalid in the run recaluclate the Symbol, otherwise use
`currentSymbol` as before.
To fix we recalculate the symbol from directly from NamedType when from
invalid run, instead of updating it's validity (which is impossible, as
its owners do not include it in their decls).
Copy link
Contributor

@nicolasstucki nicolasstucki left a comment

Choose a reason for hiding this comment

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

This looks ok to me. But it needs a second opinion from someone more familiar with the intricacies of how we compute symbols/denotations.

@nicolasstucki nicolasstucki requested a review from odersky June 28, 2023 09:25
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.

Looks good to me also.

@odersky odersky merged commit d43d6bd into scala:main Jun 30, 2023
@odersky odersky deleted the fix-i17294 branch June 30, 2023 09:38
@ftucky
Copy link

ftucky commented Jun 30, 2023

Hello, I commented in #17294 that I encountered a similar problem but was unable to minimize it.
I confirm that the "stale symbol" crash has disappeared in 3.3.2-RC1-bin-20230627-588a0b1-NIGHTLY.

The code does not involve macros, but involves compiler suspension/resume.

Compiled code behaves as expected.

In a nutshell:

  • This was a real-life bug ( not only the aftermath of a cyclic macro )
  • Bug seems to be fixed.

@soronpo
Copy link
Contributor

soronpo commented Jun 30, 2023

OMG, thank you so much for solving this! It has plagued my library in so many ways.

@Kordyjan Kordyjan added this to the 3.4.0 milestone Aug 1, 2023
Kordyjan added a commit that referenced this pull request Dec 8, 2023
…ro contexts" to LTS (#19051)

Backports #18077 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
@Kordyjan Kordyjan modified the milestones: 3.4.0, 3.3.2 Dec 14, 2023
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.

Stale symbol crash Crash (regression): dotty.tools.dotc.core.Denotations$StaleSymbol: stale symbol
7 participants