Skip to content

Drop old whitebox macro syntax #9055

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

Merged
merged 3 commits into from
May 29, 2020
Merged
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
59 changes: 20 additions & 39 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ object Parsers {

import ast.untpd._

val AllowOldWhiteboxSyntax = true

case class OpInfo(operand: Tree, operator: Ident, offset: Offset)

class ParensCounters {
Expand Down Expand Up @@ -1822,16 +1820,9 @@ object Parsers {
Nil
}

def typedOpt(): Tree = {
if (in.token == COLONEOL) in.token = COLON
// a hack to allow
//
// def f():
// T
//
def typedOpt(): Tree =
if (in.token == COLON) { in.nextToken(); toplevelTyp() }
else TypeTree().withSpan(Span(in.lastOffset))
}

def typeDependingOn(location: Location): Tree =
if location.inParens then typ()
Expand Down Expand Up @@ -3266,7 +3257,7 @@ object Parsers {
}
}

/** DefDef ::= DefSig [(‘:’ | ‘<:’) Type] ‘=’ Expr
/** DefDef ::= DefSig [‘:’ Type] ‘=’ Expr
* | this ParamClause ParamClauses `=' ConstrExpr
* DefDcl ::= DefSig `:' Type
* DefSig ::= id [DefTypeParamClause] DefParamClauses
Expand Down Expand Up @@ -3342,12 +3333,13 @@ object Parsers {
case rparamss =>
leadingVparamss ::: rparamss
var tpt = fromWithinReturnType {
if in.token == SUBTYPE && mods.is(Inline) && AllowOldWhiteboxSyntax then
deprecationWarning("`<:` return type will no longer be supported. Use transparent modifier instead.")
in.nextToken()
mods1 = addMod(mods1, Mod.Transparent())
toplevelTyp()
else typedOpt()
if in.token == COLONEOL then in.token = COLON
// a hack to allow
//
// def f():
// T
//
typedOpt()
}
if (migrateTo3) newLineOptWhenFollowedBy(LBRACE)
val rhs =
Expand Down Expand Up @@ -3581,7 +3573,7 @@ object Parsers {
syntaxError(i"extension clause can only define methods", stat.span)
}

/** GivenDef ::= [GivenSig] [‘_’ ‘<:’] Type ‘=’ Expr
/** GivenDef ::= [GivenSig] Type ‘=’ Expr
* | [GivenSig] ConstrApps [TemplateBody]
* GivenSig ::= [id] [DefTypeParamClause] {UsingParamClauses} ‘as’
*/
Expand All @@ -3601,30 +3593,19 @@ object Parsers {
newLinesOpt()
if isIdent(nme.as) || !name.isEmpty || !tparams.isEmpty || !vparamss.isEmpty then
accept(nme.as)
def givenAlias(tpt: Tree) =
val parents = constrApps(commaOK = true, templateCanFollow = true)
if in.token == EQUALS && parents.length == 1 && parents.head.isType then
accept(EQUALS)
mods1 |= Final
DefDef(name, tparams, vparamss, tpt, subExpr())
if in.token == USCORE && AllowOldWhiteboxSyntax then
deprecationWarning("`<:` return type will no longer be supported. Use transparent modifier instead.")
if !mods.is(Inline) then
syntaxError("`_ <:` is only allowed for given with `inline` modifier")
in.nextToken()
accept(SUBTYPE)
mods1 = addMod(mods1, Mod.Transparent())
givenAlias(toplevelTyp())
DefDef(name, tparams, vparamss, parents.head, subExpr())
else
val parents = constrApps(commaOK = true, templateCanFollow = true)
if in.token == EQUALS && parents.length == 1 && parents.head.isType then
givenAlias(parents.head)
else
possibleTemplateStart()
val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal))
val vparamss1 = vparamss.map(_.map(vparam =>
vparam.withMods(vparam.mods &~ Param | ParamAccessor | Protected)))
val templ = templateBodyOpt(makeConstructor(tparams1, vparamss1), parents, Nil)
if tparams.isEmpty && vparamss.isEmpty then ModuleDef(name, templ)
else TypeDef(name.toTypeName, templ)
possibleTemplateStart()
val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal))
val vparamss1 = vparamss.map(_.map(vparam =>
vparam.withMods(vparam.mods &~ Param | ParamAccessor | Protected)))
val templ = templateBodyOpt(makeConstructor(tparams1, vparamss1), parents, Nil)
if tparams.isEmpty && vparamss.isEmpty then ModuleDef(name, templ)
else TypeDef(name.toTypeName, templ)
end gdef
finalizeDef(gdef, mods1, start)
}
Expand Down
16 changes: 8 additions & 8 deletions docs/docs/internals/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ WithType ::= AnnotType {‘with’ AnnotType}
AnnotType ::= SimpleType {Annotation} Annotated(t, annot)

