Skip to content

Commit

Permalink
Disable experimental by default in unstable builds
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Mar 8, 2024
1 parent 2fa92c4 commit 9aa0ce6
Show file tree
Hide file tree
Showing 44 changed files with 83 additions and 49 deletions.
4 changes: 1 addition & 3 deletions compiler/src/dotty/tools/dotc/config/Feature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ object Feature:
em"""Experimental $which may only be used under experimental mode:
| 1. in a definition marked as @experimental, or
| 2. an experimental feature is imported in at the package level, or
| 3. compiling with the -experimental compiler flag, or
| 4. with a nightly or snapshot version of the compiler.$note
| 3. compiling with the -experimental compiler.$note
|""", srcPos)

private def ccException(sym: Symbol)(using Context): Boolean =
Expand All @@ -162,7 +161,6 @@ object Feature:
checkExperimentalFeature("definition", srcPos, s"\n\n$note")

def isExperimentalEnabledBySetting(using Context): Boolean =
(Properties.unstableExperimentalEnabled && !ctx.settings.YnoExperimental.value) ||
ctx.settings.experimental.value ||
experimentalAutoEnableFeatures.exists(enabledBySetting)

Expand Down
6 changes: 0 additions & 6 deletions compiler/src/dotty/tools/dotc/config/Properties.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ trait PropertiesTrait {
*/
val versionString: String = "version " + simpleVersionString

/** Whether the current version of compiler is experimental
*
* Snapshot, nightly releases and non-bootstrapped compiler are experimental.
*/
val unstableExperimentalEnabled: Boolean = versionString.contains("SNAPSHOT") || versionString.contains("NIGHTLY") || versionString.contains("nonbootstrapped")

/** Whether the current version of compiler supports research plugins. */
val researchPluginEnabled: Boolean = versionString.contains("SNAPSHOT") || versionString.contains("NIGHTLY") || versionString.contains("nonbootstrapped")

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ private sealed trait YSettings:
val YretainTrees: Setting[Boolean] = BooleanSetting("-Yretain-trees", "Retain trees for top-level classes, accessible from ClassSymbol#tree")
val YshowTreeIds: Setting[Boolean] = BooleanSetting("-Yshow-tree-ids", "Uniquely tag all tree nodes in debugging output.")
val YfromTastyIgnoreList: Setting[List[String]] = MultiStringSetting("-Yfrom-tasty-ignore-list", "file", "List of `tasty` files in jar files that will not be loaded when using -from-tasty.")
val YnoExperimental: Setting[Boolean] = BooleanSetting("-Yno-experimental", "Disable experimental language features by default in NIGHTLY/SNAPSHOT versions of the compiler.")
val YnoExperimental: Setting[Boolean] = BooleanSetting("-Yno-experimental", "Disable experimental language features by default in NIGHTLY/SNAPSHOT versions of the compiler (deprecated, no-op).")
val YlegacyLazyVals: Setting[Boolean] = BooleanSetting("-Ylegacy-lazy-vals", "Use legacy (pre 3.3.0) implementation of lazy vals.")
val YcompileScala2Library: Setting[Boolean] = BooleanSetting("-Ycompile-scala2-library", "Used when compiling the Scala 2 standard library.")
val YoutputOnlyTasty: Setting[Boolean] = BooleanSetting("-Youtput-only-tasty", "Used to only generate the TASTy file without the classfiles")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class PublicInBinaryTests extends DottyBytecodeTest {
override def initCtx =
val ctx0 = super.initCtx
ctx0.setSetting(ctx0.settings.experimental, true)
ctx0.setSetting(ctx0.settings.YnoExperimental, true)

@Test
def publicInBinaryDef(): Unit = {
Expand Down
5 changes: 1 addition & 4 deletions docs/_docs/reference/other-new-features/experimental-defs.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,7 @@ Experimental definitions can only be referenced in an experimental scope. Experi

</details>

6. Any code compiled using a [_Nightly_](https://search.maven.org/artifact/org.scala-lang/scala3-compiler_3) or _Snapshot_ version of the compiler is considered to be in an experimental scope.
Can use the `-Yno-experimental` compiler flag to disable it and run as a proper release.

7. An experimental language feature is imported in at the package level. All top-level definitions will be marked as `@experimental`.
6. An experimental language feature is imported in at the package level. All top-level definitions will be marked as `@experimental`.

In any other situation, a reference to an experimental definition will cause a compilation error.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,7 @@ Experimental definitions can only be referenced in an experimental scope. Experi

</details>

6. Any code compiled using a [_Nightly_](https://search.maven.org/artifact/org.scala-lang/scala3-compiler_3) or _Snapshot_ version of the compiler is considered to be in an experimental scope.
Can use the `-Yno-experimental` compiler flag to disable it and run as a proper release.

7. An experimental language feature is imported in at the package level. All top-level definitions will be marked as `@experimental`.
6. An experimental language feature is imported in at the package level. All top-level definitions will be marked as `@experimental`.

In any other situation, a reference to an experimental definition will cause a compilation error.

Expand Down
3 changes: 3 additions & 0 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,9 @@ object Build {
SourceLinksIntegrationTest / scalaSource := baseDirectory.value / "test-source-links",
SourceLinksIntegrationTest / test:= ((SourceLinksIntegrationTest / test) dependsOn generateScalaDocumentation.toTask("")).value,
).
settings(
scalacOptions += "-experimental" // workaround use of experimental .info in Scaladoc2AnchorCreator
).
settings(
Compile / resourceGenerators ++= Seq(
generateStaticAssetsTask.taskValue,
Expand Down
8 changes: 4 additions & 4 deletions scala2-library-cc/src/scala/collection/generic/IsSeq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ object IsSeq {
* The helper method [[seqViewIsSeq_]] is added to make the binary compatible.
*/
@annotation.targetName("seqViewIsSeq")
@annotation.publicInBinary
private[IsSeq] def seqViewIsSeq_[CC0[X] <: SeqView[X], A0]: IsSeq[CC0[A0]] { type A = A0; type C = View[A0] } = ???
// @annotation.publicInBinary private[IsSeq] // FIXME: enable when publicInBinary becomes stable
def seqViewIsSeq_[CC0[X] <: SeqView[X], A0]: IsSeq[CC0[A0]] { type A = A0; type C = View[A0] } = ???
implicit inline def seqViewIsSeq[CC0[X] <: SeqView[X], A0]: IsIterable[CC0[A0]] { type A = A0; type C = View[A0] } = seqViewIsSeq_[CC0, A0].asInstanceOf

/** !!! Under cc, views are not Seqs and can't use SeqOps.
* Therefore, [[stringViewIsSeq]] now returns an [[IsIterable]].
* The helper method [[stringViewIsSeq__]] is added to make the binary compatible.
*/
@annotation.targetName("stringViewIsSeq")
@annotation.publicInBinary
private[IsSeq] val stringViewIsSeq_ : IsSeq[StringView] { type A = Char; type C = View[Char] } = ???
// @annotation.publicInBinary private[IsSeq] // FIXME: enable when publicInBinary becomes stable
val stringViewIsSeq_ : IsSeq[StringView] { type A = Char; type C = View[Char] } = ???
inline implicit def stringViewIsSeq: IsIterable[StringView] { type A = Char; type C = View[Char] } = stringViewIsSeq_.asInstanceOf

implicit val stringIsSeq: IsSeq[String] { type A = Char; type C = String } =
Expand Down
2 changes: 1 addition & 1 deletion scaladoc-testcases/src/tests/hugetype.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ trait E:
@deprecated
protected implicit def same[A](a: A): A

trait XD extends E:
@experimental trait XD extends E:
/**
* Some important information :o
*
Expand Down
4 changes: 2 additions & 2 deletions scaladoc-testcases/src/tests/methodsAndConstructors.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package tests.methodsAndConstructors

import scala.language.experimental.clauseInterleaving

class A
class B extends A
class C
Expand Down Expand Up @@ -60,8 +62,6 @@ class Methods:
def withImplicitParam2(v: String)(implicit ab: Double, a: Int, b: String): String
= ???

import scala.language.experimental.clauseInterleaving

def clauseInterleaving[T](x: T)[U](y: U)(using (T, U)): (T, U)
= ???

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class SnippetCompiler(
object SnippetDriver extends Driver:
val currentCtx =
val rootCtx = initCtx.fresh.addMode(Mode.ReadPositions).addMode(Mode.Interactive)
rootCtx.setSetting(rootCtx.settings.experimental, true)
rootCtx.setSetting(rootCtx.settings.YretainTrees, true)
rootCtx.setSetting(rootCtx.settings.YcookComments, true)
rootCtx.setSetting(rootCtx.settings.YreadComments, true)
Expand Down
2 changes: 2 additions & 0 deletions tests/init-global/pos/global-region1.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -experimental

import scala.annotation.init.region

trait B { def foo(): Int }
Expand Down
2 changes: 2 additions & 0 deletions tests/init-global/warn/i18628_3.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -experimental

import scala.annotation.init.widen

object Test:
Expand Down
1 change: 1 addition & 0 deletions tests/neg-macros/i19842/Macro.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//> using options -experimental

import scala.annotation.{experimental, targetName}
import scala.quoted.*
Expand Down
2 changes: 0 additions & 2 deletions tests/neg/experimental-nested-imports-2.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//> using options -Yno-experimental

import annotation.experimental

class Class1:
Expand Down
2 changes: 0 additions & 2 deletions tests/neg/experimental-nested-imports-3.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//> using options -Yno-experimental

import annotation.experimental

class Class1:
Expand Down
2 changes: 0 additions & 2 deletions tests/neg/experimental-nested-imports.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//> using options -Yno-experimental

import annotation.experimental

class Class1:
Expand Down
15 changes: 15 additions & 0 deletions tests/neg/i13091.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- [E190] Potential Issue Warning: tests/neg/i13091.scala:7:17 ---------------------------------------------------------
7 |def test: Unit = new Foo // error: class Foo is marked @experimental ...
| ^^^^^^^
| Discarded non-Unit value of type Foo. You may want to use `()`.
|
| longer explanation available when compiling with `-explain`
-- Error: tests/neg/i13091.scala:7:21 ----------------------------------------------------------------------------------
7 |def test: Unit = new Foo // error: class Foo is marked @experimental ...
| ^^^
| Experimental definition may only be used under experimental mode:
| 1. in a definition marked as @experimental, or
| 2. an experimental feature is imported in at the package level, or
| 3. compiling with the -experimental compiler flag.
|
| class Foo is marked @experimental
2 changes: 1 addition & 1 deletion tests/neg/inline-unstable-accessors.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//> using options -Werror -WunstableInlineAccessors -explain
//> using options -experimental -Werror -WunstableInlineAccessors -explain

package foo
import scala.annotation.publicInBinary
Expand Down
2 changes: 2 additions & 0 deletions tests/neg/overrides.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -experimental

class Foo {
type A = Int
type B >: Int <: Int
Expand Down
10 changes: 5 additions & 5 deletions tests/neg/publicInBinaryOverride.check
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- [E164] Declaration Error: tests/neg/publicInBinaryOverride.scala:8:15 -----------------------------------------------
8 | override def f(): Unit = () // error
| ^
| error overriding method f in class A of type (): Unit;
| method f of type (): Unit also needs to be declared with @publicInBinary
-- [E164] Declaration Error: tests/neg/publicInBinaryOverride.scala:10:15 ----------------------------------------------
10 | override def f(): Unit = () // error
| ^
| error overriding method f in class A of type (): Unit;
| method f of type (): Unit also needs to be declared with @publicInBinary
2 changes: 2 additions & 0 deletions tests/neg/publicInBinaryOverride.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -experimental

import scala.annotation.publicInBinary

class A:
Expand Down
3 changes: 1 addition & 2 deletions tests/neg/use-experimental-def.check
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
| Experimental definition may only be used under experimental mode:
| 1. in a definition marked as @experimental, or
| 2. an experimental feature is imported in at the package level, or
| 3. compiling with the -experimental compiler flag, or
| 4. with a nightly or snapshot version of the compiler.
| 3. compiling with the -experimental compiler.
|
| method foo is marked @experimental
2 changes: 2 additions & 0 deletions tests/pos-custom-args/captures/curried-closures.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -experimental

object Test:
def map2(xs: List[Int])(f: Int => Int): List[Int] = xs.map(f)
val f1 = map2
Expand Down
2 changes: 2 additions & 0 deletions tests/pos-macros/erasedArgs/Test_2.scala
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
//> using options -experimental

def test: "1abc" = mcr
2 changes: 2 additions & 0 deletions tests/pos/TupleReverse.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -experimental

import scala.Tuple.*
def test[T1, T2, T3, T4] =
summon[Reverse[EmptyTuple] =:= EmptyTuple]
Expand Down
2 changes: 2 additions & 0 deletions tests/pos/TupleReverseOnto.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -experimental

import scala.Tuple.*
def test[T1, T2, T3, T4] =
summon[ReverseOnto[(T1, T2), (T3, T4)] =:= ReverseOnto[(T1, T2), (T3, T4)]]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//> using options -experimental -Yno-experimental
//> using options -experimental

import scala.annotation.experimental

Expand Down
3 changes: 0 additions & 3 deletions tests/pos/i13091.scala

This file was deleted.

2 changes: 2 additions & 0 deletions tests/pos/i7851.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -experimental

trait Wrappable[T] { }
given Wrappable[Float] with { }

Expand Down
4 changes: 3 additions & 1 deletion tests/pos/overrides.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//> using options -experimental

class A[T] {

def f(x: T)(y: T = x) = y

import scala.language.experimental.clauseInterleaving

def b[U <: T](x: Int)[V >: T](y: String) = false
Expand Down
2 changes: 2 additions & 0 deletions tests/pos/tupled-function-instances.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -experimental

import scala.util.TupledFunction
object Test {
def main(args: Array[String]): Unit = {
Expand Down
2 changes: 2 additions & 0 deletions tests/run-deep-subtype/Tuple-reverse.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -experimental

import scala.reflect.ClassTag

object Test {
Expand Down
2 changes: 2 additions & 0 deletions tests/run-macros/i12021/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -experimental

import scala.quoted.*

inline def inspect[A]: String =
Expand Down
2 changes: 2 additions & 0 deletions tests/run-macros/i17105/Test_3.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -experimental

import reflect.Selectable.reflectiveSelectable

class Hoe { def f(x: Int): String = s"Hoe got ${x}" }
Expand Down
2 changes: 2 additions & 0 deletions tests/run-macros/macro-erased/Test_2.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -experimental

object Test {
def main(args: Array[String]): Unit = {
assert(Macro.foo1(1) == 0)
Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/term-show.check
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
()
}
@scala.annotation.internal.SourceFile("tests/run-macros/term-show/Test_2.scala") trait A() extends java.lang.Object {
@scala.annotation.internal.SourceFile("tests/run-macros/term-show/Test_2.scala") @scala.annotation.experimental trait A() extends java.lang.Object {
def imp(x: scala.Int)(implicit str: scala.Predef.String): scala.Int
def use(`x₂`: scala.Int)(using `str₂`: scala.Predef.String): scala.Int
def era(`x₃`: scala.Int)(erased `str₃`: scala.Predef.String): scala.Int
Expand Down
2 changes: 1 addition & 1 deletion tests/run/i13215.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//> using options -Werror -WunstableInlineAccessors
//> using options -experimental -Werror -WunstableInlineAccessors

import scala.annotation.publicInBinary

Expand Down
3 changes: 2 additions & 1 deletion tests/run/interleaving.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import scala.language.experimental.clauseInterleaving

object Test extends App {
import scala.language.experimental.clauseInterleaving
trait Key { type Value }
trait DB {
def getOrElse(k: Key)[V >: k.Value](default: V): V // dependent type parameter
Expand Down
2 changes: 2 additions & 0 deletions tests/run/noProtectedSuper.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -experimental

import scala.annotation.publicInBinary

package p {
Expand Down
2 changes: 1 addition & 1 deletion tests/run/publicInBinary/Lib_1.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//> using options -Werror -WunstableInlineAccessors
//> using options -experimental -Werror -WunstableInlineAccessors

package foo

Expand Down
1 change: 1 addition & 0 deletions tests/run/publicInBinary/Test_2.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//> using options -experimental
import foo.*

@main def Test: Unit =
Expand Down
2 changes: 2 additions & 0 deletions tests/run/quotes-add-erased/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//> using options -experimental

import scala.annotation.MacroAnnotation
import scala.annotation.internal.ErasedParam
import scala.quoted._
Expand Down
3 changes: 3 additions & 0 deletions tests/run/quotes-reflection/Macros_1.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

//> using options -experimental

import scala.quoted.*

inline def inspect[A]: String =
Expand Down

0 comments on commit 9aa0ce6

Please sign in to comment.