ballerina-lang icon indicating copy to clipboard operation
ballerina-lang copied to clipboard

Add chain invocation for `$moduleInit()`, `$moduleStart()`, `$moduleStop()`, and `$configureInit()` methods

Open Thushara-Piyasekara opened this issue 10 months ago • 4 comments

Purpose

During the codegen phase we generate a set of functions for initializing modules and their ballerina constructs. As of now, these initializations are done using a flattened dependency list for each ballerina module. With this PR we intend to refactor the invocation design to graph like a chain invocation. Refer to the issue for more information.

Fixes #42367

Approach

Changed the $moduleInit() BIRFunction generation boilerplate to generate invocations of $moduleInit() functions instead of <.init>() functions. The new method generation will be as follows,

image

Did the same change for generated $moduleStart, $moduleStop, and $configureInit() functions.

To achieve the chain invocation effect, had to add a set of static fields to $configurationMapper and $_init classes as well.

For $moduleStop methods, the stop order is determined by the algorithm(suggested by @manuranga) specified in this document.

Samples

Full change comparison can be found in this document.

Generated executable JAR samples of before and after the change can be found in this folder.

Performance comparison for bal build command can be found in this document.

Remarks

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

Check List

  • [x] Read the Contributing Guide
  • [ ] Updated Change Log
  • [ ] Checked Tooling Support (#<Issue Number>)
  • [ ] 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

Thushara-Piyasekara avatar Mar 29 '24 08:03 Thushara-Piyasekara

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Mar 29 '24 08:03 CLAassistant

During the offline discussion with @warunalakshitha we decided to add chain invocations for $moduleStop() as well. Explanation on how the $moduleStop() methods get triggered can be found in this document.

Thushara-Piyasekara avatar Mar 29 '24 10:03 Thushara-Piyasekara

Codecov Report

Attention: Patch coverage is 98.81890% with 3 lines in your changes missing coverage. Please review.

Project coverage is 77.66%. Comparing base (8bbaeaa) to head (48458c0). Report is 207 commits behind head on master.

Files Patch % Lines
...java/io/ballerina/runtime/internal/BalRuntime.java 0.00% 1 Missing :warning:
...erinalang/compiler/bir/codegen/JvmCodeGenUtil.java 0.00% 0 Missing and 1 partial :warning:
...inalang/compiler/bir/codegen/JvmTerminatorGen.java 80.00% 0 Missing and 1 partial :warning:
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #42433      +/-   ##
============================================
+ Coverage     77.28%   77.66%   +0.37%     
- Complexity    51339    51479     +140     
============================================
  Files          2929     2933       +4     
  Lines        204465   204624     +159     
  Branches      26683    26711      +28     
============================================
+ Hits         158030   158915     +885     
+ Misses        37846    37089     -757     
- Partials       8589     8620      +31     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Apr 01 '24 17:04 codecov[bot]

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[bot] avatar May 02 '24 19:05 github-actions[bot]

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[bot] avatar May 26 '24 19:05 github-actions[bot]

@warunalakshitha can you review this?

hasithaa avatar Jun 10 '24 04:06 hasithaa