@@ -42,8 +42,18 @@ object Contexts {
42
42
def nextTreeId : Int
43
43
}
44
44
45
+ private final val TreeIdChunkSize = 1024
46
+
47
+ /** Id generator for compiler-global trees that are not created in a context.
48
+ * We reserve the first chunk of ids for these
49
+ */
45
50
object GlobalTreeIds extends TreeIds {
46
- def nextTreeId = 0
51
+ private var _nextTreeId : Int = 0
52
+ def nextTreeId : Int = synchronized {
53
+ _nextTreeId += 1
54
+ assert(_nextTreeId < TreeIdChunkSize )
55
+ _nextTreeId
56
+ }
47
57
}
48
58
49
59
private val (compilerCallbackLoc, store1) = Store .empty.newLocation[CompilerCallback ]()
@@ -466,7 +476,13 @@ object Contexts {
466
476
def uniqueNamedTypes : Uniques .NamedTypeUniques = base.uniqueNamedTypes
467
477
def uniques : util.HashSet [Type ] = base.uniques
468
478
def nextSymId : Int = base.nextSymId
469
- def nextTreeId : Int = base.nextTreeId
479
+
480
+ def nextTreeId : Int = {
481
+ var id = base.nextTreeIdBySource.getOrElseUpdate(source, 0 )
482
+ if (id % TreeIdChunkSize == 0 ) id = base.reserveChunk()
483
+ base.nextTreeIdBySource(source) = id + 1
484
+ id
485
+ }
470
486
471
487
def initialize ()(implicit ctx : Context ): Unit = base.initialize()(ctx)
472
488
}
@@ -578,7 +594,6 @@ object Contexts {
578
594
579
595
@ sharable object NoContext extends Context {
580
596
val base : ContextBase = null
581
- override def nextTreeId = 0
582
597
override val implicits : ContextualImplicits = new ContextualImplicits (Nil , null )(this )
583
598
}
584
599
@@ -641,8 +656,13 @@ object Contexts {
641
656
private [core] var _nextSymId : Int = 0
642
657
def nextSymId : Int = { _nextSymId += 1 ; _nextSymId }
643
658
644
- private [dotc] var _nextTreeId : Int = 0
645
- def nextTreeId : Int = { _nextTreeId += 1 ; _nextTreeId }
659
+ private [this ] var chunksUsed : Int = 1
660
+ private [core] var nextTreeIdBySource = new mutable.HashMap [SourceFile , Int ]
661
+
662
+ /** Reserve a new chunk.
663
+ * @return First id address in that chunk
664
+ */
665
+ private [core] def reserveChunk (): Int = try chunksUsed * TreeIdChunkSize finally chunksUsed += 1
646
666
647
667
/** Sources that were loaded */
648
668
val sources : mutable.HashMap [AbstractFile , SourceFile ] = new mutable.HashMap [AbstractFile , SourceFile ]
@@ -720,6 +740,7 @@ object Contexts {
720
740
for ((_, set) <- uniqueSets) set.clear()
721
741
errorTypeMsg.clear()
722
742
sources.clear()
743
+ nextTreeIdBySource.clear()
723
744
}
724
745
725
746
// Test that access is single threaded
0 commit comments