Skip to content

Commit 94dceed

Browse files
Use compiletime.uninitialized in compiler (#18823)
2 parents dc1e35a + 38b0168 commit 94dceed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+216
-141
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import scala.tools.asm
99
import scala.tools.asm.AnnotationVisitor
1010
import scala.tools.asm.ClassWriter
1111
import scala.collection.mutable
12+
import scala.compiletime.uninitialized
1213

1314
import dotty.tools.dotc.CompilationUnit
1415
import dotty.tools.dotc.ast.tpd
@@ -576,7 +577,7 @@ trait BCodeHelpers extends BCodeIdiomatic {
576577
/* builder of mirror classes */
577578
class JMirrorBuilder extends JCommonBuilder {
578579

579-
private var cunit: CompilationUnit = _
580+
private var cunit: CompilationUnit = uninitialized
580581
def getCurrentCUnit(): CompilationUnit = cunit;
581582

582583
/* Generate a mirror class for a top-level module. A mirror class is a class

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Contexts._
99
import Symbols._
1010
import dotty.tools.io._
1111
import scala.collection.mutable
12+
import scala.compiletime.uninitialized
1213

1314
class GenBCode extends Phase { self =>
1415

@@ -25,7 +26,7 @@ class GenBCode extends Phase { self =>
2526
private val entryPoints = new mutable.HashSet[String]()
2627
def registerEntryPoint(s: String): Unit = entryPoints += s
2728

28-
private var _backendInterface: DottyBackendInterface = _
29+
private var _backendInterface: DottyBackendInterface = uninitialized
2930
def backendInterface(using ctx: Context): DottyBackendInterface = {
3031
if _backendInterface eq null then
3132
// Enforce usage of FreshContext so we would be able to modify compilation unit between runs
@@ -36,7 +37,7 @@ class GenBCode extends Phase { self =>
3637
_backendInterface
3738
}
3839

39-
private var _codeGen: CodeGen = _
40+
private var _codeGen: CodeGen = uninitialized
4041
def codeGen(using Context): CodeGen = {
4142
if _codeGen eq null then
4243
val int = backendInterface
@@ -45,28 +46,28 @@ class GenBCode extends Phase { self =>
4546
_codeGen
4647
}
4748

48-
private var _bTypes: BTypesFromSymbols[DottyBackendInterface] = _
49+
private var _bTypes: BTypesFromSymbols[DottyBackendInterface] = uninitialized
4950
def bTypes(using Context): BTypesFromSymbols[DottyBackendInterface] = {
5051
if _bTypes eq null then
5152
_bTypes = BTypesFromSymbols(backendInterface, frontendAccess)
5253
_bTypes
5354
}
5455

55-
private var _frontendAccess: PostProcessorFrontendAccess | Null = _
56+
private var _frontendAccess: PostProcessorFrontendAccess | Null = uninitialized
5657
def frontendAccess(using Context): PostProcessorFrontendAccess = {
5758
if _frontendAccess eq null then
5859
_frontendAccess = PostProcessorFrontendAccess.Impl(backendInterface, entryPoints)
5960
_frontendAccess.nn
6061
}
6162

62-
private var _postProcessor: PostProcessor | Null = _
63+
private var _postProcessor: PostProcessor | Null = uninitialized
6364
def postProcessor(using Context): PostProcessor = {
6465
if _postProcessor eq null then
6566
_postProcessor = new PostProcessor(frontendAccess, bTypes)
6667
_postProcessor.nn
6768
}
6869

69-
private var _generatedClassHandler: GeneratedClassHandler | Null = _
70+
private var _generatedClassHandler: GeneratedClassHandler | Null = uninitialized
7071
def generatedClassHandler(using Context): GeneratedClassHandler = {
7172
if _generatedClassHandler eq null then
7273
_generatedClassHandler = GeneratedClassHandler(postProcessor)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import dotty.tools.dotc.core.Phases
1515
import dotty.tools.dotc.core.Decorators.em
1616

1717
import scala.language.unsafeNulls
18+
import scala.compiletime.uninitialized
1819

1920
/**
2021
* Interface to handle post-processing and classfile writing (see [[PostProcessor]]) of generated
@@ -185,7 +186,7 @@ final private class CompilationUnitInPostProcess(private var classes: List[Gener
185186
}
186187

187188
/** the main async task submitted onto the scheduler */
188-
var task: Future[Unit] = _
189+
var task: Future[Unit] = uninitialized
189190

190191
val bufferedReporting = new PostProcessorFrontendAccess.BufferingBackendReporting()
191192
}

compiler/src/dotty/tools/backend/sjs/JSDefinitions.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Symbols._
1212
import StdNames._
1313

1414
import dotty.tools.dotc.config.SJSPlatform
15+
import scala.compiletime.uninitialized
1516

1617
object JSDefinitions {
1718
/** The Scala.js-specific definitions for the current context. */
@@ -249,7 +250,7 @@ final class JSDefinitions()(using Context) {
249250
@threadUnsafe lazy val Selectable_reflectiveSelectableFromLangReflectiveCallsR = SelectableModule.requiredMethodRef("reflectiveSelectableFromLangReflectiveCalls")
250251
def Selectable_reflectiveSelectableFromLangReflectiveCalls(using Context) = Selectable_reflectiveSelectableFromLangReflectiveCallsR.symbol
251252

252-
private var allRefClassesCache: Set[Symbol] = _
253+
private var allRefClassesCache: Set[Symbol] = uninitialized
253254
def allRefClasses(using Context): Set[Symbol] = {
254255
if (allRefClassesCache == null) {
255256
val baseNames = List("Object", "Boolean", "Character", "Byte", "Short",

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import reporting.Reporter
66
import io.AbstractFile
77

88
import scala.annotation.internal.sharable
9+
import scala.compiletime.uninitialized
910

1011
/** A main class for running compiler benchmarks. Can instantiate a given
1112
* number of compilers and run each (sequentially) a given number of times
@@ -17,7 +18,7 @@ object Bench extends Driver:
1718
@sharable private var numCompilers = 1
1819
@sharable private var waitAfter = -1
1920
@sharable private var curCompiler = 0
20-
@sharable private var times: Array[Int] = _
21+
@sharable private var times: Array[Int] = uninitialized
2122

2223
override def doCompile(compiler: Compiler, files: List[AbstractFile])(using Context): Reporter =
2324
var reporter: Reporter = emptyReporter

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
6565

6666
private var myUnits: List[CompilationUnit] = Nil
6767
private var myUnitsCached: List[CompilationUnit] = Nil
68-
private var myFiles: Set[AbstractFile] = _
68+
private var myFiles: Set[AbstractFile] = uninitialized
6969

7070
// `@nowarn` annotations by source file, populated during typer
7171
private val mySuppressions: mutable.LinkedHashMap[SourceFile, mutable.ListBuffer[Suppression]] = mutable.LinkedHashMap.empty
@@ -511,7 +511,7 @@ object Run {
511511
var currentCompletedSubtraversalCount: Int = 0 // completed subphases in the current phase
512512
var seenPhaseCount: Int = 0 // how many phases we've seen so far
513513

514-
private var currPhase: Phase = uninitialized // initialized by enterPhase
514+
private var currPhase: Phase = uninitialized // initialized by enterPhase
515515
private var subPhases: SubPhases = uninitialized // initialized by enterPhase
516516
private var currPhaseName: String = uninitialized // initialized by enterPhase
517517
private var nextPhaseName: String = uninitialized // initialized by enterPhase

compiler/src/dotty/tools/dotc/ast/Positioned.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ import ast.Trees.mods
1313
import annotation.constructorOnly
1414
import annotation.internal.sharable
1515

16+
import scala.compiletime.uninitialized
17+
1618
/** A base class for things that have positions (currently: modifiers and trees)
1719
*/
1820
abstract class Positioned(implicit @constructorOnly src: SourceFile) extends SrcPos, Product, Cloneable {
1921
import Positioned.{ids, nextId, debugId}
2022

21-
private var mySpan: Span = _
23+
private var mySpan: Span = uninitialized
2224

2325
private var mySource: SourceFile = src
2426

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import typer.ConstFold
1818

1919
import scala.annotation.tailrec
2020
import scala.collection.mutable.ListBuffer
21+
import scala.compiletime.uninitialized
2122

2223
/** Some creators for typed trees */
2324
object tpd extends Trees.Instance[Type] with TypedTreeInfo {
@@ -1309,7 +1310,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
13091310
trait TreeProvider {
13101311
protected def computeRootTrees(using Context): List[Tree]
13111312

1312-
private var myTrees: List[Tree] | Null = _
1313+
private var myTrees: List[Tree] | Null = uninitialized
13131314

13141315
/** Get trees defined by this provider. Cache them if -Yretain-trees is set. */
13151316
def rootTrees(using Context): List[Tree] =

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package core
33

44
import Contexts._
55
import config.Printers.{default, typr}
6+
import scala.compiletime.uninitialized
67

78
trait ConstraintRunInfo { self: Run =>
89
private var maxSize = 0
9-
private var maxConstraint: Constraint | Null = _
10+
private var maxConstraint: Constraint | Null = uninitialized
1011
def recordConstraintSize(c: Constraint, size: Int): Unit =
1112
if (size > maxSize) {
1213
maxSize = size

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ object Contexts {
558558
private var _owner: Symbol = uninitialized
559559
final def owner: Symbol = _owner
560560

561-
private var _tree: Tree[?]= _
561+
private var _tree: Tree[?] = uninitialized
562562
final def tree: Tree[?] = _tree
563563

564564
private var _scope: Scope = uninitialized

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import cc.{CaptureSet, RetainingType}
2020
import ast.tpd.ref
2121

2222
import scala.annotation.tailrec
23+
import scala.compiletime.uninitialized
2324

2425
object Definitions {
2526

@@ -44,7 +45,7 @@ object Definitions {
4445
class Definitions {
4546
import Definitions._
4647

47-
private var initCtx: Context = _
48+
private var initCtx: Context = uninitialized
4849
private given currentContext[Dummy_so_its_a_def]: Context = initCtx
4950

5051
private def newPermanentSymbol[N <: Name](owner: Symbol, name: N, flags: FlagSet, info: Type) =
@@ -2001,7 +2002,7 @@ class Definitions {
20012002

20022003
class PerRun[T](generate: Context ?=> T) {
20032004
private var current: RunId = NoRunId
2004-
private var cached: T = _
2005+
private var cached: T = uninitialized
20052006
def apply()(using Context): T = {
20062007
if (current != ctx.runId) {
20072008
cached = generate

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import util.common._
2424
import typer.ProtoTypes.NoViewsAllowed
2525
import collection.mutable.ListBuffer
2626

27+
import scala.compiletime.uninitialized
28+
2729
/** Denotations represent the meaning of symbols and named types.
2830
* The following diagram shows how the principal types of denotations
2931
* and their denoting entities relate to each other. Lines ending in
@@ -121,8 +123,8 @@ object Denotations {
121123
/** Map `f` over all single denotations and aggregate the results with `g`. */
122124
def aggregate[T](f: SingleDenotation => T, g: (T, T) => T): T
123125

124-
private var cachedPrefix: Type = _
125-
private var cachedAsSeenFrom: AsSeenFromResult = _
126+
private var cachedPrefix: Type = uninitialized
127+
private var cachedAsSeenFrom: AsSeenFromResult = uninitialized
126128
private var validAsSeenFrom: Period = Nowhere
127129

128130
type AsSeenFromResult <: PreDenotation

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import annotation.tailrec
1414
import annotation.internal.sharable
1515
import cc.{CapturingType, derivedCapturingType}
1616

17+
import scala.compiletime.uninitialized
18+
1719
object OrderingConstraint {
1820

1921
/** If true, use reverse dependencies in `replace` to avoid checking the bounds
@@ -881,7 +883,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
881883
i += 1
882884
}
883885

884-
private var myUninstVars: mutable.ArrayBuffer[TypeVar] | Null = _
886+
private var myUninstVars: mutable.ArrayBuffer[TypeVar] | Null = uninitialized
885887

886888
/** The uninstantiated typevars of this constraint */
887889
def uninstVars: collection.Seq[TypeVar] = {

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

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import typer.ImportInfo.withRootImports
2121
import ast.{tpd, untpd}
2222
import scala.annotation.internal.sharable
2323
import scala.util.control.NonFatal
24+
import scala.compiletime.uninitialized
2425

2526
object Phases {
2627

@@ -205,30 +206,30 @@ object Phases {
205206
if nextDenotTransformerId(i) == phase.id then
206207
nextDenotTransformerId(i) = nextDenotTransformerId(phase.id + 1)
207208

208-
private var myParserPhase: Phase = _
209-
private var myTyperPhase: Phase = _
210-
private var myPostTyperPhase: Phase = _
211-
private var mySbtExtractDependenciesPhase: Phase = _
212-
private var myPicklerPhase: Phase = _
213-
private var myInliningPhase: Phase = _
214-
private var myStagingPhase: Phase = _
215-
private var mySplicingPhase: Phase = _
216-
private var myFirstTransformPhase: Phase = _
217-
private var myCollectNullableFieldsPhase: Phase = _
218-
private var myRefChecksPhase: Phase = _
219-
private var myPatmatPhase: Phase = _
220-
private var myElimRepeatedPhase: Phase = _
221-
private var myElimByNamePhase: Phase = _
222-
private var myExtensionMethodsPhase: Phase = _
223-
private var myExplicitOuterPhase: Phase = _
224-
private var myGettersPhase: Phase = _
225-
private var myErasurePhase: Phase = _
226-
private var myElimErasedValueTypePhase: Phase = _
227-
private var myLambdaLiftPhase: Phase = _
228-
private var myCountOuterAccessesPhase: Phase = _
229-
private var myFlattenPhase: Phase = _
230-
private var myGenBCodePhase: Phase = _
231-
private var myCheckCapturesPhase: Phase = _
209+
private var myParserPhase: Phase = uninitialized
210+
private var myTyperPhase: Phase = uninitialized
211+
private var myPostTyperPhase: Phase = uninitialized
212+
private var mySbtExtractDependenciesPhase: Phase = uninitialized
213+
private var myPicklerPhase: Phase = uninitialized
214+
private var myInliningPhase: Phase = uninitialized
215+
private var myStagingPhase: Phase = uninitialized
216+
private var mySplicingPhase: Phase = uninitialized
217+
private var myFirstTransformPhase: Phase = uninitialized
218+
private var myCollectNullableFieldsPhase: Phase = uninitialized
219+
private var myRefChecksPhase: Phase = uninitialized
220+
private var myPatmatPhase: Phase = uninitialized
221+
private var myElimRepeatedPhase: Phase = uninitialized
222+
private var myElimByNamePhase: Phase = uninitialized
223+
private var myExtensionMethodsPhase: Phase = uninitialized
224+
private var myExplicitOuterPhase: Phase = uninitialized
225+
private var myGettersPhase: Phase = uninitialized
226+
private var myErasurePhase: Phase = uninitialized
227+
private var myElimErasedValueTypePhase: Phase = uninitialized
228+
private var myLambdaLiftPhase: Phase = uninitialized
229+
private var myCountOuterAccessesPhase: Phase = uninitialized
230+
private var myFlattenPhase: Phase = uninitialized
231+
private var myGenBCodePhase: Phase = uninitialized
232+
private var myCheckCapturesPhase: Phase = uninitialized
232233

233234
final def parserPhase: Phase = myParserPhase
234235
final def typerPhase: Phase = myTyperPhase
@@ -389,7 +390,7 @@ object Phases {
389390
def printingContext(ctx: Context): Context = ctx
390391

391392
private var myPeriod: Period = Periods.InvalidPeriod
392-
private var myBase: ContextBase = _
393+
private var myBase: ContextBase = uninitialized
393394
private var myErasedTypes = false
394395
private var myFlatClasses = false
395396
private var myRefChecked = false

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import printing.Printer
1919
import SymDenotations.NoDenotation
2020

2121
import collection.mutable
22+
import scala.compiletime.uninitialized
2223

2324
object Scopes {
2425

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import transform.TypeUtils._
2727
import cc.{CapturingType, derivedCapturingType}
2828

2929
import scala.annotation.internal.sharable
30+
import scala.compiletime.uninitialized
3031

3132
object SymDenotations {
3233

@@ -2431,7 +2432,7 @@ object SymDenotations {
24312432
initPrivateWithin: Symbol)
24322433
extends ClassDenotation(symbol, ownerIfExists, name, initFlags, initInfo, initPrivateWithin) {
24332434

2434-
private var packageObjsCache: List[ClassDenotation] = _
2435+
private var packageObjsCache: List[ClassDenotation] = uninitialized
24352436
private var packageObjsRunId: RunId = NoRunId
24362437
private var ambiguityWarningIssued: Boolean = false
24372438

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import scala.annotation.internal.sharable
3333
import config.Printers.typr
3434
import dotty.tools.dotc.classpath.FileUtils.isScalaBinary
3535

36+
import scala.compiletime.uninitialized
37+
3638
object Symbols {
3739

3840
implicit def eqSymbol: CanEqual[Symbol, Symbol] = CanEqual.derived
@@ -88,7 +90,7 @@ object Symbols {
8890
ctx.settings.YcheckInitGlobal.value
8991

9092
/** The last denotation of this symbol */
91-
private var lastDenot: SymDenotation = _
93+
private var lastDenot: SymDenotation = uninitialized
9294
private var checkedPeriod: Period = Nowhere
9395

9496
private[core] def invalidateDenotCache(): Unit = { checkedPeriod = Nowhere }

0 commit comments

Comments
 (0)