SimpleType ::= SimpleLiteral SingletonTypeTree(l)
| ‘?’ SubtypeBounds
| ‘?’ TypeBounds
| SimpleType1 { ‘(’ Singletons ‘)’ }
SimpleType1 ::= id Ident(name)
| Singleton ‘.’ id Select(t, name)
Expand All @@ -181,8 +181,8 @@ TypeArgs ::= ‘[’ ArgTypes ‘]’
NamedTypeArg ::= id ‘=’ Type NamedArg(id, t)
NamedTypeArgs ::= ‘[’ NamedTypeArg {‘,’ NamedTypeArg} ‘]’ nts
Refinement ::= ‘{’ [RefineDcl] {semi [RefineDcl]} ‘}’ ds
SubtypeBounds ::= [‘>:’ Type] [‘<:’ Type] | INT TypeBoundsTree(lo, hi)
TypeParamBounds ::= SubtypeBounds {‘:’ Type} ContextBounds(typeBounds, tps)
TypeBounds ::= [‘>:’ Type] [‘<:’ Type] TypeBoundsTree(lo, hi)
TypeParamBounds ::= TypeBounds {‘:’ Type} ContextBounds(typeBounds, tps)
Types ::= Type {‘,’ Type}
```

Expand Down Expand Up @@ -299,11 +299,11 @@ DefTypeParamClause::= ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’
DefTypeParam ::= {Annotation} id [HkTypeParamClause] TypeParamBounds

TypTypeParamClause::= ‘[’ TypTypeParam {‘,’ TypTypeParam} ‘]’
TypTypeParam ::= {Annotation} id [HkTypeParamClause] SubtypeBounds
TypTypeParam ::= {Annotation} id [HkTypeParamClause] TypeBounds

HkTypeParamClause ::= ‘[’ HkTypeParam {‘,’ HkTypeParam} ‘]’
HkTypeParam ::= {Annotation} [‘+’ | ‘-’] (id [HkTypeParamClause] | ‘_’)
SubtypeBounds
TypeBounds

ClsParamClauses ::= {ClsParamClause} [[nl] ‘(’ [‘implicit’] ClsParams ‘)’]
ClsParamClause ::= [nl] ‘(’ ClsParams ‘)’
Expand Down Expand Up @@ -372,7 +372,7 @@ VarDcl ::= ids ‘:’ Type
DefDcl ::= DefSig ‘:’ Type DefDef(_, name, tparams, vparamss, tpe, EmptyTree)
DefSig ::= id [DefTypeParamClause] DefParamClauses
| ExtParamClause {nl} [‘.’] id DefParamClauses
TypeDcl ::= id [TypeParamClause] {FunParamClause} SubtypeBounds TypeDefTree(_, name, tparams, bound
TypeDcl ::= id [TypeParamClause] {FunParamClause} TypeBounds TypeDefTree(_, name, tparams, bound
[‘=’ Type]

Def ::= ‘val’ PatDef
Expand All @@ -385,7 +385,7 @@ PatDef ::= ids [‘:’ Type] ‘=’ Expr
| Pattern2 [‘:’ Type | Ascription] ‘=’ Expr PatDef(_, pats, tpe?, expr)
VarDef ::= PatDef
| ids ‘:’ Type ‘=’ ‘_’
DefDef ::= DefSig [(‘:’ | ‘<:’) Type] ‘=’ Expr DefDef(_, name, tparams, vparamss, tpe, expr)
DefDef ::= DefSig [‘:’ Type] ‘=’ Expr DefDef(_, name, tparams, vparamss, tpe, expr)
| ‘this’ DefParamClause DefParamClauses ‘=’ ConstrExpr DefDef(_, <init>, Nil, vparamss, EmptyTree, expr | Block)

TmplDef ::= ([‘case’] ‘class’ | ‘trait’) ClassDef
Expand All @@ -398,7 +398,7 @@ ClassConstr ::= [ClsTypeParamClause] [ConstrMods] ClsParamClauses
ConstrMods ::= {Annotation} [AccessModifier]
ObjectDef ::= id [Template] ModuleDef(mods, name, template) // no constructor
EnumDef ::= id ClassConstr InheritClauses EnumBody EnumDef(mods, name, tparams, template)
GivenDef ::= [GivenSig] [‘_’ ‘<:’] Type ‘=’ Expr
GivenDef ::= [GivenSig] Type ‘=’ Expr
| [GivenSig] ConstrApps [TemplateBody]
GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘as’
ExtensionDef ::= [id] [‘on’ ExtParamClause {UsingParamClause}]
Expand Down
4 changes: 2 additions & 2 deletions tests/invalid/run/typelevel-patmat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ object Test extends App {
val e1 = nth(r2, 1)
val ce1: String = e1

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

def concatImpl(xs: HList, ys: HList) <: HList = xs match {
transparent def concatImpl(xs: HList, ys: HList): HList = xs match {
case HNil => ys
case HCons(x, xs1) => HCons(x, concatImpl(xs1, ys))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ final class On extends State
final class Off extends State

class Machine[S <: State] {
inline def turnOn() <: Machine[On] = inline erasedValue[S] match {
transparent inline def turnOn(): Machine[On] = inline erasedValue[S] match {
case _: Off => new Machine[On]
case _: On => error("Turning on an already turned on machine")
}
inline def turnOff() <: Machine[Off] = inline erasedValue[S] match {
transparent inline def turnOff(): Machine[Off] = inline erasedValue[S] match {
case _: On => new Machine[Off]
case _: Off => error("Turning off an already turned off machine")
}
Expand Down
3 changes: 1 addition & 2 deletions tests/neg/i7078.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
trait A
class B extends A

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

inline given g2 as _ <: A: // error: `=' expected
def foo = 2
// error
4 changes: 2 additions & 2 deletions tests/neg/machine-state-encoding-with-implicit-match.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ object IsOn {
}

