Skip to content

Do not enable experimental by default in nightly and snapshot versions #19708

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions compiler/src/dotty/tools/dotc/config/Feature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ object Feature:
report.error(
em"""Experimental $which may only be used under experimental mode:
| 1. In a definition marked as @experimental
| 2. Compiling with the -experimental compiler flag
| 3. With a nightly or snapshot version of the compiler$note
| 2. Compiling with the -experimental compiler flag$note
""", srcPos)

private def ccException(sym: Symbol)(using Context): Boolean =
Expand All @@ -163,7 +162,7 @@ object Feature:
do checkExperimentalFeature(s"feature $setting", NoSourcePosition)

def isExperimentalEnabled(using Context): Boolean =
(Properties.experimental || ctx.settings.experimental.value) && !ctx.settings.YnoExperimental.value
ctx.settings.experimental.value

/** Handle language import `import language.<prefix>.<imported>` if it is one
* of the global imports `pureFunctions` or `captureChecking`. In this case
Expand Down
9 changes: 2 additions & 7 deletions compiler/src/dotty/tools/dotc/config/Properties.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,8 @@ trait PropertiesTrait {
*/
val versionString: String = "version " + simpleVersionString

/** Whether the current version of compiler is experimental
*
* 1. Snapshot, nightly releases and non-bootstrapped compiler are experimental.
* 2. Features supported by experimental versions of the compiler:
* - research plugins
*/
val experimental: Boolean = versionString.contains("SNAPSHOT") || versionString.contains("NIGHTLY") || versionString.contains("nonbootstrapped")
/** Whether the current version of supports research plugins */
val researchPluginsEnabled: Boolean = versionString.contains("SNAPSHOT") || versionString.contains("NIGHTLY") || versionString.contains("nonbootstrapped")

val copyrightString: String = scalaPropOrElse("copyright.string", "(c) 2002-2017 LAMP/EPFL")

