Skip to content

Commit b7f3c5d

Browse files
committed
Implement SIP 64 as non-experimental
1 parent 5ec1e8b commit b7f3c5d

File tree

12 files changed

+50
-35
lines changed

12 files changed

+50
-35
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ object desugar {
12611261
str.toTermName.asSimpleName
12621262

12631263
/** Extract a synthesized given name from a type tree. This is used for
1264-
* both anonymous givens and (under x.modularity) deferred givens.
1264+
* both anonymous givens and deferred givens.
12651265
* @param followArgs if true include argument types in the name
12661266
*/
12671267
private class NameExtractor(followArgs: Boolean) extends UntypedTreeAccumulator[String] {

compiler/src/dotty/tools/dotc/ast/untpd.scala

-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
119119
case class PatDef(mods: Modifiers, pats: List[Tree], tpt: Tree, rhs: Tree)(implicit @constructorOnly src: SourceFile) extends DefTree
120120
case class ExtMethods(paramss: List[ParamClause], methods: List[Tree])(implicit @constructorOnly src: SourceFile) extends Tree
121121
case class ContextBoundTypeTree(tycon: Tree, paramName: TypeName, ownName: TermName)(implicit @constructorOnly src: SourceFile) extends Tree
122-
// `paramName: tycon as ownName`, ownName != EmptyTermName only under x.modularity
123122
case class MacroTree(expr: Tree)(implicit @constructorOnly src: SourceFile) extends Tree
124123

125124
case class ImportSelector(imported: Ident, renamed: Tree = EmptyTree, bound: Tree = EmptyTree)(implicit @constructorOnly src: SourceFile) extends Tree {

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

+8-12
Original file line numberDiff line numberDiff line change
@@ -994,8 +994,8 @@ object Parsers {
994994
skipParams()
995995
lookahead.isColon
996996
&& {
997-
!in.featureEnabled(Feature.modularity)
998-
|| { // with modularity language import, a `:` at EOL after an identifier represents a single identifier given
997+
!sourceVersion.isAtLeast(`3.6`)
998+
|| { // in the new given syntax, a `:` at EOL after an identifier represents a single identifier given
999999
// Example:
10001000
// given C:
10011001
// def f = ...
@@ -1833,7 +1833,7 @@ object Parsers {
18331833
infixOps(t, canStartInfixTypeTokens, operand, Location.ElseWhere, ParseKind.Type,
18341834
isOperator = !followingIsVararg()
18351835
&& !isPureArrow
1836-
&& !(isIdent(nme.as) && in.featureEnabled(Feature.modularity))
1836+
&& !(isIdent(nme.as) && sourceVersion.isAtLeast(`3.6`))
18371837
&& nextCanFollowOperator(canStartInfixTypeTokens))
18381838

18391839
/** RefinedType ::= WithType {[nl] Refinement} [`^` CaptureSet]
@@ -2226,18 +2226,19 @@ object Parsers {
22262226
def contextBound(pname: TypeName): Tree =
22272227
val t = toplevelTyp()
22282228
val ownName =
2229-
if isIdent(nme.as) && in.featureEnabled(Feature.modularity) then
2229+
if isIdent(nme.as) && sourceVersion.isAtLeast(`3.6`) then
22302230
in.nextToken()
22312231
ident()
22322232
else EmptyTermName
22332233
ContextBoundTypeTree(t, pname, ownName)
22342234

2235-
/** ContextBounds ::= ContextBound | `{` ContextBound {`,` ContextBound} `}`
2235+
/** ContextBounds ::= ContextBound [`:` ContextBounds]
2236+
* | `{` ContextBound {`,` ContextBound} `}`
22362237
*/
22372238
def contextBounds(pname: TypeName): List[Tree] =
22382239
if in.isColon then
22392240
in.nextToken()
2240-
if in.token == LBRACE && in.featureEnabled(Feature.modularity)
2241+
if in.token == LBRACE && sourceVersion.isAtLeast(`3.6`)
22412242
then inBraces(commaSeparated(() => contextBound(pname)))
22422243
else contextBound(pname) :: contextBounds(pname)
22432244
else if in.token == VIEWBOUND then
@@ -4189,7 +4190,7 @@ object Parsers {
41894190
def givenDef(start: Offset, mods: Modifiers, givenMod: Mod) = atSpan(start, nameStart) {
41904191
var mods1 = addMod(mods, givenMod)
41914192
val nameStart = in.offset
4192-
var newSyntaxAllowed = in.featureEnabled(Feature.modularity)
4193+
var newSyntaxAllowed = sourceVersion.isAtLeast(`3.6`)
41934194
val hasEmbeddedColon = !in.isColon && followingIsGivenDefWithColon()
41944195
val name = if isIdent && hasEmbeddedColon then ident() else EmptyTermName
41954196

@@ -4293,11 +4294,6 @@ object Parsers {
42934294
// old-style abstract given
42944295
if name.isEmpty then
42954296
syntaxError(em"Anonymous given cannot be abstract, or maybe you want to define a concrete given and are missing a `()` argument?", in.lastOffset)
4296-
if newSyntaxAllowed then
4297-
warning(
4298-
em"""This defines an abstract given, which is deprecated. Use a `deferred` given instead.
4299-
|Or, if you intend to define a concrete given, follow the type with `()` arguments.""",
4300-
in.lastOffset)
43014297
DefDef(name, adjustDefParams(joinParams(tparams, vparamss)), parents.head, EmptyTree)
43024298
else
43034299
// structural instance

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import TypeApplications.*
2424
import NameKinds.{WildcardParamName, DefaultGetterName}
2525
import util.Chars.isOperatorPart
2626
import config.{Config, Feature}
27+
import config.Feature.sourceVersion
28+
import config.SourceVersion.*
2729

2830
import dotty.tools.dotc.util.SourcePosition
2931
import dotty.tools.dotc.ast.untpd.{MemberDef, Modifiers, PackageDef, RefTree, Template, TypeDef, ValOrDefDef}
@@ -751,7 +753,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
751753
case GenAlias(pat, expr) =>
752754
toText(pat) ~ " = " ~ toText(expr)
753755
case ContextBounds(bounds, cxBounds) =>
754-
if Feature.enabled(Feature.modularity) then
756+
if sourceVersion.isAtLeast(`3.6`) then
755757
def boundsText(bounds: Tree) = bounds match
756758
case ContextBoundTypeTree(tpt, _, ownName) =>
757759
toText(tpt) ~ (" as " ~ toText(ownName) `provided` !ownName.isEmpty)

docs/_docs/internals/syntax.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,9 @@ TypeArgs ::= ‘[’ Types ‘]’
223223
Refinement ::= :<<< [RefineDcl] {semi [RefineDcl]} >>> ds
224224
TypeBounds ::= [‘>:’ Type] [‘<:’ Type] TypeBoundsTree(lo, hi)
225225
TypeAndCtxBounds ::= TypeBounds [‘:’ ContextBounds] ContextBounds(typeBounds, tps)
226-
ContextBounds ::= ContextBound | '{' ContextBound {',' ContextBound} '}'
226+
ContextBounds ::= ContextBound
227+
| ContextBound `:` ContextBounds -- to be deprecated
228+
| '{' ContextBound {',' ContextBound} '}'
227229
ContextBound ::= Type ['as' id]
228230
Types ::= Type {‘,’ Type}
229231
NamesAndTypes ::= NameAndType {‘,’ NameAndType}
@@ -464,7 +466,7 @@ TypeDef ::= id [HkTypeParamClause] {FunParamClause} TypeAndCtxBounds
464466
TmplDef ::= ([‘case’] ‘class’ | ‘trait’) ClassDef
465467
| [‘case’] ‘object’ ObjectDef
466468
| ‘enum’ EnumDef
467-
| ‘given’ GivenDef
469+
| ‘given’ (GivenDef | OldGivenDef)
468470
ClassDef ::= id ClassConstr [Template] ClassDef(mods, name, tparams, templ)
469471
ClassConstr ::= [ClsTypeParamClause] [ConstrMods] ClsParamClauses with DefDef(_, <init>, Nil, vparamss, EmptyTree, EmptyTree) as first stat
470472
ConstrMods ::= {Annotation} [AccessModifier]
@@ -483,6 +485,10 @@ GivenConditional ::= DefTypeParamClause
483485
| GivenType
484486
GivenType ::= AnnotType1 {id [nl] AnnotType1}
485487
488+
OldGivenDef ::= [OldGivenSig] (AnnotType [‘=’ Expr] | StructuralInstance) -- syntax up to Scala 3.5, to be deprecated in the future
489+
OldGivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘:’ -- one of `id`, `DefTypeParamClause`, `UsingParamClause` must be present
490+
StructuralInstance ::= ConstrApp {‘with’ ConstrApp} [‘with’ WithTemplateBody]
491+
486492
Extension ::= ‘extension’ [DefTypeParamClause] {UsingParamClause}
487493
‘(’ DefTermParam ‘)’ {UsingParamClause} ExtMethods
488494
ExtMethods ::= ExtMethod | [nl] <<< ExtMethod {semi ExtMethod} >>>

docs/_docs/reference/syntax.md

+22-5
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,11 @@ ParamValueType ::= Type [‘*’]
214214
TypeArgs ::= ‘[’ Types ‘]’
215215
Refinement ::= :<<< [RefineDcl] {semi [RefineDcl]} >>>
216216
TypeBounds ::= [‘>:’ Type] [‘<:’ Type]
217-
TypeAndCtxBounds ::= TypeBounds {‘:’ Type}
217+
TypeAndCtxBounds ::= TypeBounds [‘:’ ContextBounds]
218+
ContextBounds ::= ContextBound
219+
| ContextBound `:` ContextBounds -- to be deprecated
220+
| '{' ContextBound {',' ContextBound} '}'
221+
ContextBound ::= Type ['as' id]
218222
Types ::= Type {‘,’ Type}
219223
```
220224

@@ -437,16 +441,29 @@ TypeDef ::= id [HkTypeParamClause] {FunParamClause}TypeBounds
437441
TmplDef ::= ([‘case’] ‘class’ | ‘trait’) ClassDef
438442
| [‘case’] ‘object’ ObjectDef
439443
| ‘enum’ EnumDef
440-
| ‘given’ GivenDef
444+
| ‘given’ (GivenDef | OldGivenDef)
441445
ClassDef ::= id ClassConstr [Template]
442446
ClassConstr ::= [ClsTypeParamClause] [ConstrMods] ClsParamClauses
443447
ConstrMods ::= {Annotation} [AccessModifier]
444448
ObjectDef ::= id [Template]
445449
EnumDef ::= id ClassConstr InheritClauses EnumBody
446-
GivenDef ::= [GivenSig] (AnnotType [‘=’ Expr] | StructuralInstance)
447-
GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘:’ -- one of `id`, `DefTypeParamClause`, `UsingParamClause` must be present
448-
GivenType ::= AnnotType {id [nl] AnnotType}
450+
451+
GivenDef ::= [id ':'] GivenSig
452+
GivenSig ::= GivenImpl
453+
| '(' ')' '=>' GivenImpl
454+
| GivenConditional '=>' GivenSig
455+
GivenImpl ::= GivenType ([‘=’ Expr] | TemplateBody)
456+
| ConstrApps TemplateBody
457+
GivenConditional ::= DefTypeParamClause
458+
| DefTermParamClause
459+
| '(' FunArgTypes ')'
460+
| GivenType
461+
GivenType ::= AnnotType1 {id [nl] AnnotType1}
462+
463+
OldGivenDef ::= [OldGivenSig] (AnnotType [‘=’ Expr] | StructuralInstance) -- syntax up to Scala 3.5, to be deprecated in the future
464+
OldGivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘:’ -- one of `id`, `DefTypeParamClause`, `UsingParamClause` must be present
449465
StructuralInstance ::= ConstrApp {‘with’ ConstrApp} [‘with’ WithTemplateBody]
466+
450467
Extension ::= ‘extension’ [DefTypeParamClause] {UsingParamClause}
451468
‘(’ DefTermParam ‘)’ {UsingParamClause} ExtMethods
452469
ExtMethods ::= ExtMethod | [nl] <<< ExtMethod {semi ExtMethod} >>>

library/src/scala/compiletime/package.scala

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def uninitialized: Nothing = ???
5252
* that implement the enclosing trait and that do not contain an explicit overriding
5353
* definition of that given.
5454
*/
55-
@experimental
5655
@compileTimeOnly("`deferred` can only be used as the right hand side of a given definition in a trait")
5756
def deferred: Nothing = ???
5857

tests/neg/empty-given.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
given { // error
1+
given {
22
def foo = 1 // error
3-
} // error
3+
}

tests/neg/i12348.check

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- [E040] Syntax Error: tests/neg/i12348.scala:2:15 --------------------------------------------------------------------
1+
-- [E040] Syntax Error: tests/neg/i12348.scala:2:16 --------------------------------------------------------------------
22
2 | given inline x: Int = 0 // error
3-
| ^
4-
| 'with' expected, but identifier found
3+
| ^
4+
| an identifier expected, but ':' found

tests/run-tasty-inspector/stdlibExperimentalDefinitions.scala

-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ val experimentalDefinitionInLibrary = Set(
8383
// New feature: modularity
8484
"scala.Precise",
8585
"scala.annotation.internal.WitnessNames",
86-
"scala.compiletime.package$package$.deferred",
8786
"scala.runtime.stdLibPatches.Predef$.is",
8887

8988
// New feature: functions with erased parameters.

tests/warn/abstract-givens-new.check

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
-- Warning: tests/warn/abstract-givens-new.scala:7:22 ------------------------------------------------------------------
2-
7 | given intC: Int is C // warn
3-
| ^
4-
| This defines an abstract given, which is deprecated. Use a `deferred` given instead.
5-
| Or, if you intend to define a concrete given, follow the type with `()` arguments.
1+

tests/warn/abstract-givens-new.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class C:
44

55
trait T:
66
given Int is C // ok
7-
given intC: Int is C // warn
7+
given intC: Int is C // ok for now, will be warning
88
given intC2: (Int is C)() // ok
99
given intC3: Int is C {} // also ok
10+

0 commit comments

Comments
 (0)