Skip to content

Commit

Permalink
Fix invalid definition sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
heshanpadmasiri committed Feb 25, 2025
1 parent dfaddaa commit 9d9a1a5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,7 @@ public static boolean isNever(SemType t) {
}

public static boolean isSubType(Context cx, SemType t1, SemType t2) {
boolean res = isEmpty(cx, diff(t1, t2));
return res;
return isEmpty(cx, diff(t1, t2));
}

public static boolean isSubtypeSimple(SemType t1, SemType t2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@ public static boolean checkIsType(Object sourceVal, Type targetType) {
}
Context cx = context();
Type sourceType = getType(sourceVal);
boolean result = checkIsTypeInner(sourceVal, targetType, cx, sourceType);
return result;
return checkIsTypeInner(sourceVal, targetType, cx, sourceType);
}

private static boolean couldBelongToType(Type sourceType, Type targetType) {
Expand Down Expand Up @@ -296,9 +295,7 @@ public static BasicTypeBitSet getBasicType(Object sourceVal) {
case Long ignored -> Builder.getIntType();
case Byte ignored -> Builder.getIntType();
case Boolean ignored -> Builder.getBooleanType();
default -> {
throw new IllegalArgumentException("unexpected value type");
}
default -> throw new IllegalArgumentException("unexpected value type");
};
}

Expand Down Expand Up @@ -381,8 +378,7 @@ private static boolean shapeBelongToType(Context cx, Object sourceValue, Type ta
if (Core.isSubtypeSimple(shape, NumericTypeHolder.NUMERIC_TYPE) && allowNumericConversion) {
targetSemType = appendNumericConversionTypes(targetSemType);
}
boolean result = Core.isSubType(cx, shape, targetSemType);
return result;
return Core.isSubType(cx, shape, targetSemType);
}

private static SemType appendNumericConversionTypes(SemType semType) {
Expand Down Expand Up @@ -629,8 +625,7 @@ public static boolean checkIsType(Type sourceType, Type targetType) {
return false;
}
Context cx = context();
boolean result = isSubType(cx, sourceType, targetType);
return result;
return isSubType(cx, sourceType, targetType);
}

@Deprecated
Expand All @@ -639,8 +634,7 @@ public static boolean checkIsType(Type sourceType, Type targetType, List<TypePai
return false;
}
Context cx = context();
boolean result = isSubType(cx, sourceType, targetType);
return result;
return isSubType(cx, sourceType, targetType);
}

/**
Expand Down Expand Up @@ -1414,17 +1408,4 @@ private static SemType createConvertibleCastMask() {
}

}

private static final class TopTypesWithFillValueMaskHolder {

static final SemType TOP_TYPES_WITH_ALWAYS_FILLING = createTopTypesWithFillerValues();

private static SemType createTopTypesWithFillerValues() {
return Stream.of(Builder.getIntType(), Builder.getFloatType(), Builder.getDecimalType(),
Builder.getStringType(),
Builder.getBooleanType(), Builder.getNilType(), Builder.getTableType(), Builder.getMappingType(),
Builder.getListType()).reduce(Builder.getNeverType(), Core::union);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public class BMapType extends BType implements MapType, TypeWithShape, Cloneable
private final boolean readonly;
private IntersectionType immutableType;
private IntersectionType intersectionType = null;
private final DefinitionContainer<MappingDefinition> defn;
private final DefinitionContainer<MappingDefinition> acceptedTypeDefn;
private final DefinitionContainer<MappingDefinition> defn = new DefinitionContainer<>();
private final DefinitionContainer<MappingDefinition> acceptedTypeDefn = new DefinitionContainer<>();

public BMapType(Type constraint) {
this(constraint, false);
Expand Down Expand Up @@ -95,8 +95,6 @@ public BMapType(String typeName, Type constraint, Module pkg, boolean readonly)
readonly ? FLYWEIGHT_STORE.getRO(constraint) : FLYWEIGHT_STORE.getRW(constraint);
this.typeId = flyweight.typeId();
this.typeCheckCache = flyweight.typeCheckCache();
this.defn = flyweight.defn();
this.acceptedTypeDefn = flyweight.acceptedTypeDefn();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import io.ballerina.runtime.api.types.semtype.Definition;
import io.ballerina.runtime.api.types.semtype.TypeCheckCache;
import io.ballerina.runtime.api.types.semtype.TypeCheckCacheFactory;
import io.ballerina.runtime.internal.types.semtype.DefinitionContainer;
import io.ballerina.runtime.internal.types.semtype.FlyweightLookupTable;
import io.ballerina.runtime.internal.types.semtype.TypeCheckCacheFlyweight;

Expand All @@ -40,17 +39,13 @@ private TypeCheckCacheFlyweight<E> create(int constraintId) {
case UNNAMED -> TypeIdSupplier.getAnonId();
};
TypeCheckCache typeCheckCache = TypeCheckCacheFactory.create();
DefinitionContainer<E> defn = new DefinitionContainer<>();
DefinitionContainer<E> acceptedTypeDefn = new DefinitionContainer<>();
return new TypeCheckCacheFlyweight<>(typeId, typeCheckCache, defn, acceptedTypeDefn);
return new TypeCheckCacheFlyweight<>(typeId, typeCheckCache);
}

private TypeCheckCacheFlyweight<E> create() {
int typeId = TypeIdSupplier.getAnonId();
TypeCheckCache typeCheckCache = TypeCheckCacheFactory.create();
DefinitionContainer<E> defn = new DefinitionContainer<>();
DefinitionContainer<E> acceptedTypeDefn = new DefinitionContainer<>();
return new TypeCheckCacheFlyweight<>(typeId, typeCheckCache, defn, acceptedTypeDefn);
return new TypeCheckCacheFlyweight<>(typeId, typeCheckCache);
}

public TypeCheckCacheFlyweight<E> getRO(Type constraint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import io.ballerina.runtime.api.types.semtype.Definition;
import io.ballerina.runtime.api.types.semtype.TypeCheckCache;

public record TypeCheckCacheFlyweight<E extends Definition>(int typeId, TypeCheckCache typeCheckCache,
DefinitionContainer<E> defn,
DefinitionContainer<E> acceptedTypeDefn) {
public record TypeCheckCacheFlyweight<E extends Definition>(int typeId, TypeCheckCache typeCheckCache) {

}

0 comments on commit 9d9a1a5

Please sign in to comment.