Skip to content

Commit 827298e

Browse files
authored
Merge pull request #2741 from usethesource/fix/no-cache-during-loading
do not cache global functions during initialization anymore
2 parents d11f490 + 071ab6d commit 827298e

2 files changed

Lines changed: 21 additions & 14 deletions

File tree

src/org/rascalmpl/interpreter/env/ModuleEnvironment.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -583,22 +583,29 @@ public void getAllFunctions(String name, List<AbstractFunction> collection) {
583583
collection.addAll(lookupCachedFunctions(name));
584584
}
585585

586+
private List<AbstractFunction> lookupFunctionsNoCache(String name) {
587+
var result = new ArrayList<AbstractFunction>();
588+
super.getAllFunctions(name, result);
589+
590+
for (ModuleEnvironment mod : importedModulesResolved) {
591+
if (mod != null) {
592+
mod.getLocalPublicFunctions(name, result);
593+
}
594+
}
595+
return result;
596+
}
597+
586598
private List<AbstractFunction> lookupCachedFunctions(String name) {
587599
if (cachedPublicFunctions == null) {
588600
cachedPublicFunctions = io.usethesource.capsule.Map.Transient.of();
589601
}
590-
return cachedPublicFunctions.computeIfAbsent(name, n -> {
591-
var result = new ArrayList<AbstractFunction>();
592-
super.getAllFunctions(n, result);
593-
594-
for (ModuleEnvironment mod : importedModulesResolved) {
595-
596-
if (mod != null) {
597-
mod.getLocalPublicFunctions(n, result);
598-
}
599-
}
600-
return result;
601-
});
602+
603+
if (!initialized) {
604+
return lookupFunctionsNoCache(name);
605+
}
606+
else {
607+
return cachedPublicFunctions.computeIfAbsent(name, this::lookupFunctionsNoCache);
608+
}
602609
}
603610

604611
@Override

src/org/rascalmpl/library/lang/rascal/tests/basic/FunctionCachesAndGlobals.rsc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ default int f(int _) = 42;
44
int x = f(0);
55
int f(0) = 0;
66

7-
test bool globalInitLast() = x == 0;
87

9-
// test bool noCacheDuringInit() = f(0) == 0;
8+
test bool noCacheDuringInit() = f(0) == 0;
9+
test bool globalInitLast() = x == 0;

0 commit comments

Comments
 (0)