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

Support for field annotations in local records and tuples #38488

Conversation

chiranSachintha
Copy link
Member

@chiranSachintha chiranSachintha commented Nov 1, 2022

Purpose

$title.

Fixes #37241
Fixes #38487

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

@chiranSachintha chiranSachintha force-pushed the field-annotations-for-local-records branch from acee3c7 to 5696819 Compare November 1, 2022 03:52
@chiranSachintha chiranSachintha added the Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. label Nov 1, 2022
@codecov
Copy link

codecov bot commented Nov 3, 2022

Codecov Report

Base: 76.83% // Head: 76.85% // Increases project coverage by +0.01% 🎉

Coverage data is based on head (01f2595) compared to base (74e19c8).
Patch coverage: 96.03% of modified lines in pull request are covered.

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     
Impacted Files Coverage Δ
.../ballerinalang/compiler/BIRPackageSymbolEnter.java 89.05% <ø> (ø)
...llerinalang/compiler/bir/codegen/JvmConstants.java 100.00% <ø> (ø)
.../compiler/semantics/model/symbols/BTypeSymbol.java 87.50% <ø> (ø)
...ina/runtime/internal/values/TypedescValueImpl.java 81.25% <83.33%> (-0.24%) ⬇️
...va/org/wso2/ballerinalang/compiler/bir/BIRGen.java 92.39% <90.90%> (+<0.01%) ⬆️
...llerinalang/compiler/desugar/ClosureGenerator.java 78.96% <94.11%> (ø)
...java/io/ballerina/runtime/internal/ValueUtils.java 94.28% <100.00%> (+0.43%) ⬆️
...lerina/runtime/internal/values/TupleValueImpl.java 75.52% <100.00%> (+0.25%) ⬆️
...nalang/compiler/bir/codegen/JvmInstructionGen.java 89.77% <100.00%> (+0.02%) ⬆️
...allerinalang/compiler/bir/codegen/JvmValueGen.java 93.10% <100.00%> (+0.37%) ⬆️
... and 17 more

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.
📢 Do you have feedback about the report comment? Let us know in this issue.

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.

Let's schedule a code review for this.

Comment on lines 590 to 592
if (annotation != null) {
return annotation;
}
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member Author

@chiranSachintha chiranSachintha Jan 22, 2023

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

@chiranSachintha chiranSachintha force-pushed the field-annotations-for-local-records branch from 2d42177 to b88ddd0 Compare November 14, 2022 06:33
@github-actions
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
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 Dec 15, 2022
@chiranSachintha chiranSachintha force-pushed the field-annotations-for-local-records branch from 77e4305 to ffa50c3 Compare January 23, 2023 11:47
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.

Have we added BIR tests yet? We need them for compile-time annotation access also. E.g., org.ballerinalang.test.bala.annotation.AnnotationTests#testParamAnnotAttachmentsViaBir

@MaryamZi
Copy link
Member

@chiranSachintha, org.ballerinalang.test.runtime.api.RuntimeAPITest is failing.

ballerina-new-parser-test-suite > jballerina-test > org.ballerinalang.test.runtime.api.RuntimeAPITest > testRuntimeAPIs[4](types) FAILED
    io.ballerina.runtime.internal.util.exceptions.BLangRuntimeException: error: Annotation is not available.
    	at testorg.types.typeref.1:checkInlineRecordAnnotations(typeref.bal:501)
    	   testorg.types.typeref.1:validateInlineRecordField(typeref.bal:494)
    	   testorg.types.typeref.1:validateTypeRef(typeref.bal:92)
    	   testorg.types.1:main(main.bal:24)
        at org.ballerinalang.test.BRunUtil.invoke(BRunUtil.java:206)
        at org.ballerinalang.test.BRunUtil.invokeOnJBallerina(BRunUtil.java:148)
        at org.ballerinalang.test.BRunUtil.invoke(BRunUtil.java:87)
        at org.ballerinalang.test.BRunUtil.invoke(BRunUtil.java:269)
        at org.ballerinalang.test.runtime.api.RuntimeAPITest.testRuntimeAPIs(RuntimeAPITest.java:36)

        Caused by:
        error("error: Annotation is not available.
        	at testorg.types.typeref.1:checkInlineRecordAnnotations(typeref.bal:501)
        	   testorg.types.typeref.1:validateInlineRecordField(typeref.bal:494)
        	   testorg.types.typeref.1:validateTypeRef(typeref.bal:92)
        	   testorg.types.1:main(main.bal:24)")

@@ -84,13 +91,17 @@ public Object instantiate(Strand s) {
return instantiate(s, new BInitialValueEntry[0]);
}

public MapValue getAnnotations() {
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?

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed in chiranSachintha#8

Comment on lines +1688 to +1700
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);
}
Copy link
Member

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.

Comment on lines +2270 to +2273
visitTypedesc(pos, type, varDcls, null);
}

private void visitTypedesc(Location pos, BType type, List<BIROperand> varDcls, BIROperand annotations) {
Copy link
Member

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?

BSymbol symbol = localVarRef.symbol;
if (encInvokable == null || (symbol.tag & SymTag.VARIABLE) != SymTag.VARIABLE) {
result = localVarRef;
return;
Copy link
Member

Choose a reason for hiding this comment

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

Codecov warning.

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(#39349)

Comment on lines +61 to +62
Assert.assertTrue(annot1 instanceof BMap);
Assert.assertTrue(annot2 instanceof BMap);
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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?

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(#39349)

Comment on lines +74 to +75
function testGlobalAnnotationsOnFunctionPointerReturnType() {
map<any> m1 = getLocalTupleAnnotations(typeof x(), "$field$.0");
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Change name to testTupleAnnotationsOnFunctionPointerReturnType

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.

@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) {

Copy link
Contributor

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.

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(#39349)

@warunalakshitha
Copy link
Contributor

Runtime changes LGTM

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
No open projects
Status: Addressing Review Suggestions
4 participants