Skip to content

Commit

Permalink
Avoid caching narrow type
Browse files Browse the repository at this point in the history
  • Loading branch information
heshanpadmasiri committed Feb 28, 2025
1 parent f38db34 commit cca787b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -551,16 +551,17 @@ private static BRecordType registeredRecordType(String typeName, Module pkg) {
public static void registerRecordType(BRecordType recordType) {
String name = recordType.getName();
Module pkg = recordType.getPackage();
if (name == null || pkg == null) {
return;
}
if (name.contains("$anon")) {
TypeIdentifier typeIdentifier = new TypeIdentifier(pkg, name);
if (typeIdentifier.avoidCaching()) {
return;
}
TypeIdentifier typeIdentifier = new TypeIdentifier(pkg, name);
registeredRecordTypes.put(typeIdentifier, recordType);
}

private static boolean avoidCaching(String name, Module pkg) {
return name == null || pkg == null || name.contains("$anon") || name.contains("narrowType");
}

public static void resetAllCaches() {
RecordTypeCache.cache.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ public record TypeIdentifier(Module pkg, String typeName) {
assert typeName != null;
assert pkg != null;
}

public boolean avoidCaching() {
return typeName == null || pkg == null || typeName.contains("$anon") || typeName.contains("narrowType");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ private TypeCheckCacheFactory() {
}

public static TypeCheckCache get(TypeIdentifier identifier) {
if (identifier.avoidCaching()) {
return create();
}
var cached = cache.get(identifier);
if (cached != null) {
return cached;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ private TypeIdSupplier() {
}

public static int namedId(TypeIdentifier id) {
if (id.avoidCaching()) {
return getAnonId();
}
var cachedId = cache.get(id);
if (cachedId != null) {
return cachedId;
Expand Down

0 comments on commit cca787b

Please sign in to comment.