class Machine[S <: State] {
inline def turnOn()(using s: IsOff[S]) <: Machine[On] = summonFrom {
transparent inline def turnOn()(using s: IsOff[S]): Machine[On] = summonFrom {
case _: IsOff[Off] => new Machine[On]
}
inline def turnOff()(using s: IsOn[S]) <: Machine[Off] = summonFrom {
transparent inline def turnOff()(using s: IsOn[S]): Machine[Off] = summonFrom {
case _: IsOn[On] => new Machine[Off]
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/pos-macros/tasty-constant-type/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ object Macro {

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

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

def impl[A <: Int : Type, B <: Int : Type](a: Type[A], b: Type[B])(using qctx: QuoteContext) : Expr[AddInt[A, B]] = {
import qctx.tasty._
Expand Down
2 changes: 1 addition & 1 deletion tests/pos/i5572.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
trait Foo {
type Id[t] = t
inline def foo[T](t: T) <: Id[T] =
transparent inline def foo[T](t: T): Id[T] =
inline t match {
case i: Int => (i+1).asInstanceOf[Id[T]]
case _ => t
Expand Down
2 changes: 1 addition & 1 deletion tests/pos/implicit-match-nested.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ object `implicit-match-nested` {
implicit val b1: B[Int] = B[Int]()
implicit val b2: B[String] = B[String]()

inline def locateB <: B[_] =
transparent inline def locateB: B[_] =
summonFrom {
case _: A[t] =>
summonFrom {
Expand Down
2 changes: 1 addition & 1 deletion tests/pos/inline-match-specialize.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
object `inline-match-specialize` {
case class Box[+T](value: T)
inline def specialize[T](box: Box[T]) <: Box[T] = inline box match {
transparent inline def specialize[T](box: Box[T]): Box[T] = inline box match {
case box: Box[t] => box
}

Expand Down
2 changes: 1 addition & 1 deletion tests/pos/inline-named-typeargs.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Working version of inline-named-typedargs, the original is currently disabled
object t1 {
inline def construct[Elem, Coll[_]](xs: List[Elem]) <: Coll[Elem] = ???
transparent inline def construct[Elem, Coll[_]](xs: List[Elem]): Coll[Elem] = ???
}
2 changes: 1 addition & 1 deletion tests/pos/reference/compile-time.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Test:

final val ctwo = toIntC[2]

inline def defaultValue[T] <: Option[Any] = inline erasedValue[T] match
transparent inline def defaultValue[T]: Option[Any] = inline erasedValue[T] match
case _: Byte => Some(0: Byte)
case _: Char => Some(0: Char)
case _: Short => Some(0: Short)
Expand Down
2 changes: 1 addition & 1 deletion tests/pos/reference/delegate-match.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Test extends App:
import scala.collection.immutable.{TreeSet, HashSet}
import scala.compiletime.summonFrom

inline def setFor[T] <: Set[T] = summonFrom {
transparent inline def setFor[T]: Set[T] = summonFrom {
case given ord: Ordering[T] => new TreeSet[T]
case _ => new HashSet[T]
}
Expand Down
4 changes: 2 additions & 2 deletions tests/run-custom-args/typeclass-derivation2c.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ object Lst {
case Nil => 1
}
inline override def numberOfCases = 2
inline override def alternative(n: Int) <: Generic[_ <: Lst[T]] =
transparent inline override def alternative(n: Int): Generic[_ <: Lst[T]] =
inline n match {
case 0 => Cons.GenericCons[T]
case 1 => Nil.GenericNil
Expand Down Expand Up @@ -153,7 +153,7 @@ object Either {
case x: Right[_] => 1
}
inline override def numberOfCases = 2
inline override def alternative(n: Int) <: Generic[_ <: Either[L, R]] =
inline override def alternative(n: Int): _ <: Generic[_ <: Either[L, R]] =
inline n match {
case 0 => Left.GenericLeft[L]
case 1 => Right.GenericRight[R]
Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/xml-interpolation-5/Macros_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object XmlQuote {
opaque type StringContext = scala.StringContext
def apply(sc: scala.StringContext): StringContext = sc
}
inline def (inline ctx: StringContext).xml <: SCOps.StringContext = SCOps(ctx)
transparent inline def (inline ctx: StringContext).xml: SCOps.StringContext = SCOps(ctx)
inline def (inline ctx: SCOps.StringContext).apply(inline args: Any*): Xml =
${XmlQuote.impl('ctx, 'args)}
// inline def (inline ctx: SCOps.StringContext).unapplySeq(...): Xml = ...
Expand Down
2 changes: 1 addition & 1 deletion tests/run/typeclass-derivation2b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ object Lst {
case x: Cons[_] => 0
case Nil => 1
}
inline def alternative(inline n: Int) <: GenericProduct[_ <: Lst[T]] =
transparent inline def alternative(inline n: Int): GenericProduct[_ <: Lst[T]] =
inline n match {
case 0 => Cons.GenericCons[T]
case 1 => Nil.GenericNil
Expand Down