ballerina-platform / ballerina-lang

The Ballerina Programming Language
https://ballerina.io/
Apache License 2.0
3.68k stars 752 forks source link

[Bug]: Transactional function can be isolated #40404

Open pcnfernando opened 1 year ago

pcnfernando commented 1 year ago

Description

import ballerina/io;

public function main() {
    io:println(isIsolated(foo)); // prints false
}

transactional isolated function foo() {
}

function isIsolated(any func) returns boolean {
    return func is isolated function;
}

Steps to Reproduce

No response

Affected Version(s)

2201.5.0

OS, DB, other environment details and versions

No response

Related area

-> Compilation

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

MaryamZi commented 1 year ago

This is because of transactional, right?

import ballerina/io;

public function main() {
    // isolated function a = foo; // compilation error

    any fn = foo;
    io:println(fn is isolated function); // 1 - false
    io:println(fn is isolated function ()); // 2 - false
    io:println(fn is isolated transactional function ()); // 3 - true

    fn = bar;
    io:println(fn is isolated function); // 4 - true
    io:println(fn is isolated function ()); // 5 - true
    io:println(fn is isolated transactional function ()); // 6 - true
}

transactional isolated function foo() {
}

isolated function bar() {
}

https://ballerina.io/spec/lang/master/#functions last paragraph

In addition to a readonly bit and an isolated bit, a function value also has a transactional bit. A function value with its transactional bit set can only be called in a transactional scope; this is enforced by the type system. A function value with its transactional bit not set belongs to the type described by a function-type-descriptor with a function-signature only if the function-type-descriptor does not include a transactional qualifier. This means that a function-type-descriptor with a function-signature but without a transactional qualifier is a subtype of the corresponding function-type-descriptor with a transactional qualifier. Note that the subtyping relationship for transactional is in the opposite direction from isolated. A function value's transactional bit does not affect whether it belongs to the type described by a function-type-descriptor without a function-signature.

I think everything except 1 is OK. Maybe 1 should be true according to the last sentence?

MaryamZi commented 1 year ago

I think everything except 1 is OK. Maybe 1 should be true according to the last sentence?

Unless the last sentence was specifically for is function, which is more consistent?

pcnfernando commented 1 year ago

Yes, the reasoning makes sense. Shall we request the spec to be more explicit on this?

MaryamZi commented 1 year ago

Yes, the reasoning makes sense. Shall we request the spec to be more explicit on this?

+1 to get it verified against the terms used in the spec.