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 isolation analysis for start actions #42366

Conversation

LakshanWeerasinghe
Copy link
Contributor

@LakshanWeerasinghe LakshanWeerasinghe commented Mar 21, 2024

Purpose

$subject

FIxes #41691

Related PR #41772

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

This PR includes only fixing isolation analysis with start actions. The compiler crashes happens when passing mapping and list constructors will be fixed by #41772.

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

@LakshanWeerasinghe LakshanWeerasinghe requested review from MaryamZi and removed request for hasithaa and sameerajayasoma March 21, 2024 05:42
@LakshanWeerasinghe LakshanWeerasinghe added the Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. label Mar 21, 2024
Copy link

codecov bot commented Mar 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.73%. Comparing base (09e0471) to head (a22e04b).
Report is 114 commits behind head on master.

Additional details and impacted files
@@              Coverage Diff              @@
##             master   #42366       +/-   ##
=============================================
+ Coverage      0.00%   76.73%   +76.73%     
- Complexity        0    53738    +53738     
=============================================
  Files             9     2907     +2898     
  Lines            35   203156   +203121     
  Branches          0    26484    +26484     
=============================================
+ Hits              0   155883   +155883     
- Misses           35    38754    +38719     
- Partials          0     8519     +8519     

☔ 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.

We don't seem to be logging a warning for

import ballerina/http;

type UserRegistration record {
    string name;
    string email;
};

class Obj {
    int x = 1;

    function fn() {

    }
}

function getObj(Obj obj) returns Obj => obj;

service on new http:Listener(8080) {
    resource function get h1(UserRegistration user) {
        Obj obj = new;
        _ = start sendEmailNotification(getObj(obj));
    }
}

isolated function sendEmailNotification(object {} ob) returns error? {
}

@MaryamZi
Copy link
Member

MaryamZi commented Apr 2, 2024

We don't seem to be logging a warning for

import ballerina/http;

type UserRegistration record {
    string name;
    string email;
};

class Obj {
    int x = 1;

    function fn() {

    }
}

function getObj(Obj obj) returns Obj => obj;

service on new http:Listener(8080) {
    resource function get h1(UserRegistration user) {
        Obj obj = new;
        _ = start sendEmailNotification(getObj(obj));
    }
}

isolated function sendEmailNotification(object {} ob) returns error? {
}

This isn't fixed yet?

@CLAassistant
Copy link

CLAassistant commented Apr 2, 2024

CLA assistant check
All committers have signed the CLA.

@LakshanWeerasinghe
Copy link
Contributor Author

Fix issue with infering func isolation

Fixed in commit.

@LakshanWeerasinghe LakshanWeerasinghe added this to the 2201.9.0 milestone Apr 3, 2024
Comment on lines 1277 to 1297
if (this.inIsolatedStartAction
&& !isSubtypeOfReadOnlyOrIsolatedObjectOrInferableObject(symbol.owner, symbol.getType())) {
inferredIsolated = false;
}
Copy link
Member

Choose a reason for hiding this comment

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

Can't this happen outside the outer check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At the outside of the outer check we analyse symbols with recordFieldDefaultValue and objectFieldDefaultValueRequiringIsolation being true. For those I don't think we need to check its a subtype of readonly or isolated object.

Copy link
Member

Choose a reason for hiding this comment

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

But for those this.inIsolatedStartAction won't be true, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. But outer was there to handle both true and false scenarios. We have add this new check to validate start actions specifically. Which wasn't being analysed previously.

Copy link
Member

Choose a reason for hiding this comment

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

My point is if we can't do

if (this.inIsolatedStartAction
          && !isSubtypeOfReadOnlyOrIsolatedObjectOrInferableObject(symbol.owner, symbol.getType())) {
      inferredIsolated = false;
      return;
}

outside.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then we need isReferenceToVarDefinedInSameInvokable check as well.

Copy link
Member

Choose a reason for hiding this comment

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

Can you give an example for when we need that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I am running the test locally previously seems I haven't added the return statement. We can move this to the outside of the outer if. Updated in commit.

@@ -4125,7 +4133,8 @@ private boolean inferFunctionIsolation(BSymbol symbol, IsolationInferenceInfo fu
}

for (BLangExpression dependsOnArg : functionIsolationInferenceInfo.dependsOnFuncCallArgExprs) {
if (!isIsolatedExpression(dependsOnArg)) {
if (!isIsolatedExpression(dependsOnArg, false, false, new ArrayList<>(), true,
publiclyExposedObjectTypes, classDefinitions, moduleLevelVariables, new HashSet<>())) {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we pass unresolvedSymbols here? Shall we add a test too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The existing tests will cover this scenario.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in commit.

Copy link
Member

@MaryamZi MaryamZi Apr 3, 2024

Choose a reason for hiding this comment

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

But that should have resulted in a stack overflow-ish error, right? If we are recursively checking the isolated-ness of the same construct?

Copy link
Member

Choose a reason for hiding this comment

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

Example:

function fn(any x = ()) returns any {
    _ = start fn(fn());
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!
When we don't pass unresolved symbols, for the provided sample it gives SO.

@LakshanWeerasinghe LakshanWeerasinghe merged commit 0a7e4c9 into ballerina-platform:master Apr 4, 2024
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Invalid inferring of isolated with start actions when the arguments are not isolated expressions
3 participants