Skip to content

Commit e134cc8

Browse files
committed
Address review suggestions
Address review suggestions and do type constraint equality check to identity the typedesc in different packages
1 parent 32b0574 commit e134cc8

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java

+14-8
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.ballerinalang.model.tree.OperatorKind;
3535
import org.ballerinalang.model.tree.TopLevelNode;
3636
import org.ballerinalang.model.tree.expressions.RecordLiteralNode;
37+
import org.ballerinalang.model.types.TypeKind;
3738
import org.wso2.ballerinalang.compiler.bir.model.BIRNode;
3839
import org.wso2.ballerinalang.compiler.bir.model.BIRNode.BIRAnnotation;
3940
import org.wso2.ballerinalang.compiler.bir.model.BIRNode.BIRAnnotationAttachment;
@@ -2434,7 +2435,7 @@ private BIRVariableDcl getOrCreateTypedescVariable(BType type, Location pos) {
24342435
return variableDcl;
24352436
}
24362437

2437-
variableDcl = findInPackageScope(type);
2438+
variableDcl = findInDifferentPackage(type);
24382439
if (variableDcl != null && variableDcl.initialized) {
24392440
return variableDcl;
24402441
}
@@ -2446,16 +2447,24 @@ private BIRVariableDcl getOrCreateTypedescVariable(BType type, Location pos) {
24462447
return this.env.targetOperand.variableDcl;
24472448
}
24482449

2449-
private BIRVariableDcl findInPackageScope(BType type) {
2450+
private BIRVariableDcl findInDifferentPackage(BType type) {
24502451
BTypeSymbol typeSymbol = type.tsymbol;
24512452
if (typeSymbol == null || typeSymbol.owner.tag != SymTag.PACKAGE ||
24522453
isInSameModule(typeSymbol, env.enclPkg.packageID)) {
24532454
return null;
24542455
}
24552456
BPackageSymbol packageSymbol = (BPackageSymbol) typeSymbol.owner;
2456-
Scope.ScopeEntry scopeEntry =
2457-
packageSymbol.scope.lookup(new Name(TYPEDESC + typeSymbol.name.value));
2458-
BSymbol symbol = scopeEntry.symbol;
2457+
BSymbol symbol = packageSymbol.scope.entries.entrySet().stream()
2458+
.filter(entry -> entry.getKey().value.startsWith(TYPEDESC))
2459+
.map(entry -> entry.getValue().symbol)
2460+
.filter(entrySymbol -> {
2461+
BType symbolType = entrySymbol.getType();
2462+
return symbolType.getKind() == TypeKind.TYPEDESC &&
2463+
((BTypedescType) symbolType).constraint == type;
2464+
})
2465+
.findFirst()
2466+
.orElse(null);
2467+
24592468
return symbol != null ? getVarRef(createPackageVarRef(symbol)) : null;
24602469
}
24612470

@@ -2504,9 +2513,7 @@ private void createNewTypedescInst(BType resolveType, Location position) {
25042513
BTypeSymbol typeSymbol = resolveType.tsymbol;
25052514
BIRVariableDcl tempVarDcl = createTempVariable();
25062515
BIROperand toVarRef = new BIROperand(tempVarDcl);
2507-
25082516
BIRNonTerminator.NewTypeDesc newTypeDesc = createNewTypeDesc(position, toVarRef, resolveType, typeSymbol);
2509-
25102517
this.env.targetOperand = toVarRef;
25112518
setScopeAndEmit(newTypeDesc);
25122519
}
@@ -2812,7 +2819,6 @@ private void generateListConstructorExpr(BLangListConstructorExpr listConstructo
28122819
VarScope.FUNCTION, VarKind.TEMP);
28132820
this.env.enclFunc.localVars.add(tempVarDcl);
28142821
BIROperand toVarRef = new BIROperand(tempVarDcl);
2815-
28162822
BType listConstructorExprType = listConstructorExpr.getBType();
28172823

28182824
List<BLangExpression> exprs = listConstructorExpr.exprs;

compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/optimizer/LargeMethodOptimizer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public class LargeMethodOptimizer {
9797
// splits are done only if the newly created method will contain more instructions than the below number
9898
private static final int SPLIT_INSTRUCTION_COUNT_THRESHOLD = 25;
9999
// splits are done only if the newly created method will have less function arguments than the below number
100-
private static final int MAX_SPLIT_FUNCTION_ARG_COUNT = 93;
100+
private static final int MAX_SPLIT_FUNCTION_ARG_COUNT = 90;
101101
// total least no. of terminators and non-terminators that should be there to make the periodic split
102102
private static final int INS_COUNT_PERIODIC_SPLIT_THRESHOLD = 500;
103103
// current BIR package id
@@ -845,7 +845,7 @@ private void splitParentFuncForPeriodicArraySplits(BIRFunction parentFunc, List<
845845
for (int bbIndex = 0; bbIndex < bbs.size() - 1; bbIndex++) {
846846
BIRBasicBlock bb = bbs.get(bbIndex);
847847
handleBasicBlockStart(splitFuncEnv, nextBBPendingIns, bb);
848-
// skip large arg restore and array size ins
848+
// skips large argument restore instructions and array size instruction
849849
int insIndex = bbIndex == 0 ? skipLargeArgRestoreInstsAndGetIndex(bb) + 1 : 0;
850850
for (; insIndex < bb.instructions.size(); insIndex++) {
851851
if ((bbIndex == newArrayInsBBNum) && (insIndex == newArrayInsNumInRelevantBB)) {

compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java

-2
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,6 @@ public void visit(BLangPackage pkgNode) {
853853
}
854854
pkgNode.completedPhases.add(CompilerPhase.DESUGAR);
855855
clearGlobalVariables();
856-
857856
result = pkgNode;
858857
}
859858

@@ -9007,7 +9006,6 @@ public void visit(BLangConstant constant) {
90079006
} else {
90089007
constant.expr = rewriteExpr(constant.expr);
90099008
}
9010-
90119009
constant.annAttachments.forEach(attachment -> rewrite(attachment, env));
90129010
result = constant;
90139011
}

tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bir/TypeDescBIRTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ private String readFile(String name) throws IOException {
6262
try (Stream<String> stream = Files.lines(filePath, StandardCharsets.UTF_8)) {
6363
stream.forEach(s -> contentBuilder.append(s).append("\n"));
6464
}
65-
6665
return contentBuilder.toString().trim();
6766
}
6867
Assert.fail("Expected BIR file not found for test: " + name);

0 commit comments

Comments
 (0)