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

[Draft] Fix BIRPackage.importModules containing duplicate elements #42346

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -25,6 +25,7 @@

import java.io.PrintStream;
import java.util.List;
import java.util.Set;

import static org.wso2.ballerinalang.compiler.bir.emit.EmitterUtils.emitBasicBlockRef;
import static org.wso2.ballerinalang.compiler.bir.emit.EmitterUtils.emitFlags;
Expand Down Expand Up @@ -101,7 +102,7 @@ public static String emitModule(BIRNode.BIRPackage mod) {
return modStr;
}

private static String emitImports(List<BIRNode.BIRImportModule> impMods) {
private static String emitImports(Set<BIRNode.BIRImportModule> impMods) {

StringBuilder impStr = new StringBuilder();
for (BIRNode.BIRImportModule mod : impMods) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
Expand All @@ -55,7 +56,7 @@
*/
public static class BIRPackage extends BIRNode {
public final PackageID packageID;
public final List<BIRImportModule> importModules;
public final Set<BIRImportModule> importModules;
public final List<BIRTypeDefinition> typeDefs;
public final List<BIRGlobalVariableDcl> globalVars;
public final Set<BIRGlobalVariableDcl> importedGlobalVarsDummyVarDcls;
Expand All @@ -74,7 +75,7 @@
String sourceRoot, boolean skipTest, boolean isTestPkg) {
super(pos);
packageID = new PackageID(org, pkgName, name, version, sourceFileName, sourceRoot, isTestPkg, skipTest);
this.importModules = new ArrayList<>();
this.importModules = new LinkedHashSet<>();
this.typeDefs = new ArrayList<>();
this.globalVars = new ArrayList<>();
this.importedGlobalVarsDummyVarDcls = new HashSet<>();
Expand Down Expand Up @@ -107,6 +108,24 @@
public void accept(BIRVisitor visitor) {
visitor.visit(this);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;

Check warning on line 115 in compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNode.java

View check run for this annotation

Codecov / codecov/patch

compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNode.java#L115

Added line #L115 was not covered by tests
}

if (o == null || getClass() != o.getClass()) {
return false;

Check warning on line 119 in compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNode.java

View check run for this annotation

Codecov / codecov/patch

compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNode.java#L119

Added line #L119 was not covered by tests
}

return this.packageID.equals(((BIRImportModule) o).packageID);
}

@Override
public int hashCode() {
return this.packageID.hashCode();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.Set;

import static org.wso2.ballerinalang.compiler.bir.writer.BIRWriterUtils.writeConstValue;

Expand Down Expand Up @@ -95,7 +96,7 @@ public byte[] serialize() {

// private methods

private void writeImportModuleDecls(ByteBuf buf, List<BIRNode.BIRImportModule> birImpModList) {
private void writeImportModuleDecls(ByteBuf buf, Set<BIRNode.BIRImportModule> birImpModList) {
buf.writeInt(birImpModList.size());
birImpModList.forEach(impMod -> {
PackageID packageID = impMod.packageID;
Expand Down
Loading