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

[Bug]: Getting a NoSuchFieldError when running tests for Ballerina IO package with Dead code elimination #43554

Closed
ayeshLK opened this issue Nov 6, 2024 · 5 comments
Assignees
Labels
Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug userCategory/Compilation

Comments

@ayeshLK
Copy link
Member

ayeshLK commented Nov 6, 2024

Description

$subject

Steps to Reproduce

  1. Update Ballerina lang version to 2201.11.0-20241101-105200-f94714be in the gradle.properties.

  2. Build Ballerina IO module (using gradle) and there will be an intermediate pack constructed in <project-root>/target/ballerina-runtime.

  3. Run the following command.

BAL_DISABLE_HARDCODED_OPTIMIZATIONS=true <path-to-intermediate-pack>/bin/bal test --eliminate-dead-code --dead-code-elimination-report

Affected Version(s)

Ballerina Lang version 2201.11.0-20241101-105200-f94714be

OS, DB, other environment details and versions

No response

Related area

-> Compilation

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@ballerina-bot ballerina-bot added needTriage The issue has to be inspected and labeled manually userCategory/Compilation labels Nov 6, 2024
@ayeshLK ayeshLK changed the title [Bug]: Getting a NoSuchFieldError for tests in Ballerina IO package when using Dead code elimination [Bug]: Getting a NoSuchFieldError when running tests for Ballerina IO package with Dead code elimination Nov 6, 2024
@MaryamZi MaryamZi added Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. and removed needTriage The issue has to be inspected and labeled manually labels Nov 7, 2024
@MaryamZi MaryamZi self-assigned this Nov 7, 2024
@MaryamZi MaryamZi moved this to In Progress in Ballerina Team Main Board Nov 7, 2024
@MaryamZi
Copy link
Member

MaryamZi commented Nov 7, 2024

Without adding the annotations, if we use BAL_DISABLE_HARDCODED_OPTIMIZATIONS, errors are expected.

This may still be a bug though. In the report, toTableExtern is identified as used, but it seems like the anonymous record member type of the table type in the return type is getting removed.

@MaryamZi
Copy link
Member

MaryamZi commented Nov 7, 2024

The issue seems to be due to the isTestablePkgImportedModuleDependency check incorrectly returning true for in-line types like tables (and probably maps, arrays, etc.), since their package IDs are the lang.annotation package's package ID.

@MaryamZi
Copy link
Member

MaryamZi commented Nov 7, 2024

When we special case such types the original errors go away, but then I see errors similar to that reported in #43552.

diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/UsedTypeDefAnalyzer.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/UsedTypeDefAnalyzer.java
index 0fb5137c051..d0e16870aa5 100644
--- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/UsedTypeDefAnalyzer.java
+++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/UsedTypeDefAnalyzer.java
@@ -20,6 +20,7 @@ package io.ballerina.projects;
 import org.wso2.ballerinalang.compiler.PackageCache;
 import org.wso2.ballerinalang.compiler.bir.model.BIRNode;
 import org.wso2.ballerinalang.compiler.semantics.model.SimpleBTypeAnalyzer;
+import org.wso2.ballerinalang.compiler.semantics.model.SymbolTable;
 import org.wso2.ballerinalang.compiler.semantics.model.types.BType;
 import org.wso2.ballerinalang.compiler.util.CompilerContext;
 import org.wso2.ballerinalang.compiler.util.TypeTags;
@@ -43,11 +44,13 @@ public final class UsedTypeDefAnalyzer extends SimpleBTypeAnalyzer<UsedTypeDefAn
     private final Set<BType> visitedTypes = new HashSet<>();
     private final PackageCache pkgCache;
     private final UsedBIRNodeAnalyzer usedBIRNodeAnalyzer;
+    private final SymbolTable symbolTable;
 
     private UsedTypeDefAnalyzer(CompilerContext context) {
         context.put(BIR_TYPE_DEF_ANALYZER_KEY, this);
         this.pkgCache = PackageCache.getInstance(context);
         this.usedBIRNodeAnalyzer = UsedBIRNodeAnalyzer.getInstance(context);
+        this.symbolTable = SymbolTable.getInstance(context);
     }
 
     public static UsedTypeDefAnalyzer getInstance(CompilerContext context) {
@@ -177,6 +180,7 @@ public final class UsedTypeDefAnalyzer extends SimpleBTypeAnalyzer<UsedTypeDefAn
         }
 
         return usedBIRNodeAnalyzer.isTestablePkgAnalysis &&
+                !bType.tsymbol.pkgID.equals(symbolTable.langAnnotationModuleSymbol.pkgID) && // built-in types
                 !bType.tsymbol.pkgID.equals(usedBIRNodeAnalyzer.currentPkgID);
     }

@MaryamZi MaryamZi moved this from In Progress to BackLog in Ballerina Team Main Board Nov 8, 2024
@MaryamZi MaryamZi moved this from BackLog to PR Sent in Ballerina Team Main Board Nov 8, 2024
@MaryamZi
Copy link
Member

We've added some fixes which are available with 2201.11.0-20241111-101700-af28a18f, can you please check with this version?

@MaryamZi MaryamZi added the Reason/EngineeringMistake The issue occurred due to a mistake made in the past. label Nov 13, 2024
@MaryamZi
Copy link
Member

Fixed in #43557.

@github-project-automation github-project-automation bot moved this from PR Sent to Done in Ballerina Team Main Board Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug userCategory/Compilation
Projects
Status: Done
Development

No branches or pull requests

3 participants