Skip to content

Commit 92c9c55

Browse files
committed
Change ctx.run to nullable
1 parent 2492300 commit 92c9c55

20 files changed

+40
-37
lines changed

compiler/src/dotty/tools/backend/jvm/GenBCode.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class GenBCode extends Phase {
7575
try super.runOn(units)
7676
finally outputDir match {
7777
case jar: JarArchive =>
78-
if (ctx.run.suspendedUnits.nonEmpty)
78+
if (ctx.run.nn.suspendedUnits.nonEmpty)
7979
// If we close the jar the next run will not be able to write on the jar.
8080
// But if we do not close it we cannot use it as part of the macro classpath of the suspended files.
8181
report.error("Can not suspend and output to a jar at the same time. See suspension with -Xprint-suspension.")

compiler/src/dotty/tools/dotc/CompilationUnit.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class CompilationUnit protected (val source: SourceFile) {
7171
if (ctx.settings.XprintSuspension.value)
7272
report.echo(i"suspended: $this")
7373
suspended = true
74-
ctx.run.suspendedUnits += this
74+
ctx.run.nn.suspendedUnits += this
7575
if ctx.phase == Phases.inliningPhase then
7676
suspendedAtInliningPhase = true
7777
throw CompilationUnit.SuspendException()

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class Compiler {
152152

153153
def reset()(using Context): Unit = {
154154
ctx.base.reset()
155-
val run: Run | Null = ctx.run
155+
val run = ctx.run
156156
if (run != null) run.reset()
157157
}
158158

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ object Contexts {
4949
private val (printerFnLoc, store3) = store2.newLocation[Context => Printer](new RefinedPrinter(_))
5050
private val (settingsStateLoc, store4) = store3.newLocation[SettingsState]()
5151
private val (compilationUnitLoc, store5) = store4.newLocation[CompilationUnit]()
52-
private val (runLoc, store6) = store5.newLocation[Run]()
52+
private val (runLoc, store6) = store5.newLocation[Run | Null]()
5353
private val (profilerLoc, store7) = store6.newLocation[Profiler]()
5454
private val (notNullInfosLoc, store8) = store7.newLocation[List[NotNullInfo]]()
5555
private val (importInfoLoc, store9) = store8.newLocation[ImportInfo]()
@@ -227,7 +227,7 @@ object Contexts {
227227
def compilationUnit: CompilationUnit = store(compilationUnitLoc)
228228

229229
/** The current compiler-run */
230-
def run: Run = store(runLoc)
230+
def run: Run | Null = store(runLoc)
231231

232232
/** The current compiler-run profiler */
233233
def profiler: Profiler = store(profilerLoc)
@@ -655,7 +655,7 @@ object Contexts {
655655
def setSbtCallback(callback: AnalysisCallback): this.type = updateStore(sbtCallbackLoc, callback)
656656
def setPrinterFn(printer: Context => Printer): this.type = updateStore(printerFnLoc, printer)
657657
def setSettings(settingsState: SettingsState): this.type = updateStore(settingsStateLoc, settingsState)
658-
def setRun(run: Run): this.type = updateStore(runLoc, run)
658+
def setRun(run: Run | Null): this.type = updateStore(runLoc, run)
659659
def setProfiler(profiler: Profiler): this.type = updateStore(profilerLoc, profiler)
660660
def setNotNullInfos(notNullInfos: List[NotNullInfo]): this.type = updateStore(notNullInfosLoc, notNullInfos)
661661
def setImportInfo(importInfo: ImportInfo): this.type =

compiler/src/dotty/tools/dotc/core/Denotations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,7 @@ object Denotations {
13181318
recurSimple(path.length, wrap)
13191319
}
13201320

1321-
val run: Run | Null = ctx.run
1321+
val run = ctx.run
13221322
if run == null then recur(path)
13231323
else run.staticRefs.getOrElseUpdate(path, recur(path))
13241324
}

compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ object OrderingConstraint {
2929
empty
3030
else
3131
val result = new OrderingConstraint(boundsMap, lowerMap, upperMap)
32-
ctx.run.recordConstraintSize(result, result.boundsMap.size)
32+
ctx.run.nn.recordConstraintSize(result, result.boundsMap.size)
3333
result
3434

3535
/** A lens for updating a single entry array in one of the three constraint maps */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ class SourcefileLoader(val srcfile: AbstractFile) extends SymbolLoader {
426426
def description(using Context): String = "source file " + srcfile.toString
427427
override def sourceFileOrNull: AbstractFile | Null = srcfile
428428
def doComplete(root: SymDenotation)(using Context): Unit =
429-
ctx.run.lateCompile(srcfile, typeCheck = ctx.settings.YretainTrees.value)
429+
ctx.run.nn.lateCompile(srcfile, typeCheck = ctx.settings.YretainTrees.value)
430430
}
431431

432432
/** A NoCompleter which is also a SymbolLoader. */

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ object Symbols {
142142

143143
/** Does this symbol come from a currently compiled source file? */
144144
final def isDefinedInCurrentRun(using Context): Boolean =
145-
span.exists && defRunId == ctx.runId && associatedFileMatches(ctx.run.files.contains)
145+
span.exists && defRunId == ctx.runId && associatedFileMatches(ctx.run.nn.files.contains)
146146

147147
/** Is this symbol valid in the current run and has an associated file that is
148148
* not a binary file. e.g. This will return true for

compiler/src/dotty/tools/dotc/decompiler/IDEDecompilerDriver.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class IDEDecompilerDriver(val settings: List[String]) extends dotc.Driver {
3737
inContext(run.runContext) {
3838
run.compile(List(tastyFile))
3939
run.printSummary()
40-
val unit = ctx.run.units.head
40+
val unit = ctx.run.nn.units.head
4141

4242
val decompiled = QuotesImpl.showDecompiledTree(unit.tpdTree)
4343
val tree = new TastyHTMLPrinter(unit.pickled.head._2()).showContents()

compiler/src/dotty/tools/dotc/interactive/Completion.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ object Completion {
353353
val extMethodsFromGivensInScope = extractMemberExtensionMethods(givensInScope)
354354

355355
// 3. The reference is of the form r.m and the extension method is defined in the implicit scope of the type of r.
356-
val implicitScopeCompanions = ctx.run.implicitScope(qual.tpe).companionRefs.showAsList
356+
val implicitScopeCompanions = ctx.run.nn.implicitScope(qual.tpe).companionRefs.showAsList
357357
val extMethodsFromImplicitScope = extractMemberExtensionMethods(implicitScopeCompanions)
358358

359359
// 4. The reference is of the form r.m and the extension method is defined in some given instance in the implicit scope of the type of r.

compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ class InteractiveDriver(val settings: List[String]) extends Driver {
164164

165165
run.compileSources(List(source))
166166
run.printSummary()
167-
val unit = if ctx.run.units.nonEmpty then ctx.run.units.head else ctx.run.suspendedUnits.head
167+
val ctxrun = ctx.run.nn
168+
val unit = if ctxrun.units.nonEmpty then ctxrun.units.head else ctxrun.suspendedUnits.head
168169
val t = unit.tpdTree
169170
cleanup(t)
170171
myOpenedTrees(uri) = topLevelTrees(t, source)

compiler/src/dotty/tools/dotc/reporting/Reporter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ abstract class Reporter extends interfaces.ReporterResult {
181181
// `ctx.run` can be null in test, also in the repl when parsing the first line. The parser runs early, the Run is
182182
// only created in ReplDriver.compile when a line is submitted. This means that `@nowarn` doesnt work on parser
183183
// warnings in the first line.
184-
val run: Run | Null = ctx.run
184+
val run = ctx.run
185185
dia match
186186
case w: Warning if run != null =>
187187
val sup = run.suppressions

compiler/src/dotty/tools/dotc/transform/Inlining.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Inlining extends MacroTransform {
3030

3131
override def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] =
3232
val newUnits = super.runOn(units).filterNot(_.suspended)
33-
ctx.run.checkSuspendedUnits(newUnits)
33+
ctx.run.nn.checkSuspendedUnits(newUnits)
3434
newUnits
3535

3636
override def checkPostCondition(tree: Tree)(using Context): Unit =

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ trait Implicits:
10391039

10401040
/** Try to typecheck an implicit reference */
10411041
def typedImplicit(cand: Candidate, pt: Type, argument: Tree, span: Span)(using Context): SearchResult = trace(i"typed implicit ${cand.ref}, pt = $pt, implicitsEnabled == ${ctx.mode is ImplicitsEnabled}", implicits, show = true) {
1042-
if ctx.run.isCancelled then NoMatchingImplicitsFailure
1042+
if ctx.run.nn.isCancelled then NoMatchingImplicitsFailure
10431043
else
10441044
record("typedImplicit")
10451045
val ref = cand.ref
@@ -1503,7 +1503,7 @@ trait Implicits:
15031503
searchImplicit(contextual = true)
15041504
end bestImplicit
15051505

1506-
def implicitScope(tp: Type): OfTypeImplicits = ctx.run.implicitScope(tp)
1506+
def implicitScope(tp: Type): OfTypeImplicits = ctx.run.nn.implicitScope(tp)
15071507

15081508
/** All available implicits, without ranking */
15091509
def allImplicits: Set[TermRef] = {

compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ trait ImportSuggestions:
148148
*/
149149
private def importSuggestions(pt: Type)(using Context): (List[TermRef], List[TermRef]) =
150150
val timer = new Timer()
151-
val allotted = ctx.run.importSuggestionBudget
151+
val allotted = ctx.run.nn.importSuggestionBudget
152152
if allotted <= 1 then return (Nil, Nil)
153153
implicits.println(i"looking for import suggestions, timeout = ${allotted}ms")
154154
val start = System.currentTimeMillis()
@@ -160,7 +160,7 @@ trait ImportSuggestions:
160160
val alreadyAvailableCandidates: Set[Symbol] = {
161161
val wildProto = wildApprox(pt)
162162
val contextualCandidates = ctx.implicits.eligible(wildProto)
163-
val implicitScopeCandidates = ctx.run.implicitScope(wildProto).eligible
163+
val implicitScopeCandidates = ctx.run.nn.implicitScope(wildProto).eligible
164164
val allCandidates = contextualCandidates ++ implicitScopeCandidates
165165
allCandidates.map(_.implicitRef.underlyingRef.symbol).toSet
166166
}
@@ -196,7 +196,7 @@ trait ImportSuggestions:
196196
val task = new TimerTask:
197197
def run() =
198198
println(i"Cancelling test of $ref when making suggestions for error in ${ctx.source}")
199-
ctx.run.isCancelled = true
199+
ctx.run.nn.isCancelled = true
200200
val span = ctx.owner.srcPos.span
201201
val (expectedType, argument, kind) = pt match
202202
case ViewProto(argType, resType) =>
@@ -212,11 +212,12 @@ trait ImportSuggestions:
212212
typedImplicit(candidate, expectedType, argument, span)(
213213
using testContext()).isSuccess
214214
finally
215+
val run = ctx.run.nn
215216
if task.cancel() then // timer task has not run yet
216-
assert(!ctx.run.isCancelled)
217+
assert(!run.isCancelled)
217218
else
218-
while !ctx.run.isCancelled do () // wait until timer task has run to completion
219-
ctx.run.isCancelled = false
219+
while !run.isCancelled do () // wait until timer task has run to completion
220+
run.isCancelled = false
220221
}
221222
end deepTest
222223

@@ -265,8 +266,9 @@ trait ImportSuggestions:
265266
* for current search, but but never less than to half of the previous budget.
266267
*/
267268
private def reduceTimeBudget(used: Int)(using Context) =
268-
ctx.run.importSuggestionBudget =
269-
(ctx.run.importSuggestionBudget - used) max (ctx.run.importSuggestionBudget / 2)
269+
val run = ctx.run.nn
270+
run.importSuggestionBudget =
271+
(run.importSuggestionBudget - used) max (run.importSuggestionBudget / 2)
270272

271273
/** The `ref` parts of this list of pairs, discarding subsequent elements that
272274
* have the same String part. Elements are sorted by their String parts.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,7 +2184,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
21842184
val sup = Suppression(tree.sourcePos, filters, range.start, range.end, verbose)
21852185
// invalid suppressions, don't report as unused
21862186
if filters == List(MessageFilter.None) then sup.markUsed()
2187-
ctx.run.suppressions.addSuppression(sup)
2187+
ctx.run.nn.suppressions.addSuppression(sup)
21882188

21892189
def typedValDef(vdef: untpd.ValDef, sym: Symbol)(using Context): Tree = {
21902190
val ValDef(name, tpt, _) = vdef
@@ -2937,7 +2937,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
29372937
assertPositioned(tree)
29382938
if tree.source != ctx.source && tree.source.exists then
29392939
typed(tree, pt, locked)(using ctx.withSource(tree.source))
2940-
else if ctx.run.isCancelled then
2940+
else if ctx.run.nn.isCancelled then
29412941
tree.withType(WildcardType)
29422942
else adapt(typedUnadapted(tree, pt, locked), pt, locked)
29432943
}

compiler/src/dotty/tools/dotc/typer/TyperPhase.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class TyperPhase(addRootImports: Boolean = true) extends Phase {
4444
typr.println("typed: " + unit.source)
4545
record("retained untyped trees", unit.untpdTree.treeSize)
4646
record("retained typed trees after typer", unit.tpdTree.treeSize)
47-
ctx.run.suppressions.reportSuspendedMessages(unit.source)
47+
ctx.run.nn.suppressions.reportSuspendedMessages(unit.source)
4848
catch
4949
case ex: CompilationUnit.SuspendException =>
5050
}
@@ -86,7 +86,7 @@ class TyperPhase(addRootImports: Boolean = true) extends Phase {
8686
unitContexts.foreach(javaCheck(using _)) // after typechecking to avoid cycles
8787

8888
val newUnits = unitContexts.map(_.compilationUnit).filterNot(discardAfterTyper)
89-
ctx.run.checkSuspendedUnits(newUnits)
89+
ctx.run.nn.checkSuspendedUnits(newUnits)
9090
newUnits
9191

9292
def run(using Context): Unit = unsupported("run")

compiler/src/dotty/tools/dotc/util/Store.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@ object Store {
77
val empty: Store = new Store(Array())
88
}
99

10-
class Store(private val elems: Array[AnyRef]) extends AnyVal {
10+
class Store(private val elems: Array[AnyRef | Null]) extends AnyVal {
1111
import Store._
1212

1313
def newLocation[T](): (Location[T], Store) = {
14-
val elems1 = new Array[AnyRef](elems.length + 1)
14+
val elems1 = new Array[AnyRef | Null](elems.length + 1)
1515
System.arraycopy(elems, 0, elems1, 0, elems.length)
1616
(new Location(elems.length), new Store(elems1))
1717
}
1818

1919
def newLocation[T](initial: T): (Location[T], Store) = {
2020
val (loc, store) = newLocation[T]()
21-
store.elems(loc.idx) = initial.asInstanceOf[AnyRef]
21+
store.elems(loc.idx) = initial.asInstanceOf[AnyRef | Null]
2222
(loc, store)
2323
}
2424

2525
def updated[T](loc: Location[T], value: T): Store = {
2626
val elems1 = elems.clone
27-
elems1(loc.idx) = value.asInstanceOf[AnyRef]
27+
elems1(loc.idx) = value.asInstanceOf[AnyRef | Null]
2828
new Store(elems1)
2929
}
3030

compiler/src/dotty/tools/repl/ReplCompiler.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ class ReplCompiler extends Compiler {
163163

164164
private def runCompilationUnit(unit: CompilationUnit, state: State): Result[(CompilationUnit, State)] = {
165165
val ctx = state.context
166-
ctx.run.compileUnits(unit :: Nil)
167-
ctx.run.printSummary() // this outputs "2 errors found" like normal - but we might decide that's needlessly noisy for the REPL
166+
ctx.run.nn.compileUnits(unit :: Nil)
167+
ctx.run.nn.printSummary() // this outputs "2 errors found" like normal - but we might decide that's needlessly noisy for the REPL
168168

169169
if (!ctx.reporter.hasErrors) (unit, state).result
170170
else ctx.reporter.removeBufferedMessages(using ctx).errors
@@ -291,7 +291,7 @@ class ReplCompiler extends Compiler {
291291
wrapped(expr, src, state).flatMap { pkg =>
292292
val unit = CompilationUnit(src)
293293
unit.untpdTree = pkg
294-
ctx.run.compileUnits(unit :: Nil, ctx)
294+
ctx.run.nn.compileUnits(unit :: Nil, ctx)
295295

296296
if (errorsAllowed || !ctx.reporter.hasErrors)
297297
unwrapped(unit.tpdTree, src)

scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ case class ScaladocTastyInspector()(using ctx: DocContext) extends DocTastyInspe
3737
// however, path-dependent types disallow doing so w/o using casts
3838
inline def hackForeachTree(thunk: reflect.Tree => Unit): Unit =
3939
given dctx: dotc.core.Contexts.Context = quotes.asInstanceOf[scala.quoted.runtime.impl.QuotesImpl].ctx
40-
dctx.run.units.foreach { compilationUnit =>
40+
dctx.run.nn.units.foreach { compilationUnit =>
4141
// mirrors code from TastyInspector
4242
thunk(compilationUnit.tpdTree.asInstanceOf[reflect.Tree])
4343
}

0 commit comments

Comments
 (0)