Skip to content

Some refactoring #4830

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 1 commit into from
Jul 24, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import dotty.tools.dotc.transform.MegaPhase._
import ValueClasses._
import dotty.tools.dotc.ast.{Trees, tpd}
import scala.collection.{ mutable, immutable }
import mutable.ListBuffer
import core._
import dotty.tools.dotc.core.Phases.Phase
import Types._, Contexts._, Constants._, Names._, NameOps._, Flags._, DenotTransformers._
Expand Down Expand Up @@ -158,13 +157,7 @@ class ExtensionMethods extends MiniPhase with DenotTransformer with FullParamete
assert(staticClass.exists, s"$origClass lacks companion, ${origClass.owner.definedPeriodsString} ${origClass.owner.info.decls} ${origClass.owner.info.decls}")
val extensionMeth = extensionMethod(origMeth)
ctx.log(s"Value class $origClass spawns extension method.\n Old: ${origMeth.showDcl}\n New: ${extensionMeth.showDcl}")
val store: ListBuffer[Tree] = extensionDefs.get(staticClass) match {
case Some(x) => x
case None =>
val newC = new ListBuffer[Tree]()
extensionDefs(staticClass) = newC
newC
}
val store = extensionDefs.getOrElseUpdate(staticClass, new mutable.ListBuffer[Tree])
store += fullyParameterizedDef(extensionMeth, tree)
cpy.DefDef(tree)(rhs = forwarder(extensionMeth, tree))
} else tree
Expand Down
24 changes: 12 additions & 12 deletions compiler/src/dotty/tools/dotc/transform/LazyVals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
}

private def nullOut(nullables: List[Symbol])(implicit ctx: Context): List[Tree] = {
val nullConst = Literal(Constants.Constant(null))
val nullConst = Literal(Constant(null))
nullables.map { field =>
assert(field.isField)
field.setFlag(Flags.Mutable)
Expand All @@ -220,7 +220,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
def mkNonThreadSafeDef(target: Tree, flag: Tree, rhs: Tree, nullables: List[Symbol])(implicit ctx: Context) = {
val stats = new mutable.ListBuffer[Tree]
if (!isWildcardArg(rhs)) stats += target.becomes(rhs)
stats += flag.becomes(Literal(Constants.Constant(true))) ++= nullOut(nullables)
stats += flag.becomes(Literal(Constant(true))) ++= nullOut(nullables)
If(flag.ensureApplied, target.ensureApplied, Block(stats.toList, target.ensureApplied))
}

Expand Down Expand Up @@ -262,7 +262,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
else {
val flagName = LazyBitMapName.fresh(x.name.asTermName)
val flagSymbol = ctx.newSymbol(x.symbol.owner, flagName, containerFlags | Flags.Private, defn.BooleanType).enteredAfter(this)
val flag = ValDef(flagSymbol, Literal(Constants.Constant(false)))
val flag = ValDef(flagSymbol, Literal(Constant(false)))
val slowPath = DefDef(x.symbol.asTerm, mkNonThreadSafeDef(ref(containerSymbol), ref(flagSymbol), x.rhs, nullableFor(x.symbol)))
Thicket(containerTree, flag, slowPath)
}
Expand Down Expand Up @@ -315,10 +315,10 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
setFlagState: Tree,
waitOnLock: Tree,
nullables: List[Symbol])(implicit ctx: Context) = {
val initState = Literal(Constants.Constant(0))
val computeState = Literal(Constants.Constant(1))
val notifyState = Literal(Constants.Constant(2))
val computedState = Literal(Constants.Constant(3))
val initState = Literal(Constant(0))
val computeState = Literal(Constant(1))
val notifyState = Literal(Constant(2))
val computedState = Literal(Constant(3))
val flagSymbol = ctx.newSymbol(methodSymbol, lazyNme.flag, containerFlags, defn.LongType)
val flagDef = ValDef(flagSymbol, Literal(Constant(0L)))

Expand All @@ -328,7 +328,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
val resultDef = ValDef(resultSymbol, defaultValue(tp))

val retrySymbol = ctx.newSymbol(methodSymbol, lazyNme.retry, containerFlags, defn.BooleanType)
val retryDef = ValDef(retrySymbol, Literal(Constants.Constant(true)))
val retryDef = ValDef(retrySymbol, Literal(Constant(true)))

val whileCond = ref(retrySymbol)

Expand All @@ -346,7 +346,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
val compute = ref(resultSymbol).becomes(rhs)
val tr = Try(compute, List(handler), EmptyTree)
val assign = ref(target).becomes(ref(resultSymbol))
val noRetry = ref(retrySymbol).becomes(Literal(Constants.Constant(false)))
val noRetry = ref(retrySymbol).becomes(Literal(Constant(false)))
val body = If(casFlag.appliedTo(thiz, offset, ref(flagSymbol), computeState, Literal(Constant(ord))),
Block(tr :: assign :: complete :: noRetry :: Nil, Literal(Constant(()))),
Literal(Constant(())))
Expand All @@ -365,7 +365,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
}

val computed = {
val noRetry = ref(retrySymbol).becomes(Literal(Constants.Constant(false)))
val noRetry = ref(retrySymbol).becomes(Literal(Constant(false)))
val result = ref(resultSymbol).becomes(ref(target))
val body = Block(noRetry :: result :: Nil, Literal(Constant(())))
CaseDef(computedState, EmptyTree, body)
Expand Down Expand Up @@ -413,7 +413,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
offsetSymbol.addAnnotation(Annotation(defn.ScalaStaticAnnot))
val flagName = (StdNames.nme.BITMAP_PREFIX + id.toString).toTermName
val flagSymbol = ctx.newSymbol(claz, flagName, containerFlags, defn.LongType).enteredAfter(this)
flag = ValDef(flagSymbol, Literal(Constants.Constant(0L)))
flag = ValDef(flagSymbol, Literal(Constant(0L)))
val offsetTree = ValDef(offsetSymbol, getOffset.appliedTo(thizClass, Literal(Constant(flagName.toString))))
info.defs = offsetTree :: info.defs
}
Expand All @@ -423,7 +423,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
offsetSymbol.addAnnotation(Annotation(defn.ScalaStaticAnnot))
val flagName = (StdNames.nme.BITMAP_PREFIX + "0").toTermName
val flagSymbol = ctx.newSymbol(claz, flagName, containerFlags, defn.LongType).enteredAfter(this)
flag = ValDef(flagSymbol, Literal(Constants.Constant(0L)))
flag = ValDef(flagSymbol, Literal(Constant(0L)))
val offsetTree = ValDef(offsetSymbol, getOffset.appliedTo(thizClass, Literal(Constant(flagName.toString))))
appendOffsetDefs += (claz -> new OffsetInfo(List(offsetTree), ord))
}
Expand Down