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]: Duplicate BIRNonTerminator.TypeCast instruction when passing arguments to a method with complex Varargs type parameter #42492

Open
Thushara-Piyasekara opened this issue Apr 5, 2024 · 0 comments
Labels
Area/BIR Compiler BIR related issues #Compiler Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug

Comments

@Thushara-Piyasekara
Copy link
Contributor

Description

When passing arguments to a complex Varargs type parameter, BIRGen phase generate a duplicate BIRNonTerminator.TypeCast instruction. This duplicate instruction can be removed for better runtime performance.

Steps to Reproduce

See the following example,

public function main() {
    bar("hello");
}

function bar(string|int... item) {

}

use bal build --dump-bir to see the BIR instructions,

public main function() -> () {
    %0(RETURN) ();
    %1(TEMP) string|int[];
    %2(TEMP) int;
    %3(TEMP) string|int;
    %4(TEMP) string|int;
    %5(TEMP) string;
    %6(TEMP) ();

    bb0 {
        %2 = ConstLoad -1;
        %5 = ConstLoad hello;
        %4 = <string|int> %5;
        %3 = <string|int> %4;
        %1 = newArray string|int[][%2]{%3};
        %6 = bar(%1) -> bb1;
    }
    bb1 {
        %0 = ConstLoad 0;
        GOTO bb2;
    }
    bb2 {
        return;
    }
}

In bb0 following duplicate instructions can be found,

        %4 = <string|int> %5;
        %3 = <string|int> %4;

Same duplicate instructions can be found when debugging the BIRgen phase,

image

Affected Version(s)

Ballerina 2201.9.0 (Swan Lake Update 9) SNAPSHOT

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 Apr 5, 2024
@nipunayf nipunayf added Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Area/BIR Compiler BIR related issues #Compiler and removed needTriage The issue has to be inspected and labeled manually userCategory/Compilation labels Apr 5, 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 Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug
Projects
None yet
Development

No branches or pull requests

3 participants