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

Sync with master #41760

Merged
merged 41 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
b4e1234
Clean up BIR after codegen phase
Nadeeshan96 Oct 12, 2023
e97faff
Refactor JvmDesugarPhase
Nadeeshan96 Oct 12, 2023
4a3cde7
Refactor CodeGenerator
Nadeeshan96 Oct 12, 2023
7aff2ff
Fix listenerDeclarationFound method in JvmPackageGen
Nadeeshan96 Oct 12, 2023
8a83469
Refactor BIRModelTest
Nadeeshan96 Oct 12, 2023
ec28a7c
Make BPackageSymbol imports a set
Nadeeshan96 Oct 12, 2023
66ac0fb
Remove text document of dependencies
Nadeeshan96 Oct 16, 2023
faf16bb
Refactor DocumentContext class
Nadeeshan96 Oct 16, 2023
231e944
Merge branch 'master' into mas-cleanup-bir-41384
Nadeeshan96 Oct 23, 2023
7108843
Clean BLangPackage after codegen for Bala projects
Nadeeshan96 Oct 19, 2023
3dd45cd
Refactor ModuleContext
Nadeeshan96 Oct 23, 2023
71cf961
Remove unused BirWriter class
Nadeeshan96 Oct 23, 2023
255d850
Remove unneeded comments
Nadeeshan96 Oct 23, 2023
5608d82
feat: getAllDependents & getAllDependencies
adripo Oct 23, 2023
727eb0f
chore: update changelog
adripo Oct 23, 2023
385e4a3
test: validation of getAllDependents and getAllDependencies
adripo Oct 27, 2023
c847e89
Merge branch 'ballerina-platform:master' into depgraph-methods
adripo Nov 2, 2023
574f672
fix: missing imports
adripo Nov 2, 2023
eea0172
Fix unnecessary central call
Thevakumar-Luheerathan Nov 2, 2023
96abfc2
Address the comments
Thevakumar-Luheerathan Nov 2, 2023
8242911
fix: tests logic
adripo Nov 3, 2023
a7a95fa
Test only having a listener in an imported module
Nadeeshan96 Nov 8, 2023
199d333
Add tests for listeners in imported modules
Nadeeshan96 Nov 8, 2023
8df7083
Merge branch 'master' into mas-cleanup-bir-41384
Nadeeshan96 Nov 8, 2023
2c265d7
Merge branch 'master' into mas-cleanup-bir-41384
Nadeeshan96 Nov 9, 2023
63d54d7
Fix default worker crash with error return
gabilang Nov 10, 2023
0312066
Add unit test for service with error union return
gabilang Nov 11, 2023
cd09380
Merge branch 'master' into mas-cleanup-bir-41384
Nadeeshan96 Nov 15, 2023
68d25fa
Merge branch 'master' into mas-cleanup-bir-41384
Nadeeshan96 Nov 20, 2023
2b9e233
Fix invalid stream signature in CreateVariable
nipunayf Oct 18, 2023
18bfa61
Address review suggestions
gabilang Nov 21, 2023
908dd8b
Remove additional white line
gabilang Nov 21, 2023
d8c385c
Update license header
gabilang Nov 21, 2023
fbffe44
Remove the added service test case
gabilang Nov 21, 2023
3b4940b
Merge branch 'master'
gabilang Nov 21, 2023
3957cf1
Merge pull request #41534 from nipunayf/bal-persist-codeaction
KavinduZoysa Nov 22, 2023
b20b0ea
Merge branch 'ballerina-platform:master' into depgraph-methods
adripo Nov 23, 2023
ad0ab92
Merge pull request #41510 from Nadeeshan96/mas-cleanup-bir-41384
warunalakshitha Nov 23, 2023
79694aa
Merge pull request #41679 from gabilang/fix-default-worker-error-return
warunalakshitha Nov 23, 2023
a430acd
Merge pull request #41625 from Thevakumar-Luheerathan/fix-unnecessary…
Thevakumar-Luheerathan Nov 23, 2023
1c44405
Merge pull request #41561 from adripo/depgraph-methods
azinneera Nov 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. When sendin

### Language

-
- [Add getAllDependents and getAllDependencies method to the DependencyGraph class](https://github.com/ballerina-platform/ballerina-lang/pull/41561)
-
-
-
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ public T getRoot() {
return rootNode;
}

// Returns all direct and indirect dependents of the node T
public Collection<T> getAllDependents(T node) {
Set<T> allDependents = new HashSet<>();
Set<T> visited = new HashSet<>();
getAllDependentsRecursive(node, allDependents, visited);
return allDependents;
}

// Returns all direct and indirect dependencies of node T
public Collection<T> getAllDependencies(T node) {
Set<T> allDependencies = new HashSet<>();
Set<T> visited = new HashSet<>();
getAllDependenciesRecursive(node, allDependencies, visited);
return allDependencies;
}

public boolean contains(T node) {
return dependencies.containsKey(node);
}
Expand Down Expand Up @@ -192,6 +208,30 @@ private void sortTopologically(T vertex, List<T> visited, List<T> ancestors, Lis
ancestors.remove(vertex);
}

private void getAllDependentsRecursive(T node, Set<T> allDependents, Set<T> visited) {
visited.add(node);
Collection<T> directDependents = getDirectDependents(node);
allDependents.addAll(directDependents);

for (T dependent : directDependents) {
if (!visited.contains(dependent)) {
getAllDependentsRecursive(dependent, allDependents, visited);
}
}
}

private void getAllDependenciesRecursive(T node, Set<T> allDependencies, Set<T> visited) {
visited.add(node);
Collection<T> directDependencies = getDirectDependencies(node);
allDependencies.addAll(directDependencies);

for (T dependency : directDependencies) {
if (!visited.contains(dependency)) {
getAllDependenciesRecursive(dependency, allDependencies, visited);
}
}
}

/**
* Builds a {@code DependencyGraph}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class DocumentContext {
private final DocumentId documentId;
private final String name;
private String content;
private boolean disableSyntaxTree = false;
private final boolean disableSyntaxTree;

private DocumentContext(DocumentId documentId, String name, String content, boolean disableSyntaxTree) {
this.documentId = documentId;
Expand All @@ -82,40 +82,44 @@ String name() {
}

SyntaxTree parse() {
if (syntaxTree != null) {
return syntaxTree;
if (this.syntaxTree != null) {
return this.syntaxTree;
}
if (!disableSyntaxTree) {
syntaxTree = SyntaxTree.from(this.textDocument(), name);
return syntaxTree;
if (!this.disableSyntaxTree) {
this.syntaxTree = SyntaxTree.from(this.textDocument(), this.name);
return this.syntaxTree;
}
return SyntaxTree.from(this.textDocument(), name);
return SyntaxTree.from(this.textDocument(), this.name);
}

SyntaxTree syntaxTree() {
return parse();
}

TextDocument textDocument() {
if (this.textDocument == null) {
if (this.textDocument != null) {
return this.textDocument;
}
if (!this.disableSyntaxTree) {
this.textDocument = TextDocuments.from(this.content);
return this.textDocument;
}
return this.textDocument;
return TextDocuments.from(this.content);
}

BLangCompilationUnit compilationUnit(CompilerContext compilerContext, PackageID pkgID, SourceKind sourceKind) {
BLangDiagnosticLog dlog = BLangDiagnosticLog.getInstance(compilerContext);
SyntaxTree syntaxTree = syntaxTree();
reportSyntaxDiagnostics(pkgID, syntaxTree, dlog);
SyntaxTree synTree = syntaxTree();
reportSyntaxDiagnostics(pkgID, synTree, dlog);

nodeCloner = NodeCloner.getInstance(compilerContext);
if (compilationUnit != null) {
return nodeCloner.cloneCUnit(compilationUnit);
this.nodeCloner = NodeCloner.getInstance(compilerContext);
if (this.compilationUnit != null) {
return this.nodeCloner.cloneCUnit(this.compilationUnit);
}
BLangNodeBuilder bLangNodeBuilder = new BLangNodeBuilder(compilerContext, pkgID, this.name);
compilationUnit = (BLangCompilationUnit) bLangNodeBuilder.accept(syntaxTree.rootNode()).get(0);
compilationUnit.setSourceKind(sourceKind);
return nodeCloner.cloneCUnit(compilationUnit);
this.compilationUnit = (BLangCompilationUnit) bLangNodeBuilder.accept(synTree.rootNode()).get(0);
this.compilationUnit.setSourceKind(sourceKind);
return this.nodeCloner.cloneCUnit(this.compilationUnit);
}

Set<ModuleLoadRequest> moduleLoadRequests(ModuleDescriptor currentModuleDesc, PackageDependencyScope scope) {
Expand All @@ -129,10 +133,10 @@ Set<ModuleLoadRequest> moduleLoadRequests(ModuleDescriptor currentModuleDesc, Pa

private Set<ModuleLoadRequest> getModuleLoadRequests(ModuleDescriptor currentModuleDesc,
PackageDependencyScope scope) {
Set<ModuleLoadRequest> moduleLoadRequests = new LinkedHashSet<>();
Set<ModuleLoadRequest> moduleLoadRequestSet = new LinkedHashSet<>();
ModulePartNode modulePartNode = syntaxTree().rootNode();
for (ImportDeclarationNode importDcl : modulePartNode.imports()) {
moduleLoadRequests.add(getModuleLoadRequest(importDcl, scope));
moduleLoadRequestSet.add(getModuleLoadRequest(importDcl, scope));
}

// TODO This is a temporary solution for SLP6 release
Expand All @@ -145,9 +149,9 @@ private Set<ModuleLoadRequest> getModuleLoadRequests(ModuleDescriptor currentMod
ModuleLoadRequest ballerinaiLoadReq = new ModuleLoadRequest(
PackageOrg.from(Names.BALLERINA_INTERNAL_ORG.value),
moduleName, scope, DependencyResolutionType.PLATFORM_PROVIDED);
moduleLoadRequests.add(ballerinaiLoadReq);
moduleLoadRequestSet.add(ballerinaiLoadReq);
}
return moduleLoadRequests;
return moduleLoadRequestSet;
}

private ModuleLoadRequest getModuleLoadRequest(ImportDeclarationNode importDcl, PackageDependencyScope scope) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,10 @@ private void performCodeGen() {
new PackageDiagnostic(diagnostic, moduleContext.descriptor(), moduleContext.project()));
}

//TODO: remove this once ballerina-lang#41407 is fixed
ModuleContext.shrinkDocuments(moduleContext);
if (moduleContext.project().kind() == ProjectKind.BALA_PROJECT) {
moduleContext.cleanBLangPackage();
}
}
// add compilation diagnostics
diagnostics.addAll(moduleDiagnostics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ BLangPackage bLangPackage() {
return getBLangPackageOrThrow();
}

protected void cleanBLangPackage() {
this.bLangPackage = null;
}

ModuleCompilationState compilationState() {
return moduleCompState;
}
Expand Down Expand Up @@ -308,10 +312,6 @@ void setCompilationState(ModuleCompilationState moduleCompState) {
this.moduleCompState = moduleCompState;
}

void parse() {
currentCompilationState().parse(this);
}

void resolveDependencies(DependencyResolution dependencyResolution) {
Set<ModuleDependency> moduleDependencies = new HashSet<>();
if (this.project.kind() == ProjectKind.BALA_PROJECT) {
Expand Down Expand Up @@ -506,12 +506,8 @@ private static boolean shouldGenerateBir(ModuleContext moduleContext, CompilerCo
if (Boolean.parseBoolean(compilerOptions.get(CompilerOptionName.DUMP_BIR_FILE))) {
return true;
}
if (moduleContext.project.kind().equals(ProjectKind.BUILD_PROJECT)
&& moduleContext.project().buildOptions().enableCache()) {
return true;
}

return false;
return moduleContext.project.kind().equals(ProjectKind.BUILD_PROJECT)
&& moduleContext.project().buildOptions().enableCache();
}

private static ByteArrayOutputStream generateBIR(ModuleContext moduleContext, CompilerContext compilerContext) {
Expand Down Expand Up @@ -560,7 +556,6 @@ static void loadPlatformSpecificCodeInternal(ModuleContext moduleContext, Compil
// TODO implement
}

//TODO: should be removed once we properly fix ballerina-lang#41407
static void shrinkDocuments(ModuleContext moduleContext) {
moduleContext.srcDocContextMap.values().forEach(DocumentContext::shrink);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public PackageContainer<DirectPackageDependency> resolveModuleLoadRequests(
for (ModuleLoadRequest moduleLoadRequest : moduleLoadRequests) {
resolveModuleLoadRequest(moduleLoadRequest, pkgContainer, unresolvedModuleRequests);
}
if (unresolvedModuleRequests.isEmpty()) {
return pkgContainer;
}

// Resolve unresolved import module declarations
Collection<ImportModuleResponse> importModResponses =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.wso2.ballerinalang.compiler.PackageCache;
import org.wso2.ballerinalang.compiler.bir.BIRGenUtils;
import org.wso2.ballerinalang.compiler.bir.codegen.optimizer.LargeMethodOptimizer;
import org.wso2.ballerinalang.compiler.bir.model.BIRNode;
import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLog;
import org.wso2.ballerinalang.compiler.semantics.analyzer.Types;
import org.wso2.ballerinalang.compiler.semantics.model.SymbolTable;
Expand All @@ -38,14 +39,12 @@
public class CodeGenerator {

private static final CompilerContext.Key<CodeGenerator> CODE_GEN = new CompilerContext.Key<>();
private SymbolTable symbolTable;
private PackageCache packageCache;
private BLangDiagnosticLog dlog;
private Types types;
private LargeMethodOptimizer largeMethodOptimizer;
private final SymbolTable symbolTable;
private final PackageCache packageCache;
private final BLangDiagnosticLog dlog;
private final Types types;

private CodeGenerator(CompilerContext compilerContext) {

compilerContext.put(CODE_GEN, this);
this.symbolTable = SymbolTable.getInstance(compilerContext);
this.packageCache = PackageCache.getInstance(compilerContext);
Expand All @@ -54,12 +53,10 @@ private CodeGenerator(CompilerContext compilerContext) {
}

public static CodeGenerator getInstance(CompilerContext context) {

CodeGenerator codeGenerator = context.get(CODE_GEN);
if (codeGenerator == null) {
codeGenerator = new CodeGenerator(context);
}

return codeGenerator;
}

Expand All @@ -75,7 +72,7 @@ public CompiledJarFile generateTestModule(BLangPackage bLangTestablePackage) {
private CompiledJarFile generate(BPackageSymbol packageSymbol) {

// Split large BIR functions into smaller methods
largeMethodOptimizer = new LargeMethodOptimizer(symbolTable);
LargeMethodOptimizer largeMethodOptimizer = new LargeMethodOptimizer(symbolTable);
largeMethodOptimizer.splitLargeBIRFunctions(packageSymbol.bir);

// Desugar BIR to include the observations
Expand All @@ -93,9 +90,42 @@ private CompiledJarFile generate(BPackageSymbol packageSymbol) {

// TODO Get-rid of the following assignment
CompiledJarFile compiledJarFile = jvmPackageGen.generate(packageSymbol.bir, true);

cleanUpBirPackage(packageSymbol);
//Revert encoding identifier names
JvmDesugarPhase.replaceEncodedModuleIdentifiers(packageSymbol.bir, originalIdentifierMap);
return compiledJarFile;
}

private static void cleanUpBirPackage(BPackageSymbol packageSymbol) {
packageSymbol.birPackageFile = null;
BIRNode.BIRPackage bir = packageSymbol.bir;
for (BIRNode.BIRTypeDefinition typeDef : bir.typeDefs) {
for (BIRNode.BIRFunction attachedFunc : typeDef.attachedFuncs) {
cleanUpBirFunction(attachedFunc);
}
typeDef.annotAttachments = null;
}
bir.importedGlobalVarsDummyVarDcls.clear();
for (BIRNode.BIRFunction function : bir.functions) {
cleanUpBirFunction(function);
}
bir.annotations.clear();
bir.constants.clear();
bir.serviceDecls.clear();
}

private static void cleanUpBirFunction(BIRNode.BIRFunction function) {
function.receiver = null;
function.localVars = null;
function.returnVariable = null;
function.parameters = null;
function.basicBlocks = null;
function.errorTable = null;
function.workerChannels = null;
function.annotAttachments = null;
function.returnTypeAnnots = null;
function.dependentGlobalVars = null;
function.pathParams = null;
function.restPathParam = null;
}
}
Loading
Loading