-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
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.
There was a problem hiding this 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.
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: |
@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. |
This backports scala#20409 which fixes a regression introduced in 3.5.0-RC1 causing compiler crashes when enabling `-experimental`.
Other issue now cross-posted here: #20421 |
This backports #20409 which fixes a regression introduced in 3.5.0-RC1 causing compiler crashes when enabling `-experimental`.
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 issym.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 formodule-info.class
, but this PR is intentionally minimal so we can backport it to 3.5.0-RC2 without risks.