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

[Improvement]: Remove unnecessary type definition creation for interop function definitions #40914

Closed
Nadeeshan96 opened this issue Jul 4, 2023 · 0 comments · Fixed by #40964
Assignees
Labels
Priority/High Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Improvement
Milestone

Comments

@Nadeeshan96
Copy link
Contributor

Nadeeshan96 commented Jul 4, 2023

Description

$title

If an interop function is defined in Ballerina it creates unnecessary type definitions by the front-end per each interop function.

For example, langlibs have high no. of interop functions. (eg: float langlib nearly 35 and it has 70 BLangTypeDefinitions in the BLangPackage - 2 per one interop function).

image image

Hence we have high no. of unnecessary typedesc classes, value classes, frame classes that result in unnecessarily large jar size.

Describe your problem(s)

E.g.:

import ballerina/jballerina.java;

public isolated function abs(float x) returns float = @java:Method {
    'class: "org.ballerinalang.langlib.floatingpoint.Abs",
    name: "abs"
} external;

public isolated function max(float... xs) returns float = @java:Method {
    'class: "org.ballerinalang.langlib.floatingpoint.Max",
    name: "max"
} external;

public isolated function absBal(float x) returns float {
    return x > 0.0 ? x : -x;
}

For the first 2 interop functions, the front-end creates records {class:.., name:..} and 2 type definitions for each interop function.
image

Describe your solution(s)

We see the type definitions created for all interop functions are mostly the same. We can try removing all of them or keep at most just 2, thus removing unnecessary typeDefs and attached functions in the BIRPackage.

Related area

-> Compilation

Related issue(s) (optional)

#40867

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority/High Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Improvement
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants