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]: Improve field access expression desugar #43769

Open
rdulmina opened this issue Jan 27, 2025 · 1 comment · Fixed by #43770 · May be fixed by #43782
Open

[Improvement]: Improve field access expression desugar #43769

rdulmina opened this issue Jan 27, 2025 · 1 comment · Fixed by #43770 · May be fixed by #43782
Assignees
Labels
Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Improvement

Comments

@rdulmina
Copy link
Contributor

Description

Currently, the field access expression desugared in to match statement which cases lot of instructions when there is a large chain access of the field access expression. This could lead to unwanted method to large errors at runtime.

Need to find a better way of desugaring eg: Try to desugar into if statement.

Related internal issue: https://github.com/wso2-enterprise/internal-support-ballerina/issues/862

Describe your problem(s)

No response

Describe your solution(s)

No response

Related area

-> Compilation

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@rdulmina rdulmina added Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Improvement labels Jan 27, 2025
@rdulmina rdulmina self-assigned this Jan 27, 2025
@rdulmina
Copy link
Contributor Author

Desugared field access expression to the following structure

// Before :
type A {
  B b;
}
type B {
 int c;
}
int? res = a?.b?.c

// After desugar :
any|error temp_result;
temp_result = a;
if temp_result !is error? {
    temp_result = (<A> temp_result).b;
    if temp_result !is error? {
        temp_result = (<B> temp_result).c;
    }
}
int? res = <int> temp_result;
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Improvement
Projects
Status: PR Sent
1 participant