Skip to content

Commit

Permalink
Address review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
rdulmina committed Jan 31, 2025
1 parent 4640af1 commit b897f30
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ private BType silentIntTypeCheck(BLangLiteral literalExpr, Object literalValue,
AnalyzerData data) {
boolean prevNonErrorLoggingCheck = data.commonAnalyzerData.nonErrorLoggingCheck;
data.commonAnalyzerData.nonErrorLoggingCheck = true;
GlobalStateData previousGlobalState = getGlobalStateSnapshotAndResetGlobalState();
GlobalStateSnapshot previousGlobalState = getGlobalStateSnapshotAndResetGlobalState();
this.dlog.mute();

BType exprCompatibleType = getIntegerLiteralType(nodeCloner.cloneNode(literalExpr), literalValue, expType,
Expand Down Expand Up @@ -1226,7 +1226,7 @@ public void visit(BLangTableConstructorExpr tableConstructorExpr, AnalyzerData d

boolean prevNonErrorLoggingCheck = data.commonAnalyzerData.nonErrorLoggingCheck;
data.commonAnalyzerData.nonErrorLoggingCheck = true;
GlobalStateData previousGlobalState = getGlobalStateSnapshotAndResetGlobalState();
GlobalStateSnapshot previousGlobalState = getGlobalStateSnapshotAndResetGlobalState();
this.dlog.mute();

List<BType> matchingTypes = new ArrayList<>();
Expand Down Expand Up @@ -1805,7 +1805,7 @@ private BType checkListConstructorCompatibility(BType referredType, BType origin
int tag = referredType.tag;
if (tag == TypeTags.UNION) {
boolean prevNonErrorLoggingCheck = data.commonAnalyzerData.nonErrorLoggingCheck;
GlobalStateData previousGlobalState = getGlobalStateSnapshotAndResetGlobalState();
GlobalStateSnapshot previousGlobalState = getGlobalStateSnapshotAndResetGlobalState();
data.commonAnalyzerData.nonErrorLoggingCheck = true;
this.dlog.mute();

Expand Down Expand Up @@ -2547,7 +2547,7 @@ public BType checkMappingConstructorCompatibility(BType bType, BLangRecordLitera
if (tag == TypeTags.UNION) {
boolean prevNonErrorLoggingCheck = data.commonAnalyzerData.nonErrorLoggingCheck;
data.commonAnalyzerData.nonErrorLoggingCheck = true;
GlobalStateData previousGlobalState = getGlobalStateSnapshotAndResetGlobalState();
GlobalStateSnapshot previousGlobalState = getGlobalStateSnapshotAndResetGlobalState();
this.dlog.mute();

List<BType> compatibleTypes = new ArrayList<>();
Expand Down Expand Up @@ -3931,7 +3931,7 @@ protected BType checkExprSilent(BLangExpression expr, BType expType, AnalyzerDat
boolean prevNonErrorLoggingCheck = data.commonAnalyzerData.nonErrorLoggingCheck;
data.commonAnalyzerData.nonErrorLoggingCheck = true;
this.dlog.mute();
GlobalStateData previousGlobalState = getGlobalStateSnapshotAndResetGlobalState();
GlobalStateSnapshot previousGlobalState = getGlobalStateSnapshotAndResetGlobalState();

BType type = checkExpr(expr, expType, data);

Expand Down Expand Up @@ -5471,7 +5471,7 @@ public boolean isOptionalFloatOrDecimal(BType expectedType) {
private BType checkAndGetType(BLangExpression expr, SymbolEnv env, BLangBinaryExpr binaryExpr, AnalyzerData data) {
boolean prevNonErrorLoggingCheck = data.commonAnalyzerData.nonErrorLoggingCheck;
data.commonAnalyzerData.nonErrorLoggingCheck = true;
GlobalStateData previousGlobalState = getGlobalStateSnapshotAndResetGlobalState();
GlobalStateSnapshot previousGlobalState = getGlobalStateSnapshotAndResetGlobalState();
this.dlog.mute();

expr.cloneAttempt++;
Expand Down Expand Up @@ -5732,7 +5732,7 @@ public boolean silentCompatibleFiniteMembersInUnionTypeCheck(BLangUnaryExpr unar
AnalyzerData data) {
boolean prevNonErrorLoggingCheck = data.commonAnalyzerData.nonErrorLoggingCheck;
data.commonAnalyzerData.nonErrorLoggingCheck = true;
GlobalStateData previousGlobalState = getGlobalStateSnapshotAndResetGlobalState();
GlobalStateSnapshot previousGlobalState = getGlobalStateSnapshotAndResetGlobalState();
this.dlog.mute();

BType compatibleTypeOfUnaryExpression;
Expand All @@ -5748,7 +5748,7 @@ public boolean silentCompatibleFiniteMembersInUnionTypeCheck(BLangUnaryExpr unar
return false;
}

private void unmuteDlog(AnalyzerData data, boolean prevNonErrorLoggingCheck, GlobalStateData previousGlobalState) {
private void unmuteDlog(AnalyzerData data, boolean prevNonErrorLoggingCheck, GlobalStateSnapshot previousGlobalState) {
data.commonAnalyzerData.nonErrorLoggingCheck = prevNonErrorLoggingCheck;
restoreGlobalState(previousGlobalState);
if (!prevNonErrorLoggingCheck) {
Expand All @@ -5759,7 +5759,7 @@ private void unmuteDlog(AnalyzerData data, boolean prevNonErrorLoggingCheck, Glo
public BType silentTypeCheckExpr(BLangExpression expr, BType referredType, AnalyzerData data) {
boolean prevNonErrorLoggingCheck = data.commonAnalyzerData.nonErrorLoggingCheck;
data.commonAnalyzerData.nonErrorLoggingCheck = true;
GlobalStateData previousGlobalState = getGlobalStateSnapshotAndResetGlobalState();
GlobalStateSnapshot previousGlobalState = getGlobalStateSnapshotAndResetGlobalState();
this.dlog.mute();

BType exprCompatibleType = checkExpr(nodeCloner.cloneNode(expr), referredType, data);
Expand Down Expand Up @@ -5822,7 +5822,7 @@ public void visit(BLangTypeConversionExpr conversionExpr, AnalyzerData data) {

boolean prevNonErrorLoggingCheck = data.commonAnalyzerData.nonErrorLoggingCheck;
data.commonAnalyzerData.nonErrorLoggingCheck = true;
GlobalStateData previousGlobalState = getGlobalStateSnapshotAndResetGlobalState();
GlobalStateSnapshot previousGlobalState = getGlobalStateSnapshotAndResetGlobalState();
this.dlog.mute();

BType exprCompatibleType = checkExpr(nodeCloner.cloneNode(expr), targetType, data);
Expand Down Expand Up @@ -6608,7 +6608,7 @@ private BType getCandidateType(BLangCheckedExpr checkedExpr, BType checkExprCand
boolean prevNonErrorLoggingCheck = data.commonAnalyzerData.nonErrorLoggingCheck;
data.commonAnalyzerData.nonErrorLoggingCheck = true;
this.dlog.mute();
GlobalStateData previousGlobalState = getGlobalStateSnapshotAndResetGlobalState();
GlobalStateSnapshot previousGlobalState = getGlobalStateSnapshotAndResetGlobalState();

checkedExpr.expr.cloneAttempt++;
BLangExpression clone = nodeCloner.cloneNode(checkedExpr.expr);
Expand Down Expand Up @@ -8240,7 +8240,7 @@ private List<BLangExpression> concatSimilarKindXMLNodes(List<BLangExpression> ex
for (BLangExpression expr : exprs) {
boolean prevNonErrorLoggingCheck = data.commonAnalyzerData.nonErrorLoggingCheck;
data.commonAnalyzerData.nonErrorLoggingCheck = true;
GlobalStateData previousGlobalState = getGlobalStateSnapshotAndResetGlobalState();
GlobalStateSnapshot previousGlobalState = getGlobalStateSnapshotAndResetGlobalState();
this.dlog.mute();

BType exprType = checkExpr(nodeCloner.cloneNode(expr), xmlElementEnv, symTable.xmlType, data);
Expand Down Expand Up @@ -9914,20 +9914,21 @@ String recordsToString(Set<BRecordType> recordTypeSet) {
}
}

public GlobalStateData getGlobalStateSnapshotAndResetGlobalState() {
public GlobalStateSnapshot getGlobalStateSnapshotAndResetGlobalState() {
// Preserve global state
GlobalStateData globalStateData = new GlobalStateData(typeResolver.unknownTypeRefs, this.dlog.errorCount());
GlobalStateSnapshot globalStateSnapshot = new GlobalStateSnapshot(typeResolver.getUnknownTypeRefs(),
this.dlog.errorCount());

// Reset global state
typeResolver.unknownTypeRefs = new HashSet<>();
typeResolver.setUnknownTypeRefs(new HashSet<>());
this.dlog.resetErrorCount();

return globalStateData;
return globalStateSnapshot;
}

public void restoreGlobalState(GlobalStateData globalStateData) {
typeResolver.unknownTypeRefs = globalStateData.unknownTypeRefs;
this.dlog.setErrorCount(globalStateData.errorCount);
public void restoreGlobalState(GlobalStateSnapshot globalStateSnapshot) {
typeResolver.setUnknownTypeRefs(globalStateSnapshot.unknownTypeRefs);
this.dlog.setErrorCount(globalStateSnapshot.errorCount);
}

/**
Expand All @@ -9947,8 +9948,9 @@ public static class AnalyzerData {
}

/**
* This record is used to hold a snapshot of the global fields of multiple class objects.
* @since 2201.12.0
*/
public record GlobalStateData(HashSet<TypeResolver.LocationData> unknownTypeRefs, int errorCount) {
public record GlobalStateSnapshot(HashSet<TypeResolver.LocationData> unknownTypeRefs, int errorCount) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public class TypeResolver {
private final HashSet<BLangClassDefinition> resolvedClassDef = new HashSet<>();
private final Map<String, BLangNode> modTable = new LinkedHashMap<>();
private final Map<String, BLangConstantValue> constantMap = new HashMap<>();
public HashSet<LocationData> unknownTypeRefs;
private HashSet<LocationData> unknownTypeRefs;
private SymbolEnv pkgEnv;
private int currentDepth;
private Deque<BType> resolvingTypes;
Expand Down Expand Up @@ -211,6 +211,14 @@ public static TypeResolver getInstance(CompilerContext context) {
return typeResolver;
}

public HashSet<LocationData> getUnknownTypeRefs() {
return unknownTypeRefs;
}

public void setUnknownTypeRefs(HashSet<LocationData> unknownTypeRefs) {
this.unknownTypeRefs = unknownTypeRefs;
}

public void defineBTypes(List<BLangNode> moduleDefs, SymbolEnv pkgEnv) {
this.pkgEnv = pkgEnv;
typePrecedence = 0;
Expand Down

0 comments on commit b897f30

Please sign in to comment.