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

jBallerina Compiler Backend Rewrite #21435

Merged
merged 266 commits into from
Mar 4, 2020
Merged

jBallerina Compiler Backend Rewrite #21435

merged 266 commits into from
Mar 4, 2020

Conversation

Kishanthan
Copy link
Contributor

@Kishanthan Kishanthan commented Mar 3, 2020

Purpose

$subject.

Approach

Describe how you are implementing the solutions along with the design details.

Samples

Provide high-level details about the samples related to this feature.

Remarks

List any other known issues, related PRs, TODO items, or any other notes related to the PR.

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

Kishanthan and others added 30 commits February 12, 2020 11:26
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 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
manuranga and others added 2 commits March 3, 2020 18:22
Change the class loader in tests to system class loader
@manuranga manuranga closed this Mar 3, 2020
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.ballerinalang.compiler.bir;
Copy link
Contributor

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?

Suggested change
package org.wso2.ballerinalang.compiler.bir;
package org.wso2.ballerinalang.compiler.bir;

@manuranga manuranga reopened this Mar 3, 2020

public static void generateBToJCheckCast(MethodVisitor mv, BType sourceType, JType targetType) {

if (targetType.jTag == JTypeTags.JBYTE) {
Copy link
Contributor

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) {
Copy link
Contributor

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",
Copy link
Contributor

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) {
Copy link
Contributor

@riyafa riyafa Mar 4, 2020

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);
Copy link
Contributor

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?

Copy link
Contributor

@manuranga manuranga Mar 4, 2020

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.

Copy link
Contributor

@riyafa riyafa Mar 4, 2020

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

Copy link
Contributor

@manuranga manuranga Mar 4, 2020

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);
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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;

Copy link
Contributor

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.

@anupama-pathirage
Copy link
Contributor

@Kishanthan This pr topic does not adhere to our guidelines. Refer https://github.com/ballerina-platform/ballerina-lang/blob/master/CONTRIBUTING.md for details.
We follow https://chris.beams.io/posts/git-commit/ for commit messages and PR topics.
Pls change the PR topic accordingly.
Basically a properly formed Git commit subject line/PR topic should always be able to complete the following sentence:
If applied, this commit/PR will your subject line here

@riyafa
Copy link
Contributor

riyafa commented Mar 4, 2020

Shall we track disabled tests by creating issues? Otherwise we may miss on fixing them.

@manuranga
Copy link
Contributor

manuranga commented Mar 4, 2020

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-io
Copy link

codecov-io commented Mar 4, 2020

Codecov Report

Merging #21435 into master will increase coverage by 4.5%.
The diff coverage is n/a.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
tool-plugins/vscode/src/extension.ts 0% <0%> (ø) ⬆️
composer/packages/tracing/src/ToolBar.tsx 71.05% <0%> (ø)
composer/packages/tracing/src/TraceList.tsx 94.44% <0%> (ø)
composer/packages/tracing/src/DetailView.tsx 72.72% <0%> (ø)
composer/packages/tracing/src/TraceLogs.tsx 70.37% <0%> (ø)
composer/packages/tracing/src/index.ts 0% <0%> (ø)
tool-plugins/vscode/src/core/extension.ts 28.37% <0%> (+0.39%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bc5ec12...a68378a. Read the comment docs.

@manuranga manuranga merged commit d0b0e8a into master Mar 4, 2020
@riyafa
Copy link
Contributor

riyafa commented Mar 5, 2020

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.

The reason why that "We are going to refactor later" is normally a lie in the software industry:

  • It normally means the authors don't want to spend time on it now and probably will find more important tasks to work on later so refactoring will never be done.
  • Every one can't have refactoring code as a task on their sprint so the original authors will pass maintenance to some one else who don't understand the code so that they can move onto something interesting to do. And these new people don't know the head or tail to fix it.
  • The broken window issue. Once the code is degraded future maintainers are not going to fix it, they are going to follow the general pattern of writing bad code.
  • Refactoring code is a time consuming task. And probably will take more time than writing the original "something that works" code so the original authors can't account for this time when they have already informed the higher management that they have already completed the task.

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
Please note I am talking in the general sense and not very specific to this PR

@sameerajayasoma sameerajayasoma deleted the jbal-be-rewrite branch August 28, 2020 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants