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

Introduce support for isolated objects #26357

Merged
merged 24 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6c5b25c
Add the isolated flag for isolated objects
MaryamZi Oct 1, 2020
b42b70f
Add mutable field validation for isolated objects
MaryamZi Oct 2, 2020
f460bb6
Add initial value checks for isolated objects
MaryamZi Oct 5, 2020
949dd3d
Merge branch 'master' of https://github.com/ballerina-lang/ballerina …
MaryamZi Oct 7, 2020
21c2e7d
Add copy in/out analysis for isolated object methods
MaryamZi Oct 8, 2020
e97efa0
Validate invocation isolation in lock accessing mutable isolated obje…
MaryamZi Oct 9, 2020
7eaa536
Consider the isolated flag for subtyping
MaryamZi Oct 9, 2020
085bd15
Merge branch 'master' of https://github.com/ballerina-lang/ballerina …
MaryamZi Oct 9, 2020
3f0753b
Fix copy in/out analysis
MaryamZi Oct 12, 2020
4147158
Avoid logging not private errors for isolated object typedesc fields
MaryamZi Oct 13, 2020
38a644e
Infer isolatedness from expType only for object constructor exprs
MaryamZi Oct 13, 2020
6fbed4f
Fix isolation analysis for uniqueness and method calls on self
MaryamZi Oct 14, 2020
24d334f
Add initial set of negative tests
MaryamZi Oct 14, 2020
40f0935
Fix issues in copy in/out analysis for self
MaryamZi Oct 15, 2020
d2225dd
Add tests for invalid copy-in
MaryamZi Oct 15, 2020
f95afc5
Fix issues in copy in analysis and add negative tests
MaryamZi Oct 16, 2020
f8edfa8
Fix copy out analysis for return stmt and add more tests
MaryamZi Oct 17, 2020
cc71335
Add isolation negative test for object-constr with type inclusion
MaryamZi Oct 19, 2020
baf164c
Update isolated expression analysis
MaryamZi Oct 20, 2020
43b6e7a
Fix several deviations with the spec for isolated objects
MaryamZi Oct 20, 2020
2f6a725
Resolve conflicts and merge branch 'master' of https://github.com/bal…
MaryamZi Oct 20, 2020
83c8d51
Fix analysis for new-expr with stream
MaryamZi Oct 20, 2020
719ab8c
Merge branch 'master' of https://github.com/ballerina-lang/ballerina …
MaryamZi Oct 20, 2020
3cfdd23
Resolve conflicts and merge branch 'master' of https://github.com/bal…
MaryamZi Oct 21, 2020
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 @@ -1481,6 +1481,12 @@ private static boolean checkObjectEquivalency(Object sourceVal, Type sourceType,
unresolvedTypes.add(pair);

BObjectType sourceObjectType = (BObjectType) sourceType;

if (Flags.isFlagOn(targetType.flags, Flags.ISOLATED) &&
!Flags.isFlagOn(sourceObjectType.flags, Flags.ISOLATED)) {
return false;
}

Map<String, Field> targetFields = targetType.getFields();
Map<String, Field> sourceFields = sourceObjectType.getFields();
AttachedFunctionType[] targetFuncs = targetType.getAttachedFunctions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,18 @@ public enum DiagnosticCode {
INVALID_FORK_STATEMENT_IN_ISOLATED_FUNCTION("invalid.fork.statement.in.isolated.function"),
FUNCTION_CAN_BE_MARKED_ISOLATED("function.can.be.marked.isolated"),

INVALID_NON_PRIVATE_MUTABLE_FIELD_IN_ISOLATED_OBJECT("invalid.non.private.mutable.field.in.isolated.object"),
INVALID_MUTABLE_FIELD_ACCESS_IN_ISOLATED_OBJECT_OUTSIDE_LOCK(
"invalid.mutable.field.access.in.isolated.object.outside.lock"),
INVALID_REFERENCE_TO_SELF_IN_ISOLATED_OBJECT_OUTSIDE_LOCK(
"invalid.reference.to.self.in.isolated.object.outside.lock"),
INVALID_NON_UNIQUE_EXPRESSION_AS_INITIAL_VALUE_IN_ISOLATED_OBJECT(
"invalid.non.unique.expression.as.initial.value.in.isolated.object"),
INVALID_COPY_OUT_OF_MUTABLE_VALUE_FROM_ISOLATED_OBJECT("invalid.copy.out.of.mutable.value.from.isolated.object"),
INVALID_COPY_IN_OF_MUTABLE_VALUE_INTO_ISOLATED_OBJECT("invalid.copy.in.of.mutable.value.into.isolated.object"),
INVALID_NON_ISOLATED_INVOCATION_IN_ISOLATED_OBJECT_METHOD(
"invalid.non.isolated.invocation.in.isolated.object.method"),

COMPILER_PLUGIN_ERROR("compiler.plugin.crashed"),
;
private String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@
import java.util.Stack;
import java.util.regex.Matcher;

import static org.ballerinalang.model.elements.Flag.ISOLATED;
import static org.ballerinalang.model.elements.Flag.SERVICE;
import static org.wso2.ballerinalang.compiler.util.Constants.INFERRED_ARRAY_INDICATOR;
import static org.wso2.ballerinalang.compiler.util.Constants.OPEN_ARRAY_INDICATOR;
Expand Down Expand Up @@ -861,13 +862,23 @@ public BLangNode transform(ObjectTypeDescriptorNode objTypeDescNode) {
BLangObjectTypeNode objectTypeNode = (BLangObjectTypeNode) TreeBuilder.createObjectTypeNode();

for (Token qualifier : objTypeDescNode.objectTypeQualifiers()) {
if (qualifier.kind() == SyntaxKind.CLIENT_KEYWORD) {
SyntaxKind kind = qualifier.kind();
if (kind == SyntaxKind.CLIENT_KEYWORD) {
objectTypeNode.flagSet.add(Flag.CLIENT);
} else if (qualifier.kind() == SyntaxKind.SERVICE_KEYWORD) {
continue;
}

if (kind == SyntaxKind.SERVICE_KEYWORD) {
objectTypeNode.flagSet.add(SERVICE);
} else {
throw new RuntimeException("Syntax kind is not supported: " + qualifier.kind());
continue;
}

if (kind == SyntaxKind.ISOLATED_KEYWORD) {
objectTypeNode.flagSet.add(ISOLATED);
continue;
}

throw new RuntimeException("Syntax kind is not supported: " + kind);
}

NodeList<Node> members = objTypeDescNode.members();
Expand Down Expand Up @@ -3624,20 +3635,26 @@ public BLangNode transform(ClassDefinitionNode classDefinitionNode) {
});

for (Token qualifier : classDefinitionNode.classTypeQualifiers()) {
if (qualifier.kind() == SyntaxKind.DISTINCT_KEYWORD) {
blangClass.flagSet.add(Flag.DISTINCT);
}
SyntaxKind kind = qualifier.kind();

if (qualifier.kind() == SyntaxKind.CLIENT_KEYWORD) {
blangClass.flagSet.add(Flag.CLIENT);
}

if (qualifier.kind() == SyntaxKind.READONLY_KEYWORD) {
blangClass.flagSet.add(Flag.READONLY);
}

if (qualifier.kind() == SyntaxKind.SERVICE_KEYWORD) {
blangClass.flagSet.add(SERVICE);
switch (kind) {
case DISTINCT_KEYWORD:
blangClass.flagSet.add(Flag.DISTINCT);
break;
case CLIENT_KEYWORD:
blangClass.flagSet.add(Flag.CLIENT);
break;
case READONLY_KEYWORD:
blangClass.flagSet.add(Flag.READONLY);
break;
case SERVICE_KEYWORD:
blangClass.flagSet.add(Flag.SERVICE);
break;
case ISOLATED_KEYWORD:
blangClass.flagSet.add(Flag.ISOLATED);
break;
default:
throw new RuntimeException("Syntax kind is not supported: " + kind);
}
}

Expand Down
Loading