You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add @scala.annotation.internal.preview annotation and -preview flag. (#22317)
This adds `@scala.annotation.internal.preview` to mark Scala 3 stdlib
API as preview-only and accessors for easy marking Scala features in the
compiler as preview (similarly to experimental features)
Access to preview features/API is granted to user using the `-preview`
compiler flag - it enables all access to preview features/API without
possibility to enable only their subset.
`@preview` annotated definitions follows the same rules as
`@experimental` with exception of being non viral - we're not
automatically adding `@preview` annotation to when refering to preview
definitions, but still require preview scope (by `-preview` flag), we
still check if class overloads, overrides or externs a definition marked
as `@preview`.
Other difference is that `@preview` is `private[scala]` to prevent users
from defining their own preview definitions as it was happening with
`@experimental`
Copy file name to clipboardExpand all lines: compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
+1
Original file line number
Diff line number
Diff line change
@@ -116,6 +116,7 @@ trait CommonScalaSettings:
116
116
valunchecked:Setting[Boolean] =BooleanSetting(RootSetting, "unchecked", "Enable additional warnings where generated code depends on assumptions.", initialValue =true, aliases =List("--unchecked"))
117
117
vallanguage:Setting[List[ChoiceWithHelp[String]]] =MultiChoiceHelpSetting(RootSetting, "language", "feature", "Enable one or more language features.", choices =ScalaSettingsProperties.supportedLanguageFeatures, legacyChoices =ScalaSettingsProperties.legacyLanguageFeatures, default =Nil, aliases =List("--language"))
118
118
valexperimental:Setting[Boolean] =BooleanSetting(RootSetting, "experimental", "Annotate all top-level definitions with @experimental. This enables the use of experimental features anywhere in the project.")
119
+
valpreview:Setting[Boolean] =BooleanSetting(RootSetting, "preview", "Enable the use of preview features anywhere in the project.")
119
120
120
121
/* Coverage settings */
121
122
valcoverageOutputDir=PathSetting(RootSetting, "coverage-out", "Destination for coverage classfiles and instrumentation data.", "", aliases =List("--coverage-out"))
New Scala language features or standard library APIs are initially introduced as experimental, but once they become fully implemented and accepted by the [SIP](https://docs.scala-lang.org/sips/) these can become a preview features.
8
+
Preview language features and APIs are guaranteed to be standardized in some next Scala minor release, but allow the compiler team to introduce small, possibly binary incompatible, changes based on the community feedback.
9
+
These can be used by early adopters who can accept the possibility of binary compatibility breakage. For instance, preview features could be used in some internal tool or application. On the other hand, preview features are discouraged in publicly available libraries.
10
+
11
+
Users can enable access to preview features and definitions by compiling with the `-preview` flag. The flag would enable all preview features and definitions. There is no scheme for enabling only a subset of preview features.
12
+
13
+
The biggest difference of preview features compared to experimental features is their non-viral behavior.
14
+
A definition compiled in preview mode (using the `-preview` flag) is not marked as a preview definition itself.
15
+
This behavior allows to use preview features transitively in other compilation units without explicitly enabled preview mode, as long as it does not directly reference APIs or features marked as preview.
16
+
17
+
The [`@preview`](https://scala-lang.org/api/3.x/scala/annotation/internal/preview.html) annotation is used to mark Scala 3 standard library APIs currently available under preview mode.
18
+
The rules for `@preview` are similar to [`@experimental`](https://scala-lang.org/api/3.x/scala/annotation/experimental.html) when it comes to accessing, subtyping, overriding or overloading definitions marked with this annotation - all of these can only be performed in compilation units that enable preview mode.
0 commit comments