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 tagged datatype semtypes in runtime #43259

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
e53937a
Implement scaffolding
heshanpadmasiri May 7, 2024
6e5778a
Port never type
heshanpadmasiri May 9, 2024
4fba4b0
Port nil type
heshanpadmasiri May 10, 2024
1cb6259
Port Decimal type
heshanpadmasiri May 10, 2024
b95ab4f
Port float type
heshanpadmasiri May 10, 2024
d4c1b44
Refactor caches to use DATs
heshanpadmasiri May 10, 2024
322c805
Port int type
heshanpadmasiri May 12, 2024
2d9e692
Port Boolean type
heshanpadmasiri May 12, 2024
19ec3a4
Port String type
heshanpadmasiri May 12, 2024
24b3ca1
Refactor SemType implementation
heshanpadmasiri May 14, 2024
850f047
Add doc comments
heshanpadmasiri May 27, 2024
a502bd9
Fix float equality
heshanpadmasiri May 29, 2024
85ab8c5
Refactor type tests
heshanpadmasiri May 28, 2024
dac0565
Add runtime type tests provider
heshanpadmasiri May 28, 2024
0e38c60
Add more basic type tests
heshanpadmasiri May 29, 2024
0ab1450
Fix compile time type bugs
heshanpadmasiri May 29, 2024
19311f8
Refactor type resolvers
heshanpadmasiri Jun 3, 2024
56ca5a4
Add runtime type tests provider
heshanpadmasiri May 28, 2024
4594c96
Make it possible to create cell type
heshanpadmasiri May 29, 2024
0d3518c
Implement bdd operations
heshanpadmasiri May 30, 2024
8ca9f48
Introduce cell delegate
heshanpadmasiri May 30, 2024
6ebcc4e
Implement cell subtype
heshanpadmasiri May 30, 2024
7b8deb7
Cache cell type creation
heshanpadmasiri Jun 3, 2024
c46d083
Use read write locks for atom table
heshanpadmasiri Jun 3, 2024
cd50f8b
Add JDoc comments to new classes
heshanpadmasiri Jun 3, 2024
4cb96c0
Add minimum implementation to create list types
heshanpadmasiri Jun 4, 2024
d866aac
Implemented list type projection
heshanpadmasiri Jun 4, 2024
07b8079
Implement list semtype
heshanpadmasiri Jun 5, 2024
584c79d
Refactor list projection
heshanpadmasiri Jun 6, 2024
9e2ae77
Ennable list type tests
heshanpadmasiri Jun 4, 2024
587bbf3
Make context thread safe
heshanpadmasiri Jun 7, 2024
461e2b6
Optimize TypeChecker:basicType
heshanpadmasiri Jun 7, 2024
93768e9
Port list subtype improvements
heshanpadmasiri Jun 7, 2024
b9ec05d
Fix hash and equals for semtypes
heshanpadmasiri Jun 9, 2024
2085beb
Cache type check results
heshanpadmasiri Jun 10, 2024
80d6da7
Reduce the cost of Objects.hash
heshanpadmasiri Jun 10, 2024
768fef7
Reduce type check cache overhead
heshanpadmasiri Jun 10, 2024
92c64fe
Implement MappingDefinition
heshanpadmasiri Jun 11, 2024
1a9fe9a
Implement mapping subtype empty
heshanpadmasiri Jun 11, 2024
5170b04
Enable semtype tests expect projections for mappings
heshanpadmasiri Jun 11, 2024
2be64c3
Fix illegal modification of mapping atomic type
heshanpadmasiri Jun 11, 2024
3f69bf8
Enable more tests
heshanpadmasiri Jun 11, 2024
87574f6
Implement mapping type projection
heshanpadmasiri Jun 11, 2024
bb293a5
WIP: Make Mapping BTypes use semtypes
heshanpadmasiri Jun 12, 2024
1b61f3f
Implement singleton types for BMaps
heshanpadmasiri Jun 12, 2024
58b9c2d
Fix cyclic recursive type problem
heshanpadmasiri Jun 12, 2024
2a16329
Fix never type not being set correctly for records
heshanpadmasiri Jun 13, 2024
f7a7246
Fix initialization bug
heshanpadmasiri Jun 13, 2024
17b3576
WIP: add hack to make never? on the positive side work
heshanpadmasiri Jun 13, 2024
4d0bfe9
Make type creation synchronized for definition based types
heshanpadmasiri Jun 16, 2024
1387a84
Extend mapping type projection to support getting cell type of field
heshanpadmasiri Jun 16, 2024
115e65e
Refactor type checker with "widenedType"
heshanpadmasiri Jun 16, 2024
3c59a70
Refactor shape calculation
heshanpadmasiri Jun 16, 2024
4259e21
Type with shape for mappings
heshanpadmasiri Jun 16, 2024
eb11f91
Use shape with lists
heshanpadmasiri Jun 16, 2024
62a8de0
Fix type checker not using shape correctly
heshanpadmasiri Jun 16, 2024
3f770ca
Fixed optional fields not been handled correctly in shape
heshanpadmasiri Jun 16, 2024
ce17d24
Fixed readonly values not being handled correctly
heshanpadmasiri Jun 16, 2024
f53a1a2
Fix synchronizing bug
heshanpadmasiri Jun 16, 2024
da873cb
Implement caching for shape of map
heshanpadmasiri Jun 16, 2024
d144b1a
Fix expected error message
heshanpadmasiri Jun 17, 2024
0ef4fcd
Fix runtime type clash
heshanpadmasiri Jun 19, 2024
0b024c7
Refactor MappingAtomicType
heshanpadmasiri Jun 20, 2024
1465e55
Fix cyclic typing issue
heshanpadmasiri Jun 20, 2024
88ec0ef
Switch to non sparse array to represent SubTypeData
heshanpadmasiri Jun 22, 2024
4493b20
Refact: introduce explicit empty class for TypeCheckCache
heshanpadmasiri Jun 24, 2024
33176ef
Implement Function definition
heshanpadmasiri Jul 17, 2024
152ca7d
Use function semtype in runtime
heshanpadmasiri Jul 17, 2024
3066714
Fix isolation flag
heshanpadmasiri Jul 22, 2024
296c5f6
Port object type to runtime
heshanpadmasiri Jul 23, 2024
6fd3cb7
WIP: implement predefined Env
heshanpadmasiri Jul 26, 2024
f1a3ceb
WIP: implement lazy containers
heshanpadmasiri Jul 26, 2024
63326e1
Fix object readonly
heshanpadmasiri Jul 26, 2024
9414c67
Fix stack trace type
heshanpadmasiri Jul 26, 2024
3dbcb2e
WIP: Integrate object type
heshanpadmasiri Jul 26, 2024
fab7e33
Integrate object semtype
heshanpadmasiri Jul 28, 2024
a695855
Fix record shape
heshanpadmasiri Jul 28, 2024
980080a
Fix checkstyle violations
heshanpadmasiri Jul 29, 2024
2d89139
Port error semtype
heshanpadmasiri Jul 30, 2024
6b3f655
WIP: Integrate error type
heshanpadmasiri Jul 30, 2024
b5afc73
WIP: [BUG] implement shapeOf
heshanpadmasiri Jul 30, 2024
ec245aa
Fix error type distinct
heshanpadmasiri Jul 31, 2024
ff5257a
Fix intersection type
heshanpadmasiri Jul 31, 2024
445b55a
Fix checkstyle violations
heshanpadmasiri Jul 31, 2024
9686ae1
Port XML type
heshanpadmasiri Aug 1, 2024
a4181d4
Make constraint final
heshanpadmasiri Aug 1, 2024
f3a9fd8
Integrate XML type
heshanpadmasiri Aug 2, 2024
a8eb6d3
Fix unit tests
heshanpadmasiri Aug 2, 2024
b51340a
Add workaround to value converter
heshanpadmasiri Aug 5, 2024
e3faec1
Use lazy containers to xml types in Builder
heshanpadmasiri Aug 4, 2024
f2e92fc
Use lazy suppliers for PredefinedEnv
heshanpadmasiri Aug 4, 2024
c19c7f3
Rename Lazy containers to lazy suppliers
heshanpadmasiri Aug 4, 2024
6f9fe09
Simplify context supplying
heshanpadmasiri Aug 4, 2024
4a8d6f2
More lazy initialization in predefined env
heshanpadmasiri Aug 4, 2024
d4f665d
Get rid of unwanted private methods and rearrange the code
heshanpadmasiri Aug 4, 2024
45b6482
Impmlement handle semtype
heshanpadmasiri Aug 6, 2024
339655b
Cleanup BSemTypeWrapper
heshanpadmasiri Aug 6, 2024
7e6e80f
Re-ennable type check cache
heshanpadmasiri Aug 6, 2024
4fe206f
Fix checkstyle violations
heshanpadmasiri Aug 6, 2024
3b5186d
Encapsulate access to all and some
heshanpadmasiri Aug 6, 2024
7640f6f
Refactor the semtype class hierachy
heshanpadmasiri Aug 6, 2024
65ff9ee
Move immutable semtype class to internals
heshanpadmasiri Aug 6, 2024
b4245af
Make BTypes proper semtypes
heshanpadmasiri Aug 7, 2024
483af3e
Patch unit tests with clashing type names
heshanpadmasiri Aug 7, 2024
f52cea4
Port future type
heshanpadmasiri Aug 7, 2024
3b0a312
Integrate future type
heshanpadmasiri Aug 7, 2024
c8b290e
Add regex type code
heshanpadmasiri Aug 7, 2024
5f00c19
Implement regex type
heshanpadmasiri Aug 7, 2024
fbfa901
Implement regex shape
heshanpadmasiri Aug 7, 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
Expand Up @@ -89,7 +89,7 @@
*/
public 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 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 @@ -17,6 +17,8 @@
*/
package io.ballerina.runtime.api.types;

