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 large list and mapping constructors #41017

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
cb54615
Revert "Remove unnecessary changes"
Nadeeshan96 Jun 7, 2023
4fe76dc
Add new large array BIR instruction
Nadeeshan96 Jun 8, 2023
27e966e
Handle global vars and arguments
Nadeeshan96 Jun 12, 2023
b88cc58
Move global var and arg array element population
Nadeeshan96 Jun 12, 2023
e3dd4a1
Create new BBs when handling call terminators
Nadeeshan96 Jun 13, 2023
dfd43e5
Remove unnecessary temp variable creation
Nadeeshan96 Jun 13, 2023
0c7dfa9
Split large array BIR functions
Nadeeshan96 Jun 19, 2023
c104d9b
Introduce SplitFuncEnv and ParentFuncEnv
Nadeeshan96 Jun 19, 2023
67afa30
Refactor long methods
Nadeeshan96 Jun 19, 2023
fdb8969
Fix changed basic blocks
Nadeeshan96 Jun 20, 2023
4b62ae5
Handle check expressions in split functions
Nadeeshan96 Jun 21, 2023
011d3f9
Fix bug with BB terminator split's thenBB
Nadeeshan96 Jul 10, 2023
19bd19e
Edit BIREmitter NewArray ins
Nadeeshan96 Jul 10, 2023
b5ac757
Fix split points of a BIRFunction by adding pass
Nadeeshan96 Jul 11, 2023
15fcd21
Omit checking NewArray instruction as split point
Nadeeshan96 Jul 11, 2023
21b2ef0
Handle instructions multiple array value operands
Nadeeshan96 Jul 11, 2023
fc63337
Fix BB terminators to BBs outside split functions
Nadeeshan96 Jul 12, 2023
9c3a1b8
Fix choosing split points
Nadeeshan96 Jul 12, 2023
54faf22
Fix bug with newly created BB terminators
Nadeeshan96 Jul 13, 2023
3543246
Do not choose branch terminator as a split point
Nadeeshan96 Jul 13, 2023
194f1ba
Do not consider every instruction LHS operands
Nadeeshan96 Jul 13, 2023
e60815a
Split functions only at last set array elements
Nadeeshan96 Jul 14, 2023
4262708
Merge branch 'mas-f-lmo-f-large-start-splits' into master-fix-large-a…
Nadeeshan96 Jul 14, 2023
5d6b91d
Print NewMap initial values in BIREmitter
Nadeeshan96 Jul 14, 2023
8710649
Fix adding instructions with error table operands
Nadeeshan96 Jul 17, 2023
4991a1f
Fix rectifyVarKindsAndTerminators method
Nadeeshan96 Jul 17, 2023
9533ae6
Introduce LargeStructureUtils class
Nadeeshan96 Jul 19, 2023
09b4f5d
Split function further with high instruction count
Nadeeshan96 Jul 19, 2023
427c32b
Introduce JLargeArrayInstruction instruction
Nadeeshan96 Jul 19, 2023
f4276d0
Improve large method optimizer bug fix
HindujaB Jul 19, 2023
e2eb5e6
Use single map per function when rectifying vars
Nadeeshan96 Jul 20, 2023
858a9ed
Clean the newly added code
Nadeeshan96 Jul 20, 2023
cc4d6e2
Set thresholds and remove clutter
Nadeeshan96 Jul 20, 2023
c19efc9
Fix failing BirVariableOptimizationTest tests
Nadeeshan96 Jul 20, 2023
0013204
Remove unnecessary variables
Nadeeshan96 Jul 20, 2023
8b6eff5
Add tests for large arrays
Nadeeshan96 Jul 21, 2023
07af243
Change split function argument count
Nadeeshan96 Jul 24, 2023
559f1da
Add test for large array and tuple
Nadeeshan96 Jul 24, 2023
c1cb2fc
Revert "Set thresholds and remove clutter"
Nadeeshan96 Jul 24, 2023
11d840e
Add methods for maps in LargeStructureUtils
Nadeeshan96 Jul 24, 2023
08d847b
Add JLargeMapInstruction class
Nadeeshan96 Jul 24, 2023
10066d3
Support splitting large maps
Nadeeshan96 Jul 26, 2023
e0e540d
Fix passing map key arguments to split function
Nadeeshan96 Jul 26, 2023
e7edce2
Collect only last set map key operands
Nadeeshan96 Jul 26, 2023
06bdfe7
Do not set map key values when key is not set
Nadeeshan96 Jul 27, 2023
df21b2a
Add missing parent function local variable
Nadeeshan96 Jul 27, 2023
4c67dd1
Fix checking object constructor name
Nadeeshan96 Jul 28, 2023
c8dfcb7
Rearrange basic blocks after generating splits
Nadeeshan96 Jul 28, 2023
b9cb50d
Rearrange basic blocks after generating splits
Nadeeshan96 Jul 28, 2023
df7367c
Add ConstLoad instructions to first basic block
Nadeeshan96 Jul 28, 2023
53ada32
Fix null pointer exception
Nadeeshan96 Jul 28, 2023
da05fa9
Refactor code
Nadeeshan96 Jul 28, 2023
ae82258
Merge branch 'mas-fla-36440-split-map' into master-fix-large-arr-36440
Nadeeshan96 Jul 31, 2023
8455c46
Remove BIRTerminator getKind method
Nadeeshan96 Jul 31, 2023
aa6d983
Merge branch 'master' into master-fix-large-arr-36440
Nadeeshan96 Jul 31, 2023
619bfcb
Set thresholds and remove unneeded code
Nadeeshan96 Jul 31, 2023
e73952f
Set local var start and end BBs for map key vars
Nadeeshan96 Jul 31, 2023
1cfaa1a
Check compilation errors in BRunUtil run method
Nadeeshan96 Jul 31, 2023
05e13d8
Merge branch 'master' into master-fix-large-arr-36440
Nadeeshan96 Aug 2, 2023
4f62513
Consider map key-value all var kinds
Nadeeshan96 Aug 3, 2023
775dcd5
Add test with array spread operator
Nadeeshan96 Aug 10, 2023
3cd8887
Add test with large maps and records
Nadeeshan96 Aug 10, 2023
48ab894
Separate compilation and execution in large tests
Nadeeshan96 Aug 10, 2023
7f1c2e8
Improve test coverage
Nadeeshan96 Aug 10, 2023
4f62c12
Merge branch 'master' into master-fix-large-arr-36440
Nadeeshan96 Aug 10, 2023
1486411
Add tests with spread entry for maps and arrays
Nadeeshan96 Aug 13, 2023
5822c33
Remove unnecessary fixing split func local var BB
Nadeeshan96 Aug 13, 2023
6d66bed
Improve test coverage and add comments
Nadeeshan96 Aug 13, 2023
595e61f
Merge branch 'master' into master-fix-large-arr-36440
Nadeeshan96 Aug 13, 2023
c00df1f
Remove java stream usages
Nadeeshan96 Aug 15, 2023
07202cb
Merge branch 'master' into master-fix-large-arr-36440
Nadeeshan96 Aug 15, 2023
2bf4098
Improve test coverage
Nadeeshan96 Aug 15, 2023
d537d77
Fix line endings
Nadeeshan96 Aug 15, 2023
39dea0f
Fix typos and grammar in comments
Nadeeshan96 Aug 15, 2023
50008a0
Refactor generatePlatformIns method
Nadeeshan96 Aug 15, 2023
8371631
Address PR comments and fix checkstyle issues
Nadeeshan96 Aug 15, 2023
bfad17e
Merge branch 'master' into master-fix-large-arr-36440
Nadeeshan96 Aug 15, 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
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com) All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package io.ballerina.runtime.internal.util;

