ballerina-platform / ballerina-lang

The Ballerina Programming Language
https://ballerina.io/
Apache License 2.0
3.67k stars 751 forks source link

[Improvement]: Make the type engine to work when part of the type is SemType and the other part is BType #41066

Closed lochana-chathura closed 7 months ago

lochana-chathura commented 1 year ago

Description

$subject.

Describe your problem(s)

In the current integration of sem-types, we can't ship it until we fully complete the sem-type engine for all the types. Therefore, as per our recent discussions we need to make the type checker work when only part of the type are sem-types.

Describe your solution(s)

A type would have two components. A BType component and a SemType component. When we do type operations like union, intersection, and subtyping, we can split it into two sub-problems.

Let type P = P1|P2 and Q = Q1|Q2. Here P1/Q1 are the BType components and P2/Q2 are the semtype components. We expect BType and SemType components to be disjoint.

Then we can derive the operations on top of P and Q like this.

In the above, each operation is split into two operations where the first operation is done from the existing logic whereas the second operation is done from the new logic.

lochana-chathura commented 1 year ago

Update:

lochana-chathura commented 1 year ago

Update:

lochana-chathura commented 1 year ago

Update:

lochana-chathura commented 8 months ago

This issue had been parked for a while due to eggplant priorities. However, it is now back in progress.

Current state: All tests are passing except for the tests that rely upon the syntax order of the union type. e.g. cloneWithType After a discussion with James, It was concluded to maintain the order of the basic type bitset at least.

lochana-chathura commented 8 months ago

Current state: All tests are passing except for the tests that rely upon the syntax order of the union type. e.g. cloneWithType After a discussion with James, It was concluded to maintain the order of the basic type bitset at least.

Tests are all passing with the fix done with #42158.

Current state: Working on refactoring several places before sending the final PR.

lochana-chathura commented 7 months ago

Changes are now complete.

Following performance tests were conducted on top of the changes.

  1. Building the nBallerina compiler
  2. Running jBallerina unit tests

Results are attached with the screenshot.

Screenshot 2024-03-05 at 16 54 38

In summary, there is a 2% performance drop with the changes. This could be because we are populating an extra sem-type property for each BType.

lochana-chathura commented 7 months ago

As discussed with @hasithaa, it was decided to not include these changes for update 9. However, will be shipped in a future release.

Closing the issue as changes are done and are available at the nutcracker branch.