Skip to content

Commit 09bfd11

Browse files
authored
Merge pull request #9055 from dotty-staging/drop-old-whitebox
Drop old whitebox macro syntax
2 parents 0540e5e + 677830f commit 09bfd11

File tree

17 files changed

+47
-67
lines changed

17 files changed

+47
-67
lines changed

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

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ object Parsers {
3636

3737
import ast.untpd._
3838

39-
val AllowOldWhiteboxSyntax = true
40-
4139
case class OpInfo(operand: Tree, operator: Ident, offset: Offset)
4240

4341
class ParensCounters {
@@ -1822,16 +1820,9 @@ object Parsers {
18221820
Nil
18231821
}
18241822

1825-
def typedOpt(): Tree = {
1826-
if (in.token == COLONEOL) in.token = COLON
1827-
// a hack to allow
1828-
//
1829-
// def f():
1830-
// T
1831-
//
1823+
def typedOpt(): Tree =
18321824
if (in.token == COLON) { in.nextToken(); toplevelTyp() }
18331825
else TypeTree().withSpan(Span(in.lastOffset))
1834-
}
18351826

18361827
def typeDependingOn(location: Location): Tree =
18371828
if location.inParens then typ()
@@ -3266,7 +3257,7 @@ object Parsers {
32663257
}
32673258
}
32683259

3269-
/** DefDef ::= DefSig [(‘:’ | ‘<:’) Type] ‘=’ Expr
3260+
/** DefDef ::= DefSig [‘:’ Type] ‘=’ Expr
32703261
* | this ParamClause ParamClauses `=' ConstrExpr
32713262
* DefDcl ::= DefSig `:' Type
32723263
* DefSig ::= id [DefTypeParamClause] DefParamClauses
@@ -3342,12 +3333,13 @@ object Parsers {
33423333
case rparamss =>
33433334
leadingVparamss ::: rparamss
33443335
var tpt = fromWithinReturnType {
3345-
if in.token == SUBTYPE && mods.is(Inline) && AllowOldWhiteboxSyntax then
3346-
deprecationWarning("`<:` return type will no longer be supported. Use transparent modifier instead.")
3347-
in.nextToken()
3348-
mods1 = addMod(mods1, Mod.Transparent())
3349-
toplevelTyp()
3350-
else typedOpt()
3336+
if in.token == COLONEOL then in.token = COLON
3337+
// a hack to allow
3338+
//
3339+
// def f():
3340+
// T
3341+
//
3342+
typedOpt()
33513343
}
33523344
if (migrateTo3) newLineOptWhenFollowedBy(LBRACE)
33533345
val rhs =
@@ -3581,7 +3573,7 @@ object Parsers {
35813573
syntaxError(i"extension clause can only define methods", stat.span)
35823574
}
35833575

3584-
/** GivenDef ::= [GivenSig] [‘_’ ‘<:’] Type ‘=’ Expr
3576+
/** GivenDef ::= [GivenSig] Type ‘=’ Expr
35853577
* | [GivenSig] ConstrApps [TemplateBody]
35863578
* GivenSig ::= [id] [DefTypeParamClause] {UsingParamClauses} ‘as’
35873579
*/
@@ -3601,30 +3593,19 @@ object Parsers {
36013593
newLinesOpt()
36023594
if isIdent(nme.as) || !name.isEmpty || !tparams.isEmpty || !vparamss.isEmpty then
36033595
accept(nme.as)
3604-
def givenAlias(tpt: Tree) =
3596+
val parents = constrApps(commaOK = true, templateCanFollow = true)
3597+
if in.token == EQUALS && parents.length == 1 && parents.head.isType then
36053598
accept(EQUALS)
36063599
mods1 |= Final
3607-
DefDef(name, tparams, vparamss, tpt, subExpr())
3608-
if in.token == USCORE && AllowOldWhiteboxSyntax then
3609-
deprecationWarning("`<:` return type will no longer be supported. Use transparent modifier instead.")
3610-
if !mods.is(Inline) then
3611-
syntaxError("`_ <:` is only allowed for given with `inline` modifier")
3612-
in.nextToken()
3613-
accept(SUBTYPE)
3614-
mods1 = addMod(mods1, Mod.Transparent())
3615-
givenAlias(toplevelTyp())
3600+
DefDef(name, tparams, vparamss, parents.head, subExpr())
36163601
else
3617-
val parents = constrApps(commaOK = true, templateCanFollow = true)
3618-
if in.token == EQUALS && parents.length == 1 && parents.head.isType then
3619-
givenAlias(parents.head)
3620-
else
3621-
possibleTemplateStart()
3622-
val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal))
3623-
val vparamss1 = vparamss.map(_.map(vparam =>
3624-
vparam.withMods(vparam.mods &~ Param | ParamAccessor | Protected)))
3625-
val templ = templateBodyOpt(makeConstructor(tparams1, vparamss1), parents, Nil)
3626-
if tparams.isEmpty && vparamss.isEmpty then ModuleDef(name, templ)
3627-
else TypeDef(name.toTypeName, templ)
3602+
possibleTemplateStart()
3603+
val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal))
3604+
val vparamss1 = vparamss.map(_.map(vparam =>
3605+
vparam.withMods(vparam.mods &~ Param | ParamAccessor | Protected)))
3606+
val templ = templateBodyOpt(makeConstructor(tparams1, vparamss1), parents, Nil)
3607+
if tparams.isEmpty && vparamss.isEmpty then ModuleDef(name, templ)
3608+
else TypeDef(name.toTypeName, templ)
36283609
end gdef
36293610
finalizeDef(gdef, mods1, start)
36303611
}

