Skip to content

Commit 3e4794b

Browse files
committed
Do not enable experimental by default in nightly and snapshot versions
This scheme was devised as a simple way to enable experimental on non-stable released. This made it impossible to publish a library containing experimental features for a non-experimental version of the compiler. We had `-Yno-experimental` to test the expected behavior on stable releases. Later we added `-experimental` which add `@experimental` to all top-level classes. On a stable release, this has the same effect as enabling experimental features, but it also allows publishing this library (users will need to also be experimental to use it). We can use `-experimental` on nightly and snapshot releases to achieve the same behavior as before. By doing this the `-Yno-experimental` flag is no longer needed and can be removed. We will need to use `-experimental` in all our tests to enable experimental by default. We can add this compiler flag to the default settings. We also need a few tests that do not use `-experimental` to test the behavior of `@experimental`. These can be added in `tests/*-no-experimental/`. Not all tests have `-experimental` enabled, this will be added on a need basis. With this we detected one bug, the runtime staging compile crashes if the code uses experimental features. To fix this we enable `-experimental` by default in this compiler. Note that the experimental-ness checks will have been done by the compiler that compiled the quotes.
1 parent 0800dec commit 3e4794b

File tree

67 files changed

+40
-53
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+40
-53
lines changed

compiler/src/dotty/tools/dotc/config/Feature.scala

+2-3
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ object Feature:
136136
report.error(
137137
em"""Experimental $which may only be used under experimental mode:
138138
| 1. In a definition marked as @experimental
139-
| 2. Compiling with the -experimental compiler flag
140-
| 3. With a nightly or snapshot version of the compiler$note
139+
| 2. Compiling with the -experimental compiler flag$note
141140
""", srcPos)
142141

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

165164
def isExperimentalEnabled(using Context): Boolean =
166-
(Properties.experimental || ctx.settings.experimental.value) && !ctx.settings.YnoExperimental.value
165+
ctx.settings.experimental.value
167166

168167
/** Handle language import `import language.<prefix>.<imported>` if it is one
169168
* of the global imports `pureFunctions` or `captureChecking`. In this case

compiler/src/dotty/tools/dotc/config/Properties.scala

+2-7
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,8 @@ trait PropertiesTrait {
8484
*/
8585
val versionString: String = "version " + simpleVersionString
8686

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

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

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ private sealed trait YSettings:
397397
val YretainTrees: Setting[Boolean] = BooleanSetting("-Yretain-trees", "Retain trees for top-level classes, accessible from ClassSymbol#tree")
398398
val YshowTreeIds: Setting[Boolean] = BooleanSetting("-Yshow-tree-ids", "Uniquely tag all tree nodes in debugging output.")
399399
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.")
400-
val YnoExperimental: Setting[Boolean] = BooleanSetting("-Yno-experimental", "Disable experimental language features.")
401400
val YlegacyLazyVals: Setting[Boolean] = BooleanSetting("-Ylegacy-lazy-vals", "Use legacy (pre 3.3.0) implementation of lazy vals.")
402401
val YcompileScala2Library: Setting[Boolean] = BooleanSetting("-Ycompile-scala2-library", "Used when compiling the Scala 2 standard library.")
403402
val YoutputOnlyTasty: Setting[Boolean] = BooleanSetting("-Youtput-only-tasty", "Used to only generate the TASTy file without the classfiles")

