-
Notifications
You must be signed in to change notification settings - Fork 753
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
Support for field annotations in local records and tuples #38488
Support for field annotations in local records and tuples #38488
Conversation
acee3c7
to
5696819
Compare
Codecov ReportBase: 76.83% // Head: 76.85% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## annot-tuple-members #38488 +/- ##
=========================================================
+ Coverage 76.83% 76.85% +0.01%
- Complexity 53429 53469 +40
=========================================================
Files 3350 3350
Lines 199739 199889 +150
Branches 25780 25800 +20
=========================================================
+ Hits 153475 153615 +140
- Misses 37676 37688 +12
+ Partials 8588 8586 -2
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
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.
Let's schedule a code review for this.
bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/values/BTypedesc.java
Outdated
Show resolved
Hide resolved
if (annotation != null) { | ||
return annotation; | ||
} |
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 the annotation is null here, why do we need to go on to check in the type?
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.
still, annotations related to record types are in the type. I didn't move those to the map created in typedesc.
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 didn't we move it?
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.
No specific reason for that, Will add them to the annotation map created for each type, instead of the global map
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.
@MaryamZi Currently, we create the typedesc for type definitions in a separate method. However, this approach leads to not being able to identify the necessary annotations for typedesc during creation. To resolve this issue, we need to make changes to move the generation of typedesc for type definitions to the init function, as previously discussed
bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TypedescValueImpl.java
Show resolved
Hide resolved
bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TypedescValueImpl.java
Outdated
Show resolved
Hide resolved
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java
Outdated
Show resolved
Hide resolved
...ballerina-unit-test/src/test/resources/test-src/annotations/local_record_annotation_test.bal
Outdated
Show resolved
Hide resolved
...ballerina-unit-test/src/test/resources/test-src/annotations/local_record_annotation_test.bal
Outdated
Show resolved
Hide resolved
...ballerina-unit-test/src/test/resources/test-src/annotations/local_record_annotation_test.bal
Outdated
Show resolved
Hide resolved
...ballerina-unit-test/src/test/resources/test-src/annotations/local_record_annotation_test.bal
Outdated
Show resolved
Hide resolved
...ballerina-unit-test/src/test/resources/test-src/annotations/local_record_annotation_test.bal
Outdated
Show resolved
Hide resolved
…ina-lang into field-annotations-for-local-records
2d42177
to
b88ddd0
Compare
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the |
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the |
...r/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmConstants.java
Outdated
Show resolved
Hide resolved
...er/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmValueGen.java
Outdated
Show resolved
Hide resolved
77e4305
to
ffa50c3
Compare
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.
Have we added BIR tests yet? We need them for compile-time annotation access also. E.g., org.ballerinalang.test.bala.annotation.AnnotationTests#testParamAnnotAttachmentsViaBir
bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TypedescValue.java
Outdated
Show resolved
Hide resolved
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java
Outdated
Show resolved
Hide resolved
...iler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/BIRPackageSymbolEnter.java
Outdated
Show resolved
Hide resolved
...-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BTypeSymbol.java
Show resolved
Hide resolved
...r/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClosureGenerator.java
Show resolved
Hide resolved
...r/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClosureGenerator.java
Show resolved
Hide resolved
...r/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClosureGenerator.java
Show resolved
Hide resolved
...-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/DataflowAnalyzer.java
Show resolved
Hide resolved
@chiranSachintha,
|
…atform/ballerina-lang into field-annotations-for-local-records
@@ -84,13 +91,17 @@ public Object instantiate(Strand s) { | |||
return instantiate(s, new BInitialValueEntry[0]); | |||
} | |||
|
|||
public MapValue getAnnotations() { |
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.
Do we need this?
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.
Removed in chiranSachintha#8
private BIROperand getAnnotations(BTypeSymbol typeSymbol, BIRGenEnv env) { | ||
if (typeSymbol == null || typeSymbol.annotations == null) { | ||
return null; | ||
} | ||
return new BIROperand(getAnnotations(typeSymbol.annotations, env)); | ||
} | ||
|
||
private BIRVariableDcl getAnnotations(BVarSymbol annotations, BIRGenEnv env) { | ||
if (env.symbolVarMap.containsKey(annotations)) { | ||
return env.symbolVarMap.get(annotations); | ||
} | ||
return globalVarMap.get(annotations); | ||
} |
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.
Move private function to the bottom.
visitTypedesc(pos, type, varDcls, null); | ||
} | ||
|
||
private void visitTypedesc(Location pos, BType type, List<BIROperand> varDcls, BIROperand annotations) { |
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 do we need a separate method?
...r/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClosureGenerator.java
Show resolved
Hide resolved
...r/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClosureGenerator.java
Show resolved
Hide resolved
BSymbol symbol = localVarRef.symbol; | ||
if (encInvokable == null || (symbol.tag & SymTag.VARIABLE) != SymTag.VARIABLE) { | ||
result = localVarRef; | ||
return; |
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.
Codecov warning.
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.
Updated(#39349)
...-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BTypeSymbol.java
Show resolved
Hide resolved
...na-unit-test/src/test/java/org/ballerinalang/test/annotations/LocalRecordAnnotationTest.java
Show resolved
Hide resolved
Assert.assertTrue(annot1 instanceof BMap); | ||
Assert.assertTrue(annot2 instanceof BMap); |
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 should assert the values also.
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.
I believe you can also use io.ballerina.runtime.api.utils.TypeUtils#getType
and check by tag instead of the instanceof check.
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.
Better yet, why not do these assertions also in Ballerina, similar to others?
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.
Updated(#39349)
function testGlobalAnnotationsOnFunctionPointerReturnType() { | ||
map<any> m1 = getLocalTupleAnnotations(typeof x(), "$field$.0"); |
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.
Test function name says global but this is local.
Btw we use module-level, not global.
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.
Change name to testTupleAnnotationsOnFunctionPointerReturnType
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.
@chiranSachintha, please address suggestions in separate PRs.
@@ -429,6 +436,32 @@ private void createTypeDescConstructor(ClassWriter cw) { | |||
mv.visitEnd(); | |||
} | |||
|
|||
private void createTypeDescConstructorWithAnnotations(ClassWriter cw, String name) { | |||
|
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.
Lets remove these new lines in the method. Better to remove with separate PR.
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.
Updated(#39349)
Runtime changes LGTM |
Purpose
Fixes #37241
Fixes #38487
Check List