@@ -2,7 +2,6 @@ package dotty.tools
22package backend
33package jvm
44
5- import scala .language .unsafeNulls
65import scala .annotation .tailrec
76import scala .collection .{immutable , mutable }
87import scala .tools .asm
@@ -23,6 +22,8 @@ import SymbolUtils.given
2322import dotty .tools .dotc .core .NameOps .isStaticConstructorName
2423import tpd .*
2524
25+ import scala .compiletime .uninitialized
26+
2627/*
2728 *
2829 * @author Miguel Garcia, http://lamp.epfl.ch/~magarcia/ScalaCompilerCornerReloaded/
@@ -132,14 +133,14 @@ trait BCodeSkelBuilder extends BCodeHelpers {
132133 with BCJGenSigGen {
133134
134135 // Strangely I can't find this in the asm code 255, but reserving 1 for "this"
135- inline val MaximumJvmParameters = 254
136+ private inline val MaximumJvmParameters = 254
136137
137138 // current class
138- var cnode : ClassNode1 = null
139- var thisName : String = null // the internal name of the class being emitted
139+ private var cnode : ClassNode1 = uninitialized
140+ private var thisName : String = uninitialized // the internal name of the class being emitted
140141
141- var claszSymbol : Symbol = null
142- var isCZStaticModule = false
142+ protected var claszSymbol : Symbol = uninitialized
143+ private var isCZStaticModule = false
143144
144145 // keep track of interfaces that are used in super calls, as they need to be directly inherited even if they are also indirectly inherited
145146 val superCallTargets = mutable.LinkedHashSet [ClassBType ]()
@@ -160,7 +161,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
160161
161162 /* ---------------- helper utils for generating classes and fields ---------------- */
162163
163- def genPlainClass (cd0 : TypeDef )(using Context ) = (cd0 : @ unchecked) match {
164+ def genPlainClass (cd0 : TypeDef )(using Context ): ClassNode1 = (cd0 : @ unchecked) match {
164165 case TypeDef (_, impl : Template ) =>
165166 assert(cnode == null , " GenBCode detected nested methods." )
166167
@@ -288,7 +289,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
288289 TraceUtils .traceClassIfRequested(cnode)
289290
290291 assert(cd.symbol == claszSymbol, " Someone messed up BCodePhase.claszSymbol during genPlainClass()." )
291-
292+ cnode
292293 } // end of method genPlainClass()
293294
294295 /*
@@ -386,7 +387,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
386387 .addFlagIf(! sym.is(Mutable ), ACC_FINAL )
387388 }
388389
389- def addClassField (f : Symbol )(using Context ): Unit = {
390+ private def addClassField (f : Symbol )(using Context ): Unit = {
390391 val javagensig = getGenericSignature(f, claszSymbol)
391392 val flags = javaFieldFlags(f)
392393
@@ -404,7 +405,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
404405 emitAnnotations(jfield, f.annotations)
405406 }
406407
407- def addClassFields ()(using Context ): Unit =
408+ private def addClassFields ()(using Context ): Unit =
408409 /* Non-method term members are fields, except for module members. Module
409410 * members can only happen on .NET (no flatten) for inner traits. There,
410411 * a module symbol is generated (transformInfo in mixin) which is used
@@ -415,18 +416,18 @@ trait BCodeSkelBuilder extends BCodeHelpers {
415416 claszSymbol.info.decls.filter(p => p.isTerm && ! p.is(Method )).foreach(addClassField)
416417
417418 // current method
418- var mnode : MethodNode1 = null
419- var jMethodName : String = null
420- var isMethSymStaticCtor = false
421- var returnType : BType = null
422- var methSymbol : Symbol = null
419+ var mnode : MethodNode1 = uninitialized
420+ var jMethodName : String = uninitialized
421+ private var isMethSymStaticCtor = false
422+ var returnType : BType = uninitialized
423+ var methSymbol : Symbol = uninitialized
423424 // used by genLoadTry() and genSynchronized()
424- var earlyReturnVar : Symbol = null
425+ var earlyReturnVar : Symbol | Null = null
425426 var shouldEmitCleanup = false
426427 // stack tracking
427428 val stack = new BTypesStack
428429 // line numbers
429- var lastEmittedLineNr = - 1
430+ private var lastEmittedLineNr = - 1
430431
431432 object bc extends JCodeMethodN {
432433 override def jmethod = PlainSkelBuilder .this .mnode
@@ -439,7 +440,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
439440 * The `jumpDest` map is used to find the `LoadDestination` at the end of the `Labeled` block, as well as the
440441 * corresponding expected type. The `LoadDestination` can never be `FallThrough` here.
441442 */
442- var jumpDest : immutable.Map [ /* Labeled */ Symbol , (BType , LoadDestination ) ] = null
443+ var jumpDest : immutable.Map [ /* Labeled */ Symbol , (BType , LoadDestination ) ] = immutable. Map .empty
443444 def registerJumpDest (labelSym : Symbol , expectedType : BType , dest : LoadDestination )(using Context ): Unit = {
444445 assert(labelSym.is(Label ), s " trying to register a jump-dest for a non-label symbol, at: ${labelSym.span}" )
445446 assert(dest != LoadDestination .FallThrough , s " trying to register a FallThrough dest for label, at: ${labelSym.span}" )
@@ -483,10 +484,10 @@ trait BCodeSkelBuilder extends BCodeHelpers {
483484 * emitted for that purpose as described in `genLoadTry()` and `genSynchronized()`.
484485 */
485486 var cleanups : List [asm.Label ] = Nil
486- def registerCleanup (finCleanup : asm.Label ): Unit = {
487+ def registerCleanup (finCleanup : asm.Label | Null ): Unit = {
487488 if (finCleanup != null ) { cleanups = finCleanup :: cleanups }
488489 }
489- def unregisterCleanup (finCleanup : asm.Label ): Unit = {
490+ def unregisterCleanup (finCleanup : asm.Label | Null ): Unit = {
490491 if (finCleanup != null ) {
491492 assert(cleanups.head eq finCleanup,
492493 s " Bad nesting of cleanup operations: $cleanups trying to unregister: $finCleanup" )
@@ -584,7 +585,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
584585 /* ---------------- Part 2 of program points, ie Labels in the ASM world ---------------- */
585586
586587 // bookkeeping the scopes of non-synthetic local vars, to emit debug info (`emitVars`).
587- var varsInScope : List [(Symbol , asm.Label )] = null // (local-var-sym -> start-of-scope)
588+ var varsInScope : List [(Symbol , asm.Label )] | Null = null // (local-var-sym -> start-of-scope)
588589
589590 // helpers around program-points.
590591 def lastInsn : asm.tree.AbstractInsnNode = mnode.instructions.getLast
@@ -805,7 +806,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
805806 .withAttachment(BCodeHelpers .UseInvokeSpecial , ())
806807 })
807808
808- def genDefDef (dd : DefDef )(using Context ): Unit = {
809+ private def genDefDef (dd : DefDef )(using Context ): Unit = {
809810 val rhs = dd.rhs
810811 val vparamss = dd.termParamss
811812 // the only method whose implementation is not emitted: getClass()
@@ -923,7 +924,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
923924
924925 TraceUtils .traceMethodIfRequested(mnode)
925926
926- mnode = null
927+ mnode = null . asInstanceOf [ MethodNode1 ] // for GC
927928 } // end of method genDefDef()
928929
929930 def emitLocalVarScope (sym : Symbol , start : asm.Label , end : asm.Label , force : Boolean = false ): Unit = {
0 commit comments