Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into worker_change
Browse files Browse the repository at this point in the history
  • Loading branch information
lochana-chathura committed Nov 24, 2023
2 parents 71e46db + f59419a commit e0db559
Show file tree
Hide file tree
Showing 391 changed files with 100,002 additions and 1,414 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,13 @@ private void pushBalaToCustomRepo(Path balaFilePath) {

Path balaDestPath = repoPath.resolve(ProjectConstants.BALA_DIR_NAME)
.resolve(org).resolve(packageName).resolve(version).resolve(platform);
Path balaVersionPath = repoPath.resolve(ProjectConstants.BALA_DIR_NAME)
.resolve(org).resolve(packageName).resolve(version);
Path balaCachesPath = repoPath.resolve(ProjectConstants.CACHES_DIR_NAME + "-" + ballerinaShortVersion)
.resolve(org).resolve(packageName).resolve(version);
try {
if (Files.exists(balaDestPath)) {
ProjectUtils.deleteDirectory(balaDestPath);
if (Files.exists(balaVersionPath)) {
ProjectUtils.deleteDirectory(balaVersionPath);
}
if (Files.exists(balaCachesPath)) {
ProjectUtils.deleteDirectory(balaCachesPath);
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 @@ -468,7 +468,6 @@ public enum DiagnosticErrorCode implements DiagnosticCode {

FAIL_EXPR_NO_MATCHING_ERROR_RETURN_IN_ENCL_INVOKABLE(
"BCE3035", "fail.expr.no.matching.error.return.in.encl.invokable"),
INCOMPATIBLE_ON_FAIL_ERROR_DEFINITION("BCE3036", "on.fail.no.matching.error"),

START_REQUIRE_INVOCATION("BCE3037", "start.require.invocation"),
INVALID_EXPR_STATEMENT("BCE3038", "invalid.expr.statement"),
Expand Down Expand Up @@ -815,7 +814,8 @@ public enum DiagnosticErrorCode implements DiagnosticCode {
CANNOT_USE_ALTERNATE_WAIT_ACTION_WITHIN_MULTIPLE_WAIT_ACTION("BCE4056",
"cannot.use.alternate.wait.action.within.multiple.wait.action"),
EXPRESSION_OF_FUTURE_TYPE_EXPECTED("BCE4057", "future.expression.expected"),
INSTANTIATION_ERROR("BCE4058", "instantiation.error")
INSTANTIATION_ERROR("BCE4058", "instantiation.error"),
INVALID_BINDING_PATTERN_IN_ON_FAIL("BCE4059", "invalid.binding.pattern.in.on.fail")
;

private String diagnosticId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.wso2.ballerinalang.compiler.bir;

import io.ballerina.identifier.Utils;
import io.ballerina.tools.diagnostics.Location;
import io.ballerina.tools.text.LinePosition;
import io.ballerina.tools.text.LineRange;
Expand Down Expand Up @@ -364,11 +365,11 @@ public void visit(BLangTypeDefinition astTypeDefinition) {
BType type = getDefinedType(astTypeDefinition);
BType referredType = Types.getImpliedType(type);
BSymbol symbol = astTypeDefinition.symbol;
Name displayName = symbol.name;
String displayName = symbol.name.value;
if (referredType.tag == TypeTags.RECORD) {
BRecordType recordType = (BRecordType) referredType;
if (recordType.shouldPrintShape()) {
displayName = new Name(recordType.toString());
displayName = recordType.toString();
}
}

Expand All @@ -379,7 +380,7 @@ public void visit(BLangTypeDefinition astTypeDefinition) {
type,
new ArrayList<>(),
symbol.origin.toBIROrigin(),
displayName,
new Name(Utils.unescapeBallerina(displayName)),
symbol.originalName);
if (symbol.tag == SymTag.TYPE_DEF) {
BTypeReferenceType referenceType = ((BTypeDefinitionSymbol) symbol).referenceType;
Expand Down
Loading

0 comments on commit e0db559

Please sign in to comment.