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

0 commit comments

Comments
 (0)