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

Implement runtime type checker on SemTypes #43279

Open
wants to merge 178 commits into
base: nutcracker
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
178 commits
Select commit Hold shift + click to select a range
fe4d108
Implement scaffolding
heshanpadmasiri May 7, 2024
6251533
Port never type
heshanpadmasiri May 9, 2024
f78bd54
Port nil type
heshanpadmasiri May 10, 2024
e0ba173
Port Decimal type
heshanpadmasiri May 10, 2024
dee3647
Port float type
heshanpadmasiri May 10, 2024
914aa5c
Refactor caches to use DATs
heshanpadmasiri May 10, 2024
a6946ee
Port int type
heshanpadmasiri May 12, 2024
965fc0f
Port Boolean type
heshanpadmasiri May 12, 2024
99a2027
Port String type
heshanpadmasiri May 12, 2024
c3ca7f4
Refactor SemType implementation
heshanpadmasiri May 14, 2024
388d5b4
Add doc comments
heshanpadmasiri May 27, 2024
550fcbc
Fix float equality
heshanpadmasiri May 29, 2024
3e5a47d
Refactor type tests
heshanpadmasiri May 28, 2024
4a1d4a3
Add runtime type tests provider
heshanpadmasiri May 28, 2024
de8b70b
Add more basic type tests
heshanpadmasiri May 29, 2024
b0ea088
Fix compile time type bugs
heshanpadmasiri May 29, 2024
865b63a
Refactor type resolvers
heshanpadmasiri Jun 3, 2024
d197c7f
Add runtime type tests provider
heshanpadmasiri May 28, 2024
7c20ff1
Make it possible to create cell type
heshanpadmasiri May 29, 2024
293ddab
Implement bdd operations
heshanpadmasiri May 30, 2024
b3f2d6d
Introduce cell delegate
heshanpadmasiri May 30, 2024
6994da4
Implement cell subtype
heshanpadmasiri May 30, 2024
1950eb5
Cache cell type creation
heshanpadmasiri Jun 3, 2024
99cc815
Use read write locks for atom table
heshanpadmasiri Jun 3, 2024
f79bf1c
Add JDoc comments to new classes
heshanpadmasiri Jun 3, 2024
1ca5853
Add minimum implementation to create list types
heshanpadmasiri Jun 4, 2024
e38b5db
Implemented list type projection
heshanpadmasiri Jun 4, 2024
19c430f
Implement list semtype
heshanpadmasiri Jun 5, 2024
5991bb9
Refactor list projection
heshanpadmasiri Jun 6, 2024
8f7d28e
Ennable list type tests
heshanpadmasiri Jun 4, 2024
be45d00
Make context thread safe
heshanpadmasiri Jun 7, 2024
829c589
Optimize TypeChecker:basicType
heshanpadmasiri Jun 7, 2024
146891b
Port list subtype improvements
heshanpadmasiri Jun 7, 2024
2a0db6d
Fix hash and equals for semtypes
heshanpadmasiri Jun 9, 2024
c257b76
Cache type check results
heshanpadmasiri Jun 10, 2024
11eca87
Reduce the cost of Objects.hash
heshanpadmasiri Jun 10, 2024
5370798
Reduce type check cache overhead
heshanpadmasiri Jun 10, 2024
9803e97
Implement MappingDefinition
heshanpadmasiri Jun 11, 2024
b76a6b8
Implement mapping subtype empty
heshanpadmasiri Jun 11, 2024
d5f541e
Enable semtype tests expect projections for mappings
heshanpadmasiri Jun 11, 2024
2b083d8
Fix illegal modification of mapping atomic type
heshanpadmasiri Jun 11, 2024
f44704f
Enable more tests
heshanpadmasiri Jun 11, 2024
1ea5a0d
Implement mapping type projection
heshanpadmasiri Jun 11, 2024
e7531be
Implement singleton types for BMaps
heshanpadmasiri Jun 12, 2024
9f93c7c
Fix cyclic recursive type problem
heshanpadmasiri Jun 12, 2024
d17e9f1
Fix never type not being set correctly for records
heshanpadmasiri Jun 13, 2024
ed549ef
Make type creation synchronized for definition based types
heshanpadmasiri Jun 16, 2024
28ef5b7
Extend mapping type projection to support getting cell type of field
heshanpadmasiri Jun 16, 2024
0b11b0f
Refactor type checker with "widenedType"
heshanpadmasiri Jun 16, 2024
1def5bd
Refactor shape calculation
heshanpadmasiri Jun 16, 2024
bbd5642
Type with shape for mappings
heshanpadmasiri Jun 16, 2024
7ce1b62
Use shape with lists
heshanpadmasiri Jun 16, 2024
3cd82d6
Fix type checker not using shape correctly
heshanpadmasiri Jun 16, 2024
2fb2983
Fixed optional fields not been handled correctly in shape
heshanpadmasiri Jun 16, 2024
5dd68f2
Fixed readonly values not being handled correctly
heshanpadmasiri Jun 16, 2024
22a1275
Fix synchronizing bug
heshanpadmasiri Jun 16, 2024
9bb161d
Implement caching for shape of map
heshanpadmasiri Jun 16, 2024
4afb210
Fix expected error message
heshanpadmasiri Jun 17, 2024
1a1279e
Refactor MappingAtomicType
heshanpadmasiri Jun 20, 2024
ff8e15f
Fix cyclic typing issue
heshanpadmasiri Jun 20, 2024
c79f1bc
Switch to non sparse array to represent SubTypeData
heshanpadmasiri Jun 22, 2024
1f3711a
Refact: introduce explicit empty class for TypeCheckCache
heshanpadmasiri Jun 24, 2024
cdab9f7
Implement function semtype
heshanpadmasiri Jul 17, 2024
7cc8cb6
Implement object semtype
heshanpadmasiri Jul 23, 2024
7adb3fc
Fix record shape
heshanpadmasiri Jul 28, 2024
794b552
Implement error semtype
heshanpadmasiri Jul 29, 2024
519e5ce
Fix unit tests
heshanpadmasiri Aug 2, 2024
e6ea5e6
Add workaround to value converter
heshanpadmasiri Aug 5, 2024
f923661
Use lazy containers to xml types in Builder
heshanpadmasiri Aug 4, 2024
e5fb35f
Use lazy suppliers for PredefinedEnv
heshanpadmasiri Aug 4, 2024
355ebc9
Rename Lazy containers to lazy suppliers
heshanpadmasiri Aug 4, 2024
3538323
Simplify context supplying
heshanpadmasiri Aug 4, 2024
95e1515
More lazy initialization in predefined env
heshanpadmasiri Aug 4, 2024
d9301b9
Get rid of unwanted private methods and rearrange the code
heshanpadmasiri Aug 4, 2024
ff36b2a
Impmlement handle semtype
heshanpadmasiri Aug 6, 2024
b601d2f
Cleanup BSemTypeWrapper
heshanpadmasiri Aug 6, 2024
0480057
Re-ennable type check cache
heshanpadmasiri Aug 6, 2024
c7543d9
Encapsulate access to all and some
heshanpadmasiri Aug 6, 2024
5fa7e07
Refactor the semtype class hierachy
heshanpadmasiri Aug 6, 2024
b678c1e
Move immutable semtype class to internals
heshanpadmasiri Aug 6, 2024
b777083
Make BTypes proper semtypes
heshanpadmasiri Aug 7, 2024
8c4607e
Patch unit tests with clashing type names
heshanpadmasiri Aug 7, 2024
92249d4
Implement future semtype
heshanpadmasiri Aug 7, 2024
c4d1297
Implement regex type
heshanpadmasiri Aug 7, 2024
554e819
Implement typedesc semtype
heshanpadmasiri Aug 9, 2024
5a9fa45
Implement table and stream types
heshanpadmasiri Aug 9, 2024
e50452f
Remove fallback type checker from type checking
heshanpadmasiri Aug 13, 2024
824e579
Implement isSimpleBasicType with SemTypes
heshanpadmasiri Aug 13, 2024
b3c464d
Implement isReferenceEqual with semtypes
heshanpadmasiri Aug 13, 2024
c98d01e
Re ennable type result caching
heshanpadmasiri Aug 13, 2024
c78b285
Implement value conversion
heshanpadmasiri Aug 13, 2024
d18e8b9
Remove fallback type checker
heshanpadmasiri Aug 13, 2024
0807969
Make semtype part of the top type
heshanpadmasiri Aug 13, 2024
ec25872
Refactor isSameType
heshanpadmasiri Aug 13, 2024
12abdbe
Optimize convertible type for int subtypes
heshanpadmasiri Aug 14, 2024
b9e2d77
Introduce SimpleBdd
heshanpadmasiri Aug 14, 2024
355526b
Move MutableSemTypeDependencyManager to internal
heshanpadmasiri Aug 14, 2024
aa4379c
Make any and readonly types immutable semtypes
heshanpadmasiri Aug 14, 2024
e5629e5
Lazy initialize inner BTypes
heshanpadmasiri Aug 14, 2024
30c867f
Cache cell atom creation
heshanpadmasiri Aug 14, 2024
e6698d7
Optimize mapping subtype check
heshanpadmasiri Aug 15, 2024
8910490
Use semtypes for valuesEquals
heshanpadmasiri Aug 15, 2024
7a693bf
Use semtypes for casting
heshanpadmasiri Aug 15, 2024
bdf91aa
Refact shapeOf to support inlining
heshanpadmasiri Aug 15, 2024
3940add
Refactor memoSubtypeIsEmpty to make it inline
heshanpadmasiri Aug 15, 2024
9161308
Fix thread safty issue in createSemType
heshanpadmasiri Aug 15, 2024
85982c1
Cache BType results as well
heshanpadmasiri Aug 15, 2024
a9be211
Only hold weak references in the mutable semtype dependency manager
heshanpadmasiri Aug 15, 2024
f3160ad
Make all context memo tables weak hash maps
heshanpadmasiri Aug 16, 2024
b9ec8e9
Make atom table hold only weak references
heshanpadmasiri Aug 16, 2024
3678eb1
Cache repeated semtype creation
heshanpadmasiri Aug 16, 2024
af65f46
Introduce simplified cell subtype
heshanpadmasiri Aug 18, 2024
8448eef
Avoid caching cell semtypes for complex types
heshanpadmasiri Aug 18, 2024
d4d768c
Avoid unnecessarily checking for shape
heshanpadmasiri Aug 18, 2024
711bf85
Cache type check results for user defined types
heshanpadmasiri Aug 18, 2024
0f1b631
Cache runtime type creation
heshanpadmasiri Aug 18, 2024
4ff0e2f
Remove unwanted caching logic
heshanpadmasiri Aug 18, 2024
1f5141d
Cleanup access to context
heshanpadmasiri Aug 18, 2024
3787c49
Refactor anydata type creation
heshanpadmasiri Aug 18, 2024
b572b4c
Use a simple weak map for dependency manager
heshanpadmasiri Aug 19, 2024
904aa45
Introduce copy of write BMapType
heshanpadmasiri Aug 19, 2024
1bc0cfd
Simplify getType
heshanpadmasiri Aug 19, 2024
f06b552
Remove unwanted optimizations
heshanpadmasiri Aug 19, 2024
7dbb817
Fix result caching for futures
heshanpadmasiri Aug 19, 2024
e7856ba
Fix Union type not getting reset correctly
heshanpadmasiri Aug 19, 2024
fb30a7c
Reduce the overhead for calculating couldShapeBeDifferent
heshanpadmasiri Aug 20, 2024
48d3d9a
Be lazy about calculating the flags of tuple types
heshanpadmasiri Aug 20, 2024
06cd585
Be lazy when creating the semtype result cache
heshanpadmasiri Aug 20, 2024
6126610
Get rid of the stream when filtering nulls
heshanpadmasiri Aug 20, 2024
2fa358e
Use concurrent lazy suppliers for BSemTypeWrappers
heshanpadmasiri Aug 21, 2024
ed5fc41
Reduce contention in dependency manager
heshanpadmasiri Aug 21, 2024
4e527a3
Fix runtime semtype resolver
heshanpadmasiri Aug 23, 2024
7f976b3
Fix BFunction Equal
heshanpadmasiri Aug 23, 2024
5c7b4c4
Add workarounds to make libraries compile
heshanpadmasiri Aug 23, 2024
8fc2f5c
Better caching of the type creator
heshanpadmasiri Aug 25, 2024
6524324
Make shape calculation thread safe
heshanpadmasiri Aug 25, 2024
b000727
Add workaround to handle cyclic shapes
heshanpadmasiri Aug 25, 2024
70fa9a5
Add default implementations to make TestUtils work
heshanpadmasiri Aug 25, 2024
041aa1d
Fix type casts in Intersection type
heshanpadmasiri Aug 25, 2024
74ce571
Fix error equals
heshanpadmasiri Aug 25, 2024
2d8324b
Add workaround to make SQL work
heshanpadmasiri Aug 26, 2024
e21c4d0
Patch runtime resolver to handle dependtly typed func
heshanpadmasiri Aug 26, 2024
3b2e601
Fix runtime test errors
heshanpadmasiri Aug 26, 2024
79fb814
Change synchronization of atom table
heshanpadmasiri Aug 28, 2024
6bf8f5c
Remove BasicTypeBitSet
heshanpadmasiri Aug 31, 2024
9db0a51
Restructure semtype structure
heshanpadmasiri Aug 31, 2024
1be568a
Make tag directly accesible
heshanpadmasiri Sep 1, 2024
d6162ea
Avoid creating BType when trying to calculate hash and equal for wrapper
heshanpadmasiri Sep 1, 2024
aa97891
Use result caching with all semtypes
heshanpadmasiri Sep 1, 2024
fcdc9ec
Add fast path to hasFillerValue
heshanpadmasiri Sep 2, 2024
d3f5262
Refactor workarounds to isSubType
heshanpadmasiri Sep 2, 2024
e5d32aa
Remove MutableSemTypeDependencyManager
heshanpadmasiri Sep 2, 2024
8416880
Get rid of BType basic type
heshanpadmasiri Sep 3, 2024
f8ffbfc
Refactor shape anlayzer
heshanpadmasiri Sep 3, 2024
6e546b4
Avoid creating the inner BType with BSemTypeWrapper when possible
heshanpadmasiri Sep 3, 2024
528545d
Fix failing windows errors
heshanpadmasiri Sep 3, 2024
846f34d
Fix string shape calculation
heshanpadmasiri Sep 4, 2024
f02292d
Avoid result caching for basic types
heshanpadmasiri Sep 4, 2024
98eb2b2
Avoid unnecessarily calculating inherent type
heshanpadmasiri Sep 4, 2024
0ebdd73
Avoid unnecessarily creating singleton types
heshanpadmasiri Sep 6, 2024
e2e04d2
Refactor atoms
heshanpadmasiri Sep 8, 2024
a78802c
Refactor shape calculation
heshanpadmasiri Sep 6, 2024
716c1d7
Get rid of unwanted sychronizations
heshanpadmasiri Sep 8, 2024
a36335f
Move BddMemo to inner
heshanpadmasiri Sep 11, 2024
d40c858
Use accepted type for is likeShape
heshanpadmasiri Sep 15, 2024
e16eda7
Introduce wrapper for bddEvery
heshanpadmasiri Sep 18, 2024
ddd17a8
Move mutable semtype to inner
heshanpadmasiri Sep 18, 2024
c97b52c
Refactor method names
heshanpadmasiri Sep 29, 2024
816e9b4
Use holder classes to avoid initialization costs in TypeChecker
heshanpadmasiri Sep 29, 2024
5a76fb0
Fix invalid accepted type for union and tables
heshanpadmasiri Oct 1, 2024
8f70ddf
Refactor type check caching
heshanpadmasiri Oct 3, 2024
dca84d0
Make cache sharable between type descriptors
heshanpadmasiri Oct 4, 2024
019797b
Avoid necessary caching in TypeCreator
heshanpadmasiri Oct 4, 2024
297e74e
Avoid duplicate record type creation
heshanpadmasiri Oct 6, 2024
42d6320
Fix narrow type getting cached invalidly
heshanpadmasiri Oct 8, 2024
7fbf7f4
Fix tests with duplicate type definitions
heshanpadmasiri Oct 9, 2024
c6cfef7
Fix comments and naming
heshanpadmasiri Oct 11, 2024
5dfc0a4
Fix Dependently typed functions
heshanpadmasiri Oct 13, 2024
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
@@ -1,15 +1,15 @@
[
{
"description": "Define types.",
"code": "type Person record { string name; int age; }; type Employee record { string name; int age; int empNo; }; type Department record { string code; };"
"code": "type PersonOP record { string name; int age; }; type EmployeeOP record { string name; int age; int empNo; }; type DepartmentOP record { string code; };"
},
{
"description": "Define employee.",
"code": "Employee employee = {name: \"Jane Doe\", age: 25, empNo: 1};"
"code": "EmployeeOP employee = {name: \"Jane Doe\", age: 25, empNo: 1};"
},
{
"description": "Cas employee to person.",
"code": "Person person = <Person>employee;"
"code": "PersonOP person = <PersonOP>employee;"
},
{
"description": "Cas employee to person - get value.",
Expand All @@ -18,7 +18,7 @@
},
{
"description": "Recast back to employee.",
"code": "Employee employeeTwo = <Employee>person;"
"code": "EmployeeOP employeeTwo = <EmployeeOP>person;"
},
{
"description": "Recast back to employee - get value.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[
{
"description": "Define types.",
"code": "type Employee record { string name; int id; }; type Person record { string name; };"
"code": "type EmployeeEQ record { string name; int id; }; type PersonEQ record { string name; };"
},
{
"description": "Define employee.",
"code": "final Employee moduleEmployee = {name: \"John\", id: 2102};"
"code": "final EmployeeEQ moduleEmployee = {name: \"John\", id: 2102};"
},
{
"description": "Define module ref getter.",
"code": "function getModuleEmployee() returns Employee { return moduleEmployee; }"
"code": "function getModuleEmployee() returns EmployeeEQ { return moduleEmployee; }"
},
{
"description": "Equality ==.",
Expand Down Expand Up @@ -49,7 +49,7 @@
},
{
"description": "Deep inequality in records.",
"code": "Employee e1 = {name: \"Jane\", id: 1100}; Employee e2 = {name: \"Jane\", id: 1100};"
"code": "EmployeeEQ e1 = {name: \"Jane\", id: 1100}; EmployeeEQ e2 = {name: \"Jane\", id: 1100};"
},
{
"description": "Deep inequality in records. - get value",
Expand All @@ -58,7 +58,7 @@
},
{
"description": "Deep equality in records.",
"code": "Employee e3 = {name: \"Anne\", id: 1100};"
"code": "EmployeeEQ e3 = {name: \"Anne\", id: 1100};"
},
{
"description": "Deep equality in records. - get value",
Expand All @@ -67,7 +67,7 @@
},
{
"description": "Reference equality ===.",
"code": "Employee e4 = getModuleEmployee(); Person e5 = getModuleEmployee();"
"code": "EmployeeEQ e4 = getModuleEmployee(); PersonEQ e5 = getModuleEmployee();"
},
{
"description": "Reference equality ===. - get value",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[
{
"description": "Define types.",
"code": "type Address record { string country; string state; string city; string street; }; type Person record { string name; int age; boolean married; float salary; Address address; };"
"code": "type AddressCloneTest record { string country; string state; string city; string street; }; type PersonCloneTest record { string name; int age; boolean married; float salary; AddressCloneTest address; };"
},
{
"description": "Define address.",
"code": "Address address = { country: \"USA\", state: \"NC\", city: \"Raleigh\", street: \"Daniels St\" };"
"code": "AddressCloneTest address = { country: \"USA\", state: \"NC\", city: \"Raleigh\", street: \"Daniels St\" };"
},
{
"description": "Define person.",
"code": "Person person = { name: \"Alex\", age: 24, married: false, salary: 8000.0, address: address };"
"code": "PersonCloneTest person = { name: \"Alex\", age: 24, married: false, salary: 8000.0, address: address };"
},
{
"description": "Clone operation.",
"code": "Person result = person.clone();"
"code": "PersonCloneTest result = person.clone();"
},
{
"description": "Check reference equality.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
[
{
"description": "Define Details.",
"code": "type Details record {| string name; int id; |};"
"code": "type DetailsImmutableTest record {| string name; int id; |};"
},
{
"description": "Define Student.",
"code": "type Student record {| int 'class; Details details; map<int> marks; |};"
"code": "type StudentImmutableTest record {| int 'class; DetailsImmutableTest details; map<int> marks; |};"
},
{
"description": "Define addEntryToMap.",
"code": "function addEntryToMap(map<string|int> m, string key, string|int value) { m[key] = value; }"
},
{
"description": "Define immutable Details",
"code": "Details & readonly immutableDetails = { name: \"May\", id: 112233 };"
"code": "DetailsImmutableTest & readonly immutableDetails = { name: \"May\", id: 112233 };"
},
{
"description": "Define immutable Student &",
"code": "Student & readonly student = { 'class: 12, details: immutableDetails, marks: { math: 80, physics: 85, chemistry: 75 } };"
"code": "StudentImmutableTest & readonly student = { 'class: 12, details: immutableDetails, marks: { math: 80, physics: 85, chemistry: 75 } };"
},
{
"description": "Readonly status of student.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
*/
public final class PredefinedTypes {

private static final Module EMPTY_MODULE = new Module(null, null, null);
public static final Module EMPTY_MODULE = new Module(null, null, null);

public static final IntegerType TYPE_INT = new BIntegerType(TypeConstants.INT_TNAME, EMPTY_MODULE);
public static final IntegerType TYPE_INT_SIGNED_8 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public final class RuntimeConstants {
// Empty value for string
public static final BString STRING_EMPTY_VALUE = StringUtils.fromString("");

public static final Long INT_MAX_VALUE = 9223372036854775807L;
public static final Long INT_MIN_VALUE = -9223372036854775807L - 1L;
public static final Integer BBYTE_MIN_VALUE = 0;
public static final Integer BBYTE_MAX_VALUE = 255;
public static final Integer SIGNED32_MAX_VALUE = 2147483647;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
* Class @{@link TypeCreator} provides APIs to create ballerina type instances.
Expand All @@ -58,6 +59,7 @@
*/
public final class TypeCreator {

private static final RecordTypeCache registeredRecordTypes = new RecordTypeCache();
/**
* Creates a new array type with given element type.
*
Expand Down Expand Up @@ -147,7 +149,7 @@ public static TupleType createTupleType(List<Type> typeList, Type restType, int
* @return the new tuple type
*/
public static TupleType createTupleType(List<Type> typeList, Type restType,
int typeFlags, boolean isCyclic, boolean readonly) {
int typeFlags, boolean isCyclic, boolean readonly) {
return new BTupleType(typeList, restType, typeFlags, isCyclic, readonly);
}

Expand All @@ -162,16 +164,16 @@ public static TupleType createTupleType(List<Type> typeList, Type restType,
* @return the new tuple type
*/
public static TupleType createTupleType(String name, Module pkg,
int typeFlags, boolean isCyclic, boolean readonly) {
int typeFlags, boolean isCyclic, boolean readonly) {
return new BTupleType(name, pkg, typeFlags, isCyclic, readonly);
}

/**
* Create a {@code MapType} which represents the map type.
*
* @param constraint constraint type which particular map is bound to.
* @return the new map type
*/
* Create a {@code MapType} which represents the map type.
*
* @param constraint constraint type which particular map is bound to.
* @return the new map type
*/
public static MapType createMapType(Type constraint) {
return new BMapType(constraint);
}
Expand Down Expand Up @@ -224,6 +226,10 @@ public static MapType createMapType(String typeName, Type constraint, Module mod
*/
public static RecordType createRecordType(String typeName, Module module, long flags, boolean sealed,
int typeFlags) {
BRecordType memo = registeredRecordType(typeName, module);
if (memo != null) {
return memo;
}
return new BRecordType(typeName, typeName, module, flags, sealed, typeFlags);
}

Expand All @@ -240,8 +246,11 @@ public static RecordType createRecordType(String typeName, Module module, long f
* @return the new record type
*/
public static RecordType createRecordType(String typeName, Module module, long flags, Map<String, Field> fields,
Type restFieldType,
boolean sealed, int typeFlags) {
Type restFieldType, boolean sealed, int typeFlags) {
BRecordType memo = registeredRecordType(typeName, module);
if (memo != null) {
return memo;
}
return new BRecordType(typeName, module, flags, fields, restFieldType, sealed, typeFlags);
}

Expand Down Expand Up @@ -520,4 +529,42 @@ public static FiniteType createFiniteType(String typeName, Set<Object> values, i

private TypeCreator() {
}

private static BRecordType registeredRecordType(String typeName, Module pkg) {
if (typeName == null || pkg == null) {
return null;
}
return registeredRecordTypes.get(new TypeIdentifier(typeName, pkg));
}

public static void registerRecordType(BRecordType recordType) {
String name = recordType.getName();
Module pkg = recordType.getPackage();
if (name == null || pkg == null) {
return;
}
TypeIdentifier typeIdentifier = new TypeIdentifier(name, pkg);
registeredRecordTypes.put(typeIdentifier, recordType);
}

private static final class RecordTypeCache {

private static final Map<TypeIdentifier, BRecordType> cache = new ConcurrentHashMap<>();

BRecordType get(TypeIdentifier key) {
return cache.get(key);
}

void put(TypeIdentifier identifier, BRecordType value) {
cache.put(identifier, value);
}
}

public record TypeIdentifier(String typeName, Module pkg) {

public TypeIdentifier {
assert typeName != null;
assert pkg != null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package io.ballerina.runtime.api.types.semtype;

/**
* Represent the BDD atom.
*
* @since 2201.11.0
*/
public sealed interface Atom permits RecAtom, TypeAtom {

/**
* Get the index of the atom. For {@code TypeAtoms} this is a unique index within the {@code Env}. Each
* {@code RecAtom} that points to the same {@code TypeAtom} will have the same index.
*
* @return index of the atom
*/
int index();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package io.ballerina.runtime.api.types.semtype;

import io.ballerina.runtime.internal.types.semtype.CellAtomicType;
import io.ballerina.runtime.internal.types.semtype.FunctionAtomicType;
import io.ballerina.runtime.internal.types.semtype.ListAtomicType;
import io.ballerina.runtime.internal.types.semtype.MappingAtomicType;

/**
* Marker type representing AtomicType.
*
* @since 2201.11.0
*/
public sealed interface AtomicType permits CellAtomicType, FunctionAtomicType, ListAtomicType, MappingAtomicType {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.ballerina.runtime.api.types.semtype;

abstract sealed class BasicTypeBitSet permits SemType {

private int all;

protected BasicTypeBitSet(int all) {
this.all = all;
}

protected void setAll(int all) {
this.all = all;
}

public final int all() {
assert all != -1 : "SemType created by no arg constructor must be initialized with setAll";
return all;
}
}
Loading
Loading