-
Notifications
You must be signed in to change notification settings - Fork 752
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
Rewrite BUnionType's getMemberTypes()
usages using SemTypes
#43341
base: nutcracker
Are you sure you want to change the base?
Rewrite BUnionType's getMemberTypes()
usages using SemTypes
#43341
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## nutcracker #43341 +/- ##
================================================
+ Coverage 77.47% 77.55% +0.08%
+ Complexity 58442 58128 -314
================================================
Files 3449 3449
Lines 219783 218626 -1157
Branches 28815 28377 -438
================================================
- Hits 170269 169549 -720
+ Misses 40047 39690 -357
+ Partials 9467 9387 -80 ☔ View full report in Codecov by Sentry. |
6d652a5
to
dfb9b06
Compare
9af942a
to
f8d8a47
Compare
ad2e562
to
f503052
Compare
81e9418
to
6b38208
Compare
getMemberTypes()
usages getMemberTypes()
usages using SemTypes
SemType otherTy = null; | ||
for (SemType s : ((BUnionType) sourceType).getMemberSemTypes()) { | ||
if (PredefinedType.NIL.equals(s)) { |
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.
Is there a reason why we can't do containsBasicType
here? (since nil
don't have subtypes)
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.
Fixed in e2ce145
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java
Outdated
Show resolved
Hide resolved
...ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmTypeTestGen.java
Outdated
Show resolved
Hide resolved
int foundError = 0; | ||
for (BType bType : ((BUnionType) sourceType).getMemberTypes()) { | ||
if (bType.tag == TypeTags.ERROR) { | ||
for (SemType s : ((BUnionType) sourceType).getMemberSemTypes()) { |
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.
If I understand this correctly what we are actually trying to check is if we have a is E
where E is a error subtype and error part of a
is a subtype of E. (In which case if a
is a BError above type check passes so we just do instanceof
check). If that is the case wouldn't it be easier to,
- Check target is
isSubTypeSimple(error)
- Check
SemType errorPart = intersect(sourceType, error);
->errorPart
is not never - Check if
errorPart
is a subtype of target
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.
Thanks. Fixed in 445ecc9
...ler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ServiceDesugar.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
return true; | ||
return !Core.isEmpty(types.typeCtx(), Core.diff(returnType.semType(), PredefinedType.ERROR)); |
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.
Isn't this same as !Core.isSubtyp(returnType.semType(), PredefinedType.ERROR))
? Also in the previous code we had handled the case where returnType
could be null don't we need to handle it here a well?
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.
...rina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/CodeAnalyzer.java
Outdated
Show resolved
Hide resolved
...r/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java
Outdated
Show resolved
Hide resolved
...r/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java
Outdated
Show resolved
Hide resolved
* When the type is mutated we need to reset resolved semType. | ||
*/ | ||
public void resetSemType() { | ||
this.semType = 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.
Shouldn't we also clear the memberSemTypes
as well?
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.
We repopulate the memberSemTypes here, whenever the semtype is null
.
Lines 485 to 492 in efc16e5
public void populateMemberSemTypes(boolean ignoreTypeIds) { | |
LinkedHashSet<SemType> memberSemTypes = new LinkedHashSet<>(); | |
for (BType memberType : this.memberTypes) { | |
populateMemberSemTypes(memberType, memberSemTypes, ignoreTypeIds); | |
} | |
this.memberSemTypes = memberSemTypes; |
d1ee4ee
to
b54109b
Compare
Since ballerina-platform#35886 has been addressed, we should be able to remove the temporary shape check workaround. Please refer to ballerina-platform#35872 (comment)
Previously ballerina `readonly` return type allowed for java void methods. However, `error?` was not allowed with java void. This inconsistency is due to type checking not recognizing the fact that readonly type does include the error type. The error given in the latter case too is wrong because error is optional.
Previously this was implemented with a temporary workaround which was inefficient as we recalculated the semtypes.
Please refer to ballerina-platform#43344 (comment) for the reason
7a8795f
to
27a377a
Compare
27a377a
to
ff06641
Compare
Purpose
$subject
Fixes #43344
Fixes #43437
Approach
n/a
Samples
n/a
Remarks
n/a
Check List