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

Fix invalid isolated inference of resource functions which has start actions #41772

Conversation

LakshanWeerasinghe
Copy link
Contributor

@LakshanWeerasinghe LakshanWeerasinghe commented Nov 27, 2023

Purpose

Describe the problems, issues, or needs driving this feature/fix and include links to related issues.

Fixes #41691
Fixes #41766
Fixes #41818

Approach

Describe how you are implementing the solutions along with the design details.

Samples

Provide high-level details about the samples related to this feature.

Remarks

List any other known issues, related PRs, TODO items, or any other notes related to the PR.

Check List

  • Read the Contributing Guide
  • Updated Change Log
  • Checked Tooling Support (#)
  • Added necessary tests
    • Unit Tests
    • Spec Conformance Tests
    • Integration Tests
    • Ballerina By Example Tests
  • Increased Test Coverage
  • Added necessary documentation
    • API documentation
    • Module documentation in Module.md files
    • Ballerina By Examples

Copy link

codecov bot commented Nov 27, 2023

Codecov Report

Attention: Patch coverage is 93.54839% with 8 lines in your changes are missing coverage. Please review.

Project coverage is 76.70%. Comparing base (187079a) to head (d7e7729).
Report is 796 commits behind head on master.

Files Patch % Lines
...compiler/semantics/analyzer/IsolationAnalyzer.java 93.54% 1 Missing and 7 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #41772      +/-   ##
============================================
+ Coverage     76.68%   76.70%   +0.02%     
- Complexity    53066    53122      +56     
============================================
  Files          2882     2884       +2     
  Lines        200002   200247     +245     
  Branches      26040    26080      +40     
============================================
+ Hits         153362   153599     +237     
- Misses        38206    38214       +8     
  Partials       8434     8434              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@MaryamZi MaryamZi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the warning is now logged for

class Foo {
    private int i = 1;

    function init() {
        
    }
}

service on new Listener() {
    resource function default test() {
        _ = start fn(new Foo());
    }
}

function fn(Foo foo) {
    
}

public isolated class Listener {

    public function 'start() returns error? {
    }

    public function gracefulStop() returns error? {
    }

    public function immediateStop() returns error? {
    }

    public function detach(service object {} s) returns error? {
    }

    public function attach(service object {} s, string[]|string|() name = ()) returns error? {
    }
}

@MaryamZi
Copy link
Member

Seems like the warning is now logged for

class Foo {
    private int i = 1;

    function init() {
        
    }
}

service on new Listener() {
    resource function default test() {
        _ = start fn(new Foo());
    }
}

function fn(Foo foo) {
    
}

public isolated class Listener {

    public function 'start() returns error? {
    }

    public function gracefulStop() returns error? {
    }

    public function immediateStop() returns error? {
    }

    public function detach(service object {} s) returns error? {
    }

    public function attach(service object {} s, string[]|string|() name = ()) returns error? {
    }
}

The warning is still logged for this, right?

Copy link

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@github-actions github-actions bot added the Stale label Dec 29, 2023
Copy link

github-actions bot commented Jan 2, 2024

Closed PR due to inactivity for more than 18 days.

@MaryamZi
Copy link
Member

MaryamZi commented Jan 3, 2024

Seems like the warning is now logged for

class Foo {
    private int i = 1;

    function init() {
        
    }
}

service on new Listener() {
    resource function default test() {
        _ = start fn(new Foo());
    }
}

function fn(Foo foo) {
    
}

public isolated class Listener {

    public function 'start() returns error? {
    }

    public function gracefulStop() returns error? {
    }

    public function immediateStop() returns error? {
    }

    public function detach(service object {} s) returns error? {
    }

    public function attach(service object {} s, string[]|string|() name = ()) returns error? {
    }
}

The warning is still logged for this, right?

Still seeing the warning for this.

@LakshanWeerasinghe
Copy link
Contributor Author

Seems like the warning is now logged for

class Foo {
    private int i = 1;

