Skip to content

Commit

Permalink
Merge pull request #43588 from rdulmina/typeDesc-stmt
Browse files Browse the repository at this point in the history
Generate `new typedesc` instruction for record and tuple when type descriptor resolving
  • Loading branch information
rdulmina authored Nov 18, 2024
2 parents b517ec9 + 3ff9914 commit e7ec6cc
Show file tree
Hide file tree
Showing 51 changed files with 1,013 additions and 690 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,11 @@ public static Object getAnnotValue(TypedescValue typedescValue, BString annotTag
if (!(describingType instanceof BAnnotatableType annotatableType)) {
return null;
}
MapValue annotations = ((TypedescValueImpl) typedescValue).annotations;
if (annotations != null) {
// ATM only field annotations will reach here
return annotations.get(annotTag);
}
return annotatableType.getAnnotation(annotTag);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ private void computeStringRepresentation() {
if (cachedToString != null) {
return;
}
if (typeName != null && !typeName.isEmpty()) {
cachedToString = typeName;
return;
}
StringBuilder stringRep =
new StringBuilder("[").append(tupleTypes.stream().map(Type::toString).collect(Collectors.joining(",")));
if (restType != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private MapUtils() {
}

public static void handleMapStore(MapValue<BString, Object> mapValue, BString fieldName, Object value) {
updateMapValue(TypeUtils.getImpliedType(mapValue.getType()), mapValue, fieldName, value);
updateMapValue(mapValue.getType(), mapValue, fieldName, value);
}

public static void handleInherentTypeViolatingMapUpdate(Object value, BMapType mapType) {
Expand Down Expand Up @@ -149,7 +149,7 @@ public static void checkIsMapOnlyOperation(Type mapType, String op) {

private static void updateMapValue(Type mapType, MapValue<BString, Object> mapValue, BString fieldName,
Object value) {

mapType = TypeUtils.getImpliedType(mapType);
switch (mapType.getTag()) {
case TypeTags.MAP_TAG:
handleInherentTypeViolatingMapUpdate(value, (BMapType) mapType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.ballerina.runtime.api.types.Type;
import io.ballerina.runtime.api.types.TypeTags;
import io.ballerina.runtime.api.utils.StringUtils;
import io.ballerina.runtime.api.utils.TypeUtils;
import io.ballerina.runtime.api.values.BArray;
import io.ballerina.runtime.api.values.BError;
import io.ballerina.runtime.api.values.BFunctionPointer;
Expand Down Expand Up @@ -314,8 +315,9 @@ public void setTypeForcefully(Type type) {

protected void populateInitialValues(BMapInitialValueEntry[] initialValues) {
Map<String, BFunctionPointer> defaultValues = new HashMap<>();
if (type.getTag() == TypeTags.RECORD_TYPE_TAG) {
defaultValues.putAll(((BRecordType) type).getDefaultValues());
Type impliedType = TypeUtils.getImpliedType(type);
if (impliedType.getTag() == TypeTags.RECORD_TYPE_TAG) {
defaultValues.putAll(((BRecordType) impliedType).getDefaultValues());
}

for (BMapInitialValueEntry initialValue : initialValues) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,8 @@ private static BIntersectionType setImmutableIntersectionType(Type type, Set<Typ
}
return objectIntersectionType;
case TypeTags.TYPE_REFERENCED_TYPE_TAG:
BTypeReferenceType bType = (BTypeReferenceType) type;
BTypeReferenceType refType = new BTypeReferenceType(bType.getName(), bType.getPkg(),
bType.getTypeFlags(), true);
refType.setReferredType(getImmutableType(bType.getReferredType(), unresolvedTypes));
return createAndSetImmutableIntersectionType(bType, refType);
return createAndSetImmutableIntersectionType(type,
getImmutableType(((BTypeReferenceType) type).getReferredType(), unresolvedTypes));
case TypeTags.ANY_TAG:
case TypeTags.ANYDATA_TAG:
case TypeTags.JSON_TAG:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public class TypedescValueImpl implements TypedescValue {

final Type type;
final Type describingType; // Type of the value describe by this typedesc.
public MapValue<?, ?>[] closures;
public MapValue<?, ?> annotations;
private BTypedesc typedesc;

Expand All @@ -63,14 +62,8 @@ public TypedescValueImpl(Type describingType) {
this.describingType = describingType;
}

public TypedescValueImpl(Type describingType, MapValue<?, ?>[] closures) {
this.type = new BTypedescType(describingType);
this.describingType = describingType;
this.closures = closures;
}

public TypedescValueImpl(Type describingType, MapValue<?, ?>[] closures, MapValue<BString, Object> annotations) {
this(describingType, closures);
public TypedescValueImpl(Type describingType, MapValue<BString, Object> annotations) {
this(describingType);
this.annotations = annotations;
((BAnnotatableType) describingType).setAnnotations(annotations);
}
Expand Down
5 changes: 5 additions & 0 deletions compiler/ballerina-lang/spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -500,4 +500,9 @@
<Method name="performCodeGen"/>
<Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE" />
</Match>
<Match>
<Class name="org.wso2.ballerinalang.compiler.bir.codegen.optimizer.LargeMethodOptimizer" />
<Method name="restoreOriginalArgsFromTuple" />
<Bug pattern="BC_UNCONFIRMED_CAST" />
</Match>
</FindBugsFilter>
Loading

0 comments on commit e7ec6cc

Please sign in to comment.