@@ -620,9 +620,9 @@ final class Emitter[E >: Null <: js.Transformed.Value](
620
620
}
621
621
622
622
val fullClass = extractChanged {
623
- val fullClassCache = classCache.getFullClassCache ()
623
+ val fullClassChangeTracker = classCache.getFullClassChangeTracker ()
624
624
625
- fullClassCache.getOrElseUpdate (linkedClass.version, ctorWithGlobals,
625
+ fullClassChangeTracker.trackChanged (linkedClass.version, ctorWithGlobals,
626
626
memberMethodsWithGlobals, exportedMembersWithGlobals, {
627
627
for {
628
628
ctor <- ctorWithGlobals
@@ -639,7 +639,7 @@ final class Emitter[E >: Null <: js.Transformed.Value](
639
639
storeJSSuperClass.map(js.Transformed (_)), // invalidated by class version
640
640
useESClass, // invalidated by class version (depends on kind, config and ancestry only)
641
641
membersAsTrees // invalidated directly
642
- )(moduleContext, fullClassCache , linkedClass.pos) // pos invalidated by class version
642
+ )(moduleContext, fullClassChangeTracker , linkedClass.pos) // pos invalidated by class version
643
643
} yield {
644
644
// Avoid a nested post transform if we just got the original members back.
645
645
if (clazz eq membersAsTrees) {
@@ -863,7 +863,7 @@ final class Emitter[E >: Null <: js.Transformed.Value](
863
863
private [this ] val _exportedMembersCache =
864
864
mutable.Map .empty[Int , MethodCache [E ]]
865
865
866
- private [this ] var _fullClassCache : Option [FullClassCache ] = None
866
+ private [this ] var _fullClassChangeTracker : Option [FullClassChangeTracker ] = None
867
867
868
868
override def invalidate (): Unit = {
869
869
/* Do not invalidate contained methods, as they have their own
@@ -879,7 +879,7 @@ final class Emitter[E >: Null <: js.Transformed.Value](
879
879
_methodCaches.foreach(_.valuesIterator.foreach(_.startRun()))
880
880
_memberMethodCache.valuesIterator.foreach(_.startRun())
881
881
_constructorCache.foreach(_.startRun())
882
- _fullClassCache .foreach(_.startRun())
882
+ _fullClassChangeTracker .foreach(_.startRun())
883
883
}
884
884
885
885
def getCache (version : Version ): (DesugaredClassCache [E ], Boolean ) = {
@@ -918,10 +918,10 @@ final class Emitter[E >: Null <: js.Transformed.Value](
918
918
def getExportedMemberCache (idx : Int ): MethodCache [E ] =
919
919
_exportedMembersCache.getOrElseUpdate(idx, new MethodCache )
920
920
921
- def getFullClassCache (): FullClassCache = {
922
- _fullClassCache .getOrElse {
923
- val cache = new FullClassCache
924
- _fullClassCache = Some (cache)
921
+ def getFullClassChangeTracker (): FullClassChangeTracker = {
922
+ _fullClassChangeTracker .getOrElse {
923
+ val cache = new FullClassChangeTracker
924
+ _fullClassChangeTracker = Some (cache)
925
925
cache
926
926
}
927
927
}
@@ -935,8 +935,8 @@ final class Emitter[E >: Null <: js.Transformed.Value](
935
935
936
936
_exportedMembersCache.filterInPlace((_, c) => c.cleanAfterRun())
937
937
938
- if (_fullClassCache .exists(! _.cleanAfterRun()))
939
- _fullClassCache = None
938
+ if (_fullClassChangeTracker .exists(! _.cleanAfterRun()))
939
+ _fullClassChangeTracker = None
940
940
941
941
if (! _cacheUsed)
942
942
invalidate()
@@ -981,26 +981,24 @@ final class Emitter[E >: Null <: js.Transformed.Value](
981
981
}
982
982
}
983
983
984
- private class FullClassCache extends knowledgeGuardian.KnowledgeAccessor {
985
- private [this ] var _tree : WithGlobals [List [E ]] = null
984
+ private class FullClassChangeTracker extends knowledgeGuardian.KnowledgeAccessor {
986
985
private [this ] var _lastVersion : Version = Version .Unversioned
987
986
private [this ] var _lastCtor : WithGlobals [E ] = null
988
987
private [this ] var _lastMemberMethods : List [WithGlobals [E ]] = null
989
988
private [this ] var _lastExportedMembers : List [WithGlobals [E ]] = null
990
- private [this ] var _cacheUsed = false
989
+ private [this ] var _trackerUsed = false
991
990
992
991
override def invalidate (): Unit = {
993
992
super .invalidate()
994
- _tree = null
995
993
_lastVersion = Version .Unversioned
996
994
_lastCtor = null
997
995
_lastMemberMethods = null
998
996
_lastExportedMembers = null
999
997
}
1000
998
1001
- def startRun (): Unit = _cacheUsed = false
999
+ def startRun (): Unit = _trackerUsed = false
1002
1000
1003
- def getOrElseUpdate (version : Version , ctor : WithGlobals [E ],
1001
+ def trackChanged (version : Version , ctor : WithGlobals [E ],
1004
1002
memberMethods : List [WithGlobals [E ]], exportedMembers : List [WithGlobals [E ]],
1005
1003
compute : => WithGlobals [List [E ]]): (WithGlobals [List [E ]], Boolean ) = {
1006
1004
@@ -1012,28 +1010,32 @@ final class Emitter[E >: Null <: js.Transformed.Value](
1012
1010
}
1013
1011
}
1014
1012
1015
- _cacheUsed = true
1013
+ _trackerUsed = true
1016
1014
1017
- if (_tree == null || ! version.sameVersion(_lastVersion) || (_lastCtor ne ctor) ||
1015
+ if (! version.sameVersion(_lastVersion) || (_lastCtor ne ctor) ||
1018
1016
! allSame(_lastMemberMethods, memberMethods) ||
1019
1017
! allSame(_lastExportedMembers, exportedMembers)) {
1018
+ // Input has changed or we were invalidated.
1019
+ // Clean knowledge tracking and re-track dependencies.
1020
1020
invalidate()
1021
- _tree = compute
1022
1021
_lastVersion = version
1023
1022
_lastCtor = ctor
1024
1023
_lastMemberMethods = memberMethods
1025
1024
_lastExportedMembers = exportedMembers
1026
- (_tree, true )
1025
+
1026
+ (compute, true )
1027
1027
} else {
1028
- (_tree, false )
1028
+ // Input has not changed and we were not invalidated.
1029
+ // --> nothing has changed (we recompute to save memory).
1030
+ (compute, false )
1029
1031
}
1030
1032
}
1031
1033
1032
1034
def cleanAfterRun (): Boolean = {
1033
- if (! _cacheUsed )
1035
+ if (! _trackerUsed )
1034
1036
invalidate()
1035
1037
1036
- _cacheUsed
1038
+ _trackerUsed
1037
1039
}
1038
1040
}
1039
1041
0 commit comments