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

Support record defaultable fields with closure values for runtime #40579

Merged
Show file tree
Hide file tree
Changes from 216 commits
Commits
Show all changes
244 commits
Select commit Hold shift + click to select a range
b091f8e
Create closures for default values of record fields
chiranSachintha Jul 31, 2022
8239d79
Updates fields of record literals
chiranSachintha Jul 31, 2022
a1edca9
Refactor closure symbol mark logic
chiranSachintha Jul 31, 2022
77f35a8
Add flag to record fields withs default values
chiranSachintha Jul 31, 2022
d55e2e2
Remove `initFunction` from record type node
chiranSachintha Jul 31, 2022
830edc6
Remove `initializerFunc` from record type symbol
chiranSachintha Jul 31, 2022
a75558f
Introduce default values to record type symbol
chiranSachintha Jul 31, 2022
98c8d6b
Update instantiate record values logic
chiranSachintha Jul 31, 2022
1b7ee69
Remove initializer from record type
chiranSachintha Jul 31, 2022
8325e40
Remove `enclMapSymbols` from BLangStructLiteral
chiranSachintha Jul 31, 2022
c7cdb26
Merge branch 'master' of https://github.com/ballerina-platform/baller…
chiranSachintha Aug 1, 2022
5922082
Resolve conflicts
chiranSachintha Aug 5, 2022
5eaa9f4
Add default values info in the BIR
chiranSachintha Aug 6, 2022
bc27195
Updates fields of record literals
chiranSachintha Aug 6, 2022
9c69ed9
Add default values to ksy file
chiranSachintha Aug 6, 2022
22127cb
Merge branch 'master' of https://github.com/ballerina-platform/baller…
chiranSachintha Aug 25, 2022
555e0a0
Merge branch 'master' of https://github.com/ballerina-platform/baller…
chiranSachintha Sep 2, 2022
bb22312
Merge branch 'closure-changes-for-function-defult-values' of https://…
chiranSachintha Sep 5, 2022
f042529
Remove duplicate visit function
chiranSachintha Sep 15, 2022
7b44339
Add tests for record type
chiranSachintha Sep 15, 2022
6ab8659
Enable builds on the closure branch
chiranSachintha Sep 15, 2022
f34be4e
Merge branch 'closure-changes-for-function-defult-values' of https://…
chiranSachintha Sep 16, 2022
ad672c7
Set closures from the mutable type
chiranSachintha Sep 19, 2022
3a80a18
Merge branch 'master' of https://github.com/ballerina-platform/baller…
chiranSachintha Sep 30, 2022
6fe9727
Resolve conflicts
chiranSachintha Sep 30, 2022
5868535
Rename `ParameterDesugar` to `GenerateClosuresForDefaultValues`
chiranSachintha Sep 30, 2022
ad68c3f
Merge branch 'master' of https://github.com/ballerina-platform/baller…
chiranSachintha Oct 18, 2022
7c5487b
fix review suggestions
chiranSachintha Nov 9, 2022
4ba8e40
Merge branch 'master' of https://github.com/ballerina-platform/baller…
chiranSachintha Nov 9, 2022
bef24be
fix review suggestions
chiranSachintha Nov 9, 2022
5850bdf
Allow intersection of readonly and record type with default values
chiranSachintha Nov 11, 2022
d7bcb23
Add unit tests for intersection of readonly and record type with defa…
chiranSachintha Nov 11, 2022
dbacbeb
Merge branch 'master' of https://github.com/ballerina-platform/baller…
chiranSachintha Feb 21, 2023
4dcab88
Resolve conflicts
chiranSachintha Feb 21, 2023
c798f0c
Rewrite expressions of fields in class definitions
chiranSachintha Mar 21, 2023
bc3708d
Merge branch 'master' of https://github.com/ballerina-platform/baller…
chiranSachintha Mar 21, 2023
8491f61
Reorder import statements
chiranSachintha Mar 22, 2023
0cb664b
Rewrite type node of test expression
chiranSachintha Mar 22, 2023
91e9268
Add default values of type refs to generated type node
chiranSachintha Apr 3, 2023
dbbd54a
Update `getNamesOfUserSpecifiedRecordFields` logic
chiranSachintha Apr 3, 2023
b196f6f
Fix review suggestions
chiranSachintha Apr 27, 2023
e29eb7e
Merge branch 'master' of https://github.com/ballerina-platform/baller…
chiranSachintha Apr 27, 2023
6266b9e
Resolve conflicts
chiranSachintha Apr 27, 2023
0382134
Merge with master
HindujaB May 10, 2023
9e25324
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB May 15, 2023
39a7cd8
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB May 16, 2023
763c15e
Add default value information to record type
HindujaB May 23, 2023
e6d211d
Move cli option creation after init
HindujaB May 23, 2023
e533488
Merge branch 'master' of https://github.com/ballerina-platform/baller…
chiranSachintha Jun 2, 2023
8e13d03
Fix failing tests
HindujaB Jun 2, 2023
bd04cbf
Resolve conflicts
chiranSachintha Jun 2, 2023
05ffb56
Resolve merge conflicts
HindujaB Jun 2, 2023
3cabb7c
Merge branch 'master' of https://github.com/ballerina-platform/baller…
chiranSachintha Jun 7, 2023
fc69d04
Fix review suggestions
chiranSachintha Jun 9, 2023
d7beeef
Add unit tests
chiranSachintha Jun 9, 2023
079cba7
typedesc
chiranSachintha Jun 9, 2023
f9344ed
Introduce expression conversion logic
chiranSachintha Jun 11, 2023
3b8ca3e
Disabled tests
chiranSachintha Jun 11, 2023
0be3bf2
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Jun 12, 2023
9eb2305
Merge branch 'master' of https://github.com/ballerina-platform/baller…
chiranSachintha Jun 13, 2023
50525a6
Resolve conflicts
chiranSachintha Jun 13, 2023
be96367
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Jun 15, 2023
eb6e998
Fix merge conflicts
HindujaB Jun 15, 2023
8d1fa2b
Fix failing tests
HindujaB Jun 16, 2023
0a46de6
Fix conflicts
HindujaB Jun 19, 2023
8b875e6
Fix field name retrieval
HindujaB Jun 19, 2023
3abc989
Update closure variable logic
chiranSachintha Jun 19, 2023
163b2b2
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Jun 19, 2023
edcc0d9
Fix merge conflicts
HindujaB Jun 19, 2023
e1a6aee
Add constant default value optimization
HindujaB Jun 20, 2023
70c3201
Fix checkstyle errors
HindujaB Jun 20, 2023
cc32f98
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Jun 28, 2023
fb9f549
Add unit test with multiple type inclusions
chiranSachintha Jun 29, 2023
f73dd37
Merge branch 'master' of https://github.com/ballerina-platform/baller…
chiranSachintha Jun 29, 2023
b1ac6ba
Fix large method errors
HindujaB Jun 29, 2023
0b96de6
Fix cli test error
HindujaB Jun 29, 2023
cf0d697
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Jun 29, 2023
e6fe74a
Fix spotbugs-exclude.xml
HindujaB Jun 29, 2023
0de4a3e
Fix checkStyle error
HindujaB Jun 30, 2023
5ea7497
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Jun 30, 2023
8151a30
Fix bir-spec tests
HindujaB Jun 30, 2023
c231496
Fix failing integration tests
HindujaB Jul 4, 2023
c50d918
Fix cloneWithType records
HindujaB Jul 4, 2023
44866f2
Fix test record creation
HindujaB Jul 4, 2023
a87d897
Fix merge conflicts
HindujaB Jul 10, 2023
8459084
Fix failing value creator tests
HindujaB Jul 12, 2023
a3512f9
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Jul 12, 2023
93097ab
Fix checkstyle error
HindujaB Jul 12, 2023
d05c1ba
Fix non-strand value creation
HindujaB Jul 13, 2023
a6d8cc8
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Jul 13, 2023
cc7604a
Fix debugger tests
HindujaB Jul 14, 2023
40dd8de
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Jul 14, 2023
caaea07
Fix checkstyle error
HindujaB Jul 14, 2023
1cb5486
Fix large method optimizer bug
HindujaB Jul 18, 2023
840b522
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Jul 18, 2023
1705512
Improve large method optimizer bug fix
HindujaB Jul 19, 2023
8a9deac
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Jul 19, 2023
5d23185
Fix checkStyle errors
HindujaB Jul 19, 2023
c2d110f
Move rhs operand map
HindujaB Jul 20, 2023
e3da81b
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Jul 21, 2023
d43775c
Fix type inclusion record creation
HindujaB Jul 26, 2023
069d838
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Jul 26, 2023
7a3c838
Fix typecast variable creation at record optimizer
HindujaB Jul 28, 2023
8fae5d4
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Jul 28, 2023
91bdac5
Fix review suggestions
chiranSachintha Aug 1, 2023
235bc14
Add unit tests
chiranSachintha Aug 1, 2023
bc0eeda
Merge branch 'master' of https://github.com/ballerina-platform/baller…
chiranSachintha Aug 1, 2023
1ba04a5
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Aug 2, 2023
9724bad
Fix merge conflicts
HindujaB Aug 2, 2023
195ea05
Fix test failures
HindujaB Aug 2, 2023
3de00a1
Define closures within the scope
chiranSachintha Aug 3, 2023
b51cb71
Define closures within the scope
chiranSachintha Aug 3, 2023
32e14f7
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Aug 4, 2023
70023ff
Fix testerina test
HindujaB Aug 4, 2023
f8f8b50
Merge branch 'closures-for-record-default-values' of github.com:Hindu…
HindujaB Aug 4, 2023
086f91b
Fix default value creation on separate thread
HindujaB Aug 7, 2023
0f0b6fd
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Aug 7, 2023
b4e1354
Revert "Disabled tests"
HindujaB Aug 7, 2023
77c1fb2
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Aug 9, 2023
b0ca0e9
Simplify record value optimizer logic
HindujaB Aug 9, 2023
edf5438
Utilize closures for setting initial values from defaultEntries
chiranSachintha Aug 10, 2023
52a832c
Update unit tests
chiranSachintha Aug 10, 2023
b71bf1e
Add newline
chiranSachintha Aug 10, 2023
e15f521
Remove new BIR instruction
HindujaB Aug 10, 2023
fdc449a
Merge branch 'closures-for-record-default-values' of github.com:Hindu…
HindujaB Aug 10, 2023
a14efb3
Improve MapValue logic
HindujaB Aug 10, 2023
12c822a
Fix merge conflicts
HindujaB Aug 10, 2023
bddee51
Fix issue with intersection of readonly and record type
chiranSachintha Aug 10, 2023
60ef611
Refactor logic
chiranSachintha Aug 10, 2023
bf72998
Merge branch 'master' of https://github.com/ballerina-platform/baller…
chiranSachintha Aug 10, 2023
83818f4
Resolve conflicts
chiranSachintha Aug 10, 2023
6e6b919
Address review suggestions
HindujaB Aug 10, 2023
cac1ac2
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Aug 10, 2023
24933d2
Implement method to mark closure variables
chiranSachintha Aug 10, 2023
9aa5efe
Add unit tests
chiranSachintha Aug 11, 2023
b2e3053
Add bala test
chiranSachintha Aug 11, 2023
813d724
Merge branch 'master' of https://github.com/ballerina-platform/baller…
chiranSachintha Aug 11, 2023
6d92107
Fix bir-spec-test for fp_load
HindujaB Aug 11, 2023
d4b63c8
Fix merge conflicts
HindujaB Aug 11, 2023
2421eef
Merge branch 'closures-for-record-default-values' of https://github.c…
chiranSachintha Aug 14, 2023
6504e6b
Merge branch 'master' of https://github.com/ballerina-platform/baller…
chiranSachintha Aug 14, 2023
6be4a87
Fix checkstyle issue
chiranSachintha Aug 14, 2023
4644376
Resolve conflicts
chiranSachintha Aug 14, 2023
d9f7cce
Unescaped field names
chiranSachintha Aug 15, 2023
3d861fc
Create record value within default package using the record type
chiranSachintha Aug 15, 2023
f7d10e4
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Aug 15, 2023
0a87576
Move CLI option runtime-tests to unit tests
HindujaB Aug 15, 2023
198e9eb
Add unit tests
chiranSachintha Aug 15, 2023
c43c946
Refactor option tests
HindujaB Aug 15, 2023
6ec372b
Merge branch 'closures-for-record-default-values' of github.com:Hindu…
HindujaB Aug 15, 2023
07ac9ba
Fix BIROptimizerTest
HindujaB Aug 15, 2023
aa63945
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Aug 15, 2023
9c195d5
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Aug 16, 2023
42eeb59
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang
HindujaB Aug 16, 2023
bcd0d68
Fix compilation error
HindujaB Aug 16, 2023
f846176
Fix review suggestions
chiranSachintha Aug 16, 2023
4913e3f
Add visit() method
HindujaB Aug 16, 2023
01c17a5
Move addConversionExprIfRequired function from desugar to types class
chiranSachintha Aug 16, 2023
00a1775
Merge branch 'master' of https://github.com/ballerina-platform/baller…
chiranSachintha Aug 16, 2023
aa8d616
Address scope NPE errors
HindujaB Aug 16, 2023
8fcbdb5
Fix review suggestions
chiranSachintha Aug 16, 2023
3f3eb42
Remove unused imports
chiranSachintha Aug 16, 2023
ac6e380
Fix merge conflicts
HindujaB Aug 17, 2023
f43b31d
Merge branch 'closures-for-record-default-values' of github.com:Hindu…
HindujaB Aug 17, 2023
d898b84
Utilize mutable type for readonly record intersection check
chiranSachintha Aug 17, 2023
34bab03
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Aug 17, 2023
c6f1770
Fix LargeMap and LargeArray instructions
HindujaB Aug 17, 2023
933ffd0
Fix checkStyle error
HindujaB Aug 17, 2023
c6d2e6e
Fix issue with readonly record intersection check
chiranSachintha Aug 17, 2023
d8ff8a6
Merge branch 'closures-for-record-default-values' of https://github.c…
chiranSachintha Aug 17, 2023
db038b6
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Aug 17, 2023
1d2bf2d
Fix issue with query expressions
chiranSachintha Aug 18, 2023
c7edaa1
Merge branch 'closures-for-record-default-values' of https://github.c…
chiranSachintha Aug 18, 2023
b3ea341
Update visitor functions
chiranSachintha Aug 18, 2023
0906691
Merge branch 'closures-for-record-default-values' of https://github.c…
chiranSachintha Aug 18, 2023
76ce5c6
Merge branch 'closures-for-record-default-values' of https://github.c…
chiranSachintha Aug 18, 2023
d436c19
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Aug 18, 2023
ee94ff8
Fix large method errors
HindujaB Aug 18, 2023
23d0a4a
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Aug 18, 2023
4e3c3df
Fix issue with readonly intersection
chiranSachintha Aug 19, 2023
7a3116e
Refactor logic
chiranSachintha Aug 20, 2023
61b7455
Update logic related to intersection of record and readonly
chiranSachintha Aug 21, 2023
58f7d9a
Merge branch 'master' of https://github.com/ballerina-platform/baller…
chiranSachintha Aug 22, 2023
53dbec4
Resolve conflicts
chiranSachintha Aug 22, 2023
656a188
Add unit tests
chiranSachintha Aug 22, 2023
d64221c
Add unit tests
chiranSachintha Aug 22, 2023
3cdb618
Fix getReferredType() API usage
HindujaB Aug 22, 2023
00941a6
Merge branch 'closures-for-record-default-values' of github.com:Hindu…
HindujaB Aug 22, 2023
c0c3388
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Sep 1, 2023
6bb2afc
Remove line position for record type-def
HindujaB Aug 29, 2023
826069a
Fix code coverage,debugger tests
HindujaB Aug 31, 2023
cf626fc
Fix failing tests for default expressions
HindujaB Sep 1, 2023
2095a58
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Sep 5, 2023
660d144
Merge branch 'master' of https://github.com/ballerina-platform/baller…
chiranSachintha Sep 11, 2023
8d0072c
Fix debugger test failure
HindujaB Sep 12, 2023
fd09345
Fix defaultValue call order
HindujaB Sep 13, 2023
a0a078c
Add test for cloneWithType
HindujaB Sep 13, 2023
96d84c0
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Sep 13, 2023
212b8e9
Update logic relate to mark closure variables
chiranSachintha Sep 13, 2023
87879c7
Fix merge conflicts
HindujaB Sep 15, 2023
310039c
Merge branch 'closures-for-record-default-values' of github.com:Hindu…
HindujaB Sep 15, 2023
55a7de4
Fix merge conflicts
HindujaB Sep 20, 2023
10c4b14
Fix ValueConverter to support immutable cloning
HindujaB Sep 20, 2023
3dd32b4
Add readonly test
HindujaB Sep 20, 2023
4569a88
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Oct 9, 2023
9fd99eb
Address review suggestions
HindujaB Oct 9, 2023
bf81d85
Fix compilation issue
HindujaB Oct 9, 2023
be905fa
Fix checkStyle issue
HindujaB Oct 9, 2023
1b67ab9
Add scope to new constantLoad instruction
HindujaB Oct 10, 2023
1f02427
Remove anon prefix check
HindujaB Oct 10, 2023
550ceb4
Fix checkstyle error
HindujaB Oct 10, 2023
0d2d79a
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Oct 12, 2023
e191c63
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Oct 19, 2023
a78613b
Uncomment commented large package tests
HindujaB Oct 19, 2023
fe690c0
Move record tests to main function
HindujaB Oct 19, 2023
0288375
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Oct 19, 2023
b2943a4
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Oct 25, 2023
5466b6f
Remove runtime constants usage
HindujaB Oct 25, 2023
c912ed5
Address suggestions
HindujaB Oct 25, 2023
426cac9
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Oct 26, 2023
c4c2054
Fix checkstyle error
HindujaB Oct 26, 2023
6f835e9
Update `capturedClosureEnv` to reference 'env' directly without cloning
chiranSachintha Oct 26, 2023
4d70988
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Oct 30, 2023
2a38df3
Merge branch 'closures-for-record-default-values' of github.com:Hindu…
HindujaB Oct 30, 2023
4a50986
Add unit tests
chiranSachintha Nov 1, 2023
e4d495a
Fix review suggestions
chiranSachintha Nov 1, 2023
d3da6ad
Move record default to separate instruction
HindujaB Nov 1, 2023
e3680fc
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Nov 1, 2023
e099065
Merge branch 'closures-for-record-default-values' of github.com:Hindu…
HindujaB Nov 1, 2023
ce56e63
Fix checkstyle error
HindujaB Nov 1, 2023
b295ff7
Fix merge conflicts
HindujaB Nov 16, 2023
1d9651c
Fix checkstyle error
HindujaB Nov 16, 2023
0c2ff07
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
HindujaB Nov 20, 2023
5bdcf45
Fix merge conflicts
HindujaB Nov 21, 2023
eeedf3f
Fix checkstyle error
HindujaB Nov 21, 2023
fd187f5
Fix merge conflicts
HindujaB Nov 23, 2023
f481535
Add javadoc comment
HindujaB Nov 23, 2023
b5d8788
Fix checkstyle error
HindujaB Nov 23, 2023
459db87
Merge branch 'master' of https://github.com/ballerina-platform/baller…
chiranSachintha Nov 24, 2023
f0dcb27
Update bir version numbers
chiranSachintha Nov 24, 2023
263578c
Fix review suggestions
chiranSachintha Nov 24, 2023
96ac2d3
Fix checkstyle error
chiranSachintha Nov 24, 2023
8b352da
Add comment
chiranSachintha Nov 24, 2023
42c4311
Merge branch 'master' of https://github.com/ballerina-platform/baller…
chiranSachintha Dec 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class RuntimeConstants {
public static final String UNDERSCORE = "_";
public static final String COLON = ":";
public static final char DOLLAR = '$';
warunalakshitha marked this conversation as resolved.
Show resolved Hide resolved

public static final String RECORD_DELIMITER = DOLLAR + "rec" + DOLLAR;
public static final String BLANG_SRC_FILE_EXT = "bal";
public static final String BLANG_SRC_FILE_SUFFIX = "." + BLANG_SRC_FILE_EXT;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.ballerina.runtime.api.types.AnydataType;
import io.ballerina.runtime.api.types.ArrayType;
import io.ballerina.runtime.api.types.Field;
import io.ballerina.runtime.api.types.IntersectionType;
import io.ballerina.runtime.api.types.MapType;
import io.ballerina.runtime.api.types.RecordType;
import io.ballerina.runtime.api.types.TableType;
Expand All @@ -45,9 +46,12 @@
import io.ballerina.runtime.internal.errors.ErrorHelper;
import io.ballerina.runtime.internal.errors.ErrorReasons;
import io.ballerina.runtime.internal.regexp.RegExpFactory;
import io.ballerina.runtime.internal.types.BIntersectionType;
import io.ballerina.runtime.internal.types.BRecordType;
import io.ballerina.runtime.internal.values.ArrayValue;
import io.ballerina.runtime.internal.values.ArrayValueImpl;
import io.ballerina.runtime.internal.values.MapValueImpl;
import io.ballerina.runtime.internal.values.ReadOnlyUtils;
import io.ballerina.runtime.internal.values.TableValueImpl;
import io.ballerina.runtime.internal.values.TupleValueImpl;

Expand All @@ -56,6 +60,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import static io.ballerina.runtime.api.creators.ErrorCreator.createError;
Expand Down Expand Up @@ -209,6 +214,12 @@ private static BMap<BString, Object> convertToRecord(BMap<?, ?> map, Set<TypeVal
Object newValue = convertRecordEntry(unresolvedValues, restFieldType, targetTypeField, entry);
valueMap.put(entry.getKey().toString(), newValue);
}
Optional<IntersectionType> intersectionType = ((BRecordType) TypeUtils.getImpliedType(recordRefType))
.getIntersectionType();
if (recordRefType.isReadOnly() && intersectionType.isPresent() && !map.getType().isReadOnly()) {
Type mutableType = ReadOnlyUtils.getMutableType((BIntersectionType) intersectionType.get());
return ValueCreator.createReadonlyRecordValue(mutableType.getPackage(), mutableType.getName(), valueMap);
}
return ValueCreator.createRecordValue(recordRefType.getPackage(), recordRefType.getName(), valueMap);
}