docs/docs/internals/syntax.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ WithType ::= AnnotType {‘with’ AnnotType}
156156
AnnotType ::= SimpleType {Annotation} Annotated(t, annot)
157157
158158
SimpleType ::= SimpleLiteral SingletonTypeTree(l)
159-
| ‘?’ SubtypeBounds
159+
| ‘?’ TypeBounds
160160
| SimpleType1 { ‘(’ Singletons ‘)’ }
161161
SimpleType1 ::= id Ident(name)
162162
| Singleton ‘.’ id Select(t, name)
@@ -181,8 +181,8 @@ TypeArgs ::= ‘[’ ArgTypes ‘]’
181181
NamedTypeArg ::= id ‘=’ Type NamedArg(id, t)
182182
NamedTypeArgs ::= ‘[’ NamedTypeArg {‘,’ NamedTypeArg} ‘]’ nts
183183
Refinement ::= ‘{’ [RefineDcl] {semi [RefineDcl]} ‘}’ ds
184-
SubtypeBounds ::= [‘>:’ Type] [‘<:’ Type] | INT TypeBoundsTree(lo, hi)
185-
TypeParamBounds ::= SubtypeBounds {‘:’ Type} ContextBounds(typeBounds, tps)
184+
TypeBounds ::= [‘>:’ Type] [‘<:’ Type] TypeBoundsTree(lo, hi)
185+
TypeParamBounds ::= TypeBounds {‘:’ Type} ContextBounds(typeBounds, tps)
186186
Types ::= Type {‘,’ Type}
187187
```
188188

@@ -299,11 +299,11 @@ DefTypeParamClause::= ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’
299299
DefTypeParam ::= {Annotation} id [HkTypeParamClause] TypeParamBounds
300300
301301
TypTypeParamClause::= ‘[’ TypTypeParam {‘,’ TypTypeParam} ‘]’
302-
TypTypeParam ::= {Annotation} id [HkTypeParamClause] SubtypeBounds
302+
TypTypeParam ::= {Annotation} id [HkTypeParamClause] TypeBounds
303303
304304
HkTypeParamClause ::= ‘[’ HkTypeParam {‘,’ HkTypeParam} ‘]’
305305
HkTypeParam ::= {Annotation} [‘+’ | ‘-’] (id [HkTypeParamClause] | ‘_’)
306-
SubtypeBounds
306+
TypeBounds
307307
308308
ClsParamClauses ::= {ClsParamClause} [[nl] ‘(’ [‘implicit’] ClsParams ‘)’]
309309
ClsParamClause ::= [nl] ‘(’ ClsParams ‘)’
@@ -372,7 +372,7 @@ VarDcl ::= ids ‘:’ Type
372372
DefDcl ::= DefSig ‘:’ Type DefDef(_, name, tparams, vparamss, tpe, EmptyTree)
373373
DefSig ::= id [DefTypeParamClause] DefParamClauses
374374
| ExtParamClause {nl} [‘.’] id DefParamClauses
375-
TypeDcl ::= id [TypeParamClause] {FunParamClause} SubtypeBounds TypeDefTree(_, name, tparams, bound
375+
TypeDcl ::= id [TypeParamClause] {FunParamClause} TypeBounds TypeDefTree(_, name, tparams, bound
376376
[‘=’ Type]
377377
378378
Def ::= ‘val’ PatDef
@@ -385,7 +385,7 @@ PatDef ::= ids [‘:’ Type] ‘=’ Expr
385385
| Pattern2 [‘:’ Type | Ascription] ‘=’ Expr PatDef(_, pats, tpe?, expr)
386386
VarDef ::= PatDef
387387
| ids ‘:’ Type ‘=’ ‘_’
388-
DefDef ::= DefSig [(‘:’ | ‘<:’) Type] ‘=’ Expr DefDef(_, name, tparams, vparamss, tpe, expr)
388+
DefDef ::= DefSig [‘:’ Type] ‘=’ Expr DefDef(_, name, tparams, vparamss, tpe, expr)
389389
| ‘this’ DefParamClause DefParamClauses ‘=’ ConstrExpr DefDef(_, <init>, Nil, vparamss, EmptyTree, expr | Block)
390390
391391
TmplDef ::= ([‘case’] ‘class’ | ‘trait’) ClassDef
@@ -398,7 +398,7 @@ ClassConstr ::= [ClsTypeParamClause] [ConstrMods] ClsParamClauses
398398
ConstrMods ::= {Annotation} [AccessModifier]
399399
ObjectDef ::= id [Template] ModuleDef(mods, name, template) // no constructor
400400
EnumDef ::= id ClassConstr InheritClauses EnumBody EnumDef(mods, name, tparams, template)
401-
GivenDef ::= [GivenSig] [‘_’ ‘<:’] Type ‘=’ Expr
401+
GivenDef ::= [GivenSig] Type ‘=’ Expr
402402
| [GivenSig] ConstrApps [TemplateBody]
403403
GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘as’
404404
ExtensionDef ::= [id] [‘on’ ExtParamClause {UsingParamClause}]

tests/invalid/run/typelevel-patmat.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ object Test extends App {
7878
val e1 = nth(r2, 1)
7979
val ce1: String = e1
8080

81-
inline def concatTyped(xs: HList, ys: HList) <: Typed[_ <: HList] = inline xs match {
81+
transparent inline def concatTyped(xs: HList, ys: HList): Typed[_ <: HList] = inline xs match {
8282
case HNil => Typed(ys)
8383
case HCons(x, xs1) => Typed(HCons(x, concatTyped(xs1, ys).value))
8484
}
8585

86-
def concatImpl(xs: HList, ys: HList) <: HList = xs match {
86+
transparent def concatImpl(xs: HList, ys: HList): HList = xs match {
8787
case HNil => ys
8888
case HCons(x, xs1) => HCons(x, concatImpl(xs1, ys))
8989
}

tests/neg-custom-args/erased/erased-machine-state-encoding-with-inline.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ final class On extends State
55
final class Off extends State
66

77
class Machine[S <: State] {
8-
inline def turnOn() <: Machine[On] = inline erasedValue[S] match {
8+
transparent inline def turnOn(): Machine[On] = inline erasedValue[S] match {
99
case _: Off => new Machine[On]
1010
case _: On => error("Turning on an already turned on machine")
1111
}
12-
inline def turnOff() <: Machine[Off] = inline erasedValue[S] match {
12+
transparent inline def turnOff(): Machine[Off] = inline erasedValue[S] match {
1313
case _: On => new Machine[Off]
1414
case _: Off => error("Turning off an already turned off machine")
1515
}

tests/neg/i7078.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
trait A
22
class B extends A
33

4-
given g1 as _ <: A = B() // error: `_ <:' is only allowed for given with `inline' modifier
4+
transparent given g1 as A = B() // error: `transparent` can only be used in conjunction with `inline`
55

