Skip to content

Commit 992f200

Browse files
committed
use scratch type dependencies set
1 parent 3702fe9 commit 992f200

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,13 @@ private class ExtractDependenciesCollector(rec: DependencyRecorder) extends tpd.
232232
throw ex
233233
}
234234

235+
/**Reused EqHashSet, safe to use as each TypeDependencyTraverser is used atomically
236+
* Avoid cycles by remembering both the types (testcase:
237+
* tests/run/enum-values.scala) and the symbols of named types (testcase:
238+
* tests/pos-java-interop/i13575) we've seen before.
239+
*/
240+
private val scratchSeen = new util.EqHashSet[Symbol | Type](128)
241+
235242
/** Traverse a used type and record all the dependencies we need to keep track
236243
* of for incremental recompilation.
237244
*
@@ -268,15 +275,13 @@ private class ExtractDependenciesCollector(rec: DependencyRecorder) extends tpd.
268275
private abstract class TypeDependencyTraverser(using Context) extends TypeTraverser() {
269276
protected def addDependency(symbol: Symbol): Unit
270277

271-
// Avoid cycles by remembering both the types (testcase:
272-
// tests/run/enum-values.scala) and the symbols of named types (testcase:
273-
// tests/pos-java-interop/i13575) we've seen before.
274-
val seen = new util.EqHashSet[Symbol | Type](128) // 64 still needs to grow often for scala3-compiler
275-
def traverse(tp: Type): Unit = if seen.add(tp) then {
278+
scratchSeen.clear(resetToInitial = false)
279+
280+
def traverse(tp: Type): Unit = if scratchSeen.add(tp) then {
276281
tp match {
277282
case tp: NamedType =>
278283
val sym = tp.symbol
279-
if !sym.is(Package) && seen.add(sym) then
284+
if !sym.is(Package) && scratchSeen.add(sym) then
280285
addDependency(sym)
281286
if !sym.isClass then traverse(tp.info)
282287
traverse(tp.prefix)

0 commit comments

Comments
 (0)