@@ -616,9 +616,9 @@ final class Emitter[E >: Null <: js.Transformed.Value](
616
616
}
617
617
618
618
val fullClass = extractChanged {
619
- val fullClassCache = classCache.getFullClassCache ()
619
+ val fullClassChangeTracker = classCache.getFullClassChangeTracker ()
620
620
621
- fullClassCache.getOrElseUpdate (linkedClass.version, ctorWithGlobals,
621
+ fullClassChangeTracker.trackChanged (linkedClass.version, ctorWithGlobals,
622
622
memberMethodsWithGlobals, exportedMembersWithGlobals, {
623
623
for {
624
624
ctor <- ctorWithGlobals
@@ -635,7 +635,7 @@ final class Emitter[E >: Null <: js.Transformed.Value](
635
635
storeJSSuperClass.map(js.Transformed (_)), // invalidated by class version
636
636
useESClass, // invalidated by class version (depends on kind, config and ancestry only)
637
637
membersAsTrees, // invalidated directly
638
- )(moduleContext, fullClassCache , linkedClass.pos) // pos invalidated by class version
638
+ )(moduleContext, fullClassChangeTracker , linkedClass.pos) // pos invalidated by class version
639
639
} yield {
640
640
// Avoid a nested post transform if we just got the original members back.
641
641
if (clazz eq membersAsTrees) {
@@ -849,7 +849,7 @@ final class Emitter[E >: Null <: js.Transformed.Value](
849
849
private [this ] val _exportedMembersCache =
850
850
mutable.Map .empty[Int , MethodCache [E ]]
851
851
852
- private [this ] var _fullClassCache : Option [FullClassCache ] = None
852
+ private [this ] var _fullClassChangeTracker : Option [FullClassChangeTracker ] = None
853
853
854
854
override def invalidate (): Unit = {
855
855
/* Do not invalidate contained methods, as they have their own
@@ -865,7 +865,7 @@ final class Emitter[E >: Null <: js.Transformed.Value](
865
865
_methodCaches.foreach(_.valuesIterator.foreach(_.startRun()))
866
866
_memberMethodCache.valuesIterator.foreach(_.startRun())
867
867
_constructorCache.foreach(_.startRun())
868
- _fullClassCache .foreach(_.startRun())
868
+ _fullClassChangeTracker .foreach(_.startRun())
869
869
}
870
870
871
871
def getCache (version : Version ): (DesugaredClassCache [E ], Boolean ) = {
@@ -904,10 +904,10 @@ final class Emitter[E >: Null <: js.Transformed.Value](
904
904
def getExportedMemberCache (idx : Int ): MethodCache [E ] =
905
905
_exportedMembersCache.getOrElseUpdate(idx, new MethodCache )
906
906
907
- def getFullClassCache (): FullClassCache = {
908
- _fullClassCache .getOrElse {
909
- val cache = new FullClassCache
910
- _fullClassCache = Some (cache)
907
+ def getFullClassChangeTracker (): FullClassChangeTracker = {
908
+ _fullClassChangeTracker .getOrElse {
909
+ val cache = new FullClassChangeTracker
910
+ _fullClassChangeTracker = Some (cache)
911
911
cache
912
912
}
913
913
}
@@ -921,8 +921,8 @@ final class Emitter[E >: Null <: js.Transformed.Value](
921
921
922
922
_exportedMembersCache.filterInPlace((_, c) => c.cleanAfterRun())
923
923
924
- if (_fullClassCache .exists(! _.cleanAfterRun()))
925
- _fullClassCache = None
924
+ if (_fullClassChangeTracker .exists(! _.cleanAfterRun()))
925
+ _fullClassChangeTracker = None
926
926
927
927
if (! _cacheUsed)
928
928
invalidate()
@@ -967,26 +967,24 @@ final class Emitter[E >: Null <: js.Transformed.Value](
967
967
}
968
968
}
969
969
970
- private class FullClassCache extends knowledgeGuardian.KnowledgeAccessor {
971
- private [this ] var _tree : WithGlobals [List [E ]] = null
970
+ private class FullClassChangeTracker extends knowledgeGuardian.KnowledgeAccessor {
972
971
private [this ] var _lastVersion : Version = Version .Unversioned
973
972
private [this ] var _lastCtor : WithGlobals [E ] = null
974
973
private [this ] var _lastMemberMethods : List [WithGlobals [E ]] = null
975
974
private [this ] var _lastExportedMembers : List [WithGlobals [E ]] = null
976
- private [this ] var _cacheUsed = false
975
+ private [this ] var _trackerUsed = false
977
976
978
977
override def invalidate (): Unit = {
979
978
super .invalidate()
980
- _tree = null
981
979
_lastVersion = Version .Unversioned
982
980
_lastCtor = null
983
981
_lastMemberMethods = null
984
982
_lastExportedMembers = null
985
983
}
986
984
987
- def startRun (): Unit = _cacheUsed = false
985
+ def startRun (): Unit = _trackerUsed = false
988
986
989
- def getOrElseUpdate (version : Version , ctor : WithGlobals [E ],
987
+ def trackChanged (version : Version , ctor : WithGlobals [E ],
990
988
memberMethods : List [WithGlobals [E ]], exportedMembers : List [WithGlobals [E ]],
991
989
compute : => WithGlobals [List [E ]]): (WithGlobals [List [E ]], Boolean ) = {
992
990
@@ -998,28 +996,32 @@ final class Emitter[E >: Null <: js.Transformed.Value](
998
996
}
999
997
}
1000
998
1001
- _cacheUsed = true
999
+ _trackerUsed = true
1002
1000
1003
- if (_tree == null || ! version.sameVersion(_lastVersion) || (_lastCtor ne ctor) ||
1001
+ if (! version.sameVersion(_lastVersion) || (_lastCtor ne ctor) ||
1004
1002
! allSame(_lastMemberMethods, memberMethods) ||
1005
1003
! allSame(_lastExportedMembers, exportedMembers)) {
1004
+ // Input has changed or we were invalidated.
1005
+ // Clean knowledge tracking and re-track dependencies.
1006
1006
invalidate()
1007
- _tree = compute
1008
1007
_lastVersion = version
1009
1008
_lastCtor = ctor
1010
1009
_lastMemberMethods = memberMethods
1011
1010
_lastExportedMembers = exportedMembers
1012
- (_tree, true )
1011
+
1012
+ (compute, true )
1013
1013
} else {
1014
- (_tree, false )
1014
+ // Input has not changed and we were not invalidated.
1015
+ // --> nothing has changed (we recompute to save memory).
1016
+ (compute, false )
1015
1017
}
1016
1018
}
1017
1019
1018
1020
def cleanAfterRun (): Boolean = {
1019
- if (! _cacheUsed )
1021
+ if (! _trackerUsed )
1020
1022
invalidate()
1021
1023
1022
- _cacheUsed
1024
+ _trackerUsed
1023
1025
}
1024
1026
}
1025
1027
0 commit comments