Skip to content

Commit 64247c1

Browse files
committed
Make a new fresh name creator for each unit
Needed to make builds deterministic.
1 parent f6e454b commit 64247c1

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

src/dotty/tools/dotc/Compiler.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ import Scopes._
99
import typer.{FrontEnd, Typer, Mode, ImportInfo, RefChecks}
1010
import reporting.{Reporter, ConsoleReporter}
1111
import Phases.Phase
12-
import dotty.tools.dotc.transform._
13-
import dotty.tools.dotc.transform.TreeTransforms.{TreeTransform, TreeTransformer}
14-
import dotty.tools.dotc.core.DenotTransformers.DenotTransformer
15-
import dotty.tools.dotc.core.Denotations.SingleDenotation
16-
12+
import transform._
13+
import transform.TreeTransforms.{TreeTransform, TreeTransformer}
14+
import core.DenotTransformers.DenotTransformer
15+
import core.Denotations.SingleDenotation
1716

1817
import dotty.tools.backend.jvm.{LabelDefs, GenBCode}
1918

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ object Contexts {
153153
protected def gadt_=(gadt: GADTMap) = _gadt = gadt
154154
def gadt: GADTMap = _gadt
155155

156+
/**The current fresh name creator */
157+
private[this] var _freshNames: FreshNameCreator = _
158+
protected def freshNames_=(freshNames: FreshNameCreator) = _freshNames = freshNames
159+
def freshNames: FreshNameCreator = _freshNames
160+
161+
def freshName(prefix: String = ""): String = freshNames.newName(prefix)
162+
def freshName(prefix: Name): String = freshName(prefix.toString)
163+
156164
/** A map in which more contextual properties can be stored */
157165
private var _moreProperties: Map[String, Any] = _
158166
protected def moreProperties_=(moreProperties: Map[String, Any]) = _moreProperties = moreProperties
@@ -423,6 +431,7 @@ object Contexts {
423431
def setDiagnostics(diagnostics: Option[StringBuilder]): this.type = { this.diagnostics = diagnostics; this }
424432
def setTypeComparerFn(tcfn: Context => TypeComparer): this.type = { this.typeComparer = tcfn(this); this }
425433
def setSearchHistory(searchHistory: SearchHistory): this.type = { this.searchHistory = searchHistory; this }
434+
def setFreshNames(freshNames: FreshNameCreator): this.type = { this.freshNames = freshNames; this }
426435
def setMoreProperties(moreProperties: Map[String, Any]): this.type = { this.moreProperties = moreProperties; this }
427436

428437
def setProperty(prop: (String, Any)): this.type = setMoreProperties(moreProperties + prop)
@@ -468,6 +477,7 @@ object Contexts {
468477
typeAssigner = TypeAssigner
469478
runInfo = new RunInfo(this)
470479
diagnostics = None
480+
freshNames = new FreshNameCreator.Default
471481
moreProperties = Map.empty
472482
typeComparer = new TypeComparer(this)
473483
searchHistory = new SearchHistory(0, Map())
@@ -498,12 +508,6 @@ object Contexts {
498508
/** The platform */
499509
val platform: Platform = new JavaPlatform
500510

501-
/** The standard fresh name creator */
502-
val freshNames = new FreshNameCreator.Default
503-
504-
def freshName(prefix: String = ""): String = freshNames.newName(prefix)
505-
def freshName(prefix: Name): String = freshName(prefix.toString)
506-
507511
/** The loader that loads the members of _root_ */
508512
def rootLoader(root: TermSymbol)(implicit ctx: Context): SymbolLoader = platform.rootLoader(root)
509513

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import parsing.Parsers.Parser
99
import config.Printers._
1010
import util.Stats._
1111
import scala.util.control.NonFatal
12+
import util.FreshNameCreator
1213

1314
class FrontEnd extends Phase {
1415

@@ -46,7 +47,8 @@ class FrontEnd extends Phase {
4647
}
4748

4849
override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = {
49-
val unitContexts = units map (unit => ctx.fresh.setCompilationUnit(unit))
50+
val unitContexts = for (unit <- units) yield
51+
ctx.fresh.setCompilationUnit(unit).setFreshNames(new FreshNameCreator.Default)
5052
unitContexts foreach (parse(_))
5153
record("parsedTrees", ast.Trees.ntrees)
5254
unitContexts foreach (enterSyms(_))

0 commit comments

Comments
 (0)