Skip to content

Commit 8491d1e

Browse files
committed
Move type assigner to store
Thsi gets Context size down to 72 bytes from 80, assuming a 12 byte header and 8 byte rounding. In the type/* benchmark this gives a saving of ~700K contexts * 8 bytes = 5.4M vs a store allocation increase of 11K * ~90bytes -= 1M (approx).
1 parent ab35a35 commit 8491d1e

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

compiler/src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ object Contexts {
4949
private val (profilerLoc, store7) = store6.newLocation[Profiler]()
5050
private val (notNullInfosLoc, store8) = store7.newLocation[List[NotNullInfo]]()
5151
private val (importInfoLoc, store9) = store8.newLocation[ImportInfo]()
52+
private val (typeAssignerLoc, store10) = store9.newLocation[TypeAssigner](TypeAssigner)
5253

53-
private val initialStore = store9
54+
private val initialStore = store10
5455

5556
/** The current context */
5657
inline def ctx(using ctx: Context): Context = ctx
@@ -157,11 +158,6 @@ object Contexts {
157158
protected def typerState_=(typerState: TyperState): Unit = _typerState = typerState
158159
final def typerState: TyperState = _typerState
159160

160-
/** The current type assigner or typer */
161-
private var _typeAssigner: TypeAssigner = _
162-
protected def typeAssigner_=(typeAssigner: TypeAssigner): Unit = _typeAssigner = typeAssigner
163-
final def typeAssigner: TypeAssigner = _typeAssigner
164-
165161
/** The current bounds in force for type parameters appearing in a GADT */
166162
private var _gadt: GadtConstraint = _
167163
protected def gadt_=(gadt: GadtConstraint): Unit = _gadt = gadt
@@ -228,6 +224,9 @@ object Contexts {
228224
/** The currently active import info */
229225
def importInfo = store(importInfoLoc)
230226

227+
/** The current type assigner or typer */
228+
def typeAssigner: TypeAssigner = store(typeAssignerLoc)
229+
231230
/** The new implicit references that are introduced by this scope */
232231
protected var implicitsCache: ContextualImplicits = null
233232
def implicits: ContextualImplicits = {
@@ -483,7 +482,6 @@ object Contexts {
483482
_owner = origin.owner
484483
_tree = origin.tree
485484
_scope = origin.scope
486-
_typeAssigner = origin.typeAssigner
487485
_gadt = origin.gadt
488486
_searchHistory = origin.searchHistory
489487
_source = origin.source
@@ -574,10 +572,6 @@ object Contexts {
574572
def setNewTyperState(): this.type = setTyperState(typerState.fresh().setCommittable(true))
575573
def setExploreTyperState(): this.type = setTyperState(typerState.fresh().setCommittable(false))
576574
def setReporter(reporter: Reporter): this.type = setTyperState(typerState.fresh().setReporter(reporter))
577-
def setTypeAssigner(typeAssigner: TypeAssigner): this.type =
578-
util.Stats.record("Context.setTypeAssigner")
579-
this.typeAssigner = typeAssigner
580-
this
581575
def setTyper(typer: Typer): this.type = { this.scope = typer.scope; setTypeAssigner(typer) }
582576
def setGadt(gadt: GadtConstraint): this.type =
583577
util.Stats.record("Context.setGadt")
@@ -615,6 +609,7 @@ object Contexts {
615609
def setProfiler(profiler: Profiler): this.type = updateStore(profilerLoc, profiler)
616610
def setNotNullInfos(notNullInfos: List[NotNullInfo]): this.type = updateStore(notNullInfosLoc, notNullInfos)
617611
def setImportInfo(importInfo: ImportInfo): this.type = updateStore(importInfoLoc, importInfo)
612+
def setTypeAssigner(typeAssigner: TypeAssigner): this.type = updateStore(typeAssignerLoc, typeAssigner)
618613

619614
def setProperty[T](key: Key[T], value: T): this.type =
620615
setMoreProperties(moreProperties.updated(key, value))
@@ -741,7 +736,6 @@ object Contexts {
741736
typerState = TyperState.initialState()
742737
owner = NoSymbol
743738
tree = untpd.EmptyTree
744-
typeAssigner = TypeAssigner
745739
moreProperties = Map(MessageLimiter -> DefaultMessageLimiter())
746740
source = NoSource
747741
store = initialStore

0 commit comments

Comments
 (0)