-
Notifications
You must be signed in to change notification settings - Fork 756
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
jBallerina Compiler Backend Rewrite #21435
Conversation
Migrate JvmTerminatorGen and fix compilation errors
Remove BIRVarRef class and use BIROperand instead
Migrate JvmPackageGen and fix compilation errors
Migrate JvmObservabilityGen, JvmLabelGen and fix compilation errors
Migrate JvmMethodGen to java
Migrate interop gen related classes
Fix runtime bugs to get migrated backend working for empty function
Fix InteropMethodGen compilation errors and conflicts
Clean JInteropFieldValidator and Use BackendDriver for test source compilation
Change the class loader in tests to system class loader
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.wso2.ballerinalang.compiler.bir; |
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.
Shall we add a new line in all places?
package org.wso2.ballerinalang.compiler.bir; | |
package org.wso2.ballerinalang.compiler.bir; |
|
||
public static void generateBToJCheckCast(MethodVisitor mv, BType sourceType, JType targetType) { | ||
|
||
if (targetType.jTag == JTypeTags.JBYTE) { |
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 don't we use a switch statement here?
|
||
if (sourceType.tag == TypeTags.BYTE) { | ||
// do nothing | ||
} else if (sourceType.tag == TypeTags.INT) { |
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.
Shall we use switch statement?
private static void generateCheckCastBToJString(MethodVisitor mv, BType sourceType) { | ||
|
||
if (sourceType.tag == TypeTags.STRING) { | ||
mv.visitMethodInsn(INVOKESTATIC, STRING_UTILS, "fromString", |
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.
Shall we use a constant for hardcoded method name?
|
||
private static void generateCheckCastBToJChar(MethodVisitor mv, BType sourceType) { | ||
|
||
if (sourceType.tag == TypeTags.BYTE) { |
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.
Shall we use switch statements in all places instead of if-else-if statements?
mv.visitInsn(D2I); | ||
mv.visitInsn(I2S); | ||
} else if (sourceType.tag == TypeTags.HANDLE) { | ||
mv.visitMethodInsn(INVOKEVIRTUAL, HANDLE_VALUE, "getValue", "()Ljava/lang/Object;", false); |
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.
Shall we use constants for the hardcoded values in all places?
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?, I personally find it easier to read when I can see the value.
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 we change the name of the method in the future we would need to change only a constant instead of grepping to change all files which can create mistakes. It is a best practice to define method names as constants
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.
Code is read more often than changed, so it better if its easier to read, not easier to modify. In my opinion you need to question the this kind of best practices than blindly trust them.
@@ -460,6 +461,7 @@ public void visit(BLangFunction astFunc) { | |||
// Special %0 location for storing return values | |||
birFunc.returnVariable = new BIRVariableDcl(astFunc.pos, astFunc.symbol.type.getReturnType(), | |||
this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.RETURN, null); | |||
birFunc.localVars.add(0, birFunc.returnVariable); |
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 add(0,
is used in multiple places. A new reader might not know what 0
signifies. If we define a constant for 0
it would add clarity.
// return; | ||
//} else if (sourceType is bir:BRecordType && (targetType is bir:BMapType && targetType.constraint | ||
// is bir:BTypeAny)) { | ||
// // do nothing |
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.
Shall we remove commented out code in all places before merging?
|
||
// # Generate adding a new value to an array | ||
// # | ||
// # + inst - array store instruction |
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.
Shall we fix these strange comments?
if (!isBuiltinModule) { | ||
generateObjectArgs(mv, paramIndex); | ||
paramIndex += 1; | ||
|
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 really need switch statements.
@Kishanthan This pr topic does not adhere to our guidelines. Refer https://github.com/ballerina-platform/ballerina-lang/blob/master/CONTRIBUTING.md for details. |
Shall we track disabled tests by creating issues? Otherwise we may miss on fixing them. |
+1 reason we haven't cleaned up this code is to make it easy to port all the changes you (and Vinod) has been doing to this branch. we are planing to do a major refactoring after that. |
Codecov Report
@@ Coverage Diff @@
## master #21435 +/- ##
=========================================
+ Coverage 14.67% 19.17% +4.5%
=========================================
Files 51 56 +5
Lines 1404 1528 +124
Branches 215 233 +18
=========================================
+ Hits 206 293 +87
- Misses 1182 1219 +37
Partials 16 16
Continue to review full report at Codecov.
|
The reason why that "We are going to refactor later" is normally a lie in the software industry:
Once the original authors leave, the code will be no longer salvageable and the complexities will remain forever or someone else will try to rewrite and again the same loop will repeat. Read The Total Cost of Owning a Mess in Chapter 1 of Clean code book: https://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882 |
Purpose
$subject.
Approach
Samples
Remarks
Check List