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 compiler crash when accessing previous parameter in default expression with lambda expression #41816

Merged
merged 17 commits into from
Apr 2, 2024

Conversation

chiranSachintha
Copy link
Member

Purpose

$title.

Fixes #41802

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

@MaryamZi MaryamZi added the Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. label Dec 8, 2023
…ina-lang into fix-41802

# Conflicts:
#	compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClosureGenerator.java
Copy link

codecov bot commented Dec 21, 2023

Codecov Report

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

Project coverage is 76.56%. Comparing base (48a9e69) to head (3824057).
Report is 17 commits behind head on master.

Files Patch % Lines
...llerinalang/compiler/desugar/ClosureGenerator.java 90.90% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             master   #41816       +/-   ##
=============================================
+ Coverage      0.00%   76.56%   +76.56%     
- Complexity        0    53525    +53525     
=============================================
  Files             9     2905     +2896     
  Lines            35   202267   +202232     
  Branches          0    26336    +26336     
=============================================
+ Hits              0   154858   +154858     
- Misses           35    38924    +38889     
- Partials          0     8485     +8485     

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

Comment on lines 160 to 163
if (function instanceof BallerinaFunctionSymbol &&
((BallerinaFunctionSymbol) function).getInternalSymbol().getOrigin() == SymbolOrigin.VIRTUAL) {
continue;
}
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

How come we didn't come across this previously?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Previously we haven't got any values such as this here to do the filtering. Let's better check why this is happening with the new changes.

However, it would be better to do the filtering in https://github.com/ballerina-platform/ballerina-lang/blob/master/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/LangLibrary.java

Copy link
Member Author

Choose a reason for hiding this comment

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

The issue arises when using a parameter as the default value for another parameter without creating a new symbol for it. That is not correct. With this I have fixed that, and now we create a new symbol for that. So we need to skip those function as they are created in the desugar level.

BVarSymbol varSymbol = new BVarSymbol(Flags.REQUIRED_PARAM, symbolName, symbol.pkgID, type, funcSymbol, pos,

@dulajdilshan We need to skip them within the filterLangLibMethods. Isn't it?

Copy link
Contributor

Choose a reason for hiding this comment

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

How about we filter them in here:

private static void addLangLibMethods(String basicType, BPackageSymbol langLibModule,

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

Comment on lines -1613 to +1612
varSymbol.owner == resolvedSymbolEnv.scope.owner) {
if (entry != NOT_FOUND_ENTRY && varSymbol == entry.symbol) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this because we don't shadow the symbol like we discussed offline?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, when looking for the resolved level of a symbol, we don't need to check for the symbol owner. If there's the same symbol with two different owners, it becomes a compile-time error. I believe we introduced this logic before addressing the shadowing issue(that is the reason to add this check).

The reason for keeping the varSymbol == entry.symbol logic is because there are instances in the desugar where we use the same symbol generate variable. However, this is also not correct, and we need to address it separately.

Copy link
Member

Choose a reason for hiding this comment

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

Have we created an issue for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link

github-actions bot commented Jan 6, 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.

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 Jan 23, 2024
Copy link

Closed PR due to inactivity for more than 18 days.

Copy link

github-actions bot commented Mar 8, 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.

dulajdilshan
dulajdilshan previously approved these changes Mar 19, 2024
Comment on lines -1613 to +1612
varSymbol.owner == resolvedSymbolEnv.scope.owner) {
if (entry != NOT_FOUND_ENTRY && varSymbol == entry.symbol) {
Copy link
Member

Choose a reason for hiding this comment

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

Have we created an issue for this?

varSymbol.flags = 0;
funcSymbol.scope.define(varSymbol.name, varSymbol);
BType type = symbol.type;
Location pos = funcSymbol.pos;
Copy link
Member

Choose a reason for hiding this comment

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

This is fixed, so extract to a variable outside the loop?

Copy link
Member Author

Choose a reason for hiding this comment

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

Only the position right? Type is extract from the parameter

Copy link
Member

Choose a reason for hiding this comment

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

Yes.

@chiranSachintha chiranSachintha added this to the 2201.9.0 milestone Mar 21, 2024
return a + b();
}

function testParamUseAsValueInAnonFuncWithDefaultForNextParam() {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
function testParamUseAsValueInAnonFuncWithDefaultForNextParam() {
function testUsingParamInAnonFuncDefaultValueOfSubsequentParam() {

}) returns int {
return a + b();
}

Copy link
Member

Choose a reason for hiding this comment

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

Add at least one test

  • where it's not the next immediate param that accesses a previous param like this
  • with an expression-bodied function as the default value

Copy link
Member Author

Choose a reason for hiding this comment

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

Add tests with ce41d41

@CLAassistant
Copy link

CLAassistant commented Mar 29, 2024

CLA assistant check
All committers have signed the CLA.

MaryamZi
MaryamZi previously approved these changes Mar 29, 2024
@MaryamZi
Copy link
Member

@chiranSachintha, please check the level 6 build failure.

@MaryamZi MaryamZi requested a review from poorna2152 April 2, 2024 08:47
@MaryamZi MaryamZi merged commit 5e01f3c into ballerina-platform:master Apr 2, 2024
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
6 participants