compiler/src/dotty/tools/dotc/plugins/Plugins.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ trait Plugins {
129129
val updatedPlan = Plugins.schedule(plan, pluginPhases)
130130

131131
// add research plugins
132-
if Properties.experimental && !ctx.settings.YnoExperimental.value then
132+
if Properties.researchPluginsEnabled then
133133
plugins.collect { case p: ResearchPlugin => p }.foldRight(updatedPlan) {
134134
(plug, plan) => plug.init(options(plug), plan)
135135
}

compiler/test/dotty/tools/DottyTest.scala

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ trait DottyTest extends ContextEscapeDetection {
4040
protected def initializeCtx(fc: FreshContext): Unit = {
4141
fc.setSetting(fc.settings.encoding, "UTF8")
4242
fc.setSetting(fc.settings.classpath, TestConfiguration.basicClasspath)
43+
fc.setSetting(fc.settings.experimental, true)
4344
fc.setSetting(fc.settings.language, List("experimental.erasedDefinitions"))
4445
fc.setProperty(ContextDoc, new ContextDocstrings)
4546
}

compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala

+9-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class BootstrappedOnlyCompilationTests {
2929
aggregateTests(
3030
compileFilesInDir("tests/bench", defaultOptions.without("-Yno-deep-subtypes")),
3131
compileFilesInDir("tests/pos-macros", defaultOptions.and("-Xcheck-macros")),
32+
compileFilesInDir("tests/pos-no-experimental", defaultOptions.without("-experimental")),
3233
).checkCompile()
3334
}
3435

@@ -104,8 +105,10 @@ class BootstrappedOnlyCompilationTests {
104105

105106
@Test def negMacros: Unit = {
106107
implicit val testGroup: TestGroup = TestGroup("compileNegWithCompiler")
107-
compileFilesInDir("tests/neg-macros", defaultOptions.and("-Xcheck-macros"))
108-
.checkExpectedErrors()
108+
aggregateTests(
109+
compileFilesInDir("tests/neg-macros", defaultOptions.and("-Xcheck-macros")),
110+
compileFilesInDir("tests/neg-no-experimental", defaultOptions.without("-experimental")),
111+
).checkExpectedErrors()
109112
}
110113

111114
@Test def negWithCompiler: Unit = {
@@ -120,8 +123,10 @@ class BootstrappedOnlyCompilationTests {
120123

121124
@Test def runMacros: Unit = {
122125
implicit val testGroup: TestGroup = TestGroup("runMacros")
123-
compileFilesInDir("tests/run-macros", defaultOptions.and("-Xcheck-macros"), FileFilter.exclude(TestSources.runMacrosScala2LibraryTastyBlacklisted))
124-
.checkRuns()
126+
aggregateTests(
127+
compileFilesInDir("tests/run-macros", defaultOptions.and("-Xcheck-macros"), FileFilter.exclude(TestSources.runMacrosScala2LibraryTastyBlacklisted)),
128+
compileFilesInDir("tests/run-no-experimental", defaultOptions.without("-experimental")),
129+
).checkRuns()
125130
}
126131

127132
@Test def runWithCompiler: Unit = {

compiler/test/dotty/tools/repl/ReplTest.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,6 @@ extends ReplDriver(options, new PrintStream(out, true, StandardCharsets.UTF_8.na
104104
}
105105

106106
object ReplTest:
107-
val commonOptions = Array("-color:never", "-language:experimental.erasedDefinitions", "-pagewidth", "80")
107+
val commonOptions = Array("-color:never", "-pagewidth", "80")
108108
val defaultOptions = commonOptions ++ Array("-classpath", TestConfiguration.basicClasspath)
109109
lazy val withStagingOptions = commonOptions ++ Array("-classpath", TestConfiguration.withStagingClasspath)

compiler/test/dotty/tools/repl/ScriptedTests.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import org.junit.Test
66
import org.junit.experimental.categories.Category
77

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

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

@@ -17,4 +17,5 @@ class ScriptedTests extends ReplTest {
1717
}
1818

1919
object ScriptedTests {
20+
val options = Array("-experimental", "-language:experimental.erasedDefinitions") ++ ReplTest.defaultOptions
2021
}

compiler/test/dotty/tools/vulpix/TestConfiguration.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ object TestConfiguration {
6565

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

68-
val commonOptions = Array("-indent") ++ checkOptions ++ noCheckOptions ++ yCheckOptions
68+
val commonOptions = Array("-indent", "-experimental") ++ checkOptions ++ noCheckOptions ++ yCheckOptions
6969
val defaultOptions = TestFlags(basicClasspath, commonOptions)
7070
val unindentOptions = TestFlags(basicClasspath, Array("-no-indent") ++ checkOptions ++ noCheckOptions ++ yCheckOptions)
7171
val withCompilerOptions =

docs/_docs/reference/other-new-features/experimental-defs.md

-2

docs/_spec/TODOreference/other-new-features/experimental-defs.md

+2-5

project/Build.scala

-3
Original file line numberDiff line numberDiff line change
@@ -2155,9 +2155,6 @@ object Build {
21552155
settings(
21562156
versionScheme := Some("semver-spec"),
21572157
libraryDependencies += "org.scala-lang" % "scala-library" % stdlibVersion,
2158-
// Make sure we do not refer to experimental features outside an experimental scope.
2159-
// In other words, disable NIGHTLY/SNAPSHOT experimental scope.
2160-
scalacOptions += "-Yno-experimental",
21612158
).
21622159
settings(dottyLibrarySettings)
21632160
if (mode == Bootstrapped) {

staging/src/scala/quoted/staging/QuoteDriver.scala

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ private class QuoteDriver(appClassloader: ClassLoader) extends Driver:
3737
val ctx = {
3838
val ctx0 = QuotesCache.init(initCtx.fresh)
3939
val ctx1 = setup(settings.compilerArgs.toArray :+ "dummy.scala", ctx0).get._2
40-
setCompilerSettings(ctx1.fresh.setSetting(ctx1.settings.outputDir, outDir), settings)
40+
val ctx2 = ctx1.fresh
41+
ctx2.setSetting(ctx1.settings.outputDir, outDir)
42+
ctx2.setSetting(ctx1.settings.experimental, true)
43+
setCompilerSettings(ctx2, settings)
4144
}
4245

4346
new QuoteCompiler().newRun(ctx).compileExpr(exprBuilder) match

tests/neg-macros/i18677-a.check

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11

2-
-- Error: tests/neg-macros/i18677-a/Test_2.scala:4:6 -------------------------------------------------------------------
3-
3 |@extendFoo
4-
4 |class AFoo // error
2+
-- Error: tests/neg-macros/i18677-a/Test_2.scala:2:6 -------------------------------------------------------------------
3+
1 |@extendFoo
4+
2 |class AFoo // error
55
|^
66
|Malformed tree was found while expanding macro with -Xcheck-macros.
77
|The tree does not conform to the compiler's tree invariants.
88
|
99
|Macro was:
10-
|@scala.annotation.internal.SourceFile("tests/neg-macros/i18677-a/Test_2.scala") @extendFoo class AFoo()
10+
|@scala.annotation.internal.SourceFile("tests/neg-macros/i18677-a/Test_2.scala") @scala.annotation.experimental @extendFoo class AFoo()
1111
|
1212
|The macro returned:
13-
|@scala.annotation.internal.SourceFile("tests/neg-macros/i18677-a/Test_2.scala") @extendFoo class AFoo() extends Foo
13+
|@scala.annotation.internal.SourceFile("tests/neg-macros/i18677-a/Test_2.scala") @scala.annotation.experimental @extendFoo class AFoo() extends Foo
1414
|
1515
|Error:
1616
|assertion failed: Parents of class symbol differs from the parents in the tree for class AFoo

tests/neg-macros/i18677-a/Macro_1.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//> using -expermiental
2-
31
import annotation.MacroAnnotation
42
import quoted.*
53

@@ -15,4 +13,4 @@ class extendFoo extends MacroAnnotation :
1513
newTree :: Nil
1614
case _ =>
1715
report.error("@extendFoo can only annotate class definitions")
18-
tree :: Nil
16+
tree :: Nil
+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
//> using -expermiental
2-
31
@extendFoo
4-
class AFoo // error
2+
class AFoo // error

tests/neg-macros/i18677-b.check

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11

2-
-- Error: tests/neg-macros/i18677-b/Test_2.scala:4:6 -------------------------------------------------------------------
3-
3 |@extendFoo
4-
4 |class AFoo // error
2+
-- Error: tests/neg-macros/i18677-b/Test_2.scala:2:6 -------------------------------------------------------------------
3+
1 |@extendFoo
4+
2 |class AFoo // error
55
|^
66
|Malformed tree was found while expanding macro with -Xcheck-macros.
77
|The tree does not conform to the compiler's tree invariants.
88
|
99
|Macro was:
10-
|@scala.annotation.internal.SourceFile("tests/neg-macros/i18677-b/Test_2.scala") @extendFoo class AFoo()
10+
|@scala.annotation.internal.SourceFile("tests/neg-macros/i18677-b/Test_2.scala") @scala.annotation.experimental @extendFoo class AFoo()
1111
|
1212
|The macro returned:
13-
|@scala.annotation.internal.SourceFile("tests/neg-macros/i18677-b/Test_2.scala") @extendFoo class AFoo() extends Foo
13+
|@scala.annotation.internal.SourceFile("tests/neg-macros/i18677-b/Test_2.scala") @scala.annotation.experimental @extendFoo class AFoo() extends Foo
1414
|
1515
|Error:
1616
|assertion failed: Parents of class symbol differs from the parents in the tree for class AFoo

tests/neg-macros/i18677-b/Macro_1.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//> using -expermiental
2-
31
import annotation.MacroAnnotation
42
import quoted.*
53

@@ -15,4 +13,4 @@ class extendFoo extends MacroAnnotation :
1513
newTree :: Nil
1614
case _ =>
1715
report.error("@extendFoo can only annotate class definitions")
18-
tree :: Nil
16+
tree :: Nil
+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
//> using -expermiental
2-
31
@extendFoo
4-
class AFoo // error
2+
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.

tests/run-macros/term-show.check

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111
()
1212
}
13-
@scala.annotation.internal.SourceFile("tests/run-macros/term-show/Test_2.scala") trait A() extends java.lang.Object {
13+
@scala.annotation.internal.SourceFile("tests/run-macros/term-show/Test_2.scala") @scala.annotation.experimental trait A() extends java.lang.Object {
1414
def imp(x: scala.Int)(implicit str: scala.Predef.String): scala.Int
1515
def use(`x₂`: scala.Int)(using `str₂`: scala.Predef.String): scala.Int
1616
def era(`x₃`: scala.Int)(erased `str₃`: scala.Predef.String): scala.Int

0 commit comments

Comments
 (0)