ballerina-lang
ballerina-lang copied to clipboard
[Improvement]: Change invocation design of `$moduleInit()` and `$configureInit()` methods in codegen phase
Description
During the codegen phase we generate a set of functions for initializing modules and their ballerina constructs. As of now, these initializations is done in a flattened dependency list for each ballerina module. See the following example,
Note the following dependency tree,
This is the existing design for initializing the packages, In this design we never call the $moduleInit()
of dependent pkgs. Only the $moduleInit()
of root module is called during execution.
Note: Design of $configureInit()
function inside $configurationMapper
class is also similar to the above design. We can improve its design as well.
Describe your problem(s)
The current design has the following disadvantages,
-
$moduleInit()
of non-root modules never gets invoked. Making it dead code. - It is not possible to reuse the top level cached JARs when a dependency change happens in a lower level in the module dependency graph. (Since the
$moduleInit()
is generated relative the flattened dependency tree, it becomes outdated whenever the dependency graph changes).
Describe your solution(s)
It is possible to improve the existing design by using a chain module initialization instead of a flattened one. This will eliminate the dead code and increase the modularity of the generated thin JARs. See the following design,
Related area
-> Runtime
Related issue(s) (optional)
No response
Suggested label(s) (optional)
No response
Suggested assignee(s) (optional)
No response