    function init() {
        
    }
}

service on new Listener() {
    resource function default test() {
        _ = start fn(new Foo());
    }
}

function fn(Foo foo) {
    
}

public isolated class Listener {

    public function 'start() returns error? {
    }

    public function gracefulStop() returns error? {
    }

    public function immediateStop() returns error? {
    }

    public function detach(service object {} s) returns error? {
    }

    public function attach(service object {} s, string[]|string|() name = ()) returns error? {
    }
}

The warning is still logged for this, right?

Still seeing the warning for this.

I will check this.

Copy link

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@LakshanWeerasinghe
Copy link
Contributor Author

Seems like the warning is now logged for

class Foo {
    private int i = 1;

    function init() {
        
    }
}

service on new Listener() {
    resource function default test() {
        _ = start fn(new Foo());
    }
}

function fn(Foo foo) {
    
}

public isolated class Listener {

    public function 'start() returns error? {
    }

    public function gracefulStop() returns error? {
    }

    public function immediateStop() returns error? {
    }

    public function detach(service object {} s) returns error? {
    }

    public function attach(service object {} s, string[]|string|() name = ()) returns error? {
    }
}

The warning is still logged for this, right?

Still seeing the warning for this.

This behavior was visible when we do a bal run. But it won't appear when we do a bal build. The reason was the order of the entries coming from the IsolationInferableHashMap was different in the two scenarios. As per the offline discussion we had the order shouldn't matter when inferring the isolatedness of a function. When further investigating I found we are not inferring the isolation of dependent function call argument expression. After call the isIsolatedExpression with correct arguments to infer the expression, got the correct result.

Copy link

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@github-actions github-actions bot added the Stale label Feb 17, 2024
Copy link

Closed PR due to inactivity for more than 18 days.

arg = varRefRecordField;
break;
}
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There still seem to be codecov warnings.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still seeing codecov warnings.

public void visit(BLangRecordLiteral.BLangRecordSpreadOperatorField spreadOperatorField) {
analyzeNode(spreadOperatorField.expr, env);
NodeKind kind = spreadOperatorField.expr.getKind();
if (!(kind == NodeKind.RECORD_LITERAL_EXPR || kind == NodeKind.TYPE_CONVERSION_EXPR)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this special case we're trying to handle here? Why do we need to special case the type cast expression?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In here we only need to add whats inside the mapping constructor (key values and simple var refs).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inside the spread operator field, the expression can be type cast expression.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spread (with a mapping constructor) can be other expressions too, not just these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only these will be allowed to pass as a function argument. Others will be not allowed by the type checking phase.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that statement correct?

type Record record {|
    string[] arr1;
    string[] arr2;
    string[] arr3;
|};

function qux() {
    f(...<Record> {arr1: [], arr2: [], ...({arr3: []})}); // grouped expression in spread
}

isolated function f(string[] arr1, string[] arr2, string[] arr3) {
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't figure out this is possible previously. Handle it in commit.

public void visit(BLangRecordLiteral.BLangRecordSpreadOperatorField spreadOperatorField) {
analyzeNode(spreadOperatorField.expr, env);
NodeKind kind = spreadOperatorField.expr.getKind();
if (!(kind == NodeKind.RECORD_LITERAL_EXPR || kind == NodeKind.TYPE_CONVERSION_EXPR)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that statement correct?

type Record record {|
    string[] arr1;
    string[] arr2;
    string[] arr3;
|};

function qux() {
    f(...<Record> {arr1: [], arr2: [], ...({arr3: []})}); // grouped expression in spread
}

isolated function f(string[] arr1, string[] arr2, string[] arr3) {
}

arg = varRefRecordField;
break;
}
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still seeing codecov warnings.

Copy link

github-actions bot commented Apr 4, 2024

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@github-actions github-actions bot added the Stale label Apr 4, 2024
Copy link

github-actions bot commented Apr 8, 2024

Closed PR due to inactivity for more than 18 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants