Skip to content
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

Standardize how previously experimental features are handled #21686

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion community-build/community-projects/intent
Submodule intent updated 2 files
+0 −3 build.sbt
+0 −1 consume/build.sbt
9 changes: 0 additions & 9 deletions compiler/src/dotty/tools/dotc/config/Feature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ object Feature:
val dependent = experimental("dependent")
val erasedDefinitions = experimental("erasedDefinitions")
val symbolLiterals = deprecated("symbolLiterals")
val fewerBraces = experimental("fewerBraces")
val saferExceptions = experimental("saferExceptions")
val clauseInterleaving = experimental("clauseInterleaving")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not drop this one too ?

Suggested change
val clauseInterleaving = experimental("clauseInterleaving")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove namedTuples in line 36 too.

val pureFunctions = experimental("pureFunctions")
Expand Down Expand Up @@ -60,9 +59,7 @@ object Feature:
(dependent, "Allow dependent method types"),
(erasedDefinitions, "Allow erased definitions"),
(symbolLiterals, "Allow symbol literals"),
(fewerBraces, "Enable support for using indentation for arguments"),
(saferExceptions, "Enable safer exceptions"),
(clauseInterleaving, "Enable clause interleaving"),
(pureFunctions, "Enable pure functions for capture checking"),
(captureChecking, "Enable experimental capture checking"),
(into, "Allow into modifier on parameter types"),
Expand Down Expand Up @@ -124,9 +121,6 @@ object Feature:

def namedTypeArgsEnabled(using Context) = enabled(namedTypeArguments)

def clauseInterleavingEnabled(using Context) =
sourceVersion.isAtLeast(`3.6`) || enabled(clauseInterleaving)

def betterForsEnabled(using Context) = enabled(betterFors)

def genericNumberLiteralsEnabled(using Context) = enabled(genericNumberLiterals)
Expand Down Expand Up @@ -169,9 +163,6 @@ object Feature:
def migrateTo3(using Context): Boolean =
sourceVersion == `3.0-migration`

def fewerBracesEnabled(using Context) =
sourceVersion.isAtLeast(`3.3`) || enabled(fewerBraces)

/** If current source migrates to `version`, issue given warning message
* and return `true`, otherwise return `false`.
*/
Expand Down
5 changes: 5 additions & 0 deletions compiler/src/dotty/tools/dotc/config/SourceVersion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ enum SourceVersion:

def isAtMost(v: SourceVersion) = stable.ordinal <= v.ordinal

def enablesFewerBraces = isAtLeast(`3.3`)
def enablesClauseInterleaving = isAtLeast(`3.6`)
def enablesNewGivens = isAtLeast(`3.6`)
def enablesNamedTuples = isAtLeast(`3.6`)
Comment on lines +33 to +34
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where these two functions are used so far

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should rebase this PR to take into account #21680 and #21668


object SourceVersion extends Property.Key[SourceVersion]:
def defaultSourceVersion = `3.6`

Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ object Parsers {
}
})
canRewrite &= (in.isAfterLineEnd || statCtdTokens.contains(in.token)) // test (5)
if canRewrite && (!underColonSyntax || Feature.fewerBracesEnabled) then
if canRewrite && (!underColonSyntax || sourceVersion.enablesFewerBraces) then
val openingPatchStr =
if !colonRequired then ""
else if testChar(startOpening - 1, Chars.isOperatorPart(_)) then " :"
Expand Down Expand Up @@ -1119,7 +1119,7 @@ object Parsers {
* body
*/
def isColonLambda =
Feature.fewerBracesEnabled && in.token == COLONfollow && followingIsLambdaAfterColon()
sourceVersion.enablesFewerBraces && in.token == COLONfollow && followingIsLambdaAfterColon()

/** operand { infixop operand | MatchClause } [postfixop],
*
Expand Down Expand Up @@ -3914,7 +3914,7 @@ object Parsers {
val ident = termIdent()
var name = ident.name.asTermName
val paramss =
if Feature.clauseInterleavingEnabled(using in.languageImportContext) then
if sourceVersion.enablesClauseInterleaving then
typeOrTermParamClauses(ParamOwner.Def, numLeadParams)
else
val tparams = typeParamClauseOpt(ParamOwner.Def)
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import scala.collection.mutable
import scala.collection.immutable.SortedMap
import rewrites.Rewrites.patch
import config.Feature
import config.Feature.{migrateTo3, fewerBracesEnabled}
import config.Feature.migrateTo3
import config.SourceVersion.{`3.0`, `3.0-migration`}
import config.MigrationVersion
import reporting.{NoProfile, Profile, Message}
Expand Down Expand Up @@ -663,7 +663,7 @@ object Scanners {
if token == COLONop && inTemplate then
report.deprecationWarning(em"`:` after symbolic operator is deprecated; use backticks around operator instead", sourcePos(offset))
true
else token == COLONfollow && (inTemplate || fewerBracesEnabled)
else token == COLONfollow && (inTemplate || sourceVersion.enablesFewerBraces)
if enabled then
peekAhead()
val atEOL = isAfterLineEnd || token == EOF
Expand Down
4 changes: 1 addition & 3 deletions tests/pos/interleavingExperimental.scala
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can actually drop this test, it's purpose was to check that we require the import when the source is < 3.6

Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//> using options --source 3.5

import scala.language.experimental.clauseInterleaving
//> using options --source 3.6

def ba[A](x: A)[B](using B): B = summon[B]
Loading