1212import de .peeeq .wurstscript .ast .*;
1313import de .peeeq .wurstscript .gui .WurstGui ;
1414import de .peeeq .wurstscript .gui .WurstGuiLogger ;
15+ import de .peeeq .wurstscript .intermediatelang .interpreter .LocalState ;
16+ import de .peeeq .wurstscript .jassIm .ImFunction ;
17+ import de .peeeq .wurstscript .jassIm .JassIm ;
1518import de .peeeq .wurstscript .types .WurstType ;
1619import de .peeeq .wurstscript .types .WurstTypeClass ;
1720import de .peeeq .wurstscript .types .WurstTypeString ;
2730import java .io .File ;
2831import java .io .IOException ;
2932import java .nio .file .Files ;
33+ import java .util .Collections ;
3034import java .util .HashMap ;
3135import java .util .Map ;
3236import java .util .concurrent .atomic .AtomicBoolean ;
@@ -484,7 +488,7 @@ private CacheFixture setupCacheFixture(String projectName) throws IOException {
484488 assertTrue (GlobalCaches .lookupCache .containsKey (keyC ));
485489 assertTrue (GlobalCaches .lookupCache .containsKey (keyD ));
486490
487- return new CacheFixture (manager , results , fileA , fileB , fileC , fileD , keyA , keyB , keyC , keyD );
491+ return new CacheFixture (manager , results , fileA , fileB , fileC , fileD , keyA , keyB , keyC , keyD , pkgA , pkgB , pkgC , pkgD );
488492 }
489493
490494 private static final class CacheFixture {
@@ -498,10 +502,15 @@ private static final class CacheFixture {
498502 final GlobalCaches .CacheKey keyB ;
499503 final GlobalCaches .CacheKey keyC ;
500504 final GlobalCaches .CacheKey keyD ;
505+ final WPackage pkgA ;
506+ final WPackage pkgB ;
507+ final WPackage pkgC ;
508+ final WPackage pkgD ;
501509
502510 CacheFixture (ModelManagerImpl manager , Map <WFile , String > results , WFile fileA , WFile fileB ,
503511 WFile fileC , WFile fileD , GlobalCaches .CacheKey keyA , GlobalCaches .CacheKey keyB ,
504- GlobalCaches .CacheKey keyC , GlobalCaches .CacheKey keyD ) {
512+ GlobalCaches .CacheKey keyC , GlobalCaches .CacheKey keyD ,
513+ WPackage pkgA , WPackage pkgB , WPackage pkgC , WPackage pkgD ) {
505514 this .manager = manager ;
506515 this .results = results ;
507516 this .fileA = fileA ;
@@ -512,9 +521,54 @@ private static final class CacheFixture {
512521 this .keyB = keyB ;
513522 this .keyC = keyC ;
514523 this .keyD = keyD ;
524+ this .pkgA = pkgA ;
525+ this .pkgB = pkgB ;
526+ this .pkgC = pkgC ;
527+ this .pkgD = pkgD ;
515528 }
516529 }
517530
531+ private static final class NoArgCacheFixture {
532+ final ImFunction fnA ;
533+ final ImFunction fnB ;
534+ final ImFunction fnC ;
535+ final ImFunction fnD ;
536+
537+ NoArgCacheFixture (ImFunction fnA , ImFunction fnB , ImFunction fnC , ImFunction fnD ) {
538+ this .fnA = fnA ;
539+ this .fnB = fnB ;
540+ this .fnC = fnC ;
541+ this .fnD = fnD ;
542+ }
543+ }
544+
545+ private NoArgCacheFixture seedNoArgLocalStateCache (CacheFixture fixture ) {
546+ ImFunction fnA = JassIm .ImFunction (
547+ fixture .pkgA , "cachedA" , JassIm .ImTypeVars (), JassIm .ImVars (), JassIm .ImVoid (),
548+ JassIm .ImVars (), JassIm .ImStmts (), Collections .emptyList ());
549+ ImFunction fnB = JassIm .ImFunction (
550+ fixture .pkgB , "cachedB" , JassIm .ImTypeVars (), JassIm .ImVars (), JassIm .ImVoid (),
551+ JassIm .ImVars (), JassIm .ImStmts (), Collections .emptyList ());
552+ ImFunction fnC = JassIm .ImFunction (
553+ fixture .pkgC , "cachedC" , JassIm .ImTypeVars (), JassIm .ImVars (), JassIm .ImVoid (),
554+ JassIm .ImVars (), JassIm .ImStmts (), Collections .emptyList ());
555+ ImFunction fnD = JassIm .ImFunction (
556+ fixture .pkgD , "cachedD" , JassIm .ImTypeVars (), JassIm .ImVars (), JassIm .ImVoid (),
557+ JassIm .ImVars (), JassIm .ImStmts (), Collections .emptyList ());
558+
559+ GlobalCaches .LOCAL_STATE_NOARG_CACHE .put (fnA , new LocalState ());
560+ GlobalCaches .LOCAL_STATE_NOARG_CACHE .put (fnB , new LocalState ());
561+ GlobalCaches .LOCAL_STATE_NOARG_CACHE .put (fnC , new LocalState ());
562+ GlobalCaches .LOCAL_STATE_NOARG_CACHE .put (fnD , new LocalState ());
563+
564+ assertTrue (GlobalCaches .LOCAL_STATE_NOARG_CACHE .containsKey (fnA ));
565+ assertTrue (GlobalCaches .LOCAL_STATE_NOARG_CACHE .containsKey (fnB ));
566+ assertTrue (GlobalCaches .LOCAL_STATE_NOARG_CACHE .containsKey (fnC ));
567+ assertTrue (GlobalCaches .LOCAL_STATE_NOARG_CACHE .containsKey (fnD ));
568+
569+ return new NoArgCacheFixture (fnA , fnB , fnC , fnD );
570+ }
571+
518572 private void newCleanFolder (File f ) throws IOException {
519573 FileUtils .deleteRecursively (f );
520574 Files .createDirectories (f .toPath ());
@@ -608,6 +662,7 @@ public void visit(ClassDef c) {
608662 @ Test
609663 public void selectiveCacheInvalidationSkipsUnaffectedUnits () throws IOException {
610664 CacheFixture fixture = setupCacheFixture ("cacheInvalidationProject1" );
665+ NoArgCacheFixture noArg = seedNoArgLocalStateCache (fixture );
611666 fixture .results .clear ();
612667
613668 String packageBUpdated = string (
@@ -625,11 +680,17 @@ public void selectiveCacheInvalidationSkipsUnaffectedUnits() throws IOException
625680 assertFalse (GlobalCaches .lookupCache .containsKey (fixture .keyB ));
626681 assertTrue (GlobalCaches .lookupCache .containsKey (fixture .keyC ));
627682 assertTrue (GlobalCaches .lookupCache .containsKey (fixture .keyD ));
683+
684+ assertFalse (GlobalCaches .LOCAL_STATE_NOARG_CACHE .containsKey (noArg .fnA ));
685+ assertFalse (GlobalCaches .LOCAL_STATE_NOARG_CACHE .containsKey (noArg .fnB ));
686+ assertTrue (GlobalCaches .LOCAL_STATE_NOARG_CACHE .containsKey (noArg .fnC ));
687+ assertTrue (GlobalCaches .LOCAL_STATE_NOARG_CACHE .containsKey (noArg .fnD ));
628688 }
629689
630690 @ Test
631691 public void selectiveCacheInvalidationCoversTransitiveDependents () throws IOException {
632692 CacheFixture fixture = setupCacheFixture ("cacheInvalidationProject2" );
693+ NoArgCacheFixture noArg = seedNoArgLocalStateCache (fixture );
633694 fixture .results .clear ();
634695
635696 String packageCUpdated = string (
@@ -646,6 +707,11 @@ public void selectiveCacheInvalidationCoversTransitiveDependents() throws IOExce
646707 assertFalse (GlobalCaches .lookupCache .containsKey (fixture .keyB ));
647708 assertFalse (GlobalCaches .lookupCache .containsKey (fixture .keyC ));
648709 assertTrue (GlobalCaches .lookupCache .containsKey (fixture .keyD ));
710+
711+ assertFalse (GlobalCaches .LOCAL_STATE_NOARG_CACHE .containsKey (noArg .fnA ));
712+ assertFalse (GlobalCaches .LOCAL_STATE_NOARG_CACHE .containsKey (noArg .fnB ));
713+ assertFalse (GlobalCaches .LOCAL_STATE_NOARG_CACHE .containsKey (noArg .fnC ));
714+ assertTrue (GlobalCaches .LOCAL_STATE_NOARG_CACHE .containsKey (noArg .fnD ));
649715 }
650716
651717 @ Test
0 commit comments