import io.ballerina.runtime.api.values.BArray;
import io.ballerina.runtime.api.values.BMap;
import io.ballerina.runtime.api.values.BMapInitialValueEntry;
import io.ballerina.runtime.internal.values.HandleValue;
import io.ballerina.runtime.internal.values.ListInitialValueEntry;
import io.ballerina.runtime.internal.values.MappingInitialValueEntry;

/**
* Util methods required for handling large arrays, tuples, maps and records.
*
* @since 2201.8.0
*/
public class LargeStructureUtils {

private LargeStructureUtils() {}

public static HandleValue getListInitialValueEntryArray(long size) {
return new HandleValue(new ListInitialValueEntry[(int) size]);
}

public static void setExpressionEntry(HandleValue arrayList, Object element, long index) {
ListInitialValueEntry[] arr = (ListInitialValueEntry[]) arrayList.getValue();
arr[(int) index] = new ListInitialValueEntry.ExpressionEntry(element);
}

public static void setSpreadEntry(HandleValue arrayList, Object element, long index) {
ListInitialValueEntry[] arr = (ListInitialValueEntry[]) arrayList.getValue();
arr[(int) index] = new ListInitialValueEntry.SpreadEntry((BArray) element);
Nadeeshan96 marked this conversation as resolved.
Show resolved Hide resolved
}

public static HandleValue getBMapInitialValueEntryArray(long size) {
return new HandleValue(new BMapInitialValueEntry[(int) size]);
}

public static void setKeyValueEntry(HandleValue arrayList, Object key, Object value, long index) {
BMapInitialValueEntry[] arr = (BMapInitialValueEntry[]) arrayList.getValue();
arr[(int) index] = new MappingInitialValueEntry.KeyValueEntry(key, value);
}

public static void setSpreadFieldEntry(HandleValue arrayList, Object spreadFieldEntry, long index) {
BMapInitialValueEntry[] arr = (BMapInitialValueEntry[]) arrayList.getValue();
arr[(int) index] = new MappingInitialValueEntry.SpreadFieldEntry((BMap) spreadFieldEntry);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public class HandleValue implements BHandle, RefValue {
private Object value;
private BTypedesc typedesc;

@Deprecated
public HandleValue(Object value) {
this.value = value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ public static void rearrangeBasicBlocks(BIRNode.BIRFunction birFunction) {
int currentBBId = 0;
// Re-arrange basic blocks
for (BIRNode.BIRBasicBlock bb : birFunction.basicBlocks) {
bb.number = currentBBId;
bb.id = new Name(BIRBasicBlock.BIR_BASIC_BLOCK_PREFIX + currentBBId++);
currentBBId = renumberBasicBlock(currentBBId, bb);
}
// Re-arrange error entries
birFunction.errorTable.sort(Comparator.comparingInt(o -> o.trapBB.number));
}

public static int renumberBasicBlock(int newBBNum, BIRBasicBlock bb) {
bb.number = newBBNum;
bb.id = new Name(BIRBasicBlock.BIR_BASIC_BLOCK_PREFIX + newBBNum);
return newBBNum + 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public class JvmConstants {
public static final String ERROR_UTILS = "io/ballerina/runtime/internal/ErrorUtils";
public static final String ERROR_CREATOR = "io/ballerina/runtime/api/ErrorCreator";
public static final String RUNTIME_UTILS = "io/ballerina/runtime/internal/util/RuntimeUtils";
public static final String LARGE_STRUCTURE_UTILS = "io/ballerina/runtime/internal/util/LargeStructureUtils";
public static final String OPTION = "io/ballerina/runtime/internal/cli/Option";
public static final String OPERAND = "io/ballerina/runtime/internal/cli/Operand";
public static final String CLI_SPEC = "io/ballerina/runtime/internal/cli/CliSpec";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
import org.wso2.ballerinalang.compiler.bir.codegen.internal.AsyncDataCollector;
import org.wso2.ballerinalang.compiler.bir.codegen.internal.BIRVarToJVMIndexMap;
import org.wso2.ballerinalang.compiler.bir.codegen.interop.JCast;
import org.wso2.ballerinalang.compiler.bir.codegen.interop.JInsKind;
import org.wso2.ballerinalang.compiler.bir.codegen.interop.JInstruction;
import org.wso2.ballerinalang.compiler.bir.codegen.interop.JLargeArrayInstruction;
import org.wso2.ballerinalang.compiler.bir.codegen.interop.JLargeMapInstruction;
import org.wso2.ballerinalang.compiler.bir.codegen.interop.JMethodCallInstruction;
import org.wso2.ballerinalang.compiler.bir.codegen.interop.JType;
import org.wso2.ballerinalang.compiler.bir.codegen.interop.JTypeTags;
Expand Down Expand Up @@ -128,6 +129,7 @@
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.ARRAY_VALUE_IMPL;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.BAL_ENV_CLASS;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.BYTE_VALUE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.B_LIST_INITIAL_VALUE_ENTRY;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.B_MAPPING_INITIAL_VALUE_ENTRY;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.B_OBJECT;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.B_STRING_VALUE;
Expand All @@ -137,6 +139,8 @@
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.EQUALS_METHOD;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.ERROR_VALUE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.FUNCTION_POINTER;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.GET_VALUE_METHOD;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.HANDLE_VALUE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.INSTANTIATE_FUNCTION;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.INT_VALUE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.JSON_UTILS;
Expand Down Expand Up @@ -233,6 +237,7 @@
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.PASS_OBJECT_RETURN_OBJECT;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.PROCESS_FP_ANNOTATIONS;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.PROCESS_OBJ_CTR_ANNOTATIONS;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.RETURN_OBJECT;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.SET_DECIMAL_RETURN_DECIMAL;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.SET_ON_INIT;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.TWO_OBJECTS_ARGS;
Expand Down Expand Up @@ -598,37 +603,85 @@ private BType getSmallestBuiltInUnsignedIntSubTypeContainingTypes(BType lhsType,
}

void generatePlatformIns(JInstruction ins, int localVarOffset) {
if (ins.jKind == JInsKind.JCAST) {
JCast castIns = (JCast) ins;
BType targetType = castIns.targetType;
this.loadVar(castIns.rhsOp.variableDcl);
jvmCastGen.generatePlatformCheckCast(this.mv, this.indexMap, castIns.rhsOp.variableDcl.type, targetType);
this.storeToVar(castIns.lhsOp.variableDcl);
} else if (ins.jKind == JInsKind.CALL) {
JMethodCallInstruction callIns = (JMethodCallInstruction) ins;
boolean isInterface = callIns.invocationType == INVOKEINTERFACE;
int argIndex = 0;
String jMethodVMSig = callIns.jMethodVMSig;
boolean hasBalEnvParam = jMethodVMSig.startsWith(BAL_ENV_PARAM);
if (hasBalEnvParam) {
mv.visitTypeInsn(NEW, BAL_ENV_CLASS);
mv.visitInsn(DUP);
// load the strand
this.mv.visitVarInsn(ALOAD, localVarOffset);
// load the current Module
mv.visitFieldInsn(GETSTATIC, this.moduleInitClass, CURRENT_MODULE_VAR_NAME, GET_MODULE);
mv.visitMethodInsn(INVOKESPECIAL, BAL_ENV_CLASS, JVM_INIT_METHOD,
INIT_BAL_ENV, false);
}
switch (ins.jKind) {
Nadeeshan96 marked this conversation as resolved.
Show resolved Hide resolved
case JCAST -> generateJCastIns((JCast) ins);
case CALL -> generateJMethodCallIns(localVarOffset, (JMethodCallInstruction) ins);
case LARGE_ARRAY -> generateJLargeArrayIns(localVarOffset, (JLargeArrayInstruction) ins);
default -> generateJLargeMapIns(localVarOffset, (JLargeMapInstruction) ins);
}
}

private void generateJLargeMapIns(int localVarOffset, JLargeMapInstruction mapNewIns) {
this.loadVar(mapNewIns.rhsOp.variableDcl);
this.mv.visitVarInsn(ALOAD, localVarOffset);

while (argIndex < callIns.args.size()) {
BIROperand arg = callIns.args.get(argIndex);
this.loadVar(arg.variableDcl);
argIndex += 1;
// load the initial values operand
this.loadVar(mapNewIns.initialValues.variableDcl);
mv.visitMethodInsn(INVOKEVIRTUAL, HANDLE_VALUE, GET_VALUE_METHOD, RETURN_OBJECT, false);
mv.visitTypeInsn(CHECKCAST, "[L" + B_MAPPING_INITIAL_VALUE_ENTRY + ";");

this.mv.visitMethodInsn(INVOKEINTERFACE, TYPEDESC_VALUE, INSTANTIATE_FUNCTION, INSTANTIATE, true);
this.storeToVar(mapNewIns.lhsOp.variableDcl);
}

private void generateJLargeArrayIns(int localVarOffset, JLargeArrayInstruction inst) {
BType instType = JvmCodeGenUtil.getReferredType(inst.type);
if (instType.tag == TypeTags.ARRAY) {
this.mv.visitTypeInsn(NEW, ARRAY_VALUE_IMPL);
this.mv.visitInsn(DUP);
jvmTypeGen.loadType(this.mv, inst.type);
loadListInitialValues(inst);
BType elementType = JvmCodeGenUtil.getReferredType(((BArrayType) instType).eType);
if (elementType.tag == TypeTags.RECORD || (elementType.tag == TypeTags.INTERSECTION &&
((BIntersectionType) elementType).effectiveType.tag == TypeTags.RECORD)) {
visitNewRecordArray(elementType);
} else {
this.mv.visitMethodInsn(INVOKESPECIAL, ARRAY_VALUE_IMPL, JVM_INIT_METHOD,
INIT_ARRAY, false);
}
this.mv.visitMethodInsn(callIns.invocationType, callIns.jClassName, callIns.name, jMethodVMSig,
isInterface);
this.storeToVar(inst.lhsOp.variableDcl);
} else {
this.loadVar(inst.typedescOp.variableDcl);
this.mv.visitVarInsn(ALOAD, localVarOffset);
loadListInitialValues(inst);
this.mv.visitMethodInsn(INVOKEINTERFACE, TYPEDESC_VALUE, INSTANTIATE_FUNCTION, INSTANTIATE, true);
this.storeToVar(inst.lhsOp.variableDcl);
}
}

private void generateJMethodCallIns(int localVarOffset, JMethodCallInstruction callIns) {
boolean isInterface = callIns.invocationType == INVOKEINTERFACE;
int argIndex = 0;
String jMethodVMSig = callIns.jMethodVMSig;
boolean hasBalEnvParam = jMethodVMSig.startsWith(BAL_ENV_PARAM);
if (hasBalEnvParam) {
mv.visitTypeInsn(NEW, BAL_ENV_CLASS);
mv.visitInsn(DUP);
// load the strand
this.mv.visitVarInsn(ALOAD, localVarOffset);
// load the current Module
mv.visitFieldInsn(GETSTATIC, this.moduleInitClass, CURRENT_MODULE_VAR_NAME, GET_MODULE);
mv.visitMethodInsn(INVOKESPECIAL, BAL_ENV_CLASS, JVM_INIT_METHOD,
INIT_BAL_ENV, false);
}
while (argIndex < callIns.args.size()) {
BIROperand arg = callIns.args.get(argIndex);
this.loadVar(arg.variableDcl);
argIndex += 1;
}
this.mv.visitMethodInsn(callIns.invocationType, callIns.jClassName, callIns.name, jMethodVMSig,
isInterface);
if (callIns.lhsOp != null) {
this.storeToVar(callIns.lhsOp.variableDcl);
}
}

private void generateJCastIns(JCast castIns) {
BType targetType = castIns.targetType;
this.loadVar(castIns.rhsOp.variableDcl);
jvmCastGen.generatePlatformCheckCast(this.mv, this.indexMap, castIns.rhsOp.variableDcl.type,
targetType);
this.storeToVar(castIns.lhsOp.variableDcl);
}

void generateMoveIns(BIRNonTerminator.Move moveIns) {
Expand Down Expand Up @@ -2174,6 +2227,12 @@ private void loadListInitialValues(BIRNonTerminator.NewArray arrayNewIns) {
}
}

private void loadListInitialValues(JLargeArrayInstruction largeArrayIns) {
this.loadVar(largeArrayIns.values.variableDcl);
mv.visitMethodInsn(INVOKEVIRTUAL, HANDLE_VALUE, GET_VALUE_METHOD, RETURN_OBJECT, false);
mv.visitTypeInsn(CHECKCAST, "[L" + B_LIST_INITIAL_VALUE_ENTRY + ";");
}

private void createExprEntry(BIRNode.BIRListConstructorEntry initialValueOp) {
mv.visitTypeInsn(NEW, LIST_INITIAL_EXPRESSION_ENTRY);
mv.visitInsn(DUP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ public class JvmSignatures {
public static final String HANDLE_WAIT_MULTIPLE = "(L" + MAP + ";L" + MAP_VALUE + ";)V";
public static final String HANDLE_WORKER_ERROR =
"(L" + REF_VALUE + ";L" + STRAND_CLASS + ";[L" + CHANNEL_DETAILS + ";)V";
public static final String HANDLE_OBJECT_LONG_ARGS = "(" + GET_HANDLE_VALUE + GET_OBJECT + "J)V";
public static final String INIT_ARRAY = "(L" + TYPE + ";[L" + B_LIST_INITIAL_VALUE_ENTRY + ";)V";
public static final String INIT_ARRAY_TYPE_IMPL = "(L" + TYPE + ";IZI)V";
public static final String INIT_ARRAY_WITH_INITIAL_VALUES =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@
return args.toArray(new BIROperand[0]);
}

@Override
public void setRhsOperands(BIROperand[] operands) {
this.args = List.of(operands);
}

@Override

Check warning on line 63 in compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JIConstructorCall.java

View check run for this annotation

Codecov / codecov/patch

compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JIConstructorCall.java#L60-L63

Added lines #L60 - L63 were not covered by tests
public BIRBasicBlock[] getNextBasicBlocks() {
return new BIRBasicBlock[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public BIROperand[] getRhsOperands() {
return args.toArray(new BIROperand[0]);
}

@Override
public void setRhsOperands(BIROperand[] operands) {
this.args = List.of(operands);
}

@Override
public BIRBasicBlock[] getNextBasicBlocks() {
return new BIRBasicBlock[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
*/
public enum JInsKind {
JCAST((byte) 1),
CALL((byte) 2);
CALL((byte) 2),
LARGE_ARRAY((byte) 3),
LARGE_MAP((byte) 4);

byte value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@
public BIROperand[] getRhsOperands() {
return new BIROperand[0];
}

@Override
public void setRhsOperands(BIROperand[] operands) {
// do nothing
}

Check warning on line 54 in compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JInstruction.java

View check run for this annotation

Codecov / codecov/patch

compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JInstruction.java#L54

Added line #L54 was not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com) All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.ballerinalang.compiler.bir.codegen.interop;

import io.ballerina.tools.diagnostics.Location;
import org.wso2.ballerinalang.compiler.bir.model.BIROperand;
import org.wso2.ballerinalang.compiler.semantics.model.types.BType;

/**
* New large array instruction modeled as BIR NonTerminator JInstruction.
*
* @since 2201.8.0
*/
public class JLargeArrayInstruction extends JInstruction {

public BIROperand typedescOp;
public BIROperand sizeOp;
public BType type;
public BIROperand values;

public JLargeArrayInstruction(Location location, BType type, BIROperand lhsOp, BIROperand sizeOp,
BIROperand values) {
super(location);
jKind = JInsKind.LARGE_ARRAY;
this.type = type;
this.lhsOp = lhsOp;
this.sizeOp = sizeOp;
this.values = values;
}

public JLargeArrayInstruction(Location location, BType type, BIROperand lhsOp, BIROperand typedescOp,
BIROperand sizeOp, BIROperand values) {
this(location, type, lhsOp, sizeOp, values);
this.typedescOp = typedescOp;
}

@Override
public BIROperand[] getRhsOperands() {
if (typedescOp != null) {
return new BIROperand[]{typedescOp, sizeOp, values};

Check warning on line 56 in compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JLargeArrayInstruction.java

View check run for this annotation

Codecov / codecov/patch

compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JLargeArrayInstruction.java#L56

Added line #L56 was not covered by tests
} else {
return new BIROperand[]{sizeOp, values};

Check warning on line 58 in compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JLargeArrayInstruction.java

View check run for this annotation

Codecov / codecov/patch

compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JLargeArrayInstruction.java#L58

Added line #L58 was not covered by tests
}
}

@Override
public void setRhsOperands(BIROperand[] operands) {
if (operands.length == 3) {
this.typedescOp = operands[0];
this.sizeOp = operands[1];
this.values = operands[2];

Check warning on line 67 in compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JLargeArrayInstruction.java

View check run for this annotation

Codecov / codecov/patch

compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JLargeArrayInstruction.java#L65-L67

Added lines #L65 - L67 were not covered by tests
} else {
this.sizeOp = operands[0];
this.values = operands[1];

Check warning on line 70 in compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JLargeArrayInstruction.java

View check run for this annotation

Codecov / codecov/patch

compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JLargeArrayInstruction.java#L69-L70

Added lines #L69 - L70 were not covered by tests
}
}

Check warning on line 72 in compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JLargeArrayInstruction.java

View check run for this annotation

Codecov / codecov/patch

compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JLargeArrayInstruction.java#L72

Added line #L72 was not covered by tests
}
Loading
Loading