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 a REPL bad symbolic reference #19786

Merged
merged 6 commits into from
Feb 26, 2024

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Feb 26, 2024

Fixes #15562

Copy of #19775 with a final tweak commit at the end.

I created a new PR since the original PRs were not on staging.

dwijnand and others added 4 commits February 26, 2024 12:09
 - Be more specific when we go into the special case of not
   updating checkedPeriod
 - Always update lastDenotation.
 - Keep computeDenot small, move work to recomputeDenot
@dwijnand
Copy link
Member

If we always update the lastDenotation then we lose the denotation in the truncated, tab-completion run (we replace an outdated denotation with NoDenotation).

Here's what I'm trying: another ErrorDenotation subclass that holds the outdated denotation, so we can update it when we can.

@odersky
Copy link
Contributor Author

odersky commented Feb 26, 2024

If we always update the lastDenotation then we lose the denotation in the truncated, tab-completion run (we replace an outdated denotation with NoDenotation).

Yes, but I am not sure where it would make a difference. Presumably, we get at the denotation only in the case where we do import suggestions, so it's an error case and we won't get in the same run to the later phase where the denotation matters.

@dwijnand
Copy link
Member

so it's an error case and we won't get in the same run to the later phase where the denotation matters.

Correct. And then in the next run we do get to a later phase, and the denotation is gone, with all the information that we had from classfile parsing.

@odersky
Copy link
Contributor Author

odersky commented Feb 26, 2024

Right. But then I wonder why that was not caught in the test case?

…ario

This brings back an element of the original solution.
@dwijnand
Copy link
Member

Right. But then I wonder why that was not caught in the test case?

That patch failed for me locally.

@odersky
Copy link
Contributor Author

odersky commented Feb 26, 2024

Ah, I only ran testCompilation and that does not include the repl tests. How does it work for you with the latest patch? (I force pushed with a fix not to set lastDenot to NoDenotation).

@dwijnand
Copy link
Member

Yeah it does.

I think that approach has the downside that it disables any caching of these denotations. Perhaps that's fine, but do you want to consider my new subclass approach?

@odersky
Copy link
Contributor Author

odersky commented Feb 26, 2024

I was worried about the caching before since we never cached NoDenotations. But now it only happens in the very specific (and hopefully rare) case where we do have a denotation in a later phase. So I am less concerned about this now.

@dwijnand dwijnand added the backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. label Feb 26, 2024
@dwijnand dwijnand merged commit b701542 into scala:main Feb 26, 2024
17 checks passed
@dwijnand dwijnand deleted the rebase/repl-bad-symbolic-ref branch February 26, 2024 22:25
@Kordyjan Kordyjan added this to the 3.4.2 milestone Mar 28, 2024
jchyb added a commit that referenced this pull request Sep 23, 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.

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).
@WojciechMazur WojciechMazur removed the backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. label Nov 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
4 participants