Expand Down Expand Up @@ -262,15 +273,28 @@ private static Object convertArray(BArray array, Type targetType, Type targetRef
private static Object convertTable(BTable<?, ?> bTable, Type targetType,
Type targetRefType, Set<TypeValuePair> unresolvedValues) {
TableType tableType = (TableType) targetType;
Optional<IntersectionType> intersectionType = tableType.getIntersectionType();
if (targetRefType.isReadOnly() && intersectionType.isPresent() && !bTable.getType().isReadOnly()) {
tableType = (TableType) ReadOnlyUtils.getMutableType((BIntersectionType) intersectionType.get());
TableValueImpl<?, ?> tableValue = getTableValue(bTable, unresolvedValues, tableType, tableType);
tableValue.freezeDirect();
return tableValue;
}
return getTableValue(bTable, unresolvedValues, tableType, targetRefType);
}

private static TableValueImpl<?, ?> getTableValue(BTable<?, ?> bTable, Set<TypeValuePair> unresolvedValues,
TableType tableType, Type targetRefType) {
Object[] tableValues = new Object[bTable.size()];
int count = 0;
for (Object tableValue : bTable.values()) {
BMap<?, ?> bMap = (BMap<?, ?>) convert(tableValue, tableType.getConstrainedType(), unresolvedValues);
tableValues[count++] = bMap;
}
BArray data = ValueCreator.createArrayValue(tableValues,
TypeCreator.createArrayType(tableType.getConstrainedType()));
BArray data = ValueCreator.createArrayValue(tableValues, TypeCreator.createArrayType(
tableType.getConstrainedType()));
BArray fieldNames = StringUtils.fromStringArray(tableType.getFieldNames());
return new TableValueImpl(targetRefType, (ArrayValue) data, (ArrayValue) fieldNames);
return new TableValueImpl<>(targetRefType, (ArrayValue) data, (ArrayValue) fieldNames);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,44 @@
package io.ballerina.runtime.internal;

import io.ballerina.runtime.api.Module;
import io.ballerina.runtime.api.async.StrandMetadata;
import io.ballerina.runtime.api.creators.ErrorCreator;
import io.ballerina.runtime.api.creators.TypeCreator;
import io.ballerina.runtime.api.flags.SymbolFlags;
import io.ballerina.runtime.api.types.Field;
import io.ballerina.runtime.api.types.FunctionType;
import io.ballerina.runtime.api.types.Type;
import io.ballerina.runtime.api.utils.StringUtils;
import io.ballerina.runtime.api.utils.TypeUtils;
import io.ballerina.runtime.api.values.BError;
import io.ballerina.runtime.api.values.BFunctionPointer;
import io.ballerina.runtime.api.values.BMap;
import io.ballerina.runtime.api.values.BObject;
import io.ballerina.runtime.api.values.BString;
import io.ballerina.runtime.api.values.BTypedesc;
import io.ballerina.runtime.api.values.BValue;
import io.ballerina.runtime.api.values.BXml;
import io.ballerina.runtime.internal.scheduling.AsyncFunctionCallback;
import io.ballerina.runtime.internal.scheduling.Scheduler;
import io.ballerina.runtime.internal.scheduling.State;
import io.ballerina.runtime.internal.scheduling.Strand;
import io.ballerina.runtime.internal.types.BRecordType;
import io.ballerina.runtime.internal.values.FutureValue;
import io.ballerina.runtime.internal.values.MapValue;
import io.ballerina.runtime.internal.values.MapValueImpl;
import io.ballerina.runtime.internal.values.TypedescValueImpl;
import io.ballerina.runtime.internal.values.ValueCreator;

import java.io.PrintStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;

import static io.ballerina.runtime.api.values.BError.ERROR_PRINT_PREFIX;

/**
* Class @{@link ValueUtils} provides utils to create Ballerina Values.
Expand All @@ -49,6 +64,8 @@
*/
public class ValueUtils {

private static final PrintStream errStream = System.err;

/**
* Create a record value using the given package ID and record type name.
*
Expand All @@ -57,19 +74,139 @@
* @return value of the record.
*/
public static BMap<BString, Object> createRecordValue(Module packageId, String recordTypeName) {
return createRecordValue(packageId, recordTypeName, new HashSet<>());
}

public static BMap<BString, Object> createRecordValue(Module packageId, String recordTypeName,
Set<String> providedFields) {
ValueCreator valueCreator = ValueCreator.getValueCreator(ValueCreator.getLookupKey(packageId, false));
try {
return valueCreator.createRecordValue(recordTypeName);
return getPopulatedRecordValue(valueCreator, recordTypeName, providedFields);
} catch (BError e) {
// If record type definition not found, get it from test module.
String testLookupKey = ValueCreator.getLookupKey(packageId, true);
if (ValueCreator.containsValueCreator(testLookupKey)) {
return ValueCreator.getValueCreator(testLookupKey).createRecordValue(recordTypeName);
return getPopulatedRecordValue(ValueCreator.getValueCreator(testLookupKey), recordTypeName,

Check warning on line 89 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java#L89

Added line #L89 was not covered by tests
providedFields);
}
throw e;
}
}

private static BMap<BString, Object> getPopulatedRecordValue(ValueCreator valueCreator, String recordTypeName,
Set<String> providedFields) {
MapValue<BString, Object> recordValue = valueCreator.createRecordValue(recordTypeName);
BRecordType type = (BRecordType) TypeUtils.getImpliedType(recordValue.getType());
return populateDefaultValues(recordValue, type, providedFields);
}

public static BMap<BString, Object> populateDefaultValues(BMap<BString, Object> recordValue, BRecordType type,
Set<String> providedFields) {
Map<String, BFunctionPointer<Object, ?>> defaultValues = type.getDefaultValues();
if (defaultValues.isEmpty()) {
return recordValue;
}
defaultValues = getNonProvidedDefaultValues(defaultValues, providedFields);
Strand strand = Scheduler.getStrandNoException();
if (strand == null) {
try {
final CountDownLatch latch = new CountDownLatch(defaultValues.size());
populateInitialValuesWithNoStrand(recordValue, latch, defaultValues);
latch.await();
} catch (InterruptedException e) {
throw ErrorCreator.createError(
StringUtils.fromString("error occurred when populating default values"), e);
}

Check warning on line 119 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java#L113-L119

Added lines #L113 - L119 were not covered by tests
} else {
for (Map.Entry<String, BFunctionPointer<Object, ?>> field : defaultValues.entrySet()) {
recordValue.populateInitialValue(StringUtils.fromString(field.getKey()),
field.getValue().call(new Object[]{strand}));
}
}
return recordValue;
}

private static Map<String, BFunctionPointer<Object, ?>> getNonProvidedDefaultValues(
Map<String, BFunctionPointer<Object, ?>> defaultValues, Set<String> providedFields) {
Map<String, BFunctionPointer<Object, ?>> result = new HashMap<>();
for (Map.Entry<String, BFunctionPointer<Object, ?>> entry : defaultValues.entrySet()) {
if (!providedFields.contains(entry.getKey())) {
result.put(entry.getKey(), entry.getValue());
}
}
return result;
}

private static void populateInitialValuesWithNoStrand(BMap<BString, Object> recordValue, CountDownLatch latch,
Map<String, BFunctionPointer<Object, ?>> defaultValues) {
String[] fields = defaultValues.keySet().toArray(new String[0]);
invokeFPAsyncIterativelyWithNoStrand(recordValue, defaultValues, fields, "default",
Scheduler.getDaemonStrand().getMetadata(), defaultValues.size(), o -> {
}, Scheduler.getDaemonStrand().scheduler, latch);
}

Check warning on line 146 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java#L142-L146

Added lines #L142 - L146 were not covered by tests

public static void invokeFPAsyncIterativelyWithNoStrand(BMap<BString, Object> recordValue,
Map<String, BFunctionPointer<Object, ?>> defaultValues,
String[] fields, String strandName, StrandMetadata metadata,
int noOfIterations, Consumer<Object> futureResultConsumer,
Scheduler scheduler, CountDownLatch latch) {
if (noOfIterations <= 0) {
return;

Check warning on line 154 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java#L154

Added line #L154 was not covered by tests
}
AtomicInteger callCount = new AtomicInteger(0);
scheduleNextFunction(recordValue, defaultValues, fields, strandName, metadata, noOfIterations, callCount,

Check warning on line 157 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java#L156-L157

Added lines #L156 - L157 were not covered by tests
HindujaB marked this conversation as resolved.
Show resolved Hide resolved
futureResultConsumer, scheduler, latch);
}

Check warning on line 159 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java#L159

Added line #L159 was not covered by tests

private static void scheduleNextFunction(BMap<BString, Object> recordValue,
Map<String, BFunctionPointer<Object, ?>> defaultValues, String[] fields,
String strandName, StrandMetadata metadata, int noOfIterations,
AtomicInteger callCount, Consumer<Object> futureResultConsumer,
HindujaB marked this conversation as resolved.
Show resolved Hide resolved
Scheduler scheduler, CountDownLatch latch) {
BFunctionPointer<?, ?> func = defaultValues.get(fields[callCount.get()]);
Type retType = ((FunctionType) TypeUtils.getImpliedType(func.getType())).getReturnType();
FutureValue future = scheduler.createFuture(null, null, null, retType, strandName, metadata);
AsyncFunctionCallback callback = new AsyncFunctionCallback(null) {

Check warning on line 169 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java#L166-L169

Added lines #L166 - L169 were not covered by tests
@Override
public void notifySuccess(Object result) {
futureResultConsumer.accept(getFutureResult());
recordValue.populateInitialValue(StringUtils.fromString(fields[callCount.get()]), result);
int i = callCount.incrementAndGet();
latch.countDown();

Check warning on line 175 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java#L172-L175

Added lines #L172 - L175 were not covered by tests
if (i != noOfIterations) {
scheduleNextFunction(recordValue, defaultValues, fields, strandName, metadata, noOfIterations,

Check warning on line 177 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java#L177

Added line #L177 was not covered by tests
callCount, futureResultConsumer, scheduler, latch);
}
}

Check warning on line 180 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java#L180

Added line #L180 was not covered by tests

@Override
public void notifyFailure(BError error) {
errStream.println(ERROR_PRINT_PREFIX + error.getPrintableStackTrace());
}

Check warning on line 185 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java#L184-L185

Added lines #L184 - L185 were not covered by tests
};

invokeFunctionPointerAsync(func, retType, future, callback, scheduler, strandName, metadata);
}

Check warning on line 189 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java#L188-L189

Added lines #L188 - L189 were not covered by tests

private static void invokeFunctionPointerAsync(BFunctionPointer<?, ?> func, Type returnType, FutureValue future,
AsyncFunctionCallback callback, Scheduler scheduler,
String strandName, StrandMetadata metadata) {
future.callback = callback;
callback.setFuture(future);
AsyncFunctionCallback childCallback = new AsyncFunctionCallback(future.strand) {

Check warning on line 196 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java#L194-L196

Added lines #L194 - L196 were not covered by tests
@Override
public void notifySuccess(Object result) {
callback.notifySuccess(result);
}

Check warning on line 200 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java#L199-L200

Added lines #L199 - L200 were not covered by tests

@Override
public void notifyFailure(BError error) {
callback.notifyFailure(error);
}

Check warning on line 205 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java#L204-L205

Added lines #L204 - L205 were not covered by tests
};
scheduler.scheduleFunction(new Object[1], func, null, returnType, strandName, metadata, childCallback);
}

Check warning on line 208 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueUtils.java#L207-L208

Added lines #L207 - L208 were not covered by tests

/**
* Create a record value that populates record fields using the given package ID, record type name and a map of
* field names and associated values for the fields.
Expand All @@ -81,7 +218,7 @@
*/
public static BMap<BString, Object> createRecordValue(Module packageId, String recordTypeName,
Map<String, Object> valueMap) {
BMap<BString, Object> recordValue = createRecordValue(packageId, recordTypeName);
BMap<BString, Object> recordValue = createRecordValue(packageId, recordTypeName, valueMap.keySet());
for (Map.Entry<String, Object> fieldEntry : valueMap.entrySet()) {
Object val = fieldEntry.getValue();
// TODO: Remove the following String to BString conversion.
Expand All @@ -104,7 +241,11 @@
*/
public static BMap<BString, Object> createRecordValue(Module packageId, String recordTypeName,
BMap<BString, Object> valueMap) {
BMap<BString, Object> recordValue = createRecordValue(packageId, recordTypeName);
Set<String> keySet = new HashSet<>();
for (BString key : valueMap.getKeys()) {
keySet.add(key.getValue());
}
BMap<BString, Object> recordValue = createRecordValue(packageId, recordTypeName, keySet);
for (Map.Entry<BString, Object> fieldEntry : valueMap.entrySet()) {
recordValue.populateInitialValue(fieldEntry.getKey(), fieldEntry.getValue());
}
Expand Down Expand Up @@ -248,7 +389,7 @@
* @param inherentType Inherent type of the value
* @return typedesc with the suitable type
*/
public static BTypedesc getTypedescValue(Boolean readOnly, BValue value, TypedescValueImpl inherentType) {
public static BTypedesc getTypedescValue(boolean readOnly, BValue value, TypedescValueImpl inherentType) {
if (readOnly) {
TypedescValueImpl typedesc = (TypedescValueImpl) createSingletonTypedesc(value);
typedesc.annotations = inherentType.annotations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Object[] getMainArgs() {
mainArgs.add(optionLocation, recordVal);
} else {
RecordType type = TypeCreator.createRecordType("dummy", null, 1, new HashMap<>(), null, true, 6);
Option dummyOption = new Option(type, ValueCreator.createRecordValue(type));
Option dummyOption = new Option(type, 0);
dummyOption.parseRecord(args);
processOperands(dummyOption.getOperandArgs());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package io.ballerina.runtime.internal.cli;

import io.ballerina.runtime.api.Module;
import io.ballerina.runtime.api.TypeTags;
import io.ballerina.runtime.api.creators.ErrorCreator;
import io.ballerina.runtime.api.creators.ValueCreator;
Expand Down Expand Up @@ -46,7 +47,7 @@
private static final String NAMED_ARG_DELIMITER = "=";

private final RecordType recordType;
private final BMap<BString, Object> recordVal;
private BMap<BString, Object> recordVal;
private final List<String> operandArgs;
private final Set<BString> recordKeysFound;
private final int location;
Expand All @@ -55,23 +56,23 @@
private static final Pattern HEX_LITERAL = Pattern.compile("[-+]?0[xX][\\dA-Fa-f.pP\\-+]+");

public Option(Type recordType, int location) {
this((RecordType) getImpliedType(recordType),
ValueCreator.createRecordValue(recordType.getPackage(), recordType.getName()), location);
this((RecordType) getImpliedType(recordType), location);

Check warning on line 59 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/cli/Option.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/cli/Option.java#L59

Added line #L59 was not covered by tests
}

public Option(RecordType recordType, BMap<BString, Object> recordVal) {
this(recordType, recordVal, 0);
}

public Option(RecordType recordType, BMap<BString, Object> recordVal, int location) {
public Option(RecordType recordType, int location) {
this.recordType = recordType;
this.recordVal = recordVal;
operandArgs = new ArrayList<>();
recordKeysFound = new HashSet<>();
this.location = location;
}

public BMap<BString, Object> parseRecord(String[] args) {
Module packageId = recordType.getPackage();
if (packageId == null) {
this.recordVal = ValueCreator.createRecordValue(recordType);
} else {
this.recordVal = ValueCreator.createRecordValue(packageId, recordType.getName());

Check warning on line 74 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/cli/Option.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/cli/Option.java#L74

Added line #L74 was not covered by tests
}
int index = 0;
while (index < args.length) {
String arg = args[index++];
Expand Down
Loading
Loading