@@ -68,21 +68,20 @@ object Contexts {
68
68
* of all class fields of type context; allow them only in whitelisted
69
69
* classes (which should be short-lived).
70
70
*/
71
- abstract class Context extends Periods
72
- with Substituters
73
- with TypeOps
74
- with Phases
75
- with Printers
76
- with Symbols
77
- with SymDenotations
78
- with Reporting
79
- with NamerContextOps
80
- with Plugins
81
- with Cloneable { thiscontext =>
82
- implicit def ctx : Context = this
71
+ abstract class Context ( val base : ContextBase )
72
+ extends Periods
73
+ with Substituters
74
+ with TypeOps
75
+ with Phases
76
+ with Printers
77
+ with Symbols
78
+ with SymDenotations
79
+ with Reporting
80
+ with NamerContextOps
81
+ with Plugins
82
+ with Cloneable { thiscontext =>
83
83
84
- /** The context base at the root */
85
- val base : ContextBase
84
+ implicit def ctx : Context = this
86
85
87
86
/** All outer contexts, ending in `base.initialCtx` and then `NoContext` */
88
87
def outersIterator : Iterator [Context ] = new Iterator [Context ] {
@@ -94,83 +93,85 @@ object Contexts {
94
93
/** The outer context */
95
94
private [this ] var _outer : Context = _
96
95
protected def outer_= (outer : Context ): Unit = _outer = outer
97
- def outer : Context = _outer
96
+ final def outer : Context = _outer
98
97
99
98
/** The current context */
100
99
private [this ] var _period : Period = _
101
100
protected def period_= (period : Period ): Unit = {
102
101
assert(period.firstPhaseId == period.lastPhaseId, period)
103
102
_period = period
104
103
}
105
- def period : Period = _period
104
+ final def period : Period = _period
106
105
107
106
/** The scope nesting level */
108
107
private [this ] var _mode : Mode = _
109
108
protected def mode_= (mode : Mode ): Unit = _mode = mode
110
- def mode : Mode = _mode
109
+ final def mode : Mode = _mode
111
110
112
111
/** The current owner symbol */
113
112
private [this ] var _owner : Symbol = _
114
113
protected def owner_= (owner : Symbol ): Unit = _owner = owner
115
- def owner : Symbol = _owner
114
+ final def owner : Symbol = _owner
116
115
117
116
/** The current tree */
118
117
private [this ] var _tree : Tree [_ >: Untyped ]= _
119
118
protected def tree_= (tree : Tree [_ >: Untyped ]): Unit = _tree = tree
120
- def tree : Tree [_ >: Untyped ] = _tree
119
+ final def tree : Tree [_ >: Untyped ] = _tree
121
120
122
121
/** The current scope */
123
122
private [this ] var _scope : Scope = _
124
123
protected def scope_= (scope : Scope ): Unit = _scope = scope
125
- def scope : Scope = _scope
124
+ final def scope : Scope = _scope
126
125
127
126
/** The current type comparer */
128
127
private [this ] var _typerState : TyperState = _
129
128
protected def typerState_= (typerState : TyperState ): Unit = _typerState = typerState
130
- def typerState : TyperState = _typerState
129
+ final def typerState : TyperState = _typerState
131
130
132
131
/** The current type assigner or typer */
133
132
private [this ] var _typeAssigner : TypeAssigner = _
134
133
protected def typeAssigner_= (typeAssigner : TypeAssigner ): Unit = _typeAssigner = typeAssigner
135
- def typeAssigner : TypeAssigner = _typeAssigner
134
+ final def typeAssigner : TypeAssigner = _typeAssigner
136
135
137
136
/** The currently active import info */
138
137
private [this ] var _importInfo : ImportInfo = _
139
138
protected def importInfo_= (importInfo : ImportInfo ): Unit = _importInfo = importInfo
140
- def importInfo : ImportInfo = _importInfo
139
+ final def importInfo : ImportInfo = _importInfo
141
140
142
141
/** The current bounds in force for type parameters appearing in a GADT */
143
142
private [this ] var _gadt : GADTMap = _
144
143
protected def gadt_= (gadt : GADTMap ): Unit = _gadt = gadt
145
- def gadt : GADTMap = _gadt
144
+ final def gadt : GADTMap = _gadt
146
145
147
146
/** The history of implicit searches that are currently active */
148
147
private [this ] var _searchHistory : SearchHistory = null
149
148
protected def searchHistory_= (searchHistory : SearchHistory ): Unit = _searchHistory = searchHistory
150
- def searchHistory : SearchHistory = _searchHistory
149
+ final def searchHistory : SearchHistory = _searchHistory
151
150
152
151
/** The current type comparer. This ones updates itself automatically for
153
152
* each new context.
154
153
*/
155
- private [this ] var _typeComparer : TypeComparer = _
156
- protected def typeComparer_= (typeComparer : TypeComparer ): Unit = _typeComparer = typeComparer
157
- def typeComparer : TypeComparer = {
158
- if (_typeComparer.ctx ne this )
159
- _typeComparer = _typeComparer.copyIn(this )
154
+ private [this ] var _typeComparer : TypeComparer = null
155
+ protected def typeComparer_= (typeComparer : TypeComparer ): Unit = {
156
+ assert(typeComparer.ctx eq this )
157
+ _typeComparer = typeComparer
158
+ }
159
+ final def typeComparer : TypeComparer = {
160
+ if (_typeComparer == null ) _typeComparer = outer.typeComparer.copyIn(this )
160
161
_typeComparer
161
162
}
162
163
163
164
/** The current source file */
164
165
private [this ] var _source : SourceFile = _
165
166
protected def source_= (source : SourceFile ): Unit = _source = source
166
- def source : SourceFile = _source
167
+ final def source : SourceFile = _source
167
168
168
169
/** A map in which more contextual properties can be stored
169
170
* Typically used for attributes that are read and written only in special situations.
170
171
*/
171
172
private [this ] var _moreProperties : Map [Key [Any ], Any ] = _
172
173
protected def moreProperties_= (moreProperties : Map [Key [Any ], Any ]): Unit = _moreProperties = moreProperties
173
- def moreProperties : Map [Key [Any ], Any ] = _moreProperties
174
+ final def moreProperties : Map [Key [Any ], Any ] = _moreProperties
174
175
175
176
def property [T ](key : Key [T ]): Option [T ] =
176
177
moreProperties.get(key).asInstanceOf [Option [T ]]
@@ -182,7 +183,7 @@ object Contexts {
182
183
*/
183
184
private var _store : Store = _
184
185
protected def store_= (store : Store ): Unit = _store = store
185
- def store : Store = _store
186
+ final def store : Store = _store
186
187
187
188
/** The compiler callback implementation, or null if no callback will be called. */
188
189
def compilerCallback : CompilerCallback = store(compilerCallbackLoc)
@@ -258,7 +259,7 @@ object Contexts {
258
259
* phasedCtxs is array that uses phaseId's as indexes,
259
260
* contexts are created only on request and cached in this array
260
261
*/
261
- private [this ] var phasedCtx : Context = _
262
+ private [this ] var phasedCtx : Context = this
262
263
private [this ] var phasedCtxs : Array [Context ] = _
263
264
264
265
/** This context at given phase.
@@ -422,18 +423,28 @@ object Contexts {
422
423
base.settings.color.value == " always"
423
424
424
425
protected def init (outer : Context ): this .type = {
425
- this .outer = outer
426
- this .implicitsCache = null
427
- this .phasedCtx = this
428
- this .phasedCtxs = null
429
- this .sourceCtx = null
430
- // See comment related to `creationTrace` in this file
431
- // setCreationTrace()
426
+ _outer = outer
427
+ _period = outer.period
428
+ _mode = outer.mode
429
+ _owner = outer.owner
430
+ _tree = outer.tree
431
+ _scope = outer.scope
432
+ _typerState = outer.typerState
433
+ _typeAssigner = outer.typeAssigner
434
+ _importInfo = outer.importInfo
435
+ _gadt = outer.gadt
436
+ _searchHistory = outer.searchHistory
437
+ _source = outer.source
438
+ _moreProperties = outer.moreProperties
439
+ _store = outer.store
432
440
this
433
441
}
434
442
435
443
/** A fresh clone of this context. */
436
- def fresh : FreshContext = clone.asInstanceOf [FreshContext ].init(this )
444
+ def fresh : FreshContext = {
445
+ util.Stats .record(" Context.fresh" )
446
+ new FreshContext (base).init(this )
447
+ }
437
448
438
449
final def withOwner (owner : Symbol ): Context =
439
450
if (owner ne this .owner) fresh.setOwner(owner) else this
@@ -508,7 +519,7 @@ object Contexts {
508
519
/** A fresh context allows selective modification
509
520
* of its attributes using the with... methods.
510
521
*/
511
- abstract class FreshContext extends Context {
522
+ class FreshContext ( base : ContextBase ) extends Context (base) {
512
523
def setPeriod (period : Period ): this .type = { this .period = period; this }
513
524
def setMode (mode : Mode ): this .type = { this .mode = mode; this }
514
525
def setOwner (owner : Symbol ): this .type = { assert(owner != NoSymbol ); this .owner = owner; this }
@@ -592,7 +603,7 @@ object Contexts {
592
603
/** A class defining the initial context with given context base
593
604
* and set of possible settings.
594
605
*/
595
- private class InitialContext (val base : ContextBase , settingsGroup : SettingGroup ) extends FreshContext {
606
+ private class InitialContext (base : ContextBase , settingsGroup : SettingGroup ) extends FreshContext (base) {
596
607
outer = NoContext
597
608
period = InitialPeriod
598
609
mode = Mode .None
@@ -608,9 +619,8 @@ object Contexts {
608
619
gadt = EmptyGADTMap
609
620
}
610
621
611
- @ sharable object NoContext extends Context {
612
- override def source = NoSource
613
- val base : ContextBase = null
622
+ @ sharable object NoContext extends Context (null ) {
623
+ source = NoSource
614
624
override val implicits : ContextualImplicits = new ContextualImplicits (Nil , null )(this )
615
625
}
616
626
0 commit comments