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 xml semtype in runtime #43225

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
58b3177
Implement scaffolding
heshanpadmasiri May 7, 2024
c5397fd
Port never type
heshanpadmasiri May 9, 2024
78a1953
Port nil type
heshanpadmasiri May 10, 2024
d59e17f
Port Decimal type
heshanpadmasiri May 10, 2024
ed71405
Port float type
heshanpadmasiri May 10, 2024
b5d6326
Refactor caches to use DATs
heshanpadmasiri May 10, 2024
7954de5
Port int type
heshanpadmasiri May 12, 2024
ac31fef
Port Boolean type
heshanpadmasiri May 12, 2024
09c5c94
Port String type
heshanpadmasiri May 12, 2024
1c16f6f
Refactor SemType implementation
heshanpadmasiri May 14, 2024
8d6a251
Add doc comments
heshanpadmasiri May 27, 2024
1f16d81
Fix float equality
heshanpadmasiri May 29, 2024
ee052f9
Refactor type tests
heshanpadmasiri May 28, 2024
0a73764
Add runtime type tests provider
heshanpadmasiri May 28, 2024
42b59ed
Add more basic type tests
heshanpadmasiri May 29, 2024
32f7c98
Fix compile time type bugs
heshanpadmasiri May 29, 2024
505006f
Refactor type resolvers
heshanpadmasiri Jun 3, 2024
be9b5c1
Add runtime type tests provider
heshanpadmasiri May 28, 2024
00e7160
Make it possible to create cell type
heshanpadmasiri May 29, 2024
9abce86
Implement bdd operations
heshanpadmasiri May 30, 2024
d0eaf68
Introduce cell delegate
heshanpadmasiri May 30, 2024
fbbe814
Implement cell subtype
heshanpadmasiri May 30, 2024
a912920
Cache cell type creation
heshanpadmasiri Jun 3, 2024
bfb6132
Use read write locks for atom table
heshanpadmasiri Jun 3, 2024
1cf21f4
Add JDoc comments to new classes
heshanpadmasiri Jun 3, 2024
38100fd
Add minimum implementation to create list types
heshanpadmasiri Jun 4, 2024
914a17a
Implemented list type projection
heshanpadmasiri Jun 4, 2024
5c19a12
Implement list semtype
heshanpadmasiri Jun 5, 2024
32ccb4a
Refactor list projection
heshanpadmasiri Jun 6, 2024
892fb59
Ennable list type tests
heshanpadmasiri Jun 4, 2024
ad5f250
Make context thread safe
heshanpadmasiri Jun 7, 2024
51c1bf2
Optimize TypeChecker:basicType
heshanpadmasiri Jun 7, 2024
c72fcb4
Port list subtype improvements
heshanpadmasiri Jun 7, 2024
3fdd5aa
Fix hash and equals for semtypes
heshanpadmasiri Jun 9, 2024
b85031e
Cache type check results
heshanpadmasiri Jun 10, 2024
17b3872
Reduce the cost of Objects.hash
heshanpadmasiri Jun 10, 2024
29c0fde
Reduce type check cache overhead
heshanpadmasiri Jun 10, 2024
7a03d08
Implement MappingDefinition
heshanpadmasiri Jun 11, 2024
78429ef
Implement mapping subtype empty
heshanpadmasiri Jun 11, 2024
a45d97e
Enable semtype tests expect projections for mappings
heshanpadmasiri Jun 11, 2024
8ac35eb
Fix illegal modification of mapping atomic type
heshanpadmasiri Jun 11, 2024
094679e
Enable more tests
heshanpadmasiri Jun 11, 2024
631c5a7
Implement mapping type projection
heshanpadmasiri Jun 11, 2024
99ea3a3
WIP: Make Mapping BTypes use semtypes
heshanpadmasiri Jun 12, 2024
0590827
Implement singleton types for BMaps
heshanpadmasiri Jun 12, 2024
4789a86
Fix cyclic recursive type problem
heshanpadmasiri Jun 12, 2024
cd4a805
Fix never type not being set correctly for records
heshanpadmasiri Jun 13, 2024
1f2d30a
Fix initialization bug
heshanpadmasiri Jun 13, 2024
d11f249
WIP: add hack to make never? on the positive side work
heshanpadmasiri Jun 13, 2024
4637498
Make type creation synchronized for definition based types
heshanpadmasiri Jun 16, 2024
ca59d70
Extend mapping type projection to support getting cell type of field
heshanpadmasiri Jun 16, 2024
e4f565d
Refactor type checker with "widenedType"
heshanpadmasiri Jun 16, 2024
acdd496
Refactor shape calculation
heshanpadmasiri Jun 16, 2024
e93fc87
Type with shape for mappings
heshanpadmasiri Jun 16, 2024
605a9dc
Use shape with lists
heshanpadmasiri Jun 16, 2024
58a59bc
Fix type checker not using shape correctly
heshanpadmasiri Jun 16, 2024
b3a3c34
Fixed optional fields not been handled correctly in shape
heshanpadmasiri Jun 16, 2024
2edcaf7
Fixed readonly values not being handled correctly
heshanpadmasiri Jun 16, 2024
cc9a6b6
Fix synchronizing bug
heshanpadmasiri Jun 16, 2024
3f34ecf
Implement caching for shape of map
heshanpadmasiri Jun 16, 2024
c676d37
Fix expected error message
heshanpadmasiri Jun 17, 2024
99bae05
Fix runtime type clash
heshanpadmasiri Jun 19, 2024
b6679a6
Refactor MappingAtomicType
heshanpadmasiri Jun 20, 2024
15eb7a5
Fix cyclic typing issue
heshanpadmasiri Jun 20, 2024
e09fea5
Switch to non sparse array to represent SubTypeData
heshanpadmasiri Jun 22, 2024
034d83e
Refact: introduce explicit empty class for TypeCheckCache
heshanpadmasiri Jun 24, 2024
758acff
Implement Function definition
heshanpadmasiri Jul 17, 2024
39cecd6
Use function semtype in runtime
heshanpadmasiri Jul 17, 2024
a3fe87e
Fix isolation flag
heshanpadmasiri Jul 22, 2024
9af2816
Port object type to runtime
heshanpadmasiri Jul 23, 2024
34ea451
WIP: implement predefined Env
heshanpadmasiri Jul 26, 2024
0d84358
WIP: implement lazy containers
heshanpadmasiri Jul 26, 2024
2ae686f
Fix object readonly
heshanpadmasiri Jul 26, 2024
0ed44b9
Fix stack trace type
heshanpadmasiri Jul 26, 2024
e0467f5
WIP: Integrate object type
heshanpadmasiri Jul 26, 2024
64ae1e3
Integrate object semtype
heshanpadmasiri Jul 28, 2024
c45fd0f
Fix record shape
heshanpadmasiri Jul 28, 2024
631b762
Fix checkstyle violations
heshanpadmasiri Jul 29, 2024
b4066e2
Port error semtype
heshanpadmasiri Jul 30, 2024
9f71ceb
WIP: Integrate error type
heshanpadmasiri Jul 30, 2024
3c99a44
WIP: [BUG] implement shapeOf
heshanpadmasiri Jul 30, 2024
de35941
Fix error type distinct
heshanpadmasiri Jul 31, 2024
fce9516
Fix intersection type
heshanpadmasiri Jul 31, 2024
e1b7e16
Fix checkstyle violations
heshanpadmasiri Jul 31, 2024
008c3ae
Port XML type
heshanpadmasiri Aug 1, 2024
602f486
Make constraint final
heshanpadmasiri Aug 1, 2024
dd780c0
Integrate XML type
heshanpadmasiri Aug 2, 2024
71472f6
Fix unit tests
heshanpadmasiri Aug 2, 2024
54944b5
Add workaround to value converter
heshanpadmasiri Aug 5, 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,134 @@
/*
* 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_FUTURE = 0x0A;
public static final int CODE_STREAM = 0x0B;
public static final int CODE_LIST = 0x0C;
public static final int CODE_MAPPING = 0x0D;
public static final int CODE_TABLE = 0x0E;
public static final int CODE_XML = 0x0F;
public static final int CODE_OBJECT = 0x10;
public static final int CODE_CELL = 0x11;
public static final int CODE_UNDEF = 0x12;
public static final int CODE_B_TYPE = 0x13;

// 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);

// 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;
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 = 0x0A;
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