import io.ballerina.runtime.internal.types.semtype.FunctionQualifiers;

/**
* {@code FunctionType} represents a function type in ballerina.
*
Expand All @@ -39,4 +41,6 @@ public interface FunctionType extends AnnotatableType {
Type getRestType();

Parameter[] getParameters();

FunctionQualifiers getQualifiers();
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ public interface MethodType extends FunctionType {
* @return true if {@link MethodType} method is isolated otherwise false.
*/
boolean isIsolated();

String name();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.10.0
*/
public interface Atom {

int index();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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;

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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;

// SEMTYPE-TODO: revisit this after fully implementing semtypes. Added this to match nBallerina where this is just a
// type alias to int. Maybe not needed here due to the way we have modeled type hierarchy (need to check if doing
// instancof checks on this is faster than checking if some is 0)

/**
* Represents a union of basic types.
*
* @since 2201.10.0
*/
public interface BasicTypeBitSet {

default int some() {
return 0;
}

default SubType[] subTypeData() {
return new SubType[0];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* 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 bit field that indicate which basic type a semType belongs to.
*
* @since 2201.10.0
*/
public final class BasicTypeCode {

public static final int CODE_NIL = 0x00;
public static final int CODE_BOOLEAN = 0x01;
public static final int CODE_INT = 0x02;
public static final int CODE_FLOAT = 0x03;
public static final int CODE_DECIMAL = 0x04;
public static final int CODE_STRING = 0x05;
public static final int CODE_ERROR = 0x06;
public static final int CODE_TYPEDESC = 0x07;
public static final int CODE_HANDLE = 0x08;
public static final int CODE_FUNCTION = 0x09;
public static final int CODE_REGEXP = 0x0A;
public static final int CODE_FUTURE = 0x0B;
public static final int CODE_STREAM = 0x0C;
public static final int CODE_LIST = 0x0D;
public static final int CODE_MAPPING = 0x0E;
public static final int CODE_TABLE = 0x0F;
public static final int CODE_XML = 0x10;
public static final int CODE_OBJECT = 0x11;
public static final int CODE_CELL = 0x12;
public static final int CODE_UNDEF = 0x13;
public static final int CODE_B_TYPE = 0x14;

// TODO: see if we can turn this class to an enum with a value
// Inherently immutable
public static final BasicTypeCode BT_NIL = from(CODE_NIL);
public static final BasicTypeCode BT_BOOLEAN = from(CODE_BOOLEAN);
public static final BasicTypeCode BT_INT = from(CODE_INT);
public static final BasicTypeCode BT_FLOAT = from(CODE_FLOAT);
public static final BasicTypeCode BT_DECIMAL = from(CODE_DECIMAL);
public static final BasicTypeCode BT_STRING = from(CODE_STRING);
public static final BasicTypeCode BT_ERROR = from(CODE_ERROR);
public static final BasicTypeCode BT_TYPEDESC = from(CODE_TYPEDESC);
public static final BasicTypeCode BT_HANDLE = from(CODE_HANDLE);
public static final BasicTypeCode BT_FUNCTION = from(CODE_FUNCTION);
public static final BasicTypeCode BT_REGEXP = from(CODE_REGEXP);

// Inherently mutable
public static final BasicTypeCode BT_FUTURE = from(CODE_FUTURE);
public static final BasicTypeCode BT_STREAM = from(CODE_STREAM);

// Selectively immutable
public static final BasicTypeCode BT_LIST = from(CODE_LIST);
public static final BasicTypeCode BT_MAPPING = from(CODE_MAPPING);
public static final BasicTypeCode BT_TABLE = from(CODE_TABLE);
public static final BasicTypeCode BT_XML = from(CODE_XML);
public static final BasicTypeCode BT_OBJECT = from(CODE_OBJECT);

// Non-val
public static final BasicTypeCode BT_CELL = from(CODE_CELL);
public static final BasicTypeCode BT_UNDEF = from(CODE_UNDEF);
public static final BasicTypeCode BT_B_TYPE = from(CODE_B_TYPE);

// Helper bit fields (does not represent basic type tag)
static final int VT_COUNT = CODE_OBJECT + 1;
public static final int BASIC_TYPE_MASK = (1 << (CODE_STRING + 1)) - 1;
static final int VT_MASK = (1 << VT_COUNT) - 1;

static final int VT_COUNT_INHERENTLY_IMMUTABLE = CODE_FUTURE;
public static final int VT_INHERENTLY_IMMUTABLE = (1 << VT_COUNT_INHERENTLY_IMMUTABLE) - 1;

private int code;

private BasicTypeCode(int code) {
this.code = code;
}

public static BasicTypeCode from(int code) {
if (BasicTypeCodeCache.isCached(code)) {
return BasicTypeCodeCache.cache[code];
}
return new BasicTypeCode(code);
}

public int code() {
return code;
}

@Override
public int hashCode() {
return code;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof BasicTypeCode other) {
return code == other.code;
}
return false;
}

private static final class BasicTypeCodeCache {

private static final BasicTypeCode[] cache;
static {
cache = new BasicTypeCode[CODE_B_TYPE + 2];
for (int i = CODE_NIL; i < CODE_B_TYPE + 1; i++) {
cache[i] = new BasicTypeCode(i);
}
}

private static boolean isCached(int code) {
return 0 < code && code < VT_COUNT;
}

}
}
Loading
Loading