Skip to content

Commit e1aa2c7

Browse files
committed
Drop old whitebox macro syntax
Standardize on transparent
1 parent 7934cc9 commit e1aa2c7

File tree

16 files changed

+46
-66
lines changed

16 files changed

+46
-66
lines changed

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

+20-39
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 {
@@ -1774,16 +1772,9 @@ object Parsers {
17741772
Nil
17751773
}
17761774

1777-
def typedOpt(): Tree = {
1778-
if (in.token == COLONEOL) in.token = COLON
1779-
// a hack to allow
1780-
//
1781-
// def f():
1782-
// T
1783-
//
1775+
def typedOpt(): Tree =
17841776
if (in.token == COLON) { in.nextToken(); toplevelTyp() }
17851777
else TypeTree().withSpan(Span(in.lastOffset))
1786-
}
17871778

17881779
def typeDependingOn(location: Location): Tree =
17891780
if location.inParens then typ()
@@ -3218,7 +3209,7 @@ object Parsers {
32183209
}
32193210
}
32203211

3221-
/** DefDef ::= DefSig [(‘:’ | ‘<:’) Type] ‘=’ Expr
3212+
/** DefDef ::= DefSig [‘:’ Type] ‘=’ Expr
32223213
* | this ParamClause ParamClauses `=' ConstrExpr
32233214
* DefDcl ::= DefSig `:' Type
32243215
* DefSig ::= id [DefTypeParamClause] DefParamClauses
@@ -3294,12 +3285,13 @@ object Parsers {
32943285
case rparamss =>
32953286
leadingVparamss ::: rparamss
32963287
var tpt = fromWithinReturnType {
3297-
if in.token == SUBTYPE && mods.is(Inline) && AllowOldWhiteboxSyntax then
3298-
deprecationWarning("`<:` return type will no longer be supported. Use transparent modifier instead.")
3299-
in.nextToken()
3300-
mods1 = addMod(mods1, Mod.Transparent())
3301-
toplevelTyp()
3302-
else typedOpt()
3288+
if in.token == COLONEOL then in.token = COLON
3289+
// a hack to allow
3290+
//
3291+
// def f():
3292+
// T
3293+
//
3294+
typedOpt()
33033295
}
33043296
if (migrateTo3) newLineOptWhenFollowedBy(LBRACE)
33053297
val rhs =
@@ -3532,7 +3524,7 @@ object Parsers {
35323524
syntaxError(i"extension clause can only define methods", stat.span)
35333525
}
35343526

3535-
/** GivenDef ::= [GivenSig] [‘_’ ‘<:’] Type ‘=’ Expr
3527+
/** GivenDef ::= [GivenSig] Type ‘=’ Expr
35363528
* | [GivenSig] ConstrApps [TemplateBody]
35373529
* GivenSig ::= [id] [DefTypeParamClause] {UsingParamClauses} ‘as’
35383530
*/
@@ -3552,30 +3544,19 @@ object Parsers {
35523544
newLinesOpt()
35533545
if isIdent(nme.as) || !name.isEmpty || !tparams.isEmpty || !vparamss.isEmpty then
35543546
accept(nme.as)
3555-
def givenAlias(tpt: Tree) =
3547+
val parents = constrApps(commaOK = true, templateCanFollow = true)
3548+
if in.token == EQUALS && parents.length == 1 && parents.head.isType then
35563549
accept(EQUALS)
35573550
mods1 |= Final
3558-
DefDef(name, tparams, vparamss, tpt, subExpr())
3559-
if in.token == USCORE && AllowOldWhiteboxSyntax then
3560-
deprecationWarning("`<:` return type will no longer be supported. Use transparent modifier instead.")
3561-
if !mods.is(Inline) then
3562-
syntaxError("`_ <:` is only allowed for given with `inline` modifier")
3563-
in.nextToken()
3564-
accept(SUBTYPE)
3565-
mods1 = addMod(mods1, Mod.Transparent())
3566-
givenAlias(toplevelTyp())
3551+
DefDef(name, tparams, vparamss, parents.head, subExpr())
35673552
else
3568-
val parents = constrApps(commaOK = true, templateCanFollow = true)
3569-
if in.token == EQUALS && parents.length == 1 && parents.head.isType then
3570-
givenAlias(parents.head)
3571-
else
3572-
possibleTemplateStart()
3573-
val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal))
3574-
val vparamss1 = vparamss.map(_.map(vparam =>
3575-
vparam.withMods(vparam.mods &~ Param | ParamAccessor | Protected)))
3576-
val templ = templateBodyOpt(makeConstructor(tparams1, vparamss1), parents, Nil)
3577-
if tparams.isEmpty && vparamss.isEmpty then ModuleDef(name, templ)
3578-
else TypeDef(name.toTypeName, templ)
3553+
possibleTemplateStart()
3554+
val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal))
3555+
val vparamss1 = vparamss.map(_.map(vparam =>
3556+
vparam.withMods(vparam.mods &~ Param | ParamAccessor | Protected)))
3557+
val templ = templateBodyOpt(makeConstructor(tparams1, vparamss1), parents, Nil)
3558+
if tparams.isEmpty && vparamss.isEmpty then ModuleDef(name, templ)
3559+
else TypeDef(name.toTypeName, templ)
35793560
end gdef
35803561
finalizeDef(gdef, mods1, start)
35813562
}

