From 38b0168cc2cbba99e39bab89e459bfea51bda783 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 2 Nov 2023 09:44:43 +0100 Subject: [PATCH] Use `compiletime.uninitialized` in compiler --- .../tools/backend/jvm/BCodeHelpers.scala | 3 +- .../dotty/tools/backend/jvm/GenBCode.scala | 13 ++--- .../backend/jvm/GeneratedClassHandler.scala | 3 +- .../tools/backend/sjs/JSDefinitions.scala | 3 +- compiler/src/dotty/tools/dotc/Bench.scala | 3 +- compiler/src/dotty/tools/dotc/Run.scala | 4 +- .../src/dotty/tools/dotc/ast/Positioned.scala | 4 +- compiler/src/dotty/tools/dotc/ast/tpd.scala | 3 +- .../tools/dotc/core/ConstraintRunInfo.scala | 3 +- .../src/dotty/tools/dotc/core/Contexts.scala | 2 +- .../dotty/tools/dotc/core/Definitions.scala | 5 +- .../dotty/tools/dotc/core/Denotations.scala | 6 ++- .../tools/dotc/core/OrderingConstraint.scala | 4 +- .../src/dotty/tools/dotc/core/Phases.scala | 51 ++++++++++--------- .../src/dotty/tools/dotc/core/Scopes.scala | 1 + .../tools/dotc/core/SymDenotations.scala | 3 +- .../src/dotty/tools/dotc/core/Symbols.scala | 4 +- .../dotty/tools/dotc/core/TyperState.scala | 19 +++---- .../src/dotty/tools/dotc/core/Types.scala | 28 +++++----- .../dotc/core/classfile/ClassfileParser.scala | 10 ++-- .../classfile/ClassfileTastyUUIDParser.scala | 3 +- .../dotc/core/tasty/PositionUnpickler.scala | 8 +-- .../tools/dotc/core/tasty/TreeUnpickler.scala | 3 +- .../tools/dotc/parsing/CharArrayReader.scala | 4 +- .../dotc/parsing/xml/MarkupParsers.scala | 3 +- .../dotc/parsing/xml/SymbolicXMLBuilder.scala | 3 +- .../dotty/tools/dotc/plugins/Plugins.scala | 6 ++- .../tools/dotc/sbt/ExtractDependencies.scala | 10 ++-- .../tools/dotc/transform/CapturedVars.scala | 4 +- .../dotty/tools/dotc/transform/CtxLazy.scala | 4 +- .../tools/dotc/transform/Dependencies.scala | 5 +- .../dotty/tools/dotc/transform/Flatten.scala | 4 +- .../dotc/transform/ForwardDepChecks.scala | 8 +-- .../dotc/transform/Instrumentation.scala | 12 +++-- .../tools/dotc/transform/LambdaLift.scala | 4 +- .../dotty/tools/dotc/transform/LazyVals.scala | 3 +- .../tools/dotc/transform/MegaPhase.scala | 8 +-- .../dotty/tools/dotc/transform/Memoize.scala | 3 +- .../dotc/transform/OverridingPairs.scala | 6 ++- .../dotty/tools/dotc/transform/TailRec.scala | 4 +- .../transform/sjs/ExplicitJSClasses.scala | 3 +- .../dotty/tools/dotc/typer/Implicits.scala | 3 +- .../dotty/tools/dotc/typer/ImportInfo.scala | 6 ++- .../src/dotty/tools/dotc/typer/Namer.scala | 3 +- .../tools/dotc/typer/VarianceChecker.scala | 4 +- .../tools/dotc/util/GenericHashMap.scala | 8 +-- .../tools/dotc/util/GenericHashSet.scala | 8 +-- .../src/dotty/tools/dotc/util/IntMap.scala | 4 +- .../tools/dotc/util/PerfectHashing.scala | 8 +-- .../dotty/tools/dotc/util/SourceFile.scala | 3 +- .../tools/repl/CollectTopLevelImports.scala | 4 +- compiler/src/dotty/tools/repl/Rendering.scala | 5 +- .../src/dotty/tools/repl/ReplDriver.scala | 9 ++-- .../tools/dotc/reporting/TestReporter.scala | 7 +-- .../tools/vulpix/RunnerOrchestration.scala | 5 +- 55 files changed, 216 insertions(+), 141 deletions(-) diff --git a/compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala b/compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala index c36c8c546635..3085c9411222 100644 --- a/compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala +++ b/compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala @@ -9,6 +9,7 @@ import scala.tools.asm import scala.tools.asm.AnnotationVisitor import scala.tools.asm.ClassWriter import scala.collection.mutable +import scala.compiletime.uninitialized import dotty.tools.dotc.CompilationUnit import dotty.tools.dotc.ast.tpd @@ -576,7 +577,7 @@ trait BCodeHelpers extends BCodeIdiomatic { /* builder of mirror classes */ class JMirrorBuilder extends JCommonBuilder { - private var cunit: CompilationUnit = _ + private var cunit: CompilationUnit = uninitialized def getCurrentCUnit(): CompilationUnit = cunit; /* Generate a mirror class for a top-level module. A mirror class is a class diff --git a/compiler/src/dotty/tools/backend/jvm/GenBCode.scala b/compiler/src/dotty/tools/backend/jvm/GenBCode.scala index 8c1691e88b80..6dcaaa23c61d 100644 --- a/compiler/src/dotty/tools/backend/jvm/GenBCode.scala +++ b/compiler/src/dotty/tools/backend/jvm/GenBCode.scala @@ -9,6 +9,7 @@ import Contexts._ import Symbols._ import dotty.tools.io._ import scala.collection.mutable +import scala.compiletime.uninitialized class GenBCode extends Phase { self => @@ -25,7 +26,7 @@ class GenBCode extends Phase { self => private val entryPoints = new mutable.HashSet[String]() def registerEntryPoint(s: String): Unit = entryPoints += s - private var _backendInterface: DottyBackendInterface = _ + private var _backendInterface: DottyBackendInterface = uninitialized def backendInterface(using ctx: Context): DottyBackendInterface = { if _backendInterface eq null then // Enforce usage of FreshContext so we would be able to modify compilation unit between runs @@ -36,7 +37,7 @@ class GenBCode extends Phase { self => _backendInterface } - private var _codeGen: CodeGen = _ + private var _codeGen: CodeGen = uninitialized def codeGen(using Context): CodeGen = { if _codeGen eq null then val int = backendInterface @@ -45,28 +46,28 @@ class GenBCode extends Phase { self => _codeGen } - private var _bTypes: BTypesFromSymbols[DottyBackendInterface] = _ + private var _bTypes: BTypesFromSymbols[DottyBackendInterface] = uninitialized def bTypes(using Context): BTypesFromSymbols[DottyBackendInterface] = { if _bTypes eq null then _bTypes = BTypesFromSymbols(backendInterface, frontendAccess) _bTypes } - private var _frontendAccess: PostProcessorFrontendAccess | Null = _ + private var _frontendAccess: PostProcessorFrontendAccess | Null = uninitialized def frontendAccess(using Context): PostProcessorFrontendAccess = { if _frontendAccess eq null then _frontendAccess = PostProcessorFrontendAccess.Impl(backendInterface, entryPoints) _frontendAccess.nn } - private var _postProcessor: PostProcessor | Null = _ + private var _postProcessor: PostProcessor | Null = uninitialized def postProcessor(using Context): PostProcessor = { if _postProcessor eq null then _postProcessor = new PostProcessor(frontendAccess, bTypes) _postProcessor.nn } - private var _generatedClassHandler: GeneratedClassHandler | Null = _ + private var _generatedClassHandler: GeneratedClassHandler | Null = uninitialized def generatedClassHandler(using Context): GeneratedClassHandler = { if _generatedClassHandler eq null then _generatedClassHandler = GeneratedClassHandler(postProcessor) diff --git a/compiler/src/dotty/tools/backend/jvm/GeneratedClassHandler.scala b/compiler/src/dotty/tools/backend/jvm/GeneratedClassHandler.scala index fc02d9597efe..f17f9d620d90 100644 --- a/compiler/src/dotty/tools/backend/jvm/GeneratedClassHandler.scala +++ b/compiler/src/dotty/tools/backend/jvm/GeneratedClassHandler.scala @@ -15,6 +15,7 @@ import dotty.tools.dotc.core.Phases import dotty.tools.dotc.core.Decorators.em import scala.language.unsafeNulls +import scala.compiletime.uninitialized /** * 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 } /** the main async task submitted onto the scheduler */ - var task: Future[Unit] = _ + var task: Future[Unit] = uninitialized val bufferedReporting = new PostProcessorFrontendAccess.BufferingBackendReporting() } \ No newline at end of file diff --git a/compiler/src/dotty/tools/backend/sjs/JSDefinitions.scala b/compiler/src/dotty/tools/backend/sjs/JSDefinitions.scala index 5336d60129ac..49755a8ee83e 100644 --- a/compiler/src/dotty/tools/backend/sjs/JSDefinitions.scala +++ b/compiler/src/dotty/tools/backend/sjs/JSDefinitions.scala @@ -12,6 +12,7 @@ import Symbols._ import StdNames._ import dotty.tools.dotc.config.SJSPlatform +import scala.compiletime.uninitialized object JSDefinitions { /** The Scala.js-specific definitions for the current context. */ @@ -249,7 +250,7 @@ final class JSDefinitions()(using Context) { @threadUnsafe lazy val Selectable_reflectiveSelectableFromLangReflectiveCallsR = SelectableModule.requiredMethodRef("reflectiveSelectableFromLangReflectiveCalls") def Selectable_reflectiveSelectableFromLangReflectiveCalls(using Context) = Selectable_reflectiveSelectableFromLangReflectiveCallsR.symbol - private var allRefClassesCache: Set[Symbol] = _ + private var allRefClassesCache: Set[Symbol] = uninitialized def allRefClasses(using Context): Set[Symbol] = { if (allRefClassesCache == null) { val baseNames = List("Object", "Boolean", "Character", "Byte", "Short", diff --git a/compiler/src/dotty/tools/dotc/Bench.scala b/compiler/src/dotty/tools/dotc/Bench.scala index 5f5e9fc799b5..40ad66a0a9e6 100644 --- a/compiler/src/dotty/tools/dotc/Bench.scala +++ b/compiler/src/dotty/tools/dotc/Bench.scala @@ -6,6 +6,7 @@ import reporting.Reporter import io.AbstractFile import scala.annotation.internal.sharable +import scala.compiletime.uninitialized /** A main class for running compiler benchmarks. Can instantiate a given * number of compilers and run each (sequentially) a given number of times @@ -17,7 +18,7 @@ object Bench extends Driver: @sharable private var numCompilers = 1 @sharable private var waitAfter = -1 @sharable private var curCompiler = 0 - @sharable private var times: Array[Int] = _ + @sharable private var times: Array[Int] = uninitialized override def doCompile(compiler: Compiler, files: List[AbstractFile])(using Context): Reporter = var reporter: Reporter = emptyReporter diff --git a/compiler/src/dotty/tools/dotc/Run.scala b/compiler/src/dotty/tools/dotc/Run.scala index d85e03e92d60..7b09e7ef833a 100644 --- a/compiler/src/dotty/tools/dotc/Run.scala +++ b/compiler/src/dotty/tools/dotc/Run.scala @@ -65,7 +65,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint private var myUnits: List[CompilationUnit] = Nil private var myUnitsCached: List[CompilationUnit] = Nil - private var myFiles: Set[AbstractFile] = _ + private var myFiles: Set[AbstractFile] = uninitialized // `@nowarn` annotations by source file, populated during typer private val mySuppressions: mutable.LinkedHashMap[SourceFile, mutable.ListBuffer[Suppression]] = mutable.LinkedHashMap.empty @@ -511,7 +511,7 @@ object Run { var currentCompletedSubtraversalCount: Int = 0 // completed subphases in the current phase var seenPhaseCount: Int = 0 // how many phases we've seen so far - private var currPhase: Phase = uninitialized // initialized by enterPhase + private var currPhase: Phase = uninitialized // initialized by enterPhase private var subPhases: SubPhases = uninitialized // initialized by enterPhase private var currPhaseName: String = uninitialized // initialized by enterPhase private var nextPhaseName: String = uninitialized // initialized by enterPhase diff --git a/compiler/src/dotty/tools/dotc/ast/Positioned.scala b/compiler/src/dotty/tools/dotc/ast/Positioned.scala index dd783be7a9e1..980042f8292e 100644 --- a/compiler/src/dotty/tools/dotc/ast/Positioned.scala +++ b/compiler/src/dotty/tools/dotc/ast/Positioned.scala @@ -13,12 +13,14 @@ import ast.Trees.mods import annotation.constructorOnly import annotation.internal.sharable +import scala.compiletime.uninitialized + /** A base class for things that have positions (currently: modifiers and trees) */ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends SrcPos, Product, Cloneable { import Positioned.{ids, nextId, debugId} - private var mySpan: Span = _ + private var mySpan: Span = uninitialized private var mySource: SourceFile = src diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index e0b282e2d8db..7625a61d48aa 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -18,6 +18,7 @@ import typer.ConstFold import scala.annotation.tailrec import scala.collection.mutable.ListBuffer +import scala.compiletime.uninitialized /** Some creators for typed trees */ object tpd extends Trees.Instance[Type] with TypedTreeInfo { @@ -1309,7 +1310,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { trait TreeProvider { protected def computeRootTrees(using Context): List[Tree] - private var myTrees: List[Tree] | Null = _ + private var myTrees: List[Tree] | Null = uninitialized /** Get trees defined by this provider. Cache them if -Yretain-trees is set. */ def rootTrees(using Context): List[Tree] = diff --git a/compiler/src/dotty/tools/dotc/core/ConstraintRunInfo.scala b/compiler/src/dotty/tools/dotc/core/ConstraintRunInfo.scala index d2b1246a8149..412b4228677d 100644 --- a/compiler/src/dotty/tools/dotc/core/ConstraintRunInfo.scala +++ b/compiler/src/dotty/tools/dotc/core/ConstraintRunInfo.scala @@ -3,10 +3,11 @@ package core import Contexts._ import config.Printers.{default, typr} +import scala.compiletime.uninitialized trait ConstraintRunInfo { self: Run => private var maxSize = 0 - private var maxConstraint: Constraint | Null = _ + private var maxConstraint: Constraint | Null = uninitialized def recordConstraintSize(c: Constraint, size: Int): Unit = if (size > maxSize) { maxSize = size diff --git a/compiler/src/dotty/tools/dotc/core/Contexts.scala b/compiler/src/dotty/tools/dotc/core/Contexts.scala index a2adc0058938..b6474ca7973c 100644 --- a/compiler/src/dotty/tools/dotc/core/Contexts.scala +++ b/compiler/src/dotty/tools/dotc/core/Contexts.scala @@ -558,7 +558,7 @@ object Contexts { private var _owner: Symbol = uninitialized final def owner: Symbol = _owner - private var _tree: Tree[?]= _ + private var _tree: Tree[?] = uninitialized final def tree: Tree[?] = _tree private var _scope: Scope = uninitialized diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 97b1b7db1b21..205d43cd07ca 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -20,6 +20,7 @@ import cc.{CaptureSet, RetainingType} import ast.tpd.ref import scala.annotation.tailrec +import scala.compiletime.uninitialized object Definitions { @@ -44,7 +45,7 @@ object Definitions { class Definitions { import Definitions._ - private var initCtx: Context = _ + private var initCtx: Context = uninitialized private given currentContext[Dummy_so_its_a_def]: Context = initCtx private def newPermanentSymbol[N <: Name](owner: Symbol, name: N, flags: FlagSet, info: Type) = @@ -2001,7 +2002,7 @@ class Definitions { class PerRun[T](generate: Context ?=> T) { private var current: RunId = NoRunId - private var cached: T = _ + private var cached: T = uninitialized def apply()(using Context): T = { if (current != ctx.runId) { cached = generate diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index 640ba8015be7..1969c87d7a86 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -24,6 +24,8 @@ import util.common._ import typer.ProtoTypes.NoViewsAllowed import collection.mutable.ListBuffer +import scala.compiletime.uninitialized + /** Denotations represent the meaning of symbols and named types. * The following diagram shows how the principal types of denotations * and their denoting entities relate to each other. Lines ending in @@ -121,8 +123,8 @@ object Denotations { /** Map `f` over all single denotations and aggregate the results with `g`. */ def aggregate[T](f: SingleDenotation => T, g: (T, T) => T): T - private var cachedPrefix: Type = _ - private var cachedAsSeenFrom: AsSeenFromResult = _ + private var cachedPrefix: Type = uninitialized + private var cachedAsSeenFrom: AsSeenFromResult = uninitialized private var validAsSeenFrom: Period = Nowhere type AsSeenFromResult <: PreDenotation diff --git a/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala b/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala index 0328cea9b3ca..0f05778266fd 100644 --- a/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala +++ b/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala @@ -14,6 +14,8 @@ import annotation.tailrec import annotation.internal.sharable import cc.{CapturingType, derivedCapturingType} +import scala.compiletime.uninitialized + object OrderingConstraint { /** If true, use reverse dependencies in `replace` to avoid checking the bounds @@ -881,7 +883,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds, i += 1 } - private var myUninstVars: mutable.ArrayBuffer[TypeVar] | Null = _ + private var myUninstVars: mutable.ArrayBuffer[TypeVar] | Null = uninitialized /** The uninstantiated typevars of this constraint */ def uninstVars: collection.Seq[TypeVar] = { diff --git a/compiler/src/dotty/tools/dotc/core/Phases.scala b/compiler/src/dotty/tools/dotc/core/Phases.scala index 9ba8332a8634..dd354b66cb4a 100644 --- a/compiler/src/dotty/tools/dotc/core/Phases.scala +++ b/compiler/src/dotty/tools/dotc/core/Phases.scala @@ -21,6 +21,7 @@ import typer.ImportInfo.withRootImports import ast.{tpd, untpd} import scala.annotation.internal.sharable import scala.util.control.NonFatal +import scala.compiletime.uninitialized object Phases { @@ -205,30 +206,30 @@ object Phases { if nextDenotTransformerId(i) == phase.id then nextDenotTransformerId(i) = nextDenotTransformerId(phase.id + 1) - private var myParserPhase: Phase = _ - private var myTyperPhase: Phase = _ - private var myPostTyperPhase: Phase = _ - private var mySbtExtractDependenciesPhase: Phase = _ - private var myPicklerPhase: Phase = _ - private var myInliningPhase: Phase = _ - private var myStagingPhase: Phase = _ - private var mySplicingPhase: Phase = _ - private var myFirstTransformPhase: Phase = _ - private var myCollectNullableFieldsPhase: Phase = _ - private var myRefChecksPhase: Phase = _ - private var myPatmatPhase: Phase = _ - private var myElimRepeatedPhase: Phase = _ - private var myElimByNamePhase: Phase = _ - private var myExtensionMethodsPhase: Phase = _ - private var myExplicitOuterPhase: Phase = _ - private var myGettersPhase: Phase = _ - private var myErasurePhase: Phase = _ - private var myElimErasedValueTypePhase: Phase = _ - private var myLambdaLiftPhase: Phase = _ - private var myCountOuterAccessesPhase: Phase = _ - private var myFlattenPhase: Phase = _ - private var myGenBCodePhase: Phase = _ - private var myCheckCapturesPhase: Phase = _ + private var myParserPhase: Phase = uninitialized + private var myTyperPhase: Phase = uninitialized + private var myPostTyperPhase: Phase = uninitialized + private var mySbtExtractDependenciesPhase: Phase = uninitialized + private var myPicklerPhase: Phase = uninitialized + private var myInliningPhase: Phase = uninitialized + private var myStagingPhase: Phase = uninitialized + private var mySplicingPhase: Phase = uninitialized + private var myFirstTransformPhase: Phase = uninitialized + private var myCollectNullableFieldsPhase: Phase = uninitialized + private var myRefChecksPhase: Phase = uninitialized + private var myPatmatPhase: Phase = uninitialized + private var myElimRepeatedPhase: Phase = uninitialized + private var myElimByNamePhase: Phase = uninitialized + private var myExtensionMethodsPhase: Phase = uninitialized + private var myExplicitOuterPhase: Phase = uninitialized + private var myGettersPhase: Phase = uninitialized + private var myErasurePhase: Phase = uninitialized + private var myElimErasedValueTypePhase: Phase = uninitialized + private var myLambdaLiftPhase: Phase = uninitialized + private var myCountOuterAccessesPhase: Phase = uninitialized + private var myFlattenPhase: Phase = uninitialized + private var myGenBCodePhase: Phase = uninitialized + private var myCheckCapturesPhase: Phase = uninitialized final def parserPhase: Phase = myParserPhase final def typerPhase: Phase = myTyperPhase @@ -389,7 +390,7 @@ object Phases { def printingContext(ctx: Context): Context = ctx private var myPeriod: Period = Periods.InvalidPeriod - private var myBase: ContextBase = _ + private var myBase: ContextBase = uninitialized private var myErasedTypes = false private var myFlatClasses = false private var myRefChecked = false diff --git a/compiler/src/dotty/tools/dotc/core/Scopes.scala b/compiler/src/dotty/tools/dotc/core/Scopes.scala index 99076b422358..7762ce8da339 100644 --- a/compiler/src/dotty/tools/dotc/core/Scopes.scala +++ b/compiler/src/dotty/tools/dotc/core/Scopes.scala @@ -19,6 +19,7 @@ import printing.Printer import SymDenotations.NoDenotation import collection.mutable +import scala.compiletime.uninitialized object Scopes { diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 395164b1dd48..c2e0e6f717dd 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -27,6 +27,7 @@ import transform.TypeUtils._ import cc.{CapturingType, derivedCapturingType} import scala.annotation.internal.sharable +import scala.compiletime.uninitialized object SymDenotations { @@ -2431,7 +2432,7 @@ object SymDenotations { initPrivateWithin: Symbol) extends ClassDenotation(symbol, ownerIfExists, name, initFlags, initInfo, initPrivateWithin) { - private var packageObjsCache: List[ClassDenotation] = _ + private var packageObjsCache: List[ClassDenotation] = uninitialized private var packageObjsRunId: RunId = NoRunId private var ambiguityWarningIssued: Boolean = false diff --git a/compiler/src/dotty/tools/dotc/core/Symbols.scala b/compiler/src/dotty/tools/dotc/core/Symbols.scala index 1e21c1a743f4..9c7c6a9a18bf 100644 --- a/compiler/src/dotty/tools/dotc/core/Symbols.scala +++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala @@ -33,6 +33,8 @@ import scala.annotation.internal.sharable import config.Printers.typr import dotty.tools.dotc.classpath.FileUtils.isScalaBinary +import scala.compiletime.uninitialized + object Symbols { implicit def eqSymbol: CanEqual[Symbol, Symbol] = CanEqual.derived @@ -88,7 +90,7 @@ object Symbols { ctx.settings.YcheckInitGlobal.value /** The last denotation of this symbol */ - private var lastDenot: SymDenotation = _ + private var lastDenot: SymDenotation = uninitialized private var checkedPeriod: Period = Nowhere private[core] def invalidateDenotCache(): Unit = { checkedPeriod = Nowhere } diff --git a/compiler/src/dotty/tools/dotc/core/TyperState.scala b/compiler/src/dotty/tools/dotc/core/TyperState.scala index d2df2a2aebef..54ddd4c0eb6b 100644 --- a/compiler/src/dotty/tools/dotc/core/TyperState.scala +++ b/compiler/src/dotty/tools/dotc/core/TyperState.scala @@ -14,6 +14,7 @@ import util.{Stats, SimpleIdentityMap} import Decorators._ import scala.annotation.internal.sharable +import scala.compiletime.uninitialized object TyperState { @sharable private var nextId: Int = 0 @@ -44,19 +45,19 @@ object TyperState { class TyperState() { import TyperState.LevelMap - private var myId: Int = _ + private var myId: Int = uninitialized def id: Int = myId - private var previous: TyperState | Null = _ + private var previous: TyperState | Null = uninitialized - private var myReporter: Reporter = _ + private var myReporter: Reporter = uninitialized def reporter: Reporter = myReporter /** A fresh type state with the same constraint as this one and the given reporter */ def setReporter(reporter: Reporter): this.type = { myReporter = reporter; this } - private var myConstraint: Constraint = _ + private var myConstraint: Constraint = uninitialized def constraint: Constraint = myConstraint def constraint_=(c: Constraint)(using Context): Unit = { @@ -66,9 +67,9 @@ class TyperState() { c.checkConsistentVars() } - private var previousConstraint: Constraint = _ + private var previousConstraint: Constraint = uninitialized - private var myIsCommittable: Boolean = _ + private var myIsCommittable: Boolean = uninitialized def isCommittable: Boolean = myIsCommittable @@ -79,7 +80,7 @@ class TyperState() { def isGlobalCommittable: Boolean = isCommittable && (previous == null || previous.uncheckedNN.isGlobalCommittable) - private var isCommitted: Boolean = _ + private var isCommitted: Boolean = uninitialized /** The set of uninstantiated type variables which have this state as their owning state. * @@ -87,11 +88,11 @@ class TyperState() { * if `tstate.isCommittable` then * `tstate.ownedVars.contains(tvar)` iff `tvar.owningState.get eq tstate` */ - private var myOwnedVars: TypeVars = _ + private var myOwnedVars: TypeVars = uninitialized def ownedVars: TypeVars = myOwnedVars def ownedVars_=(vs: TypeVars): Unit = myOwnedVars = vs - private var upLevels: LevelMap = _ + private var upLevels: LevelMap = uninitialized /** Initializes all fields except reporter, isCommittable, which need to be * set separately. diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index eb878b430183..f26cf432277f 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -2164,7 +2164,7 @@ object Types { /** A trait for references in CaptureSets. These can be NamedTypes, ThisTypes or ParamRefs */ trait CaptureRef extends SingletonType: - private var myCaptureSet: CaptureSet | Null = _ + private var myCaptureSet: CaptureSet | Null = uninitialized private var myCaptureSetRunId: Int = NoRunId private var mySingletonCaptureSet: CaptureSet.Const | Null = null @@ -2285,7 +2285,7 @@ object Types { private var lastSymbol: Symbol | Null = null private var checkedPeriod: Period = Nowhere private var myStableHash: Byte = 0 - private var mySignature: Signature = _ + private var mySignature: Signature = uninitialized private var mySignatureRunId: Int = NoRunId // Invariants: @@ -2941,7 +2941,7 @@ object Types { type ThisName = TypeName private var myCanDropAliasPeriod: Period = Nowhere - private var myCanDropAlias: Boolean = _ + private var myCanDropAlias: Boolean = uninitialized /** Given an alias type `type A = B` where a recursive comparison with `B` yields * `false`, can we conclude that the comparison is definitely false? @@ -3405,7 +3405,7 @@ object Types { abstract case class AndType(tp1: Type, tp2: Type) extends AndOrType { def isAnd: Boolean = true private var myBaseClassesPeriod: Period = Nowhere - private var myBaseClasses: List[ClassSymbol] = _ + private var myBaseClasses: List[ClassSymbol] = uninitialized /** Base classes are the merge of the operand base classes. */ override final def baseClasses(using Context): List[ClassSymbol] = { if (myBaseClassesPeriod != ctx.period) { @@ -3498,7 +3498,7 @@ object Types { def isAnd: Boolean = false def isSoft: Boolean private var myBaseClassesPeriod: Period = Nowhere - private var myBaseClasses: List[ClassSymbol] = _ + private var myBaseClasses: List[ClassSymbol] = uninitialized /** Base classes are the intersection of the operand base classes. */ override final def baseClasses(using Context): List[ClassSymbol] = { if (myBaseClassesPeriod != ctx.period) { @@ -3527,7 +3527,7 @@ object Types { myFactorCount else 1 - private var myJoin: Type = _ + private var myJoin: Type = uninitialized private var myJoinPeriod: Period = Nowhere /** Replace or type by the closest non-or type above it */ @@ -3541,7 +3541,7 @@ object Types { myJoin } - private var myUnion: Type = _ + private var myUnion: Type = uninitialized private var myUnionPeriod: Period = Nowhere override def widenUnionWithoutNull(using Context): Type = @@ -3556,8 +3556,8 @@ object Types { myUnion private var atomsRunId: RunId = NoRunId - private var myAtoms: Atoms = _ - private var myWidened: Type = _ + private var myAtoms: Atoms = uninitialized + private var myWidened: Type = uninitialized private def computeAtoms()(using Context): Atoms = val tp1n = tp1.normalized @@ -3797,11 +3797,11 @@ object Types { // (1) mySignatureRunId != NoRunId => mySignature != null // (2) myJavaSignatureRunId != NoRunId => myJavaSignature != null - private var mySignature: Signature = _ + private var mySignature: Signature = uninitialized private var mySignatureRunId: Int = NoRunId - private var myJavaSignature: Signature = _ + private var myJavaSignature: Signature = uninitialized private var myJavaSignatureRunId: Int = NoRunId - private var myScala2Signature: Signature = _ + private var myScala2Signature: Signature = uninitialized private var myScala2SignatureRunId: Int = NoRunId /** If `isJava` is false, the Scala signature of this method. Otherwise, its Java signature. @@ -4993,7 +4993,7 @@ object Types { def underlying(using Context): Type = bound private var myReduced: Type | Null = null - private var reductionContext: util.MutableMap[Type, Type] = _ + private var reductionContext: util.MutableMap[Type, Type] = uninitialized override def tryNormalize(using Context): Type = try @@ -5420,7 +5420,7 @@ object Types { override def stripped(using Context): Type = parent.stripped private var isRefiningKnown = false - private var isRefiningCache: Boolean = _ + private var isRefiningCache: Boolean = uninitialized def isRefining(using Context): Boolean = { if (!isRefiningKnown) { diff --git a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala index 5e816502f359..349dbc445971 100644 --- a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala +++ b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala @@ -25,6 +25,8 @@ import io.{AbstractFile, ZipArchive} import scala.util.control.NonFatal import dotty.tools.dotc.classpath.FileUtils.classToTasty +import scala.compiletime.uninitialized + object ClassfileParser { import ClassfileConstants._ @@ -237,11 +239,11 @@ class ClassfileParser( protected val staticModule: Symbol = moduleRoot.sourceModule(using ictx) - protected val instanceScope: MutableScope = newScope(0) // the scope of all instance definitions - protected val staticScope: MutableScope = newScope(0) // the scope of all static definitions - protected var pool: ConstantPool = _ // the classfile's constant pool + protected val instanceScope: MutableScope = newScope(0) // the scope of all instance definitions + protected val staticScope: MutableScope = newScope(0) // the scope of all static definitions + protected var pool: ConstantPool = uninitialized // the classfile's constant pool - protected var currentClassName: SimpleName = _ // JVM name of the current class + protected var currentClassName: SimpleName = uninitialized // JVM name of the current class protected var classTParams: Map[Name, Symbol] = Map() private var Scala2UnpicklingMode = Mode.Scala2Unpickling diff --git a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileTastyUUIDParser.scala b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileTastyUUIDParser.scala index a9c91a68bb60..4c4885fd5313 100644 --- a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileTastyUUIDParser.scala +++ b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileTastyUUIDParser.scala @@ -2,6 +2,7 @@ package dotty.tools.dotc package core.classfile import scala.language.unsafeNulls +import scala.compiletime.uninitialized import dotty.tools.dotc.core.Contexts._ import dotty.tools.dotc.core.Decorators._ @@ -21,7 +22,7 @@ class ClassfileTastyUUIDParser(classfile: AbstractFile)(ictx: Context) { import ClassfileConstants._ - private var pool: ConstantPool = _ // the classfile's constant pool + private var pool: ConstantPool = uninitialized // the classfile's constant pool def checkTastyUUID(tastyUUID: UUID)(using Context): Unit = try ctx.base.reusableDataReader.withInstance { reader => implicit val reader2 = reader.reset(classfile) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala index 9c66e43eae80..bc58138f2db6 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala @@ -3,6 +3,8 @@ package dotc package core package tasty +import scala.compiletime.uninitialized + import dotty.tools.tasty.{TastyFormat, TastyBuffer, TastyReader} import TastyFormat.SOURCE import TastyBuffer.{Addr, NameRef} @@ -14,9 +16,9 @@ import Names.TermName class PositionUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName) { import reader._ - private var myLineSizes: Array[Int] = _ - private var mySpans: util.HashMap[Addr, Span] = _ - private var mySourcePaths: util.HashMap[Addr, String] = _ + private var myLineSizes: Array[Int] = uninitialized + private var mySpans: util.HashMap[Addr, Span] = uninitialized + private var mySourcePaths: util.HashMap[Addr, String] = uninitialized private var isDefined = false def ensureDefined(): Unit = { diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index 1748b1edd08e..840bb3bd94fb 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -46,6 +46,7 @@ import dotty.tools.tasty.TastyFormat._ import scala.annotation.constructorOnly import scala.annotation.internal.sharable +import scala.compiletime.uninitialized /** Unpickler for typed trees * @param reader the reader from which to unpickle @@ -88,7 +89,7 @@ class TreeUnpickler(reader: TastyReader, private var seenRoots: Set[Symbol] = Set() /** The root owner tree. See `OwnerTree` class definition. Set by `enterTopLevel`. */ - private var ownerTree: OwnerTree = _ + private var ownerTree: OwnerTree = uninitialized /** Was unpickled class compiled with pureFunctions? */ private var withPureFuns: Boolean = false diff --git a/compiler/src/dotty/tools/dotc/parsing/CharArrayReader.scala b/compiler/src/dotty/tools/dotc/parsing/CharArrayReader.scala index c63409d0d52b..a3769f4f813d 100644 --- a/compiler/src/dotty/tools/dotc/parsing/CharArrayReader.scala +++ b/compiler/src/dotty/tools/dotc/parsing/CharArrayReader.scala @@ -4,6 +4,8 @@ package parsing import util.Chars._ +import scala.compiletime.uninitialized + abstract class CharArrayReader { self => val buf: Array[Char] @@ -16,7 +18,7 @@ abstract class CharArrayReader { self => protected def error(msg: String, offset: Int): Unit /** the last read character */ - var ch: Char = _ + var ch: Char = uninitialized /** The offset one past the last read character */ var charOffset: Int = startFrom diff --git a/compiler/src/dotty/tools/dotc/parsing/xml/MarkupParsers.scala b/compiler/src/dotty/tools/dotc/parsing/xml/MarkupParsers.scala index b3f41fab9eaa..0f0a2a3ee61f 100644 --- a/compiler/src/dotty/tools/dotc/parsing/xml/MarkupParsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/xml/MarkupParsers.scala @@ -4,6 +4,7 @@ package parsing package xml import scala.language.unsafeNulls +import scala.compiletime.uninitialized import scala.collection.mutable import scala.collection.BufferedIterator @@ -71,7 +72,7 @@ object MarkupParsers { if (ch == SU) throw TruncatedXMLControl else reportSyntaxError(msg) - var input : CharArrayReader = _ + var input : CharArrayReader = uninitialized def lookahead(): BufferedIterator[Char] = (input.buf drop input.charOffset).iterator.buffered diff --git a/compiler/src/dotty/tools/dotc/parsing/xml/SymbolicXMLBuilder.scala b/compiler/src/dotty/tools/dotc/parsing/xml/SymbolicXMLBuilder.scala index 0e70cc077fa4..6d49360feb85 100644 --- a/compiler/src/dotty/tools/dotc/parsing/xml/SymbolicXMLBuilder.scala +++ b/compiler/src/dotty/tools/dotc/parsing/xml/SymbolicXMLBuilder.scala @@ -4,6 +4,7 @@ package parsing package xml import scala.language.unsafeNulls +import scala.compiletime.uninitialized import scala.collection.mutable import core._ @@ -32,7 +33,7 @@ class SymbolicXMLBuilder(parser: Parser, preserveWS: Boolean)(using Context) { import parser.atSpan - private[parsing] var isPattern: Boolean = _ + private[parsing] var isPattern: Boolean = uninitialized private object xmltypes extends ScalaTypeNames { val _Comment: TypeName = "Comment" diff --git a/compiler/src/dotty/tools/dotc/plugins/Plugins.scala b/compiler/src/dotty/tools/dotc/plugins/Plugins.scala index c44fe4cf59b4..12acc3d7b4c3 100644 --- a/compiler/src/dotty/tools/dotc/plugins/Plugins.scala +++ b/compiler/src/dotty/tools/dotc/plugins/Plugins.scala @@ -11,6 +11,8 @@ import dotty.tools.io._ import Phases._ import config.Printers.plugins.{ println => debug } +import scala.compiletime.uninitialized + /** Support for run-time loading of compiler plugins. * * @author Lex Spoon @@ -44,7 +46,7 @@ trait Plugins { goods map (_.get) } - private var _roughPluginsList: List[Plugin] = _ + private var _roughPluginsList: List[Plugin] = uninitialized protected def roughPluginsList(using Context): List[Plugin] = if (_roughPluginsList == null) { _roughPluginsList = loadRoughPluginsList @@ -96,7 +98,7 @@ trait Plugins { plugs } - private var _plugins: List[Plugin] = _ + private var _plugins: List[Plugin] = uninitialized def plugins(using Context): List[Plugin] = if (_plugins == null) { _plugins = loadPlugins diff --git a/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala b/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala index d0330a955148..60cfeeced209 100644 --- a/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala +++ b/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala @@ -29,7 +29,7 @@ import xsbti.api.DependencyContext._ import scala.jdk.CollectionConverters.* import scala.collection.{Set, mutable} - +import scala.compiletime.uninitialized /** This phase sends information on classes' dependencies to sbt via callbacks. * @@ -519,9 +519,9 @@ class DependencyRecorder { } } - private var lastOwner: Symbol = _ - private var lastDepSource: Symbol = _ - private var lastFoundCache: FoundDepsInClass | Null = _ + private var lastOwner: Symbol = uninitialized + private var lastDepSource: Symbol = uninitialized + private var lastFoundCache: FoundDepsInClass | Null = uninitialized /** The source of the dependency according to `nonLocalEnclosingClass` * if it exists, otherwise fall back to `responsibleForImports`. @@ -558,7 +558,7 @@ class DependencyRecorder { clazz } - private var _responsibleForImports: Symbol = _ + private var _responsibleForImports: Symbol = uninitialized /** Top level import dependencies are registered as coming from a first top level * class/trait/object declared in the compilation unit. If none exists, issue a warning and return NoSymbol. diff --git a/compiler/src/dotty/tools/dotc/transform/CapturedVars.scala b/compiler/src/dotty/tools/dotc/transform/CapturedVars.scala index 8964beb26051..a018bbd1a3ac 100644 --- a/compiler/src/dotty/tools/dotc/transform/CapturedVars.scala +++ b/compiler/src/dotty/tools/dotc/transform/CapturedVars.scala @@ -14,6 +14,8 @@ import core.Constants._ import util.Store import dotty.tools.uncheckedNN +import scala.compiletime.uninitialized + /** This phase translates variables that are captured in closures to * heap-allocated refs. */ @@ -25,7 +27,7 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer: override def description: String = CapturedVars.description - private[this] var Captured: Store.Location[util.ReadOnlySet[Symbol]] = _ + private[this] var Captured: Store.Location[util.ReadOnlySet[Symbol]] = uninitialized private def captured(using Context) = ctx.store(Captured) override def initContext(ctx: FreshContext): Unit = diff --git a/compiler/src/dotty/tools/dotc/transform/CtxLazy.scala b/compiler/src/dotty/tools/dotc/transform/CtxLazy.scala index 808cf928ecc2..4f8f1b195bb3 100644 --- a/compiler/src/dotty/tools/dotc/transform/CtxLazy.scala +++ b/compiler/src/dotty/tools/dotc/transform/CtxLazy.scala @@ -3,6 +3,8 @@ package transform import core.Contexts._ +import scala.compiletime.uninitialized + /** Utility class for lazy values whose evaluation depends on a context. * This should be used whenever the evaluation of a lazy expression * depends on some context, but the value can be re-used afterwards @@ -12,7 +14,7 @@ import core.Contexts._ * the expression intiializing the lazy val depends only on the root context, but not any changes afterwards. */ class CtxLazy[T](expr: Context ?=> T) { - private var myValue: T = _ + private var myValue: T = uninitialized private var forced = false def apply()(using Context): T = { if (!forced) { diff --git a/compiler/src/dotty/tools/dotc/transform/Dependencies.scala b/compiler/src/dotty/tools/dotc/transform/Dependencies.scala index 08189e107d94..46285c324307 100644 --- a/compiler/src/dotty/tools/dotc/transform/Dependencies.scala +++ b/compiler/src/dotty/tools/dotc/transform/Dependencies.scala @@ -6,6 +6,7 @@ import Symbols.*, Contexts.*, Types.*, Flags.*, Decorators.* import SymUtils.* import collection.mutable.{LinkedHashMap, LinkedHashSet} import annotation.constructorOnly +import scala.compiletime.uninitialized import dotty.tools.backend.sjs.JSDefinitions.jsdefn @@ -51,10 +52,10 @@ abstract class Dependencies(root: ast.tpd.Tree, @constructorOnly rootContext: Co private val logicOwner = new LinkedHashMap[Symbol, Symbol] /** A flag to indicate whether new free variables have been found */ - private var changedFreeVars: Boolean = _ + private var changedFreeVars: Boolean = uninitialized /** A flag to indicate whether lifted owners have changed */ - private var changedLogicOwner: Boolean = _ + private var changedLogicOwner: Boolean = uninitialized private def newSymSet: LinkedHashSet[Symbol] = new LinkedHashSet[Symbol] diff --git a/compiler/src/dotty/tools/dotc/transform/Flatten.scala b/compiler/src/dotty/tools/dotc/transform/Flatten.scala index 25df51d0916d..84f3d35c80b7 100644 --- a/compiler/src/dotty/tools/dotc/transform/Flatten.scala +++ b/compiler/src/dotty/tools/dotc/transform/Flatten.scala @@ -10,6 +10,8 @@ import collection.mutable import MegaPhase.MiniPhase import util.Store +import scala.compiletime.uninitialized + /** Lift nested classes to toplevel */ class Flatten extends MiniPhase with SymTransformer { import ast.tpd._ @@ -24,7 +26,7 @@ class Flatten extends MiniPhase with SymTransformer { override def changesMembers: Boolean = true // the phase removes inner classes - private var LiftedDefs: Store.Location[mutable.ListBuffer[Tree] | Null] = _ + private var LiftedDefs: Store.Location[mutable.ListBuffer[Tree] | Null] = uninitialized private def liftedDefs(using Context) = ctx.store(LiftedDefs) override def initContext(ctx: FreshContext): Unit = diff --git a/compiler/src/dotty/tools/dotc/transform/ForwardDepChecks.scala b/compiler/src/dotty/tools/dotc/transform/ForwardDepChecks.scala index bf8a6fa6c7bf..afe78ce1296d 100644 --- a/compiler/src/dotty/tools/dotc/transform/ForwardDepChecks.scala +++ b/compiler/src/dotty/tools/dotc/transform/ForwardDepChecks.scala @@ -10,6 +10,8 @@ import collection.immutable import ast.tpd import MegaPhase.MiniPhase +import scala.compiletime.uninitialized + object ForwardDepChecks: import tpd.* @@ -37,8 +39,8 @@ object ForwardDepChecks: (m1, idx + 1) }._1 var maxIndex: Int = Int.MinValue - var refSpan: Span = _ - var refSym: Symbol = _ + var refSpan: Span = uninitialized + var refSym: Symbol = uninitialized override def enterReference(sym: Symbol, span: Span): Unit = if (sym.exists && sym.owner.isTerm) @@ -63,7 +65,7 @@ class ForwardDepChecks extends MiniPhase: override def runsAfter: Set[String] = Set(ElimByName.name) - private var LevelInfo: Store.Location[OptLevelInfo] = _ + private var LevelInfo: Store.Location[OptLevelInfo] = uninitialized private def currentLevel(using Context): OptLevelInfo = ctx.store(LevelInfo) override def initContext(ctx: FreshContext): Unit = diff --git a/compiler/src/dotty/tools/dotc/transform/Instrumentation.scala b/compiler/src/dotty/tools/dotc/transform/Instrumentation.scala index 046147f20d82..9802de34a6e0 100644 --- a/compiler/src/dotty/tools/dotc/transform/Instrumentation.scala +++ b/compiler/src/dotty/tools/dotc/transform/Instrumentation.scala @@ -12,6 +12,8 @@ import MegaPhase._ import Names._ import Constants.Constant +import scala.compiletime.uninitialized + /** The phase is enabled if the -Yinstrument option is set. * If enabled, it counts the number of closures or allocations for each source position. @@ -40,11 +42,11 @@ class Instrumentation extends MiniPhase { thisPhase => "::", "+=", "toString", "newArray", "box", "toCharArray", "termName", "typeName", "slice", "staticRef", "requiredClass") - private var namesToRecord: Set[Name] = _ - private var collectionNamesToRecord: Set[Name] = _ - private var Stats_doRecord: Symbol = _ - private var Stats_doRecordSize: Symbol = _ - private var CollectionIterableClass: ClassSymbol = _ + private var namesToRecord: Set[Name] = uninitialized + private var collectionNamesToRecord: Set[Name] = uninitialized + private var Stats_doRecord: Symbol = uninitialized + private var Stats_doRecordSize: Symbol = uninitialized + private var CollectionIterableClass: ClassSymbol = uninitialized override def prepareForUnit(tree: Tree)(using Context): Context = namesToRecord = namesOfInterest.map(_.toTermName).toSet diff --git a/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala b/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala index 6ec0f330efff..5be43fd56952 100644 --- a/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala +++ b/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala @@ -18,6 +18,8 @@ import ExplicitOuter.outer import util.Store import collection.mutable.{HashMap, LinkedHashMap, ListBuffer} +import scala.compiletime.uninitialized + object LambdaLift: import ast.tpd._ @@ -266,7 +268,7 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisPhase => // lambda lift for super calls right. Witness the implementation restrictions to // this effect in scalac. - private var Lifter: Store.Location[Lifter] = _ + private var Lifter: Store.Location[Lifter] = uninitialized private def lifter(using Context) = ctx.store(Lifter) override def initContext(ctx: FreshContext): Unit = diff --git a/compiler/src/dotty/tools/dotc/transform/LazyVals.scala b/compiler/src/dotty/tools/dotc/transform/LazyVals.scala index b433e37e39c0..4fabaf99f843 100644 --- a/compiler/src/dotty/tools/dotc/transform/LazyVals.scala +++ b/compiler/src/dotty/tools/dotc/transform/LazyVals.scala @@ -19,6 +19,7 @@ import transform.MegaPhase.MiniPhase import transform.SymUtils.* import scala.collection.mutable +import scala.compiletime.uninitialized class LazyVals extends MiniPhase with IdentityDenotTransformer { import LazyVals._ @@ -47,7 +48,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer { val containerFlagsMask: FlagSet = Method | Lazy | Accessor | Module /** A map of lazy values to the fields they should null after initialization. */ - private var lazyValNullables: IdentityHashMap[Symbol, mutable.ListBuffer[Symbol]] | Null = _ + private var lazyValNullables: IdentityHashMap[Symbol, mutable.ListBuffer[Symbol]] | Null = uninitialized private def nullableFor(sym: Symbol)(using Context) = { // optimisation: value only used once, we can remove the value from the map val nullables = lazyValNullables.nn.remove(sym) diff --git a/compiler/src/dotty/tools/dotc/transform/MegaPhase.scala b/compiler/src/dotty/tools/dotc/transform/MegaPhase.scala index fe70a1659036..eff634b485b8 100644 --- a/compiler/src/dotty/tools/dotc/transform/MegaPhase.scala +++ b/compiler/src/dotty/tools/dotc/transform/MegaPhase.scala @@ -2,6 +2,8 @@ package dotty.tools package dotc package transform +import scala.compiletime.uninitialized + import core._ import Contexts._, Phases._, Symbols._, Decorators._ import Flags.PackageVal @@ -31,8 +33,8 @@ object MegaPhase { */ abstract class MiniPhase extends Phase { - private[MegaPhase] var superPhase: MegaPhase = _ - private[MegaPhase] var idxInGroup: Int = _ + private[MegaPhase] var superPhase: MegaPhase = uninitialized + private[MegaPhase] var idxInGroup: Int = uninitialized /** List of names of phases that should have finished their processing of all compilation units * before this phase starts @@ -151,7 +153,7 @@ class MegaPhase(val miniPhases: Array[MiniPhase]) extends Phase { else s"MegaPhase{${miniPhases.head.phaseName},...,${miniPhases.last.phaseName}}" - private var relaxedTypingCache: Boolean = _ + private var relaxedTypingCache: Boolean = uninitialized private var relaxedTypingKnown = false override final def relaxedTyping: Boolean = { diff --git a/compiler/src/dotty/tools/dotc/transform/Memoize.scala b/compiler/src/dotty/tools/dotc/transform/Memoize.scala index af6533cfc17f..91f394866035 100644 --- a/compiler/src/dotty/tools/dotc/transform/Memoize.scala +++ b/compiler/src/dotty/tools/dotc/transform/Memoize.scala @@ -19,6 +19,7 @@ import StdNames.nme import sjs.JSSymUtils._ import util.Store +import scala.compiletime.uninitialized object Memoize { val name: String = "memoize" @@ -52,7 +53,7 @@ class Memoize extends MiniPhase with IdentityDenotTransformer { thisPhase => override def description: String = Memoize.description - private var MyState: Store.Location[MyState] = _ + private var MyState: Store.Location[MyState] = uninitialized private def myState(using Context): MyState = ctx.store(MyState) override def initContext(ctx: FreshContext): Unit = diff --git a/compiler/src/dotty/tools/dotc/transform/OverridingPairs.scala b/compiler/src/dotty/tools/dotc/transform/OverridingPairs.scala index 0e38e9c074cd..92039a8b9af8 100644 --- a/compiler/src/dotty/tools/dotc/transform/OverridingPairs.scala +++ b/compiler/src/dotty/tools/dotc/transform/OverridingPairs.scala @@ -10,6 +10,8 @@ import collection.immutable.BitSet import scala.annotation.tailrec import cc.isCaptureChecking +import scala.compiletime.uninitialized + /** A module that can produce a kind of iterator (`Cursor`), * which yields all pairs of overriding/overridden symbols * that are visible in some baseclass, unless there's a parent class @@ -118,10 +120,10 @@ object OverridingPairs: private var nextEntry = curEntry /** The current candidate symbol for overriding */ - var overriding: Symbol = _ + var overriding: Symbol = uninitialized /** If not null: The symbol overridden by overriding */ - var overridden: Symbol = _ + var overridden: Symbol = uninitialized //@M: note that next is called once during object initialization final def hasNext: Boolean = nextEntry != null diff --git a/compiler/src/dotty/tools/dotc/transform/TailRec.scala b/compiler/src/dotty/tools/dotc/transform/TailRec.scala index 741b9d1627fe..45330b6e9f5d 100644 --- a/compiler/src/dotty/tools/dotc/transform/TailRec.scala +++ b/compiler/src/dotty/tools/dotc/transform/TailRec.scala @@ -13,6 +13,8 @@ import transform.MegaPhase.MiniPhase import util.LinearSet import dotty.tools.uncheckedNN +import scala.compiletime.uninitialized + /** A Tail Rec Transformer. * * What it does: @@ -232,7 +234,7 @@ class TailRec extends MiniPhase { var failureReported: Boolean = false /** The `tailLabelN` label symbol, used to encode a `continue` from the infinite `while` loop. */ - private var myContinueLabel: Symbol | Null = _ + private var myContinueLabel: Symbol | Null = uninitialized def continueLabel(using Context): Symbol = { if (myContinueLabel == null) myContinueLabel = newSymbol(method, TailLabelName.fresh(), Label, defn.UnitType) diff --git a/compiler/src/dotty/tools/dotc/transform/sjs/ExplicitJSClasses.scala b/compiler/src/dotty/tools/dotc/transform/sjs/ExplicitJSClasses.scala index 705b3cc404a8..71783c509596 100644 --- a/compiler/src/dotty/tools/dotc/transform/sjs/ExplicitJSClasses.scala +++ b/compiler/src/dotty/tools/dotc/transform/sjs/ExplicitJSClasses.scala @@ -3,6 +3,7 @@ package dotc package transform package sjs +import scala.compiletime.uninitialized import MegaPhase._ import core.Annotations._ @@ -236,7 +237,7 @@ class ExplicitJSClasses extends MiniPhase with InfoTransformer { thisPhase => override def description: String = ExplicitJSClasses.description - private var MyState: Store.Location[MyState] = _ + private var MyState: Store.Location[MyState] = uninitialized private def myState(using Context) = ctx.store(MyState) override def initContext(ctx: FreshContext): Unit = diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index 5cba406a302e..58323f708144 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -37,6 +37,7 @@ import annotation.tailrec import scala.annotation.internal.sharable import scala.annotation.threadUnsafe +import scala.compiletime.uninitialized /** Implicit resolution */ object Implicits: @@ -620,7 +621,7 @@ trait ImplicitRunInfo: object collectParts extends TypeTraverser: - private var parts: mutable.LinkedHashSet[Type] = _ + private var parts: mutable.LinkedHashSet[Type] = uninitialized private val partSeen = util.HashSet[Type]() def traverse(t: Type) = try diff --git a/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala b/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala index ba05cba229ae..4850e7bdffa9 100644 --- a/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala +++ b/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala @@ -12,6 +12,8 @@ import StdNames.nme import printing.Texts.Text import NameKinds.QualifiedName +import scala.compiletime.uninitialized + object ImportInfo { case class RootRef(refFn: () => TermRef, isPredef: Boolean = false) @@ -66,7 +68,7 @@ class ImportInfo(symf: Context ?=> Symbol, } mySym.uncheckedNN } - private var mySym: Symbol | Null = _ + private var mySym: Symbol | Null = uninitialized /** The (TermRef) type of the qualifier of the import clause */ def site(using Context): Type = importSym.info match { @@ -180,7 +182,7 @@ class ImportInfo(symf: Context ?=> Symbol, private val isLanguageImport: Boolean = untpd.languageImport(qualifier).isDefined - private var myUnimported: Symbol | Null = _ + private var myUnimported: Symbol | Null = uninitialized private var featureCache: SimpleIdentityMap[TermName, java.lang.Boolean] = SimpleIdentityMap.empty diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 44d8077e44db..6d6580e740db 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -30,6 +30,7 @@ import reporting._ import config.Feature.sourceVersion import config.SourceVersion._ +import scala.compiletime.uninitialized /** This class creates symbols from definitions and imports and gives them * lazy types. @@ -1078,7 +1079,7 @@ class Namer { typer: Typer => protected implicit val completerCtx: Context = localContext(cls) - private var localCtx: Context = _ + private var localCtx: Context = uninitialized /** info to be used temporarily while completing the class, to avoid cyclic references. */ private var tempInfo: TempClassInfo | Null = null diff --git a/compiler/src/dotty/tools/dotc/typer/VarianceChecker.scala b/compiler/src/dotty/tools/dotc/typer/VarianceChecker.scala index 21fa9eed0df4..7d129e128518 100644 --- a/compiler/src/dotty/tools/dotc/typer/VarianceChecker.scala +++ b/compiler/src/dotty/tools/dotc/typer/VarianceChecker.scala @@ -13,6 +13,8 @@ import config.Feature.migrateTo3 import reporting.trace import printing.Formatting.hl +import scala.compiletime.uninitialized + /** Provides `check` method to check that all top-level definitions * in tree are variance correct. Does not recurse inside methods. * The method should be invoked once for each Template. @@ -67,7 +69,7 @@ class VarianceChecker(using Context) { import tpd._ private object Validator extends TypeAccumulator[Option[VarianceError]] { - private var base: Symbol = _ + private var base: Symbol = uninitialized /** The variance of a symbol occurrence of `tvar` seen at the level of the definition of `base`. * The search proceeds from `base` to the owner of `tvar`. diff --git a/compiler/src/dotty/tools/dotc/util/GenericHashMap.scala b/compiler/src/dotty/tools/dotc/util/GenericHashMap.scala index 6d013717ec52..8c0506573109 100644 --- a/compiler/src/dotty/tools/dotc/util/GenericHashMap.scala +++ b/compiler/src/dotty/tools/dotc/util/GenericHashMap.scala @@ -1,6 +1,8 @@ package dotty.tools package dotc.util +import scala.compiletime.uninitialized + object GenericHashMap: /** The number of elements up to which dense packing is used. @@ -27,9 +29,9 @@ abstract class GenericHashMap[Key, Value] (initialCapacity: Int, capacityMultiple: Int) extends MutableMap[Key, Value]: import GenericHashMap.DenseLimit - protected var used: Int = _ - protected var limit: Int = _ - protected var table: Array[AnyRef | Null] = _ + protected var used: Int = uninitialized + protected var limit: Int = uninitialized + protected var table: Array[AnyRef | Null] = uninitialized clear() private def allocate(capacity: Int) = diff --git a/compiler/src/dotty/tools/dotc/util/GenericHashSet.scala b/compiler/src/dotty/tools/dotc/util/GenericHashSet.scala index 7abe40a8e13d..3c30e8e73300 100644 --- a/compiler/src/dotty/tools/dotc/util/GenericHashSet.scala +++ b/compiler/src/dotty/tools/dotc/util/GenericHashSet.scala @@ -2,6 +2,8 @@ package dotty.tools.dotc.util import dotty.tools.uncheckedNN +import scala.compiletime.uninitialized + object GenericHashSet: /** The number of elements up to which dense packing is used. @@ -24,9 +26,9 @@ object GenericHashSet: abstract class GenericHashSet[T](initialCapacity: Int = 8, capacityMultiple: Int = 2) extends MutableSet[T] { import GenericHashSet.DenseLimit - protected var used: Int = _ - protected var limit: Int = _ - protected var table: Array[AnyRef | Null] = _ + protected var used: Int = uninitialized + protected var limit: Int = uninitialized + protected var table: Array[AnyRef | Null] = uninitialized clear() diff --git a/compiler/src/dotty/tools/dotc/util/IntMap.scala b/compiler/src/dotty/tools/dotc/util/IntMap.scala index 008ea866f70e..1d04567e99c7 100644 --- a/compiler/src/dotty/tools/dotc/util/IntMap.scala +++ b/compiler/src/dotty/tools/dotc/util/IntMap.scala @@ -1,5 +1,7 @@ package dotty.tools.dotc.util +import scala.compiletime.uninitialized + /** A dense map from some `Key` type to `Int. Dense means: All keys and values * are stored in arrays from 0 up to the size of the map. Keys and values * can be obtained by index using `key(index)` and `value(index)`. Values @@ -19,7 +21,7 @@ package dotty.tools.dotc.util */ final class IntMap[Key](initialCapacity: Int = 8, capacityMultiple: Int = 2) extends PerfectHashing[Key](initialCapacity, capacityMultiple): - private var values: Array[Int] = _ + private var values: Array[Int] = uninitialized def default: Int = -1 diff --git a/compiler/src/dotty/tools/dotc/util/PerfectHashing.scala b/compiler/src/dotty/tools/dotc/util/PerfectHashing.scala index fca790837959..1351afb68f3d 100644 --- a/compiler/src/dotty/tools/dotc/util/PerfectHashing.scala +++ b/compiler/src/dotty/tools/dotc/util/PerfectHashing.scala @@ -1,5 +1,7 @@ package dotty.tools.dotc.util +import scala.compiletime.uninitialized + object PerfectHashing: /** The number of elements up to which dense packing is used. @@ -22,9 +24,9 @@ object PerfectHashing: class PerfectHashing[Key](initialCapacity: Int = 8, capacityMultiple: Int = 2): import PerfectHashing.DenseLimit - private var used: Int = _ - private var table: Array[Int] = _ - private var keys: Array[AnyRef] = _ + private var used: Int = uninitialized + private var table: Array[Int] = uninitialized + private var keys: Array[AnyRef] = uninitialized clear() diff --git a/compiler/src/dotty/tools/dotc/util/SourceFile.scala b/compiler/src/dotty/tools/dotc/util/SourceFile.scala index 3462036d7ba6..d35509f591a3 100644 --- a/compiler/src/dotty/tools/dotc/util/SourceFile.scala +++ b/compiler/src/dotty/tools/dotc/util/SourceFile.scala @@ -13,6 +13,7 @@ import Chars._ import scala.annotation.internal.sharable import scala.collection.mutable import scala.collection.mutable.ArrayBuffer +import scala.compiletime.uninitialized import scala.util.chaining.given import java.io.File.separator @@ -137,7 +138,7 @@ class SourceFile(val file: AbstractFile, computeContent: => Array[Char]) extends buf.toArray } - private var lineIndicesCache: Array[Int] = _ + private var lineIndicesCache: Array[Int] = uninitialized private def lineIndices: Array[Int] = if lineIndicesCache eq null then lineIndicesCache = calculateLineIndicesFromContents() diff --git a/compiler/src/dotty/tools/repl/CollectTopLevelImports.scala b/compiler/src/dotty/tools/repl/CollectTopLevelImports.scala index d539c1986f8d..8a12ae22be37 100644 --- a/compiler/src/dotty/tools/repl/CollectTopLevelImports.scala +++ b/compiler/src/dotty/tools/repl/CollectTopLevelImports.scala @@ -4,6 +4,8 @@ import dotty.tools.dotc.ast.tpd import dotty.tools.dotc.core.Contexts._ import dotty.tools.dotc.core.Phases.Phase +import scala.compiletime.uninitialized + /** A phase that collects user defined top level imports. * * These imports must be collected as typed trees and therefore @@ -14,7 +16,7 @@ class CollectTopLevelImports extends Phase { def phaseName: String = "collectTopLevelImports" - private var myImports: List[Import] = _ + private var myImports: List[Import] = uninitialized def imports: List[Import] = myImports def run(using Context): Unit = { diff --git a/compiler/src/dotty/tools/repl/Rendering.scala b/compiler/src/dotty/tools/repl/Rendering.scala index c647ef302bb9..972baa39877b 100644 --- a/compiler/src/dotty/tools/repl/Rendering.scala +++ b/compiler/src/dotty/tools/repl/Rendering.scala @@ -10,6 +10,7 @@ import reporting.Diagnostic import transform.ValueClasses import util.StackTraceOps.* +import scala.compiletime.uninitialized import scala.util.control.NonFatal /** This rendering object uses `ClassLoader`s to accomplish crossing the 4th @@ -24,10 +25,10 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None): import Rendering._ - var myClassLoader: AbstractFileClassLoader = _ + var myClassLoader: AbstractFileClassLoader = uninitialized /** (value, maxElements, maxCharacters) => String */ - var myReplStringOf: (Object, Int, Int) => String = _ + var myReplStringOf: (Object, Int, Int) => String = uninitialized /** Class loader used to load compiled code */ private[repl] def classLoader()(using Context) = diff --git a/compiler/src/dotty/tools/repl/ReplDriver.scala b/compiler/src/dotty/tools/repl/ReplDriver.scala index 2471f6bece42..6bb3d21dd45f 100644 --- a/compiler/src/dotty/tools/repl/ReplDriver.scala +++ b/compiler/src/dotty/tools/repl/ReplDriver.scala @@ -36,6 +36,7 @@ import org.jline.reader._ import scala.annotation.tailrec import scala.collection.mutable +import scala.compiletime.uninitialized import scala.jdk.CollectionConverters._ import scala.util.control.NonFatal import scala.util.Using @@ -116,10 +117,10 @@ class ReplDriver(settings: Array[String], rendering = new Rendering(classLoader) } - private var rootCtx: Context = _ - private var shouldStart: Boolean = _ - private var compiler: ReplCompiler = _ - protected var rendering: Rendering = _ + private var rootCtx: Context = uninitialized + private var shouldStart: Boolean = uninitialized + private var compiler: ReplCompiler = uninitialized + protected var rendering: Rendering = uninitialized // initialize the REPL session as part of the constructor so that once `run` // is called, we're in business diff --git a/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala b/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala index 03b61c393d35..a96a2765d56a 100644 --- a/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala +++ b/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala @@ -17,6 +17,7 @@ import dotty.Properties import interfaces.Diagnostic.{ERROR, WARNING} import scala.io.Codec +import scala.compiletime.uninitialized class TestReporter protected (outWriter: PrintWriter, logLevel: Int) extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with MessageRendering { @@ -81,9 +82,9 @@ object TestReporter { private val failedTestsFileName: String = "last-failed.log" private val failedTestsFile: JFile = new JFile(s"$testLogsDirName/$failedTestsFileName") - private var outFile: JFile = _ - private var logWriter: PrintWriter = _ - private var failedTestsWriter: PrintWriter = _ + private var outFile: JFile = uninitialized + private var logWriter: PrintWriter = uninitialized + private var failedTestsWriter: PrintWriter = uninitialized private def initLog() = if (logWriter eq null) { val date = new Date diff --git a/compiler/test/dotty/tools/vulpix/RunnerOrchestration.scala b/compiler/test/dotty/tools/vulpix/RunnerOrchestration.scala index 8e9a27e766b4..9047bb6737dc 100644 --- a/compiler/test/dotty/tools/vulpix/RunnerOrchestration.scala +++ b/compiler/test/dotty/tools/vulpix/RunnerOrchestration.scala @@ -14,6 +14,7 @@ import scala.concurrent.duration.Duration import scala.concurrent.{ Await, Future } import scala.concurrent.ExecutionContext.Implicits.global import scala.collection.mutable +import scala.compiletime.uninitialized /** Vulpix spawns JVM subprocesses (`numberOfSlaves`) in order to run tests * without compromising the main JVM @@ -70,8 +71,8 @@ trait RunnerOrchestration { withRunner(_.runMain(classPath)) private class Runner(private var process: Process) { - private var childStdout: BufferedReader = _ - private var childStdin: PrintStream = _ + private var childStdout: BufferedReader = uninitialized + private var childStdin: PrintStream = uninitialized /** Checks if `process` is still alive *