Skip to content

Commit 82f76bd

Browse files
authored
Merge pull request #214 from Philippus/fix-deprecation-warnings
Fix deprecation warnings
2 parents bfe2352 + 139c342 commit 82f76bd

13 files changed

+67
-73
lines changed

src/main/scala/scala/async/internal/AnfTransform.scala

+7-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ private[async] trait AnfTransform {
6565

6666
def listToBlock(trees: List[Tree]): Block = trees match {
6767
case trees @ (init :+ last) =>
68-
val pos = trees.map(_.pos).reduceLeft(_ union _)
68+
val pos = trees.map(_.pos).reduceLeft{
69+
(p, q) =>
70+
if (!q.isRange) p
71+
else if (p.isRange) p.withStart(p.start.min(q.start)).withEnd(p.end.max(q.end))
72+
else q
73+
}
6974
newBlock(init, last).setType(last.tpe).setPos(pos)
7075
}
7176

@@ -81,7 +86,7 @@ private[async] trait AnfTransform {
8186
def statsExprUnit =
8287
stats :+ expr :+ api.typecheck(atPos(expr.pos)(Literal(Constant(()))))
8388
def statsExprThrow =
84-
stats :+ expr :+ api.typecheck(atPos(expr.pos)(Throw(Apply(Select(New(gen.mkAttributedRef(defn.IllegalStateExceptionClass)), nme.CONSTRUCTOR), Nil))))
89+
stats :+ expr :+ api.typecheck(atPos(expr.pos)(Throw(Apply(Select(New(gen.mkAttributedRef(defn.IllegalStateExceptionClass)), termNames.CONSTRUCTOR), Nil))))
8590
expr match {
8691
case Apply(fun, args) if isAwait(fun) =>
8792
val valDef = defineVal(name.await(), expr, tree.pos)
@@ -329,7 +334,6 @@ private[async] trait AnfTransform {
329334

330335
val matchResults = collection.mutable.Buffer[Tree]()
331336
def modifyLabelDef(ld: LabelDef): (Tree, Tree) = {
332-
val symTab = c.universe.asInstanceOf[reflect.internal.SymbolTable]
333337
val param = ld.params.head
334338
val ld2 = if (ld.params.head.tpe.typeSymbol == definitions.UnitClass) {
335339
// Unit typed match: eliminate the label def parameter, but don't create a matchres temp variable to

src/main/scala/scala/async/internal/AsyncBase.scala

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
package scala.async.internal
1414

15-
import scala.reflect.internal.annotations.compileTimeOnly
16-
import scala.reflect.macros.Context
15+
import scala.annotation.compileTimeOnly
16+
import scala.reflect.macros.whitebox
1717
import scala.reflect.api.Universe
1818

1919
/**
@@ -47,10 +47,10 @@ abstract class AsyncBase {
4747
@compileTimeOnly("`await` must be enclosed in an `async` block")
4848
def await[T](awaitable: futureSystem.Fut[T]): T = ???
4949

50-
def asyncImpl[T: c.WeakTypeTag](c: Context)
50+
def asyncImpl[T: c.WeakTypeTag](c: whitebox.Context)
5151
(body: c.Expr[T])
5252
(execContext: c.Expr[futureSystem.ExecContext]): c.Expr[futureSystem.Fut[T]] = {
53-
import c.universe._, c.internal._, decorators._
53+
import c.internal._, decorators._
5454
val asyncMacro = AsyncMacro(c, self)(body.tree)
5555

5656
val code = asyncMacro.asyncTransform[T](execContext.tree)(c.weakTypeTag[T])
@@ -64,13 +64,13 @@ abstract class AsyncBase {
6464
protected[async] def asyncMethod(u: Universe)(asyncMacroSymbol: u.Symbol): u.Symbol = {
6565
import u._
6666
if (asyncMacroSymbol == null) NoSymbol
67-
else asyncMacroSymbol.owner.typeSignature.member(newTermName("async"))
67+
else asyncMacroSymbol.owner.typeSignature.member(TermName("async"))
6868
}
6969

7070
protected[async] def awaitMethod(u: Universe)(asyncMacroSymbol: u.Symbol): u.Symbol = {
7171
import u._
7272
if (asyncMacroSymbol == null) NoSymbol
73-
else asyncMacroSymbol.owner.typeSignature.member(newTermName("await"))
73+
else asyncMacroSymbol.owner.typeSignature.member(TermName("await"))
7474
}
7575

7676
protected[async] def nullOut(u: Universe)(name: u.Expr[String], v: u.Expr[Any]): u.Expr[Unit] =

src/main/scala/scala/async/internal/AsyncId.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
package scala.async.internal
1414

1515
import language.experimental.macros
16-
import scala.reflect.macros.Context
16+
import scala.reflect.macros.whitebox
1717
import scala.reflect.api.Universe
1818

1919
object AsyncId extends AsyncBase {
@@ -22,7 +22,7 @@ object AsyncId extends AsyncBase {
2222

2323
def async[T](body: => T): T = macro asyncIdImpl[T]
2424

25-
def asyncIdImpl[T: c.WeakTypeTag](c: Context)(body: c.Expr[T]): c.Expr[T] = asyncImpl[T](c)(body)(c.literalUnit)
25+
def asyncIdImpl[T: c.WeakTypeTag](c: whitebox.Context)(body: c.Expr[T]): c.Expr[T] = asyncImpl[T](c)(body)(c.literalUnit)
2626
}
2727

2828
object AsyncTestLV extends AsyncBase {
@@ -31,7 +31,7 @@ object AsyncTestLV extends AsyncBase {
3131

3232
def async[T](body: T): T = macro asyncIdImpl[T]
3333

34-
def asyncIdImpl[T: c.WeakTypeTag](c: Context)(body: c.Expr[T]): c.Expr[T] = asyncImpl[T](c)(body)(c.literalUnit)
34+
def asyncIdImpl[T: c.WeakTypeTag](c: whitebox.Context)(body: c.Expr[T]): c.Expr[T] = asyncImpl[T](c)(body)(c.literalUnit)
3535

3636
var log: List[(String, Any)] = Nil
3737
def assertNulledOut(a: Any): Unit = assert(log.exists(_._2 == a), AsyncTestLV.log)
@@ -59,7 +59,7 @@ object IdentityFutureSystem extends FutureSystem {
5959
type ExecContext = Unit
6060
type Tryy[A] = scala.util.Try[A]
6161

62-
def mkOps(c0: Context): Ops {val c: c0.type} = new Ops {
62+
def mkOps(c0: whitebox.Context): Ops {val c: c0.type} = new Ops {
6363
val c: c0.type = c0
6464
import c.universe._
6565

src/main/scala/scala/async/internal/AsyncMacro.scala

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
package scala.async.internal
1414

1515
object AsyncMacro {
16-
def apply(c0: reflect.macros.Context, base: AsyncBase)(body0: c0.Tree): AsyncMacro { val c: c0.type } = {
17-
import language.reflectiveCalls
18-
16+
def apply(c0: reflect.macros.whitebox.Context, base: AsyncBase)(body0: c0.Tree): AsyncMacro { val c: c0.type } = {
1917
// Use an attachment on RootClass as a sneaky place for a per-Global cache
2018
val att = c0.internal.attachments(c0.universe.rootMirror.RootClass)
2119
val names = att.get[AsyncNames[_]].getOrElse {
@@ -42,7 +40,7 @@ private[async] trait AsyncMacro
4240
extends AnfTransform with TransformUtils with Lifter
4341
with ExprBuilder with AsyncTransform with AsyncAnalysis with LiveVariables {
4442

45-
val c: scala.reflect.macros.Context
43+
val c: scala.reflect.macros.whitebox.Context
4644
val body: c.Tree
4745
var containsAwait: c.Tree => Boolean
4846
val asyncNames: AsyncNames[c.universe.type]

src/main/scala/scala/async/internal/AsyncNames.scala

+10-10
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,24 @@ final class AsyncNames[U <: Names with Singleton](val u: U) {
4040
}
4141

4242
final class TermNameCache(base: String) extends NameCache[U#TermName](base) {
43-
override protected def newName(s: String): U#TermName = newTermName(s)
43+
override protected def newName(s: String): U#TermName = TermName(s)
4444
}
4545
final class TypeNameCache(base: String) extends NameCache[U#TypeName](base) {
46-
override protected def newName(s: String): U#TypeName = newTypeName(s)
46+
override protected def newName(s: String): U#TypeName = TypeName(s)
4747
}
4848
private val matchRes: TermNameCache = new TermNameCache("match")
4949
private val ifRes: TermNameCache = new TermNameCache("if")
5050
private val await: TermNameCache = new TermNameCache("await")
5151

52-
private val result = newTermName("result$async")
53-
private val completed: TermName = newTermName("completed$async")
54-
private val apply = newTermName("apply")
55-
private val stateMachine = newTermName("stateMachine$async")
52+
private val result = TermName("result$async")
53+
private val completed: TermName = TermName("completed$async")
54+
private val apply = TermName("apply")
55+
private val stateMachine = TermName("stateMachine$async")
5656
private val stateMachineT = stateMachine.toTypeName
57-
private val state: u.TermName = newTermName("state$async")
58-
private val execContext = newTermName("execContext$async")
59-
private val tr: u.TermName = newTermName("tr$async")
60-
private val t: u.TermName = newTermName("throwable$async")
57+
private val state: u.TermName = TermName("state$async")
58+
private val execContext = TermName("execContext$async")
59+
private val tr: u.TermName = TermName("tr$async")
60+
private val t: u.TermName = TermName("throwable$async")
6161

6262
final class NameSource[N <: U#Name](cache: NameCache[N]) {
6363
private val count = new AtomicInteger(0)

src/main/scala/scala/async/internal/AsyncTransform.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ trait AsyncTransform {
7070
symbolOf[scala.Function1[Any, Any]]
7171
}
7272
val tryToUnit = appliedType(tycon, futureSystemOps.tryType[Any], typeOf[Unit])
73-
val template = Template((futureSystemOps.stateMachineClassParents ::: List(tryToUnit, typeOf[() => Unit])).map(TypeTree(_)), emptyValDef, body)
73+
val template = Template((futureSystemOps.stateMachineClassParents ::: List(tryToUnit, typeOf[() => Unit])).map(TypeTree(_)), noSelfType, body)
7474

7575
val t = ClassDef(NoMods, name.stateMachineT, Nil, template)
7676
typecheckClassDef(t)
@@ -112,7 +112,7 @@ trait AsyncTransform {
112112

113113
Block(List[Tree](
114114
stateMachineSpliced,
115-
ValDef(NoMods, name.stateMachine, TypeTree(), Apply(Select(New(Ident(stateMachine.symbol)), nme.CONSTRUCTOR), Nil)),
115+
ValDef(NoMods, name.stateMachine, TypeTree(), Apply(Select(New(Ident(stateMachine.symbol)), termNames.CONSTRUCTOR), Nil)),
116116
futureSystemOps.spawn(Apply(selectStateMachine(name.apply), Nil), selectStateMachine(name.execContext))
117117
),
118118
futureSystemOps.promiseToFuture(c.Expr[futureSystem.Prom[T]](selectStateMachine(name.result))).tree)
@@ -205,7 +205,7 @@ trait AsyncTransform {
205205
atPos(tree.pos) {
206206
gen.mkAttributedStableRef(thisType(fieldSym.owner.asClass), fieldSym).setType(tree.tpe)
207207
}
208-
case sel @ Select(n@New(tt: TypeTree), nme.CONSTRUCTOR) =>
208+
case sel @ Select(n@New(tt: TypeTree), termNamesCONSTRUCTOR) =>
209209
adjustType(sel)
210210
adjustType(n)
211211
adjustType(tt)

src/main/scala/scala/async/internal/ExprBuilder.scala

+14-17
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ import java.util.function.IntUnaryOperator
1616

1717
import scala.collection.mutable
1818
import scala.collection.mutable.ListBuffer
19-
import language.existentials
2019

2120
trait ExprBuilder {
2221
builder: AsyncMacro =>
2322

2423
import c.universe._
25-
import defn._
2624
import c.internal._
2725

2826
val futureSystem: FutureSystem
@@ -99,7 +97,7 @@ trait ExprBuilder {
9997
Array(nextState)
10098

10199
override def mkHandlerCaseForState[T: WeakTypeTag]: CaseDef = {
102-
val fun = This(tpnme.EMPTY)
100+
val fun = This(typeNames.EMPTY)
103101
val callOnComplete = futureSystemOps.onComplete[Any, Unit](c.Expr[futureSystem.Fut[Any]](awaitable.expr),
104102
c.Expr[futureSystem.Tryy[Any] => Unit](fun), c.Expr[futureSystem.ExecContext](Ident(name.execContext))).tree
105103
val tryGetOrCallOnComplete: List[Tree] =
@@ -118,7 +116,7 @@ trait ExprBuilder {
118116
private def tryGetTree(tryReference: => Tree) =
119117
Assign(
120118
Ident(awaitable.resultName),
121-
TypeApply(Select(futureSystemOps.tryyGet[Any](c.Expr[futureSystem.Tryy[Any]](tryReference)).tree, newTermName("asInstanceOf")), List(TypeTree(awaitable.resultType)))
119+
TypeApply(Select(futureSystemOps.tryyGet[Any](c.Expr[futureSystem.Tryy[Any]](tryReference)).tree, TermName("asInstanceOf")), List(TypeTree(awaitable.resultType)))
122120
)
123121

124122
/* if (tr.isFailure)
@@ -136,7 +134,7 @@ trait ExprBuilder {
136134
Block(toList(futureSystemOps.completeProm[T](
137135
c.Expr[futureSystem.Prom[T]](symLookup.memberRef(name.result)),
138136
c.Expr[futureSystem.Tryy[T]](
139-
TypeApply(Select(tryReference, newTermName("asInstanceOf")),
137+
TypeApply(Select(tryReference, TermName("asInstanceOf")),
140138
List(TypeTree(futureSystemOps.tryType[T]))))).tree),
141139
Return(literalUnit)),
142140
getAndUpdateState
@@ -401,7 +399,7 @@ trait ExprBuilder {
401399
val dotBuilder = new StringBuilder()
402400
dotBuilder.append("digraph {\n")
403401
def stateLabel(s: Int) = {
404-
if (s == 0) "INITIAL" else if (s == Int.MaxValue) "TERMINAL" else switchIds.getOrElse(s, s).toString
402+
if (s == 0) "INITIAL" else if (s == Int.MaxValue) "TERMINAL" else switchIds.get(s).map(_.toString).getOrElse(s.toString)
405403
}
406404
val length = states.size
407405
for ((state, i) <- asyncStates.zipWithIndex) {
@@ -521,25 +519,24 @@ trait ExprBuilder {
521519
* }
522520
*/
523521
private def resumeFunTree[T: WeakTypeTag]: Tree = {
524-
val stateMemberSymbol = symLookup.stateMachineMember(name.state)
525522
val stateMemberRef = symLookup.memberRef(name.state)
526-
val body = Match(stateMemberRef, mkCombinedHandlerCases[T] ++ initStates.flatMap(_.mkOnCompleteHandler[T]) ++ List(CaseDef(Ident(nme.WILDCARD), EmptyTree, Throw(Apply(Select(New(Ident(defn.IllegalStateExceptionClass)), termNames.CONSTRUCTOR), List())))))
523+
val body = Match(stateMemberRef, mkCombinedHandlerCases[T] ++ initStates.flatMap(_.mkOnCompleteHandler[T]) ++ List(CaseDef(Ident(termNames.WILDCARD), EmptyTree, Throw(Apply(Select(New(Ident(defn.IllegalStateExceptionClass)), termNames.CONSTRUCTOR), List())))))
527524
val body1 = compactStates(body)
528525

529526
maybeTry(
530527
body1,
531528
List(
532529
CaseDef(
533-
Bind(name.t, Typed(Ident(nme.WILDCARD), Ident(defn.ThrowableClass))),
530+
Bind(name.t, Typed(Ident(termNames.WILDCARD), Ident(defn.ThrowableClass))),
534531
EmptyTree, {
535-
val then = {
532+
val thenn = {
536533
val t = c.Expr[Throwable](Ident(name.t))
537534
val complete = futureSystemOps.completeProm[T](
538535
c.Expr[futureSystem.Prom[T]](symLookup.memberRef(name.result)), futureSystemOps.tryyFailure[T](t)).tree
539536
Block(toList(complete), Return(literalUnit))
540537
}
541-
If(Apply(Ident(defn.NonFatalClass), List(Ident(name.t))), then, Throw(Ident(name.t)))
542-
then
538+
If(Apply(Ident(defn.NonFatalClass), List(Ident(name.t))), thenn, Throw(Ident(name.t)))
539+
thenn
543540
})), EmptyTree)
544541
}
545542

@@ -567,8 +564,8 @@ trait ExprBuilder {
567564
}
568565

569566
def forever(t: Tree): Tree = {
570-
val labelName = name.fresh("while$")
571-
LabelDef(labelName, Nil, Block(toList(t), Apply(Ident(labelName), Nil)))
567+
val termName = TermName(name.fresh("while$"))
568+
LabelDef(termName, Nil, Block(toList(t), Apply(Ident(termName), Nil)))
572569
}
573570

574571
/**
@@ -584,7 +581,7 @@ trait ExprBuilder {
584581
* }
585582
*/
586583
def onCompleteHandler[T: WeakTypeTag]: Tree = {
587-
val onCompletes = initStates.flatMap(_.mkOnCompleteHandler[T])
584+
initStates.flatMap(_.mkOnCompleteHandler[T])
588585
forever {
589586
adaptToUnit(toList(resumeFunTree))
590587
}
@@ -617,7 +614,7 @@ trait ExprBuilder {
617614
case _ if t.tpe != null => t.tpe
618615
case Try(body, Nil, _) => tpeOf(body)
619616
case Block(_, expr) => tpeOf(expr)
620-
case Literal(Constant(value)) if value == () => definitions.UnitTpe
617+
case Literal(Constant(value)) if value == (()) => definitions.UnitTpe
621618
case Return(_) => definitions.NothingTpe
622619
case _ => NoType
623620
}
@@ -645,7 +642,7 @@ trait ExprBuilder {
645642
def literalUnit = Literal(Constant(())) // a def to avoid sharing trees
646643

647644
def toList(tree: Tree): List[Tree] = tree match {
648-
case Block(stats, Literal(Constant(value))) if value == () => stats
645+
case Block(stats, Literal(Constant(value))) if value == (()) => stats
649646
case _ => tree :: Nil
650647
}
651648

src/main/scala/scala/async/internal/FutureSystem.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
package scala.async.internal
1414

1515
import scala.language.higherKinds
16-
import scala.reflect.macros.Context
16+
import scala.reflect.macros.whitebox
1717

1818
/**
1919
* An abstraction over a future system.
2020
*
21-
* Used by the macro implementations in [[scala.async.AsyncBase]] to
21+
* Used by the macro implementations in [[scala.async.internal.AsyncBase]] to
2222
* customize the code generation.
2323
*
2424
* The API mirrors that of `scala.concurrent.Future`, see the instance
@@ -36,7 +36,7 @@ trait FutureSystem {
3636
type Tryy[T]
3737

3838
trait Ops {
39-
val c: Context
39+
val c: whitebox.Context
4040
import c.universe._
4141

4242
def promType[A: WeakTypeTag]: Type
@@ -85,7 +85,7 @@ trait FutureSystem {
8585
def dot(enclosingOwner: Symbol, macroApplication: Tree): Option[(String => Unit)] = None
8686
}
8787

88-
def mkOps(c0: Context): Ops { val c: c0.type }
88+
def mkOps(c0: whitebox.Context): Ops { val c: c0.type }
8989

9090
@deprecated("No longer honoured by the macro, all generated names now contain $async to avoid accidental clashes with lambda lifted names", "0.9.7")
9191
def freshenAllNames: Boolean = false
@@ -103,7 +103,7 @@ object ScalaConcurrentFutureSystem extends FutureSystem {
103103
type ExecContext = ExecutionContext
104104
type Tryy[A] = scala.util.Try[A]
105105

106-
def mkOps(c0: Context): Ops {val c: c0.type} = new Ops {
106+
def mkOps(c0: whitebox.Context): Ops {val c: c0.type} = new Ops {
107107
val c: c0.type = c0
108108
import c.universe._
109109

src/main/scala/scala/async/internal/Lifter.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ trait Lifter {
4040
def record(defs: List[Tree]): Unit = {
4141
// Keep note of local companions so we rename them consistently
4242
// when lifting.
43-
val comps = for {
43+
for {
4444
cd@ClassDef(_, _, _, _) <- defs
4545
md@ModuleDef(_, _, _) <- defs
4646
if (cd.name.toTermName == md.name)

src/main/scala/scala/async/internal/LiveVariables.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ package scala.async.internal
1414

1515
import scala.collection.mutable
1616

17-
import java.util
18-
import java.util.function.{IntConsumer, IntPredicate}
17+
import java.util.function.IntConsumer
1918

2019
import scala.collection.immutable.IntMap
2120

src/main/scala/scala/async/internal/ScalaConcurrentAsync.scala

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ package scala
1414
package async
1515
package internal
1616

17-
import scala.language.experimental.macros
18-
import scala.reflect.macros.Context
17+
import scala.reflect.macros.whitebox
1918
import scala.concurrent.Future
2019

2120
object ScalaConcurrentAsync extends AsyncBase {
2221
type FS = ScalaConcurrentFutureSystem.type
2322
val futureSystem: FS = ScalaConcurrentFutureSystem
2423

25-
override def asyncImpl[T: c.WeakTypeTag](c: Context)
24+
override def asyncImpl[T: c.WeakTypeTag](c: whitebox.Context)
2625
(body: c.Expr[T])
2726
(execContext: c.Expr[futureSystem.ExecContext]): c.Expr[Future[T]] = {
2827
super.asyncImpl[T](c)(body)(execContext)

src/main/scala/scala/async/internal/StateSet.scala

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import java.util
1616
import java.util.function.{Consumer, IntConsumer}
1717

1818
import scala.collection.JavaConverters.{asScalaIteratorConverter, iterableAsScalaIterableConverter}
19-
import scala.collection.mutable
2019

2120
// Set for StateIds, which are either small positive integers or -symbolID.
2221
final class StateSet {

0 commit comments

Comments
 (0)