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