docs/docs/internals/syntax.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ WithType ::= AnnotType {‘with’ AnnotType}
154154
AnnotType ::= SimpleType {Annotation} Annotated(t, annot)
155155
156156
SimpleType ::= SimpleLiteral SingletonTypeTree(l)
157-
| ‘?’ SubtypeBounds
157+
| ‘?’ TypeBounds
158158
| SimpleType ‘(’ Singletons ‘)’
159159
| SimpleType1
160160
SimpleType1 ::= id Ident(name)
@@ -179,8 +179,8 @@ TypeArgs ::= ‘[’ ArgTypes ‘]’
179179
NamedTypeArg ::= id ‘=’ Type NamedArg(id, t)
180180
NamedTypeArgs ::= ‘[’ NamedTypeArg {‘,’ NamedTypeArg} ‘]’ nts
181181
Refinement ::= ‘{’ [RefineDcl] {semi [RefineDcl]} ‘}’ ds
182-
SubtypeBounds ::= [‘>:’ Type] [‘<:’ Type] | INT TypeBoundsTree(lo, hi)
183-
TypeParamBounds ::= SubtypeBounds {‘:’ Type} ContextBounds(typeBounds, tps)
182+
TypeBounds ::= [‘>:’ Type] [‘<:’ Type] TypeBoundsTree(lo, hi)
183+
TypeParamBounds ::= TypeBounds {‘:’ Type} ContextBounds(typeBounds, tps)
184184
Types ::= Type {‘,’ Type}
185185
```
186186

@@ -297,11 +297,11 @@ DefTypeParamClause::= ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’
297297
DefTypeParam ::= {Annotation} id [HkTypeParamClause] TypeParamBounds
298298
299299
TypTypeParamClause::= ‘[’ TypTypeParam {‘,’ TypTypeParam} ‘]’
300-
TypTypeParam ::= {Annotation} id [HkTypeParamClause] SubtypeBounds
300+
TypTypeParam ::= {Annotation} id [HkTypeParamClause] TypeBounds
301301
302302
HkTypeParamClause ::= ‘[’ HkTypeParam {‘,’ HkTypeParam} ‘]’
303303
HkTypeParam ::= {Annotation} [‘+’ | ‘-’] (id [HkTypeParamClause] | ‘_’)
304-
SubtypeBounds
304+
TypeBounds
305305
306306
ClsParamClauses ::= {ClsParamClause} [[nl] ‘(’ [‘implicit’] ClsParams ‘)’]
307307
ClsParamClause ::= [nl] ‘(’ ClsParams ‘)’
@@ -370,7 +370,7 @@ VarDcl ::= ids ‘:’ Type
370370
DefDcl ::= DefSig ‘:’ Type DefDef(_, name, tparams, vparamss, tpe, EmptyTree)
371371
DefSig ::= id [DefTypeParamClause] DefParamClauses
372372
| ExtParamClause {nl} [‘.’] id DefParamClauses
373-
TypeDcl ::= id [TypeParamClause] SubtypeBounds [‘=’ Type] TypeDefTree(_, name, tparams, bound
373+
TypeDcl ::= id [TypeParamClause] TypeBounds [‘=’ Type] TypeDefTree(_, name, tparams, bound
374374
375375
Def ::= ‘val’ PatDef
376376
| ‘var’ VarDef
@@ -382,7 +382,7 @@ PatDef ::= ids [‘:’ Type] ‘=’ Expr
382382
| Pattern2 [‘:’ Type | Ascription] ‘=’ Expr PatDef(_, pats, tpe?, expr)
383383
VarDef ::= PatDef
384384
| ids ‘:’ Type ‘=’ ‘_’
385-
DefDef ::= DefSig [(‘:’ | ‘<:’) Type] ‘=’ Expr DefDef(_, name, tparams, vparamss, tpe, expr)
385+
DefDef ::= DefSig [‘:’ Type] ‘=’ Expr DefDef(_, name, tparams, vparamss, tpe, expr)
386386
| ‘this’ DefParamClause DefParamClauses ‘=’ ConstrExpr DefDef(_, <init>, Nil, vparamss, EmptyTree, expr | Block)
387387
388388
TmplDef ::= ([‘case’] ‘class’ | ‘trait’) ClassDef
@@ -395,7 +395,7 @@ ClassConstr ::= [ClsTypeParamClause] [ConstrMods] ClsParamClauses
395395
ConstrMods ::= {Annotation} [AccessModifier]
396396
ObjectDef ::= id [Template] ModuleDef(mods, name, template) // no constructor
397397
EnumDef ::= id ClassConstr InheritClauses EnumBody EnumDef(mods, name, tparams, template)
398-
GivenDef ::= [GivenSig] [‘_’ ‘<:’] Type ‘=’ Expr
398+
GivenDef ::= [GivenSig] Type ‘=’ Expr
399399
| [GivenSig] ConstrApps [TemplateBody]
400400
GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘as’
401401
ExtensionDef ::= [id] [‘on’ ExtParamClause {UsingParamClause}]

tests/invalid/run/typelevel-patmat.scala

+2-2
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

+2-2
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

+1-2
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

+2-2
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+2-2
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

+1-1
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

+1-1
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)