Expand Down
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ 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.")
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/plugins/Plugins.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ trait Plugins {
val updatedPlan = Plugins.schedule(plan, pluginPhases)

// add research plugins
if Properties.experimental && !ctx.settings.YnoExperimental.value then
if Properties.researchPluginsEnabled then
plugins.collect { case p: ResearchPlugin => p }.foldRight(updatedPlan) {
(plug, plan) => plug.init(options(plug), plan)
}
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotty/tools/DottyTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ trait DottyTest extends ContextEscapeDetection {
protected def initializeCtx(fc: FreshContext): Unit = {
fc.setSetting(fc.settings.encoding, "UTF8")
fc.setSetting(fc.settings.classpath, TestConfiguration.basicClasspath)
fc.setSetting(fc.settings.experimental, true)
fc.setSetting(fc.settings.language, List("experimental.erasedDefinitions"))
fc.setProperty(ContextDoc, new ContextDocstrings)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class BootstrappedOnlyCompilationTests {
aggregateTests(
compileFilesInDir("tests/bench", defaultOptions.without("-Yno-deep-subtypes")),
compileFilesInDir("tests/pos-macros", defaultOptions.and("-Xcheck-macros")),
compileFilesInDir("tests/pos-no-experimental", defaultOptions.without("-experimental")),
).checkCompile()
}

Expand Down Expand Up @@ -104,8 +105,10 @@ class BootstrappedOnlyCompilationTests {

@Test def negMacros: Unit = {
implicit val testGroup: TestGroup = TestGroup("compileNegWithCompiler")
compileFilesInDir("tests/neg-macros", defaultOptions.and("-Xcheck-macros"))
.checkExpectedErrors()
aggregateTests(
compileFilesInDir("tests/neg-macros", defaultOptions.and("-Xcheck-macros")),
compileFilesInDir("tests/neg-no-experimental", defaultOptions.without("-experimental")),
).checkExpectedErrors()
}

@Test def negWithCompiler: Unit = {
Expand Down
4 changes: 3 additions & 1 deletion compiler/test/dotty/tools/dotc/TastyBootstrapTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ class TastyBootstrapTests {

val lib =
compileList("lib", librarySources,
defaultOptions.and("-Ycheck-reentrant",
defaultOptions.and(
"-Ycheck-reentrant",
"-experimental",
"-language:experimental.erasedDefinitions", // support declaration of scala.compiletime.erasedValue
// "-source", "future", // TODO: re-enable once library uses updated syntax for vararg splices, wildcard imports, and import renaming
))(libGroup)
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/dotty/tools/repl/ReplTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@ extends ReplDriver(options, new PrintStream(out, true, StandardCharsets.UTF_8.na
}

object ReplTest:
val commonOptions = Array("-color:never", "-language:experimental.erasedDefinitions", "-pagewidth", "80")
val commonOptions = Array("-color:never", "-pagewidth", "80")
val defaultOptions = commonOptions ++ Array("-classpath", TestConfiguration.basicClasspath)
lazy val withStagingOptions = commonOptions ++ Array("-classpath", TestConfiguration.withStagingClasspath)
3 changes: 2 additions & 1 deletion compiler/test/dotty/tools/repl/ScriptedTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.junit.Test
import org.junit.experimental.categories.Category

/** Runs all tests contained in `compiler/test-resources/repl/` */
class ScriptedTests extends ReplTest {
class ScriptedTests extends ReplTest(ScriptedTests.options) {

@Test def replTests = scripts("/repl").foreach(testFile)

Expand All @@ -17,4 +17,5 @@ class ScriptedTests extends ReplTest {
}

object ScriptedTests {
val options = Array("-experimental", "-language:experimental.erasedDefinitions") ++ ReplTest.defaultOptions
}
2 changes: 1 addition & 1 deletion compiler/test/dotty/tools/vulpix/TestConfiguration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ object TestConfiguration {

val yCheckOptions = Array("-Ycheck:all")

val commonOptions = Array("-indent") ++ checkOptions ++ noCheckOptions ++ yCheckOptions
val commonOptions = Array("-indent", "-experimental") ++ checkOptions ++ noCheckOptions ++ yCheckOptions
val defaultOptions = TestFlags(basicClasspath, commonOptions)
val unindentOptions = TestFlags(basicClasspath, Array("-no-indent") ++ checkOptions ++ noCheckOptions ++ yCheckOptions)
val withCompilerOptions =
Expand Down
2 changes: 0 additions & 2 deletions docs/_docs/reference/other-new-features/experimental-defs.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,6 @@ 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.

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 @@ -216,7 +216,7 @@ Experimental definitions can only be referenced in an experimental scope. Experi

<details>
<summary>Example 1</summary>

```scala
import scala.annotation.experimental

Expand All @@ -242,7 +242,7 @@ Experimental definitions can only be referenced in an experimental scope. Experi
}
}
```

</details>

5. Annotations of an experimental definition are in experimental scopes. Examples:
Expand All @@ -265,9 +265,6 @@ 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.

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

## Experimental inheritance
Expand Down
9 changes: 5 additions & 4 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,10 @@ object Build {

lazy val `scaladoc-testcases` = project.in(file("scaladoc-testcases")).
dependsOn(`scala3-compiler-bootstrapped`).
settings(commonBootstrappedSettings)
settings(commonBootstrappedSettings).
settings(
scalacOptions += "-experimental",
)


/**
Expand Down Expand Up @@ -1758,6 +1761,7 @@ object Build {
SourceLinksIntegrationTest / test:= ((SourceLinksIntegrationTest / test) dependsOn generateScalaDocumentation.toTask("")).value,
).
settings(
scalacOptions += "-experimental", // FIXME scaladoc should not use exprimental APIs
Compile / resourceGenerators ++= Seq(
generateStaticAssetsTask.taskValue,
bundleCSS.taskValue
Expand Down Expand Up @@ -2155,9 +2159,6 @@ object Build {
settings(
versionScheme := Some("semver-spec"),
libraryDependencies += "org.scala-lang" % "scala-library" % stdlibVersion,
// Make sure we do not refer to experimental features outside an experimental scope.
// In other words, disable NIGHTLY/SNAPSHOT experimental scope.
scalacOptions += "-Yno-experimental",
).
settings(dottyLibrarySettings)
if (mode == Bootstrapped) {
Expand Down
5 changes: 4 additions & 1 deletion staging/src/scala/quoted/staging/QuoteDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ private class QuoteDriver(appClassloader: ClassLoader) extends Driver:
val ctx = {
val ctx0 = QuotesCache.init(initCtx.fresh)
val ctx1 = setup(settings.compilerArgs.toArray :+ "dummy.scala", ctx0).get._2
setCompilerSettings(ctx1.fresh.setSetting(ctx1.settings.outputDir, outDir), settings)
val ctx2 = ctx1.fresh
ctx2.setSetting(ctx1.settings.outputDir, outDir)
ctx2.setSetting(ctx1.settings.experimental, true)
setCompilerSettings(ctx2, settings)
}

new QuoteCompiler().newRun(ctx).compileExpr(exprBuilder) match
Expand Down
10 changes: 5 additions & 5 deletions tests/neg-macros/i18677-a.check
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@

-- Error: tests/neg-macros/i18677-a/Test_2.scala:4:6 -------------------------------------------------------------------
3 |@extendFoo
4 |class AFoo // error
-- Error: tests/neg-macros/i18677-a/Test_2.scala:2:6 -------------------------------------------------------------------
1 |@extendFoo
2 |class AFoo // error
|^
|Malformed tree was found while expanding macro with -Xcheck-macros.
|The tree does not conform to the compiler's tree invariants.
|
|Macro was:
|@scala.annotation.internal.SourceFile("tests/neg-macros/i18677-a/Test_2.scala") @extendFoo class AFoo()
|@scala.annotation.internal.SourceFile("tests/neg-macros/i18677-a/Test_2.scala") @scala.annotation.experimental @extendFoo class AFoo()
|
|The macro returned:
|@scala.annotation.internal.SourceFile("tests/neg-macros/i18677-a/Test_2.scala") @extendFoo class AFoo() extends Foo
|@scala.annotation.internal.SourceFile("tests/neg-macros/i18677-a/Test_2.scala") @scala.annotation.experimental @extendFoo class AFoo() extends Foo
|
|Error:
|assertion failed: Parents of class symbol differs from the parents in the tree for class AFoo
Expand Down
4 changes: 1 addition & 3 deletions tests/neg-macros/i18677-a/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//> using -expermiental

import annotation.MacroAnnotation
import quoted.*

Expand All @@ -15,4 +13,4 @@ class extendFoo extends MacroAnnotation :
newTree :: Nil
case _ =>
report.error("@extendFoo can only annotate class definitions")
tree :: Nil
tree :: Nil
4 changes: 1 addition & 3 deletions tests/neg-macros/i18677-a/Test_2.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
//> using -expermiental

@extendFoo
class AFoo // error
class AFoo // error
10 changes: 5 additions & 5 deletions tests/neg-macros/i18677-b.check
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@

-- Error: tests/neg-macros/i18677-b/Test_2.scala:4:6 -------------------------------------------------------------------
3 |@extendFoo
4 |class AFoo // error
-- Error: tests/neg-macros/i18677-b/Test_2.scala:2:6 -------------------------------------------------------------------
1 |@extendFoo
2 |class AFoo // error
|^
|Malformed tree was found while expanding macro with -Xcheck-macros.
|The tree does not conform to the compiler's tree invariants.
|
|Macro was:
|@scala.annotation.internal.SourceFile("tests/neg-macros/i18677-b/Test_2.scala") @extendFoo class AFoo()
|@scala.annotation.internal.SourceFile("tests/neg-macros/i18677-b/Test_2.scala") @scala.annotation.experimental @extendFoo class AFoo()
|
|The macro returned:
|@scala.annotation.internal.SourceFile("tests/neg-macros/i18677-b/Test_2.scala") @extendFoo class AFoo() extends Foo
|@scala.annotation.internal.SourceFile("tests/neg-macros/i18677-b/Test_2.scala") @scala.annotation.experimental @extendFoo class AFoo() extends Foo
|
|Error:
|assertion failed: Parents of class symbol differs from the parents in the tree for class AFoo
Expand Down
4 changes: 1 addition & 3 deletions tests/neg-macros/i18677-b/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//> using -expermiental

import annotation.MacroAnnotation
import quoted.*

Expand All @@ -15,4 +13,4 @@ class extendFoo extends MacroAnnotation :
newTree :: Nil
case _ =>
report.error("@extendFoo can only annotate class definitions")
tree :: Nil
tree :: Nil
4 changes: 1 addition & 3 deletions tests/neg-macros/i18677-b/Test_2.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
//> using -expermiental

@extendFoo
class AFoo // error
class AFoo // error
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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