Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for field annotations in local records and tuples #38488

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
9593c36
Generate closures for annotations of local record types
chiranSachintha Oct 31, 2022
9dd1884
Introduce details of annotations to typedesc instruction
chiranSachintha Oct 31, 2022
d1e1e7c
Instantiate annotations using typedesc
chiranSachintha Oct 31, 2022
1f2b606
Add support to access annotations using annotation map in typedesc
chiranSachintha Oct 31, 2022
8069fe1
Add tests for local record annotations
chiranSachintha Oct 31, 2022
5696819
Update version
chiranSachintha Nov 1, 2022
347ed0f
Merge branch 'master' of https://github.com/ballerina-platform/baller…
chiranSachintha Nov 14, 2022
ebc4c18
Move local annotation desugar logic to parameter desugar phase
chiranSachintha Nov 14, 2022
d66a17c
fix `getting unused variable warning`
chiranSachintha Nov 3, 2022
e084377
fix review suggestions
chiranSachintha Nov 10, 2022
b88ddd0
Rename `ParameterDesugar` class as `ClosureGenerator`
chiranSachintha Nov 14, 2022
5429015
Add annotation details to BIR
chiranSachintha Nov 14, 2022
097c3eb
Update bir spec with annotation details
chiranSachintha Nov 14, 2022
8b62528
Merge branch 'master' of https://github.com/ballerina-platform/baller…
chiranSachintha Jan 11, 2023
b34390d
Fix review suggestions
chiranSachintha Jan 11, 2023
fd46e70
Merge branch 'annot-tuple-members' of https://github.com/ballerina-pl…
chiranSachintha Jan 12, 2023
482b160
Add support for TupleValueImpl constructor, including TypedescValueImpl
chiranSachintha Jan 12, 2023
7b3fd03
Add annotations field to BTypeSymbol
chiranSachintha Jan 12, 2023
49c5772
Update class name
chiranSachintha Jan 12, 2023
788a8ac
Implement method to mark closure variables
chiranSachintha Jan 12, 2023
ecbcd6e
Add support for defining field annotations in tuple types
chiranSachintha Jan 12, 2023
30617b3
Add test cases for local tuple annotations
chiranSachintha Jan 12, 2023
3bcf5c2
Support field annotation on function return type and parameters
chiranSachintha Jan 12, 2023
c3b7bc1
Add test cases for local tuple annotations
chiranSachintha Jan 12, 2023
b619783
Add method for providing typedesc value based on value immutability
chiranSachintha Jan 17, 2023
604f118
Add a new list to keep references for package-level closures
chiranSachintha Jan 17, 2023
144b904
Fix review suggestions
chiranSachintha Jan 18, 2023
f00c676
Refactor `getAnnotations` function
chiranSachintha Jan 18, 2023
84b1b8b
Desugar field annotations
chiranSachintha Jan 18, 2023
28bf26d
Add annotation support to bir
chiranSachintha Jan 18, 2023
c15e4a9
Update BIR spec
chiranSachintha Jan 18, 2023
ba469c5
Rename function `createNewTypeDescConstructor` to `createTypeDescCons…
chiranSachintha Jan 18, 2023
6c66c1d
Merge branch 'annot-tuple-members' of https://github.com/ballerina-pl…
chiranSachintha Jan 22, 2023
dd11149
Resolve conflicts
chiranSachintha Jan 22, 2023
a5accff
Fix review suggestions
chiranSachintha Jan 23, 2023
0a93d03
Set annotation to the type
chiranSachintha Jan 23, 2023
65b7432
Add unit test
chiranSachintha Jan 23, 2023
85a4717
Add annotation for anonymous records
chiranSachintha Jan 23, 2023
04d0403
Retrieved annotation from type
chiranSachintha Jan 23, 2023
ffa50c3
Add unit tests
chiranSachintha Jan 23, 2023
b4798a6
Fix review suggestions
chiranSachintha Jan 23, 2023
294bcc7
Update ksy file
chiranSachintha Jan 23, 2023
bf4915b
fix `getting unused variable warning` with tuple annotation
chiranSachintha Jan 23, 2023
e14d9f1
Add tests for unused variable warnings
chiranSachintha Jan 23, 2023
ca112e1
Merge branch 'annot-tuple-members' of https://github.com/ballerina-pl…
chiranSachintha Jan 23, 2023
e1da96f
Add bala test
chiranSachintha Jan 24, 2023
b9b862e
Add annotation for anonymous records to global map
chiranSachintha Jan 24, 2023
01f2595
Update bala tests
chiranSachintha Jan 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,19 @@ public static BTypedesc getTypedescValue(Type type, BValue value) {
return new TypedescValueImpl(type);
}

/**
* Provide the Typedesc Value depending on the immutability of a value.
* @param readOnly Indicates that the type is a subtype of readonly
* @param value Ballerina value
* @param inherentType Inherent type of the value
* @return typedesc with the suitable type
*/
public static BTypedesc getTypedescValue(Boolean readOnly, BValue value, TypedescValueImpl inherentType) {
if (readOnly) {
TypedescValueImpl typedesc = (TypedescValueImpl) createSingletonTypedesc(value);
typedesc.annotations = inherentType.annotations;
return typedesc;
}
return inherentType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ public TupleValueImpl(Type type, BListInitialValueEntry[] initialValues) {
this.typedesc = getTypedescValue(type, this);
}

public TupleValueImpl(Type type, BListInitialValueEntry[] initialValues, TypedescValueImpl inherentType) {
this(type, initialValues);
this.typedesc = getTypedescValue(type.isReadOnly(), this, inherentType);
}

@Override
public BTypedesc getTypedesc() {
return typedesc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@
* @since 1.3.0
*/
public interface TypedescValue extends RefValue, BTypedesc {

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.ballerina.runtime.api.values.BMapInitialValueEntry;
import io.ballerina.runtime.api.values.BTypedesc;
import io.ballerina.runtime.internal.scheduling.Strand;
import io.ballerina.runtime.internal.types.BAnnotatableType;
import io.ballerina.runtime.internal.types.BTypedescType;
import io.ballerina.runtime.internal.util.exceptions.BallerinaException;

Expand Down Expand Up @@ -52,6 +53,7 @@ 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if someone tries to retrieve the annotations via the type now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide an example of this? Is it possible to access annotations from a type?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Java code. io.ballerina.runtime.internal.types.BAnnotatableType#getAnnotations.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This returns a null value. And also this is an internal method and can not be utilized by external parties. Right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

io.ballerina.runtime.api.types.AnnotatableType#getAnnotations

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if it was only used within lang, should be consistent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we set the same annotations to the type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the issue by setting the annotation to the type and utilizing the type to retrieve the annotations(Except using annotations in the typedesc)


@Deprecated
public TypedescValueImpl(Type describingType) {
Expand All @@ -66,6 +68,11 @@ public TypedescValueImpl(Type describingType, MapValue[] closures) {
this.closures = closures;
}

public TypedescValueImpl(Type describingType, MapValue[] closures, MapValue annotations) {
this(describingType, closures);
this.annotations = annotations;
((BAnnotatableType) describingType).setAnnotations(annotations);
}

chiranSachintha marked this conversation as resolved.
Show resolved Hide resolved
/**
* Returns the {@code BType} of the value describe by this type descriptor.
Expand All @@ -84,13 +91,17 @@ public Object instantiate(Strand s) {
return instantiate(s, new BInitialValueEntry[0]);
}

public MapValue getAnnotations() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in chiranSachintha#8

return annotations;
}

@Override
public Object instantiate(Strand s, BInitialValueEntry[] initialValues) {
Type referredType = getReferredType(this.describingType);
if (referredType.getTag() == TypeTags.MAP_TAG) {
return new MapValueImpl(this.describingType, (BMapInitialValueEntry[]) initialValues);
} else if (referredType.getTag() == TypeTags.TUPLE_TAG) {
return new TupleValueImpl(this.describingType, (BListInitialValueEntry[]) initialValues);
return new TupleValueImpl(this.describingType, (BListInitialValueEntry[]) initialValues, this);
}
// This method will be overridden for user-defined types, therefor this line shouldn't be reached.
throw new BallerinaException("Given type can't be instantiated at runtime : " + this.describingType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,6 @@ public BType readType(int cpI) throws IOException {

// Read the type flags to identify if type reference types are nullable.
int typeFlags = inputStream.readInt();

switch (tag) {
case TypeTags.INT:
return typeParamAnalyzer.getNominalType(symTable.intType, name, flags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,8 @@ public void visit(BLangTypeConversionExpr astTypeConversionExpr) {
@Override
public void visit(BLangStructLiteral astStructLiteralExpr) {
List<BIROperand> varDcls = mapToVarDcls(astStructLiteralExpr.enclMapSymbols);
visitTypedesc(astStructLiteralExpr.pos, astStructLiteralExpr.getBType(), varDcls);
BType type = astStructLiteralExpr.getBType();
visitTypedesc(astStructLiteralExpr.pos, type, varDcls, getAnnotations(type.tsymbol, this.env));

BIRVariableDcl tempVarDcl = new BIRVariableDcl(astStructLiteralExpr.getBType(),
this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.TEMP);
Expand Down Expand Up @@ -1671,17 +1672,33 @@ public void visit(BLangSimpleVarRef.BLangFieldVarRef fieldVarRef) {
public void visit(BLangArrayLiteral astArrayLiteralExpr) {
BType bType = astArrayLiteralExpr.getBType();
if (bType.tag == TypeTags.TUPLE) {
visitTypedesc(astArrayLiteralExpr.pos, bType, Collections.emptyList());
visitTypedesc(astArrayLiteralExpr.pos, bType, Collections.emptyList(),
getAnnotations(bType.tsymbol, this.env));
}
generateListConstructorExpr(astArrayLiteralExpr);
}

@Override
public void visit(BLangTupleLiteral tupleLiteral) {
visitTypedesc(tupleLiteral.pos, tupleLiteral.getBType(), Collections.emptyList());
BType type = tupleLiteral.getBType();
visitTypedesc(tupleLiteral.pos, type, Collections.emptyList(), getAnnotations(type.tsymbol, this.env));
generateListConstructorExpr(tupleLiteral);
}

private BIROperand getAnnotations(BTypeSymbol typeSymbol, BIRGenEnv env) {
if (typeSymbol == null || typeSymbol.annotations == null) {
return null;
}
return new BIROperand(getAnnotations(typeSymbol.annotations, env));
}

private BIRVariableDcl getAnnotations(BVarSymbol annotations, BIRGenEnv env) {
if (env.symbolVarMap.containsKey(annotations)) {
return env.symbolVarMap.get(annotations);
}
return globalVarMap.get(annotations);
}
Comment on lines +1688 to +1700
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move private function to the bottom.


@Override
public void visit(BLangGroupExpr groupExpr) {
groupExpr.expression.accept(this);
Expand All @@ -1691,7 +1708,8 @@ public void visit(BLangGroupExpr groupExpr) {
public void visit(BLangJSONArrayLiteral jsonArrayLiteralExpr) {
BType bType = jsonArrayLiteralExpr.getBType();
if (bType.tag == TypeTags.TUPLE) {
visitTypedesc(jsonArrayLiteralExpr.pos, bType, Collections.emptyList());
visitTypedesc(jsonArrayLiteralExpr.pos, bType, Collections.emptyList(),
getAnnotations(bType.tsymbol, this.env));
}
generateListConstructorExpr(jsonArrayLiteralExpr);
}
Expand Down Expand Up @@ -2195,7 +2213,7 @@ public void visit(BLangTypedescExpr accessExpr) {
this.env.enclFunc.localVars.add(tempVarDcl);
BIROperand toVarRef = new BIROperand(tempVarDcl);
setScopeAndEmit(new BIRNonTerminator.NewTypeDesc(accessExpr.pos, toVarRef, accessExpr.resolvedType,
Collections.emptyList()));
Collections.emptyList()));
this.env.targetOperand = toVarRef;
}

Expand Down Expand Up @@ -2249,11 +2267,19 @@ public void visit(BLangSimpleVarRef.BLangTypeLoad typeLoad) {
}

private void visitTypedesc(Location pos, BType type, List<BIROperand> varDcls) {
BIRVariableDcl tempVarDcl =
new BIRVariableDcl(symTable.typeDesc, this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind
.TEMP);
visitTypedesc(pos, type, varDcls, null);
}

private void visitTypedesc(Location pos, BType type, List<BIROperand> varDcls, BIROperand annotations) {
Comment on lines +2270 to +2273
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a separate method?

BIRVariableDcl tempVarDcl = new BIRVariableDcl(symTable.typeDesc, this.env.nextLocalVarId(names),
VarScope.FUNCTION, VarKind.TEMP);
this.env.enclFunc.localVars.add(tempVarDcl);
BIROperand toVarRef = new BIROperand(tempVarDcl);
if (annotations != null) {
setScopeAndEmit(new BIRNonTerminator.NewTypeDesc(pos, toVarRef, type, varDcls, annotations));
this.env.targetOperand = toVarRef;
return;
}
setScopeAndEmit(new BIRNonTerminator.NewTypeDesc(pos, toVarRef, type, varDcls));
this.env.targetOperand = toVarRef;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ public class JvmConstants {
// service objects, annotation processing related classes
public static final String ANNOTATION_UTILS = "io/ballerina/runtime/internal/AnnotationUtils";
public static final String ANNOTATION_MAP_NAME = "$annotation_data";
public static final String ANNOTATIONS_FIELD = "$annotations";
public static final String DEFAULTABLE_ARGS_ANOT_NAME = "DefaultableArgs";
public static final String DEFAULTABLE_ARGS_ANOT_FIELD = "args";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.SET_ON_INIT;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.TWO_OBJECTS_ARGS;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.TYPE_DESC_CONSTRUCTOR;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.TYPE_DESC_CONSTRUCTOR_WITH_ANNOTATIONS;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.XML_ADD_CHILDREN;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.XML_CHILDREN;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.XML_CHILDREN_FROM_STRING;
Expand Down Expand Up @@ -2094,7 +2095,7 @@ void generateNewTypedescIns(BIRNonTerminator.NewTypeDesc newTypeDesc) {
String fieldName = jvmTypeGen.getTypedescFieldName(toNameString(type));
mv.visitFieldInsn(GETSTATIC, typeOwner, fieldName, GET_TYPEDESC);
} else {
generateNewTypedescCreate(newTypeDesc.type, closureVars);
generateNewTypedescCreate(newTypeDesc.type, closureVars, newTypeDesc.annotations);
}
this.storeToVar(newTypeDesc.lhsOp.variableDcl);
}
Expand All @@ -2108,7 +2109,7 @@ private boolean isNonReferredRecord(BType type) {
type.getQualifiedTypeName().equals(referredType.getQualifiedTypeName());
}

private void generateNewTypedescCreate(BType btype, List<BIROperand> closureVars) {
private void generateNewTypedescCreate(BType btype, List<BIROperand> closureVars, BIROperand annotations) {
BType type = JvmCodeGenUtil.getReferredType(btype);
String className = TYPEDESC_VALUE_IMPL;
if (type.tag == TypeTags.RECORD) {
Expand All @@ -2127,8 +2128,13 @@ private void generateNewTypedescCreate(BType btype, List<BIROperand> closureVars
this.loadVar(closureVar.variableDcl);
mv.visitInsn(AASTORE);
}

this.mv.visitMethodInsn(INVOKESPECIAL, className, JVM_INIT_METHOD, TYPE_DESC_CONSTRUCTOR, false);
if (annotations != null) {
this.loadVar(annotations.variableDcl);
this.mv.visitMethodInsn(INVOKESPECIAL, className, JVM_INIT_METHOD, TYPE_DESC_CONSTRUCTOR_WITH_ANNOTATIONS,
false);
} else {
this.mv.visitMethodInsn(INVOKESPECIAL, className, JVM_INIT_METHOD, TYPE_DESC_CONSTRUCTOR, false);
}
}

void loadVar(BIRNode.BIRVariableDcl varDcl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ public class JvmSignatures {
public static final String TUPLE_SET_MEMBERS_METHOD = "(L" + LIST + ";L" + TYPE + ";)V";
public static final String TWO_OBJECTS_ARGS = "(L" + OBJECT + ";L" + OBJECT + ";)V";
public static final String TYPE_DESC_CONSTRUCTOR = "(L" + TYPE + ";[L" + MAP_VALUE + ";)V";
public static final String TYPE_DESC_CONSTRUCTOR_WITH_ANNOTATIONS =
"(L" + TYPE + ";[L" + MAP_VALUE + ";L" + MAP_VALUE + ";)V";
public static final String TYPE_PARAMETER = "(L" + TYPE + ";)V";
public static final String UPDATE_CHANNEL_DETAILS = "([L" + CHANNEL_DETAILS + ";)V";
public static final String VALUE_CLASS_INIT = "(L" + STRAND_CLASS + ";L" + MAP_VALUE + ";)L" + OBJECT + ";";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
import static org.objectweb.asm.Opcodes.V1_8;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmCodeGenUtil.toNameString;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.ABSTRACT_OBJECT_VALUE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.ANNOTATIONS_FIELD;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.BAL_OPTIONAL;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.B_OBJECT;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.JVM_INIT_METHOD;
Expand All @@ -108,13 +109,15 @@
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmPackageGen.computeLockNameFromString;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.CAST_B_MAPPING_INITIAL_VALUE_ENTRY;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_MAP_ARRAY;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_MAP_VALUE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.INIT_TYPEDESC;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.INSTANTIATE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.OBJECT_TYPE_IMPL_INIT;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.POPULATE_INITIAL_VALUES;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.RECORD_INIT_WRAPPER;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.RECORD_VALUE_CLASS;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.TYPE_DESC_CONSTRUCTOR;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.TYPE_DESC_CONSTRUCTOR_WITH_ANNOTATIONS;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.TYPE_PARAMETER;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.VALUE_CLASS_INIT;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmTypeGen.getTypeDesc;
Expand Down Expand Up @@ -249,7 +252,11 @@ private byte[] createRecordTypeDescClass(BRecordType recordType, String classNam
}
cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, className, null, TYPEDESC_VALUE_IMPL, new String[]{TYPEDESC_VALUE});

FieldVisitor fv = cw.visitField(0, ANNOTATIONS_FIELD, GET_MAP_VALUE, null, null);
fv.visitEnd();

this.createTypeDescConstructor(cw);
this.createTypeDescConstructorWithAnnotations(cw, className);
this.createInstantiateMethod(cw, recordType, typeDef);

cw.visitEnd();
Expand Down Expand Up @@ -429,6 +436,32 @@ private void createTypeDescConstructor(ClassWriter cw) {
mv.visitEnd();
}

private void createTypeDescConstructorWithAnnotations(ClassWriter cw, String name) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets remove these new lines in the method. Better to remove with separate PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated(#39349)

String descriptor = TYPE_DESC_CONSTRUCTOR_WITH_ANNOTATIONS;
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, JVM_INIT_METHOD, descriptor, null, null);
mv.visitCode();

mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 3);
mv.visitFieldInsn(PUTFIELD, name, ANNOTATIONS_FIELD, GET_MAP_VALUE);
// load super
mv.visitVarInsn(ALOAD, 0);
// load type
mv.visitVarInsn(ALOAD, 1);
// load closures
mv.visitVarInsn(ALOAD, 2);
// load annotations
mv.visitVarInsn(ALOAD, 3);
// invoke `super(type)`;
mv.visitMethodInsn(INVOKESPECIAL, TYPEDESC_VALUE_IMPL, JVM_INIT_METHOD, TYPE_DESC_CONSTRUCTOR_WITH_ANNOTATIONS,
false);

mv.visitInsn(RETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}

private void createRecordConstructor(ClassWriter cw, String argumentClass) {
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, JVM_INIT_METHOD, argumentClass, null, null);
mv.visitCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,7 @@ public BIROperand[] getRhsOperands() {
public static class NewTypeDesc extends BIRNonTerminator {
public final List<BIROperand> closureVars;
public BType type;
public BIROperand annotations;

public NewTypeDesc(Location pos, BIROperand lhsOp, BType type, List<BIROperand> closureVars) {
super(pos, InstructionKind.NEW_TYPEDESC);
Expand All @@ -832,6 +833,12 @@ public NewTypeDesc(Location pos, BIROperand lhsOp, BType type, List<BIROperand>
this.type = type;
}

public NewTypeDesc(Location pos, BIROperand lhsOp, BType type, List<BIROperand> closureVars,
BIROperand annotations) {
this(pos, lhsOp, type, closureVars);
this.annotations = annotations;
}

@Override
public void accept(BIRVisitor visitor) {
visitor.visit(this);
Expand Down
Loading