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

Avoid forcing whole package when using -experimental #20409

Merged
merged 1 commit into from
May 16, 2024

Conversation

smarter
Copy link
Member

@smarter smarter commented May 14, 2024

In #19807, the behavior of -experimental was changed to mark all top-level definitions as experimental. To do so, the implementation traverses the whole package and checks every symbol to see if it should be transformed or not. The problem was that the first check we do is sym.isExperimental which ends up forcing the symbol.

Besides being a performance issue, this could also lead to a crash if the current package is the empty package, because we could end up forcing the magic module-info.class that Java modules place there. For some reason, this appear to only happen when building with sbt, hence the additional scripted test.

This PR fixes this issue by reordering the checks (and adding a preliminary isDefinedInCurrentRun check for good measure). We should also investigate whether we can avoid creating a symbol for module-info.class, but this PR is intentionally minimal so we can backport it to 3.5.0-RC2 without risks.

In scala#19807, the behavior of `-experimental`
was changed to mark all top-level definitions as experimental. To do so, the
implementation traverses the whole package and checks every symbol to see if it
should be transformed or not. The problem was that the first check we do is
`sym.isExperimental` which ends up forcing the symbol.

Besides being a performance issue, this could also lead to a crash if the
current package is the empty package, because we could end up forcing the magic
`module-info.class` that Java modules place there. For some reason, this appear
to only happen when building with sbt, hence the additional scripted test.

This PR fixes this issue by reordering the checks (and adding a preliminary
`isDefinedInCurrentRun` check for good measure). We should also investigate
whether we can avoid creating a symbol for `module-info.class`, but this PR is
intentionally minimal so we can backport it to 3.5.0-RC2 without risks.
@smarter smarter added this to the 3.5.0-RC2 milestone May 14, 2024
@smarter smarter added the backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. label May 14, 2024
@smarter smarter requested a review from odersky May 14, 2024 22:20
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.

The change looks good, but we could go further. Why traverse all symbols of the package? We could just traverse the symbols of the trees we are given.

@odersky odersky assigned smarter and unassigned odersky May 16, 2024
@bjornregnell
Copy link
Contributor

Don't know if it is related (as hinted by @som-snytt ) but here is a crash in REPL when loading class module-info that also for some reason only happens in sbt:
sbt/sbt#7560

@smarter
Copy link
Member Author

smarter commented May 16, 2024

@bjornregnell Could you open a separate issue for this? We should address the root cause here but I'd like to get this in first.

@smarter smarter merged commit 73bb2aa into scala:main May 16, 2024
19 checks passed
@smarter smarter deleted the fix-exp branch May 16, 2024 16:13
smarter added a commit to dotty-staging/dotty that referenced this pull request May 16, 2024
This backports scala#20409 which fixes a
regression introduced in 3.5.0-RC1 causing compiler crashes when enabling
`-experimental`.
@bjornregnell
Copy link
Contributor

bjornregnell commented May 16, 2024

Other issue now cross-posted here: #20421

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants