Skip to content

Fix deprecation warnings #214

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 17 commits into from
Feb 22, 2019
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
10 changes: 7 additions & 3 deletions src/main/scala/scala/async/internal/AnfTransform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ private[async] trait AnfTransform {

def listToBlock(trees: List[Tree]): Block = trees match {
case trees @ (init :+ last) =>
val pos = trees.map(_.pos).reduceLeft(_ union _)
val pos = trees.map(_.pos).reduceLeft{
(p, q) =>
if (!q.isRange) p
else if (p.isRange) p.withStart(p.start.min(q.start)).withEnd(p.end.max(q.end))
else q
}
newBlock(init, last).setType(last.tpe).setPos(pos)
}

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

val matchResults = collection.mutable.Buffer[Tree]()
def modifyLabelDef(ld: LabelDef): (Tree, Tree) = {
val symTab = c.universe.asInstanceOf[reflect.internal.SymbolTable]
val param = ld.params.head
val ld2 = if (ld.params.head.tpe.typeSymbol == definitions.UnitClass) {
// Unit typed match: eliminate the label def parameter, but don't create a matchres temp variable to
Expand Down
12 changes: 6 additions & 6 deletions src/main/scala/scala/async/internal/AsyncBase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

package scala.async.internal

import scala.reflect.internal.annotations.compileTimeOnly
import scala.reflect.macros.Context
import scala.annotation.compileTimeOnly
import scala.reflect.macros.whitebox
import scala.reflect.api.Universe

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

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

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

protected[async] def awaitMethod(u: Universe)(asyncMacroSymbol: u.Symbol): u.Symbol = {
import u._
if (asyncMacroSymbol == null) NoSymbol
else asyncMacroSymbol.owner.typeSignature.member(newTermName("await"))
else asyncMacroSymbol.owner.typeSignature.member(TermName("await"))
}

protected[async] def nullOut(u: Universe)(name: u.Expr[String], v: u.Expr[Any]): u.Expr[Unit] =
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/scala/async/internal/AsyncId.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
package scala.async.internal

import language.experimental.macros
import scala.reflect.macros.Context
import scala.reflect.macros.whitebox
import scala.reflect.api.Universe

object AsyncId extends AsyncBase {
Expand All @@ -22,7 +22,7 @@ object AsyncId extends AsyncBase {

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

def asyncIdImpl[T: c.WeakTypeTag](c: Context)(body: c.Expr[T]): c.Expr[T] = asyncImpl[T](c)(body)(c.literalUnit)
def asyncIdImpl[T: c.WeakTypeTag](c: whitebox.Context)(body: c.Expr[T]): c.Expr[T] = asyncImpl[T](c)(body)(c.literalUnit)
}

object AsyncTestLV extends AsyncBase {
Expand All @@ -31,7 +31,7 @@ object AsyncTestLV extends AsyncBase {

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

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

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

def mkOps(c0: Context): Ops {val c: c0.type} = new Ops {
def mkOps(c0: whitebox.Context): Ops {val c: c0.type} = new Ops {
val c: c0.type = c0
import c.universe._

Expand Down
6 changes: 2 additions & 4 deletions src/main/scala/scala/async/internal/AsyncMacro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
package scala.async.internal

object AsyncMacro {
def apply(c0: reflect.macros.Context, base: AsyncBase)(body0: c0.Tree): AsyncMacro { val c: c0.type } = {
import language.reflectiveCalls

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

val c: scala.reflect.macros.Context
val c: scala.reflect.macros.whitebox.Context
val body: c.Tree
var containsAwait: c.Tree => Boolean
val asyncNames: AsyncNames[c.universe.type]
Expand Down
20 changes: 10 additions & 10 deletions src/main/scala/scala/async/internal/AsyncNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,24 @@ final class AsyncNames[U <: Names with Singleton](val u: U) {
}

final class TermNameCache(base: String) extends NameCache[U#TermName](base) {
override protected def newName(s: String): U#TermName = newTermName(s)
override protected def newName(s: String): U#TermName = TermName(s)
}
final class TypeNameCache(base: String) extends NameCache[U#TypeName](base) {
override protected def newName(s: String): U#TypeName = newTypeName(s)
override protected def newName(s: String): U#TypeName = TypeName(s)
}
private val matchRes: TermNameCache = new TermNameCache("match")
private val ifRes: TermNameCache = new TermNameCache("if")
private val await: TermNameCache = new TermNameCache("await")

private val result = newTermName("result$async")
private val completed: TermName = newTermName("completed$async")
private val apply = newTermName("apply")
private val stateMachine = newTermName("stateMachine$async")
private val result = TermName("result$async")
private val completed: TermName = TermName("completed$async")
private val apply = TermName("apply")
private val stateMachine = TermName("stateMachine$async")
private val stateMachineT = stateMachine.toTypeName
private val state: u.TermName = newTermName("state$async")
private val execContext = newTermName("execContext$async")
private val tr: u.TermName = newTermName("tr$async")
private val t: u.TermName = newTermName("throwable$async")
private val state: u.TermName = TermName("state$async")
private val execContext = TermName("execContext$async")
private val tr: u.TermName = TermName("tr$async")
private val t: u.TermName = TermName("throwable$async")

final class NameSource[N <: U#Name](cache: NameCache[N]) {
private val count = new AtomicInteger(0)
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/scala/async/internal/AsyncTransform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ trait AsyncTransform {
symbolOf[scala.Function1[Any, Any]]
}
val tryToUnit = appliedType(tycon, futureSystemOps.tryType[Any], typeOf[Unit])
val template = Template((futureSystemOps.stateMachineClassParents ::: List(tryToUnit, typeOf[() => Unit])).map(TypeTree(_)), emptyValDef, body)
val template = Template((futureSystemOps.stateMachineClassParents ::: List(tryToUnit, typeOf[() => Unit])).map(TypeTree(_)), noSelfType, body)

val t = ClassDef(NoMods, name.stateMachineT, Nil, template)
typecheckClassDef(t)
Expand Down Expand Up @@ -112,7 +112,7 @@ trait AsyncTransform {

Block(List[Tree](
stateMachineSpliced,
ValDef(NoMods, name.stateMachine, TypeTree(), Apply(Select(New(Ident(stateMachine.symbol)), nme.CONSTRUCTOR), Nil)),
ValDef(NoMods, name.stateMachine, TypeTree(), Apply(Select(New(Ident(stateMachine.symbol)), termNames.CONSTRUCTOR), Nil)),
futureSystemOps.spawn(Apply(selectStateMachine(name.apply), Nil), selectStateMachine(name.execContext))
),
futureSystemOps.promiseToFuture(c.Expr[futureSystem.Prom[T]](selectStateMachine(name.result))).tree)
Expand Down Expand Up @@ -205,7 +205,7 @@ trait AsyncTransform {
atPos(tree.pos) {
gen.mkAttributedStableRef(thisType(fieldSym.owner.asClass), fieldSym).setType(tree.tpe)
}
case sel @ Select(n@New(tt: TypeTree), nme.CONSTRUCTOR) =>
case sel @ Select(n@New(tt: TypeTree), termNamesCONSTRUCTOR) =>
adjustType(sel)
adjustType(n)
adjustType(tt)
Expand Down
31 changes: 14 additions & 17 deletions src/main/scala/scala/async/internal/ExprBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ import java.util.function.IntUnaryOperator

import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import language.existentials

trait ExprBuilder {
builder: AsyncMacro =>

import c.universe._
import defn._
import c.internal._

val futureSystem: FutureSystem
Expand Down Expand Up @@ -99,7 +97,7 @@ trait ExprBuilder {
Array(nextState)

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

/* if (tr.isFailure)
Expand All @@ -136,7 +134,7 @@ trait ExprBuilder {
Block(toList(futureSystemOps.completeProm[T](
c.Expr[futureSystem.Prom[T]](symLookup.memberRef(name.result)),
c.Expr[futureSystem.Tryy[T]](
TypeApply(Select(tryReference, newTermName("asInstanceOf")),
TypeApply(Select(tryReference, TermName("asInstanceOf")),
List(TypeTree(futureSystemOps.tryType[T]))))).tree),
Return(literalUnit)),
getAndUpdateState
Expand Down Expand Up @@ -401,7 +399,7 @@ trait ExprBuilder {
val dotBuilder = new StringBuilder()
dotBuilder.append("digraph {\n")
def stateLabel(s: Int) = {
if (s == 0) "INITIAL" else if (s == Int.MaxValue) "TERMINAL" else switchIds.getOrElse(s, s).toString
if (s == 0) "INITIAL" else if (s == Int.MaxValue) "TERMINAL" else switchIds.get(s).map(_.toString).getOrElse(s.toString)
}
val length = states.size
for ((state, i) <- asyncStates.zipWithIndex) {
Expand Down Expand Up @@ -521,25 +519,24 @@ trait ExprBuilder {
* }
*/
private def resumeFunTree[T: WeakTypeTag]: Tree = {
val stateMemberSymbol = symLookup.stateMachineMember(name.state)
val stateMemberRef = symLookup.memberRef(name.state)
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())))))
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())))))
val body1 = compactStates(body)

maybeTry(
body1,
List(
CaseDef(
Bind(name.t, Typed(Ident(nme.WILDCARD), Ident(defn.ThrowableClass))),
Bind(name.t, Typed(Ident(termNames.WILDCARD), Ident(defn.ThrowableClass))),
EmptyTree, {
val then = {
val thenn = {
val t = c.Expr[Throwable](Ident(name.t))
val complete = futureSystemOps.completeProm[T](
c.Expr[futureSystem.Prom[T]](symLookup.memberRef(name.result)), futureSystemOps.tryyFailure[T](t)).tree
Block(toList(complete), Return(literalUnit))
}
If(Apply(Ident(defn.NonFatalClass), List(Ident(name.t))), then, Throw(Ident(name.t)))
then
If(Apply(Ident(defn.NonFatalClass), List(Ident(name.t))), thenn, Throw(Ident(name.t)))
thenn
})), EmptyTree)
}

Expand Down Expand Up @@ -567,8 +564,8 @@ trait ExprBuilder {
}

def forever(t: Tree): Tree = {
val labelName = name.fresh("while$")
LabelDef(labelName, Nil, Block(toList(t), Apply(Ident(labelName), Nil)))
val termName = TermName(name.fresh("while$"))
LabelDef(termName, Nil, Block(toList(t), Apply(Ident(termName), Nil)))
}

/**
Expand All @@ -584,7 +581,7 @@ trait ExprBuilder {
* }
*/
def onCompleteHandler[T: WeakTypeTag]: Tree = {
val onCompletes = initStates.flatMap(_.mkOnCompleteHandler[T])
initStates.flatMap(_.mkOnCompleteHandler[T])
forever {
adaptToUnit(toList(resumeFunTree))
}
Expand Down Expand Up @@ -617,7 +614,7 @@ trait ExprBuilder {
case _ if t.tpe != null => t.tpe
case Try(body, Nil, _) => tpeOf(body)
case Block(_, expr) => tpeOf(expr)
case Literal(Constant(value)) if value == () => definitions.UnitTpe
case Literal(Constant(value)) if value == (()) => definitions.UnitTpe
case Return(_) => definitions.NothingTpe
case _ => NoType
}
Expand Down Expand Up @@ -645,7 +642,7 @@ trait ExprBuilder {
def literalUnit = Literal(Constant(())) // a def to avoid sharing trees

def toList(tree: Tree): List[Tree] = tree match {
case Block(stats, Literal(Constant(value))) if value == () => stats
case Block(stats, Literal(Constant(value))) if value == (()) => stats
case _ => tree :: Nil
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/scala/async/internal/FutureSystem.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
package scala.async.internal

import scala.language.higherKinds
import scala.reflect.macros.Context
import scala.reflect.macros.whitebox

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

trait Ops {
val c: Context
val c: whitebox.Context
import c.universe._

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

def mkOps(c0: Context): Ops { val c: c0.type }
def mkOps(c0: whitebox.Context): Ops { val c: c0.type }

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

def mkOps(c0: Context): Ops {val c: c0.type} = new Ops {
def mkOps(c0: whitebox.Context): Ops {val c: c0.type} = new Ops {
val c: c0.type = c0
import c.universe._

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/scala/async/internal/Lifter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ trait Lifter {
def record(defs: List[Tree]): Unit = {
// Keep note of local companions so we rename them consistently
// when lifting.
val comps = for {
for {
cd@ClassDef(_, _, _, _) <- defs
md@ModuleDef(_, _, _) <- defs
if (cd.name.toTermName == md.name)
Expand Down
3 changes: 1 addition & 2 deletions src/main/scala/scala/async/internal/LiveVariables.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ package scala.async.internal

import scala.collection.mutable

import java.util
import java.util.function.{IntConsumer, IntPredicate}
import java.util.function.IntConsumer

import scala.collection.immutable.IntMap

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ package scala
package async
package internal

import scala.language.experimental.macros
import scala.reflect.macros.Context
import scala.reflect.macros.whitebox
import scala.concurrent.Future

object ScalaConcurrentAsync extends AsyncBase {
type FS = ScalaConcurrentFutureSystem.type
val futureSystem: FS = ScalaConcurrentFutureSystem

override def asyncImpl[T: c.WeakTypeTag](c: Context)
override def asyncImpl[T: c.WeakTypeTag](c: whitebox.Context)
(body: c.Expr[T])
(execContext: c.Expr[futureSystem.ExecContext]): c.Expr[Future[T]] = {
super.asyncImpl[T](c)(body)(execContext)
Expand Down
1 change: 0 additions & 1 deletion src/main/scala/scala/async/internal/StateSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import java.util
import java.util.function.{Consumer, IntConsumer}

import scala.collection.JavaConverters.{asScalaIteratorConverter, iterableAsScalaIterableConverter}
import scala.collection.mutable

// Set for StateIds, which are either small positive integers or -symbolID.
final class StateSet {
Expand Down
Loading