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]: Compiler crash in worker when on fail clause is present and a worker returns error #42502

Open
poorna2152 opened this issue Apr 8, 2024 · 1 comment
Assignees
Labels
Area/BIR Compiler BIR related issues #Compiler Area/Desugar Issue related Desugar and Code optimizer #Compiler Lang/Workers Workers and Worker Interaction related issues Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug

Comments

@poorna2152
Copy link
Contributor

poorna2152 commented Apr 8, 2024

Description

Consider the following code,

import ballerina/io;

public function main() returns error? {
    boolean condition = true;
    worker w1 returns error? {
        if condition {
            return error("Error in worker 1");
        }
        0 -> w2;
    }

    worker w2 returns error? {
        int x = check <- w1;
    } on fail {
    }

    error? e = wait w2;

    io:println(e);
}

This code gives a compiler crash,

Resolving Maven dependencies
        Downloading dependencies into /Users/poorna/Documents/issues/lang/xmlns_def/target/platform-libs

Compiling source
        poorna/xmlns_def:0.1.0
ballerina: Oh no, something really went wrong. Bad. Sad.

We appreciate it if you can report the code that broke Ballerina in
https://github.com/ballerina-platform/ballerina-lang/issues with the
log you get below and your sample code.

We thank you for helping make us better.

[2024-04-08 14:03:50,878] SEVERE {b7a.log.crash} - Cannot read field "number" because "targetBB" is null 
java.lang.NullPointerException: Cannot read field "number" because "targetBB" is null
        at org.wso2.ballerinalang.compiler.bir.optimizer.BIRBasicBlockOptimizer.getRemovableBasicBlocks(BIRBasicBlockOptimizer.java:125)
        at org.wso2.ballerinalang.compiler.bir.optimizer.BIRBasicBlockOptimizer.visit(BIRBasicBlockOptimizer.java:79)
        at org.wso2.ballerinalang.compiler.bir.model.BIRNode$BIRFunction.accept(BIRNode.java:432)
        at org.wso2.ballerinalang.compiler.bir.optimizer.BIRBasicBlockOptimizer.lambda$visit$1(BIRBasicBlockOptimizer.java:62)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
        at org.wso2.ballerinalang.compiler.bir.optimizer.BIRBasicBlockOptimizer.visit(BIRBasicBlockOptimizer.java:62)
        at org.wso2.ballerinalang.compiler.bir.model.BIRNode$BIRPackage.accept(BIRNode.java:89)
        at org.wso2.ballerinalang.compiler.bir.optimizer.BIRBasicBlockOptimizer.optimizeNode(BIRBasicBlockOptimizer.java:51)
        at org.wso2.ballerinalang.compiler.bir.optimizer.BIROptimizer.optimizePackage(BIROptimizer.java:99)
        at org.wso2.ballerinalang.compiler.bir.BIRGen.genBIR(BIRGen.java:294)
        at io.ballerina.projects.internal.CompilerPhaseRunner.birGen(CompilerPhaseRunner.java:216)
        at io.ballerina.projects.internal.CompilerPhaseRunner.performBirGenPhases(CompilerPhaseRunner.java:153)
        at io.ballerina.projects.ModuleContext.generateCodeInternal(ModuleContext.java:454)
        at io.ballerina.projects.ModuleCompilationState$4.generatePlatformSpecificCode(ModuleCompilationState.java:132)
        at io.ballerina.projects.ModuleContext.generatePlatformSpecificCode(ModuleContext.java:387)
        at io.ballerina.projects.JBallerinaBackend.performCodeGen(JBallerinaBackend.java:173)
        at io.ballerina.projects.JBallerinaBackend.<init>(JBallerinaBackend.java:142)
        at io.ballerina.projects.JBallerinaBackend.lambda$from$0(JBallerinaBackend.java:126)
        at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1220)
        at io.ballerina.projects.PackageCompilation.getCompilerBackend(PackageCompilation.java:178)
        at io.ballerina.projects.JBallerinaBackend.from(JBallerinaBackend.java:125)
        at io.ballerina.projects.JBallerinaBackend.from(JBallerinaBackend.java:113)
        at io.ballerina.cli.task.CompileTask.execute(CompileTask.java:216)
        at io.ballerina.cli.TaskExecutor.executeTasks(TaskExecutor.java:40)
        at io.ballerina.cli.cmd.RunCommand.execute(RunCommand.java:254)
        at java.base/java.util.Optional.ifPresent(Optional.java:178)
        at io.ballerina.cli.launcher.Main.main(Main.java:58)
 
WARNING [main.bal:(441:9,441:29)] unused variable 'x'
ERROR [xmlns_def:(1:1,1:1)] Compilation failed due to: Cannot read field "number" because "targetBB" is null
error: compilation contains errors
@ballerina-bot ballerina-bot added needTriage The issue has to be inspected and labeled manually userCategory/Compilation labels Apr 8, 2024
@poorna2152 poorna2152 removed the needTriage The issue has to be inspected and labeled manually label Apr 8, 2024
@lochana-chathura lochana-chathura added Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime Lang/Actions/WorkerMessagePassing Lang/Workers Workers and Worker Interaction related issues and removed userCategory/Compilation Lang/Actions/WorkerMessagePassing labels Apr 8, 2024
@gabilang gabilang self-assigned this May 14, 2024
@gabilang
Copy link
Contributor

The following works without crash,

public function main() returns error? {
    boolean condition = true;
    worker w1 returns error? {
        if condition {
            return error("Error in worker 1");
        } 
        0 -> w2;
    }

    worker w2 returns error? {
        _ = check foo();
        _ = check <- w1;
    } on fail {
        return error("Error in worker 2");
    }

    check wait w2;
}

function foo() returns int|error {
    return 10;
}

It seems the issue happens, when there are check expr only from worker receive actions.

@gabilang gabilang added Area/Desugar Issue related Desugar and Code optimizer #Compiler Area/BIR Compiler BIR related issues #Compiler Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. and removed Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime labels May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/BIR Compiler BIR related issues #Compiler Area/Desugar Issue related Desugar and Code optimizer #Compiler Lang/Workers Workers and Worker Interaction related issues Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug
Projects
Status: No status
Development

No branches or pull requests

4 participants