-
Notifications
You must be signed in to change notification settings - Fork 1.1k
chore: use language import instead of -Ycompile-scala2-library
#23082
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
base: main
Are you sure you want to change the base?
Conversation
if ctx.settings.YcompileScala2Library.value then | ||
() |
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.
Since scala.language.2
lives in the patches, we will need to patch the denotations to gain access to it. Otherwise, typer complains because the member is not found.
4fa87d0
to
7de4910
Compare
6aaf63d
to
3aed10f
Compare
@@ -17,6 +17,7 @@ enum SourceVersion: | |||
case `3.7-migration`, `3.7` | |||
case `3.8-migration`, `3.8` | |||
// !!! Keep in sync with scala.runtime.stdlibPatches.language !!! | |||
case `2` |
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.
Wouldn't this one leak into the -source
setting choices that can be specified by users?
I guess that the main goal of this PR is to restrict access to special mode of compilation Scala 2 standard library so that it cannot be used in any other project. Is there a plan to compile any other sources then Scala 2 stdlib? If no, then maybe special marker class added to sources would be enough to to check at compile time (eg. using requiredClass
method) that -Ycompile-scala2-library
is not used in foreign scope.
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.
Wouldn't this one leak into the -source setting choices that can be specified by users?
As it is right now, yes. And I actually use it to make this work until I add the imports manually. But when this is done, it will be forbidden in -source
. We can disallow the option by adding "2"
here:
val illegalSourceVersionNames = List("3.1-migration", "never").map(_.toTermName) |
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.
I guess that the main goal of this PR is to restrict access to special mode of compilation Scala 2 standard library so that it cannot be used in any other project.
Actually, this is not the primary goal of this PR. We will be adding the source files of the scala2 library in the same folder as the scala3 library and we need a way to still behave as scala2 for those specific files. A flag affects all the files while an import can affect on specific compilation units.
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.
Aren't all files of single sbt project part of single compilation unit beside macros? I always thought there is no effective difference between the flag and import, but maybe I've missed something
We will revert commit: 43e45e7 when we merge this PR |
11b9a52
to
43e45e7
Compare
43e45e7
to
a10622a
Compare
I'm renaming the object from |
This PR adds a new language import (
scala.language.2
) to replace the-Ycompile-scala2-library
flag.This language import should only be used in the stdlib (package
scala
). To enforce this, the language import isprivate[scala]
but we still need to enforce it (#23081).For now, I've allowed the
-source 2
option but this will be disallowed once we add the source files of the stdlib in this repository.