Skip to content

Commit cb9c30d

Browse files
committed
Revert "WIP on paralelization"
This reverts commit cb00827.
1 parent 81c1355 commit cb9c30d

File tree

11 files changed

+292
-171
lines changed

11 files changed

+292
-171
lines changed

src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,9 +704,8 @@ object Trees {
704704
* The contained trees will be integrated when transformed with
705705
* a `transform(List[Tree])` call.
706706
*/
707-
case class Thicket[-T >: Untyped](val treesList: List[Tree[T]])
707+
case class Thicket[-T >: Untyped](trees: List[Tree[T]])
708708
extends Tree[T] with WithoutTypeOrPos[T] {
709-
def trees = treesList
710709
type ThisTree[-T >: Untyped] = Thicket[T]
711710
override def isEmpty: Boolean = trees.isEmpty
712711
override def toList: List[Tree[T]] = flatten(trees)

src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,6 @@ import scala.annotation.tailrec
1919
/** Some creators for typed trees */
2020
object tpd extends Trees.Instance[Type] with TypedTreeInfo {
2121

22-
class TypedAsync(val untypedTree: untpd.Tree, val outerTpe: Type, val ctx:Context) extends Thicket(Nil) {
23-
24-
var typedTree: tpd.Tree = null
25-
26-
override def trees = {
27-
if (typedTree eq null) {
28-
typedTree = ctx.typer.typedExpr(untypedTree, outerTpe)(ctx)
29-
}
30-
ctx.typerState.commit()(ctx)
31-
List(typedTree)
32-
}
33-
34-
override def toString: String = s"TypedAsync($untypedTree, $outerTpe)($typedTree)"
35-
}
36-
3722
private def ta(implicit ctx: Context) = ctx.typeAssigner
3823

3924
def Modifiers(sym: Symbol)(implicit ctx: Context): Modifiers = Modifiers(

src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ import config.{Settings, ScalaSettings, Platform, JavaPlatform}
2929
import language.implicitConversions
3030
import DenotTransformers.DenotTransformer
3131

32-
import scala.collection.concurrent.TrieMap
33-
3432
object Contexts {
3533

3634
/** A context is passed basically everywhere in dotc.
@@ -510,29 +508,6 @@ object Contexts {
510508
/** The platform */
511509
val platform: Platform = new JavaPlatform
512510

513-
val executors = new java.util.concurrent.ForkJoinPool()
514-
515-
def addToWaitList(dependOn: Thread, monitor: Object): Boolean = {
516-
val thisThread = Thread.currentThread()
517-
def followAliases(cur: Thread): Thread = {
518-
val nxt = waitList.getOrElse(cur, null)
519-
if ((nxt ne null) && (nxt ne thisThread))
520-
followAliases(nxt)
521-
else
522-
nxt
523-
}
524-
if (followAliases(dependOn) eq null) {
525-
waitList.put(Thread.currentThread(), dependOn)
526-
println(s"$thisThread waiting for $dependOn")
527-
monitor.synchronized {
528-
monitor.wait()
529-
}
530-
true
531-
} else false
532-
}
533-
534-
val waitList = new TrieMap[Thread, Thread]()
535-
536511
/** The loader that loads the members of _root_ */
537512
def rootLoader(root: TermSymbol)(implicit ctx: Context): SymbolLoader = platform.rootLoader(root)
538513

src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 28 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package dotty.tools
22
package dotc
33
package core
44

5-
import java.util.concurrent.atomic.AtomicReference
6-
75
import Periods._, Contexts._, Symbols._, Denotations._, Names._, NameOps._, Annotations._
86
import Types._, Flags._, Decorators._, DenotTransformers._, StdNames._, Scopes._
97
import NameOps._
@@ -88,7 +86,6 @@ object SymDenotations {
8886
// ------ Getting and setting fields -----------------------------
8987

9088
private[this] var myFlags: FlagSet = adaptFlags(initFlags)
91-
private[this] val initializingThread: AtomicReference[Thread] = new AtomicReference[Thread](null)
9289
private[this] var myInfo: Type = initInfo
9390
private[this] var myPrivateWithin: Symbol = initPrivateWithin
9491
private[this] var myAnnotations: List[Annotation] = Nil
@@ -166,52 +163,27 @@ object SymDenotations {
166163
}
167164

168165
private def completeFrom(completer: LazyType)(implicit ctx: Context): Unit = {
169-
170-
// if (myFlags is Touched) throw CyclicReference(this)
171-
val touched = myFlags is Touched
166+
if (completions ne noPrinter) {
167+
completions.println(i"${" " * indent}completing ${if (isType) "type" else "val"} $name")
168+
indent += 1
169+
}
170+
indent += 1
171+
if (myFlags is Touched) throw CyclicReference(this)
172172
myFlags |= Touched
173-
val curThread = initializingThread.get()
174-
if (curThread eq Thread.currentThread())
175-
throw CyclicReference(this)
176-
if ((curThread ne null)) {
177-
val noCycle = ctx.addToWaitList(curThread, this)
178-
if (!noCycle) {
179-
println("yesCycle")
180-
throw CyclicReference(this)
181-
}
182-
info
183-
} else if (initializingThread.compareAndSet(null, Thread.currentThread())) {
184173

174+
// completions.println(s"completing ${this.debugString}")
175+
try completer.complete(this)(ctx.withPhase(validFor.firstPhaseId))
176+
catch {
177+
case ex: CyclicReference =>
178+
completions.println(s"error while completing ${this.debugString}")
179+
throw ex
180+
}
181+
finally
185182
if (completions ne noPrinter) {
186-
completions.println(i"${" " * indent}completing ${if (isType) "type" else "val"} $name")
187-
indent += 1
188-
}
189-
indent += 1
190-
191-
// completions.println(s"completing ${this.debugString}")
192-
this.synchronized {
193-
try {
194-
completer.complete(this)(ctx.withPhase(validFor.firstPhaseId))
195-
}
196-
catch {
197-
case ex: CyclicReference =>
198-
completions.println(s"error while completing ${this.debugString}")
199-
throw ex
200-
}
201-
finally {
202-
if (completions ne noPrinter) {
203-
indent -= 1
204-
completions.println(i"${" " * indent}completed $name in $owner")
205-
}
206-
val oldV = initializingThread.get()
207-
assert(oldV == Thread.currentThread())
208-
initializingThread.set(null)
209-
210-
this.notifyAll()
211-
}
183+
indent -= 1
184+
completions.println(i"${" " * indent}completed $name in $owner")
212185
}
213-
// completions.println(s"completed ${this.debugString}")
214-
} else info
186+
// completions.println(s"completed ${this.debugString}")
215187
}
216188

217189
protected[dotc] def info_=(tp: Type) = {
@@ -1642,20 +1614,18 @@ object SymDenotations {
16421614
/*>|>*/ ctx.debugTraceIndented(s"$tp.baseTypeRef($this)") /*<|<*/ {
16431615
tp match {
16441616
case tp: CachedType =>
1645-
this.synchronized {
1646-
checkBasesUpToDate()
1647-
var basetp = baseTypeRefCache get tp
1648-
if (basetp == null) {
1649-
baseTypeRefCache.put(tp, NoPrefix)
1650-
basetp = computeBaseTypeRefOf(tp)
1651-
if (isCachable(tp)) baseTypeRefCache.put(tp, basetp)
1652-
else baseTypeRefCache.remove(tp)
1653-
} else if (basetp == NoPrefix) {
1654-
baseTypeRefCache.put(tp, null)
1655-
throw CyclicReference(this)
1656-
}
1657-
basetp
1617+
checkBasesUpToDate()
1618+
var basetp = baseTypeRefCache get tp
1619+
if (basetp == null) {
1620+
baseTypeRefCache.put(tp, NoPrefix)
1621+
basetp = computeBaseTypeRefOf(tp)
1622+
if (isCachable(tp)) baseTypeRefCache.put(tp, basetp)
1623+
else baseTypeRefCache.remove(tp)
1624+
} else if (basetp == NoPrefix) {
1625+
baseTypeRefCache.put(tp, null)
1626+
throw CyclicReference(this)
16581627
}
1628+
basetp
16591629
case _ =>
16601630
computeBaseTypeRefOf(tp)
16611631
}

src/dotty/tools/dotc/core/SymbolLoaders.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ class SymbolLoaders {
156156
val pre = root.owner.thisType
157157
root.info = ClassInfo(pre, root.symbol.asClass, Nil, currentDecls, pre select sourceModule)
158158
if (!sourceModule.isCompleted)
159-
sourceModule.completer.complete(sourceModule) // todo: am I sure that this gets executed only by a single thread?
160-
//sourceModule.info
159+
sourceModule.completer.complete(sourceModule)
161160
if (!root.isRoot) {
162161
for (classRep <- classpath.classes)
163162
if (!maybeModuleClass(classRep))

src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3285,9 +3285,7 @@ object Types {
32853285

32863286
class CyclicReference private (val denot: SymDenotation)
32873287
extends TypeError(s"cyclic reference involving $denot") {
3288-
val thread = Thread.currentThread()
3289-
val stack = new Exception()
3290-
def show(implicit ctx: Context) = s"cyclic reference involving ${denot.show} in $thread. Stack: ${stack.getStackTrace.mkString("\n")}"
3288+
def show(implicit ctx: Context) = s"cyclic reference involving ${denot.show}"
32913289
}
32923290

32933291
object CyclicReference {

src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,10 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
369369
}
370370

371371
protected def atReadPos[T](start: Int, op: () => T): T = {
372-
this.synchronized {
373-
val savedIndex = readIndex
374-
readIndex = start
375-
try op()
376-
finally readIndex = savedIndex
377-
}
372+
val savedIndex = readIndex
373+
readIndex = start
374+
try op()
375+
finally readIndex = savedIndex
378376
}
379377

380378
/** Read a name */

src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
108108
tree match {
109109
case tree: TypeTree =>
110110
tree
111-
case tree: TypedAsync =>
112-
tree.trees.head
113111
case AppliedTypeTree(tycon, args) =>
114112
val tparams = tycon.tpe.typeSymbol.typeParams
115113
val bounds = tparams.map(tparam =>

src/dotty/tools/dotc/typer/FrontEnd.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ class FrontEnd extends Phase {
6868
unitContexts foreach (enterSyms(_))
6969
unitContexts foreach (typeCheck(_))
7070
record("totalTrees", ast.Trees.ntrees)
71-
val res = unitContexts.map(_.compilationUnit).filterNot(discardAfterTyper)
72-
ctx.executors.awaitQuiescence(1, java.util.concurrent.TimeUnit.DAYS)
73-
res
71+
unitContexts.map(_.compilationUnit).filterNot(discardAfterTyper)
7472
}
7573

7674
override def run(implicit ctx: Context): Unit = {

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -910,11 +910,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
910910
assignType(cpy.ValDef(vdef)(name, tpt1, rhs1), sym)
911911
}
912912

913-
914-
915913
def typedDefDef(ddef: untpd.DefDef, sym: Symbol)(implicit ctx: Context) = track("typedDefDef") {
916914
val DefDef(name, tparams, vparamss, tpt, _) = ddef
917-
918915
completeAnnotations(ddef, sym)
919916
val tparams1 = tparams mapconserve (typed(_).asInstanceOf[TypeDef])
920917
// for secondary constructors we need to use that their type parameters
@@ -927,20 +924,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
927924
val vparamss1 = vparamss nestedMapconserve (typed(_).asInstanceOf[ValDef])
928925
if (sym is Implicit) checkImplicitParamsNotSingletons(vparamss1)
929926
val tpt1 = checkSimpleKinded(typedType(tpt))
930-
931-
val typedAhead = expanded(ddef.rhs).getAttachment(TypedAhead)
932-
933-
if (typedAhead.isDefined || ddef.rhs.isEmpty) {
934-
val rhs1 = typedExpr(ddef.rhs, tpt1.tpe)
935-
936-
assignType(cpy.DefDef(ddef)(name, tparams1, vparamss1, tpt1, rhs1), sym)
937-
} else {
938-
939-
val asyncTree = new tpd.TypedAsync(ddef.rhs, tpt1.tpe, ctx.fresh.setNewTyperState)
940-
ctx.executors.execute(new Runnable{def run = asyncTree.trees})
941-
942-
assignType(cpy.DefDef(ddef)(name, tparams1, vparamss1, tpt1, asyncTree), sym)
943-
}
927+
val rhs1 = typedExpr(ddef.rhs, tpt1.tpe)
928+
assignType(cpy.DefDef(ddef)(name, tparams1, vparamss1, tpt1, rhs1), sym)
944929
//todo: make sure dependent method types do not depend on implicits or by-name params
945930
}
946931

0 commit comments

Comments
 (0)