@@ -28,6 +28,7 @@ import printing._
28
28
import config .{JavaPlatform , SJSPlatform , Platform , ScalaSettings }
29
29
import classfile .ReusableDataReader
30
30
import StdNames .nme
31
+ import compiletime .uninitialized
31
32
32
33
import scala .annotation .internal .sharable
33
34
@@ -310,7 +311,7 @@ object Contexts {
310
311
/** If -Ydebug is on, the top of the stack trace where this context
311
312
* was created, otherwise `null`.
312
313
*/
313
- private var creationTrace: Array[StackTraceElement] = _
314
+ private var creationTrace: Array[StackTraceElement] = uninitialized
314
315
315
316
private def setCreationTrace() =
316
317
creationTrace = (new Throwable).getStackTrace().take(20)
@@ -517,55 +518,41 @@ object Contexts {
517
518
*/
518
519
class FreshContext (base : ContextBase ) extends Context (base) {
519
520
520
- private var _outer : Context = _
521
- protected def outer_= (outer : Context ): Unit = _outer = outer
521
+ private var _outer : Context = uninitialized
522
522
def outer : Context = _outer
523
523
524
- private var _period : Period = _
525
- protected def period_= (period : Period ): Unit =
526
- assert(period.firstPhaseId == period.lastPhaseId, period)
524
+ private var _period : Period = uninitialized
527
525
_period = period
528
526
final def period : Period = _period
529
527
530
- private var _mode : Mode = _
531
- protected def mode_= (mode : Mode ): Unit = _mode = mode
528
+ private var _mode : Mode = uninitialized
532
529
final def mode : Mode = _mode
533
530
534
- private var _owner : Symbol = _
535
- protected def owner_= (owner : Symbol ): Unit = _owner = owner
531
+ private var _owner : Symbol = uninitialized
536
532
final def owner : Symbol = _owner
537
533
538
- /** The current tree */
539
534
private var _tree : Tree [? ]= _
540
- protected def tree_= (tree : Tree [? ]): Unit = _tree = tree
541
535
final def tree : Tree [? ] = _tree
542
536
543
- private var _scope : Scope = _
544
- protected def scope_= (scope : Scope ): Unit = _scope = scope
537
+ private var _scope : Scope = uninitialized
545
538
final def scope : Scope = _scope
546
539
547
- private var _typerState : TyperState = _
548
- protected def typerState_= (typerState : TyperState ): Unit = _typerState = typerState
540
+ private var _typerState : TyperState = uninitialized
549
541
final def typerState : TyperState = _typerState
550
542
551
- private var _gadt : GadtConstraint = _
552
- protected def gadt_= (gadt : GadtConstraint ): Unit = _gadt = gadt
543
+ private var _gadt : GadtConstraint = uninitialized
553
544
final def gadt : GadtConstraint = _gadt
554
545
555
- private var _searchHistory : SearchHistory = _
556
- protected def searchHistory_= (searchHistory : SearchHistory ): Unit = _searchHistory = searchHistory
546
+ private var _searchHistory : SearchHistory = uninitialized
557
547
final def searchHistory : SearchHistory = _searchHistory
558
548
559
- private var _source : SourceFile = _
560
- protected def source_= (source : SourceFile ): Unit = _source = source
549
+ private var _source : SourceFile = uninitialized
561
550
final def source : SourceFile = _source
562
551
563
- private var _moreProperties : Map [Key [Any ], Any ] = _
564
- protected def moreProperties_= (moreProperties : Map [Key [Any ], Any ]): Unit = _moreProperties = moreProperties
552
+ private var _moreProperties : Map [Key [Any ], Any ] = uninitialized
565
553
final def moreProperties : Map [Key [Any ], Any ] = _moreProperties
566
554
567
- private var _store : Store = _
568
- protected def store_= (store : Store ): Unit = _store = store
555
+ private var _store : Store = uninitialized
569
556
final def store : Store = _store
570
557
571
558
/** Initialize all context fields, except typerState, which has to be set separately
@@ -593,51 +580,74 @@ object Contexts {
593
580
594
581
def setPeriod (period : Period ): this .type =
595
582
util.Stats .record(" Context.setPeriod" )
596
- this .period = period
583
+ assert(period.firstPhaseId == period.lastPhaseId, period)
584
+ this ._period = period
597
585
this
586
+
598
587
def setMode (mode : Mode ): this .type =
599
588
util.Stats .record(" Context.setMode" )
600
- this .mode = mode
589
+ this ._mode = mode
601
590
this
591
+
602
592
def setOwner (owner : Symbol ): this .type =
603
593
util.Stats .record(" Context.setOwner" )
604
594
assert(owner != NoSymbol )
605
- this .owner = owner
595
+ this ._owner = owner
606
596
this
597
+
607
598
def setTree (tree : Tree [? ]): this .type =
608
599
util.Stats .record(" Context.setTree" )
609
- this .tree = tree
600
+ this ._tree = tree
610
601
this
611
- def setScope (scope : Scope ): this .type = { this .scope = scope; this }
602
+
603
+ def setScope (scope : Scope ): this .type =
604
+ this ._scope = scope
605
+ this
606
+
612
607
def setNewScope : this .type =
613
608
util.Stats .record(" Context.setScope" )
614
- this .scope = newScope
609
+ this ._scope = newScope
615
610
this
616
- def setTyperState (typerState : TyperState ): this .type = { this .typerState = typerState; this }
617
- def setNewTyperState (): this .type = setTyperState(typerState.fresh(committable = true ))
618
- def setExploreTyperState (): this .type = setTyperState(typerState.fresh(committable = false ))
619
- def setReporter (reporter : Reporter ): this .type = setTyperState(typerState.fresh().setReporter(reporter))
620
- def setTyper (typer : Typer ): this .type = { this .scope = typer.scope; setTypeAssigner(typer) }
611
+
612
+ def setTyperState (typerState : TyperState ): this .type =
613
+ this ._typerState = typerState
614
+ this
615
+ def setNewTyperState (): this .type =
616
+ setTyperState(typerState.fresh(committable = true ))
617
+ def setExploreTyperState (): this .type =
618
+ setTyperState(typerState.fresh(committable = false ))
619
+ def setReporter (reporter : Reporter ): this .type =
620
+ setTyperState(typerState.fresh().setReporter(reporter))
621
+
622
+ def setTyper (typer : Typer ): this .type =
623
+ this ._scope = typer.scope
624
+ setTypeAssigner(typer)
625
+
621
626
def setGadt (gadt : GadtConstraint ): this .type =
622
627
util.Stats .record(" Context.setGadt" )
623
- this .gadt = gadt
628
+ this ._gadt = gadt
624
629
this
625
- def setFreshGADTBounds : this .type = setGadt(gadt.fresh)
630
+ def setFreshGADTBounds : this .type =
631
+ setGadt(gadt.fresh)
632
+
626
633
def setSearchHistory (searchHistory : SearchHistory ): this .type =
627
634
util.Stats .record(" Context.setSearchHistory" )
628
- this .searchHistory = searchHistory
635
+ this ._searchHistory = searchHistory
629
636
this
637
+
630
638
def setSource (source : SourceFile ): this .type =
631
639
util.Stats .record(" Context.setSource" )
632
- this .source = source
640
+ this ._source = source
633
641
this
642
+
634
643
private def setMoreProperties (moreProperties : Map [Key [Any ], Any ]): this .type =
635
644
util.Stats .record(" Context.setMoreProperties" )
636
- this .moreProperties = moreProperties
645
+ this ._moreProperties = moreProperties
637
646
this
647
+
638
648
private def setStore (store : Store ): this .type =
639
649
util.Stats .record(" Context.setStore" )
640
- this .store = store
650
+ this ._store = store
641
651
this
642
652
643
653
def setCompilationUnit (compilationUnit : CompilationUnit ): this .type = {
@@ -692,6 +702,28 @@ object Contexts {
692
702
def setDebug : this .type = setSetting(base.settings.Ydebug , true )
693
703
}
694
704
705
+ object FreshContext :
706
+ /** Defines an initial context with given context base and possible settings. */
707
+ def initial (base : ContextBase , settingsGroup : SettingGroup ): Context =
708
+ val c = new FreshContext (base)
709
+ c._outer = NoContext
710
+ c._period = InitialPeriod
711
+ c._mode = Mode .None
712
+ c._typerState = TyperState .initialState()
713
+ c._owner = NoSymbol
714
+ c._tree = untpd.EmptyTree
715
+ c._moreProperties = Map (MessageLimiter -> DefaultMessageLimiter ())
716
+ c._scope = EmptyScope
717
+ c._source = NoSource
718
+ c._store = initialStore
719
+ .updated(settingsStateLoc, settingsGroup.defaultState)
720
+ .updated(notNullInfosLoc, Nil )
721
+ .updated(compilationUnitLoc, NoCompilationUnit )
722
+ c._searchHistory = new SearchRoot
723
+ c._gadt = GadtConstraint .empty
724
+ c
725
+ end FreshContext
726
+
695
727
given ops : AnyRef with
696
728
extension (c : Context )
697
729
def addNotNullInfo (info : NotNullInfo ) =
@@ -807,30 +839,9 @@ object Contexts {
807
839
finally ctx.base.comparersInUse = saved
808
840
end comparing
809
841
810
- /** A class defining the initial context with given context base
811
- * and set of possible settings.
812
- */
813
- private class InitialContext (base : ContextBase , settingsGroup : SettingGroup ) extends FreshContext (base) {
814
- outer = NoContext
815
- period = InitialPeriod
816
- mode = Mode .None
817
- typerState = TyperState .initialState()
818
- owner = NoSymbol
819
- tree = untpd.EmptyTree
820
- moreProperties = Map (MessageLimiter -> DefaultMessageLimiter ())
821
- scope = EmptyScope
822
- source = NoSource
823
- store = initialStore
824
- .updated(settingsStateLoc, settingsGroup.defaultState)
825
- .updated(notNullInfosLoc, Nil )
826
- .updated(compilationUnitLoc, NoCompilationUnit )
827
- searchHistory = new SearchRoot
828
- gadt = GadtConstraint .empty
829
- }
830
-
831
842
@ sharable val NoContext : Context = new FreshContext ((null : ContextBase | Null ).uncheckedNN) {
832
- source = NoSource
833
843
override val implicits : ContextualImplicits = new ContextualImplicits (Nil , null , false )(this : @ unchecked)
844
+ setSource(NoSource )
834
845
}
835
846
836
847
/** A context base defines state and associated methods that exist once per
@@ -844,10 +855,10 @@ object Contexts {
844
855
val settings : ScalaSettings = new ScalaSettings
845
856
846
857
/** The initial context */
847
- val initialCtx : Context = new InitialContext (this , settings)
858
+ val initialCtx : Context = FreshContext .initial (this : @ unchecked , settings)
848
859
849
860
/** The platform, initialized by `initPlatform()`. */
850
- private var _platform : Platform | Null = _
861
+ private var _platform : Platform | Null = uninitialized
851
862
852
863
/** The platform */
853
864
def platform : Platform = {
@@ -933,18 +944,18 @@ object Contexts {
933
944
934
945
// Phases state
935
946
936
- private [core] var phasesPlan : List [List [Phase ]] = _
947
+ private [core] var phasesPlan : List [List [Phase ]] = uninitialized
937
948
938
949
/** Phases by id */
939
- private [dotc] var phases : Array [Phase ] = _
950
+ private [dotc] var phases : Array [Phase ] = uninitialized
940
951
941
952
/** Phases with consecutive Transforms grouped into a single phase, Empty array if fusion is disabled */
942
953
private [core] var fusedPhases : Array [Phase ] = Array .empty[Phase ]
943
954
944
955
/** Next denotation transformer id */
945
- private [core] var nextDenotTransformerId : Array [Int ] = _
956
+ private [core] var nextDenotTransformerId : Array [Int ] = uninitialized
946
957
947
- private [core] var denotTransformers : Array [DenotTransformer ] = _
958
+ private [core] var denotTransformers : Array [DenotTransformer ] = uninitialized
948
959
949
960
/** Flag to suppress inlining, set after overflow */
950
961
private [dotc] var stopInlining : Boolean = false
@@ -978,7 +989,7 @@ object Contexts {
978
989
979
990
private [core] val reusableDataReader = ReusableInstance (new ReusableDataReader ())
980
991
981
- private [dotc] var wConfCache : (List [String ], WConf ) = _
992
+ private [dotc] var wConfCache : (List [String ], WConf ) = uninitialized
982
993
983
994
def sharedCharArray (len : Int ): Array [Char ] =
984
995
while len > charArray.length do
0 commit comments