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]: Reorder top level node list #41946

Open
chiranSachintha opened this issue Jan 8, 2024 · 2 comments
Open

[Improvement]: Reorder top level node list #41946

chiranSachintha opened this issue Jan 8, 2024 · 2 comments
Assignees
Labels
Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Improvement

Comments

@chiranSachintha
Copy link
Member

Description

In the existing implementation, we currently reorder the constants list and the global variable list separately. However, when considering the annotations of type definitions(as annotations are part of the typedesc), they depend on the order of both constants and global variables. Therefore, it is necessary to reorder the toplevel node list instead of reordering constants, global variables, and type definitions separately.

type AnnotRecord record {|
    string value;
|};

annotation AnnotRecord annot on type;

@annot {
    value: l
}
type T1 record {
    string name;
};

string l = "chiranS";

When considering the above example, the annot (annotation) is a component of the type description (typedesc) of T1. So we need to rearrange the top-level node list as follows.

type AnnotRecord record {|
    string value;
|};

annotation AnnotRecord annot on type;
string l = "chiranS";
@annot {
    value: l
}
type T1 record {
    string name;
};

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

@chiranSachintha chiranSachintha self-assigned this Jan 8, 2024
@ballerina-bot ballerina-bot added needTriage The issue has to be inspected and labeled manually userCategory/Compilation labels Jan 8, 2024
@chiranSachintha chiranSachintha 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 userCategory/Compilation labels Jan 8, 2024
@rdulmina rdulmina assigned rdulmina and unassigned chiranSachintha Aug 15, 2024
@rdulmina rdulmina moved this to In Progress in Ballerina Team Main Board Aug 15, 2024
@rdulmina
Copy link
Contributor

rdulmina commented Aug 16, 2024

The above example in the issue works without any issue in the current implementation because although the l is defined after the type T1, when we codegen we populate the annotation value for type T1 after all the const and var declarations are done. We handle this in the AnnotationDesugar Hence the above sample works without any issue.

Screenshot 2024-08-15 at 16 02 47

Issue in the current approach is when we have access the annot value before the populate happens

type AnnotRecord record {|
   string value;
|};

annotation AnnotRecord annot on type;

@annot {
   value: l
}
type T1 record {
   string name;
};

string l = "chiranS";
string? b = T1.@annot?.value;

Note that variable b is a top-level variable. The value of the b will be null in this case. If we define b locally it gives the correct value

@rdulmina
Copy link
Contributor

rdulmina commented Oct 18, 2024

Changes are done. 13 jballerina unit tests are filing ATM. Will send a PR soon. Below are some failing cases.

  1. The below sample fails with java.lang.NullPointerException: Cannot read field "name" because "varDcl" is null
public function main() {
    var input = [{name: "Saman", price: 11}];
    record {|string name; int price;|}[][] res = from var {name} in input group by name
                                                    select from var {price} in input
                                                            select {name, price};
// the issue here is we create several lambda functions for the query expression and those functions 
// do not have the typedesc in local variables. it seems typedesc need to be passed as a closure for those
}
  1. Set of test are failing causing method to large error.

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: In Progress
Development

Successfully merging a pull request may close this issue.

3 participants