Skip to content

Commit cf55a31

Browse files
committed
Disable experimental on nightly/snapshot build without -experimental
1 parent 025c211 commit cf55a31

File tree

369 files changed

+517
-295
lines changed

Some content is hidden

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

369 files changed

+517
-295
lines changed

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,9 @@ object Feature:
135135
def checkExperimentalFeature(which: String, srcPos: SrcPos, note: => String = "")(using Context) =
136136
if !isExperimentalEnabled then
137137
report.error(
138-
em"""Experimental $which may only be used under experimental mode:
138+
em"""$which may only be used under experimental mode:
139139
| 1. In a definition marked as @experimental
140-
| 2. Compiling with the -experimental compiler flag
141-
| 3. With a nightly or snapshot version of the compiler$note
140+
| 2. Compiling with the -experimental compiler flag$note
142141
""", srcPos)
143142

144143
private def ccException(sym: Symbol)(using Context): Boolean =
@@ -153,18 +152,18 @@ object Feature:
153152
if !ccException(experimentalSym) then
154153
val symMsg =
155154
if experimentalSym.exists
156-
then i"$experimentalSym is marked @experimental"
157-
else i"$sym inherits @experimental"
158-
report.error(em"$symMsg and therefore may only be used in an experimental scope.", srcPos)
155+
then i"$experimentalSym is marked @experimental, it"
156+
else i"$sym inherits @experimental, it"
157+
checkExperimentalFeature(symMsg, srcPos)
159158

160-
/** Check that experimental compiler options are only set for snapshot or nightly compiler versions. */
159+
/** Check that experimental compiler options are only set with `-experimental`. */
161160
def checkExperimentalSettings(using Context): Unit =
162161
for setting <- ctx.settings.language.value
163162
if setting.startsWith("experimental.") && setting != "experimental.macros"
164-
do checkExperimentalFeature(s"feature $setting", NoSourcePosition)
163+
do checkExperimentalFeature(s"Experimental feature $setting", NoSourcePosition)
165164

166165
def isExperimentalEnabled(using Context): Boolean =
167-
(Properties.experimental || ctx.settings.experimental.value) && !ctx.settings.YnoExperimental.value
166+
ctx.settings.experimental.value
168167

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

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,6 @@ 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")
94-
9587
val copyrightString: String = scalaPropOrElse("copyright.string", "(c) 2002-2017 LAMP/EPFL")
9688

9789
/** This is the encoding to use reading in source files, overridden with -encoding

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,6 @@ private sealed trait YSettings:
368368
val YretainTrees: Setting[Boolean] = BooleanSetting("-Yretain-trees", "Retain trees for top-level classes, accessible from ClassSymbol#tree")
369369
val YshowTreeIds: Setting[Boolean] = BooleanSetting("-Yshow-tree-ids", "Uniquely tag all tree nodes in debugging output.")
370370
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.")
371-
val YnoExperimental: Setting[Boolean] = BooleanSetting("-Yno-experimental", "Disable experimental language features.")
372371
val YlegacyLazyVals: Setting[Boolean] = BooleanSetting("-Ylegacy-lazy-vals", "Use legacy (pre 3.3.0) implementation of lazy vals.")
373372
val Yscala2Stdlib: Setting[Boolean] = BooleanSetting("-Yscala2-stdlib", "Used when compiling the Scala 2 standard library.")
374373
val YoutputOnlyTasty: Setting[Boolean] = BooleanSetting("-Youtput-only-tasty", "Used to only generate the TASTy file without the classfiles")

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,15 +805,15 @@ object Checking {
805805
case Some(nme.experimental)
806806
if !ctx.owner.isInExperimentalScope && !selectors.forall(isAllowedImport) =>
807807
def check(stable: => String) =
808-
Feature.checkExperimentalFeature("features", imp.srcPos,
808+
Feature.checkExperimentalFeature("Experimental features", imp.srcPos,
809809
s"\n\nNote: the scope enclosing the import is not considered experimental because it contains the\nnon-experimental $stable")
810810
if ctx.owner.is(Package) then
811811
// allow top-level experimental imports if all definitions are @experimental
812812
nonExperimentalStat(trees) match
813813
case EmptyTree =>
814814
case tree: MemberDef => check(i"${tree.symbol}")
815815
case tree => check(i"expression ${tree}")
816-
else Feature.checkExperimentalFeature("features", imp.srcPos)
816+
else Feature.checkExperimentalFeature("Experimental features", imp.srcPos)
817817
case _ =>
818818
end checkExperimentalImports
819819
}

compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ trait QuotesAndSplices {
173173
getQuotedPatternTypeVariable(tree.name.asTypeName) match
174174
case Some(typeSym) =>
175175
checkExperimentalFeature(
176-
"support for multiple references to the same type (without backticks) in quoted type patterns (SIP-53)",
176+
"Experimental support for multiple references to the same type (without backticks) in quoted type patterns (SIP-53)",
177177
tree.srcPos,
178178
"\n\nSIP-53: https://docs.scala-lang.org/sips/quote-pattern-type-variable-syntax.html")
179179
warnOnInferredBounds(typeSym)
@@ -225,7 +225,7 @@ trait QuotesAndSplices {
225225

226226
if quoted.isType && untpdTypeVariables.nonEmpty then
227227
checkExperimentalFeature(
228-
"explicit type variable declarations quoted type patterns (SIP-53)",
228+
"Experimental explicit type variable declarations quoted type patterns (SIP-53)",
229229
untpdTypeVariables.head.srcPos,
230230
"\n\nSIP-53: https://docs.scala-lang.org/sips/quote-pattern-type-variable-syntax.html")
231231

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class BootstrappedOnlyCompilationTests {
191191
val targets = dirs.map { dir =>
192192
val compileDir = createOutputDirsForDir(dir, sourceDir, outDir)
193193
Files.copy(dir.toPath.resolve(pluginFile), compileDir.toPath.resolve(pluginFile), StandardCopyOption.REPLACE_EXISTING)
194-
val flags = TestFlags(withCompilerClasspath, noCheckOptions).and("-Xplugin:" + compileDir.getAbsolutePath)
194+
val flags = TestFlags(withCompilerClasspath, noCheckOptions).and("-Xplugin:" + compileDir.getAbsolutePath).and("-experimental")
195195
SeparateCompilationSource("testPlugins", dir, flags, compileDir)
196196
}
197197

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class CompilationTests {
3535
compileFilesInDir("tests/pos-special/sourcepath/outer", defaultOptions.and("-sourcepath", "tests/pos-special/sourcepath")),
3636
compileFile("tests/pos-special/sourcepath/outer/nested/Test4.scala", defaultOptions.and("-sourcepath", "tests/pos-special/sourcepath")),
3737
compileFilesInDir("tests/pos-scala2", defaultOptions.and("-source", "3.0-migration")),
38-
compileFilesInDir("tests/pos-custom-args/captures", defaultOptions.and("-language:experimental.captureChecking")),
38+
compileFilesInDir("tests/pos-custom-args/captures", defaultOptions.and("-language:experimental.captureChecking", "-experimental")),
39+
compileFilesInDir("tests/pos-custom-args/erased", defaultOptions.and("-language:experimental.erasedDefinitions", "-experimental", "-Ysafe-init")),
3940
compileFile("tests/pos-special/utf8encoded.scala", defaultOptions.and("-encoding", "UTF8")),
4041
compileFile("tests/pos-special/utf16encoded.scala", defaultOptions.and("-encoding", "UTF16")),
4142
// Run tests for legacy lazy vals
@@ -125,7 +126,8 @@ class CompilationTests {
125126
aggregateTests(
126127
compileFilesInDir("tests/neg", defaultOptions),
127128
compileFilesInDir("tests/neg-deep-subtype", allowDeepSubtypes),
128-
compileFilesInDir("tests/neg-custom-args/captures", defaultOptions.and("-language:experimental.captureChecking")),
129+
compileFilesInDir("tests/neg-custom-args/captures", defaultOptions.and("-language:experimental.captureChecking", "-experimental")),
130+
compileFilesInDir("tests/neg-custom-args/erased", defaultOptions.and("-language:experimental.erasedDefinitions", "-experimental")),
129131
compileFile("tests/neg-custom-args/sourcepath/outer/nested/Test1.scala", defaultOptions.and("-sourcepath", "tests/neg-custom-args/sourcepath")),
130132
compileDir("tests/neg-custom-args/sourcepath2/hi", defaultOptions.and("-sourcepath", "tests/neg-custom-args/sourcepath2", "-Xfatal-warnings")),
131133
compileList("duplicate source", List(
@@ -148,7 +150,8 @@ class CompilationTests {
148150
aggregateTests(
149151
compileFilesInDir("tests/run", defaultOptions.and("-Ysafe-init")),
150152
compileFilesInDir("tests/run-deep-subtype", allowDeepSubtypes),
151-
compileFilesInDir("tests/run-custom-args/captures", allowDeepSubtypes.and("-language:experimental.captureChecking")),
153+
compileFilesInDir("tests/run-custom-args/captures", allowDeepSubtypes.and("-language:experimental.captureChecking", "-experimental")),
154+
compileFilesInDir("tests/run-custom-args/erased", allowDeepSubtypes.and("-language:experimental.erasedDefinitions", "-experimental")),
152155
// Run tests for legacy lazy vals.
153156
compileFilesInDir("tests/run", defaultOptions.and("-Ysafe-init", "-Ylegacy-lazy-vals", "-Ycheck-constraint-deps"), FileFilter.include(TestSources.runLazyValsAllowlist)),
154157
).checkRuns()

docs/_docs/reference/changed-features/compiler-plugins.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ For experimentation and research, Scala 3 introduces _research plugin_. Research
1818
are more powerful than Scala 2 analyzer plugins as they let plugin authors customize
1919
the whole compiler pipeline. One can easily replace the standard typer by a custom one or
2020
create a parser for a domain-specific language. However, research plugins are only
21-
enabled with the `-experimental` compiler flag or in nightly/snapshot releases of Scala 3.
21+
enabled with the `-experimental` compiler flag.
2222

2323
Common plugins that add new phases to the compiler pipeline are called
2424
_standard plugins_ in Scala 3. In terms of features, they are similar to

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,7 @@ Experimental definitions can only be referenced in an experimental scope. Experi
265265

266266
</details>
267267

268-
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.
269-
Can use the `-Yno-experimental` compiler flag to disable it and run as a proper release.
268+
6. Any code compiled using the `-experimental` compiler flag considered to be in an experimental scope.
270269

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

project/Build.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,9 +2026,6 @@ object Build {
20262026
settings(
20272027
versionScheme := Some("semver-spec"),
20282028
libraryDependencies += "org.scala-lang" % "scala-library" % stdlibVersion,
2029-
// Make sure we do not refer to experimental features outside an experimental scope.
2030-
// In other words, disable NIGHTLY/SNAPSHOT experimental scope.
2031-
scalacOptions += "-Yno-experimental",
20322029
).
20332030
settings(dottyLibrarySettings)
20342031
if (mode == Bootstrapped) {

tests/coverage/run/erased/test.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//> using options -experimental
2+
13
import scala.language.experimental.erasedDefinitions
24

35
erased def parameterless: String = "y"

tests/coverage/run/erased/test.scoverage.check

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ test$package$
2525
Object
2626
<empty>.test$package$
2727
foo
28-
181
29-
203
30-
6
28+
214
29+
236
30+
8
3131
println
3232
Apply
3333
false
@@ -42,9 +42,9 @@ test$package$
4242
Object
4343
<empty>.test$package$
4444
foo
45-
189
46-
202
47-
6
45+
222
46+
235
47+
8
4848
s
4949
Apply
5050
false
@@ -59,9 +59,9 @@ test$package$
5959
Object
6060
<empty>.test$package$
6161
foo
62-
132
63-
139
64-
5
62+
165
63+
172
64+
7
6565
foo
6666
DefDef
6767
false
@@ -76,9 +76,9 @@ test$package$
7676
Object
7777
<empty>.test$package$
7878
identity
79-
245
80-
269
81-
10
79+
278
80+
302
81+
12
8282
println
8383
Apply
8484
false
@@ -93,9 +93,9 @@ test$package$
9393
Object
9494
<empty>.test$package$
9595
identity
96-
253
97-
268
98-
10
96+
286
97+
301
98+
12
9999
s
100100
Apply
101101
false
@@ -110,9 +110,9 @@ test$package$
110110
Object
111111
<empty>.test$package$
112112
identity
113-
209
114-
221
115-
9
113+
242
114+
254
115+
11
116116
identity
117117
DefDef
118118
false
@@ -127,9 +127,9 @@ test$package$
127127
Object
128128
<empty>.test$package$
129129
Test
130-
300
131-
323
132-
15
130+
333
131+
356
132+
17
133133
foo
134134
Apply
135135
false
@@ -144,9 +144,9 @@ test$package$
144144
Object
145145
<empty>.test$package$
146146
Test
147-
326
148-
342
149-
16
147+
359
148+
375
149+
18
150150
foo
151151
Apply
152152
false
@@ -161,9 +161,9 @@ test$package$
161161
Object
162162
<empty>.test$package$
163163
Test
164-
345
165-
374
166-
17
164+
378
165+
407
166+
19
167167
foo
168168
Apply
169169
false
@@ -178,9 +178,9 @@ test$package$
178178
Object
179179
<empty>.test$package$
180180
Test
181-
357
182-
373
183-
17
181+
390
182+
406
183+
19
184184
identity
185185
Apply
186186
false
@@ -195,9 +195,9 @@ test$package$
195195
Object
196196
<empty>.test$package$
197197
Test
198-
275
199-
289
200-
14
198+
308
199+
322
200+
16
201201
Test
202202
DefDef
203203
false

tests/init-global/pos/global-region1.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//> using options -experimental
2+
13
import scala.annotation.init.region
24

35
trait B { def foo(): Int }

tests/init/pos/interleaving-overload.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//> using options -experimental
2+
13
import scala.language.experimental.clauseInterleaving
24

35
class A{

tests/init/pos/interleaving-params.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//> using options -experimental
2+
13
import scala.collection.mutable.AbstractSet
24
import scala.collection.mutable.BitSet
35
import scala.language.experimental.clauseInterleaving

tests/neg-macros/BigFloat/BigFloat_1.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//> using options -experimental
2+
13
package test
24
import language.experimental.genericNumberLiterals
35
import scala.util.FromDigits

tests/neg-macros/BigFloat/Test_2.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//> using options -experimental
2+
13
import test.BigFloat
24
object Test extends App {
35
val x: BigFloat = 1234.45e3333333333 // error: exponent too large

tests/neg-macros/GenericNumLits/Even_1.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//> using options -experimental
2+
13
import language.experimental.genericNumberLiterals
24
import scala.util.FromDigits
35
import scala.quoted.*

tests/neg-macros/GenericNumLits/Test_2.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//> using options -experimental
2+
13
import language.experimental.genericNumberLiterals
24
object Test extends App {
35

tests/neg-macros/macro-experimental.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//> using options -Yno-experimental
2-
31
import scala.quoted.*
42
import scala.annotation.experimental
53

tests/neg-macros/newClassExtendsNoParents/Macro_1.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//> using options -experimental
2+
13
import scala.quoted.*
24

35
inline def makeClass(inline name: String): Any = ${ makeClassExpr('name) }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
//> using options -experimental
2+
13
def test: Any = makeClass("foo") // error

tests/neg-macros/newClassExtendsOnlyTrait/Macro_1.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//> using options -experimental
2+
13
import scala.quoted.*
24

35
inline def makeClass(inline name: String): Foo = ${ makeClassExpr('name) }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
//> using options -experimental
2+
13
def test: Foo = makeClass("foo") // error

tests/neg-macros/quote-pattern-type-var-bounds.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//> using options -experimental
2+
13
import scala.quoted.*
24
def types(t: Type[?])(using Quotes) = t match {
35
case '[ type t; Int ] =>

0 commit comments

Comments
 (0)