-
Notifications
You must be signed in to change notification settings - Fork 758
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
Remove unnecessary casting for record field set #41917
Remove unnecessary casting for record field set #41917
Conversation
dfb0fee
to
72de51a
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #41917 +/- ##
=============================================
+ Coverage 0.00% 76.82% +76.82%
- Complexity 0 53968 +53968
=============================================
Files 9 2924 +2915
Lines 35 203890 +203855
Branches 0 26589 +26589
=============================================
+ Hits 0 156631 +156631
- Misses 35 38720 +38685
- Partials 0 8539 +8539 ☔ View full report in Codecov by Sentry. |
8e1c43d
to
72de51a
Compare
72de51a
to
ca4c44b
Compare
663ce24
to
3ae8778
Compare
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java
Outdated
Show resolved
Hide resolved
...it-test/src/test/java/org/ballerinalang/test/expressions/access/OptionalFieldAccessTest.java
Outdated
Show resolved
Hide resolved
tests/jballerina-unit-test/src/test/resources/test-src/bir/record_desugar.bal
Outdated
Show resolved
Hide resolved
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java
Outdated
Show resolved
Hide resolved
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java
Outdated
Show resolved
Hide resolved
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java
Outdated
Show resolved
Hide resolved
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java
Outdated
Show resolved
Hide resolved
39ed75c
to
7afbd4f
Compare
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java
Outdated
Show resolved
Hide resolved
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java
Outdated
Show resolved
Hide resolved
458ea68
to
2603532
Compare
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java
Outdated
Show resolved
Hide resolved
...-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java
Outdated
Show resolved
Hide resolved
...-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java
Outdated
Show resolved
Hide resolved
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/CompilerUtils.java
Outdated
Show resolved
Hide resolved
b4bedbe
to
5876dc3
Compare
c524f1b
to
70dc076
Compare
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the |
1066c95
to
6e139c7
Compare
Still for following kind of scenarios we create the unnecessary cast type R record {|
int f;
|};
function foo() {
R|R r = { f: 5 };
r.f = 6;
} |
} | ||
|
||
data.typeChecker.checkExpr(assignNode.expr, data.env, data.expType, data.prevEnvs, data.commonAnalyzerData); | ||
BLangExpression expr = assignNode.expr; | ||
data.typeChecker.checkExpr(expr, data.env, data.expType, data.prevEnvs, data.commonAnalyzerData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When doing the checkExpr
, we set the impConversionExpr
at the same time. With this logic, what we did is we set it and then reset it with the use of resetImpConversionExpr
. IMO, it is not correct, and we should avoid the setting of impConversionExpr
for scenarios which don't need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason why I decided to do this was because data.typeChecker.checkExpr
uses the expected type for doing 2 things in the end here,
- Check if the actual type is a subtype of the expected type and if not give an error
- Add an implicit cast if needed
When it comes to optional field assignments for 1 it must treat expected type for a field type T
as T?
and for 2 it must treat it as just T
. But since we are type checking the expr
part of the assignment, which don't have information about what it is being used for currently, and there for we can't distinguish between these expected types. I think there are 2 ways to actually fix this,
- Add information directly to BLangExpression node that it is being used in such a manner and in the type check we treat expected type differently for 1 and 2 (this is done in #272284f). While this requires the minimum amount of change this means we are leaking information about the parent node to the child nodes in the AST, which I think is bad
- Speical case the flow for the type checker when we have an optional field assignement. This would mean we either have to change the public API of the type checker such that we can pass information from here all the way down to
checkType
, or pass the informatio usingAnalyzerData
by giving a anther API to be used in case of optional field access similar tocheckExpr
. This would still means each expression node must do the right thing by either calling an appropriately modified version ofcheckType
or passing on this information tocheckType
by modifying the public API.
I feel 2 is the "correct" solution but given the way our code is structured this means a very large modification. Option 1 (and setting and resetting the implConversionExpr
) both require minimal changes but are "incorrect" in different ways. I am not sure which of these 3 possible options is the best. WDYT?
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/CompilerUtils.java
Show resolved
Hide resolved
return false; | ||
} | ||
BField field = ((BRecordType) targetType).fields.get(fieldAccessNode.field.value); | ||
return field != null && Symbols.isOptional(field.symbol); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we need field != null
check? As this is a field based access
expression field cannot be null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this because I got the field as null when trying to build the Ballerina langlib. Will investigate and create a issue for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get rid of this now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is caused by a preexisting bug in query de-sugar. Recent changes has surfaced it. Created #42479
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java
Show resolved
Hide resolved
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java
Show resolved
Hide resolved
fc6c5f8
to
2d1f5ea
Compare
I think this is a different issue from #41876 since we are not casting the value being assigned (ie 6) but R. And if I am not mistaken we do this whenever we refer to |
f94446b
to
8893a89
Compare
8893a89
to
7c3b67c
Compare
7c3b67c
to
badd3c6
Compare
@heshanpadmasiri Ubuntu and windows build are failing. Please check |
badd3c6
to
b4a2b30
Compare
b467de2
to
aed5e1c
Compare
aed5e1c
to
6551fb8
Compare
4bbbae3
into
ballerina-platform:master
Purpose
Remove unnecessary casting for record field set
Fixes #41876
Depends on #41998
Approach
Samples
Remarks
Check List