66
inline given g2 as _ <: A: // error: `=' expected
77
def foo = 2
8-
// error

tests/neg/machine-state-encoding-with-implicit-match.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ object IsOn {
1818
}
1919

2020
class Machine[S <: State] {
21-
inline def turnOn()(using s: IsOff[S]) <: Machine[On] = summonFrom {
21+
transparent inline def turnOn()(using s: IsOff[S]): Machine[On] = summonFrom {
2222
case _: IsOff[Off] => new Machine[On]
2323
}
24-
inline def turnOff()(using s: IsOn[S]) <: Machine[Off] = summonFrom {
24+
transparent inline def turnOff()(using s: IsOn[S]): Machine[Off] = summonFrom {
2525
case _: IsOn[On] => new Machine[Off]
2626
}
2727
}

tests/pos-macros/tasty-constant-type/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ object Macro {
44

55
trait AddInt[A <: Int, B <: Int] { type Out <: Int }
66

7-
inline def ff[A <: Int, B <: Int]() <: AddInt[A, B] = ${ impl('[A], '[B]) }
7+
transparent inline def ff[A <: Int, B <: Int](): AddInt[A, B] = ${ impl('[A], '[B]) }
88

99
def impl[A <: Int : Type, B <: Int : Type](a: Type[A], b: Type[B])(using qctx: QuoteContext) : Expr[AddInt[A, B]] = {
1010
import qctx.tasty._

tests/pos/i5572.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
trait Foo {
22
type Id[t] = t
3-
inline def foo[T](t: T) <: Id[T] =
3+
transparent inline def foo[T](t: T): Id[T] =
44
inline t match {
55
case i: Int => (i+1).asInstanceOf[Id[T]]
66
case _ => t

tests/pos/implicit-match-nested.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object `implicit-match-nested` {
88
implicit val b1: B[Int] = B[Int]()
99
implicit val b2: B[String] = B[String]()
1010

11-
inline def locateB <: B[_] =
11+
transparent inline def locateB: B[_] =
1212
summonFrom {
1313
case _: A[t] =>
1414
summonFrom {

tests/pos/inline-match-specialize.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
object `inline-match-specialize` {
22
case class Box[+T](value: T)
3-
inline def specialize[T](box: Box[T]) <: Box[T] = inline box match {
3+
transparent inline def specialize[T](box: Box[T]): Box[T] = inline box match {
44
case box: Box[t] => box
55
}
66

tests/pos/inline-named-typeargs.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// Working version of inline-named-typedargs, the original is currently disabled
22
object t1 {
3-
inline def construct[Elem, Coll[_]](xs: List[Elem]) <: Coll[Elem] = ???
3+
transparent inline def construct[Elem, Coll[_]](xs: List[Elem]): Coll[Elem] = ???
44
}

tests/pos/reference/compile-time.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Test:
1414

1515
final val ctwo = toIntC[2]
1616

17-
inline def defaultValue[T] <: Option[Any] = inline erasedValue[T] match
17+
transparent inline def defaultValue[T]: Option[Any] = inline erasedValue[T] match
1818
case _: Byte => Some(0: Byte)
1919
case _: Char => Some(0: Char)
2020
case _: Short => Some(0: Short)

tests/pos/reference/delegate-match.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Test extends App:
44
import scala.collection.immutable.{TreeSet, HashSet}
55
import scala.compiletime.summonFrom
66

7-
inline def setFor[T] <: Set[T] = summonFrom {
7+
transparent inline def setFor[T]: Set[T] = summonFrom {
88
case given ord: Ordering[T] => new TreeSet[T]
99
case _ => new HashSet[T]
1010
}

tests/run-custom-args/typeclass-derivation2c.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ object Lst {
8888
case Nil => 1
8989
}
9090
inline override def numberOfCases = 2
91-
inline override def alternative(n: Int) <: Generic[_ <: Lst[T]] =
91+
transparent inline override def alternative(n: Int): Generic[_ <: Lst[T]] =
9292
inline n match {
9393
case 0 => Cons.GenericCons[T]
9494
case 1 => Nil.GenericNil
@@ -153,7 +153,7 @@ object Either {
153153
case x: Right[_] => 1
154154
}
155155
inline override def numberOfCases = 2
156-
inline override def alternative(n: Int) <: Generic[_ <: Either[L, R]] =
156+
inline override def alternative(n: Int): _ <: Generic[_ <: Either[L, R]] =
157157
inline n match {
158158
case 0 => Left.GenericLeft[L]
159159
case 1 => Right.GenericRight[R]

tests/run-macros/xml-interpolation-5/Macros_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ object XmlQuote {
1919
opaque type StringContext = scala.StringContext
2020
def apply(sc: scala.StringContext): StringContext = sc
2121
}
22-
inline def (inline ctx: StringContext).xml <: SCOps.StringContext = SCOps(ctx)
22+
transparent inline def (inline ctx: StringContext).xml: SCOps.StringContext = SCOps(ctx)
2323
inline def (inline ctx: SCOps.StringContext).apply(inline args: Any*): Xml =
2424
${XmlQuote.impl('ctx, 'args)}
2525
// inline def (inline ctx: SCOps.StringContext).unapplySeq(...): Xml = ...

tests/run/typeclass-derivation2b.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ object Lst {
4949
case x: Cons[_] => 0
5050
case Nil => 1
5151
}
52-
inline def alternative(inline n: Int) <: GenericProduct[_ <: Lst[T]] =
52+
transparent inline def alternative(inline n: Int): GenericProduct[_ <: Lst[T]] =
5353
inline n match {
5454
case 0 => Cons.GenericCons[T]
5555
case 1 => Nil.GenericNil

0 commit comments

Comments
 (0)