diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/BuildCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/BuildCommand.java index 6c0ade458d3a..af3c5eefa90e 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/BuildCommand.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/BuildCommand.java @@ -198,6 +198,13 @@ public BuildCommand() { "generation") private String graalVMBuildOptions; + @CommandLine.Option(names = "--optimize", description = "generate optimized executable jar", defaultValue = "false") + private Boolean optimizeCodegen; + + @CommandLine.Option(names = "--optimize-report", description = "generate code generation optimization reports", + defaultValue = "false") + private Boolean optimizeReport; + @Override public void execute() { long start = 0; @@ -283,8 +290,8 @@ public void execute() { // resolve maven dependencies in Ballerina.toml .addTask(new ResolveMavenDependenciesTask(outStream)) // compile the modules - .addTask(new CompileTask(outStream, errStream, false, true, - isPackageModified, buildOptions.enableCache())) + .addTask(new CompileTask(outStream, errStream, false, true, false, isPackageModified, + buildOptions.enableCache())) .addTask(new CreateExecutableTask(outStream, this.output, null, false)) .addTask(new DumpBuildTimeTask(outStream), !project.buildOptions().dumpBuildTime()) .build(); @@ -317,7 +324,9 @@ private BuildOptions constructBuildOptions() { .setNativeImage(nativeImage) .disableSyntaxTreeCaching(disableSyntaxTreeCaching) .setGraalVMBuildOptions(graalVMBuildOptions) - .setShowDependencyDiagnostics(showDependencyDiagnostics); + .setShowDependencyDiagnostics(showDependencyDiagnostics) + .setOptimizeCodegen(optimizeCodegen) + .setOptimizeReport(optimizeReport); if (targetDir != null) { buildOptionsBuilder.targetDir(targetDir.toString()); diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PackCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PackCommand.java index b73c7ce39e8e..de675fb7afee 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PackCommand.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PackCommand.java @@ -260,8 +260,8 @@ public void execute() { .addTask(new CleanTargetDirTask(isPackageModified, buildOptions.enableCache()), isSingleFileBuild) .addTask(new RunBuildToolsTask(outStream), isSingleFileBuild) .addTask(new ResolveMavenDependenciesTask(outStream)) - .addTask(new CompileTask(outStream, errStream, true, false, - isPackageModified, buildOptions.enableCache())) + .addTask(new CompileTask(outStream, errStream, true, false, false, isPackageModified, + buildOptions.enableCache())) .addTask(new CreateBalaTask(outStream)) .addTask(new DumpBuildTimeTask(outStream), !project.buildOptions().dumpBuildTime()) .build(); diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ProfileCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ProfileCommand.java index cf4a64d2ce43..9dde1d50ff02 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ProfileCommand.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ProfileCommand.java @@ -195,7 +195,7 @@ private TaskExecutor createTaskExecutor(boolean isPackageModified, String[] args .addTask(new CleanTargetDirTask(isPackageModified, buildOptions.enableCache()), isSingleFileBuild) .addTask(new RunBuildToolsTask(outStream), isSingleFileBuild) .addTask(new ResolveMavenDependenciesTask(outStream)) - .addTask(new CompileTask(outStream, errStream, false, false, isPackageModified, + .addTask(new CompileTask(outStream, errStream, false, false, false, isPackageModified, buildOptions.enableCache())) .addTask(new CreateExecutableTask(outStream, null, null, false), false) .addTask(new DumpBuildTimeTask(outStream), false) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/RunCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/RunCommand.java index 3c8fa2d50983..a65fe11c4f3d 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/RunCommand.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/RunCommand.java @@ -262,8 +262,8 @@ public void execute() { // resolve maven dependencies in Ballerina.toml .addTask(new ResolveMavenDependenciesTask(outStream)) // compile the modules - .addTask(new CompileTask(outStream, errStream, false, false, - isPackageModified, buildOptions.enableCache())) + .addTask(new CompileTask(outStream, errStream, false, false, false, isPackageModified, + buildOptions.enableCache())) // .addTask(new CopyResourcesTask(), isSingleFileBuild) .addTask(new CreateExecutableTask(outStream, null, target, true)) .addTask(new RunExecutableTask(args, outStream, errStream, target)) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/TestCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/TestCommand.java index 0988b19d2d59..f15177075cb1 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/TestCommand.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/TestCommand.java @@ -209,6 +209,12 @@ public TestCommand() { @CommandLine.Option(names = "--cloud", description = "Enable cloud artifact generation") private String cloud; + @CommandLine.Option(names = "--optimize", description = "generate optimized executable jar", defaultValue = "false") + private Boolean optimizeCodegen; + + @CommandLine.Option(names = "--optimize-report", description = "generate code generation optimization reports", + defaultValue = "false") + private Boolean optimizeReport; private static final String testCmd = "bal test [--OPTIONS]\n" + " [ | ] [(-Ckey=value)...]"; @@ -374,8 +380,8 @@ public void execute() { TaskExecutor taskExecutor = new TaskExecutor.TaskBuilder() .addTask(new ResolveMavenDependenciesTask(outStream)) // resolve maven dependencies in Ballerina.toml // compile the modules - .addTask(new CompileTask(outStream, errStream, false, false, - isPackageModified, buildOptions.enableCache())) + .addTask(new CompileTask(outStream, errStream, false, false, true, isPackageModified, + buildOptions.enableCache())) // .addTask(new CopyResourcesTask(), listGroups) // merged with CreateJarTask .addTask(new CreateTestExecutableTask(outStream, groupList, disableGroupList, testList, listGroups, cliArgs, isParallelExecution), @@ -415,7 +421,9 @@ private BuildOptions constructBuildOptions() { .setEnableCache(enableCache) .disableSyntaxTreeCaching(disableSyntaxTreeCaching) .setGraalVMBuildOptions(graalVMBuildOptions) - .setShowDependencyDiagnostics(showDependencyDiagnostics); + .setShowDependencyDiagnostics(showDependencyDiagnostics) + .setOptimizeCodegen(optimizeCodegen) + .setOptimizeReport(optimizeReport); if (targetDir != null) { buildOptionsBuilder.targetDir(targetDir.toString()); diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java index 414485188df8..9fefdcf0c488 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java @@ -19,6 +19,7 @@ package io.ballerina.cli.task; import io.ballerina.cli.utils.BuildTime; +import io.ballerina.projects.BuildOptions; import io.ballerina.projects.CodeGeneratorResult; import io.ballerina.projects.CodeModifierResult; import io.ballerina.projects.JBallerinaBackend; @@ -64,23 +65,26 @@ public class CompileTask implements Task { private final transient PrintStream err; private final boolean compileForBalPack; private final boolean compileForBalBuild; + private final boolean compileForBalTest; private final boolean isPackageModified; private final boolean cachesEnabled; public CompileTask(PrintStream out, PrintStream err) { - this(out, err, false, false, true, false); + this(out, err, false, false, false, true, false); } public CompileTask(PrintStream out, PrintStream err, boolean compileForBalPack, boolean compileForBalBuild, + boolean compileForBalTest, boolean isPackageModified, boolean cachesEnabled) { this.out = out; this.err = err; this.compileForBalPack = compileForBalPack; this.compileForBalBuild = compileForBalBuild; + this.compileForBalTest = compileForBalTest; this.isPackageModified = isPackageModified; this.cachesEnabled = cachesEnabled; } @@ -112,6 +116,10 @@ public void execute(Project project) { if (this.compileForBalBuild) { addDiagnosticForProvidedPlatformLibs(project, diagnostics); } + if (this.compileForBalBuild || this.compileForBalTest) { + addDiagnosticForInvalidOptimizeReportFlagUsage(project, diagnostics); + } + long start = 0; if (project.currentPackage().compilationOptions().dumpGraph() @@ -329,6 +337,17 @@ private void addDiagnosticForProvidedPlatformLibs(Project project, List diagnostics) { + BuildOptions buildOptions = project.buildOptions(); + if (buildOptions.optimizeReport() && !buildOptions.optimizeCodegen()) { + DiagnosticInfo diagnosticInfo = new DiagnosticInfo( + ProjectDiagnosticErrorCode.INVALID_VERBOSE_FLAG_USAGE.diagnosticId(), + "--optimize-report flag can only be used with --optimize flag", DiagnosticSeverity.ERROR); + diagnostics.add(new PackageDiagnostic(diagnosticInfo, + project.currentPackage().descriptor().name().toString())); + } + } + /** * If CompileTask is triggered by `bal pack` command, and project does not have CompilerPlugin.toml or BalTool.toml, * skip the compilation if project is empty. The project should be evaluated for emptiness before calling this. diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java index 9ceae719f331..63598406879c 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java @@ -41,6 +41,7 @@ import static io.ballerina.cli.launcher.LauncherUtils.createLauncherException; import static io.ballerina.cli.utils.FileUtils.getFileNameWithoutExtension; import static io.ballerina.projects.util.ProjectConstants.BLANG_COMPILED_JAR_EXT; +import static io.ballerina.projects.util.ProjectConstants.BYTECODE_OPTIMIZED_JAR_SUFFIX; import static io.ballerina.projects.util.ProjectConstants.USER_DIR; /** @@ -93,6 +94,8 @@ public void execute(Project project) { out.println(warnings); } emitResult = jBallerinaBackend.emit(JBallerinaBackend.OutputType.GRAAL_EXEC, executablePath); + } else if (project.buildOptions().optimizeCodegen()) { + emitResult = jBallerinaBackend.emit(JBallerinaBackend.OutputType.OPTIMIZE_CODEGEN, executablePath); } else { emitResult = jBallerinaBackend.emit(JBallerinaBackend.OutputType.EXEC, executablePath); } @@ -119,7 +122,7 @@ public void execute(Project project) { throw createLauncherException(e.getMessage()); } - if (!project.buildOptions().nativeImage() && !isHideTaskOutput) { + if (!project.buildOptions().nativeImage() && !isHideTaskOutput && !project.buildOptions().optimizeCodegen()) { Path relativePathToExecutable = currentDir.relativize(executablePath); if (project.buildOptions().getTargetPath() != null) { @@ -134,6 +137,25 @@ public void execute(Project project) { } } + if (project.buildOptions().optimizeCodegen()) { + Path relativePathToExecutable = currentDir.relativize(executablePath); + String relativePathToExecutableString = + relativePathToExecutable.toString().replace(BLANG_COMPILED_JAR_EXT, BYTECODE_OPTIMIZED_JAR_SUFFIX); + String executablePathString = + executablePath.toString().replace(BLANG_COMPILED_JAR_EXT, BYTECODE_OPTIMIZED_JAR_SUFFIX); + + if (project.buildOptions().getTargetPath() != null) { + this.out.println("\t" + relativePathToExecutableString); + } else { + if (relativePathToExecutableString.contains("..") + || relativePathToExecutableString.contains("." + File.separator)) { + this.out.println("\t" + executablePathString); + } else { + this.out.println("\t" + relativePathToExecutableString); + } + } + } + // notify plugin // todo following call has to be refactored after introducing new plugin architecture BuildUtils.notifyPlugins(project, target); diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunExecutableTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunExecutableTask.java index 8030f13f2844..de4c88e18ad8 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunExecutableTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunExecutableTask.java @@ -108,4 +108,3 @@ private void runGeneratedExecutable(Project project) { } } } - diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/TestUtils.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/TestUtils.java index facd0066b192..ef2afb050ca4 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/TestUtils.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/TestUtils.java @@ -484,6 +484,7 @@ public static String getClassPath(JBallerinaBackend jBallerinaBackend, Package c List jarList = getModuleJarPaths(jBallerinaBackend, currentPackage); dependencies.removeAll(jarList); + dependencies.removeAll(jarResolver.optimizedJarLibraryPaths); StringJoiner classPath = joinClassPaths(dependencies); return classPath.toString(); diff --git a/compiler/ballerina-lang/build.gradle b/compiler/ballerina-lang/build.gradle index 14a268b35c68..9e23adbad303 100644 --- a/compiler/ballerina-lang/build.gradle +++ b/compiler/ballerina-lang/build.gradle @@ -29,6 +29,7 @@ dependencies { implementation "org.apache.commons:commons-compress:${project.apacheCommonsCompressVersion}" implementation 'io.netty:netty-buffer' implementation 'org.ow2.asm:asm' + implementation "org.ow2.asm:asm-tree:${project.ow2AsmTreeVersion}" implementation 'commons-io:commons-io' implementation 'com.github.zafarkhaja:java-semver' testImplementation ("guru.nidi:graphviz-java") { @@ -71,6 +72,7 @@ processResources { include 'ballerina-toml-schema.json' include 'compiler.properties' include 'dependencies-toml-schema.json' + include 'interop-dependencies.properties' include 'old-dependencies-toml-schema.json' include 'settings-toml-schema.json' include 'bal-tools-toml-schema.json' diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BuildOptions.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BuildOptions.java index 71c2d928b7b9..2044be659401 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BuildOptions.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BuildOptions.java @@ -138,6 +138,14 @@ public boolean showDependencyDiagnostics() { return toBooleanDefaultIfNull(this.showDependencyDiagnostics); } + public boolean optimizeCodegen() { + return this.compilationOptions.optimizeCodegen(); + } + + public boolean optimizeReport() { + return this.compilationOptions.optimizeReport(); + } + /** * Merge the given build options by favoring theirs if there are conflicts. * @@ -211,6 +219,8 @@ public BuildOptions acceptTheirs(BuildOptions theirOptions) { buildOptionsBuilder.setExportOpenAPI(compilationOptions.exportOpenAPI); buildOptionsBuilder.setExportComponentModel(compilationOptions.exportComponentModel); buildOptionsBuilder.setEnableCache(compilationOptions.enableCache); + buildOptionsBuilder.setOptimizeCodegen(compilationOptions.optimizeCodegen); + buildOptionsBuilder.setOptimizeReport(compilationOptions.optimizeReport); buildOptionsBuilder.setRemoteManagement(compilationOptions.remoteManagement); return buildOptionsBuilder.build(); @@ -250,7 +260,9 @@ public enum OptionName { NATIVE_IMAGE("graalvm"), EXPORT_COMPONENT_MODEL("exportComponentModel"), GRAAL_VM_BUILD_OPTIONS("graalvmBuildOptions"), - SHOW_DEPENDENCY_DIAGNOSTICS("showDependencyDiagnostics"); + SHOW_DEPENDENCY_DIAGNOSTICS("showDependencyDiagnostics"), + OPTIMIZE_CODEGEN("optimizeCodegen"), + OPTIMIZE_REPORT("optimizeReport"); private final String name; @@ -406,11 +418,21 @@ public BuildOptionsBuilder setNativeImage(Boolean value) { return this; } + public BuildOptionsBuilder setOptimizeCodegen(Boolean value) { + compilationOptionsBuilder.setOptimizeCodegen(value); + return this; + } + public BuildOptionsBuilder setRemoteManagement(Boolean value) { compilationOptionsBuilder.setRemoteManagement(value); return this; } + public BuildOptionsBuilder setOptimizeReport(Boolean value) { + compilationOptionsBuilder.setOptimizeReport(value); + return this; + } + public BuildOptionsBuilder setShowDependencyDiagnostics(Boolean value) { showDependencyDiagnostics = value; return this; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CodeGenOptimizationReportEmitter.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CodeGenOptimizationReportEmitter.java new file mode 100644 index 000000000000..61e79d06559f --- /dev/null +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CodeGenOptimizationReportEmitter.java @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.ballerina.projects; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import org.ballerinalang.model.elements.PackageID; +import org.ballerinalang.model.symbols.SymbolOrigin; +import org.wso2.ballerinalang.compiler.bir.model.BIRNode; +import org.wso2.ballerinalang.compiler.util.CompilerContext; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.PrintStream; +import java.io.Writer; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Emits time durations and optimized node details for codegen optimization. + * + * @since 2201.10.0 + */ +public final class CodeGenOptimizationReportEmitter { + + private static final CompilerContext.Key CODEGEN_OPTIMIZATION_REPORT_EMITTER_KEY = + new CompilerContext.Key<>(); + private final Map birOptimizationDurations; + private long nativeOptimizationDuration; + private final PrintStream out; + private static final String CODEGEN_OPTIMIZATION_REPORT = "codegen_optimization_report.json"; + + private CodeGenOptimizationReportEmitter(CompilerContext compilerContext) { + compilerContext.put(CODEGEN_OPTIMIZATION_REPORT_EMITTER_KEY, this); + this.out = System.out; + this.birOptimizationDurations = new ConcurrentHashMap<>(); + this.nativeOptimizationDuration = 0; + } + + public static CodeGenOptimizationReportEmitter getInstance(CompilerContext compilerContext) { + CodeGenOptimizationReportEmitter codegenOptimizationReportEmitter = + compilerContext.get(CODEGEN_OPTIMIZATION_REPORT_EMITTER_KEY); + if (codegenOptimizationReportEmitter == null) { + codegenOptimizationReportEmitter = new CodeGenOptimizationReportEmitter(compilerContext); + } + return codegenOptimizationReportEmitter; + } + + protected void flipBirOptimizationTimer(PackageID pkgId) { + long currentTime = System.currentTimeMillis(); + if (this.birOptimizationDurations.containsKey(pkgId)) { + long totalDuration = currentTime - this.birOptimizationDurations.get(pkgId); + this.birOptimizationDurations.put(pkgId, totalDuration); + } else { + this.birOptimizationDurations.put(pkgId, currentTime); + } + } + + protected void flipNativeOptimizationTimer() { + if (this.nativeOptimizationDuration == 0) { + this.nativeOptimizationDuration = System.currentTimeMillis(); + } else { + this.nativeOptimizationDuration = System.currentTimeMillis() - this.nativeOptimizationDuration; + } + } + + protected void emitBirOptimizationDuration() { + long totalDuration = this.birOptimizationDurations.values().stream().mapToLong(Long::longValue).sum(); + this.out.printf("Duration for unused BIR node analysis : %dms%n", totalDuration); + this.birOptimizationDurations.forEach((key, value) -> this.out.printf(" %s : %dms%n", key, value)); + this.out.println(); + } + + protected void emitNativeOptimizationDuration() { + this.out.println( + "Duration for Bytecode optimization (analysis + deletion) : " + this.nativeOptimizationDuration + "ms"); + this.nativeOptimizationDuration = 0; + } + + protected void emitOptimizedExecutableSize(Path executableFilePath) { + try { + float optimizedJarSize = Files.size(executableFilePath) / (1024f * 1024f); + System.out.printf("Optimized file size : %f MB%n", optimizedJarSize); + } catch (IOException e) { + throw new ProjectException("Failed to emit optimized executable size ", e); + } + } + + protected void emitCodegenOptimizationReport(Map invocationDataMap, + Path targetDirectoryPath) { + if (!Files.exists(targetDirectoryPath)) { + try { + Files.createDirectories(targetDirectoryPath); + } catch (IOException e) { + throw new ProjectException("Failed to create optimization report directory ", e); + } + } + + Map reports = new LinkedHashMap<>(invocationDataMap.size()); + invocationDataMap.forEach((key, value) -> reports.put(key.toString(), getCodegenOptimizationReport(value))); + Path jsonFilePath = targetDirectoryPath.resolve(CODEGEN_OPTIMIZATION_REPORT); + File jsonFile = new File(jsonFilePath.toString()); + + try (Writer writer = new OutputStreamWriter(new FileOutputStream(jsonFile), StandardCharsets.UTF_8)) { + Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create(); + String json = gson.toJson(reports); + writer.write(new String(json.getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8)); + } catch (IOException e) { + throw new ProjectException("Couldn't write data to optimization report file : ", e); + } + } + + private CodegenOptimizationReport getCodegenOptimizationReport( + UsedBIRNodeAnalyzer.InvocationData invocationData) { + return new CodegenOptimizationReport(getFunctionNames(invocationData.usedFunctions), + getFunctionNames(invocationData.unusedFunctions), getTypeDefNames(invocationData.usedTypeDefs), + getTypeDefNames(invocationData.unusedTypeDefs), invocationData.usedNativeClassPaths); + } + + private CodegenOptimizationReport.FunctionNames getFunctionNames(Set birFunctions) { + CodegenOptimizationReport.FunctionNames functionNames = + new CodegenOptimizationReport.FunctionNames(new LinkedHashSet<>(), new LinkedHashSet<>()); + birFunctions.forEach(birFunction -> { + if (birFunction.origin == SymbolOrigin.COMPILED_SOURCE) { + functionNames.sourceFunctions().add(getFunctionName(birFunction)); + } else { + functionNames.virtualFunctions().add(getFunctionName(birFunction)); + } + }); + return functionNames; + } + + private String getFunctionName(BIRNode.BIRFunction birFunction) { + if (birFunction.receiver == null) { + return birFunction.name.value; + } + + // If the function is an attached function, we have to emit the parent as well. + return birFunction.receiver.type.toString() + "." + birFunction.name.value; + } + + private CodegenOptimizationReport.TypeDefinitions getTypeDefNames(Set birTypeDefs) { + CodegenOptimizationReport.TypeDefinitions typeDefNames = + new CodegenOptimizationReport.TypeDefinitions(new LinkedHashSet<>(), new LinkedHashSet<>()); + birTypeDefs.forEach(birTypeDef -> { + if (birTypeDef.origin == SymbolOrigin.COMPILED_SOURCE) { + typeDefNames.sourceTypeDefinitions().add(birTypeDef.internalName.value); + } else { + typeDefNames.virtualTypeDefinitions().add(birTypeDef.internalName.value); + } + }); + return typeDefNames; + } +} diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CodegenOptimizationReport.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CodegenOptimizationReport.java new file mode 100644 index 000000000000..1dda5e93cee2 --- /dev/null +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CodegenOptimizationReport.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.ballerina.projects; + +import java.util.Set; + +/** + * Java record used to store codegen optimization report data to JSON. + * + * @param usedFunctionNames used BIR functions identified by the UsedBIRNodeAnalyzer + * @param unusedFunctionNames unused BIR functions identified by the UsedBIRNodeAnalyzer + * @param usedTypeDefNames used BIR type definitions identified by the UsedBIRNodeAnalyzer + * @param unusedTypeDefNames unused BIR type definitions identified by the UsedBIRNodeAnalyzer + * @param usedNativeClassPaths native class paths used by external functions + * + * @since 2201.10.0 + */ +record CodegenOptimizationReport(FunctionNames usedFunctionNames, FunctionNames unusedFunctionNames, + TypeDefinitions usedTypeDefNames, TypeDefinitions unusedTypeDefNames, + Set usedNativeClassPaths) { + + /** + * @param sourceFunctions BIR functions directly derived from source + * @param virtualFunctions BIR functions generated during desugar + */ + record FunctionNames(Set sourceFunctions, Set virtualFunctions) { + + } + + /** + * @param sourceTypeDefinitions BIR type definitions directly derived from source + * @param virtualTypeDefinitions BIR type definitions generated during desugar + */ + record TypeDefinitions(Set sourceTypeDefinitions, Set virtualTypeDefinitions) { + + } +} diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CompilationCache.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CompilationCache.java index a76bbb56be69..8ed6aee90c50 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CompilationCache.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CompilationCache.java @@ -37,9 +37,9 @@ public CompilationCache(Project project) { public abstract void cacheBir(ModuleName moduleName, ByteArrayOutputStream birContent); - public abstract Optional getPlatformSpecificLibrary(CompilerBackend compilerBackend, String libraryName); + public abstract Optional getPlatformSpecificLibrary(CompilerBackend compilerBackend, String libraryName, + boolean isOptimizedLibrary); - public abstract void cachePlatformSpecificLibrary(CompilerBackend compilerBackend, - String libraryName, - ByteArrayOutputStream libraryContent); + public abstract void cachePlatformSpecificLibrary(CompilerBackend compilerBackend, String libraryName, + ByteArrayOutputStream libraryContent, boolean isOptimizedLibrary); } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CompilationOptions.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CompilationOptions.java index a7214a614199..b777a1ef3512 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CompilationOptions.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CompilationOptions.java @@ -40,13 +40,15 @@ public class CompilationOptions { Boolean enableCache; Boolean disableSyntaxTree; Boolean remoteManagement; - - CompilationOptions(Boolean offlineBuild, Boolean observabilityIncluded, Boolean dumpBir, - Boolean dumpBirFile, String cloud, Boolean listConflictedClasses, Boolean sticky, - Boolean dumpGraph, Boolean dumpRawGraphs, Boolean withCodeGenerators, - Boolean withCodeModifiers, Boolean configSchemaGen, Boolean exportOpenAPI, - Boolean exportComponentModel, Boolean enableCache, Boolean disableSyntaxTree, - Boolean remoteManagement) { + Boolean optimizeCodegen; + Boolean optimizeReport; + + private CompilationOptions(Boolean offlineBuild, Boolean observabilityIncluded, Boolean dumpBir, + Boolean dumpBirFile, String cloud, Boolean listConflictedClasses, Boolean sticky, + Boolean dumpGraph, Boolean dumpRawGraphs, Boolean withCodeGenerators, + Boolean withCodeModifiers, Boolean configSchemaGen, Boolean exportOpenAPI, + Boolean exportComponentModel, Boolean enableCache, Boolean disableSyntaxTree, + Boolean optimizeCodegen, Boolean remoteManagement, Boolean optimizeReport) { this.offlineBuild = offlineBuild; this.observabilityIncluded = observabilityIncluded; this.dumpBir = dumpBir; @@ -62,6 +64,8 @@ public class CompilationOptions { this.exportOpenAPI = exportOpenAPI; this.exportComponentModel = exportComponentModel; this.enableCache = enableCache; + this.optimizeCodegen = optimizeCodegen; + this.optimizeReport = optimizeReport; this.disableSyntaxTree = disableSyntaxTree; this.remoteManagement = remoteManagement; } @@ -126,6 +130,14 @@ public boolean enableCache() { return toBooleanDefaultIfNull(this.enableCache); } + public boolean optimizeCodegen() { + return toBooleanDefaultIfNull(optimizeCodegen); + } + + public boolean optimizeReport() { + return toBooleanDefaultIfNull(optimizeReport); + } + boolean remoteManagement() { return toBooleanDefaultIfNull(this.remoteManagement); } @@ -218,6 +230,16 @@ CompilationOptions acceptTheirs(CompilationOptions theirOptions) { } else { compilationOptionsBuilder.setRemoteManagement(this.remoteManagement); } + if (theirOptions.optimizeCodegen != null) { + compilationOptionsBuilder.setOptimizeCodegen(theirOptions.optimizeCodegen); + } else { + compilationOptionsBuilder.setOptimizeCodegen(this.optimizeCodegen); + } + if (theirOptions.optimizeReport != null) { + compilationOptionsBuilder.setOptimizeReport(theirOptions.optimizeReport); + } else { + compilationOptionsBuilder.setOptimizeReport(this.optimizeReport); + } return compilationOptionsBuilder.build(); } @@ -272,7 +294,9 @@ public static class CompilationOptionsBuilder { private Boolean exportComponentModel; private Boolean enableCache; private Boolean disableSyntaxTree; + private static Boolean optimizeCodegen; private Boolean remoteManagement; + private static Boolean optimizeReport; public CompilationOptionsBuilder setOffline(Boolean value) { offline = value; @@ -349,6 +373,20 @@ CompilationOptionsBuilder setExportComponentModel(Boolean value) { return this; } + CompilationOptionsBuilder setOptimizeCodegen(Boolean value) { + if (optimizeCodegen == null) { + optimizeCodegen = value; + } + return this; + } + + CompilationOptionsBuilder setOptimizeReport(Boolean value) { + if (optimizeReport == null) { + optimizeReport = value; + } + return this; + } + public CompilationOptionsBuilder setEnableCache(Boolean value) { enableCache = value; return this; @@ -360,10 +398,10 @@ public CompilationOptionsBuilder setRemoteManagement(Boolean value) { } public CompilationOptions build() { - return new CompilationOptions(offline, observabilityIncluded, dumpBir, - dumpBirFile, cloud, listConflictedClasses, sticky, dumpGraph, dumpRawGraph, - withCodeGenerators, withCodeModifiers, configSchemaGen, exportOpenAPI, - exportComponentModel, enableCache, disableSyntaxTree, remoteManagement); + return new CompilationOptions(offline, observabilityIncluded, dumpBir, dumpBirFile, cloud, + listConflictedClasses, sticky, dumpGraph, dumpRawGraph, withCodeGenerators, withCodeModifiers, + configSchemaGen, exportOpenAPI, exportComponentModel, enableCache, disableSyntaxTree, + optimizeCodegen, remoteManagement, optimizeReport); } } } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CompilerBackend.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CompilerBackend.java index 794134edfba1..bfb1a8473fa8 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CompilerBackend.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CompilerBackend.java @@ -59,6 +59,15 @@ public abstract Collection platformLibraryDependencies(PackageI */ public abstract PlatformLibrary codeGeneratedLibrary(PackageId packageId, ModuleName moduleName); + /** + * Returns the generated optimized platform library of the specified module. + * + * @param packageId the {@code PackageId} of the package + * @param moduleName the name of the module in the package + * @return the generated optimized platform library of the specified module + */ + public abstract PlatformLibrary codeGeneratedOptimizedLibrary(PackageId packageId, ModuleName moduleName); + /** * Returns the generated platform library of the specified module required to run tests. * diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java index 995dbbdc9cb4..1d29e44c0370 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java @@ -33,25 +33,40 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveEntryPredicate; import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; import org.apache.commons.compress.archivers.zip.ZipFile; +import org.apache.commons.compress.utils.SeekableInMemoryByteChannel; import org.apache.commons.io.FilenameUtils; import org.ballerinalang.maven.Dependency; import org.ballerinalang.maven.MavenResolver; import org.ballerinalang.maven.Utils; import org.ballerinalang.maven.exceptions.MavenResolverException; +import org.ballerinalang.model.elements.Flag; +import org.ballerinalang.model.elements.PackageID; +import org.ballerinalang.model.types.SelectivelyImmutableReferenceType; import org.wso2.ballerinalang.compiler.CompiledJarFile; import org.wso2.ballerinalang.compiler.bir.codegen.CodeGenerator; +import org.wso2.ballerinalang.compiler.bir.codegen.JvmCodeGenUtil; +import org.wso2.ballerinalang.compiler.bir.codegen.bytecodeoptimizer.NativeDependencyOptimizationReportEmitter; +import org.wso2.ballerinalang.compiler.bir.codegen.bytecodeoptimizer.NativeDependencyOptimizer; import org.wso2.ballerinalang.compiler.bir.codegen.interop.InteropValidator; +import org.wso2.ballerinalang.compiler.bir.model.BIRNode; +import org.wso2.ballerinalang.compiler.semantics.model.SymbolTable; +import org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol; +import org.wso2.ballerinalang.compiler.semantics.model.symbols.UsedState; +import org.wso2.ballerinalang.compiler.semantics.model.types.BIntersectionType; import org.wso2.ballerinalang.compiler.tree.BLangPackage; import org.wso2.ballerinalang.compiler.util.CompilerContext; +import org.wso2.ballerinalang.util.Flags; import org.wso2.ballerinalang.util.Lists; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; +import java.nio.channels.SeekableByteChannel; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -64,17 +79,22 @@ import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.jar.JarInputStream; import java.util.jar.Manifest; import java.util.stream.Collectors; +import static io.ballerina.projects.util.CodegenOptimizationUtils.isWhiteListedModule; import static io.ballerina.projects.util.FileUtils.getFileNameWithoutExtension; import static io.ballerina.projects.util.ProjectConstants.BIN_DIR_NAME; import static io.ballerina.projects.util.ProjectConstants.DOT; @@ -95,7 +115,6 @@ public class JBallerinaBackend extends CompilerBackend { private static final String JAR_FILE_NAME_SUFFIX = ""; private static final HashSet excludeExtensions = new HashSet<>(Lists.of("DSA", "SF")); private static final String OS = System.getProperty("os.name").toLowerCase(Locale.getDefault()); - private final PackageResolution pkgResolution; private final JvmTarget jdkVersion; private final PackageContext packageContext; @@ -108,6 +127,14 @@ public class JBallerinaBackend extends CompilerBackend { private DiagnosticResult diagnosticResult; private boolean codeGenCompleted; private final List conflictedJars; + private final SymbolTable symbolTable; + private final UsedBIRNodeAnalyzer usedBIRNodeAnalyzer; + private final CodeGenOptimizationReportEmitter codeGenOptimizationReportEmitter; + private final Map optimizedJarStreams; + protected final Set unusedCompilerLevelPackageIds; + protected final Set unusedProjectLevelPackageIds; + protected final Set unusedModuleIds; + protected final Map> pkgWiseUsedNativeClassPaths; public static JBallerinaBackend from(PackageCompilation packageCompilation, JvmTarget jdkVersion) { return from(packageCompilation, jdkVersion, true); @@ -139,6 +166,22 @@ private JBallerinaBackend(PackageCompilation packageCompilation, JvmTarget jdkVe this.interopValidator = InteropValidator.getInstance(compilerContext); this.jvmCodeGenerator = CodeGenerator.getInstance(compilerContext); this.conflictedJars = new ArrayList<>(); + this.symbolTable = SymbolTable.getInstance(compilerContext); + this.usedBIRNodeAnalyzer = UsedBIRNodeAnalyzer.getInstance(compilerContext); + this.codeGenOptimizationReportEmitter = CodeGenOptimizationReportEmitter.getInstance(compilerContext); + if (packageCompilation.compilationOptions().optimizeCodegen()) { + this.optimizedJarStreams = new HashMap<>(); + this.unusedCompilerLevelPackageIds = new HashSet<>(); + this.unusedProjectLevelPackageIds = new HashSet<>(); + this.unusedModuleIds = new HashSet<>(); + this.pkgWiseUsedNativeClassPaths = new LinkedHashMap<>(); + } else { + this.optimizedJarStreams = Collections.emptyMap(); + this.unusedCompilerLevelPackageIds = Collections.emptySet(); + this.unusedProjectLevelPackageIds = Collections.emptySet(); + this.unusedModuleIds = Collections.emptySet(); + this.pkgWiseUsedNativeClassPaths = Collections.emptyMap(); + } performCodeGen(shrink); } @@ -151,6 +194,10 @@ private void performCodeGen(boolean shrink) { return; } + if (this.packageContext.project().buildOptions().optimizeCodegen() && + !this.packageContext.project().buildOptions().skipTests()) { + markTestDependenciesForDuplicateBIRGen(); + } List diagnostics = new ArrayList<>(); // add package resolution diagnostics diagnostics.addAll(this.packageContext.getResolution().diagnosticResult().allDiagnostics); @@ -159,14 +206,14 @@ private void performCodeGen(boolean shrink) { // collect compilation diagnostics List moduleDiagnostics = new ArrayList<>(); for (ModuleContext moduleContext : pkgResolution.topologicallySortedModuleList()) { - if (moduleContext.moduleId().packageId().equals(packageContext.packageId())) { - if (packageCompilation.diagnosticResult().hasErrors()) { - for (Diagnostic diagnostic : moduleContext.diagnostics()) { - moduleDiagnostics.add( - new PackageDiagnostic(diagnostic, moduleContext.descriptor(), moduleContext.project())); - } - continue; + Project project = moduleContext.project(); + if (moduleContext.moduleId().packageId().equals(packageContext.packageId()) && + packageCompilation.diagnosticResult().hasErrors()) { + for (Diagnostic diagnostic : moduleContext.diagnostics()) { + moduleDiagnostics.add( + new PackageDiagnostic(diagnostic, moduleContext.descriptor(), project)); } + continue; } // We can't generate backend code when one of its dependencies have errors. if (!this.packageContext.getResolution().diagnosticResult().hasErrors() && !hasErrors(moduleDiagnostics)) { @@ -174,20 +221,26 @@ private void performCodeGen(boolean shrink) { } for (Diagnostic diagnostic : moduleContext.diagnostics()) { if (this.packageContext.project().buildOptions().showDependencyDiagnostics() || - !ProjectKind.BALA_PROJECT.equals(moduleContext.project().kind()) || + !ProjectKind.BALA_PROJECT.equals(project.kind()) || (diagnostic.diagnosticInfo().severity() == DiagnosticSeverity.ERROR)) { moduleDiagnostics.add( - new PackageDiagnostic(diagnostic, moduleContext.descriptor(), moduleContext.project())); + new PackageDiagnostic(diagnostic, moduleContext.descriptor(), project)); } } - if (shrink) { ModuleContext.shrinkDocuments(moduleContext); } - if (moduleContext.project().kind() == ProjectKind.BALA_PROJECT) { + // Codegen happens later when --optimize flag is active. We cannot clean the BlangPkgs until then. + if (!project.buildOptions().optimizeCodegen() && + project.kind() == ProjectKind.BALA_PROJECT) { moduleContext.cleanBLangPackage(); } } + + if (this.packageContext.project().buildOptions().optimizeCodegen()) { + registerUnusedBIRNodes(); + optimizeAndCodegen(); + } // add compilation diagnostics diagnostics.addAll(moduleDiagnostics); // add plugin diagnostics @@ -197,6 +250,131 @@ private void performCodeGen(boolean shrink) { codeGenCompleted = true; } + private void registerUnusedBIRNodes() { + List topologicallySortedModuleList = pkgResolution.topologicallySortedModuleList(); + // Reversed the for loop because used BIRNode analysis should start from the root module. + // Root module is usually found last in the topologicallySortedModuleList. + for (int i = topologicallySortedModuleList.size() - 1; i >= 0; i--) { + ModuleContext moduleContext = topologicallySortedModuleList.get(i); + + // Default module is analyzed first to find its immediate dependencies. + // Its immediate dependent modules are marked as "used" and they are optimized after that. + // This process happens till all "used" modules are exhausted. + if (shouldOptimize(moduleContext) && (isRootModule(moduleContext) || moduleContext.isUsed())) { + this.usedBIRNodeAnalyzer.analyze(moduleContext.bLangPackage()); + updateNativeDependencyMap(moduleContext); + } + } + + this.codeGenOptimizationReportEmitter.emitBirOptimizationDuration(); + + if (this.packageContext.project().buildOptions().optimizeReport()) { + this.codeGenOptimizationReportEmitter.emitCodegenOptimizationReport( + this.usedBIRNodeAnalyzer.pkgWiseInvocationData, getOptimizationReportParentPath()); + } + } + + private Path getOptimizationReportParentPath() { + if (packageContext.project().kind() == ProjectKind.SINGLE_FILE_PROJECT) { + return this.packageContext.project().sourceRoot.toAbsolutePath().getParent(); + } + return this.packageContext.project().targetDir(); + } + + protected Set getOptimizedPackageIDs() { + return this.usedBIRNodeAnalyzer.pkgWiseInvocationData.keySet(); + } + + private void markTestDependenciesForDuplicateBIRGen() { + for (int i = pkgResolution.topologicallySortedModuleList().size() - 1; i >= 0; i--) { + ModuleContext moduleContext = pkgResolution.topologicallySortedModuleList().get(i); + BLangPackage bLangPackage = moduleContext.bLangPackage(); + + if (isRootModule(moduleContext) && bLangPackage.hasTestablePackage()) { + markCommonDependencies(bLangPackage); + return; + } + } + } + + private void markCommonDependencies(BLangPackage bLangPackage) { + Set buildPkgDependencies = new HashSet<>(); + Set testablePkgDependencies = new HashSet<>(); + collectDependencies(bLangPackage.symbol, buildPkgDependencies); + collectDependencies(bLangPackage.getTestablePkg().symbol, testablePkgDependencies); + + buildPkgDependencies.stream() + .filter(testablePkgDependencies::contains).filter(pkgSymbol -> !isWhiteListedModule(pkgSymbol.pkgID)) + .forEach(pkgSymbol -> { + pkgSymbol.shouldGenerateDuplicateBIR = true; + // Have to use a hashmap because the pkgIds get mutated later + JvmCodeGenUtil.duplicatePkgsMap.put( + pkgSymbol.pkgID.orgName + pkgSymbol.pkgID.getNameComps().toString(), + pkgSymbol.pkgID); + }); + } + + private void collectDependencies(BPackageSymbol pkgSymbol, Set currentDependencies) { + pkgSymbol.imports.forEach(dependency -> { + if (currentDependencies.add(dependency)) { + collectDependencies(dependency, currentDependencies); + } + }); + } + + private void optimizeAndCodegen() { + // Codegen cannot be done in the inverted order of the topologicallySortedModuleList. + // Therefore, we had to move it into another for loop. + for (ModuleContext moduleContext : pkgResolution.topologicallySortedModuleList()) { + if (shouldOptimize(moduleContext)) { + if (moduleContext.isUsed()) { + // Generate optimized thin JAR byte streams. + performOptimizedCodeGen(moduleContext); + } else if (!this.packageContext.project().buildOptions().skipTests()) { + moduleContext.bLangPackage().symbol.shouldGenerateDuplicateBIR = false; + String dupId = moduleContext.bLangPackage().packageID.orgName + + moduleContext.bLangPackage().packageID.getNameComps().toString(); + JvmCodeGenUtil.duplicatePkgsMap.remove(dupId); + performCodeGen(moduleContext, moduleContext.getCompilationCache()); + } else { + updateUnusedPkgMaps(moduleContext); + } + } + if (moduleContext.project().kind() == ProjectKind.BALA_PROJECT) { + moduleContext.cleanBLangPackage(); + } + } + } + + private boolean isRootModule(ModuleContext moduleContext) { + return pkgResolution.packageContext().defaultModuleContext().moduleId() == moduleContext.moduleId(); + } + + private boolean shouldOptimize(ModuleContext moduleContext) { + return platformLibraryGenerated(moduleContext) && !moduleContext.isWhiteListedModule(); + } + + /** + * Omitting the LangLibs and other modules that does not have BIRPkgNodes. + */ + private boolean platformLibraryGenerated(ModuleContext moduleContext) { + return moduleContext.currentCompilationState() == ModuleCompilationState.PLATFORM_LIBRARY_GENERATED; + } + + private void updateUnusedPkgMaps(ModuleContext ususedModuleContext) { + unusedModuleIds.add(ususedModuleContext.moduleId()); + unusedCompilerLevelPackageIds.add(ususedModuleContext.bLangPackage().symbol.pkgID); + if (ususedModuleContext.isDefaultModule()) { + unusedProjectLevelPackageIds.add(ususedModuleContext.moduleId().packageId()); + } + } + + private void updateNativeDependencyMap(ModuleContext moduleContext) { + pkgWiseUsedNativeClassPaths.putIfAbsent(moduleContext.moduleId().packageId(), new HashSet<>()); + pkgWiseUsedNativeClassPaths.get(moduleContext.moduleId().packageId()) + .addAll(moduleContext.bLangPackage().symbol.invocationData.usedNativeClassPaths); + } + private boolean hasErrors(List diagnostics) { for (Diagnostic diagnostic : diagnostics) { if (diagnostic.diagnosticInfo().severity() == DiagnosticSeverity.ERROR) { @@ -222,6 +400,7 @@ public EmitResult emit(OutputType outputType, Path filePath) { case GRAAL_EXEC -> emitGraalExecutable(filePath, emitResultDiagnostics); case EXEC -> emitExecutable(filePath, emitResultDiagnostics); case BALA -> emitBala(filePath); + case OPTIMIZE_CODEGEN -> emitOptimizedExecutable(filePath); default -> throw new RuntimeException("Unexpected output type: " + outputType); }; @@ -336,13 +515,18 @@ private List getPlatformLibraries(PackageId packageId) { @Override public PlatformLibrary codeGeneratedLibrary(PackageId packageId, ModuleName moduleName) { - return codeGeneratedLibrary(packageId, moduleName, PlatformLibraryScope.DEFAULT, JAR_FILE_NAME_SUFFIX); + return codeGeneratedLibrary(packageId, moduleName, PlatformLibraryScope.DEFAULT, JAR_FILE_NAME_SUFFIX, false); + } + + @Override + public PlatformLibrary codeGeneratedOptimizedLibrary(PackageId packageId, ModuleName moduleName) { + return codeGeneratedLibrary(packageId, moduleName, PlatformLibraryScope.DEFAULT, JAR_FILE_NAME_SUFFIX, true); } @Override public PlatformLibrary codeGeneratedTestLibrary(PackageId packageId, ModuleName moduleName) { return codeGeneratedLibrary(packageId, moduleName, PlatformLibraryScope.DEFAULT, - TEST_JAR_FILE_NAME_SUFFIX + JAR_FILE_NAME_SUFFIX); + TEST_JAR_FILE_NAME_SUFFIX + JAR_FILE_NAME_SUFFIX, false); } @Override @@ -364,37 +548,168 @@ public void performCodeGen(ModuleContext moduleContext, CompilationCache compila return; } boolean isRemoteMgtEnabled = moduleContext.project().buildOptions().compilationOptions().remoteManagement(); - CompiledJarFile compiledJarFile = jvmCodeGenerator.generate(bLangPackage, isRemoteMgtEnabled); + CompiledJarFile compiledJarFile = jvmCodeGenerator.generate(bLangPackage, false, isRemoteMgtEnabled); if (compiledJarFile == null) { throw new IllegalStateException("Missing generated jar, module: " + moduleContext.moduleName()); } String jarFileName = getJarFileName(moduleContext) + JAR_FILE_NAME_SUFFIX; try { ByteArrayOutputStream byteStream = JarWriter.write(compiledJarFile, getResources(moduleContext)); - compilationCache.cachePlatformSpecificLibrary(this, jarFileName, byteStream); + compilationCache.cachePlatformSpecificLibrary(this, jarFileName, byteStream, false); } catch (IOException e) { throw new ProjectException("Failed to cache generated jar, module: " + moduleContext.moduleName()); } // skip generation of the test jar if --with-tests option is not provided - if (moduleContext.project().buildOptions().skipTests()) { + if (moduleContext.project().buildOptions().skipTests() || !bLangPackage.hasTestablePackage()) { return; } - if (!bLangPackage.hasTestablePackage()) { + String testJarFileName = jarFileName + TEST_JAR_FILE_NAME_SUFFIX; + CompiledJarFile compiledTestJarFile = + jvmCodeGenerator.generateTestModule(bLangPackage.testablePkgs.get(0), isRemoteMgtEnabled); + try { + ByteArrayOutputStream byteStream = JarWriter.write(compiledTestJarFile, getAllResources(moduleContext)); + compilationCache.cachePlatformSpecificLibrary(this, testJarFileName, byteStream, false); + } catch (IOException e) { + throw new ProjectException("Failed to cache generated test jar, module: " + moduleContext.moduleName()); + } + } + + public void performOptimizedCodeGen(ModuleContext moduleContext) { + BLangPackage bLangPackage = moduleContext.bLangPackage(); + boolean isRemoteMgtEnabled = moduleContext.project().buildOptions().compilationOptions().remoteManagement(); + + if (bLangPackage.symbol.shouldGenerateDuplicateBIR) { + duplicateCodegen(moduleContext, isRemoteMgtEnabled); + } + + if (isRootModule(moduleContext)) { + JvmCodeGenUtil.markIsRootPackage(); + } + optimizeBirPackage(bLangPackage.symbol); + + interopValidator.validate(moduleContext.moduleId(), this, bLangPackage); + if (bLangPackage.getErrorCount() > 0) { return; } + CompiledJarFile compiledJarFile = + jvmCodeGenerator.generate(bLangPackage, bLangPackage.symbol.shouldGenerateDuplicateBIR, + isRemoteMgtEnabled); + if (compiledJarFile == null) { + throw new IllegalStateException("Missing generated jar, module: " + moduleContext.moduleName()); + } + String jarFileName = getJarFileName(moduleContext) + JAR_FILE_NAME_SUFFIX; + if (bLangPackage.symbol.shouldGenerateDuplicateBIR) { + jarFileName = getJarFileName(moduleContext) + "_OPTIMIZED" + JAR_FILE_NAME_SUFFIX; + } + try { + ByteArrayOutputStream byteStream = JarWriter.write(compiledJarFile, getResources(moduleContext)); + if (!this.packageContext.project().buildOptions().skipTests()) { + moduleContext.getCompilationCache().cachePlatformSpecificLibrary(this, jarFileName, byteStream, true); + } else { + optimizedJarStreams.putIfAbsent(jarFileName, byteStream); + } + } catch (IOException e) { + throw new ProjectException("Failed to cache generated jar, module: " + moduleContext.moduleName()); + } + + // TODO merge this with performCodeGen + // skip generation of the test jar if --with-tests option is not provided + if (moduleContext.project().buildOptions().skipTests() || !bLangPackage.hasTestablePackage()) { + return; + } + + // Both invocation data are the same + // TODO do the merging inside usedBIRNodeAnalyzer + bLangPackage.testablePkgs.get(0).symbol.invocationData = bLangPackage.symbol.invocationData; String testJarFileName = jarFileName + TEST_JAR_FILE_NAME_SUFFIX; CompiledJarFile compiledTestJarFile = jvmCodeGenerator.generateTestModule(bLangPackage.testablePkgs.get(0), isRemoteMgtEnabled); try { ByteArrayOutputStream byteStream = JarWriter.write(compiledTestJarFile, getAllResources(moduleContext)); - compilationCache.cachePlatformSpecificLibrary(this, testJarFileName, byteStream); + moduleContext.getCompilationCache().cachePlatformSpecificLibrary(this, testJarFileName, byteStream, true); } catch (IOException e) { throw new ProjectException("Failed to cache generated test jar, module: " + moduleContext.moduleName()); } } + private void duplicateCodegen(ModuleContext moduleContext, boolean isRemoteMgtEnabled) { + BLangPackage bLangPackage = moduleContext.bLangPackage(); + BIRNode.BIRPackage optimizableBirPkg = bLangPackage.symbol.bir; + bLangPackage.symbol.bir = bLangPackage.symbol.duplicateBir; + interopValidator.validate(moduleContext.moduleId(), this, bLangPackage); + if (bLangPackage.getErrorCount() > 0) { + return; + } + CompiledJarFile originalJarFile = jvmCodeGenerator.generate(bLangPackage, false, isRemoteMgtEnabled); + if (originalJarFile == null) { + throw new IllegalStateException("Missing generated jar, module: " + moduleContext.moduleName()); + } + + bLangPackage.symbol.bir = optimizableBirPkg; + String jarFileName = getJarFileName(moduleContext) + JAR_FILE_NAME_SUFFIX; + try { + ByteArrayOutputStream byteStream = JarWriter.write(originalJarFile, getResources(moduleContext)); + moduleContext.getCompilationCache().cachePlatformSpecificLibrary(this, jarFileName, byteStream, false); + } catch (IOException e) { + throw new ProjectException("Failed to cache generated jar, module: " + moduleContext.moduleName()); + } + } + + private void optimizeBirPackage(BPackageSymbol bPackageSymbol) { + UsedBIRNodeAnalyzer.InvocationData invocationData = bPackageSymbol.invocationData; + BIRNode.BIRPackage birPackage = bPackageSymbol.bir; + + if (!invocationData.moduleIsUsed) { + // Thrown if the compiler tries to pack an UNUSED thin JAR to the final executable with --optimize flag + throw new IllegalStateException( + String.format( + "BIR Package %s should not be packed to final executable because it is not used!", + bPackageSymbol.getName())); + } + + bPackageSymbol.imports.removeIf(pkgSymbol -> + pkgSymbol != null && unusedCompilerLevelPackageIds.contains(pkgSymbol.pkgID)); + birPackage.importModules.removeIf(module -> isUnusedPkgID(module.packageID)); + birPackage.functions.removeIf(currentFunc -> currentFunc.getUsedState() == UsedState.UNUSED); + birPackage.typeDefs.removeIf(typeDef -> typeDef.getUsedState() == UsedState.UNUSED); + optimizeImmutableTypeDefs(invocationData, bPackageSymbol.pkgID); + + // FP optimization for functions with default params + birPackage.globalVars.removeIf(gVar -> gVar.getUsedState() == UsedState.UNUSED); + invocationData.getFpDataPool().forEach(UsedBIRNodeAnalyzer.FunctionPointerData::deleteIfUnused); + + // TODO Attached function optimization with polymorphism handling + } + + private boolean isUnusedPkgID(PackageID packageID) { + return unusedCompilerLevelPackageIds.stream().anyMatch(unusedPkgID -> + unusedPkgID.nameComps.equals(packageID.nameComps)); + } + + private void optimizeImmutableTypeDefs(UsedBIRNodeAnalyzer.InvocationData invocationData, PackageID pkgID) { + Map immutableTypeMap = + symbolTable.immutableTypeMaps.get(getPackageIdString(pkgID)); + + if (immutableTypeMap == null) { + return; + } + + invocationData.unusedTypeDefs.forEach(deadTypeDef -> { + if (Flags.unMask(deadTypeDef.type.flags).contains(Flag.READONLY)) { + deadTypeDef.referencedTypes.forEach(immutableTypeMap::remove); + } + }); + + // Some types don't have an associated BIRTypeDefinition. These types have to be removed manually. + immutableTypeMap.entrySet().removeIf(entry -> !entry.getValue().isUsed); + } + + public static String getPackageIdString(PackageID packageID) { + return packageID.isTestPkg ? packageID + "_testable" : packageID.toString(); + } + @Override public String libraryFileExtension() { return JAR_FILE_EXTENSION; @@ -511,6 +826,85 @@ private void sortAndCopyJars(Collection jarLibraries, ZipArchiveOutp } } + private void assembleOptimizedExecutableJar(Path executableFilePath, + Manifest manifest, + Collection jarLibraries) throws IOException { + String birOptimizedJarPath = executableFilePath.toString() + .replace(ProjectConstants.BLANG_COMPILED_JAR_EXT, ProjectConstants.BIR_OPTIMIZED_JAR_SUFFIX); + String bytecodeOptimizedJarPath = executableFilePath.toString() + .replace(ProjectConstants.BLANG_COMPILED_JAR_EXT, ProjectConstants.BYTECODE_OPTIMIZED_JAR_SUFFIX); + + ZipArchiveOutputStream outStream = new ZipArchiveOutputStream( + new BufferedOutputStream(new FileOutputStream(birOptimizedJarPath))); + try { + writeManifest(manifest, outStream); + + // Sort jar libraries list to avoid inconsistent jar reporting + List sortedJarLibraries = jarLibraries.stream() + .sorted(Comparator.comparing(jarLibrary -> jarLibrary.path().getFileName())) + .collect(Collectors.toList()); + + // Used to prevent adding duplicated entries during the final jar creation. + HashMap copiedEntries = new HashMap<>(); + // Used to process SPI related metadata entries separately. The reason is unlike the other entry types, + // service loader related information should be merged together in the final executable jar creation. + HashMap serviceEntries = new HashMap<>(); + + // Copy all the jars + for (JarLibrary library : sortedJarLibraries) { + copyJar(outStream, library, copiedEntries, serviceEntries); + } + + // Clean optimized JAR byte streams + optimizedJarStreams.clear(); + + // Copy merged spi services. + for (Map.Entry entry : serviceEntries.entrySet()) { + String s = entry.getKey(); + StringBuilder service = entry.getValue(); + JarArchiveEntry e = new JarArchiveEntry(s); + outStream.putArchiveEntry(e); + outStream.write(service.toString().getBytes(StandardCharsets.UTF_8)); + outStream.closeArchiveEntry(); + } + outStream.close(); + + this.codeGenOptimizationReportEmitter.flipNativeOptimizationTimer(); + ZipFile birOptimizedFatJar = new ZipFile(birOptimizedJarPath); + + Set startPoints = new LinkedHashSet<>(); + startPoints.add(getMainClassFileName(this.packageContext())); + ZipArchiveOutputStream optimizedJarStream = + new ZipArchiveOutputStream(new FileOutputStream(bytecodeOptimizedJarPath)); + NativeDependencyOptimizer nativeDependencyOptimizer = + new NativeDependencyOptimizer(startPoints, birOptimizedFatJar, optimizedJarStream); + + nativeDependencyOptimizer.analyzeWhiteListedClasses(); + nativeDependencyOptimizer.analyzeUsedClasses(); + nativeDependencyOptimizer.copyUsedEntries(); + optimizedJarStream.close(); + + this.codeGenOptimizationReportEmitter.flipNativeOptimizationTimer(); + this.codeGenOptimizationReportEmitter.emitNativeOptimizationDuration(); + this.codeGenOptimizationReportEmitter.emitOptimizedExecutableSize(Path.of(bytecodeOptimizedJarPath)); + if (this.packageContext.project().buildOptions().optimizeReport()) { + NativeDependencyOptimizationReportEmitter.emitCodegenOptimizationReport( + nativeDependencyOptimizer.getNativeDependencyOptimizationReport(), + getOptimizationReportParentPath()); + } + } catch (IOException e) { + throw new IOException(e); + } + } + + private static String getMainClassFileName(PackageContext rootPkgContext) { + if (rootPkgContext.project().kind() == ProjectKind.SINGLE_FILE_PROJECT) { + return "$_init"; + } + + return String.format("%s/%s/0/$_init", rootPkgContext.descriptor().org(), rootPkgContext.descriptor().name()); + } + private void writeManifest(Manifest manifest, ZipArchiveOutputStream outStream) throws IOException { JarArchiveEntry e = new JarArchiveEntry(JarFile.MANIFEST_NAME); outStream.putArchiveEntry(e); @@ -518,14 +912,21 @@ private void writeManifest(Manifest manifest, ZipArchiveOutputStream outStream) outStream.closeArchiveEntry(); } - private Manifest createManifest() { + private Manifest createManifest(boolean optimizeCodegen) { // Getting the jarFileName of the root module of this executable PlatformLibrary rootModuleJarFile = codeGeneratedLibrary(packageContext.packageId(), packageContext.defaultModuleContext().moduleName()); String mainClassName; - try (JarInputStream jarStream = new JarInputStream(Files.newInputStream(rootModuleJarFile.path()))) { + try { + JarInputStream jarStream; + if (optimizeCodegen) { + jarStream = getOptimizedJarInputStream(rootModuleJarFile.path().toString()); + } else { + jarStream = new JarInputStream(Files.newInputStream(rootModuleJarFile.path())); + } Manifest mf = jarStream.getManifest(); + jarStream.close(); mainClassName = (String) mf.getMainAttributes().get(Attributes.Name.MAIN_CLASS); } catch (IOException e) { throw new RuntimeException("Generated jar file cannot be found for the module: " + @@ -548,6 +949,24 @@ private Manifest createTestManifest() { return manifest; } + + // TODO Optimize the condition to lookup the byteArrayOutputStream + private JarInputStream getOptimizedJarInputStream(String jarPath) { + AtomicReference jarInputStream = new AtomicReference<>(); + optimizedJarStreams.forEach((key, value) -> { + if (jarPath.contains(key)) { + ByteArrayInputStream tempInStream = new ByteArrayInputStream(value.toByteArray()); + try { + jarInputStream.set(new JarInputStream(tempInStream)); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + }); + + return jarInputStream.get(); + } + /** * Copies a given jar file into the executable fat jar. * @@ -558,10 +977,9 @@ private Manifest createTestManifest() { * @throws IOException If jar file copying is failed. */ private void copyJar(ZipArchiveOutputStream outStream, JarLibrary jarLibrary, - HashMap copiedEntries, HashMap services) throws IOException { - - ZipFile zipFile = new ZipFile(jarLibrary.path().toFile()); + HashMap copiedEntries, HashMap services) + throws IOException { + ZipFile zipFile = getZipFile(jarLibrary); ZipArchiveEntryPredicate predicate = entry -> { String entryName = entry.getName(); if (entryName.equals("META-INF/MANIFEST.MF")) { @@ -615,6 +1033,28 @@ private void copyJar(ZipArchiveOutputStream outStream, JarLibrary jarLibrary, zipFile.close(); } + private ZipFile getZipFile(JarLibrary jarLibrary) throws IOException { + ByteArrayOutputStream optimizedStream = getOptimizedStream(jarLibrary.path().toString()); + if (optimizedStream.size() == 0) { + return new ZipFile(jarLibrary.path().toFile()); + } + SeekableByteChannel seekableByteChannel = new SeekableInMemoryByteChannel(optimizedStream.toByteArray()); + return new ZipFile(seekableByteChannel); + } + + private ByteArrayOutputStream getOptimizedStream(String pathName) { + if (this.optimizedJarStreams == null) { + return new ByteArrayOutputStream(0); + } + + for (Map.Entry entry : this.optimizedJarStreams.entrySet()) { + if (pathName.contains(entry.getKey())) { + return entry.getValue(); + } + } + return new ByteArrayOutputStream(0); + } + private static boolean isCopiedEntry(String entryName, HashMap copiedEntries) { return copiedEntries.containsKey(entryName); } @@ -626,20 +1066,20 @@ private static boolean isExcludedEntry(String entryName) { private PlatformLibrary codeGeneratedLibrary(PackageId packageId, ModuleName moduleName, PlatformLibraryScope scope, - String fileNameSuffix) { + String fileNameSuffix, boolean isOptimizedLibrary) { Package pkg = packageCache.getPackageOrThrow(packageId); ProjectEnvironment projectEnvironment = pkg.project().projectEnvironmentContext(); CompilationCache compilationCache = projectEnvironment.getService(CompilationCache.class); String jarFileName = getJarFileName(pkg.packageContext().moduleContext(moduleName)) + fileNameSuffix; Optional platformSpecificLibrary = compilationCache.getPlatformSpecificLibrary( - this, jarFileName); + this, jarFileName, isOptimizedLibrary); return new JarLibrary(platformSpecificLibrary.orElseThrow( () -> new IllegalStateException("Cannot find the generated jar library for module: " + moduleName)), scope); } private Path emitExecutable(Path executableFilePath, List emitResultDiagnostics) { - Manifest manifest = createManifest(); + Manifest manifest = createManifest(false); Collection jarLibraries = jarResolver.getJarFilePathsRequiredForExecution(); // Add warning when provided platform dependencies are found addProvidedDependencyWarning(emitResultDiagnostics); @@ -666,6 +1106,19 @@ private Path emitTestExecutable(Path executableFilePath, HashSet jar return executableFilePath; } + private Path emitOptimizedExecutable(Path executableFilePath) { + Manifest manifest = createManifest(true); + Collection jarLibraries = + jarResolver.getJarFilePathsRequiredForExecution(true); + try { + assembleOptimizedExecutableJar(executableFilePath, manifest, jarLibraries); + } catch (IOException e) { + throw new ProjectException("error while creating the executable jar file for package '" + + this.packageContext.packageName().toString() + "' : " + e.getMessage(), e); + } + return executableFilePath; + } + private Path emitGraalExecutable(Path executableFilePath, List emitResultDiagnostics) { // Run create executable emitExecutable(executableFilePath, emitResultDiagnostics); @@ -849,7 +1302,8 @@ public enum OutputType { EXEC("exec"), BALA("bala"), GRAAL_EXEC("graal_exec"), - TEST("test") + TEST("test"), + OPTIMIZE_CODEGEN("optimize_codegen") ; private final String value; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JarResolver.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JarResolver.java index b037d540fcc3..dc3541b82317 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JarResolver.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JarResolver.java @@ -26,20 +26,32 @@ import io.ballerina.tools.diagnostics.DiagnosticInfo; import io.ballerina.tools.diagnostics.DiagnosticSeverity; import org.apache.maven.artifact.versioning.ComparableVersion; +import org.ballerinalang.model.elements.PackageID; +import org.wso2.ballerinalang.compiler.bir.codegen.JvmCodeGenUtil; import org.wso2.ballerinalang.compiler.util.CompilerUtils; +import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; +import java.nio.file.Path; +import java.nio.file.Paths; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.jar.JarFile; +import java.util.zip.ZipEntry; import static io.ballerina.identifier.Utils.encodeNonFunctionIdentifier; +import static io.ballerina.projects.util.CodegenOptimizationConstants.BALLERINAI_OBSERVE; +import static io.ballerina.projects.util.CodegenOptimizationConstants.BALLERINAX; +import static io.ballerina.projects.util.CodegenOptimizationConstants.BALLERINA_OBSERVE; +import static io.ballerina.projects.util.CodegenOptimizationConstants.DOT_DRIVER; import static io.ballerina.projects.util.ProjectConstants.ANON_ORG; import static io.ballerina.projects.util.ProjectConstants.DOT; @@ -61,6 +73,7 @@ public class JarResolver { private List providedPlatformLibs; private ClassLoader classLoaderWithAllJars; + public Set optimizedJarLibraryPaths = new HashSet<>(); JarResolver(JBallerinaBackend jBalBackend, PackageResolution pkgResolution) { this.jBalBackend = jBalBackend; @@ -86,13 +99,17 @@ public List providedPlatformLibs() { return providedPlatformLibs; } - // TODO These method names are too long. Refactor them soon public Collection getJarFilePathsRequiredForExecution() { + return getJarFilePathsRequiredForExecution(false); + } + + // TODO These method names are too long. Refactor them soon + public Collection getJarFilePathsRequiredForExecution(boolean optimizeFinalExecutable) { // 1) Add this root package related jar files Set jarFiles = new HashSet<>(); addCodeGeneratedLibraryPaths(rootPackageContext, PlatformLibraryScope.DEFAULT, jarFiles); - addPlatformLibraryPaths(rootPackageContext, PlatformLibraryScope.DEFAULT, jarFiles); - addPlatformLibraryPaths(rootPackageContext, PlatformLibraryScope.PROVIDED, jarFiles); + addPlatformLibraryPaths(rootPackageContext, PlatformLibraryScope.DEFAULT, jarFiles, optimizeFinalExecutable); + addPlatformLibraryPaths(rootPackageContext, PlatformLibraryScope.PROVIDED, jarFiles, optimizeFinalExecutable); // 2) Get all the dependencies of the root package including transitives. // Filter out PackageDependencyScope.TEST_ONLY scope dependencies and lang libs @@ -100,13 +117,16 @@ public Collection getJarFilePathsRequiredForExecution() { .stream() .filter(pkgDep -> pkgDep.scope() != PackageDependencyScope.TEST_ONLY) .filter(pkgDep -> !pkgDep.packageInstance().descriptor().isLangLibPackage()) + .filter(pkgDep -> !optimizeFinalExecutable || !isUnusedPkgDependency(pkgDep)) .map(pkgDep -> pkgDep.packageInstance().packageContext()) .forEach(pkgContext -> { // Add generated thin jar of every module in the package represented by the packageContext addCodeGeneratedLibraryPaths(pkgContext, PlatformLibraryScope.DEFAULT, jarFiles); // All platform-specific libraries(specified in Ballerina.toml) having the default scope - addPlatformLibraryPaths(pkgContext, PlatformLibraryScope.DEFAULT, jarFiles); - addPlatformLibraryPaths(pkgContext, PlatformLibraryScope.PROVIDED, jarFiles, true); + addPlatformLibraryPaths(pkgContext, PlatformLibraryScope.DEFAULT, jarFiles, + optimizeFinalExecutable); + addPlatformLibraryPaths(pkgContext, PlatformLibraryScope.PROVIDED, jarFiles, true, + optimizeFinalExecutable); }); // 3) Add the runtime library path @@ -118,44 +138,95 @@ public Collection getJarFilePathsRequiredForExecution() { return jarFiles; } + private boolean isUnusedPkgDependency(ResolvedPackageDependency pkgDependency) { + if (!jBalBackend.unusedProjectLevelPackageIds.contains(pkgDependency.packageId())) { + return false; + } + for (ModuleId moduleId : pkgDependency.packageInstance().packageContext().moduleIds()) { + if (!jBalBackend.unusedModuleIds.contains(moduleId)) { + return false; + } + } + return true; + } + private void addCodeGeneratedLibraryPaths(PackageContext packageContext, PlatformLibraryScope scope, Set libraryPaths) { for (ModuleId moduleId : packageContext.moduleIds()) { + if (packageContext.project().buildOptions().optimizeCodegen() && + jBalBackend.unusedModuleIds.contains(moduleId)) { + continue; + } ModuleContext moduleContext = packageContext.moduleContext(moduleId); + PackageID pkgID = moduleContext.descriptor().moduleCompilationId(); + + if (packageContext.project().buildOptions().optimizeCodegen() && + !this.rootPackageContext.project().buildOptions().skipTests() && + this.jBalBackend.getOptimizedPackageIDs().contains(pkgID)) { + addOptimizedLibraryPaths(packageContext, scope, libraryPaths, moduleContext, pkgID); + } + PlatformLibrary generatedJarLibrary = jBalBackend.codeGeneratedLibrary( packageContext.packageId(), moduleContext.moduleName()); libraryPaths.add(new JarLibrary(generatedJarLibrary.path(), scope, getPackageName(packageContext))); } } + private void addOptimizedLibraryPaths(PackageContext packageContext, PlatformLibraryScope scope, + Set libraryPaths, ModuleContext moduleContext, + PackageID pkgID) { + PlatformLibrary generatedOptimizedLibrary = jBalBackend.codeGeneratedOptimizedLibrary( + packageContext.packageId(), moduleContext.moduleName()); + Path optimizedJarLibraryPath = Paths.get(generatedOptimizedLibrary.path().toAbsolutePath().toString()); + + if (JvmCodeGenUtil.duplicatePkgsMap.containsKey(pkgID.orgName + pkgID.getNameComps().toString())) { + // Package is an optimized duplicated pkg. + // This means the package is a common dependency of both testable and build projects. + optimizedJarLibraryPath = + Path.of(optimizedJarLibraryPath.toString().replace(ProjectConstants.BLANG_COMPILED_JAR_EXT, + ProjectConstants.BYTECODE_OPTIMIZED_JAR_SUFFIX)); + } + + libraryPaths.add(new JarLibrary(optimizedJarLibraryPath, scope, + getPackageName(packageContext) + ProjectConstants.BYTECODE_OPTIMIZED_JAR_SUFFIX)); + optimizedJarLibraryPaths.add(optimizedJarLibraryPath); + } + private void addPlatformLibraryPaths(PackageContext packageContext, PlatformLibraryScope scope, - Set libraryPaths) { - addPlatformLibraryPaths(packageContext, scope, libraryPaths, false); + Set libraryPaths, boolean addOnlyUsedLibraries) { + addPlatformLibraryPaths(packageContext, scope, libraryPaths, false, addOnlyUsedLibraries); } private void addPlatformLibraryPaths(PackageContext packageContext, PlatformLibraryScope scope, Set libraryPaths, - boolean addProvidedJars) { + boolean addProvidedJars, boolean addOnlyUsedLibraries) { // Add all the jar library dependencies of current package (packageId) - Collection otherJarDependencies = jBalBackend.platformLibraryDependencies( - packageContext.packageId(), scope); + PackageId packageId = packageContext.packageId(); + Collection otherJarDependencies = jBalBackend.platformLibraryDependencies(packageId, scope); + Set usedNativeClassPaths = getUsedNativeClassPaths(addOnlyUsedLibraries, packageId); + if (addProvidedJars) { providedPlatformLibs.addAll(otherJarDependencies); } + for (PlatformLibrary otherJarDependency : otherJarDependencies) { JarLibrary newEntry = (JarLibrary) otherJarDependency; - if (newEntry.groupId().isEmpty() || newEntry.artifactId().isEmpty() || newEntry.version().isEmpty()) { + // If there are more than one platform dependency, there could be secondary dependencies + if (addOnlyUsedLibraries && otherJarDependencies.size() == 1 && + !isUsedDependency(newEntry, usedNativeClassPaths)) { + continue; + } + if (hasEmptyIdOrVersion(newEntry)) { libraryPaths.add(new JarLibrary(otherJarDependency.path(), scope, getPackageName(packageContext))); continue; } if (libraryPaths.contains(newEntry)) { JarLibrary existingEntry = libraryPaths.stream().filter(jarLibrary1 -> jarLibrary1.equals(newEntry)).findAny().orElseThrow(); - if (existingEntry.groupId().isEmpty() || existingEntry.artifactId().isEmpty() || - existingEntry.version().isEmpty()) { + if (hasEmptyIdOrVersion(existingEntry)) { continue; } ComparableVersion existingVersion = new ComparableVersion(existingEntry.version().orElseThrow()); @@ -180,6 +251,48 @@ private void addPlatformLibraryPaths(PackageContext packageContext, } } + private Set getUsedNativeClassPaths(boolean addOnlyUsedLibraries, PackageId packageID) { + if (addOnlyUsedLibraries) { + return jBalBackend.pkgWiseUsedNativeClassPaths.getOrDefault(packageID, Collections.emptySet()); + } + return Collections.emptySet(); + } + + private static boolean hasEmptyIdOrVersion(JarLibrary entry) { + return entry.groupId().isEmpty() || entry.artifactId().isEmpty() || entry.version().isEmpty(); + } + + private boolean isUsedDependency(JarLibrary otherJarDependency, Set usedNativeClassPaths) { + String pkgName = otherJarDependency.packageName().orElseThrow(); + if (isWhiteListedPkg(pkgName)) { + return true; + } + if (usedNativeClassPaths.isEmpty()) { + return false; + } + try (JarFile jarFile = new JarFile(otherJarDependency.path().toFile())) { + for (String classPath : usedNativeClassPaths) { + ZipEntry usedClassEntry = jarFile.getJarEntry(classPath); + if (usedClassEntry != null) { + return true; + } + } + return false; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private boolean isWhiteListedPkg(String pkgName) { + return pkgName.equals(BALLERINA_OBSERVE) || pkgName.equals(BALLERINAI_OBSERVE) || isDriverPkg(pkgName); + } + + // Driver pkgs are pkgs such as "ballerinax/mysql.driver". + // These pkgs contain only native jars without any source code. + private boolean isDriverPkg(String pkgName) { + return pkgName.startsWith(BALLERINAX) && pkgName.endsWith(DOT_DRIVER); + } + private void reportDiagnostic(JarLibrary existingEntry, JarLibrary newEntry) { // Report diagnostic only for non ballerina dependencies if (!existingEntry.packageName().orElseThrow().startsWith(ProjectConstants.BALLERINA_ORG) @@ -212,7 +325,7 @@ public Collection getJarFilePathsRequiredForTestExecution(ModuleName } // 3) Add platform-specific libraries with test scope defined in the root package's Ballerina.toml - addPlatformLibraryPaths(rootPackageContext, PlatformLibraryScope.TEST_ONLY, allJarFileForTestExec); + addPlatformLibraryPaths(rootPackageContext, PlatformLibraryScope.TEST_ONLY, allJarFileForTestExec, false); // Get all the dependencies of the root package including transitives. // 4) Include only the dependencies with PackageDependencyScope.TEST_ONLY scope @@ -226,8 +339,8 @@ public Collection getJarFilePathsRequiredForTestExecution(ModuleName // Add generated thin jar of every module in the package represented by the packageContext addCodeGeneratedLibraryPaths(pkgContext, PlatformLibraryScope.DEFAULT, allJarFileForTestExec); // All platform-specific libraries(specified in Ballerina.toml) having the default scope - addPlatformLibraryPaths(pkgContext, PlatformLibraryScope.DEFAULT, allJarFileForTestExec); - addPlatformLibraryPaths(pkgContext, PlatformLibraryScope.PROVIDED, allJarFileForTestExec); + addPlatformLibraryPaths(pkgContext, PlatformLibraryScope.DEFAULT, allJarFileForTestExec, false); + addPlatformLibraryPaths(pkgContext, PlatformLibraryScope.PROVIDED, allJarFileForTestExec, false); }); // 6 Add other dependencies required to run Ballerina test cases diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleContext.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleContext.java index 4c5f3159c77f..40cc7ae42027 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleContext.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleContext.java @@ -23,6 +23,7 @@ import io.ballerina.projects.environment.ProjectEnvironment; import io.ballerina.projects.internal.CompilerPhaseRunner; import io.ballerina.projects.internal.ModuleContextDataHolder; +import io.ballerina.projects.util.CodegenOptimizationUtils; import io.ballerina.projects.util.ProjectUtils; import io.ballerina.tools.diagnostics.Diagnostic; import io.ballerina.tools.diagnostics.Location; @@ -302,6 +303,8 @@ ModuleCompilationState currentCompilationState() { } else if (this.project().kind() == ProjectKind.BUILD_PROJECT && !this.project.buildOptions().enableCache()) { moduleCompState = ModuleCompilationState.LOADED_FROM_SOURCES; + } else if (this.shouldOptimizeCodegen()) { + moduleCompState = ModuleCompilationState.LOADED_FROM_SOURCES; } else { moduleCompState = ModuleCompilationState.LOADED_FROM_CACHE; } @@ -345,6 +348,18 @@ void resolveDependencies(DependencyResolution dependencyResolution) { this.moduleDependencies = Collections.unmodifiableSet(moduleDependencies); } + /** + * + * Returns true if at least one method or type def is connected to one of the root methods of the root pkg. + */ + public boolean isUsed() { + return this.bLangPackage().symbol.invocationData.moduleIsUsed; + } + + public CompilationCache getCompilationCache() { + return this.compilationCache; + } + private void addModuleDependency(PackageOrg org, String moduleName, PackageDependencyScope scope, @@ -476,8 +491,13 @@ static void generateCodeInternal(ModuleContext moduleContext, return; } + boolean shouldNotOptimizeModule = + moduleContext.isWhiteListedModule() || !moduleContext.project.buildOptions().optimizeCodegen(); + // Generate and write the thin JAR to the file system - compilerBackend.performCodeGen(moduleContext, moduleContext.compilationCache); + if (shouldNotOptimizeModule) { + compilerBackend.performCodeGen(moduleContext, moduleContext.compilationCache); + } // Skip bir caching if jar generation is not successful if (Diagnostics.hasErrors(moduleContext.diagnostics())) { @@ -491,7 +511,17 @@ static void generateCodeInternal(ModuleContext moduleContext, // Write the bir to the file system // This code will execute only if JAR caching is successful // TODO: check the filesystem cache and delete if the cache is incomplete (if BIR or JAR is missing) - moduleContext.compilationCache.cacheBir(moduleContext.moduleName(), birContent); + if (shouldNotOptimizeModule) { + moduleContext.compilationCache.cacheBir(moduleContext.moduleName(), birContent); + } + } + + public boolean isWhiteListedModule() { + return CodegenOptimizationUtils.isWhiteListedModule(this.moduleDescriptor.moduleCompilationId()); + } + + private boolean shouldOptimizeCodegen() { + return this.project().buildOptions().optimizeCodegen() && !isWhiteListedModule(); } private static boolean shouldGenerateBir(ModuleContext moduleContext, CompilerContext compilerContext) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/NullBackend.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/NullBackend.java index cbffe9dbd014..904ad5f620e8 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/NullBackend.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/NullBackend.java @@ -72,6 +72,11 @@ public PlatformLibrary codeGeneratedLibrary(PackageId packageId, ModuleName modu return null; } + @Override + public PlatformLibrary codeGeneratedOptimizedLibrary(PackageId packageId, ModuleName moduleName) { + return null; + } + @Override public PlatformLibrary codeGeneratedTestLibrary(PackageId packageId, ModuleName moduleName) { return null; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ProjectEnvironmentBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ProjectEnvironmentBuilder.java index 2f753a110783..80b28539a020 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ProjectEnvironmentBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ProjectEnvironmentBuilder.java @@ -20,6 +20,7 @@ import io.ballerina.projects.environment.Environment; import io.ballerina.projects.environment.EnvironmentBuilder; import io.ballerina.projects.environment.ProjectEnvironment; +import io.ballerina.projects.internal.environment.DefaultEnvironment; import io.ballerina.projects.internal.environment.DefaultProjectEnvironment; import io.ballerina.projects.repos.BuildProjectCompilationCache; import io.ballerina.projects.repos.TempDirCompilationCache; @@ -62,6 +63,9 @@ public ProjectEnvironment build(Project project) { switch (project.kind()) { case BUILD_PROJECT: compilationCache = BuildProjectCompilationCache.from(project); + if (environment instanceof DefaultEnvironment defaultEnvironment) { + defaultEnvironment.buildProjectTargetDir = project.targetDir(); + } break; case SINGLE_FILE_PROJECT: compilationCache = TempDirCompilationCache.from(project); diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/UsedBIRNodeAnalyzer.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/UsedBIRNodeAnalyzer.java new file mode 100644 index 000000000000..f52243bbcd83 --- /dev/null +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/UsedBIRNodeAnalyzer.java @@ -0,0 +1,691 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package io.ballerina.projects; + +import org.ballerinalang.model.elements.PackageID; +import org.ballerinalang.model.types.TypeKind; +import org.wso2.ballerinalang.compiler.PackageCache; +import org.wso2.ballerinalang.compiler.bir.model.BIRNode; +import org.wso2.ballerinalang.compiler.bir.model.BIRNonTerminator; +import org.wso2.ballerinalang.compiler.bir.model.BIROperand; +import org.wso2.ballerinalang.compiler.bir.model.BIRTerminator; +import org.wso2.ballerinalang.compiler.bir.model.BIRVisitor; +import org.wso2.ballerinalang.compiler.bir.model.InstructionKind; +import org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol; +import org.wso2.ballerinalang.compiler.semantics.model.symbols.UsedState; +import org.wso2.ballerinalang.compiler.semantics.model.types.BType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BTypeReferenceType; +import org.wso2.ballerinalang.compiler.tree.BLangPackage; +import org.wso2.ballerinalang.compiler.util.CompilerContext; +import org.wso2.ballerinalang.util.Flags; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.IdentityHashMap; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +import static io.ballerina.projects.util.CodegenOptimizationConstants.BALLERINA_JBALLERINA_JAVA; +import static io.ballerina.projects.util.CodegenOptimizationConstants.CLASS; +import static io.ballerina.projects.util.CodegenOptimizationConstants.DOT_CLASS; +import static io.ballerina.projects.util.CodegenOptimizationConstants.EXTERNAL_DEPENDENCY_ANNOT; +import static io.ballerina.projects.util.CodegenOptimizationConstants.INTEROP_DEPENDENCIES_PROPERTIES_FILE; +import static org.wso2.ballerinalang.compiler.util.Constants.RECORD_DELIMITER; + +/** + * Analyses the BIR and marks unused functions and type definitions. + * + * @since 2201.10.0 + */ +public final class UsedBIRNodeAnalyzer extends BIRVisitor { + + private static final CompilerContext.Key USED_BIR_NODE_ANALYZER_KEY = + new CompilerContext.Key<>(); + private static final Set USED_FUNCTION_NAMES = + new HashSet<>(Arrays.asList("main", ".", ".", ".", "__execute__")); + private static final Map> INTEROP_DEPENDENCIES = new HashMap<>(); + private static final Set ANALYZED_INSTRUCTION_KINDS = new HashSet<>( + Arrays.asList(InstructionKind.NEW_TYPEDESC, InstructionKind.NEW_INSTANCE, InstructionKind.TYPE_CAST, + InstructionKind.FP_LOAD, InstructionKind.TYPE_TEST, InstructionKind.RECORD_DEFAULT_FP_LOAD, + InstructionKind.NEW_TABLE, InstructionKind.NEW_ARRAY, InstructionKind.MOVE, + InstructionKind.NEW_ERROR)); + private static final Set ANALYZED_TERMINATOR_KINDS = + new HashSet<>(Arrays.asList(InstructionKind.CALL, InstructionKind.FP_CALL)); + private static final String EXTERNAL_METHOD_ANNOTATION_TAG = "Method"; + private static final String EXECUTE_TEST_REGISTRAR = "executeTestRegistrar"; + // To check whether a given FP is "USED" or not, we have to keep track of the existing FPs of a given scope. + // Variable Declarations holding an FPs are needed to be tracked to achieve that. + private Map localFpHolders = new HashMap<>(); + // pkgWiseInvocationData is used for debugging purposes + public final Map pkgWiseInvocationData = new LinkedHashMap<>(); + UsedBIRNodeAnalyzer.InvocationData currentInvocationData; + boolean isTestablePkgAnalysis = false; + PackageID currentPkgID; + private final PackageCache pkgCache; + private final UsedTypeDefAnalyzer usedTypeDefAnalyzer; + private final CodeGenOptimizationReportEmitter codeGenOptimizationReportEmitter; + private List currentInstructionArr; + private BIRNode.BIRFunction currentParentFunction; + + private UsedBIRNodeAnalyzer(CompilerContext context) { + context.put(USED_BIR_NODE_ANALYZER_KEY, this); + this.pkgCache = PackageCache.getInstance(context); + this.usedTypeDefAnalyzer = UsedTypeDefAnalyzer.getInstance(context); + this.codeGenOptimizationReportEmitter = CodeGenOptimizationReportEmitter.getInstance(context); + initInteropDependencies(); + } + + public static UsedBIRNodeAnalyzer getInstance(CompilerContext context) { + UsedBIRNodeAnalyzer deadBIRNodeAnalyzer = context.get(USED_BIR_NODE_ANALYZER_KEY); + if (deadBIRNodeAnalyzer == null) { + deadBIRNodeAnalyzer = new UsedBIRNodeAnalyzer(context); + } + return deadBIRNodeAnalyzer; + } + + public void analyze(BLangPackage pkgNode) { + this.codeGenOptimizationReportEmitter.flipBirOptimizationTimer(pkgNode.packageID); + + currentPkgID = pkgNode.packageID; + currentInvocationData = pkgNode.symbol.invocationData; + pkgWiseInvocationData.putIfAbsent(currentPkgID, currentInvocationData); + + if (!currentInvocationData.moduleIsUsed) { + currentInvocationData.registerNodes(usedTypeDefAnalyzer, pkgNode.symbol.bir); + } + + // All testablePkgs will be considered as root pkgs by default. + if (pkgNode.hasTestablePackage()) { + analyzeTestablePkg(pkgNode.getTestablePkg().symbol); + } + + for (BIRNode.BIRDocumentableNode node : currentInvocationData.startPointNodes) { + visitNode(node); + } + + this.codeGenOptimizationReportEmitter.flipBirOptimizationTimer(currentPkgID); + } + + private void analyzeTestablePkg(BPackageSymbol testableSymbol) { + isTestablePkgAnalysis = true; + // since the testablePkg can access the nodes of parent package, we can merge the invocationData of both + // testable and parent packages + currentInvocationData.testablePkgInvocationData = testableSymbol.invocationData; + + testableSymbol.invocationData.registerNodes(usedTypeDefAnalyzer, testableSymbol.bir); + // Analyzing testablePkg should be done first because it is the root of the dependency graph + for (BIRNode.BIRDocumentableNode node : testableSymbol.invocationData.startPointNodes) { + visitNode(node); + } + isTestablePkgAnalysis = false; + } + + private void visitNode(BIRNode nodeToVisit) { + BIRNode.BIRFunction prevParentFunction = currentParentFunction; + List prevInstructionArr = currentInstructionArr; + + nodeToVisit.accept(this); + + currentParentFunction = prevParentFunction; + currentInstructionArr = prevInstructionArr; + } + + @Override + public void visit(BIRNode.BIRFunction birFunction) { + if (birFunction.getUsedState() == UsedState.USED) { + return; + } + + birFunction.markAsUsed(); + currentInvocationData.addToUsedPool(birFunction); + currentParentFunction = birFunction; + + if ((birFunction.flags & Flags.NATIVE) == Flags.NATIVE) { + registerUsedNativeClassPaths(birFunction); + } + + birFunction.basicBlocks.forEach(this::visitNode); + birFunction.parameters.forEach(param -> usedTypeDefAnalyzer.analyzeTypeDefWithinScope(param.type, birFunction)); + usedTypeDefAnalyzer.analyzeTypeDefWithinScope(birFunction.returnVariable.type, birFunction); + } + + @Override + public void visit(BIRNode.BIRServiceDeclaration serviceDeclaration) { + serviceDeclaration.listenerTypes.forEach( + listenerType -> usedTypeDefAnalyzer.analyzeTypeDefWithinScope(listenerType, serviceDeclaration)); + } + + @Override + public void visit(BIRNode.BIRTypeDefinition typeDef) { + if (typeDef.getUsedState() == UsedState.USED) { + return; + } + + typeDef.markAsUsed(); + currentInvocationData.addToUsedPool(typeDef); + usedTypeDefAnalyzer.analyzeTypeDef(typeDef); + typeDef.attachedFuncs.forEach( + attachedFunc -> addDependentFunctionAndVisit(typeDef, attachedFunc, typeDef.type.tsymbol.pkgID)); + } + + @Override + public void visit(BIRNode.BIRBasicBlock birBasicBlock) { + Map previousLocalFpHolders = localFpHolders; + currentInstructionArr = birBasicBlock.instructions; + localFpHolders = new HashMap<>(currentInvocationData.globalVarFPDataPool); + localFpHolders.putAll(currentInvocationData.globalVarFPDataPool); + + birBasicBlock.instructions.forEach(instruction -> { + if (ANALYZED_INSTRUCTION_KINDS.contains(instruction.getKind())) { + visitNode(instruction); + } + // The current algorithm does not track all FP assignments. + // If the FP is assigned inside the parent scope, the FP will have the same UsedState as the parent + Set rhsVars = getVarDeclarations(instruction); + for (BIRNode.BIRVariableDcl rhsVar : rhsVars) { + if (rhsVar instanceof BIRNode.BIRGlobalVariableDcl globalRhsVar) { + analyzeGlobalVariableDeclUsage(globalRhsVar); + } + } + analyzeFunctionPointerReferences(rhsVars, instruction); + }); + + if (ANALYZED_TERMINATOR_KINDS.contains(birBasicBlock.terminator.getKind())) { + visitNode(birBasicBlock.terminator); + } + localFpHolders = previousLocalFpHolders; + } + + @Override + public void visit(BIRTerminator.Call call) { + // If function pointers are passed as parameters, they will be bound to the parent function + List argVars = getUsedLocalFPHolders(call.args); + argVars.forEach(var -> { + FunctionPointerData fpData = currentInvocationData.getFPData(var); + if (fpData != null && fpData.lambdaFunction != null) { + visitNode(fpData.lambdaFunction); + } + currentParentFunction.addChildNode(var); + }); + + BIRNode.BIRDocumentableNode childNode = lookupBirFunction(call.calleePkg, call.originalName.value); + if (childNode == null) { + return; + } + // Invoked function will also be visited + addDependentFunctionAndVisit(currentParentFunction, childNode, call.calleePkg); + } + + private List getUsedLocalFPHolders(List birOperands) { + List usedLocalFPHolders = new ArrayList<>(birOperands.size()); + for (BIROperand birOperand : birOperands) { + if (localFpHolders.containsKey(birOperand.variableDcl)) { + usedLocalFPHolders.add(birOperand.variableDcl); + } + } + return usedLocalFPHolders; + } + + @Override + public void visit(BIRTerminator.FPCall fpCall) { + BIRNode.BIRVariableDcl fpPointer = fpCall.fp.variableDcl; + if (!fpPointer.isInSamePkg(currentPkgID) && isTestablePkgAnalysis) { + return; + } + + fpPointer.markAsUsed(); + currentParentFunction.childNodes.add(fpPointer); + fpPointer.parentNodes.add(currentParentFunction); + + FunctionPointerData fpData; + if (fpPointer instanceof BIRNode.BIRGlobalVariableDcl globalVariableDcl) { + fpData = currentInvocationData.globalVarFPDataPool.get(globalVariableDcl); + } else { + fpData = currentInvocationData.getFPData(fpCall.fp.variableDcl); + } + + if (fpData == null) { + if (!fpPointer.isInSamePkg(currentPkgID) && !isTestablePkgAnalysis) { + getInvocationData(fpPointer.getPackageID()) + .registerNodes(usedTypeDefAnalyzer, this.pkgCache.getBirPkg(fpPointer.getPackageID())); + } + } else if (fpData.lambdaFunction != null) { + visitNode(fpData.lambdaFunction); + usedTypeDefAnalyzer.analyzeTypeDefWithinScope(fpData.lambdaPointerVar.type, currentParentFunction); + } + } + + @Override + public void visit(BIRNonTerminator.FPLoad fpLoadInstruction) { + BIRNode.BIRFunction pointedFunction = + lookupBirFunction(fpLoadInstruction.pkgId, fpLoadInstruction.funcName.value); + + FunctionPointerData fpData = new FunctionPointerData(fpLoadInstruction, currentInstructionArr, pointedFunction); + initializeFpDataUsedState(fpLoadInstruction.lhsOp.variableDcl, pointedFunction, fpData); + + // Used to detect, + // 1. Record default fields containing function pointers + // 2. Testerina related TestRegistrars (These global function pointers are called from testerina side) + if (currentParentFunction.name.value.contains(RECORD_DELIMITER) || + currentParentFunction.name.value.startsWith(EXECUTE_TEST_REGISTRAR)) { + fpData.lambdaPointerVar.markAsUsed(); + } + + if (fpData.lambdaPointerVar instanceof BIRNode.BIRGlobalVariableDcl globalVariableDcl) { + getInvocationData(currentPkgID).globalVarFPDataPool.put(globalVariableDcl, fpData); + } + + if (fpData.lambdaPointerVar.getUsedState() == UsedState.USED && pointedFunction != null) { + visitNode(pointedFunction); + usedTypeDefAnalyzer.analyzeTypeDefWithinScope(fpData.lambdaPointerVar.type, currentParentFunction); + } + + localFpHolders.put(fpLoadInstruction.lhsOp.variableDcl, fpData); + getInvocationData(currentPkgID).functionPointerDataPool.put(fpData.lambdaPointerVar, fpData); + } + + private void initializeFpDataUsedState(BIRNode.BIRVariableDcl lambdaPointerVar, BIRNode.BIRFunction lambdaFunction, + FunctionPointerData fpData) { + if (lambdaPointerVar.getUsedState() == UsedState.UNEXPLORED) { + lambdaPointerVar.markSelfAsUnused(); + } + + localFpHolders.put(lambdaPointerVar, fpData); + if (lambdaFunction != null) { + lambdaPointerVar.childNodes.add(lambdaFunction); + lambdaFunction.parentNodes.add(lambdaPointerVar); + } + } + + /* + recordDefaultFPLoad instructions can be "USED" without any reference to the "lhsOp". + Make sure to check weather the enclosed type is used before deleting the instruction. + */ + @Override + public void visit(BIRNonTerminator.RecordDefaultFPLoad recordDefaultFPLoad) { + FunctionPointerData fpData = currentInvocationData.getFPData(recordDefaultFPLoad.lhsOp.variableDcl); + fpData.recordDefaultFPLoad = recordDefaultFPLoad; + if (fpData.recordDefaultFPLoad.enclosedType.isUsed) { + fpData.lambdaPointerVar.markAsUsed(); + visitNode(fpData.lambdaFunction); + } + currentInvocationData.recordDefTypeWiseFPDataPool.putIfAbsent(recordDefaultFPLoad.enclosedType, + new HashSet<>()); + currentInvocationData.recordDefTypeWiseFPDataPool.get(recordDefaultFPLoad.enclosedType).add(fpData); + } + + @Override + public void visit(BIRNonTerminator.NewError newError) { + usedTypeDefAnalyzer.analyzeTypeDefWithinScope(newError.type, currentParentFunction); + } + + @Override + public void visit(BIRNonTerminator.NewTypeDesc newTypeDesc) { + if (newTypeDesc.type.tsymbol == null) { + return; + } + usedTypeDefAnalyzer.analyzeTypeDefWithinScope(newTypeDesc.type, currentParentFunction); + } + + @Override + public void visit(BIRNonTerminator.NewInstance newInstance) { + usedTypeDefAnalyzer.analyzeTypeDefWithinScope(newInstance.expectedType, currentParentFunction); + if (newInstance.def != null) { + visitNode(newInstance.def); + } + } + + @Override + public void visit(BIRNonTerminator.NewArray newArray) { + usedTypeDefAnalyzer.analyzeTypeDefWithinScope(newArray.type, currentParentFunction); + } + + @Override + public void visit(BIRNonTerminator.TypeCast typeCast) { + usedTypeDefAnalyzer.analyzeTypeDefWithinScope(typeCast.type, currentParentFunction); + usedTypeDefAnalyzer.analyzeTypeDefWithinScope(typeCast.lhsOp.variableDcl.type, currentParentFunction); + usedTypeDefAnalyzer.analyzeTypeDefWithinScope(typeCast.rhsOp.variableDcl.type, currentParentFunction); + } + + @Override + public void visit(BIRNonTerminator.TypeTest typeTest) { + usedTypeDefAnalyzer.analyzeTypeDefWithinScope(typeTest.type, currentParentFunction); + } + + @Override + public void visit(BIRNonTerminator.NewTable newTable) { + usedTypeDefAnalyzer.analyzeTypeDefWithinScope(newTable.type, currentParentFunction); + } + + @Override + public void visit(BIRNonTerminator.Move move) { + usedTypeDefAnalyzer.analyzeTypeDefWithinScope(move.lhsOp.variableDcl.type, currentParentFunction); + usedTypeDefAnalyzer.analyzeTypeDefWithinScope(move.rhsOp.variableDcl.type, currentParentFunction); + } + + private boolean isFunctionKindType(BType bType) { + if (bType.getKind() == TypeKind.TYPEREFDESC) { + if (bType instanceof BTypeReferenceType referenceType) { + return referenceType.referredType.getKind() == TypeKind.FUNCTION; + } + } + return bType.getKind() == TypeKind.FUNCTION; + } + + private BIRNode.BIRFunction lookupBirFunction(PackageID pkgId, String funcName) { + UsedBIRNodeAnalyzer.InvocationData invocationData = getInvocationData(pkgId); + if (!invocationData.moduleIsUsed && !isTestablePkgAnalysis) { + invocationData.registerNodes(usedTypeDefAnalyzer, pkgCache.getBirPkg(pkgId)); + } + return invocationData.functionPool.get(funcName); + } + + public InvocationData getInvocationData(PackageID pkgId) { + if (currentPkgID.equals(pkgId)) { + return pkgId.isTestPkg ? currentInvocationData.testablePkgInvocationData : currentInvocationData; + } + return pkgCache.getInvocationData(pkgId); + } + + private void initInteropDependencies() { + Properties prop = new Properties(); + try { + InputStream stream = getClass().getClassLoader().getResourceAsStream(INTEROP_DEPENDENCIES_PROPERTIES_FILE); + prop.load(stream); + for (Map.Entry entry : prop.entrySet()) { + Set usedRecordNames = new HashSet<>(Arrays.asList(entry.getValue().toString().split(","))); + INTEROP_DEPENDENCIES.putIfAbsent(entry.getKey().toString(), usedRecordNames); + } + + } catch (IOException e) { + throw new RuntimeException("Failed to load interop-dependencies : ", e); + } + } + + private HashSet getVarDeclarations(BIRNonTerminator instruction) { + HashSet rhsVars = new HashSet<>(); + for (BIROperand rhsOperand : instruction.getRhsOperands()) { + rhsVars.add(rhsOperand.variableDcl); + } + return rhsVars; + } + + private void analyzeGlobalVariableDeclUsage(BIRNode.BIRGlobalVariableDcl globalRhsVar) { + if (!globalRhsVar.isInSamePkg(currentPkgID) && isTestablePkgAnalysis) { + return; + } + globalRhsVar.markAsUsed(); + currentParentFunction.childNodes.add(globalRhsVar); + globalRhsVar.parentNodes.add(currentParentFunction); + + if (!globalRhsVar.isInSamePkg(currentPkgID)) { + getInvocationData(globalRhsVar.pkgId) + .registerNodes(usedTypeDefAnalyzer, this.pkgCache.getBirPkg(globalRhsVar.pkgId)); + } else if (isFunctionKindType(globalRhsVar.type)) { + visitNode(currentInvocationData.globalVarFPDataPool.get(globalRhsVar).lambdaFunction); + } + } + + private void analyzeFunctionPointerReferences(Set rhsVars, BIRNonTerminator instruction) { + if (instruction.kind == InstructionKind.RECORD_DEFAULT_FP_LOAD) { + return; + } + rhsVars.retainAll(localFpHolders.keySet()); + for (BIRNode.BIRVariableDcl var : rhsVars) { + FunctionPointerData fpData = currentInvocationData.getFPData(var); + if (fpData != null && fpData.lambdaFunction != null) { + visitNode(fpData.lambdaFunction); + } + currentParentFunction.addChildNode(var); + } + } + + private void registerUsedNativeClassPaths(BIRNode.BIRFunction birFunction) { + birFunction.annotAttachments.forEach(annot -> { + if (annot.annotTagRef.value.equals(EXTERNAL_METHOD_ANNOTATION_TAG)) { + BIRNode.ConstValue constValue = ((BIRNode.BIRConstAnnotationAttachment) annot).annotValue; + String filePath = + ((HashMap) constValue.value).get(CLASS).value.toString(); + currentInvocationData.usedNativeClassPaths.add(filePath.replace(".", "/") + DOT_CLASS); + } + }); + } + + private void addDependentFunctionAndVisit(BIRNode.BIRDocumentableNode parentNode, + BIRNode.BIRDocumentableNode childFunction, PackageID childPkgId) { + parentNode.childNodes.add(childFunction); + childFunction.parentNodes.add(parentNode); + if (childPkgId.equals(currentPkgID)) { + visitNode(childFunction); + return; + } + + // Testable pkg dependencies should not be analysed because the unoptimized duplicates will be referenced + if (isTestablePkgAnalysis) { + return; + } + + UsedBIRNodeAnalyzer.InvocationData childInvocationData = getInvocationData(childPkgId); + + // Handling langLibs + if (childInvocationData == null) { + return; + } + + // Child is from another package + childInvocationData.moduleIsUsed = true; + childInvocationData.startPointNodes.add(childFunction); + currentInvocationData.childPackages.add(childFunction.getPackageID()); + } + + public static class InvocationData { + + // Following Sets are used to whitelist the bal types called through ValueCreator in native dependencies + private static final Set WHITELSITED_FILE_NAMES = + new HashSet<>(Arrays.asList("types.bal", "error.bal", "stream_types.bal")); + private static final Set PKGS_WITH_WHITELSITED_FILES = new HashSet<>( + Arrays.asList("ballerinax/mysql", "ballerina/sql", "ballerinax/persist.sql")); + private static final String BALLERINA_TEST_PKG_NAME = "ballerina/test:0.0.0"; + private static final String MOCK_FUNCTION_PREFIX = "$MOCK_"; + protected final Set usedFunctions = new LinkedHashSet<>(); + protected final Set unusedFunctions = new LinkedHashSet<>(); + protected final Set usedTypeDefs = new LinkedHashSet<>(); + protected final Set unusedTypeDefs = new LinkedHashSet<>(); + protected final Set startPointNodes = new LinkedHashSet<>(); + private final Map functionPool = new HashMap<>(); + private final Map functionPointerDataPool = + new IdentityHashMap<>(); + private final Map globalVarFPDataPool = new HashMap<>(); + private final Map> recordDefTypeWiseFPDataPool = new HashMap<>(); + private final Set childPackages = new HashSet<>(); + protected Set usedNativeClassPaths = new HashSet<>(); + protected boolean moduleIsUsed = false; + private Set interopDependencies = new HashSet<>(); + private InvocationData testablePkgInvocationData; + + private static boolean isResourceFunction(BIRNode.BIRFunction birFunction) { + return (birFunction.flags & Flags.RESOURCE) == Flags.RESOURCE; + } + + private static boolean isTestFunction(BIRNode.BIRFunction birFunction) { + if (birFunction.annotAttachments == null) { + return false; + } + return birFunction.annotAttachments.stream() + .anyMatch(annAttach -> annAttach.annotPkgId.toString().equals(BALLERINA_TEST_PKG_NAME)); + } + + private static boolean isGeneratedMockFunction(BIRNode.BIRFunction birFunction) { + return birFunction.name.value.startsWith(MOCK_FUNCTION_PREFIX); + } + + private static boolean isExternalDependencyBIRNode(BIRNode.BIRFunction birFunction) { + if (birFunction.annotAttachments == null) { + return false; + } + return containsExternalDependencyAnnot(birFunction.annotAttachments); + } + + private static boolean isExternalDependencyBIRNode(BIRNode.BIRTypeDefinition birTypeDefinition) { + if (birTypeDefinition.annotAttachments == null) { + return false; + } + return containsExternalDependencyAnnot(birTypeDefinition.annotAttachments); + } + + private static boolean containsExternalDependencyAnnot(List annotAttachments) { + for (BIRNode.BIRAnnotationAttachment annotAttachment : annotAttachments) { + if (annotAttachment.annotPkgId.getPackageNameWithOrg().equals(BALLERINA_JBALLERINA_JAVA) && + annotAttachment.annotTagRef.toString().equals(EXTERNAL_DEPENDENCY_ANNOT)) { + return true; + } + } + return false; + } + + protected void registerNodes(UsedTypeDefAnalyzer typeDefAnalyzer, BIRNode.BIRPackage birPackage) { + // If the birPackage is from a langlib it will be null. + if (birPackage == null) { + return; + } + + String packageName = birPackage.packageID.getPackageNameWithOrg(); + birPackage.functions.forEach(this::initializeFunction); + this.interopDependencies = INTEROP_DEPENDENCIES.get(packageName); + typeDefAnalyzer.populateTypeDefPool(birPackage, interopDependencies); + birPackage.typeDefs.forEach(typeDef -> { + unusedTypeDefs.add(typeDef); + typeDef.markSelfAsUnused(); + typeDef.attachedFuncs.forEach(birFunction -> initializeAttachedFunction(typeDef, birFunction)); + whiteListExternalDependencyTypedefs(packageName, typeDef); + }); + this.startPointNodes.addAll(birPackage.serviceDecls); + this.moduleIsUsed = true; + } + + private void whiteListExternalDependencyTypedefs(String packageName, BIRNode.BIRTypeDefinition typeDef) { + if (PKGS_WITH_WHITELSITED_FILES.contains(packageName)) { + if (isInWhiteListedBalFile(typeDef)) { + this.startPointNodes.add(typeDef); + } + } + if (isExternalDependencyBIRNode(typeDef)) { + this.startPointNodes.add(typeDef); + } + } + + private boolean isInWhiteListedBalFile(BIRNode.BIRTypeDefinition typedef) { + return typedef.pos != null && WHITELSITED_FILE_NAMES.contains(typedef.pos.lineRange().fileName()); + } + + private void initializeFunction(BIRNode.BIRFunction birFunction) { + birFunction.markSelfAsUnused(); + this.unusedFunctions.add(birFunction); + functionPool.putIfAbsent(birFunction.originalName.value, birFunction); + + if (USED_FUNCTION_NAMES.contains(birFunction.name.value) || isResourceFunction(birFunction) || + isTestFunction(birFunction) || isGeneratedMockFunction(birFunction) || + isExternalDependencyBIRNode(birFunction)) { + this.startPointNodes.add(birFunction); + } + } + + private void initializeAttachedFunction(BIRNode.BIRTypeDefinition parentTypeDef, + BIRNode.BIRFunction attachedFunc) { + attachedFunc.markSelfAsUnused(); + this.unusedFunctions.add(attachedFunc); + functionPool.putIfAbsent(parentTypeDef.internalName.value + "." + attachedFunc.name.value, attachedFunc); + } + + protected void addToUsedPool(BIRNode.BIRFunction birFunction) { + if (this.unusedFunctions.remove(birFunction)) { + this.usedFunctions.add(birFunction); + } else if (this.testablePkgInvocationData != null) { + this.testablePkgInvocationData.unusedFunctions.remove(birFunction); + this.testablePkgInvocationData.usedFunctions.add(birFunction); + } + } + + protected void addToUsedPool(BIRNode.BIRTypeDefinition birTypeDef) { + if (this.unusedTypeDefs.remove(birTypeDef)) { + this.usedTypeDefs.add(birTypeDef); + } else if (this.testablePkgInvocationData != null) { + this.testablePkgInvocationData.unusedTypeDefs.remove(birTypeDef); + this.testablePkgInvocationData.usedTypeDefs.add(birTypeDef); + } + } + + private FunctionPointerData getFPData(BIRNode.BIRVariableDcl variableDcl) { + return functionPointerDataPool.get(variableDcl); + } + + protected HashSet getFpData(BType bType) { + return this.recordDefTypeWiseFPDataPool.get(bType); + } + + protected Collection getFpDataPool() { + return this.functionPointerDataPool.values(); + } + } + + protected static class FunctionPointerData { + + // Can be deleted from the BirFunctions of the enclosing module + protected final BIRNode.BIRFunction lambdaFunction; + // Can be deleted from the localVar or global var list + protected final BIRNode.BIRVariableDcl lambdaPointerVar; + // Can be deleted from the instruction array of either the parent function or init<> function + private final BIRNonTerminator.FPLoad fpLoadInstruction; + private final List instructionArray; + // Holds a recordDefaultFPLoad instruction if the respective fpLoadInstruction has one + private BIRNonTerminator.RecordDefaultFPLoad recordDefaultFPLoad; + + protected FunctionPointerData(BIRNonTerminator.FPLoad fpLoadInstruction, + List instructionArray, BIRNode.BIRFunction lambdaFunction) { + this.fpLoadInstruction = fpLoadInstruction; + this.instructionArray = instructionArray; + this.lambdaPointerVar = fpLoadInstruction.lhsOp.variableDcl; + this.lambdaFunction = lambdaFunction; + } + + // functions with default parameters will desugar into a new lambda function that gets invoked through an + // FP_CALL inside the init function. + // We need to delete those if the lambda function is not used. + // If the FP_LOAD instruction is not removed its references will be used for CodeGen. + // We need to prevent this from happening to fully clean the UNUSED functions. + protected void deleteIfUnused() { + // if the parent record is used, instructions should not be deleted + if (recordDefaultFPLoad != null && recordDefaultFPLoad.enclosedType.isUsed) { + return; + } + if (lambdaPointerVar.getUsedState() == UsedState.UNUSED) { + instructionArray.remove(fpLoadInstruction); + instructionArray.remove(recordDefaultFPLoad); + } + } + } +} diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/UsedTypeDefAnalyzer.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/UsedTypeDefAnalyzer.java new file mode 100644 index 000000000000..223723dae428 --- /dev/null +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/UsedTypeDefAnalyzer.java @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package io.ballerina.projects; + +import org.wso2.ballerinalang.compiler.PackageCache; +import org.wso2.ballerinalang.compiler.bir.model.BIRNode; +import org.wso2.ballerinalang.compiler.semantics.model.SimpleBTypeAnalyzer; +import org.wso2.ballerinalang.compiler.semantics.model.types.BType; +import org.wso2.ballerinalang.compiler.util.CompilerContext; +import org.wso2.ballerinalang.compiler.util.TypeTags; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * Analyses a given type definition and marks its dependencies. + * + * @since 2201.10.0 + */ +public final class UsedTypeDefAnalyzer extends SimpleBTypeAnalyzer { + + private static final CompilerContext.Key BIR_TYPE_DEF_ANALYZER_KEY = + new CompilerContext.Key<>(); + private final Map globalTypeDefPool = new HashMap<>(); + private final Set visitedTypes = new HashSet<>(); + private PackageCache pkgCache; + private UsedBIRNodeAnalyzer usedBIRNodeAnalyzer; + + private UsedTypeDefAnalyzer(CompilerContext context) { + context.put(BIR_TYPE_DEF_ANALYZER_KEY, this); + this.pkgCache = PackageCache.getInstance(context); + this.usedBIRNodeAnalyzer = UsedBIRNodeAnalyzer.getInstance(context); + } + + public static UsedTypeDefAnalyzer getInstance(CompilerContext context) { + UsedTypeDefAnalyzer usedTypeDefAnalyzer = context.get(BIR_TYPE_DEF_ANALYZER_KEY); + if (usedTypeDefAnalyzer == null) { + usedTypeDefAnalyzer = new UsedTypeDefAnalyzer(context); + } + return usedTypeDefAnalyzer; + } + + @Override + public void visitType(BType bType, AnalyzerData data) { + if (bType == null) { + return; + } + + if (isTestablePkgImportedModuleDependency(bType)) { + return; + } + + BIRNode.BIRDocumentableNode prevParentNode = data.currentParentNode; + boolean prevShouldAnalyzeChildren = data.shouldAnalyzeChildren; + addDependency(bType, data); + if (data.shouldAnalyzeChildren) { + bType.accept(this, data); + } + + data.currentParentNode = prevParentNode; + data.shouldAnalyzeChildren = prevShouldAnalyzeChildren; + } + + // Since bRecordTypes can have related anon functions for default values we have to mark them as used as well + @Override + public void analyzeType(BType bType, AnalyzerData data) { + Set fpDataSet = + usedBIRNodeAnalyzer.currentInvocationData.getFpData(bType); + if (fpDataSet != null) { + fpDataSet.forEach(fpData -> { + fpData.lambdaPointerVar.markAsUsed(); + fpData.lambdaFunction.accept(usedBIRNodeAnalyzer); + }); + } + } + + protected void populateTypeDefPool(BIRNode.BIRPackage birPackage, Set interopDependencies) { + birPackage.typeDefs.forEach(typeDef -> { + // In case there are more than one reference types referencing to the same type + if (typeDef.referenceType != null && typeDef.type.tag == TypeTags.TYPEREFDESC) { + globalTypeDefPool.putIfAbsent(typeDef.referenceType, typeDef); + } else { + globalTypeDefPool.putIfAbsent(typeDef.type, typeDef); + } + if (interopDependencies != null && interopDependencies.contains(typeDef.internalName.toString())) { + usedBIRNodeAnalyzer.getInvocationData(typeDef.getPackageID()).startPointNodes.add(typeDef); + } + }); + } + + protected void analyzeTypeDef(BIRNode.BIRTypeDefinition typeDef) { + final AnalyzerData data = new AnalyzerData(); + data.currentParentNode = typeDef; + typeDef.referencedTypes.forEach(refType -> visitType(refType, data)); + visitType(typeDef.type, data); + } + + protected void analyzeTypeDefWithinScope(BType bType, BIRNode.BIRDocumentableNode parentNode) { + final AnalyzerData data = new AnalyzerData(); + data.currentParentNode = parentNode; + visitType(bType, data); + } + + private BIRNode.BIRTypeDefinition getBIRTypeDef(BType bType) { + if (bType.tsymbol == null) { + return null; + } + + UsedBIRNodeAnalyzer.InvocationData invocationData = usedBIRNodeAnalyzer.getInvocationData(bType.tsymbol.pkgID); + if (invocationData == null) { + return null; + } + if (!invocationData.moduleIsUsed && !usedBIRNodeAnalyzer.isTestablePkgAnalysis) { + invocationData.registerNodes(this, pkgCache.getBirPkg(bType.tsymbol.pkgID)); + } + + if (globalTypeDefPool.containsKey(bType)) { + return globalTypeDefPool.get(bType); + } + return null; + } + + private void addDependency(BType bType, AnalyzerData data) { + data.shouldAnalyzeChildren = visitedTypes.add(bType); + bType.isUsed = true; + BIRNode.BIRTypeDefinition childTypeDefNode = getBIRTypeDef(bType); + if (childTypeDefNode == null) { + return; + } + + if (data.currentParentNode != childTypeDefNode) { + data.currentParentNode.childNodes.add(childTypeDefNode); + childTypeDefNode.parentNodes.add(data.currentParentNode); + } + + if (!childTypeDefNode.isInSamePkg(usedBIRNodeAnalyzer.currentPkgID)) { + usedBIRNodeAnalyzer.getInvocationData(childTypeDefNode.getPackageID()).startPointNodes.add( + childTypeDefNode); + visitedTypes.remove(bType); + data.shouldAnalyzeChildren = false; + return; + } + + usedBIRNodeAnalyzer.currentInvocationData.addToUsedPool(childTypeDefNode); + data.currentParentNode = childTypeDefNode; + childTypeDefNode.markAsUsed(); + + // Handling method overriding instances + childTypeDefNode.attachedFuncs.forEach(attachedFunc -> { + childTypeDefNode.childNodes.add(attachedFunc); + attachedFunc.parentNodes.add(childTypeDefNode); + attachedFunc.accept(usedBIRNodeAnalyzer); + }); + } + + public boolean isTestablePkgImportedModuleDependency(BType bType) { + if (bType.tsymbol == null || bType.tsymbol.pkgID == null) { + return false; + } + + return usedBIRNodeAnalyzer.isTestablePkgAnalysis && + !bType.tsymbol.pkgID.equals(usedBIRNodeAnalyzer.currentPkgID); + } + + public static class AnalyzerData { + BIRNode.BIRDocumentableNode currentParentNode; + boolean shouldAnalyzeChildren = true; + } +} diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/CompilerPhaseRunner.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/CompilerPhaseRunner.java index 3163dfd71121..c85fd9d36d7d 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/CompilerPhaseRunner.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/CompilerPhaseRunner.java @@ -118,12 +118,12 @@ public void performTypeCheckPhases(BLangPackage pkgNode) { } dataflowAnalyze(pkgNode); - if (this.stopCompilation(pkgNode, CompilerPhase.DOCUMENTATION_ANALYZE)) { + if (this.stopCompilation(pkgNode, CompilerPhase.ISOLATION_ANALYZE)) { return; } isolationAnalyze(pkgNode); - if (this.stopCompilation(pkgNode, CompilerPhase.ISOLATION_ANALYZE)) { + if (this.stopCompilation(pkgNode, CompilerPhase.DOCUMENTATION_ANALYZE)) { return; } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java index e0bc37b308cb..98e149134d60 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java @@ -695,6 +695,10 @@ private BuildOptions setBuildOptions(TomlTableNode tomlTableNode) { CompilerOptionName.REMOTE_MANAGEMENT.toString()); Boolean showDependencyDiagnostics = getBooleanFromBuildOptionsTableNode(tableNode, BuildOptions.OptionName.SHOW_DEPENDENCY_DIAGNOSTICS.toString()); + Boolean optimizeCodegen = getBooleanFromBuildOptionsTableNode(tableNode, + BuildOptions.OptionName.OPTIMIZE_CODEGEN.toString()); + Boolean optimizeReport = getBooleanFromBuildOptionsTableNode(tableNode, + BuildOptions.OptionName.OPTIMIZE_REPORT.toString()); buildOptionsBuilder .setOffline(offline) @@ -710,7 +714,9 @@ private BuildOptions setBuildOptions(TomlTableNode tomlTableNode) { .setExportComponentModel(exportComponentModel) .setGraalVMBuildOptions(graalVMBuildOptions) .setRemoteManagement(remoteManagement) - .setShowDependencyDiagnostics(showDependencyDiagnostics); + .setShowDependencyDiagnostics(showDependencyDiagnostics) + .setOptimizeCodegen(optimizeCodegen) + .setOptimizeReport(optimizeReport); if (targetDir != null) { buildOptionsBuilder.targetDir(targetDir); diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectDiagnosticErrorCode.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectDiagnosticErrorCode.java index 00dc9bc826de..52184ad5a3a6 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectDiagnosticErrorCode.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectDiagnosticErrorCode.java @@ -64,6 +64,9 @@ public enum ProjectDiagnosticErrorCode implements DiagnosticCode { // Error codes used for pack command DEPRECATED_DOC_FILE("BCE5601", "deprecated.doc.file"), + + // Error codes for invalid flag combinations. + INVALID_VERBOSE_FLAG_USAGE("BCE5701", "invalid.verbose.flag.usage"), ; private final String diagnosticId; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/environment/DefaultEnvironment.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/environment/DefaultEnvironment.java index a9fb08f216e3..93f2e78d2b2a 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/environment/DefaultEnvironment.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/environment/DefaultEnvironment.java @@ -19,6 +19,7 @@ import io.ballerina.projects.environment.Environment; +import java.nio.file.Path; import java.util.HashMap; import java.util.Map; @@ -29,6 +30,7 @@ */ public class DefaultEnvironment extends Environment { private final Map, Object> services; + public Path buildProjectTargetDir; public DefaultEnvironment(Map, Object> services) { this.services = services; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/repos/FileSystemCache.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/repos/FileSystemCache.java index 78b6eef2e60e..702e259f4bf0 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/repos/FileSystemCache.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/repos/FileSystemCache.java @@ -24,6 +24,7 @@ import io.ballerina.projects.Package; import io.ballerina.projects.PackageManifest; import io.ballerina.projects.Project; +import io.ballerina.projects.internal.environment.DefaultEnvironment; import io.ballerina.projects.util.ProjectConstants; import org.apache.commons.io.FileUtils; @@ -34,6 +35,8 @@ import java.nio.file.Path; import java.util.Optional; +import static io.ballerina.projects.util.ProjectConstants.CACHES_DIR_NAME; + /** * An implementation of the {@code PackageCompilationCache} that is aware of the file system structure. *

@@ -92,19 +95,22 @@ public void cacheBir(ModuleName moduleName, ByteArrayOutputStream birContent) { } @Override - public Optional getPlatformSpecificLibrary(CompilerBackend compilerBackend, String libraryName) { + public Optional getPlatformSpecificLibrary(CompilerBackend compilerBackend, String libraryName, + boolean isOptimizedLibrary) { String libraryFileName = libraryName + compilerBackend.libraryFileExtension(); - Path targetPlatformCacheDirPath = getTargetPlatformCacheDirPath(compilerBackend); + Path targetPlatformCacheDirPath = isOptimizedLibrary ? getOptimizedTargetPlatformCacheDirPath(compilerBackend) : + getTargetPlatformCacheDirPath(compilerBackend); Path jarFilePath = targetPlatformCacheDirPath.resolve(libraryFileName); - return Files.exists(jarFilePath) ? Optional.of(jarFilePath) : Optional.empty(); + return Optional.of(jarFilePath); } @Override public void cachePlatformSpecificLibrary(CompilerBackend compilerBackend, String libraryName, - ByteArrayOutputStream libraryContent) { + ByteArrayOutputStream libraryContent, boolean isOptimizedLibrary) { String libraryFileName = libraryName + compilerBackend.libraryFileExtension(); - Path targetPlatformCacheDirPath = getTargetPlatformCacheDirPath(compilerBackend); + Path targetPlatformCacheDirPath = isOptimizedLibrary ? getOptimizedTargetPlatformCacheDirPath(compilerBackend) : + getTargetPlatformCacheDirPath(compilerBackend); // Create directories createDirectories(targetPlatformCacheDirPath); Path jarFilePath = targetPlatformCacheDirPath.resolve(libraryFileName); @@ -123,6 +129,11 @@ private Path getTargetPlatformCacheDirPath(CompilerBackend compilerBackend) { return packageCacheDirPath().resolve(targetPlatformCode); } + private Path getOptimizedTargetPlatformCacheDirPath(CompilerBackend compilerBackend) { + String targetPlatformCode = compilerBackend.targetPlatform().code(); + return optimizedPackageCacheDirPath().resolve(targetPlatformCode); + } + private void createDirectories(Path dirPath) { if (Files.exists(dirPath)) { return; @@ -159,6 +170,17 @@ private Path packageCacheDirPath() { return packageCacheDirPath; } + private Path optimizedPackageCacheDirPath() { + Package currentPkg = project.currentPackage(); + PackageManifest pkgDescriptor = currentPkg.manifest(); + DefaultEnvironment defaultEnv = (DefaultEnvironment) this.project.projectEnvironmentContext().environment(); + if (defaultEnv.buildProjectTargetDir == null) { + return packageCacheDirPath(); + } + return defaultEnv.buildProjectTargetDir.resolve(CACHES_DIR_NAME).resolve(pkgDescriptor.org().value()) + .resolve(pkgDescriptor.name().value()).resolve(pkgDescriptor.version().toString()); + } + /** * A factory that creates instances of {@code FileSystemCache} for the given project. * diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/CodegenOptimizationConstants.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/CodegenOptimizationConstants.java new file mode 100644 index 000000000000..2e90e1c94f1c --- /dev/null +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/CodegenOptimizationConstants.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.ballerina.projects.util; + +/** + * Defines constants related to the codegen optimization. + * + * @since 2201.10.0 + */ +public class CodegenOptimizationConstants { + public static final String BALLERINA_OBSERVE = "ballerina/observe"; + public static final String BALLERINAI_OBSERVE = "ballerinai/observe"; + public static final String BALLERINA_JBALLERINA = "ballerina/jballerina"; + public static final String BALLERINA_JBALLERINA_JAVA = BALLERINA_JBALLERINA + ".java"; + public static final String BALLERINA_LANG = "ballerina/lang"; + public static final String BALLERINAX = "ballerinax/"; + public static final String DOT_DRIVER = ".driver"; + public static final String CLASS = "class"; + public static final String DOT_CLASS = ".class"; + public static final String INTEROP_DEPENDENCIES_PROPERTIES_FILE = "interop-dependencies.properties"; + public static final String EXTERNAL_DEPENDENCY_ANNOT = "ExternalDependency"; +} diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/CodegenOptimizationUtils.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/CodegenOptimizationUtils.java new file mode 100644 index 000000000000..64e7af682460 --- /dev/null +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/CodegenOptimizationUtils.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.ballerina.projects.util; + +import org.ballerinalang.model.elements.PackageID; + +import static io.ballerina.projects.util.CodegenOptimizationConstants.BALLERINAX; +import static io.ballerina.projects.util.CodegenOptimizationConstants.BALLERINA_JBALLERINA_JAVA; +import static io.ballerina.projects.util.CodegenOptimizationConstants.BALLERINA_LANG; +import static io.ballerina.projects.util.CodegenOptimizationConstants.BALLERINA_OBSERVE; +import static io.ballerina.projects.util.CodegenOptimizationConstants.DOT_DRIVER; + +/** + * Common utils for codegen optimization implementation. + * + * @since 2201.10.0 + */ +public final class CodegenOptimizationUtils { + + private CodegenOptimizationUtils() { + } + + public static boolean isObserveModule(PackageID packageID) { + return packageID.getPackageNameWithOrg().equals(BALLERINA_OBSERVE); + } + + public static boolean isDriverModule(PackageID packageID) { + return packageID.getPackageNameWithOrg().startsWith(BALLERINAX) && + packageID.getPackageNameWithOrg().endsWith(DOT_DRIVER); + } + + public static boolean isLangLibModule(PackageID packageID) { + return packageID.getPackageNameWithOrg().startsWith(BALLERINA_LANG); + } + + public static boolean isJBallerinaModule(PackageID packageID) { + return packageID.getPackageNameWithOrg().equals(BALLERINA_JBALLERINA_JAVA); + } + + public static boolean isWhiteListedModule(PackageID packageID) { + return isObserveModule(packageID) || isDriverModule(packageID) || isJBallerinaModule(packageID) + || isLangLibModule(packageID); + } +} diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/ProjectConstants.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/ProjectConstants.java index 17df391454cd..c7ffbdf792be 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/ProjectConstants.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/ProjectConstants.java @@ -90,6 +90,8 @@ private ProjectConstants() {} public static final String BLANG_COMPILED_PKG_BINARY_EXT = ".bala"; public static final String BLANG_COMPILED_PKG_BIR_EXT = ".bir"; public static final String BLANG_COMPILED_JAR_EXT = ".jar"; + public static final String BYTECODE_OPTIMIZED_JAR_SUFFIX = "_OPTIMIZED.jar"; + public static final String BIR_OPTIMIZED_JAR_SUFFIX = "_BIR_OPTIMIZED.jar"; public static final String RESOURCE_DIR_NAME = "resources"; public static final String TARGET_BALA_DIR_NAME = "bala"; diff --git a/compiler/ballerina-lang/src/main/java/module-info.java b/compiler/ballerina-lang/src/main/java/module-info.java index 5c8060c52680..62032e2b76c7 100644 --- a/compiler/ballerina-lang/src/main/java/module-info.java +++ b/compiler/ballerina-lang/src/main/java/module-info.java @@ -5,6 +5,7 @@ requires com.google.gson; requires java.xml; requires org.objectweb.asm; + requires org.objectweb.asm.tree; requires io.ballerina.runtime; requires io.netty.buffer; requires io.ballerina.parser; @@ -84,4 +85,5 @@ io.ballerina.language.server.core; exports io.ballerina.projects.plugins.completion; exports io.ballerina.projects.buildtools; + exports org.wso2.ballerinalang.compiler.bir.codegen.bytecodeoptimizer; } diff --git a/compiler/ballerina-lang/src/main/java/org/ballerinalang/model/elements/PackageID.java b/compiler/ballerina-lang/src/main/java/org/ballerinalang/model/elements/PackageID.java index f33bc65873cc..1f04e0618298 100644 --- a/compiler/ballerina-lang/src/main/java/org/ballerinalang/model/elements/PackageID.java +++ b/compiler/ballerina-lang/src/main/java/org/ballerinalang/model/elements/PackageID.java @@ -271,6 +271,19 @@ public String toString() { return org + this.name + Names.VERSION_SEPARATOR.value + this.version; } + public String getPackageNameWithOrg() { + if (Names.DOT.equals(this.name)) { + return this.name.value; + } + + String org = ""; + if (this.orgName != null && !this.orgName.equals(Names.ANON_ORG)) { + org = this.orgName + Names.ORG_NAME_SEPARATOR.value; + } + + return org + this.name; + } + public Name getOrgName() { return orgName; } diff --git a/compiler/ballerina-lang/src/main/java/org/ballerinalang/model/types/Type.java b/compiler/ballerina-lang/src/main/java/org/ballerinalang/model/types/Type.java index 96b38ad750cf..937700ce18a4 100644 --- a/compiler/ballerina-lang/src/main/java/org/ballerinalang/model/types/Type.java +++ b/compiler/ballerina-lang/src/main/java/org/ballerinalang/model/types/Type.java @@ -17,6 +17,7 @@ */ package org.ballerinalang.model.types; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; /** * {@code Type} represents a type in Ballerina. @@ -27,4 +28,5 @@ public interface Type { TypeKind getKind(); void accept(TypeVisitor visitor); + void accept(BTypeAnalyzer analyzer, T props); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/PackageCache.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/PackageCache.java index 146c3f5a4353..00cff3e74a61 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/PackageCache.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/PackageCache.java @@ -17,7 +17,9 @@ */ package org.wso2.ballerinalang.compiler; +import io.ballerina.projects.UsedBIRNodeAnalyzer; import org.ballerinalang.model.elements.PackageID; +import org.wso2.ballerinalang.compiler.bir.model.BIRNode; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol; import org.wso2.ballerinalang.compiler.tree.BLangPackage; import org.wso2.ballerinalang.compiler.util.CompilerContext; @@ -131,4 +133,23 @@ public void putSymbol(PackageID packageID, BPackageSymbol packageSymbol) { versionMap.put(Names.DEFAULT_VERSION.value, packageSymbol); } } + + public UsedBIRNodeAnalyzer.InvocationData getInvocationData(PackageID packageID) { + if (packageID == null) { + return null; + } + BPackageSymbol pkgSymbol = getSymbol(packageID); + if (pkgSymbol == null) { + return null; + } + return pkgSymbol.invocationData; + } + + public BIRNode.BIRPackage getBirPkg(PackageID packageID) { + BPackageSymbol pkgSymbol = getSymbol(packageID); + if (pkgSymbol == null) { + return null; + } + return pkgSymbol.bir; + } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java index 9d74da3a22a2..9845ca03efc4 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java @@ -279,18 +279,42 @@ private BIRGen(CompilerContext context) { } public BLangPackage genBIR(BLangPackage astPkg) { + genBIR(astPkg, false); + + if (astPkg.symbol.shouldGenerateDuplicateBIR) { + genBIR(astPkg, true); + // If we don't flip the BIRs the global var references between pkgs will use the new BIRNodes as references. + // This breaks the usedBIRNodeAnalyzer + flipBIRs(astPkg); + } + return astPkg; + } + + private void flipBIRs(BLangPackage astPkg) { + BIRPackage originalBIR = astPkg.symbol.bir; + astPkg.symbol.bir = astPkg.symbol.duplicateBir; + astPkg.symbol.duplicateBir = originalBIR; + } + + public void genBIR(BLangPackage astPkg, Boolean isDuplicateGeneration) { boolean skipTest = astPkg.moduleContextDataHolder.skipTests(); String sourceRoot = astPkg.moduleContextDataHolder.sourceRoot().toString(); BIRPackage birPkg = new BIRPackage(astPkg.pos, astPkg.packageID.orgName, astPkg.packageID.pkgName, astPkg.packageID.name, astPkg.packageID.version, astPkg.packageID.sourceFileName, sourceRoot, skipTest); - astPkg.symbol.bir = birPkg; //TODO try to remove this + if (!isDuplicateGeneration) { + astPkg.symbol.bir = birPkg; + } else { + astPkg.symbol.duplicateBir = birPkg; + } this.env = new BIRGenEnv(birPkg); astPkg.accept(this); this.birOptimizer.optimizePackage(birPkg); + + //TODO stop duplicate birgen for testable pkgs. It is not needed if (!astPkg.moduleContextDataHolder.skipTests() && astPkg.hasTestablePackage()) { astPkg.getTestablePkgs().forEach(testPkg -> { BIRPackage testBirPkg = new BIRPackage(testPkg.pos, testPkg.packageID.orgName, @@ -299,16 +323,20 @@ public BLangPackage genBIR(BLangPackage astPkg) { this.env = new BIRGenEnv(testBirPkg); testPkg.accept(this); this.birOptimizer.optimizePackage(testBirPkg); - testPkg.symbol.bir = testBirPkg; + if (!isDuplicateGeneration) { + testPkg.symbol.bir = testBirPkg; + } else { + // Technically this should never hit + //TODO find a way to restrict duplicate generation for tests + testPkg.symbol.duplicateBir = testBirPkg; + } testBirPkg.importModules.add(new BIRNode.BIRImportModule(null, testPkg.packageID.orgName, testPkg.packageID.name, testPkg.packageID.version)); }); } - - setEntryPoints(astPkg); - return astPkg; } + private void setEntryPoints(BLangPackage pkgNode) { BLangFunction mainFunc = getMainFunction(pkgNode); if (mainFunc != null || listenerDeclarationFound(pkgNode.getGlobalVariables()) || !pkgNode.services.isEmpty()) { @@ -899,6 +927,10 @@ private Name getFuncName(BInvokableSymbol symbol) { return Names.fromString(attachedFuncName.substring(offset)); } + private Name getFuncOriginalName(BInvokableSymbol symbol) { + return symbol.name; + } + private void addParam(BIRFunction birFunc, BLangVariable functionParam) { addParam(birFunc, functionParam.symbol, functionParam.expr, functionParam.pos, functionParam.symbol.getAnnotations()); @@ -1431,7 +1463,8 @@ isVirtual, invocationExpr.symbol.pkgID, getFuncName((BInvokableSymbol) invocatio List calleeAnnots = getBIRAnnotAttachments(bInvokableSymbol.getAnnotations()); this.env.enclBB.terminator = new BIRTerminator.Call(invocationExpr.pos, InstructionKind.CALL, isVirtual, - invocationExpr.symbol.pkgID, getFuncName((BInvokableSymbol) invocationExpr.symbol), args, lhsOp, + invocationExpr.symbol.pkgID, getFuncName((BInvokableSymbol) invocationExpr.symbol), + getFuncOriginalName((BInvokableSymbol) invocationExpr.symbol), args, lhsOp, thenBB, calleeAnnots, bInvokableSymbol.getFlags(), this.currentScope); } this.env.enclBB = thenBB; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/CodeGenerator.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/CodeGenerator.java index d52d4b9e801f..536d32b06fa7 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/CodeGenerator.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/CodeGenerator.java @@ -59,20 +59,24 @@ public static CodeGenerator getInstance(CompilerContext context) { return codeGenerator; } - public CompiledJarFile generate(BLangPackage bLangPackage, boolean isRemoteMgtEnabled) { + public CompiledJarFile generate(BLangPackage bLangPackage, Boolean isDuplicateGeneration, + boolean isRemoteMgtEnabled) { // generate module - return generate(bLangPackage.symbol, isRemoteMgtEnabled); + return generate(bLangPackage.symbol, isDuplicateGeneration, isRemoteMgtEnabled); } public CompiledJarFile generateTestModule(BLangPackage bLangTestablePackage, boolean isRemoteMgtEnabled) { - return generate(bLangTestablePackage.symbol, isRemoteMgtEnabled); + return generate(bLangTestablePackage.symbol, false, isRemoteMgtEnabled); } - private CompiledJarFile generate(BPackageSymbol packageSymbol, boolean isRemoteMgtEnabled) { + private CompiledJarFile generate(BPackageSymbol packageSymbol, Boolean isDuplicateGeneration, + boolean isRemoteMgtEnabled) { // Desugar BIR to include the observations JvmObservabilityGen jvmObservabilityGen = new JvmObservabilityGen(packageCache, symbolTable); jvmObservabilityGen.instrumentPackage(packageSymbol.bir); + JvmCodeGenUtil.isOptimizedCodeGen = isDuplicateGeneration; + // Re-arrange basic blocks and error entries BIRGenUtils.rearrangeBasicBlocks(packageSymbol.bir); @@ -88,6 +92,9 @@ private CompiledJarFile generate(BPackageSymbol packageSymbol, boolean isRemoteM cleanUpBirPackage(packageSymbol); //Revert encoding identifier names JvmDesugarPhase.replaceEncodedModuleIdentifiers(packageSymbol.bir, originalIdentifierMap); + + JvmCodeGenUtil.isOptimizedCodeGen = false; + JvmCodeGenUtil.isRootPkgCodeGen = false; return compiledJarFile; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java index bc6010e377ef..472f4148f72b 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java @@ -52,7 +52,9 @@ import org.wso2.ballerinalang.compiler.util.Unifier; import org.wso2.ballerinalang.util.Flags; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.regex.Pattern; @@ -158,6 +160,9 @@ public class JvmCodeGenUtil { private static final Pattern JVM_RESERVED_CHAR_SET = Pattern.compile("[.:/<>]"); public static final String SCOPE_PREFIX = "_SCOPE_"; public static final NameHashComparator NAME_HASH_COMPARATOR = new NameHashComparator(); + public static Boolean isOptimizedCodeGen = false; + public static Boolean isRootPkgCodeGen = false; + public static Map duplicatePkgsMap = new HashMap<>(); static void visitInvokeDynamic(MethodVisitor mv, String currentClass, String lambdaName, int size) { String mapDesc = getMapsDesc(size); @@ -291,9 +296,24 @@ private static String getPackageNameWithSeparator(PackageID packageID, String se if (!orgName.equalsIgnoreCase("$anon")) { packageName = orgName + separator + packageName; } + + if (isOptimizedReferenceInsideOptimizedPkg(packageID) || isOptimizedReferenceInsideRootPkg(packageID)) { + packageName = "OPTIMIZED_" + packageName; + } + return packageName; } + private static Boolean isOptimizedReferenceInsideRootPkg(PackageID referencePkgID) { + return isRootPkgCodeGen && duplicatePkgsMap + .containsKey(referencePkgID.orgName + referencePkgID.getNameComps().toString()); + } + + private static Boolean isOptimizedReferenceInsideOptimizedPkg(PackageID referencePkgID) { + return isOptimizedCodeGen && duplicatePkgsMap + .containsKey(referencePkgID.orgName + referencePkgID.getNameComps().toString()); + } + public static String getModuleLevelClassName(PackageID packageID, String sourceFileName) { return getModuleLevelClassName(packageID, sourceFileName, "/"); } @@ -812,4 +832,8 @@ public static String getSig(Class c) { } } } + + public static void markIsRootPackage() { + isRootPkgCodeGen = true; + } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/AnnotationNodeVisitor.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/AnnotationNodeVisitor.java new file mode 100644 index 000000000000..8cd852442baf --- /dev/null +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/AnnotationNodeVisitor.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.ballerinalang.compiler.bir.codegen.bytecodeoptimizer; + +import org.objectweb.asm.AnnotationVisitor; +import org.objectweb.asm.Type; + +import static org.objectweb.asm.Opcodes.ASM9; + +/** + * A visitor class used to visit annotations and collect used class types. + * + * @since 2201.10.0 + */ +public final class AnnotationNodeVisitor extends AnnotationVisitor { + + private final DependencyCollector collector; + + public AnnotationNodeVisitor(DependencyCollector collector) { + super(ASM9); + this.collector = collector; + } + + @Override + public void visit(String name, Object value) { + if (value instanceof Type type) { + collector.addType(type); + } + } + + @Override + public void visitEnum(String name, String desc, String value) { + collector.addDesc(desc); + } + + @Override + public AnnotationVisitor visitAnnotation(String name, String desc) { + collector.addDesc(desc); + return this; + } + + @Override + public AnnotationVisitor visitArray(String name) { + return this; + } +} diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/ClassNodeVisitor.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/ClassNodeVisitor.java new file mode 100644 index 000000000000..a05b0172838d --- /dev/null +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/ClassNodeVisitor.java @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.ballerinalang.compiler.bir.codegen.bytecodeoptimizer; + +import org.objectweb.asm.AnnotationVisitor; +import org.objectweb.asm.Attribute; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.FieldVisitor; +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.ModuleVisitor; +import org.objectweb.asm.Type; +import org.objectweb.asm.TypePath; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.MethodNode; + +import java.util.ArrayList; +import java.util.Set; + +import static org.objectweb.asm.Opcodes.ASM9; + +/** + * A class node visitor to visit the class attributes and annotations of a graph node. + * Also adds the names of all the methods in the class to the method list. + * + * @since 2201.10.0 + */ +public final class ClassNodeVisitor extends ClassNode { + + private final DependencyCollector collector; + private final ClassReader reader; + + public ClassNodeVisitor(byte[] classBytes) { + super(ASM9); + this.reader = new ClassReader(classBytes); + this.collector = new DependencyCollector(); + } + + void analyzeClass() { + this.reader.accept(this, 0); + } + + Set getDependentClasses() { + return this.collector.getDependencies(); + } + + /** + * Visit class's super class and implemented interfaces to the list of used dependency classes. + */ + @Override + public void visit(int version, int access, String name, String signature, String superName, + String[] interfaces) { + this.access = access; + if (signature == null) { + if (superName != null) { + collector.addName(superName); + } + collector.addInternalNames(interfaces); + } else { + collector.addSignature(signature); + } + + collector.addName(superName); + for (String parentInterface : interfaces) { + collector.addName(parentInterface); + } + } + + @Override + public void visitSource(String file, String debug) { + } + + @Override + public ModuleVisitor visitModule(String name, int access, String version) { + return null; + } + + @Override + public void visitOuterClass(String owner, String name, String desc) { + if (desc != null) { + collector.addDesc(desc); + } + } + + @Override + public void visitInnerClass(String name, String outerName, String innerName, int access) { + } + + @Override + public void visitAttribute(Attribute attr) { + collector.addInternalName(attr.type); + if (attrs == null) { + attrs = new ArrayList<>(1); + } + } + + @Override + public AnnotationVisitor visitAnnotation(String desc, boolean visible) { + collector.addDesc(desc); + return new AnnotationNodeVisitor(collector); + } + + @Override + public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { + collector.addDesc(desc); + return new AnnotationNodeVisitor(collector); + } + + /** + * Visit class level fields and add field types to class-level dependencies. + */ + @Override + public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { + if (signature == null) { + collector.addDesc(desc); + } else { + collector.addSignature(signature); + } + if (value instanceof Type type) { + collector.addType(type); + } + return new FieldNodeVisitor(collector); + } + + /** + * Create a MethodGraphNode for each method in a class and adds it to the method list. + */ + @Override + public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { + MethodNode mn = new MethodNode(access, name, desc, signature, exceptions); + methods.add(mn); + if (signature == null) { + collector.addMethodDesc(desc); + } else { + collector.addSignature(signature); + } + collector.addInternalNames(exceptions); + return new MethodNodeVisitor(collector); + } +} diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/DependencyCollector.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/DependencyCollector.java new file mode 100644 index 000000000000..d3e275c92f0f --- /dev/null +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/DependencyCollector.java @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.ballerinalang.compiler.bir.codegen.bytecodeoptimizer; +import org.objectweb.asm.Handle; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.Type; +import org.objectweb.asm.signature.SignatureReader; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Collects the dependent classes used by a particular class. + * + * @since 2201.10.0 + */ +public final class DependencyCollector { + + private static final Pattern pattern = getPattern(); + private final Set dependencies = new HashSet<>(); + + public DependencyCollector() { + } + + private static Pattern getPattern() { + return Pattern.compile("([a-zA-Z]\\w+/)+(\\w|[$])+"); + } + + /** + * Get the class name corresponding to the Type object passed. + */ + public void addType(Type type) { + switch (type.getSort()) { + case Type.ARRAY -> addType(type.getElementType()); + case Type.OBJECT -> addName(type.getInternalName()); + case Type.METHOD -> addMethodDesc(type.getDescriptor()); + default -> { + // Do nothing + } + } + } + + /** + * Get the class name corresponding to a field, annotation, or variable description. + */ + public void addDesc(String desc) { + addType(Type.getType(desc)); + } + + /** + * Get the types of the classes used in a class, method, field signature. + */ + public void addSignature(String signature) { + if (signature != null) { + new SignatureReader(signature).accept(new SignatureNodeVisitor(this)); + } + } + + public void addTypeSignature(String signature) { + if (signature != null) { + new SignatureReader(signature).acceptType(new SignatureNodeVisitor(this)); + } + } + + /** + * Get the class types of passed constants. + */ + public void addConstant(Object constant) { + if (constant instanceof Type) { + addType((Type) constant); + } else if (constant instanceof Handle handle) { + addInternalName(handle.getOwner()); + if (handle.getTag() == Opcodes.H_GETFIELD) { + addType(Type.getType(handle.getDesc())); + } else { + addMethodDesc(handle.getDesc()); + } + } else if (constant instanceof String s) { + //if the passed string matches the patters of a class name, add it as a dependency. + if (checkStringConstant(s.replace('.', '/'))) { + addInternalName(s.replace('.', '/')); + } + } + } + + /** + * Get the parameter types and return type of a method using method description. + */ + public void addMethodDesc(String desc) { + if (desc.length() <= 3) { + return; + } + addType(Type.getReturnType(desc)); + Type[] types = Type.getArgumentTypes(desc); + for (Type type : types) { + addType(type); + } + } + + /** + * Get the Type of the class represented by the given class name. + */ + public void addInternalName(String name) { + addType(Type.getObjectType(name)); + } + + public void addInternalNames(String[] names) { + if (names == null) { + return; + } + for (String name : names) { + addInternalName(name); + } + } + + /** + * Get the ClassGraphNode for the given class name from builder and add it as a + * class dependency of the current class. Only those that have created nodes are added. + */ + public void addName(String name) { + dependencies.add(name); + } + + /** + * Check if a string passed with ldc command matches the pattern of a class name. + * Purpose is catching classes passed through reflection + */ + public boolean checkStringConstant(String s) { + Matcher matcher = pattern.matcher(s); + return matcher.matches(); + } + + public Set getDependencies() { + return Collections.unmodifiableSet(dependencies); + } +} diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/FieldNodeVisitor.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/FieldNodeVisitor.java new file mode 100644 index 000000000000..4ae184c6dd8b --- /dev/null +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/FieldNodeVisitor.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.ballerinalang.compiler.bir.codegen.bytecodeoptimizer; + +import org.objectweb.asm.AnnotationVisitor; +import org.objectweb.asm.FieldVisitor; + +import static org.objectweb.asm.Opcodes.ASM9; + +/** + * A visitor class used to visit fields and collect used class types. + * + * @since 2201.10.0 + */ +public final class FieldNodeVisitor extends FieldVisitor { + + private final DependencyCollector collector; + + public FieldNodeVisitor(DependencyCollector collector) { + super(ASM9); + this.collector = collector; + } + + @Override + public AnnotationVisitor visitAnnotation(String desc, boolean visible) { + collector.addDesc(desc); + return new AnnotationNodeVisitor(collector); + } +} diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/MethodNodeVisitor.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/MethodNodeVisitor.java new file mode 100644 index 000000000000..d4a01f037121 --- /dev/null +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/MethodNodeVisitor.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.ballerinalang.compiler.bir.codegen.bytecodeoptimizer; + +import org.objectweb.asm.AnnotationVisitor; +import org.objectweb.asm.Handle; +import org.objectweb.asm.Label; +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Type; +import org.objectweb.asm.TypePath; + +import static org.objectweb.asm.Opcodes.ASM9; + +/** + * A visitor class used to visit methods collect used class types. + * + * @since 2201.10.0 + */ +public final class MethodNodeVisitor extends MethodVisitor { + + private final DependencyCollector collector; + + public MethodNodeVisitor(DependencyCollector collector) { + super(ASM9); + this.collector = collector; + } + + @Override + public AnnotationVisitor visitAnnotationDefault() { + return new AnnotationNodeVisitor(collector); + } + + @Override + public AnnotationVisitor visitAnnotation(String desc, boolean visible) { + return getAnnotationNodeVisitor(collector, desc); + } + + @Override + public AnnotationVisitor visitParameterAnnotation(int parameter, String desc, boolean visible) { + return getAnnotationNodeVisitor(collector, desc); + } + + @Override + public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { + return getAnnotationNodeVisitor(collector, desc); + } + + @Override + public void visitTypeInsn(int opcode, String type) { + collector.addType(Type.getObjectType(type)); + } + + @Override + public void visitFieldInsn(int opcode, String owner, String name, String desc) { + collectOwnerAndDesc(collector, owner, desc); + } + + @Override + public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { + collectOwnerAndDesc(collector, owner, desc); + } + + @Override + public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object... bsmArgs) { + collector.addMethodDesc(desc); + collector.addConstant(bsm); + for (Object bsmArg : bsmArgs) { + collector.addConstant(bsmArg); + } + } + + @Override + public void visitLdcInsn(Object constant) { + collector.addConstant(constant); + } + + @Override + public void visitMultiANewArrayInsn(String desc, int dims) { + collector.addDesc(desc); + } + + @Override + public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) { + collector.addTypeSignature(signature); + } + + @Override + public void visitTryCatchBlock(Label start, Label end, Label handler, String type) { + if (type != null) { + collector.addInternalName(type); + } + } + + private static AnnotationNodeVisitor getAnnotationNodeVisitor(DependencyCollector collector, String desc) { + collector.addDesc(desc); + return new AnnotationNodeVisitor(collector); + } + + private static void collectOwnerAndDesc(DependencyCollector collector, String owner, String desc) { + collector.addInternalName(owner); + collector.addDesc(desc); + } +} + diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/NativeDependencyOptimizationReport.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/NativeDependencyOptimizationReport.java new file mode 100644 index 000000000000..6fbdb6b5b416 --- /dev/null +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/NativeDependencyOptimizationReport.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.ballerinalang.compiler.bir.codegen.bytecodeoptimizer; + +import java.util.Set; + +/** + * Java record to store class level native optimization report data to JSON. + * + * @param startPointClasses start points identified by the NativeDependencyOptimizer + * @param usedExternalClasses used classes which are not present in the executable JAR (JRE classes) + * @param usedClasses used classes present in the executable JAR + * @param unusedClasses unused classes present in the executable JAR + * + * @since 2201.10.0 + */ +record NativeDependencyOptimizationReport(Set startPointClasses, Set usedExternalClasses, + Set usedClasses, Set unusedClasses) { + +} diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/NativeDependencyOptimizationReportEmitter.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/NativeDependencyOptimizationReportEmitter.java new file mode 100644 index 000000000000..cf1f745cd3f0 --- /dev/null +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/NativeDependencyOptimizationReportEmitter.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.ballerinalang.compiler.bir.codegen.bytecodeoptimizer; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import io.ballerina.projects.ProjectException; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; + +/** + * Emits optimized class file details for native dependency optimization. + * + * @since 2201.10.0 + */ +public final class NativeDependencyOptimizationReportEmitter { + + private NativeDependencyOptimizationReportEmitter() { + } + + private static final String NATIVE_DEPENDENCY_OPTIMIZATION_REPORT = "native_dependency_optimization_report.json"; + + public static void emitCodegenOptimizationReport(NativeDependencyOptimizationReport report, + Path reportParentDirectoryPath) { + if (!Files.exists(reportParentDirectoryPath)) { + try { + Files.createDirectories(reportParentDirectoryPath); + } catch (IOException e) { + throw new ProjectException("Failed to create optimization report directory ", e); + } + } + + Path jsonFilePath = reportParentDirectoryPath.resolve(NATIVE_DEPENDENCY_OPTIMIZATION_REPORT); + File jsonFile = new File(jsonFilePath.toString()); + + try (Writer writer = new OutputStreamWriter(new FileOutputStream(jsonFile), StandardCharsets.UTF_8)) { + Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create(); + String json = gson.toJson(report); + writer.write(new String(json.getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8)); + } catch (IOException e) { + throw new ProjectException("couldn't write data to optimization report file : ", e); + } + } +} + diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/NativeDependencyOptimizer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/NativeDependencyOptimizer.java new file mode 100644 index 000000000000..f639991ed1a2 --- /dev/null +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/NativeDependencyOptimizer.java @@ -0,0 +1,268 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.ballerinalang.compiler.bir.codegen.bytecodeoptimizer; + +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; +import org.apache.commons.compress.archivers.zip.ZipArchiveEntryPredicate; +import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; +import org.apache.commons.compress.archivers.zip.ZipFile; +import org.apache.commons.io.IOUtils; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.StandardCharsets; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.Stack; + +/** + * Optimizes a given JAR on class file level. + * + * @since 2201.10.0 + */ +public final class NativeDependencyOptimizer { + + private static final String CLASS = ".class"; + private static final String SERVICE_PROVIDER_DIRECTORY = "META-INF/services/"; + private static final String NATIVE_IMAGE_DIRECTORY = "META-INF/native-image"; + private static final String REFLECT_CONFIG_JSON = "reflect-config.json"; + private static final String JNI_CONFIG_JSON = "jni-config.json"; + private static final String MODULE_INFO = "module-info"; + + // These directories are whitelisted due to usages of "sun.misc.Unsafe" class + // TODO Find a way to whitelist only the necessary class files + private static final Set WHITELISTED_DIRECTORIES = new HashSet<>(List.of("io/netty/util")); + + /** + * These classes are used by GraalVM when building the native-image. Since they are not connected to the root class, + * they will be removed by the NativeDependencyOptimizer if they are not whitelisted. + */ + private static final Set GRAALVM_FEATURE_CLASSES = + new HashSet<>(List.of("io/ballerina/stdlib/crypto/svm/BouncyCastleFeature")); + + /** + * key = implementation class name, value = interface class name. + * Since one interface can be implemented by more than one child class, it is possible to have duplicate values. + *

+ * TODO modify the service provider files and delete the lines containing the UNUSED implementations of interfaces + */ + private static final Map implementationWiseAllServiceProviders = new HashMap<>(); + + /** + * key = used interface, value = used implementation. + */ + private static final Map> interfaceWiseAllServiceProviders = new HashMap<>(); + private static final Set usedSpInterfaces = new LinkedHashSet<>(); + private static final Gson gson = new Gson(); + private final Set startPointClasses; + private final Stack usedClassesStack; + // TODO use externalClasses field when modularizing the NativeDependencyOptimizer + private final Set externalClasses = new LinkedHashSet<>(); + private final Set visitedClasses = new LinkedHashSet<>(); + private final ZipFile originalJarFile; + private final ZipArchiveOutputStream optimizedJarStream; + + public NativeDependencyOptimizer(Set startPointClasses, ZipFile originalJarFile, + ZipArchiveOutputStream optimizedJarStream) { + + this.startPointClasses = startPointClasses; + this.originalJarFile = originalJarFile; + this.optimizedJarStream = optimizedJarStream; + this.usedClassesStack = new Stack<>(); + } + + private static boolean isWhiteListedEntryName(String entryName) { + if (entryName.equals(MODULE_INFO + CLASS)) { + return true; + } + + for (String whiteListedDirectory : WHITELISTED_DIRECTORIES) { + if (entryName.startsWith(whiteListedDirectory)) { + return true; + } + } + return false; + } + + private static LinkedHashSet getServiceProviderImplementations(ZipFile originalJarFile, + ZipArchiveEntry entry) throws IOException { + String allImplString = IOUtils.toString(originalJarFile.getInputStream(entry), StandardCharsets.UTF_8); + String[] serviceImplClassesArr = allImplString.split("\n"); + LinkedHashSet serviceProviderDependencies = new LinkedHashSet<>(); + + for (String serviceClass : serviceImplClassesArr) { + // Skipping the licensing comments + if (serviceClass.startsWith("#") || serviceClass.isBlank()) { + continue; + } + serviceProviderDependencies.add(getServiceProviderClassName(serviceClass)); + } + + return serviceProviderDependencies; + } + + private static boolean isServiceProvider(String entryName) { + return entryName.startsWith(SERVICE_PROVIDER_DIRECTORY); + } + + private static String getServiceProviderClassName(String providerFileName) { + int i = providerFileName.lastIndexOf('/'); + return providerFileName.substring(i + 1).replace(".", "/"); + } + + public void analyzeUsedClasses() throws IOException { + if (!jarContainsStartPoints()) { + return; + } + usedClassesStack.addAll(startPointClasses); + + while (!usedClassesStack.empty()) { + String usedClassName = usedClassesStack.pop(); + if (visitedClasses.contains(usedClassName + CLASS)) { + continue; + } + + visitedClasses.add(usedClassName + CLASS); + ZipArchiveEntry usedJarEntry = originalJarFile.getEntry(usedClassName + CLASS); + + if (usedJarEntry == null) { + externalClasses.add(usedClassName); + continue; + } + + if (interfaceWiseAllServiceProviders.containsKey(usedClassName)) { + usedSpInterfaces.add(usedClassName); + usedClassesStack.addAll(interfaceWiseAllServiceProviders.get(usedClassName)); + } + + InputStream usedClassStream = originalJarFile.getInputStream(usedJarEntry); + byte[] usedClassByteArr = IOUtils.toByteArray(usedClassStream); + + ClassNodeVisitor classNodeVisitor = new ClassNodeVisitor(usedClassByteArr); + classNodeVisitor.analyzeClass(); + usedClassesStack.addAll(classNodeVisitor.getDependentClasses()); + } + } + + public void analyzeWhiteListedClasses() throws IOException { + Enumeration jarEntries = originalJarFile.getEntries(); + while (jarEntries.hasMoreElements()) { + ZipArchiveEntry currentEntry = jarEntries.nextElement(); + + if (isServiceProvider(currentEntry.getName())) { + analyzeServiceProviders(currentEntry); + } + + if (isReflectionConfig(currentEntry.getName())) { + try (BufferedReader reader = new BufferedReader( + new InputStreamReader(originalJarFile.getInputStream(currentEntry), StandardCharsets.UTF_8))) { + whitelistReflectionClasses(reader); + } + } + } + startPointClasses.addAll(GRAALVM_FEATURE_CLASSES); + } + + private void analyzeServiceProviders(ZipArchiveEntry currentEntry) throws IOException { + String spInterfaceClassName = getServiceProviderClassName(currentEntry.getName()); + for (String spImplementationClassName : getServiceProviderImplementations(originalJarFile, currentEntry)) { + implementationWiseAllServiceProviders.put(spImplementationClassName, spInterfaceClassName); + interfaceWiseAllServiceProviders.putIfAbsent(spInterfaceClassName, new LinkedHashSet<>()); + interfaceWiseAllServiceProviders.get(spInterfaceClassName).add(spImplementationClassName); + } + } + + private boolean isReflectionConfig(String entryName) { + return (entryName.endsWith(REFLECT_CONFIG_JSON) || entryName.endsWith(JNI_CONFIG_JSON)) && + entryName.startsWith(NATIVE_IMAGE_DIRECTORY); + } + + private void whitelistReflectionClasses(Reader reader) { + JsonElement jsonElement = gson.fromJson(reader, JsonElement.class); + + jsonElement.getAsJsonArray().forEach(entry -> { + String className = entry.getAsJsonObject().get("name").getAsString(); + if (className.contains("$")) { + startPointClasses.add(className.replace(".", "/").split("\\$")[0]); + } + startPointClasses.add(className.replace(".", "/")); + }); + } + + public void copyUsedEntries() throws IOException { + ZipArchiveEntryPredicate usedClassPredicate = entry -> { + String entryName = entry.getName(); + + if (entry.isDirectory()) { + return true; + } + if (!entryName.endsWith(CLASS)) { + if (isServiceProvider(entryName)) { + return usedSpInterfaces.contains(getServiceProviderClassName(entryName)); + } + return true; + } + return visitedClasses.contains(entryName) || isWhiteListedEntryName(entryName); + }; + + originalJarFile.copyRawEntries(optimizedJarStream, usedClassPredicate); + } + + public NativeDependencyOptimizationReport getNativeDependencyOptimizationReport() { + return new NativeDependencyOptimizationReport(this.startPointClasses, this.externalClasses, this.visitedClasses, + getUnusedClasses()); + } + + private LinkedHashSet getUnusedClasses() { + LinkedHashSet unusedClasses = new LinkedHashSet<>(); + Enumeration entries = this.originalJarFile.getEntries(); + while (entries.hasMoreElements()) { + ZipArchiveEntry entry = entries.nextElement(); + String className = entry.getName(); + if (!entry.isDirectory() && className.endsWith(CLASS) && !visitedClasses.contains(className) && + !className.equals(MODULE_INFO + CLASS)) { + unusedClasses.add(className); + } + } + return unusedClasses; + } + + /* + This function can be used when modularizing the native dependency optimization. + */ + public boolean jarContainsStartPoints() { + for (String startPoint : startPointClasses) { + ZipArchiveEntry jarEntry = originalJarFile.getEntry(startPoint + CLASS); + if (jarEntry != null) { + return true; + } + } + return false; + } +} diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/SignatureNodeVisitor.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/SignatureNodeVisitor.java new file mode 100644 index 000000000000..7c1507a6c0b9 --- /dev/null +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/bytecodeoptimizer/SignatureNodeVisitor.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.ballerinalang.compiler.bir.codegen.bytecodeoptimizer; + +import org.objectweb.asm.signature.SignatureVisitor; + +import static org.objectweb.asm.Opcodes.ASM9; + +/** + * A visitor class used to visit signatures and collect used class types. + * + * @since 2201.10.0 + */ +public final class SignatureNodeVisitor extends SignatureVisitor { + + String signatureClassName; + private final DependencyCollector collector; + + public SignatureNodeVisitor(DependencyCollector collector) { + super(ASM9); + this.collector = collector; + } + + @Override + public void visitClassType(String name) { + signatureClassName = name; + collector.addInternalName(name); + } + + @Override + public void visitInnerClassType(String name) { + signatureClassName = signatureClassName + "$" + name; + collector.addInternalName(signatureClassName); + } +} diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MainMethodGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MainMethodGen.java index 8d3c240960f0..debaf1de0bab 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MainMethodGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MainMethodGen.java @@ -301,7 +301,6 @@ private void generateMethodBody(MethodVisitor mv, String initClass, String stopF int schedulerIndex = indexMap.get("newSchedulerVar"); mv.visitVarInsn(ALOAD, schedulerIndex); mv.visitMethodInsn(INVOKEVIRTUAL, SCHEDULER, SCHEDULER_START_METHOD, VOID_METHOD_DESC, false); - } private void startScheduler(int schedulerVarIndex, MethodVisitor mv) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/model/JBIRFunction.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/model/JBIRFunction.java index 537d38e69763..7309b629bfee 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/model/JBIRFunction.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/model/JBIRFunction.java @@ -29,10 +29,11 @@ public class JBIRFunction extends BIRNode.BIRFunction { public JBIRFunction(BIRFunction birFunction) { super(birFunction.pos, birFunction.name, birFunction.originalName, birFunction.flags, birFunction.origin, - birFunction.type, birFunction.requiredParams, birFunction.receiver, birFunction.restParam, - birFunction.argsCount, birFunction.localVars, birFunction.returnVariable, - birFunction.parameters, birFunction.basicBlocks, birFunction.errorTable, birFunction.workerName, - birFunction.workerChannels, birFunction.annotAttachments, - birFunction.returnTypeAnnots, birFunction.dependentGlobalVars); + birFunction.type, birFunction.requiredParams, birFunction.receiver, birFunction.restParam, + birFunction.argsCount, birFunction.localVars, birFunction.returnVariable, + birFunction.parameters, birFunction.basicBlocks, birFunction.errorTable, birFunction.workerName, + birFunction.workerChannels, birFunction.annotAttachments, + birFunction.returnTypeAnnots, birFunction.dependentGlobalVars, birFunction.usedState, + birFunction.childNodes); } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNode.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNode.java index d2862f16aa9a..8f2e86fb8e70 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNode.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNode.java @@ -23,6 +23,7 @@ import org.ballerinalang.model.elements.MarkdownDocAttachment; import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.model.symbols.SymbolOrigin; +import org.wso2.ballerinalang.compiler.semantics.model.symbols.UsedState; import org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; import org.wso2.ballerinalang.compiler.semantics.model.types.NamedNode; @@ -182,6 +183,14 @@ public int hashCode() { public String toString() { return name.toString(); } + + @Override + public PackageID getPackageID() { + if (this.type == null || this.type.tsymbol == null) { + return null; + } + return this.type.tsymbol.pkgID; + } } /** @@ -234,6 +243,11 @@ public BIRGlobalVariableDcl(Location pos, long flags, BType type, PackageID pkgI public void accept(BIRVisitor visitor) { visitor.visit(this); } + + @Override + public PackageID getPackageID() { + return this.pkgId; + } } /** @@ -380,7 +394,8 @@ public BIRFunction(Location pos, Name name, Name originalName, long flags, Symbo ChannelDetails[] workerChannels, List annotAttachments, List returnTypeAnnots, - Set dependentGlobalVars) { + Set dependentGlobalVars, UsedState usedState, + Set childNodes) { super(pos); this.name = name; this.originalName = originalName; @@ -401,6 +416,8 @@ public BIRFunction(Location pos, Name name, Name originalName, long flags, Symbo this.annotAttachments = annotAttachments; this.returnTypeAnnots = returnTypeAnnots; this.dependentGlobalVars = dependentGlobalVars; + this.usedState = usedState; + this.childNodes = childNodes; } public BIRFunction(Location pos, Name name, Name originalName, long flags, BInvokableType type, Name workerName, @@ -450,6 +467,15 @@ public BIRFunction duplicate() { public Name getName() { return name; } + + @Override + public PackageID getPackageID() { + // TODO use Optional to handle null instances + if (this.type.tsymbol == null) { + return null; + } + return this.type.tsymbol.pkgID; + } } /** @@ -480,6 +506,15 @@ public BIRBasicBlock(String idPrefix, int number) { this.terminator = null; } + public BIRBasicBlock(String id) { + super(null); + // Splitting and reading the number part + this.number = Integer.parseInt(id.split("(?<=\\D)(?=\\d)")[1]); + this.id = new Name(id); + this.instructions = new ArrayList<>(); + this.terminator = null; + } + @Override public void accept(BIRVisitor visitor) { visitor.visit(this); @@ -565,6 +600,14 @@ public String toString() { public Name getName() { return name; } + + @Override + public PackageID getPackageID() { + if (this.type == null || this.type.tsymbol == null) { + return null; + } + return this.type.tsymbol.pkgID; + } } /** @@ -682,6 +725,10 @@ public void accept(BIRVisitor visitor) { visitor.visit(this); } + @Override + public PackageID getPackageID() { + return this.packageID; + } } /** @@ -742,6 +789,13 @@ public void accept(BIRVisitor visitor) { visitor.visit(this); } + @Override + public PackageID getPackageID() { + if (this.type == null || this.type.tsymbol == null) { + return null; + } + return this.type.tsymbol.pkgID; + } } /** @@ -809,6 +863,10 @@ public ConstValue(Object value, BType type) { */ public abstract static class BIRDocumentableNode extends BIRNode { public MarkdownDocAttachment markdownDocAttachment; + public Set childNodes = new HashSet<>(); + // Used for debugging purposes + public Set parentNodes = new HashSet<>(); + public UsedState usedState = UsedState.UNEXPLORED; protected BIRDocumentableNode(Location pos) { super(pos); @@ -817,6 +875,54 @@ protected BIRDocumentableNode(Location pos) { public void setMarkdownDocAttachment(MarkdownDocAttachment markdownDocAttachment) { this.markdownDocAttachment = markdownDocAttachment; } + + public void addChildNode(BIRDocumentableNode childNode) { + if (childNode == null) { + return; + } + childNodes.add(childNode); + addParent(childNode, this); + if (this.usedState == UsedState.USED) { + // It is possible to omit unused modules from codegen if they are identified in the analyzer phase + childNode.markSelfAndChildrenAsUsed(); + } + } + + private static void addParent(BIRDocumentableNode childNode, BIRDocumentableNode parentNode) { + childNode.parentNodes.add(parentNode); + } + + public void markSelfAndChildrenAsUsed() { + if (usedState == UsedState.USED) { + return; + } + usedState = UsedState.USED; + for (BIRDocumentableNode childNode : this.childNodes) { + childNode.markSelfAndChildrenAsUsed(); + } + } + + public boolean isInSamePkg(PackageID analyzedPkgID) { + // PackageID is null for desugared constructs. And desugared constructs cannot be called from another pkg + if (this.getPackageID() == null) { + return true; + } + return this.getPackageID().equals(analyzedPkgID); + } + + public void markSelfAsUnused() { + this.usedState = UsedState.UNUSED; + } + + public void markAsUsed() { + this.usedState = UsedState.USED; + } + + public UsedState getUsedState() { + return this.usedState; + } + + public abstract PackageID getPackageID(); } /** @@ -958,11 +1064,20 @@ public BIRServiceDeclaration(List attachPoint, String attachPointLiteral this.type = type; this.origin = origin; this.flags = flags; + this.usedState = UsedState.USED; } @Override public void accept(BIRVisitor visitor) { visitor.visit(this); } + + @Override + public PackageID getPackageID() { + if (this.type == null || this.type.tsymbol == null) { + return null; + } + return this.type.tsymbol.pkgID; + } } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRTerminator.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRTerminator.java index 7f02777d0943..e4cff1068aa8 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRTerminator.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRTerminator.java @@ -102,6 +102,7 @@ public static class Call extends BIRTerminator implements BIRAssignInstruction { public boolean isVirtual; public List args; public Name name; + public Name originalName; public PackageID calleePkg; public List calleeAnnotAttachments; public Set calleeFlags; @@ -125,6 +126,7 @@ public Call(Location pos, this.calleePkg = calleePkg; this.calleeAnnotAttachments = calleeAnnotAttachments; this.calleeFlags = calleeFlags; + this.originalName = name; } public Call(Location pos, @@ -142,6 +144,23 @@ public Call(Location pos, this.scope = scope; } + public Call(Location pos, + InstructionKind kind, + boolean isVirtual, + PackageID calleePkg, + Name name, + Name originalName, + List args, + BIROperand lhsOp, + BIRBasicBlock thenBB, + List calleeAnnotAttachments, + Set calleeFlags, + BirScope scope) { + this(pos, kind, isVirtual, calleePkg, name, args, lhsOp, thenBB, calleeAnnotAttachments, calleeFlags); + this.scope = scope; + this.originalName = originalName; + } + @Override public BIROperand getLhsOperand() { return lhsOp; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ASTBuilderUtil.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ASTBuilderUtil.java index be7720ed29b5..2e5d30d0c3d9 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ASTBuilderUtil.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ASTBuilderUtil.java @@ -858,6 +858,7 @@ public static BInvokableSymbol duplicateInvokableSymbol(BInvokableSymbol invokab dupFuncSymbol.tag = invokableSymbol.tag; dupFuncSymbol.schedulerPolicy = invokableSymbol.schedulerPolicy; dupFuncSymbol.strandName = invokableSymbol.strandName; + dupFuncSymbol.owner = invokableSymbol.owner; dupFuncSymbol.setAnnotationAttachments( new ArrayList<>((List) invokableSymbol.getAnnotations())); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SymbolEnter.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SymbolEnter.java index c695585ecd49..955a9afc5d3f 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SymbolEnter.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SymbolEnter.java @@ -182,6 +182,7 @@ import javax.xml.XMLConstants; +import static org.ballerinalang.model.elements.PackageID.ANNOTATIONS; import static org.ballerinalang.model.elements.PackageID.ARRAY; import static org.ballerinalang.model.elements.PackageID.BOOLEAN; import static org.ballerinalang.model.elements.PackageID.DECIMAL; @@ -190,14 +191,18 @@ import static org.ballerinalang.model.elements.PackageID.FUNCTION; import static org.ballerinalang.model.elements.PackageID.FUTURE; import static org.ballerinalang.model.elements.PackageID.INT; +import static org.ballerinalang.model.elements.PackageID.INTERNAL; +import static org.ballerinalang.model.elements.PackageID.JAVA; import static org.ballerinalang.model.elements.PackageID.MAP; import static org.ballerinalang.model.elements.PackageID.OBJECT; import static org.ballerinalang.model.elements.PackageID.QUERY; import static org.ballerinalang.model.elements.PackageID.REGEXP; +import static org.ballerinalang.model.elements.PackageID.RUNTIME; import static org.ballerinalang.model.elements.PackageID.STREAM; import static org.ballerinalang.model.elements.PackageID.STRING; import static org.ballerinalang.model.elements.PackageID.TABLE; import static org.ballerinalang.model.elements.PackageID.TRANSACTION; +import static org.ballerinalang.model.elements.PackageID.TRANSACTION_INTERNAL; import static org.ballerinalang.model.elements.PackageID.TYPEDESC; import static org.ballerinalang.model.elements.PackageID.VALUE; import static org.ballerinalang.model.elements.PackageID.XML; @@ -3686,10 +3691,28 @@ private void populateLangLibInSymTable(BPackageSymbol packageSymbol) { return; } if (langLib.equals(REGEXP)) { + symResolver.loadRawTemplateType(); + symResolver.bootstrapIterableType(); + symResolver.bootstrapIntRangeType(); symTable.langRegexpModuleSymbol = packageSymbol; symTable.updateRegExpTypeOwners(); return; } + if (langLib.equals(ANNOTATIONS)) { + symTable.langAnnotationModuleSymbol = packageSymbol; + } + if (langLib.equals(JAVA)) { + symTable.langJavaModuleSymbol = packageSymbol; + } + if (langLib.equals(INTERNAL)) { + symTable.langInternalModuleSymbol = packageSymbol; + } + if (langLib.equals(RUNTIME)) { + symTable.langRuntimeModuleSymbol = packageSymbol; + } + if (langLib.equals(TRANSACTION_INTERNAL)) { + symTable.internalTransactionModuleSymbol = packageSymbol; + } } public boolean isValidAnnotationType(BType type) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/BTypeAnalyzer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/BTypeAnalyzer.java new file mode 100644 index 000000000000..169960334bec --- /dev/null +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/BTypeAnalyzer.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.ballerinalang.compiler.semantics.model; + +import org.wso2.ballerinalang.compiler.semantics.model.types.BAnnotationType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BAnyType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BAnydataType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BBuiltInRefType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BErrorType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BFiniteType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BFutureType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BHandleType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BIntersectionType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BJSONType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BMapType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BNeverType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BNilType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BNoType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BObjectType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BPackageType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BParameterizedType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BRecordType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BStreamType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BStructureType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BTableType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BTupleType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BTypeReferenceType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BTypedescType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BXMLType; + +/** + * The {@link BTypeAnalyzer} is a {@link BType} visitor. + * + * @param the type of data class that passed along with visit methods. + * @since 2201.10.0 + */ +public abstract class BTypeAnalyzer { + + public abstract void visit(BAnnotationType bAnnotationType, T data); + + public abstract void visit(BArrayType bArrayType, T data); + + public abstract void visit(BBuiltInRefType bBuiltInRefType, T data); + + public abstract void visit(BAnyType bAnyType, T data); + + public abstract void visit(BAnydataType bAnydataType, T data); + + public abstract void visit(BErrorType bErrorType, T data); + + public abstract void visit(BFiniteType bFiniteType, T data); + + public abstract void visit(BInvokableType bInvokableType, T data); + + public abstract void visit(BJSONType bjsonType, T data); + + public abstract void visit(BMapType bMapType, T data); + + public abstract void visit(BStreamType bStreamType, T data); + + public abstract void visit(BTypedescType bTypedescType, T data); + + public abstract void visit(BTypeReferenceType bTypeReferenceType, T data); + + public abstract void visit(BParameterizedType bTypedescType, T data); + + public abstract void visit(BNeverType bNeverType, T data); + + public abstract void visit(BNilType bNilType, T data); + + public abstract void visit(BNoType bNoType, T data); + + public abstract void visit(BPackageType bPackageType, T data); + + public abstract void visit(BStructureType bStructureType, T data); + + public abstract void visit(BTupleType bTupleType, T data); + + public abstract void visit(BUnionType bUnionType, T data); + + public abstract void visit(BIntersectionType bIntersectionType, T data); + + public abstract void visit(BXMLType bxmlType, T data); + + public abstract void visit(BTableType bTableType, T data); + + public abstract void visit(BRecordType bRecordType, T data); + + public abstract void visit(BObjectType bObjectType, T data); + + public abstract void visit(BType bType, T data); + + public abstract void visit(BFutureType bFutureType, T data); + + public abstract void visit(BHandleType bHandleType, T data); +} diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/SimpleBTypeAnalyzer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/SimpleBTypeAnalyzer.java new file mode 100644 index 000000000000..98550a3f0b41 --- /dev/null +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/SimpleBTypeAnalyzer.java @@ -0,0 +1,236 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.ballerinalang.compiler.semantics.model; + +import org.wso2.ballerinalang.compiler.semantics.model.types.BAnnotationType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BAnyType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BAnydataType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BBuiltInRefType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BErrorType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BFiniteType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BFutureType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BHandleType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BIntersectionType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BJSONType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BMapType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BNeverType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BNilType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BNoType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BObjectType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BPackageType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BParameterizedType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BRecordType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BStreamType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BStructureType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BTableType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BTupleType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BTypeReferenceType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BTypedescType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BXMLType; + +/** + * This is simplified node visitor of the {@link BTypeAnalyzer}. + * + * @param the type of data class that passed along with transform methods. + * @since 2201.10.0 + */ +public abstract class SimpleBTypeAnalyzer extends BTypeAnalyzer { + + public abstract void analyzeType(BType bType, T data); + + public void visitType(BType bType, T data) { + if (bType == null) { + return; + } + bType.accept(this, data); + } + + @Override + public void visit(BAnnotationType bAnnotationType, T data) { + analyzeType(bAnnotationType, data); + } + + @Override + public void visit(BArrayType bArrayType, T data) { + analyzeType(bArrayType, data); + visitType(bArrayType.eType, data); + } + + @Override + public void visit(BBuiltInRefType bBuiltInRefType, T data) { + analyzeType(bBuiltInRefType, data); + } + + @Override + public void visit(BAnyType bAnyType, T data) { + analyzeType(bAnyType, data); + } + + @Override + public void visit(BAnydataType bAnydataType, T data) { + analyzeType(bAnydataType, data); + } + + @Override + public void visit(BErrorType bErrorType, T data) { + analyzeType(bErrorType, data); + visitType(bErrorType.detailType, data); + } + + @Override + public void visit(BFiniteType bFiniteType, T data) { + analyzeType(bFiniteType, data); + } + + @Override + public void visit(BInvokableType bInvokableType, T data) { + analyzeType(bInvokableType, data); + if (bInvokableType.paramTypes != null) { + bInvokableType.paramTypes.forEach(param -> visitType(param, data)); + } + visitType(bInvokableType.retType, data); + } + + @Override + public void visit(BJSONType bjsonType, T data) { + analyzeType(bjsonType, data); + } + + @Override + public void visit(BMapType bMapType, T data) { + analyzeType(bMapType, data); + visitType(bMapType.mutableType, data); + visitType(bMapType.constraint, data); + } + + @Override + public void visit(BStreamType bStreamType, T data) { + analyzeType(bStreamType, data); + visitType(bStreamType.constraint, data); + visitType(bStreamType.completionType, data); + } + + @Override + public void visit(BTypedescType bTypedescType, T data) { + analyzeType(bTypedescType, data); + visitType(bTypedescType.constraint, data); + } + + @Override + public void visit(BTypeReferenceType bTypeReferenceType, T data) { + analyzeType(bTypeReferenceType, data); + visitType(bTypeReferenceType.referredType, data); + } + + @Override + public void visit(BParameterizedType bTypedescType, T data) { + analyzeType(bTypedescType, data); + } + + @Override + public void visit(BNeverType bNeverType, T data) { + analyzeType(bNeverType, data); + } + + @Override + public void visit(BNilType bNilType, T data) { + analyzeType(bNilType, data); + } + + @Override + public void visit(BNoType bNoType, T data) { + analyzeType(bNoType, data); + } + + @Override + public void visit(BPackageType bPackageType, T data) { + analyzeType(bPackageType, data); + } + + @Override + public void visit(BStructureType bStructureType, T data) { + analyzeType(bStructureType, data); + bStructureType.fields.values().forEach(field -> visitType(field.type, data)); + } + + @Override + public void visit(BTupleType bTupleType, T data) { + analyzeType(bTupleType, data); + bTupleType.getMembers().forEach(member -> visitType(member.type, data)); + } + + @Override + public void visit(BUnionType bUnionType, T data) { + analyzeType(bUnionType, data); + bUnionType.getOriginalMemberTypes().forEach(member -> visitType(member, data)); + } + + @Override + public void visit(BIntersectionType bIntersectionType, T data) { + analyzeType(bIntersectionType, data); + visitType(bIntersectionType.effectiveType, data); + bIntersectionType.getConstituentTypes().forEach(member -> visitType(member, data)); + } + + @Override + public void visit(BXMLType bxmlType, T data) { + analyzeType(bxmlType, data); + } + + @Override + public void visit(BTableType bTableType, T data) { + analyzeType(bTableType, data); + visitType(bTableType.constraint, data); + } + + @Override + public void visit(BRecordType bRecordType, T data) { + analyzeType(bRecordType, data); + visitType(bRecordType.mutableType, data); + visitType(bRecordType.restFieldType, data); + bRecordType.typeInclusions.forEach(inclusionType -> visitType(inclusionType, data)); + bRecordType.fields.values().forEach(field -> visitType(field.type, data)); + } + + @Override + public void visit(BObjectType bObjectType, T data) { + analyzeType(bObjectType, data); + visitType(bObjectType.mutableType, data); + bObjectType.typeInclusions.forEach(inclusionType -> visitType(inclusionType, data)); + bObjectType.fields.values().forEach(field -> visitType(field.type, data)); + } + + @Override + public void visit(BType bType, T data) { + analyzeType(bType, data); + } + + @Override + public void visit(BFutureType bFutureType, T data) { + analyzeType(bFutureType, data); + } + + @Override + public void visit(BHandleType bHandleType, T data) { + analyzeType(bHandleType, data); + } +} diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BPackageSymbol.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BPackageSymbol.java index aecf695a9253..68022b13d24d 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BPackageSymbol.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BPackageSymbol.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.semantics.model.symbols; import io.ballerina.projects.ModuleDescriptor; +import io.ballerina.projects.UsedBIRNodeAnalyzer; import io.ballerina.tools.diagnostics.Location; import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.model.symbols.SymbolKind; @@ -53,10 +54,13 @@ public class BPackageSymbol extends BTypeSymbol { // TODO Temporary mechanism to hold a reference to the generated bir model public BIRNode.BIRPackage bir; // TODO try to remove this + public Boolean shouldGenerateDuplicateBIR = false; + public BIRNode.BIRPackage duplicateBir; public BIRPackageFile birPackageFile; // TODO Refactor following two flags public boolean entryPointExists = false; + public UsedBIRNodeAnalyzer.InvocationData invocationData = new UsedBIRNodeAnalyzer.InvocationData(); public BPackageSymbol(PackageID pkgID, BSymbol owner, Location pos, SymbolOrigin origin) { super(PACKAGE, 0, pkgID.name, pkgID, null, owner, pos, origin); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/UsedState.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/UsedState.java new file mode 100644 index 000000000000..0e17f2c07c8f --- /dev/null +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/UsedState.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.ballerinalang.compiler.semantics.model.symbols; + +import org.wso2.ballerinalang.compiler.bir.model.BIRNode; + +/** + * This enum indicates whether the {@link BIRNode} will be used in the execution chain or not. + * + * @since 2201.10.0 + */ +public enum UsedState { + /** + * Indicates a {@link BIRNode} is connected to the invocation chain of one of the root BIRNodes. + * These BIRNodes are the only ones that is needed for the execution. + */ + USED, + + /** + * Indicates a {@link BIRNode} is not used. + * These BIRNodes can be safely removed to reduce execution time and final jar size. + */ + UNUSED, + + /** + * Indicates a {@link BIRNode} was not analyzed. + * These BIRNodes are treated the same way as {@link UsedState#USED}. + */ + UNEXPLORED +} diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BAnnotationType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BAnnotationType.java index a888fe336fa2..d2f5413580ab 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BAnnotationType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BAnnotationType.java @@ -19,6 +19,7 @@ package org.wso2.ballerinalang.compiler.semantics.model.types; import org.ballerinalang.model.types.TypeKind; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationSymbol; import org.wso2.ballerinalang.compiler.util.TypeTags; @@ -43,6 +44,11 @@ public void accept(TypeVisitor visitor) { visitor.visit(this); } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public String toString() { return this.tsymbol.toString(); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BAnyType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BAnyType.java index 0991d500ead1..f4f009e8d266 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BAnyType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BAnyType.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.Name; import org.ballerinalang.model.types.SelectivelyImmutableReferenceType; import org.ballerinalang.model.types.TypeKind; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -73,6 +74,11 @@ public void accept(TypeVisitor visitor) { visitor.visit(this); } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public String toString() { return !Symbols.isFlagOn(flags, Flags.READONLY) ? getKind().typeName() : diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BAnydataType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BAnydataType.java index cdfe4f488060..37c07c28d290 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BAnydataType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BAnydataType.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.Name; import org.ballerinalang.model.types.TypeKind; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -89,6 +90,11 @@ public void accept(TypeVisitor visitor) { visitor.visit(this); } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public R accept(BTypeVisitor visitor, T t) { return visitor.visit(this, t); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BArrayType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BArrayType.java index be1b2986bb68..417bdde13f5e 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BArrayType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BArrayType.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.types.ArrayType; import org.ballerinalang.model.types.TypeKind; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -87,6 +88,11 @@ public R accept(BTypeVisitor visitor, T t) { return visitor.visit(this, t); } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public String toString() { StringBuilder sb = new StringBuilder(eType.toString()); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BBuiltInRefType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BBuiltInRefType.java index 3dc5b104d4e1..bfee7a7b68b2 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BBuiltInRefType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BBuiltInRefType.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.types.ReferenceType; import org.ballerinalang.model.types.TypeKind; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import static org.wso2.ballerinalang.compiler.util.TypeTags.ANY; @@ -49,6 +50,11 @@ public R accept(BTypeVisitor visitor, T t) { return visitor.visit(this, t); } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public TypeKind getKind() { switch (tag) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BErrorType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BErrorType.java index 89e0892f9910..c85cec5d0c67 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BErrorType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BErrorType.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.semantics.model.types; import org.ballerinalang.model.types.ErrorType; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.util.TypeTags; @@ -62,6 +63,11 @@ public void accept(TypeVisitor visitor) { visitor.visit(this); } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public String toString() { if (tsymbol != null && tsymbol.name != null && !tsymbol.name.value.startsWith(DOLLAR) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BFiniteType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BFiniteType.java index 66934c7a5b8f..6ea96d8e5d17 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BFiniteType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BFiniteType.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.types.FiniteType; import org.ballerinalang.model.types.TypeKind; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression; @@ -74,6 +75,11 @@ public R accept(BTypeVisitor visitor, T t) { return visitor.visit(this, t); } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public String toString() { StringJoiner joiner = new StringJoiner("|"); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BFutureType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BFutureType.java index 4cb0b0b72cd7..c1dfa2e9a55e 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BFutureType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BFutureType.java @@ -17,6 +17,7 @@ package org.wso2.ballerinalang.compiler.semantics.model.types; import org.ballerinalang.model.types.ConstrainedType; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.util.TypeTags; @@ -50,7 +51,12 @@ public BType getConstraint() { public R accept(BTypeVisitor visitor, T t) { return visitor.visit(this, t); } - + + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public String toString() { if (constraint.tag == TypeTags.NONE || constraint.tag == TypeTags.SEMANTIC_ERROR diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BHandleType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BHandleType.java index 8c535433699d..24927c9cd9e3 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BHandleType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BHandleType.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.semantics.model.types; import org.ballerinalang.model.types.TypeKind; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.util.Flags; @@ -49,4 +50,9 @@ public TypeKind getKind() { public void accept(TypeVisitor visitor) { visitor.visit(this); } + + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BIntSubType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BIntSubType.java index 13dd337a6c39..a47fbb47adf6 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BIntSubType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BIntSubType.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.Name; import org.ballerinalang.model.types.TypeKind; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.util.Names; import org.wso2.ballerinalang.util.Flags; @@ -59,6 +60,11 @@ public void accept(TypeVisitor visitor) { visitor.visit(this); } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public String toString() { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BIntersectionType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BIntersectionType.java index 6c3bba3fcfe5..8f62f65942c2 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BIntersectionType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BIntersectionType.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.types.IntersectionType; import org.ballerinalang.model.types.TypeKind; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -81,6 +82,11 @@ public void accept(TypeVisitor visitor) { visitor.visit(this); } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public boolean isNullable() { return this.effectiveType.isNullable(); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BInvokableType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BInvokableType.java index 79bde4b69a0b..ddbcbb74ebda 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BInvokableType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BInvokableType.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.types.InvokableType; import org.ballerinalang.model.types.TypeKind; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -73,6 +74,11 @@ public R accept(BTypeVisitor visitor, T t) { return visitor.visit(this, t); } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public String toString() { String flagStr = ""; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BJSONType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BJSONType.java index 46b3c81d955b..559ed38ef145 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BJSONType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BJSONType.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.semantics.model.types; import org.ballerinalang.model.types.TypeKind; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -71,6 +72,11 @@ public void accept(TypeVisitor visitor) { visitor.visit(this); } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public R accept(BTypeVisitor visitor, T t) { return visitor.visit(this, t); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BMapType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BMapType.java index 3112abb1d6c8..b3267e381bc1 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BMapType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BMapType.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.types.ConstrainedType; import org.ballerinalang.model.types.SelectivelyImmutableReferenceType; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -52,6 +53,11 @@ public R accept(BTypeVisitor visitor, T t) { return visitor.visit(this, t); } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public String toString() { String stringRep; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BNeverType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BNeverType.java index fd43d8e3d06f..eaadcd27a6c5 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BNeverType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BNeverType.java @@ -17,6 +17,7 @@ */ package org.wso2.ballerinalang.compiler.semantics.model.types; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.util.Names; import org.wso2.ballerinalang.compiler.util.TypeTags; @@ -49,4 +50,10 @@ public String toString() { public void accept(TypeVisitor visitor) { visitor.visit(this); } + + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BNilType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BNilType.java index 8abb31ab1370..d4461c90cab0 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BNilType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BNilType.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.semantics.model.types; import org.ballerinalang.model.types.NullType; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.util.Names; import org.wso2.ballerinalang.compiler.util.TypeTags; @@ -49,4 +50,10 @@ public String toString() { public void accept(TypeVisitor visitor) { visitor.visit(this); } + + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BNoType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BNoType.java index 3a4abd20fde8..f015dcacc4eb 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BNoType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BNoType.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.semantics.model.types; import org.ballerinalang.model.types.NoType; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; /** @@ -33,4 +34,9 @@ public BNoType(int tag) { public void accept(TypeVisitor visitor) { visitor.visit(this); } + + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BObjectType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BObjectType.java index 8abd29cc8474..9577135fa47b 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BObjectType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BObjectType.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.types.ObjectType; import org.ballerinalang.model.types.TypeKind; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BAttachedFunction; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BObjectTypeSymbol; @@ -72,6 +73,11 @@ public R accept(BTypeVisitor visitor, T t) { return visitor.visit(this, t); } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public String toString() { if (shouldPrintShape()) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BPackageType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BPackageType.java index 7ded92db5037..9a6412af2b18 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BPackageType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BPackageType.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.semantics.model.types; import org.ballerinalang.model.types.TypeKind; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol; import org.wso2.ballerinalang.compiler.util.TypeTags; @@ -41,4 +42,9 @@ public TypeKind getKind() { public void accept(TypeVisitor visitor) { visitor.visit(this); } + + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BParameterizedType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BParameterizedType.java index f966d588da46..e97de68572d1 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BParameterizedType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BParameterizedType.java @@ -17,6 +17,7 @@ */ package org.wso2.ballerinalang.compiler.semantics.model.types; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol; @@ -60,6 +61,11 @@ public void accept(TypeVisitor visitor) { visitor.visit(this); } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public R accept(BTypeVisitor visitor, T t) { return visitor.visit(this, t); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BReadonlyType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BReadonlyType.java index b59d62a41f4a..dbd9b7ba80db 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BReadonlyType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BReadonlyType.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.Name; import org.ballerinalang.model.types.TypeKind; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.util.Flags; @@ -54,6 +55,11 @@ public R accept(BTypeVisitor visitor, T t) { return visitor.visit(this, t); } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public boolean isNullable() { return nullable; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BRecordType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BRecordType.java index a6933f7e6856..7f1a3f230ed2 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BRecordType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BRecordType.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.types.RecordType; import org.ballerinalang.model.types.TypeKind; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -69,6 +70,11 @@ public R accept(BTypeVisitor visitor, T t) { return visitor.visit(this, t); } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public String toString() { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BRegexpType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BRegexpType.java index 900216e6fef0..136a530d4669 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BRegexpType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BRegexpType.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.Name; import org.ballerinalang.model.types.TypeKind; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.util.Names; import org.wso2.ballerinalang.util.Flags; @@ -54,6 +55,11 @@ public void accept(TypeVisitor visitor) { visitor.visit(this); } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public String toString() { return Names.REGEXP.value + Names.ALIAS_SEPARATOR + name; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BSequenceType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BSequenceType.java index fee674386469..b2db1f788be8 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BSequenceType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BSequenceType.java @@ -17,6 +17,7 @@ */ package org.wso2.ballerinalang.compiler.semantics.model.types; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.util.TypeTags; /** @@ -31,6 +32,11 @@ public BSequenceType(BType elementType) { this.elementType = elementType; } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public String toString() { return "seq " + elementType; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BStreamType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BStreamType.java index e71f6997b6f1..0389ba30a314 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BStreamType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BStreamType.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.types.StreamType; import org.ballerinalang.model.types.Type; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.util.TypeTags; @@ -55,6 +56,11 @@ public R accept(BTypeVisitor visitor, T t) { return visitor.visit(this, t); } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public String toString() { if (constraint.tag == TypeTags.ANY) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BStringSubType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BStringSubType.java index d63c962f96d9..00ada429f12f 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BStringSubType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BStringSubType.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.Name; import org.ballerinalang.model.types.TypeKind; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.util.Names; import org.wso2.ballerinalang.util.Flags; @@ -59,6 +60,11 @@ public void accept(TypeVisitor visitor) { visitor.visit(this); } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public String toString() { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BStructureType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BStructureType.java index ddc360b5196d..f3a76f5ba419 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BStructureType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BStructureType.java @@ -17,6 +17,7 @@ */ package org.wso2.ballerinalang.compiler.semantics.model.types; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -60,6 +61,11 @@ public void accept(TypeVisitor visitor) { visitor.visit(this); } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + public boolean shouldPrintShape() { Name name = tsymbol.name; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTableType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTableType.java index f71dac864d89..fea53b776d8f 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTableType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTableType.java @@ -21,6 +21,7 @@ import io.ballerina.tools.diagnostics.Location; import org.ballerinalang.model.types.TableType; import org.ballerinalang.model.types.TypeKind; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -97,4 +98,9 @@ public TypeKind getKind() { public void accept(TypeVisitor visitor) { visitor.visit(this); } + + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTupleType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTupleType.java index 8421e6c66ac8..dcfb12e3417a 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTupleType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTupleType.java @@ -18,6 +18,7 @@ import org.ballerinalang.model.types.TupleType; import org.ballerinalang.model.types.TypeKind; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -117,6 +118,11 @@ public void accept(TypeVisitor visitor) { visitor.visit(this); } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public String toString() { // This logic is added to prevent duplicate recursive calls to toString diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BType.java index 8bf4e35a8498..b01e1fa6c281 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BType.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.Name; import org.ballerinalang.model.types.TypeKind; import org.ballerinalang.model.types.ValueType; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.util.Names; @@ -52,6 +53,7 @@ public class BType implements ValueType { // TODO: Refactor this after JBallerina 1.0. public Name name; public long flags; + public boolean isUsed = false; public BType(int tag, BTypeSymbol tsymbol) { this.tag = tag; @@ -118,6 +120,11 @@ public TypeKind getKind() { } } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public void accept(TypeVisitor visitor) { visitor.visit(this); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTypeReferenceType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTypeReferenceType.java index 4914628e9a6d..941279a5d58d 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTypeReferenceType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTypeReferenceType.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.types.ReferenceType; import org.ballerinalang.model.types.TypeKind; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; @@ -60,6 +61,11 @@ public void accept(TypeVisitor visitor) { visitor.visit(this); } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public TypeKind getKind() { return TypeKind.TYPEREFDESC; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTypedescType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTypedescType.java index cdd883b5b4e5..9d794c3e536c 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTypedescType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTypedescType.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.semantics.model.types; import org.ballerinalang.model.types.ConstrainedType; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.util.TypeTags; @@ -29,28 +30,23 @@ public class BTypedescType extends BBuiltInRefType implements ConstrainedType { public BType constraint; - public BTypedescType(BType constraint, BTypeSymbol tsymbol) { - super(TypeTags.TYPEDESC, tsymbol, Flags.READONLY); this.constraint = constraint; } @Override public BType getConstraint() { - return constraint; } @Override public R accept(BTypeVisitor visitor, T t) { - return visitor.visit(this, t); } @Override public String toString() { - if (constraint.tag == TypeTags.ANY) { return super.toString(); } @@ -60,7 +56,11 @@ public String toString() { @Override public void accept(TypeVisitor visitor) { - visitor.visit(this); } + + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BUnionType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BUnionType.java index bac229e3c946..fcfbe19889d7 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BUnionType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BUnionType.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.types.TypeKind; import org.ballerinalang.model.types.UnionType; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -139,6 +140,11 @@ public R accept(BTypeVisitor visitor, T t) { return visitor.visit(this, t); } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public String toString() { if (resolvingToString) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BXMLSubType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BXMLSubType.java index eb62806d81ff..19c912725dc8 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BXMLSubType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BXMLSubType.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.Name; import org.ballerinalang.model.types.SelectivelyImmutableReferenceType; import org.ballerinalang.model.types.TypeKind; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.util.Names; @@ -63,6 +64,11 @@ public void accept(TypeVisitor visitor) { visitor.visit(this); } + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } + @Override public String toString() { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BXMLType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BXMLType.java index f86112006093..dde31241e489 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BXMLType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BXMLType.java @@ -17,6 +17,7 @@ package org.wso2.ballerinalang.compiler.semantics.model.types; import org.ballerinalang.model.types.SelectivelyImmutableReferenceType; +import org.wso2.ballerinalang.compiler.semantics.model.BTypeAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -66,4 +67,9 @@ public R accept(BTypeVisitor visitor, T t) { public void accept(TypeVisitor visitor) { visitor.visit(this); } + + @Override + public void accept(BTypeAnalyzer analyzer, T data) { + analyzer.visit(this, data); + } } diff --git a/compiler/ballerina-lang/src/main/resources/interop-dependencies.properties b/compiler/ballerina-lang/src/main/resources/interop-dependencies.properties new file mode 100644 index 000000000000..897321eba38e --- /dev/null +++ b/compiler/ballerina-lang/src/main/resources/interop-dependencies.properties @@ -0,0 +1,5 @@ +# TypeDefinitions used in java native code can be found here +# These TypeDefinitions are grouped based on their parent module and BType + +ballerina/http=Caller,Remote,Local,Link,MutualSslHandshake,HeaderValue,Request,Response,Entity,RequestCacheControl,Headers,RequestContext,JwtDecoder,ErrorDetail,ResponseCacheControl,HttpFuture,PushPromise,ApplicationResponseError,DefaultErrorDetail,Error,ListenerError,ClientError,HeaderNotFoundError,PayloadBindingError,InboundRequestError,OutboundResponseError,GenericListenerError,InterceptorReturnError,InternalInterceptorReturnError,HeaderBindingError,InternalHeaderBindingError,HeaderValidationError,InternalHeaderValidationError,NoContentError,PayloadBindingClientError,InternalPayloadBindingListenerError,PayloadValidationError,PayloadValidationClientError,InternalPayloadValidationListenerError,QueryParameterBindingError,InternalQueryParameterBindingError,QueryParameterValidationError,InternalQueryParameterValidationError,PathParameterBindingError,InternalPathParameterBindingError,RequestDispatchingError,InternalRequestDispatchingError,ServiceDispatchingError,ResourceDispatchingError,ListenerAuthError,ListenerAuthnError,ListenerAuthzError,InternalListenerAuthnError,InternalListenerAuthzError,OutboundRequestError,InboundResponseError,ClientAuthError,ResiliencyError,GenericClientError,Http2ClientError,SslError,ApplicationResponseError,UnsupportedActionError,MaximumWaitTimeExceededError,CookieHandlingError,ClientConnectorError,ClientRequestError,RemoteServerError,FailoverAllEndpointsFailedError,FailoverActionFailedError,UpstreamServiceUnavailableError,AllLoadBalanceEndpointsFailedError,CircuitBreakerConfigError,AllRetryAttemptsFailed,IdleTimeoutError,LoadBalanceActionError,InitializingOutboundRequestError,WritingOutboundRequestHeadersError,WritingOutboundRequestBodyError,InitializingInboundResponseError,ReadingInboundResponseHeadersError,ReadingInboundResponseBodyError,InitializingInboundRequestError,ReadingInboundRequestHeadersError,ReadingInboundRequestBodyError,InitializingOutboundResponseError,WritingOutboundResponseHeadersError,WritingOutboundResponseBodyError,Initiating100ContinueResponseError,Writing100ContinueResponseError,InvalidCookieError,ServiceNotFoundError,InternalServiceNotFoundError,BadMatrixParamError,InternalBadMatrixParamError,ResourceNotFoundError,InternalResourceNotFoundError,ResourcePathValidationError,InternalResourcePathValidationError,ResourceMethodNotAllowedError,InternalResourceMethodNotAllowedError,UnsupportedRequestMediaTypeError,InternalUnsupportedRequestMediaTypeError,RequestNotAcceptableError,InternalRequestNotAcceptableError,ResourceDispatchingServerError,InternalResourceDispatchingServerError +ballerina/sql=BatchExecuteErrorDetail,DatabaseErrorDetail,Error,DatabaseError,BatchExecuteError,NoRowsError,ApplicationError,DataError,TypeMismatchError,ConversionError,FieldMismatchError,UnsupportedTypeError diff --git a/misc/lib-creator/src/main/java/org/ballerinalang/stdlib/utils/BuildLangLib.java b/misc/lib-creator/src/main/java/org/ballerinalang/stdlib/utils/BuildLangLib.java index 0be2d737ac4e..ad23fdf3b20b 100644 --- a/misc/lib-creator/src/main/java/org/ballerinalang/stdlib/utils/BuildLangLib.java +++ b/misc/lib-creator/src/main/java/org/ballerinalang/stdlib/utils/BuildLangLib.java @@ -180,15 +180,14 @@ public void cacheBir(ModuleName moduleName, ByteArrayOutputStream birContent) { @Override public Optional getPlatformSpecificLibrary(CompilerBackend compilerBackend, - String libraryName) { + String libraryName, boolean isOptimizedLibrary) { return Optional.empty(); } @Override - public void cachePlatformSpecificLibrary(CompilerBackend compilerBackend, - String libraryName, - ByteArrayOutputStream libraryContent) { - fsCache.cachePlatformSpecificLibrary(compilerBackend, libraryName, libraryContent); + public void cachePlatformSpecificLibrary(CompilerBackend compilerBackend, String libraryName, + ByteArrayOutputStream libraryContent, boolean isOptimizedLibrary) { + fsCache.cachePlatformSpecificLibrary(compilerBackend, libraryName, libraryContent, isOptimizedLibrary); } }); diff --git a/project-api/project-api-test/src/test/java/io/ballerina/projects/test/TestBirAndJarCache.java b/project-api/project-api-test/src/test/java/io/ballerina/projects/test/TestBirAndJarCache.java index b50cedcc1d3f..bb629c1c646e 100644 --- a/project-api/project-api-test/src/test/java/io/ballerina/projects/test/TestBirAndJarCache.java +++ b/project-api/project-api-test/src/test/java/io/ballerina/projects/test/TestBirAndJarCache.java @@ -161,10 +161,9 @@ public void cacheBir(ModuleName moduleName, ByteArrayOutputStream birContent) { } @Override - public void cachePlatformSpecificLibrary(CompilerBackend compilerBackend, - String libraryName, - ByteArrayOutputStream libraryContent) { - super.cachePlatformSpecificLibrary(compilerBackend, libraryName, libraryContent); + public void cachePlatformSpecificLibrary(CompilerBackend compilerBackend, String libraryName, + ByteArrayOutputStream libraryContent, boolean isOptimizedLibrary) { + super.cachePlatformSpecificLibrary(compilerBackend, libraryName, libraryContent, isOptimizedLibrary); jarCachedCount++; } } diff --git a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/BCompileUtil.java b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/BCompileUtil.java index 72905986706d..24ba5f4d5508 100644 --- a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/BCompileUtil.java +++ b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/BCompileUtil.java @@ -18,6 +18,7 @@ package org.ballerinalang.test; import io.ballerina.projects.BuildOptions; +import io.ballerina.projects.CompilationOptions; import io.ballerina.projects.JBallerinaBackend; import io.ballerina.projects.JvmTarget; import io.ballerina.projects.NullBackend; @@ -39,6 +40,7 @@ import org.wso2.ballerinalang.programfile.CompiledBinaryFile; import java.io.IOException; +import java.lang.reflect.Field; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -117,6 +119,39 @@ public static CompileResult compileOffline(String sourceFilePath) { return compileResult; } + public static CompileResult compileOptimized(String sourceFilePath) { + BuildOptions.BuildOptionsBuilder buildOptionsBuilder = BuildOptions.builder(); + BuildOptions buildOptions = + buildOptionsBuilder.setOptimizeCodegen(Boolean.TRUE).setOptimizeReport(Boolean.TRUE).build(); + Project project = ProjectLoader.loadProject(testSourcesDirectory.resolve(sourceFilePath), buildOptions); + + Package currentPackage = project.currentPackage(); + JBallerinaBackend jBallerinaBackend = jBallerinaBackend(currentPackage); + jBallerinaBackend.diagnosticResult().hasErrors(); + + // Since all the unit tests are running on the same JVM, we have to reset the static fields used to store the + // compilationOptions. This is not a problem in production environments because they run on dedicated JVMs. + resetStaticCompilationOptions(); + return new CompileResult(currentPackage, jBallerinaBackend); + } + + private static void resetStaticCompilationOptions() { + // Reflection is used here because if we were to provide a dedicated public method for resetting the static + // fields, future developers could use it for other unintended purposes. + Class clazz = CompilationOptions.CompilationOptionsBuilder.class; + try { + Field optimizeCodegenField = clazz.getDeclaredField("optimizeCodegen"); + Field optimizeReportField = clazz.getDeclaredField("optimizeReport"); + optimizeCodegenField.setAccessible(true); + optimizeReportField.setAccessible(true); + + optimizeCodegenField.set(null, null); + optimizeReportField.set(null, null); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + public static BIRCompileResult generateBIR(String sourceFilePath) { Project project = loadProject(sourceFilePath); NullBackend nullBackend = NullBackend.from(project.currentPackage().getCompilation()); diff --git a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/codegen/optimizer/NativeDependencyOptimizationTests.java b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/codegen/optimizer/NativeDependencyOptimizationTests.java new file mode 100644 index 000000000000..135ebd48827c --- /dev/null +++ b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/codegen/optimizer/NativeDependencyOptimizationTests.java @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.ballerinalang.test.codegen.optimizer; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.apache.commons.io.FileUtils; +import org.ballerinalang.test.BaseTest; +import org.ballerinalang.test.context.BMainInstance; +import org.ballerinalang.test.context.BallerinaTestException; +import org.ballerinalang.test.context.LogLeecher; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * Test cases to verify optimized class files from `bal build --optimize` command. + * + * @since 2201.10.0 + */ +public class NativeDependencyOptimizationTests extends BaseTest { + + private static final String NATIVE_DEPENDENCY_OPTIMIZATION_REPORT = "native_dependency_optimization_report.json"; + private static final String TEST_PROJECT_LOCATION = "src/test/resources/codegen-optimizer/native-interop-projects/"; + private static final String NATIVE_LIB_SOURCES_LOCATION = + "src/test/resources/codegen-optimizer/native-lib-sources/"; + private static final String USED_CLASSES = "usedClasses"; + private static final String UNUSED_CLASSES = "unusedClasses"; + private Path tempBalProjectPath; + private Path nativeLibSourcePaths; + + private static JsonObject fileContentAsObject(Path filePath) throws IOException { + String contentAsString = new String(Files.readAllBytes(filePath)); + return JsonParser.parseString(contentAsString).getAsJsonObject(); + } + + private static List getFunctionNamesFromJson(JsonObject parentJson, String fieldName) { + return parentJson.get(fieldName).getAsJsonArray().asList().stream().map(JsonElement::getAsString).toList(); + } + + @BeforeClass + public void setUp() throws IOException, InterruptedException { + Path parentProjectPath = Files.createTempDirectory("b7a-codegen-optimization-test-" + System.nanoTime()); + tempBalProjectPath = parentProjectPath.resolve("native-interop-test-resources"); + nativeLibSourcePaths = parentProjectPath.resolve("native-libs"); + + FileUtils.copyDirectory(Path.of(TEST_PROJECT_LOCATION).toAbsolutePath().normalize().toFile(), + tempBalProjectPath.toFile()); + FileUtils.copyDirectory(Path.of(NATIVE_LIB_SOURCES_LOCATION).toAbsolutePath().normalize().toFile(), + nativeLibSourcePaths.toFile()); + + buildAndCopyNativeLibs(); + } + + public void buildAndCopyNativeLibs() throws IOException, InterruptedException { + // Native lib jars are not packed with the tests. Only the source files of the native libs are packed. + // Compiled jars of native dependencies are generated for each test run. + for (File balProject : Objects.requireNonNull( + nativeLibSourcePaths.toAbsolutePath().normalize().toFile().listFiles())) { + for (File nativeLib : Objects.requireNonNull(balProject.listFiles())) { + Path nativeLibJarPath = buildClassesAndGetJarFilePath(nativeLib.toPath()); + Path destPath = tempBalProjectPath.resolve(balProject.getName()).resolve("libs") + .resolve(nativeLibJarPath.getFileName().toString()); + Files.createDirectory(destPath.getParent()); + Files.copy(nativeLibJarPath, destPath); + } + } + } + + private Path buildClassesAndGetJarFilePath(Path parentPackagePath) throws IOException, InterruptedException { + Path classCache = parentPackagePath.resolve("generated"); + Path generatedJar = parentPackagePath.getParent().resolve(parentPackagePath.getFileName() + ".jar"); + compileJavaFiles(parentPackagePath, classCache); + packClassFilesToJar(generatedJar, classCache); + return generatedJar; + } + + private void compileJavaFiles(Path javaFileDirectory, Path classFileDirectory) + throws IOException, InterruptedException { + List commands = new ArrayList<>(); + commands.add("javac"); + for (File file : Objects.requireNonNull(javaFileDirectory.toFile().listFiles())) { + commands.add(file.getPath()); + } + commands.add("-d"); + commands.add(classFileDirectory.toString()); + + ProcessBuilder processBuilder = new ProcessBuilder(commands); + processBuilder.start().waitFor(); + } + + private void packClassFilesToJar(Path generatedJarPath, Path classFileDirectory) + throws IOException, InterruptedException { + List commands = new ArrayList<>(); + commands.add("jar"); + commands.add("cf"); + commands.add(generatedJarPath.toString()); + for (File file : Objects.requireNonNull(classFileDirectory.toFile().listFiles())) { + commands.add(file.getName()); + } + + ProcessBuilder processBuilder = new ProcessBuilder(commands).directory(classFileDirectory.toFile()); + processBuilder.start().waitFor(); + } + + @Test(dataProvider = "InteropInfoProvider") + private void testAll(String projectName, String[] usedClassNames, String[] unusedClassNames) + throws BallerinaTestException, IOException { + + String projectPath = tempBalProjectPath.resolve(projectName).toString(); + emitOptimizationReports(projectPath); + JsonObject emittedJsonObject = fileContentAsObject( + Path.of(projectPath).resolve("target").resolve(NATIVE_DEPENDENCY_OPTIMIZATION_REPORT)); + + Assert.assertTrue(getFunctionNamesFromJson(emittedJsonObject, USED_CLASSES).containsAll( + Arrays.stream(usedClassNames).toList())); + Assert.assertTrue(getFunctionNamesFromJson(emittedJsonObject, UNUSED_CLASSES).containsAll( + Arrays.stream(unusedClassNames).toList())); + } + + @DataProvider(name = "InteropInfoProvider") + public Object[][] getInteropInfo() { + return new Object[][]{ + {"vanilla_native_interop_call", new String[]{"Foo.class"}, new String[]{"Bar.class"}}, + {"native_interop_call_with_transitive_classes", new String[]{"Foo.class", "Baz.class"}, + new String[]{"Bar.class"}}, + {"native_interop_call_with_inheritance", new String[]{"Foo.class", "Bar.class"}, + new String[]{"Baz.class"}}, + {"native_interop_call_with_interface_usage", new String[]{"Foo.class", "Bar.class"}, + new String[]{"Baz.class", "Quz.class"}}, + {"native_interop_call_with_class_usage", + new String[]{"Foo.class", "Bar.class", "Quz.class", "Corge.class"}, new String[]{"Baz.class"}}, + }; + } + + private void emitOptimizationReports(String projectPath) throws BallerinaTestException { + BMainInstance bMainInstance = new BMainInstance(balServer); + Map envProperties = new HashMap<>(); + bMainInstance.addJavaAgents(envProperties); + bMainInstance.runMain("build", new String[]{"--optimize", "--optimize-report"}, envProperties, null, + new LogLeecher[]{}, projectPath); + } +} diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_class_usage/.devcontainer.json b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_class_usage/.devcontainer.json new file mode 100644 index 000000000000..8a0177271a49 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_class_usage/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.8.6", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_class_usage/.gitignore b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_class_usage/.gitignore new file mode 100644 index 000000000000..7512ebe2325f --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_class_usage/.gitignore @@ -0,0 +1,3 @@ +target +generated +Config.toml diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_class_usage/Ballerina.toml b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_class_usage/Ballerina.toml new file mode 100644 index 000000000000..268991b74f78 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_class_usage/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "native_interop_call_with_class_usage" +version = "0.1.0" +distribution = "2201.8.6" + +[[platform.java17.dependency]] +path = "libs/native_lib_1.jar" \ No newline at end of file diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_class_usage/Dependencies.toml b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_class_usage/Dependencies.toml new file mode 100644 index 000000000000..a5090f1fddb7 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_class_usage/Dependencies.toml @@ -0,0 +1,28 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" +modules = [ + {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} +] + +[[package]] +org = "thushara_piyasekara" +name = "native_interop_call_with_inheritance" +version = "0.1.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "native_interop_call_with_inheritance", moduleName = "native_interop_call_with_inheritance"} +] + diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_class_usage/main.bal b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_class_usage/main.bal new file mode 100644 index 000000000000..e004fda08482 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_class_usage/main.bal @@ -0,0 +1,29 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +import ballerina/jballerina.java; + +public function main() { + handle fooObject = newFooObject(); + fooFunc(fooObject); +} + +public function fooFunc(handle fooObject) = @java:Method { + 'class: "Foo" +} external; + +function newFooObject() returns handle = @java:Constructor { + 'class: "Foo" +} external; diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_inheritance/.devcontainer.json b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_inheritance/.devcontainer.json new file mode 100644 index 000000000000..8a0177271a49 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_inheritance/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.8.6", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_inheritance/.gitignore b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_inheritance/.gitignore new file mode 100644 index 000000000000..7512ebe2325f --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_inheritance/.gitignore @@ -0,0 +1,3 @@ +target +generated +Config.toml diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_inheritance/Ballerina.toml b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_inheritance/Ballerina.toml new file mode 100644 index 000000000000..014f30599783 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_inheritance/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "native_interop_call_with_inheritance" +version = "0.1.0" +distribution = "2201.8.6" + +[[platform.java17.dependency]] +path = "libs/native_lib_1.jar" \ No newline at end of file diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_inheritance/Dependencies.toml b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_inheritance/Dependencies.toml new file mode 100644 index 000000000000..a5090f1fddb7 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_inheritance/Dependencies.toml @@ -0,0 +1,28 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" +modules = [ + {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} +] + +[[package]] +org = "thushara_piyasekara" +name = "native_interop_call_with_inheritance" +version = "0.1.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "native_interop_call_with_inheritance", moduleName = "native_interop_call_with_inheritance"} +] + diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_inheritance/main.bal b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_inheritance/main.bal new file mode 100644 index 000000000000..e004fda08482 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_inheritance/main.bal @@ -0,0 +1,29 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +import ballerina/jballerina.java; + +public function main() { + handle fooObject = newFooObject(); + fooFunc(fooObject); +} + +public function fooFunc(handle fooObject) = @java:Method { + 'class: "Foo" +} external; + +function newFooObject() returns handle = @java:Constructor { + 'class: "Foo" +} external; diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_interface_usage/.devcontainer.json b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_interface_usage/.devcontainer.json new file mode 100644 index 000000000000..8a0177271a49 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_interface_usage/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.8.6", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_interface_usage/.gitignore b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_interface_usage/.gitignore new file mode 100644 index 000000000000..7512ebe2325f --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_interface_usage/.gitignore @@ -0,0 +1,3 @@ +target +generated +Config.toml diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_interface_usage/Ballerina.toml b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_interface_usage/Ballerina.toml new file mode 100644 index 000000000000..9a847b9214db --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_interface_usage/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "native_interop_call_with_interface_usage" +version = "0.1.0" +distribution = "2201.8.6" + +[[platform.java17.dependency]] +path = "libs/native_lib_1.jar" \ No newline at end of file diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_interface_usage/Dependencies.toml b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_interface_usage/Dependencies.toml new file mode 100644 index 000000000000..0b74320f2467 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_interface_usage/Dependencies.toml @@ -0,0 +1,28 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" +modules = [ + {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} +] + +[[package]] +org = "thushara_piyasekara" +name = "native_interop_call_with_interface_usage" +version = "0.1.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "native_interop_call_with_interface_usage", moduleName = "native_interop_call_with_interface_usage"} +] + diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_interface_usage/main.bal b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_interface_usage/main.bal new file mode 100644 index 000000000000..e004fda08482 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_interface_usage/main.bal @@ -0,0 +1,29 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +import ballerina/jballerina.java; + +public function main() { + handle fooObject = newFooObject(); + fooFunc(fooObject); +} + +public function fooFunc(handle fooObject) = @java:Method { + 'class: "Foo" +} external; + +function newFooObject() returns handle = @java:Constructor { + 'class: "Foo" +} external; diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_transitive_classes/.devcontainer.json b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_transitive_classes/.devcontainer.json new file mode 100644 index 000000000000..8a0177271a49 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_transitive_classes/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.8.6", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_transitive_classes/.gitignore b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_transitive_classes/.gitignore new file mode 100644 index 000000000000..7512ebe2325f --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_transitive_classes/.gitignore @@ -0,0 +1,3 @@ +target +generated +Config.toml diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_transitive_classes/Ballerina.toml b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_transitive_classes/Ballerina.toml new file mode 100644 index 000000000000..b883c704b064 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_transitive_classes/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "native_interop_call_with_transitive_classes" +version = "0.1.0" +distribution = "2201.8.6" + +[[platform.java17.dependency]] +path = "libs/native_lib_1.jar" \ No newline at end of file diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_transitive_classes/Dependencies.toml b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_transitive_classes/Dependencies.toml new file mode 100644 index 000000000000..eb5d2670912e --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_transitive_classes/Dependencies.toml @@ -0,0 +1,28 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" +modules = [ + {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} +] + +[[package]] +org = "thushara_piyasekara" +name = "native_interop_call_with_transitive_classes" +version = "0.1.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "native_interop_call_with_transitive_classes", moduleName = "native_interop_call_with_transitive_classes"} +] + diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_transitive_classes/main.bal b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_transitive_classes/main.bal new file mode 100644 index 000000000000..2c31a25e389a --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/native_interop_call_with_transitive_classes/main.bal @@ -0,0 +1,24 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +import ballerina/jballerina.java; + +public function main() { + fooFunc(); +} + +public function fooFunc() = @java:Method { + 'class: "Foo" +} external; diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/vanilla_native_interop_call/.devcontainer.json b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/vanilla_native_interop_call/.devcontainer.json new file mode 100644 index 000000000000..8a0177271a49 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/vanilla_native_interop_call/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.8.6", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/vanilla_native_interop_call/.gitignore b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/vanilla_native_interop_call/.gitignore new file mode 100644 index 000000000000..7512ebe2325f --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/vanilla_native_interop_call/.gitignore @@ -0,0 +1,3 @@ +target +generated +Config.toml diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/vanilla_native_interop_call/Ballerina.toml b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/vanilla_native_interop_call/Ballerina.toml new file mode 100644 index 000000000000..919550219f7d --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/vanilla_native_interop_call/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "vanilla_native_interop_call" +version = "0.1.0" +distribution = "2201.8.6" + +[[platform.java17.dependency]] +path = "libs/native_lib_1.jar" \ No newline at end of file diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/vanilla_native_interop_call/Dependencies.toml b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/vanilla_native_interop_call/Dependencies.toml new file mode 100644 index 000000000000..abbc02993eea --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/vanilla_native_interop_call/Dependencies.toml @@ -0,0 +1,28 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" +modules = [ + {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} +] + +[[package]] +org = "thushara_piyasekara" +name = "vanilla_native_interop_call" +version = "0.1.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "vanilla_native_interop_call", moduleName = "vanilla_native_interop_call"} +] + diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/vanilla_native_interop_call/main.bal b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/vanilla_native_interop_call/main.bal new file mode 100644 index 000000000000..2c31a25e389a --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-interop-projects/vanilla_native_interop_call/main.bal @@ -0,0 +1,24 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +import ballerina/jballerina.java; + +public function main() { + fooFunc(); +} + +public function fooFunc() = @java:Method { + 'class: "Foo" +} external; diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_class_usage/native_lib_1/Bar.java b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_class_usage/native_lib_1/Bar.java new file mode 100644 index 000000000000..190ed54ecc82 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_class_usage/native_lib_1/Bar.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +public class Bar { + public void barFunc(){ + System.out.println("Bar class is being used..."); + } +} diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_class_usage/native_lib_1/Baz.java b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_class_usage/native_lib_1/Baz.java new file mode 100644 index 000000000000..bb6947f96761 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_class_usage/native_lib_1/Baz.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +public class Baz { + public void bazFunc() { + System.out.println("Baz class is being used..."); + } +} diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_class_usage/native_lib_1/Corge.java b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_class_usage/native_lib_1/Corge.java new file mode 100644 index 000000000000..88f8cc05c728 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_class_usage/native_lib_1/Corge.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +public class Corge { + +} diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_class_usage/native_lib_1/Foo.java b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_class_usage/native_lib_1/Foo.java new file mode 100644 index 000000000000..b1fb5d218b1f --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_class_usage/native_lib_1/Foo.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +public class Foo { + Quz quz; + public void fooFunc() { + System.out.println("Foo class is being used..."); + Bar bar = new Bar(); + } +} \ No newline at end of file diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_class_usage/native_lib_1/Quz.java b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_class_usage/native_lib_1/Quz.java new file mode 100644 index 000000000000..e1462318e5f1 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_class_usage/native_lib_1/Quz.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +public class Quz { + public Quz(Corge corge) { + + } + public void quzFunc(){ + System.out.println("Quz class is being used..."); + } +} diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_inheritance/native_lib_1/Bar.java b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_inheritance/native_lib_1/Bar.java new file mode 100644 index 000000000000..9e5c1cf20a22 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_inheritance/native_lib_1/Bar.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +public class Bar { + public void barFunc() { + System.out.println("Bar class is being used..."); + } +} diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_inheritance/native_lib_1/Baz.java b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_inheritance/native_lib_1/Baz.java new file mode 100644 index 000000000000..bb6947f96761 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_inheritance/native_lib_1/Baz.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +public class Baz { + public void bazFunc() { + System.out.println("Baz class is being used..."); + } +} diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_inheritance/native_lib_1/Foo.java b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_inheritance/native_lib_1/Foo.java new file mode 100644 index 000000000000..0c6455ff8289 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_inheritance/native_lib_1/Foo.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +public class Foo extends Bar { + + public void fooFunc() { + System.out.println("Foo class is being used..."); + } +} \ No newline at end of file diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_interface_usage/native_lib_1/Bar.java b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_interface_usage/native_lib_1/Bar.java new file mode 100644 index 000000000000..58ca458f70a8 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_interface_usage/native_lib_1/Bar.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +public interface Bar { + public void barFunc(); +} diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_interface_usage/native_lib_1/Baz.java b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_interface_usage/native_lib_1/Baz.java new file mode 100644 index 000000000000..ebef26e2a824 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_interface_usage/native_lib_1/Baz.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +public class Baz implements Quz { + public void bazFunc() { + System.out.println("Baz class is being used..."); + } + + @Override + public void quzFunc() { + System.out.println("Quz interface is being used..."); + } +} diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_interface_usage/native_lib_1/Foo.java b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_interface_usage/native_lib_1/Foo.java new file mode 100644 index 000000000000..fd7baacbbe48 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_interface_usage/native_lib_1/Foo.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +public class Foo implements Bar { + + public void fooFunc() { + System.out.println("Foo class is being used..."); + barFunc(); + } + + @Override + public void barFunc() { + System.out.println("Interface Bar is being used..."); + } +} \ No newline at end of file diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_interface_usage/native_lib_1/Quz.java b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_interface_usage/native_lib_1/Quz.java new file mode 100644 index 000000000000..c0d4644ecca5 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_interface_usage/native_lib_1/Quz.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +public interface Quz { + + public void quzFunc(); +} diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_transitive_classes/native_lib_1/Bar.java b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_transitive_classes/native_lib_1/Bar.java new file mode 100644 index 000000000000..8d4d4cd8aa58 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_transitive_classes/native_lib_1/Bar.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +public class Bar { + public static void barFunc() { + System.out.println("Bar class is being used..."); + } +} diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_transitive_classes/native_lib_1/Baz.java b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_transitive_classes/native_lib_1/Baz.java new file mode 100644 index 000000000000..f1ea18a6c2a8 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_transitive_classes/native_lib_1/Baz.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +public class Baz { + public static void bazFunc() { + System.out.println("Baz class is being used..."); + } +} diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_transitive_classes/native_lib_1/Foo.java b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_transitive_classes/native_lib_1/Foo.java new file mode 100644 index 000000000000..a81a5e27a4c8 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/native_interop_call_with_transitive_classes/native_lib_1/Foo.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +public class Foo { + public static void fooFunc() { + System.out.println("Foo class is being used..."); + Baz.bazFunc(); + } +} \ No newline at end of file diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/vanilla_native_interop_call/native_lib_1/Bar.java b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/vanilla_native_interop_call/native_lib_1/Bar.java new file mode 100644 index 000000000000..8d4d4cd8aa58 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/vanilla_native_interop_call/native_lib_1/Bar.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +public class Bar { + public static void barFunc() { + System.out.println("Bar class is being used..."); + } +} diff --git a/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/vanilla_native_interop_call/native_lib_1/Foo.java b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/vanilla_native_interop_call/native_lib_1/Foo.java new file mode 100644 index 000000000000..187a748e8971 --- /dev/null +++ b/tests/jballerina-integration-test/src/test/resources/codegen-optimizer/native-lib-sources/vanilla_native_interop_call/native_lib_1/Foo.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +public class Foo { + public static void fooFunc() { + System.out.println("Foo class is being used..."); + } +} \ No newline at end of file diff --git a/tests/jballerina-integration-test/src/test/resources/testng.xml b/tests/jballerina-integration-test/src/test/resources/testng.xml index 00a0c0c760e1..3284e9bfe709 100644 --- a/tests/jballerina-integration-test/src/test/resources/testng.xml +++ b/tests/jballerina-integration-test/src/test/resources/testng.xml @@ -1,160 +1,166 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/jballerina-unit-test/build.gradle b/tests/jballerina-unit-test/build.gradle index 2dbdd1aeebe9..3623dc85389f 100644 --- a/tests/jballerina-unit-test/build.gradle +++ b/tests/jballerina-unit-test/build.gradle @@ -34,6 +34,7 @@ dependencies { testImplementation 'org.wso2.transport.http:org.wso2.transport.http.netty' testImplementation 'org.wso2.carbon.messaging:org.wso2.carbon.messaging' testImplementation 'org.testng:testng' + testImplementation('com.google.code.gson:gson') testImplementation project(path: ':ballerina-test-utils', configuration: 'shadow') testImplementation project(':ballerina-runtime') testRuntimeOnly project(':ballerina-runtime') diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/codegen/optimizer/BIRLevelCodegenOptimizationTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/codegen/optimizer/BIRLevelCodegenOptimizationTest.java new file mode 100644 index 000000000000..0162b7139da9 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/codegen/optimizer/BIRLevelCodegenOptimizationTest.java @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.ballerinalang.test.codegen.optimizer; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.ballerinalang.test.BCompileUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; + +/** + * Test cases to verify optimized BIRNodes from `bal build --optimize` command. + * + * @since 2201.10.0 + */ +public class BIRLevelCodegenOptimizationTest { + + private static final Logger LOGGER = LoggerFactory.getLogger(BIRLevelCodegenOptimizationTest.class); + private static final Path TESTS_SOURCE_PATH = Path.of("src/test/resources").toAbsolutePath().normalize(); + private static final Path EXPECTED_JSON_DIR_PATH = + Path.of("src/test/resources/test-src/codegen-optimizer/json-files").toAbsolutePath().normalize(); + private static final Path SINGLE_FILE_FUNCTION_TESTS_PATH = + Path.of(TESTS_SOURCE_PATH.toString(), "test-src/codegen-optimizer/projects/single-file-projects/Functions"); + private static final Path SINGLE_FILE_TYPE_DEFINITION_TESTS_PATH = + Path.of(TESTS_SOURCE_PATH.toString(), + "test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions"); + private static final Path BUILD_PROJECT_FUNCTION_TESTS_PATH = + Path.of(TESTS_SOURCE_PATH.toString(), "test-src/codegen-optimizer/projects/build-projects/Functions"); + private static final Path BUILD_PROJECT_TYPE_DEFINITION_TESTS_PATH = + Path.of(TESTS_SOURCE_PATH.toString(), "test-src/codegen-optimizer/projects/build-projects/TypeDefinitions"); + private static final String OPTIMIZATION_REPORT_JSON = "codegen_optimization_report.json"; + private static final String TARGET = "target"; + private static final String SINGLE_FILE_PROJECTS = "single-file-projects"; + private static final String BUILD_PROJECTS = "build-projects"; + + @Test(dataProvider = "SingleFileFunctionProjectPaths") + public void testSingleProjectFunctionCasesWithDataProvider(Path singleFileProjectPath) { + BCompileUtil.compileOptimized(getProjectPathInBCompileUtilCompatibleFormat(singleFileProjectPath)); + assertSingleFileJsonReportsAreSimilar(singleFileProjectPath); + } + + @Test(dataProvider = "SingleFileTypeDefinitionProjectPaths") + public void testSingleProjectTypeDefinitionCasesWithDataProvider(Path singleFileProjectPath) { + BCompileUtil.compileOptimized(getProjectPathInBCompileUtilCompatibleFormat(singleFileProjectPath)); + assertSingleFileJsonReportsAreSimilar(singleFileProjectPath); + } + + @Test(dataProvider = "BuildProjectFunctionPaths") + public void testBuildProjectFunctionCasesWithDataProvider(Path buildProjectPath) { + BCompileUtil.compileOptimized(getProjectPathInBCompileUtilCompatibleFormat(buildProjectPath)); + assertBuildProjectJsonReportsAreSimilar(buildProjectPath); + } + + @Test(dataProvider = "BuildProjectTypeDefinitionPaths") + public void testBuildProjectTypeDefinitionCasesWithDataProvider(Path buildProjectPath) { + BCompileUtil.compileOptimized(getProjectPathInBCompileUtilCompatibleFormat(buildProjectPath)); + assertBuildProjectJsonReportsAreSimilar(buildProjectPath); + } + + @DataProvider(name = "SingleFileFunctionProjectPaths") + public Object[] getSingleFileFunctionProjectPaths() { + File[] functionFiles = SINGLE_FILE_FUNCTION_TESTS_PATH.toFile().listFiles(); + Assert.assertNotNull(functionFiles); + return Arrays.stream(functionFiles).filter(file -> file.toString().endsWith(".bal")) + .map(file -> Path.of(file.getPath()).toAbsolutePath().normalize()).toArray(); + } + + @DataProvider(name = "SingleFileTypeDefinitionProjectPaths") + public Object[] getSingleFileTypeDefinitionProjectPaths() { + File[] typeDefinitionFiles = SINGLE_FILE_TYPE_DEFINITION_TESTS_PATH.toFile().listFiles(); + Assert.assertNotNull(typeDefinitionFiles); + return Arrays.stream(typeDefinitionFiles).filter(file -> file.toString().endsWith(".bal")) + .map(file -> Path.of(file.getPath()).toAbsolutePath().normalize()).toArray(); + } + + @DataProvider(name = "BuildProjectFunctionPaths") + public Object[] getBuildProjectFunctionPaths() { + File[] functionFiles = BUILD_PROJECT_FUNCTION_TESTS_PATH.toFile().listFiles(); + Assert.assertNotNull(functionFiles); + return Arrays.stream(functionFiles).map(file -> Path.of(file.getPath()).toAbsolutePath().normalize()).toArray(); + } + + @DataProvider(name = "BuildProjectTypeDefinitionPaths") + public Object[] getBuildProjectTypeDefinitionPaths() { + File[] functionFiles = BUILD_PROJECT_TYPE_DEFINITION_TESTS_PATH.toFile().listFiles(); + Assert.assertNotNull(functionFiles); + return Arrays.stream(functionFiles).map(file -> Path.of(file.getPath()).toAbsolutePath().normalize()).toArray(); + } + + private void assertSingleFileJsonReportsAreSimilar(Path singleFileProjectPath) { + String jsonFileName = singleFileProjectPath.getFileName().toString().replace(".bal", ".json"); + Path actualJsonPath = singleFileProjectPath.getParent().resolve(OPTIMIZATION_REPORT_JSON); + + JsonObject expectedJsonObject = + fileContentAsObject(EXPECTED_JSON_DIR_PATH.resolve(SINGLE_FILE_PROJECTS).resolve(jsonFileName)); + JsonObject actualJsonObject = fileContentAsObject(actualJsonPath); + Assert.assertEquals(actualJsonObject, expectedJsonObject); + actualJsonPath.toFile().delete(); + } + + private void assertBuildProjectJsonReportsAreSimilar(Path buildProjectPath) { + String jsonFileName = buildProjectPath.getFileName().toString() + ".json"; + Path actualJsonPath = buildProjectPath.resolve(TARGET).resolve(OPTIMIZATION_REPORT_JSON); + + JsonObject expectedJsonObject = + fileContentAsObject(EXPECTED_JSON_DIR_PATH.resolve(BUILD_PROJECTS).resolve(jsonFileName)); + JsonObject actualJsonObject = fileContentAsObject(actualJsonPath); + Assert.assertEquals(actualJsonObject, expectedJsonObject); + actualJsonPath.toFile().delete(); + } + + private String getProjectPathInBCompileUtilCompatibleFormat(Path projectAbsolutePath) { + return projectAbsolutePath.toString().replace(TESTS_SOURCE_PATH.toString(), "").substring(1); + } + + private static JsonObject fileContentAsObject(Path filePath) { + String contentAsString = ""; + try { + contentAsString = new String(Files.readAllBytes(filePath)); + } catch (IOException ex) { + LOGGER.error(ex.getMessage()); + } + return JsonParser.parseString(contentAsString).getAsJsonObject(); + } +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/arrow_function_pointer_invocation_from_imported_module.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/arrow_function_pointer_invocation_from_imported_module.json new file mode 100644 index 000000000000..44d1e01226df --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/arrow_function_pointer_invocation_from_imported_module.json @@ -0,0 +1,53 @@ +{ + "thushara_piyasekara/arrow_function_pointer_invocation_from_imported_module:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + }, + "thushara_piyasekara/arrow_function_pointer_invocation_from_imported_module.subModule_1:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [ + ".", + "$lambda$_0", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [ + "$lambda$_1" + ] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/arrow_functions_1.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/arrow_functions_1.json new file mode 100644 index 000000000000..c425c54504ae --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/arrow_functions_1.json @@ -0,0 +1,32 @@ +{ + "thushara_piyasekara/arrow_functions_1:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "$lambda$_0" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [ + "$lambda$_1" + ] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "ReturnsIntFunction" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/arrow_functions_2.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/arrow_functions_2.json new file mode 100644 index 000000000000..673fd8a0c87c --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/arrow_functions_2.json @@ -0,0 +1,32 @@ +{ + "thushara_piyasekara/arrow_functions_2:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "$lambda$_0" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [ + "$lambda$_1" + ] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "ReturnsIntFunction" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/class_inclusion.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/class_inclusion.json new file mode 100644 index 000000000000..f3c0fa289589 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/class_inclusion.json @@ -0,0 +1,37 @@ +{ + "thushara_piyasekara/class_inclusion:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "thushara_piyasekara/class_inclusion:0.1.0:Engineer.clone", + "thushara_piyasekara/class_inclusion:0.1.0:Engineer.getName", + "thushara_piyasekara/class_inclusion:0.1.0:Engineer.init", + "thushara_piyasekara/class_inclusion:0.1.0:Person.getName", + "thushara_piyasekara/class_inclusion:0.1.0:Cloneable.clone" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "thushara_piyasekara/class_inclusion:0.1.0:Engineer.$init$" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "Engineer", + "Person", + "Cloneable" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/class_level_functions.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/class_level_functions.json new file mode 100644 index 000000000000..2ad7af7c81f5 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/class_level_functions.json @@ -0,0 +1,34 @@ +{ + "thushara_piyasekara/class_level_functions:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "thushara_piyasekara/class_level_functions:0.1.0:CKlass.foo", + "thushara_piyasekara/class_level_functions:0.1.0:CKlass.bar" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "thushara_piyasekara/class_level_functions:0.1.0:CKlass.$init$" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "foo" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "CKlass" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/client_class_usage.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/client_class_usage.json new file mode 100644 index 000000000000..fdcda184d189 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/client_class_usage.json @@ -0,0 +1,39 @@ +{ + "thushara_piyasekara/client_class_usage:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "thushara_piyasekara/client_class_usage:0.1.0:ClientUsed.$get$^", + "thushara_piyasekara/client_class_usage:0.1.0:ClientUsed.init" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "thushara_piyasekara/client_class_usage:0.1.0:ClientUsed.$init$" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "thushara_piyasekara/client_class_usage:0.1.0:ClientUnused.$get$^", + "thushara_piyasekara/client_class_usage:0.1.0:ClientUnused.init" + ], + "virtualFunctions": [ + "thushara_piyasekara/client_class_usage:0.1.0:ClientUnused.$init$" + ] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "ClientUsed" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "ClientUnused" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_as_default_value.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_as_default_value.json new file mode 100644 index 000000000000..5225e47ce544 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_as_default_value.json @@ -0,0 +1,40 @@ +{ + "thushara_piyasekara/function_invocation_as_default_value:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo", + "baz", + "corge" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "$UsedRec_$rec$UsedRec$rec$name", + "$corge_defaultParam" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [ + "$UnusedRec_$rec$UnusedRec$rec$name" + ] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "UsedRec" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "UnusedRec" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_in_different_module.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_in_different_module.json new file mode 100644 index 000000000000..773fea178373 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_in_different_module.json @@ -0,0 +1,54 @@ +{ + "thushara_piyasekara/function_invocation_in_different_module:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + }, + "thushara_piyasekara/function_invocation_in_different_module.subModule:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "subModuleFunction" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "foo" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_closure.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_closure.json new file mode 100644 index 000000000000..18d1c96c8ed5 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_closure.json @@ -0,0 +1,29 @@ +{ + "thushara_piyasekara/function_invocation_inside_closure:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "$lambda$_0" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_global_closure.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_global_closure.json new file mode 100644 index 000000000000..a89241943318 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_global_closure.json @@ -0,0 +1,29 @@ +{ + "thushara_piyasekara/function_invocation_inside_global_closure:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "$lambda$_0" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_listener.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_listener.json new file mode 100644 index 000000000000..93eed016e2e0 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_listener.json @@ -0,0 +1,50 @@ +{ + "thushara_piyasekara/function_invocation_inside_listener:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "object { string usedVar; resource function get albums() returns (string); }.$get$albums", + "foo", + "thushara_piyasekara/function_invocation_inside_listener:0.1.0:Listener.start", + "thushara_piyasekara/function_invocation_inside_listener:0.1.0:Listener.gracefulStop", + "thushara_piyasekara/function_invocation_inside_listener:0.1.0:Listener.immediateStop", + "thushara_piyasekara/function_invocation_inside_listener:0.1.0:Listener.detach", + "thushara_piyasekara/function_invocation_inside_listener:0.1.0:Listener.attach", + "thushara_piyasekara/function_invocation_inside_listener:0.1.0:Listener.init" + ], + "virtualFunctions": [ + ".", + "$annot_func$_0", + "thushara_piyasekara/function_invocation_inside_listener:0.1.0.0", + "object { string usedVar; resource function get albums() returns (string); }.$init$", + "thushara_piyasekara/function_invocation_inside_listener:0.1.0.1", + "thushara_piyasekara/function_invocation_inside_listener:0.1.0:Listener.$init$", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [ + "$Listener_Listener_attach_name" + ] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "Listener" + ], + "virtualTypeDefinitions": [ + "$anonType$_1", + "$anonType$_0", + "$anonType$s$detach$_0", + "$anonType$s$attach$_0" + ] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_match_statement.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_match_statement.json new file mode 100644 index 000000000000..849b0b4f7411 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_match_statement.json @@ -0,0 +1,30 @@ +{ + "thushara_piyasekara/function_invocation_inside_match_statement:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_match_statement_obstruction.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_match_statement_obstruction.json new file mode 100644 index 000000000000..8e8b34e358d7 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_match_statement_obstruction.json @@ -0,0 +1,31 @@ +{ + "thushara_piyasekara/function_invocation_inside_match_statement_obstruction:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "baz", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_record.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_record.json new file mode 100644 index 000000000000..4d53f58cb15a --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_record.json @@ -0,0 +1,32 @@ +{ + "thushara_piyasekara/function_invocation_inside_record:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "RecA" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_remote_function_body.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_remote_function_body.json new file mode 100644 index 000000000000..1d37af44b735 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_remote_function_body.json @@ -0,0 +1,50 @@ +{ + "thushara_piyasekara/function_invocation_inside_remote_function_body:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "isolated object { public isolated function albums () returns (string); }.albums", + "foo", + "thushara_piyasekara/function_invocation_inside_remote_function_body:0.1.0:Listener.start", + "thushara_piyasekara/function_invocation_inside_remote_function_body:0.1.0:Listener.gracefulStop", + "thushara_piyasekara/function_invocation_inside_remote_function_body:0.1.0:Listener.immediateStop", + "thushara_piyasekara/function_invocation_inside_remote_function_body:0.1.0:Listener.detach", + "thushara_piyasekara/function_invocation_inside_remote_function_body:0.1.0:Listener.attach", + "thushara_piyasekara/function_invocation_inside_remote_function_body:0.1.0:Listener.init" + ], + "virtualFunctions": [ + ".", + "$annot_func$_0", + "thushara_piyasekara/function_invocation_inside_remote_function_body:0.1.0.0", + "isolated object { public isolated function albums () returns (string); }.$init$", + "thushara_piyasekara/function_invocation_inside_remote_function_body:0.1.0.1", + "thushara_piyasekara/function_invocation_inside_remote_function_body:0.1.0:Listener.$init$", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [ + "$Listener_Listener_attach_name" + ] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "Listener" + ], + "virtualTypeDefinitions": [ + "$anonType$_1", + "$anonType$_0", + "$anonType$s$detach$_0", + "$anonType$s$attach$_0" + ] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_resource_function_body.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_resource_function_body.json new file mode 100644 index 000000000000..11f82d1b8b17 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_resource_function_body.json @@ -0,0 +1,50 @@ +{ + "thushara_piyasekara/function_invocation_inside_resource_function_body:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "isolated object { resource function get albums() returns (string); }.$get$albums", + "foo", + "thushara_piyasekara/function_invocation_inside_resource_function_body:0.1.0:Listener.start", + "thushara_piyasekara/function_invocation_inside_resource_function_body:0.1.0:Listener.gracefulStop", + "thushara_piyasekara/function_invocation_inside_resource_function_body:0.1.0:Listener.immediateStop", + "thushara_piyasekara/function_invocation_inside_resource_function_body:0.1.0:Listener.detach", + "thushara_piyasekara/function_invocation_inside_resource_function_body:0.1.0:Listener.attach", + "thushara_piyasekara/function_invocation_inside_resource_function_body:0.1.0:Listener.init" + ], + "virtualFunctions": [ + ".", + "$annot_func$_0", + "thushara_piyasekara/function_invocation_inside_resource_function_body:0.1.0.0", + "isolated object { resource function get albums() returns (string); }.$init$", + "thushara_piyasekara/function_invocation_inside_resource_function_body:0.1.0.1", + "thushara_piyasekara/function_invocation_inside_resource_function_body:0.1.0:Listener.$init$", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [ + "$Listener_Listener_attach_name" + ] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "Listener" + ], + "virtualTypeDefinitions": [ + "$anonType$_1", + "$anonType$_0", + "$anonType$s$detach$_0", + "$anonType$s$attach$_0" + ] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_worker_with_return.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_worker_with_return.json new file mode 100644 index 000000000000..df795958bbf6 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_worker_with_return.json @@ -0,0 +1,31 @@ +{ + "thushara_piyasekara/function_invocation_inside_worker_with_return:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "$lambda$_0" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_worker_with_wait.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_worker_with_wait.json new file mode 100644 index 000000000000..8526d4a06cdf --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_worker_with_wait.json @@ -0,0 +1,37 @@ +{ + "thushara_piyasekara/function_invocation_inside_worker_with_wait:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo", + "bar" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "$lambda$_0" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "baz", + "qux" + ], + "virtualFunctions": [ + "$lambda$_1" + ] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [ + "$anonType$_0" + ] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_workers.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_workers.json new file mode 100644 index 000000000000..0fdee75227ad --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_invocation_inside_workers.json @@ -0,0 +1,33 @@ +{ + "thushara_piyasekara/function_invocation_inside_workers:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo", + "bar" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "$lambda$_0", + "$lambda$_1" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "baz" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointer_invocation_from_imported_module.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointer_invocation_from_imported_module.json new file mode 100644 index 000000000000..256081b58002 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointer_invocation_from_imported_module.json @@ -0,0 +1,54 @@ +{ + "thushara_piyasekara/function_pointer_invocation_from_imported_module:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + }, + "thushara_piyasekara/function_pointer_invocation_from_imported_module.subModule_1:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointer_invocation_inisde_different_bb.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointer_invocation_inisde_different_bb.json new file mode 100644 index 000000000000..a2b2f577e39b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointer_invocation_inisde_different_bb.json @@ -0,0 +1,28 @@ +{ + "thushara_piyasekara/function_pointer_invocation_inisde_different_bb:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointer_invocation_inside_lock.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointer_invocation_inside_lock.json new file mode 100644 index 000000000000..0f73eec2dd5b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointer_invocation_inside_lock.json @@ -0,0 +1,33 @@ +{ + "thushara_piyasekara/function_pointer_invocation_inside_lock:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "thushara_piyasekara/function_pointer_invocation_inside_lock:0.1.0:className.foo", + "thushara_piyasekara/function_pointer_invocation_inside_lock:0.1.0:className.bar" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "thushara_piyasekara/function_pointer_invocation_inside_lock:0.1.0:className.$init$", + "$anon$method$delegate$className.foo$0" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "className" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointers_as_arguments.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointers_as_arguments.json new file mode 100644 index 000000000000..7be8df4879e1 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointers_as_arguments.json @@ -0,0 +1,34 @@ +{ + "thushara_piyasekara/function_pointers_as_arguments:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo", + "fpEater", + "baz" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "ReturnsIntFunction" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointers_global_assignment.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointers_global_assignment.json new file mode 100644 index 000000000000..12a1b77bde27 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointers_global_assignment.json @@ -0,0 +1,32 @@ +{ + "thushara_piyasekara/function_pointers_global_assignment:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "ReturnsIntFunction" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointers_inside_array.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointers_inside_array.json new file mode 100644 index 000000000000..96f3f2a95e3c --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointers_inside_array.json @@ -0,0 +1,31 @@ +{ + "thushara_piyasekara/function_pointers_inside_array:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "foo", + "bar", + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "ReturnsIntFunction" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointers_inside_lock.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointers_inside_lock.json new file mode 100644 index 000000000000..56cbe4fd4673 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointers_inside_lock.json @@ -0,0 +1,33 @@ +{ + "thushara_piyasekara/function_pointers_inside_lock:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "thushara_piyasekara/function_pointers_inside_lock:0.1.0:className.foo", + "thushara_piyasekara/function_pointers_inside_lock:0.1.0:className.execute2" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "thushara_piyasekara/function_pointers_inside_lock:0.1.0:className.$init$", + "$anon$method$delegate$className.foo$0" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "className" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointers_inside_record.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointers_inside_record.json new file mode 100644 index 000000000000..b5fc1b3ddb49 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointers_inside_record.json @@ -0,0 +1,33 @@ +{ + "thushara_piyasekara/function_pointers_inside_record:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "FPRecord", + "ReturnsIntFunction" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointers_invocation_inside_record.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointers_invocation_inside_record.json new file mode 100644 index 000000000000..0580025f7bf7 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointers_invocation_inside_record.json @@ -0,0 +1,33 @@ +{ + "thushara_piyasekara/function_pointers_invocation_inside_record:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "RecA", + "ReturnsIntFunction" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointers_local_assignment.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointers_local_assignment.json new file mode 100644 index 000000000000..a1980a0c63bc --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointers_local_assignment.json @@ -0,0 +1,32 @@ +{ + "thushara_piyasekara/function_pointers_local_assignment:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "fooUnused" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "ReturnsIntFunction" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointers_transitive_assignment.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointers_transitive_assignment.json new file mode 100644 index 000000000000..784695668aa5 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/function_pointers_transitive_assignment.json @@ -0,0 +1,32 @@ +{ + "thushara_piyasekara/function_pointers_transitive_assignment:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "ReturnsIntFunction" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/global_value_initialization.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/global_value_initialization.json new file mode 100644 index 000000000000..95e8fb9744e6 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/global_value_initialization.json @@ -0,0 +1,31 @@ +{ + "thushara_piyasekara/global_value_initialization:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "A" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "B" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/global_var_from_imported_module.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/global_var_from_imported_module.json new file mode 100644 index 000000000000..8fe682465656 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/global_var_from_imported_module.json @@ -0,0 +1,50 @@ +{ + "thushara_piyasekara/global_var_from_imported_module:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + }, + "thushara_piyasekara/global_var_from_imported_module.subModule_1:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/imported_closure_invocation.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/imported_closure_invocation.json new file mode 100644 index 000000000000..95ff03820ae6 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/imported_closure_invocation.json @@ -0,0 +1,58 @@ +{ + "thushara_piyasekara/imported_closure_invocation:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + }, + "thushara_piyasekara/imported_closure_invocation.subModule:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "closureReturn", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "$lambda$_0" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [ + "$lambda$_1" + ] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/intersection_types.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/intersection_types.json new file mode 100644 index 000000000000..058a3fb43591 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/intersection_types.json @@ -0,0 +1,33 @@ +{ + "thushara_piyasekara/intersection_types:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "BigErr", + "XErr", + "YErr" + ], + "virtualTypeDefinitions": [ + "$anonIntersectionErrorType$_0" + ] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/parameters_via_record_field_mapping.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/parameters_via_record_field_mapping.json new file mode 100644 index 000000000000..a47724e8709c --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/parameters_via_record_field_mapping.json @@ -0,0 +1,35 @@ +{ + "thushara_piyasekara/parameters_via_record_field_mapping:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "RecA", + "B", + "C" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "D", + "RecE" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/query_expression_type_usage.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/query_expression_type_usage.json new file mode 100644 index 000000000000..d221d9603d96 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/query_expression_type_usage.json @@ -0,0 +1,35 @@ +{ + "thushara_piyasekara/query_expression_type_usage:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "$streamLambda$_0", + "$streamLambda$_1", + "$streamLambda$_2" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "B" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "A", + "C" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/record_dependency.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/record_dependency.json new file mode 100644 index 000000000000..da3c78ff4d67 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/record_dependency.json @@ -0,0 +1,34 @@ +{ + "thushara_piyasekara/record_dependency:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "RecA", + "B", + "C" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "RecD", + "E" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/record_field_type_from_imported_module.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/record_field_type_from_imported_module.json new file mode 100644 index 000000000000..612db76436d2 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/record_field_type_from_imported_module.json @@ -0,0 +1,60 @@ +{ + "thushara_piyasekara/record_field_type_from_imported_module:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "RecUsed" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "RecUnused" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + }, + "thushara_piyasekara/record_field_type_from_imported_module.subModule_1:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "Baz", + "Foo" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "Bar", + "Corge" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/record_inclusion.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/record_inclusion.json new file mode 100644 index 000000000000..a487878de964 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/record_inclusion.json @@ -0,0 +1,34 @@ +{ + "thushara_piyasekara/record_inclusion:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "RecE", + "RecA", + "B", + "C" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "D" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/tranistive_functions_1.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/tranistive_functions_1.json new file mode 100644 index 000000000000..60f9a562c624 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/tranistive_functions_1.json @@ -0,0 +1,31 @@ +{ + "thushara_piyasekara/tranistive_functions_1:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo", + "bar" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "baz" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/tranistive_functions_2.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/tranistive_functions_2.json new file mode 100644 index 000000000000..bcb2aa9ec97d --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/tranistive_functions_2.json @@ -0,0 +1,31 @@ +{ + "thushara_piyasekara/tranistive_functions_2:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "bar", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "baz" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/transitive_function_in_imported_module.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/transitive_function_in_imported_module.json new file mode 100644 index 000000000000..45fb2c6584bd --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/transitive_function_in_imported_module.json @@ -0,0 +1,55 @@ +{ + "thushara_piyasekara/transitive_function_in_imported_module:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + }, + "thushara_piyasekara/transitive_function_in_imported_module.subModule:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "subModuleFunction", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/transitive_module_imports.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/transitive_module_imports.json new file mode 100644 index 000000000000..7bc23487c537 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/transitive_module_imports.json @@ -0,0 +1,79 @@ +{ + "thushara_piyasekara/transitive_module_imports:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + }, + "thushara_piyasekara/transitive_module_imports.subModule_1:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "subModuleFunction" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + }, + "thushara_piyasekara/transitive_module_imports.subModule_2:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/transitive_types.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/transitive_types.json new file mode 100644 index 000000000000..5ab48bb87004 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/transitive_types.json @@ -0,0 +1,32 @@ +{ + "thushara_piyasekara/transitive_types:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "B", + "A" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "C" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_cast.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_cast.json new file mode 100644 index 000000000000..84aed8da04aa --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_cast.json @@ -0,0 +1,31 @@ +{ + "thushara_piyasekara/type_cast:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "B", + "A", + "C" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_def_reference_inisde_closure.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_def_reference_inisde_closure.json new file mode 100644 index 000000000000..f88f61631257 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_def_reference_inisde_closure.json @@ -0,0 +1,30 @@ +{ + "thushara_piyasekara/type_def_reference_inisde_closure:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "$lambda$_0" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "CustomType" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_definition_from_imported_module.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_definition_from_imported_module.json new file mode 100644 index 000000000000..e74cb65726e5 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_definition_from_imported_module.json @@ -0,0 +1,55 @@ +{ + "thushara_piyasekara/type_definition_from_imported_module:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + }, + "thushara_piyasekara/type_definition_from_imported_module.subModule_1:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "Baz", + "Foo" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "Bar" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_definition_inside_listener.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_definition_inside_listener.json new file mode 100644 index 000000000000..3a3120a5f4f2 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_definition_inside_listener.json @@ -0,0 +1,50 @@ +{ + "thushara_piyasekara/type_definition_inside_listener:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "object { thushara_piyasekara/type_definition_inside_listener:0.1.0:UsedTypeDef customValue; resource function get albums() returns ((string|int|error)); }.$get$albums", + "thushara_piyasekara/type_definition_inside_listener:0.1.0:Listener.start", + "thushara_piyasekara/type_definition_inside_listener:0.1.0:Listener.gracefulStop", + "thushara_piyasekara/type_definition_inside_listener:0.1.0:Listener.immediateStop", + "thushara_piyasekara/type_definition_inside_listener:0.1.0:Listener.detach", + "thushara_piyasekara/type_definition_inside_listener:0.1.0:Listener.attach", + "thushara_piyasekara/type_definition_inside_listener:0.1.0:Listener.init" + ], + "virtualFunctions": [ + ".", + "$annot_func$_0", + "thushara_piyasekara/type_definition_inside_listener:0.1.0.0", + "object { thushara_piyasekara/type_definition_inside_listener:0.1.0:UsedTypeDef customValue; resource function get albums() returns ((string|int|error)); }.$init$", + "thushara_piyasekara/type_definition_inside_listener:0.1.0.1", + "thushara_piyasekara/type_definition_inside_listener:0.1.0:Listener.$init$", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [ + "$Listener_Listener_attach_name" + ] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "UsedTypeDef", + "Listener" + ], + "virtualTypeDefinitions": [ + "$anonType$_1", + "$anonType$_0", + "$anonType$s$detach$_0", + "$anonType$s$attach$_0" + ] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "UnusedTypeDef" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_definition_inside_remote_function_body.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_definition_inside_remote_function_body.json new file mode 100644 index 000000000000..63120f207c5f --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_definition_inside_remote_function_body.json @@ -0,0 +1,50 @@ +{ + "thushara_piyasekara/type_definition_inside_remote_function_body:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "isolated object { public isolated function albums () returns ((string|int|error)); }.albums", + "thushara_piyasekara/type_definition_inside_remote_function_body:0.1.0:Listener.start", + "thushara_piyasekara/type_definition_inside_remote_function_body:0.1.0:Listener.gracefulStop", + "thushara_piyasekara/type_definition_inside_remote_function_body:0.1.0:Listener.immediateStop", + "thushara_piyasekara/type_definition_inside_remote_function_body:0.1.0:Listener.detach", + "thushara_piyasekara/type_definition_inside_remote_function_body:0.1.0:Listener.attach", + "thushara_piyasekara/type_definition_inside_remote_function_body:0.1.0:Listener.init" + ], + "virtualFunctions": [ + ".", + "$annot_func$_0", + "thushara_piyasekara/type_definition_inside_remote_function_body:0.1.0.0", + "isolated object { public isolated function albums () returns ((string|int|error)); }.$init$", + "thushara_piyasekara/type_definition_inside_remote_function_body:0.1.0.1", + "thushara_piyasekara/type_definition_inside_remote_function_body:0.1.0:Listener.$init$", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [ + "$Listener_Listener_attach_name" + ] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "UsedTypeDef", + "Listener" + ], + "virtualTypeDefinitions": [ + "$anonType$_1", + "$anonType$_0", + "$anonType$s$detach$_0", + "$anonType$s$attach$_0" + ] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "UnusedTypeDef" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_definition_inside_remote_function_param.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_definition_inside_remote_function_param.json new file mode 100644 index 000000000000..86c6b3206221 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_definition_inside_remote_function_param.json @@ -0,0 +1,50 @@ +{ + "thushara_piyasekara/type_definition_inside_remote_function_param:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "isolated object { public isolated function albums () returns ((thushara_piyasekara/type_definition_inside_remote_function_param:0.1.0:UsedTypeDef|error)); }.albums", + "thushara_piyasekara/type_definition_inside_remote_function_param:0.1.0:Listener.start", + "thushara_piyasekara/type_definition_inside_remote_function_param:0.1.0:Listener.gracefulStop", + "thushara_piyasekara/type_definition_inside_remote_function_param:0.1.0:Listener.immediateStop", + "thushara_piyasekara/type_definition_inside_remote_function_param:0.1.0:Listener.detach", + "thushara_piyasekara/type_definition_inside_remote_function_param:0.1.0:Listener.attach", + "thushara_piyasekara/type_definition_inside_remote_function_param:0.1.0:Listener.init" + ], + "virtualFunctions": [ + ".", + "$annot_func$_0", + "thushara_piyasekara/type_definition_inside_remote_function_param:0.1.0.0", + "isolated object { public isolated function albums () returns ((thushara_piyasekara/type_definition_inside_remote_function_param:0.1.0:UsedTypeDef|error)); }.$init$", + "thushara_piyasekara/type_definition_inside_remote_function_param:0.1.0.1", + "thushara_piyasekara/type_definition_inside_remote_function_param:0.1.0:Listener.$init$", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [ + "$Listener_Listener_attach_name" + ] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "UsedTypeDef", + "Listener" + ], + "virtualTypeDefinitions": [ + "$anonType$_1", + "$anonType$_0", + "$anonType$s$detach$_0", + "$anonType$s$attach$_0" + ] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "UnusedTypeDef" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_definition_inside_resource_function_body.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_definition_inside_resource_function_body.json new file mode 100644 index 000000000000..7faf04b45030 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_definition_inside_resource_function_body.json @@ -0,0 +1,50 @@ +{ + "thushara_piyasekara/type_definition_inside_resource_function_body:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "isolated object { resource function get albums() returns ((string|int|error)); }.$get$albums", + "thushara_piyasekara/type_definition_inside_resource_function_body:0.1.0:Listener.start", + "thushara_piyasekara/type_definition_inside_resource_function_body:0.1.0:Listener.gracefulStop", + "thushara_piyasekara/type_definition_inside_resource_function_body:0.1.0:Listener.immediateStop", + "thushara_piyasekara/type_definition_inside_resource_function_body:0.1.0:Listener.detach", + "thushara_piyasekara/type_definition_inside_resource_function_body:0.1.0:Listener.attach", + "thushara_piyasekara/type_definition_inside_resource_function_body:0.1.0:Listener.init" + ], + "virtualFunctions": [ + ".", + "$annot_func$_0", + "thushara_piyasekara/type_definition_inside_resource_function_body:0.1.0.0", + "isolated object { resource function get albums() returns ((string|int|error)); }.$init$", + "thushara_piyasekara/type_definition_inside_resource_function_body:0.1.0.1", + "thushara_piyasekara/type_definition_inside_resource_function_body:0.1.0:Listener.$init$", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [ + "$Listener_Listener_attach_name" + ] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "UsedTypeDef", + "Listener" + ], + "virtualTypeDefinitions": [ + "$anonType$_1", + "$anonType$_0", + "$anonType$s$detach$_0", + "$anonType$s$attach$_0" + ] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "UnusedTypeDef" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_definition_inside_resource_function_param.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_definition_inside_resource_function_param.json new file mode 100644 index 000000000000..b5b51466fd36 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_definition_inside_resource_function_param.json @@ -0,0 +1,50 @@ +{ + "thushara_piyasekara/type_definition_inside_resource_function_param:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "isolated object { resource function get albums() returns ((thushara_piyasekara/type_definition_inside_resource_function_param:0.1.0:UsedTypeDef|error)); }.$get$albums", + "thushara_piyasekara/type_definition_inside_resource_function_param:0.1.0:Listener.start", + "thushara_piyasekara/type_definition_inside_resource_function_param:0.1.0:Listener.gracefulStop", + "thushara_piyasekara/type_definition_inside_resource_function_param:0.1.0:Listener.immediateStop", + "thushara_piyasekara/type_definition_inside_resource_function_param:0.1.0:Listener.detach", + "thushara_piyasekara/type_definition_inside_resource_function_param:0.1.0:Listener.attach", + "thushara_piyasekara/type_definition_inside_resource_function_param:0.1.0:Listener.init" + ], + "virtualFunctions": [ + ".", + "$annot_func$_0", + "thushara_piyasekara/type_definition_inside_resource_function_param:0.1.0.0", + "isolated object { resource function get albums() returns ((thushara_piyasekara/type_definition_inside_resource_function_param:0.1.0:UsedTypeDef|error)); }.$init$", + "thushara_piyasekara/type_definition_inside_resource_function_param:0.1.0.1", + "thushara_piyasekara/type_definition_inside_resource_function_param:0.1.0:Listener.$init$", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [ + "$Listener_Listener_attach_name" + ] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "UsedTypeDef", + "Listener" + ], + "virtualTypeDefinitions": [ + "$anonType$_1", + "$anonType$_0", + "$anonType$s$detach$_0", + "$anonType$s$attach$_0" + ] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "UnusedTypeDef" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_definition_inside_worker.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_definition_inside_worker.json new file mode 100644 index 000000000000..d66edcbd1a90 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_definition_inside_worker.json @@ -0,0 +1,32 @@ +{ + "thushara_piyasekara/type_definition_inside_worker:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "$lambda$_0" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "UsedTypeDef" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "UnusedTypeDef" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_definition_inside_worker_with_return.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_definition_inside_worker_with_return.json new file mode 100644 index 000000000000..cc001f6a14cd --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_definition_inside_worker_with_return.json @@ -0,0 +1,32 @@ +{ + "thushara_piyasekara/type_definition_inside_worker_with_return:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "$lambda$_0" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "UsedTypeDef" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "UnusedTypeDef" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_narrowing.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_narrowing.json new file mode 100644 index 000000000000..6f6f065a741a --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_narrowing.json @@ -0,0 +1,30 @@ +{ + "thushara_piyasekara/type_narrowing:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "A", + "B" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_varargs.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_varargs.json new file mode 100644 index 000000000000..e0101557d1aa --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/type_varargs.json @@ -0,0 +1,32 @@ +{ + "thushara_piyasekara/type_varargs:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "A" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "B" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/unused_anonymous_function.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/unused_anonymous_function.json new file mode 100644 index 000000000000..40a1d163f365 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/unused_anonymous_function.json @@ -0,0 +1,38 @@ +{ + "thushara_piyasekara/unused_anonymous_function:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo", + "bar", + "baz" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "$lambda$_0", + "$lambda$_2", + "$lambda$_4", + "$lambda$_6" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [ + "$lambda$_1", + "$lambda$_3", + "$lambda$_5" + ] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/vanilla_classes.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/vanilla_classes.json new file mode 100644 index 000000000000..6413bebb5789 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/vanilla_classes.json @@ -0,0 +1,34 @@ +{ + "thushara_piyasekara/vanilla_classes:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "thushara_piyasekara/vanilla_classes:0.1.0:CKlass.init" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "thushara_piyasekara/vanilla_classes:0.1.0:CKlass.$init$" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "CKlass", + "A", + "B", + "C" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/vanilla_functions.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/vanilla_functions.json new file mode 100644 index 000000000000..3c6acf27f4c5 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/vanilla_functions.json @@ -0,0 +1,30 @@ +{ + "thushara_piyasekara/vanilla_functions:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/vanilla_types.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/vanilla_types.json new file mode 100644 index 000000000000..1e48e3dd8b0e --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/vanilla_types.json @@ -0,0 +1,31 @@ +{ + "thushara_piyasekara/vanilla_types:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "A" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "B" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/worker_derived_lambda_functions.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/worker_derived_lambda_functions.json new file mode 100644 index 000000000000..8a25288cd0e0 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/build-projects/worker_derived_lambda_functions.json @@ -0,0 +1,36 @@ +{ + "thushara_piyasekara/worker_derived_lambda_functions:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "$lambda$_0" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar", + "baz" + ], + "virtualFunctions": [ + "$lambda$_1" + ] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [ + "$anonType$_0" + ] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/arrow_functions_1.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/arrow_functions_1.json new file mode 100644 index 000000000000..72201da09229 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/arrow_functions_1.json @@ -0,0 +1,32 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "$lambda$_0" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [ + "$lambda$_1" + ] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "ReturnsIntFunction" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/arrow_functions_2.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/arrow_functions_2.json new file mode 100644 index 000000000000..72201da09229 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/arrow_functions_2.json @@ -0,0 +1,32 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "$lambda$_0" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [ + "$lambda$_1" + ] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "ReturnsIntFunction" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/class_inclusion.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/class_inclusion.json new file mode 100644 index 000000000000..d18a0ec3bfdc --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/class_inclusion.json @@ -0,0 +1,37 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "Engineer.clone", + "Engineer.getName", + "Engineer.init", + "Person.getName", + "Cloneable.clone" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "Engineer.$init$" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "Engineer", + "Person", + "Cloneable" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/class_level_functions.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/class_level_functions.json new file mode 100644 index 000000000000..51ffe6d42f42 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/class_level_functions.json @@ -0,0 +1,34 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "CKlass.foo", + "CKlass.bar" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "CKlass.$init$" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "foo" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "CKlass" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_invocation_as_default_value.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_invocation_as_default_value.json new file mode 100644 index 000000000000..2f976f9ac2fd --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_invocation_as_default_value.json @@ -0,0 +1,40 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo", + "baz", + "corge" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "$UsedRec_$rec$UsedRec$rec$name", + "$corge_defaultParam" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [ + "$UnusedRec_$rec$UnusedRec$rec$name" + ] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "UsedRec" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "UnusedRec" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_invocation_inside_closure.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_invocation_inside_closure.json new file mode 100644 index 000000000000..c6f1cce638f8 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_invocation_inside_closure.json @@ -0,0 +1,29 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "$lambda$_0" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_invocation_inside_global_closure.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_invocation_inside_global_closure.json new file mode 100644 index 000000000000..c6f1cce638f8 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_invocation_inside_global_closure.json @@ -0,0 +1,29 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "$lambda$_0" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_invocation_inside_match_statement.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_invocation_inside_match_statement.json new file mode 100644 index 000000000000..6711eb705530 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_invocation_inside_match_statement.json @@ -0,0 +1,30 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_invocation_inside_match_statement_obstruction.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_invocation_inside_match_statement_obstruction.json new file mode 100644 index 000000000000..e55f2eb113f8 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_invocation_inside_match_statement_obstruction.json @@ -0,0 +1,31 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "baz", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_invocation_inside_record.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_invocation_inside_record.json new file mode 100644 index 000000000000..5a5d8d616924 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_invocation_inside_record.json @@ -0,0 +1,32 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "RecA" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointer_invocation_inisde_different_bb.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointer_invocation_inisde_different_bb.json new file mode 100644 index 000000000000..dd16f054de64 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointer_invocation_inisde_different_bb.json @@ -0,0 +1,28 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointer_invocation_inside_lock.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointer_invocation_inside_lock.json new file mode 100644 index 000000000000..c0e8128870c9 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointer_invocation_inside_lock.json @@ -0,0 +1,33 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "className.foo", + "className.bar" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "className.$init$", + "$anon$method$delegate$className.foo$0" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "className" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointers_as_arguments.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointers_as_arguments.json new file mode 100644 index 000000000000..3af01662aeec --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointers_as_arguments.json @@ -0,0 +1,34 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo", + "fpEater", + "baz" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "ReturnsIntFunction" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointers_global_assignment.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointers_global_assignment.json new file mode 100644 index 000000000000..2022acf0a6bd --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointers_global_assignment.json @@ -0,0 +1,32 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "ReturnsIntFunction" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointers_inside_array.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointers_inside_array.json new file mode 100644 index 000000000000..a0beb3bf23ea --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointers_inside_array.json @@ -0,0 +1,31 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "foo", + "bar", + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "ReturnsIntFunction" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointers_inside_lock.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointers_inside_lock.json new file mode 100644 index 000000000000..d564e41e47ef --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointers_inside_lock.json @@ -0,0 +1,33 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "className.foo", + "className.execute2" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "className.$init$", + "$anon$method$delegate$className.foo$0" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "className" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointers_inside_record.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointers_inside_record.json new file mode 100644 index 000000000000..823f1f3795cc --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointers_inside_record.json @@ -0,0 +1,33 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "FPRecord", + "ReturnsIntFunction" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointers_invocation_inside_record.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointers_invocation_inside_record.json new file mode 100644 index 000000000000..559cb4acd793 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointers_invocation_inside_record.json @@ -0,0 +1,33 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "RecA", + "ReturnsIntFunction" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointers_local_assignment.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointers_local_assignment.json new file mode 100644 index 000000000000..f2d264fe1095 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointers_local_assignment.json @@ -0,0 +1,32 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "fooUnused" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "ReturnsIntFunction" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointers_transitive_assignment.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointers_transitive_assignment.json new file mode 100644 index 000000000000..2022acf0a6bd --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/function_pointers_transitive_assignment.json @@ -0,0 +1,32 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "ReturnsIntFunction" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/global_value_initialization.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/global_value_initialization.json new file mode 100644 index 000000000000..5128c4da480a --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/global_value_initialization.json @@ -0,0 +1,31 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "A" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "B" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/intersection_types.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/intersection_types.json new file mode 100644 index 000000000000..bd39c9d05baf --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/intersection_types.json @@ -0,0 +1,33 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "BigErr", + "XErr", + "YErr" + ], + "virtualTypeDefinitions": [ + "$anonIntersectionErrorType$_0" + ] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/parameters_via_record_field_mapping.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/parameters_via_record_field_mapping.json new file mode 100644 index 000000000000..9abe37225f2f --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/parameters_via_record_field_mapping.json @@ -0,0 +1,35 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "RecA", + "B", + "C" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "D", + "RecE" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/query_expression_type_usage.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/query_expression_type_usage.json new file mode 100644 index 000000000000..e71d402123dc --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/query_expression_type_usage.json @@ -0,0 +1,35 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "$streamLambda$_0", + "$streamLambda$_1", + "$streamLambda$_2" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "B" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "A", + "C" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/record_dependency.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/record_dependency.json new file mode 100644 index 000000000000..2733bced26ff --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/record_dependency.json @@ -0,0 +1,34 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "RecA", + "B", + "C" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "RecD", + "E" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/record_inclusion.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/record_inclusion.json new file mode 100644 index 000000000000..2692f9262d3a --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/record_inclusion.json @@ -0,0 +1,34 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "RecE", + "RecA", + "B", + "C" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "D" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/tranistive_functions_1.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/tranistive_functions_1.json new file mode 100644 index 000000000000..cbb495d6d153 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/tranistive_functions_1.json @@ -0,0 +1,31 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo", + "bar" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "baz" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/tranistive_functions_2.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/tranistive_functions_2.json new file mode 100644 index 000000000000..2ca10382da8c --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/tranistive_functions_2.json @@ -0,0 +1,31 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "bar", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "baz" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/transitive_types.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/transitive_types.json new file mode 100644 index 000000000000..e334d78ebf4e --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/transitive_types.json @@ -0,0 +1,32 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "B", + "A" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "C" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/type_cast.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/type_cast.json new file mode 100644 index 000000000000..f098d7e3d957 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/type_cast.json @@ -0,0 +1,31 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "B", + "A", + "C" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/type_def_reference_inisde_closure.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/type_def_reference_inisde_closure.json new file mode 100644 index 000000000000..4df0c050dad9 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/type_def_reference_inisde_closure.json @@ -0,0 +1,30 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "$lambda$_0" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "CustomType" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/type_inside_query_expression.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/type_inside_query_expression.json new file mode 100644 index 000000000000..90437eae8e7a --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/type_inside_query_expression.json @@ -0,0 +1,32 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "$streamLambda$_0", + "$streamLambda$_1" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "A", + "B" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/type_narrowing.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/type_narrowing.json new file mode 100644 index 000000000000..07d4497af74e --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/type_narrowing.json @@ -0,0 +1,30 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "A", + "B" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/type_varargs.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/type_varargs.json new file mode 100644 index 000000000000..10dc86e56577 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/type_varargs.json @@ -0,0 +1,32 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "A" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "B" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/vanilla_classes.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/vanilla_classes.json new file mode 100644 index 000000000000..56bfbaf9ffde --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/vanilla_classes.json @@ -0,0 +1,34 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "CKlass.init" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "CKlass.$init$" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "CKlass", + "A", + "B", + "C" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/vanilla_functions.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/vanilla_functions.json new file mode 100644 index 000000000000..6711eb705530 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/vanilla_functions.json @@ -0,0 +1,30 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main", + "foo" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "bar" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/vanilla_types.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/vanilla_types.json new file mode 100644 index 000000000000..5128c4da480a --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/json-files/single-file-projects/vanilla_types.json @@ -0,0 +1,31 @@ +{ + ".": { + "usedFunctionNames": { + "sourceFunctions": [ + "main" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "A" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "B" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_function_pointer_invocation_from_imported_module/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_function_pointer_invocation_from_imported_module/.devcontainer.json new file mode 100644 index 000000000000..8a0177271a49 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_function_pointer_invocation_from_imported_module/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.8.6", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_function_pointer_invocation_from_imported_module/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_function_pointer_invocation_from_imported_module/.gitignore new file mode 100644 index 000000000000..7512ebe2325f --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_function_pointer_invocation_from_imported_module/.gitignore @@ -0,0 +1,3 @@ +target +generated +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_function_pointer_invocation_from_imported_module/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_function_pointer_invocation_from_imported_module/Ballerina.toml new file mode 100644 index 000000000000..5d10d2311c84 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_function_pointer_invocation_from_imported_module/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "arrow_function_pointer_invocation_from_imported_module" +version = "0.1.0" +distribution = "2201.8.6" + +[build-options] +observabilityIncluded = true diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_function_pointer_invocation_from_imported_module/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_function_pointer_invocation_from_imported_module/Dependencies.toml new file mode 100644 index 000000000000..3048d21c8cdf --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_function_pointer_invocation_from_imported_module/Dependencies.toml @@ -0,0 +1,46 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.3" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + +[[package]] +org = "thushara_piyasekara" +name = "arrow_function_pointer_invocation_from_imported_module" +version = "0.1.0" +dependencies = [ + {org = "ballerinai", name = "observe"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "arrow_function_pointer_invocation_from_imported_module", moduleName = "arrow_function_pointer_invocation_from_imported_module"}, + {org = "thushara_piyasekara", packageName = "arrow_function_pointer_invocation_from_imported_module", moduleName = "arrow_function_pointer_invocation_from_imported_module.subModule_1"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_function_pointer_invocation_from_imported_module/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_function_pointer_invocation_from_imported_module/main.bal new file mode 100644 index 000000000000..94cf76115f89 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_function_pointer_invocation_from_imported_module/main.bal @@ -0,0 +1,21 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import arrow_function_pointer_invocation_from_imported_module.subModule_1; + +public function main() { + _ = subModule_1:globalArrow(22, 33); +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_function_pointer_invocation_from_imported_module/modules/subModule_1/subModule_1.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_function_pointer_invocation_from_imported_module/modules/subModule_1/subModule_1.bal new file mode 100644 index 000000000000..c081e8a65551 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_function_pointer_invocation_from_imported_module/modules/subModule_1/subModule_1.bal @@ -0,0 +1,18 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function (int, int) returns int globalArrow = (a, b) => a + b; +public function (string, string) returns string globalArrowUnused = (a, b) => a + b; diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_1/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_1/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_1/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_1/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_1/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_1/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_1/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_1/Ballerina.toml new file mode 100644 index 000000000000..2f10aa8dfea7 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_1/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "arrow_functions_1" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_1/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_1/Dependencies.toml new file mode 100644 index 000000000000..803b3b144a31 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_1/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "arrow_functions_1" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "arrow_functions_1", moduleName = "arrow_functions_1"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_1/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_1/main.bal new file mode 100644 index 000000000000..a0ce59557473 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_1/main.bal @@ -0,0 +1,24 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type ReturnsIntFunction function (int) returns int; + +ReturnsIntFunction globalFP = (val) => val * 2; +ReturnsIntFunction globalFPUnused = (val) => val * 3; + +public function main() { + _ = globalFP(4); +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_2/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_2/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_2/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_2/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_2/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_2/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_2/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_2/Ballerina.toml new file mode 100644 index 000000000000..b8b5fcfeaac9 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_2/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "arrow_functions_2" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_2/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_2/Dependencies.toml new file mode 100644 index 000000000000..f7cf4f26bd13 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_2/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "arrow_functions_2" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "arrow_functions_2", moduleName = "arrow_functions_2"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_2/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_2/main.bal new file mode 100644 index 000000000000..fa47c9a75005 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/arrow_functions_2/main.bal @@ -0,0 +1,26 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type ReturnsIntFunction function (int) returns int; + +ReturnsIntFunction globalFP = (val) => val * 2; +ReturnsIntFunction globalFPUnused = (val) => val * 3; + +public function main() { + ReturnsIntFunction localFP1 = globalFP; + ReturnsIntFunction localFP2 = localFP1; + _ = localFP2(2); +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/class_level_functions/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/class_level_functions/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/class_level_functions/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/class_level_functions/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/class_level_functions/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/class_level_functions/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/class_level_functions/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/class_level_functions/Ballerina.toml new file mode 100644 index 000000000000..c507b0c6f14c --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/class_level_functions/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "class_level_functions" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/class_level_functions/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/class_level_functions/Dependencies.toml new file mode 100644 index 000000000000..8df99d476261 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/class_level_functions/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "class_level_functions" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "class_level_functions", moduleName = "class_level_functions"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/class_level_functions/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/class_level_functions/main.bal new file mode 100644 index 000000000000..cd681b95b5d9 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/class_level_functions/main.bal @@ -0,0 +1,34 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +class CKlass { + function foo() { + + } + + function bar() { + + } +} + +public function main() { + CKlass c = new (); + c.foo(); +} + +function foo() { + +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_as_default_value/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_as_default_value/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_as_default_value/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_as_default_value/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_as_default_value/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_as_default_value/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_as_default_value/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_as_default_value/Ballerina.toml new file mode 100644 index 000000000000..1418a2650638 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_as_default_value/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "function_invocation_as_default_value" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_as_default_value/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_as_default_value/Dependencies.toml new file mode 100644 index 000000000000..b03a5b66f3fe --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_as_default_value/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "function_invocation_as_default_value" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "function_invocation_as_default_value", moduleName = "function_invocation_as_default_value"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_as_default_value/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_as_default_value/main.bal new file mode 100644 index 000000000000..2068b16827c8 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_as_default_value/main.bal @@ -0,0 +1,43 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type UsedRec record { + string name = foo(); +}; + +type UnusedRec record { + string name = bar(); +}; + +public function main() { + UsedRec rec = {}; + corge(); +} + +public function corge(string defaultParam = baz()) { +} + +isolated function foo() returns string { + return "Im used"; +} + +isolated function baz() returns string { + return "Im used"; +} + +isolated function bar() returns string { + return "Im unused"; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_in_different_module/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_in_different_module/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_in_different_module/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_in_different_module/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_in_different_module/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_in_different_module/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_in_different_module/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_in_different_module/Ballerina.toml new file mode 100644 index 000000000000..a9171be1cde0 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_in_different_module/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "function_invocation_in_different_module" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_in_different_module/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_in_different_module/Dependencies.toml new file mode 100644 index 000000000000..55bfc831397f --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_in_different_module/Dependencies.toml @@ -0,0 +1,18 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "function_invocation_in_different_module" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "function_invocation_in_different_module", moduleName = "function_invocation_in_different_module"}, + {org = "thushara_piyasekara", packageName = "function_invocation_in_different_module", moduleName = "function_invocation_in_different_module.subModule"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_in_different_module/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_in_different_module/main.bal new file mode 100644 index 000000000000..74787961f3fb --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_in_different_module/main.bal @@ -0,0 +1,20 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +import function_invocation_in_different_module.subModule; + +public function main() { + subModule:subModuleFunction(); +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_in_different_module/modules/subModule/subModule.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_in_different_module/modules/subModule/subModule.bal new file mode 100644 index 000000000000..9cbd9fa52634 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_in_different_module/modules/subModule/subModule.bal @@ -0,0 +1,22 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function subModuleFunction() { +} + +function foo() { + +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_closure/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_closure/.devcontainer.json new file mode 100644 index 000000000000..8a0177271a49 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_closure/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.8.6", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_closure/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_closure/.gitignore new file mode 100644 index 000000000000..7512ebe2325f --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_closure/.gitignore @@ -0,0 +1,3 @@ +target +generated +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_closure/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_closure/Ballerina.toml new file mode 100644 index 000000000000..aad17a9d56c0 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_closure/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "function_invocation_inside_closure" +version = "0.1.0" +distribution = "2201.8.6" + +[build-options] +observabilityIncluded = true diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_closure/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_closure/Dependencies.toml new file mode 100644 index 000000000000..88d3ea4f8ea3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_closure/Dependencies.toml @@ -0,0 +1,45 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.3" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + +[[package]] +org = "thushara_piyasekara" +name = "function_invocation_inside_closure" +version = "0.1.0" +dependencies = [ + {org = "ballerinai", name = "observe"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "function_invocation_inside_closure", moduleName = "function_invocation_inside_closure"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_closure/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_closure/main.bal new file mode 100644 index 000000000000..dd2050b5a0df --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_closure/main.bal @@ -0,0 +1,27 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function main() { + var addName = function() returns string { + return foo(); + }; + + _ = addName(); +} + +function foo() returns string { + return "John"; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_global_closure/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_global_closure/.devcontainer.json new file mode 100644 index 000000000000..8a0177271a49 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_global_closure/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.8.6", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_global_closure/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_global_closure/.gitignore new file mode 100644 index 000000000000..7512ebe2325f --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_global_closure/.gitignore @@ -0,0 +1,3 @@ +target +generated +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_global_closure/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_global_closure/Ballerina.toml new file mode 100644 index 000000000000..f84d5795669a --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_global_closure/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "function_invocation_inside_global_closure" +version = "0.1.0" +distribution = "2201.8.6" + +[build-options] +observabilityIncluded = true diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_global_closure/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_global_closure/Dependencies.toml new file mode 100644 index 000000000000..6ebf8eef53c2 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_global_closure/Dependencies.toml @@ -0,0 +1,45 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.3" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + +[[package]] +org = "thushara_piyasekara" +name = "function_invocation_inside_global_closure" +version = "0.1.0" +dependencies = [ + {org = "ballerinai", name = "observe"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "function_invocation_inside_global_closure", moduleName = "function_invocation_inside_global_closure"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_global_closure/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_global_closure/main.bal new file mode 100644 index 000000000000..6e6b2281bae7 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_global_closure/main.bal @@ -0,0 +1,27 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +var addName = function() returns string { + return foo(); +}; + +public function main() { + _ = addName(); +} + +function foo() returns string { + return "John"; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_listener/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_listener/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_listener/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_listener/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_listener/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_listener/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_listener/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_listener/Ballerina.toml new file mode 100644 index 000000000000..0de66821b683 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_listener/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "function_invocation_inside_listener" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + +[build-options] +observabilityIncluded = true diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_listener/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_listener/Dependencies.toml new file mode 100644 index 000000000000..cf487dec6aad --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_listener/Dependencies.toml @@ -0,0 +1,45 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.3" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + +[[package]] +org = "thushara_piyasekara" +name = "function_invocation_inside_listener" +version = "0.1.0" +dependencies = [ + {org = "ballerinai", name = "observe"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "function_invocation_inside_listener", moduleName = "function_invocation_inside_listener"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_listener/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_listener/main.bal new file mode 100644 index 000000000000..56672fe8f70d --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_listener/main.bal @@ -0,0 +1,52 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public isolated class Listener { + private int port; + public function 'start() returns error? { + } + + public function gracefulStop() returns error? { + } + + public function immediateStop() returns error? { + } + + public function detach(service object {} s) returns error? { + } + + public function attach(service object {} s, string[]? name = ()) returns error? { + } + + public function init(int port) { + self.port = port; + } +} + +service / on new Listener(1000) { + string usedVar = foo(); + resource function get albums() returns string { + return self.usedVar; + } +} + +isolated function foo() returns string { + return "foo"; +} + +isolated function bar() returns string { + return "bar"; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement/Ballerina.toml new file mode 100644 index 000000000000..0dc2d841224c --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "function_invocation_inside_match_statement" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement/Dependencies.toml new file mode 100644 index 000000000000..7d0366295396 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "function_invocation_inside_match_statement" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "function_invocation_inside_match_statement", moduleName = "function_invocation_inside_match_statement"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement/main.bal new file mode 100644 index 000000000000..a11fb86fba34 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement/main.bal @@ -0,0 +1,33 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function main() { + int val = 0; + match val { + 0 => { + foo(); + } + 1 => { + + } + } +} + +function foo() { +} + +function bar() { +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement_obstruction/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement_obstruction/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement_obstruction/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement_obstruction/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement_obstruction/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement_obstruction/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement_obstruction/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement_obstruction/Ballerina.toml new file mode 100644 index 000000000000..272669dc3362 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement_obstruction/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "function_invocation_inside_match_statement_obstruction" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement_obstruction/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement_obstruction/Dependencies.toml new file mode 100644 index 000000000000..cc7ae901d995 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement_obstruction/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "function_invocation_inside_match_statement_obstruction" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "function_invocation_inside_match_statement_obstruction", moduleName = "function_invocation_inside_match_statement_obstruction"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement_obstruction/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement_obstruction/main.bal new file mode 100644 index 000000000000..eaa5eeeff7e0 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_match_statement_obstruction/main.bal @@ -0,0 +1,37 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function main() { + int val = 0; + match val { + 0 if baz() => { + foo(); + } + 1 => { + + } + } +} + +function foo() { +} + +function bar() { +} + +function baz() returns boolean { + return true; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_record/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_record/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_record/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_record/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_record/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_record/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_record/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_record/Ballerina.toml new file mode 100644 index 000000000000..c0f7962fd21c --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_record/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "function_invocation_inside_record" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_record/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_record/Dependencies.toml new file mode 100644 index 000000000000..9ddb5dc19014 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_record/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "function_invocation_inside_record" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "function_invocation_inside_record", moduleName = "function_invocation_inside_record"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_record/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_record/main.bal new file mode 100644 index 000000000000..a3bbade7bac2 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_record/main.bal @@ -0,0 +1,33 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type RecA record { + string name; +}; + +public function main() { + RecA rec = { + name: foo() + }; +} + +function foo() returns string { + return "Im used"; +} + +function bar() returns string { + return "Im unused"; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_remote_function_body/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_remote_function_body/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_remote_function_body/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_remote_function_body/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_remote_function_body/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_remote_function_body/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_remote_function_body/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_remote_function_body/Ballerina.toml new file mode 100644 index 000000000000..67db62895dfb --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_remote_function_body/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "function_invocation_inside_remote_function_body" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + +[build-options] +observabilityIncluded = true diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_remote_function_body/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_remote_function_body/Dependencies.toml new file mode 100644 index 000000000000..6f3b1b55f3e2 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_remote_function_body/Dependencies.toml @@ -0,0 +1,45 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.3" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + +[[package]] +org = "thushara_piyasekara" +name = "function_invocation_inside_remote_function_body" +version = "0.1.0" +dependencies = [ + {org = "ballerinai", name = "observe"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "function_invocation_inside_remote_function_body", moduleName = "function_invocation_inside_remote_function_body"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_remote_function_body/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_remote_function_body/main.bal new file mode 100644 index 000000000000..934cc3dd0df9 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_remote_function_body/main.bal @@ -0,0 +1,51 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public isolated class Listener { + private int port; + public function 'start() returns error? { + } + + public function gracefulStop() returns error? { + } + + public function immediateStop() returns error? { + } + + public function detach(service object {} s) returns error? { + } + + public function attach(service object {} s, string[]? name = ()) returns error? { + } + + public function init(int port) { + self.port = port; + } +} + +service / on new Listener(1000) { + remote function albums() returns string { + return foo(); + } +} + +isolated function foo() returns string { + return "foo"; +} + +isolated function bar() returns string { + return "bar"; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_resource_function_body/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_resource_function_body/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_resource_function_body/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_resource_function_body/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_resource_function_body/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_resource_function_body/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_resource_function_body/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_resource_function_body/Ballerina.toml new file mode 100644 index 000000000000..3a584122e3f1 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_resource_function_body/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "function_invocation_inside_resource_function_body" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + +[build-options] +observabilityIncluded = true diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_resource_function_body/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_resource_function_body/Dependencies.toml new file mode 100644 index 000000000000..cf487dec6aad --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_resource_function_body/Dependencies.toml @@ -0,0 +1,45 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.3" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + +[[package]] +org = "thushara_piyasekara" +name = "function_invocation_inside_listener" +version = "0.1.0" +dependencies = [ + {org = "ballerinai", name = "observe"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "function_invocation_inside_listener", moduleName = "function_invocation_inside_listener"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_resource_function_body/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_resource_function_body/main.bal new file mode 100644 index 000000000000..d62883e7070c --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_resource_function_body/main.bal @@ -0,0 +1,51 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public isolated class Listener { + private int port; + public function 'start() returns error? { + } + + public function gracefulStop() returns error? { + } + + public function immediateStop() returns error? { + } + + public function detach(service object {} s) returns error? { + } + + public function attach(service object {} s, string[]? name = ()) returns error? { + } + + public function init(int port) { + self.port = port; + } +} + +service / on new Listener(1000) { + resource function get albums() returns string { + return foo(); + } +} + +function foo() returns string { + return "foo"; +} + +function bar() returns string { + return "bar"; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_return/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_return/.devcontainer.json new file mode 100644 index 000000000000..8a0177271a49 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_return/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.8.6", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_return/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_return/.gitignore new file mode 100644 index 000000000000..7512ebe2325f --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_return/.gitignore @@ -0,0 +1,3 @@ +target +generated +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_return/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_return/Ballerina.toml new file mode 100644 index 000000000000..c11db792ac82 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_return/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "function_invocation_inside_worker_with_return" +version = "0.1.0" +distribution = "2201.8.6" + +[build-options] +observabilityIncluded = true diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_return/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_return/Dependencies.toml new file mode 100644 index 000000000000..5e88ab6cb15e --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_return/Dependencies.toml @@ -0,0 +1,45 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.3" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + +[[package]] +org = "thushara_piyasekara" +name = "function_invocation_inside_worker_with_return" +version = "0.1.0" +dependencies = [ + {org = "ballerinai", name = "observe"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "function_invocation_inside_worker_with_return", moduleName = "function_invocation_inside_worker_with_return"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_return/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_return/main.bal new file mode 100644 index 000000000000..e83d302ddc31 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_return/main.bal @@ -0,0 +1,30 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function main() returns error? { + worker A returns string { + return foo(); + } + + string s = check wait A; +} + +function foo() returns string { + return "foo"; +} + +function bar() { +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_wait/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_wait/.devcontainer.json new file mode 100644 index 000000000000..8a0177271a49 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_wait/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.8.6", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_wait/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_wait/.gitignore new file mode 100644 index 000000000000..7512ebe2325f --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_wait/.gitignore @@ -0,0 +1,3 @@ +target +generated +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_wait/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_wait/Ballerina.toml new file mode 100644 index 000000000000..fd1fae4c4f33 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_wait/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "function_invocation_inside_worker_with_wait" +version = "0.1.0" +distribution = "2201.8.6" + +[build-options] +observabilityIncluded = true diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_wait/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_wait/Dependencies.toml new file mode 100644 index 000000000000..68b7ac1b4641 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_wait/Dependencies.toml @@ -0,0 +1,45 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.3" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + +[[package]] +org = "thushara_piyasekara" +name = "function_invocation_inside_worker_with_wait" +version = "0.1.0" +dependencies = [ + {org = "ballerinai", name = "observe"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "function_invocation_inside_worker_with_wait", moduleName = "function_invocation_inside_worker_with_wait"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_wait/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_wait/main.bal new file mode 100644 index 000000000000..9e408b6bdbaf --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_worker_with_wait/main.bal @@ -0,0 +1,38 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function main() { + worker A { + foo(); + } + wait A; + bar(); +} + +function foo() { +} + +function bar() { +} + +function baz() { + worker B { + qux(); + } +} + +function qux() { +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_workers/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_workers/.devcontainer.json new file mode 100644 index 000000000000..8a0177271a49 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_workers/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.8.6", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_workers/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_workers/.gitignore new file mode 100644 index 000000000000..7512ebe2325f --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_workers/.gitignore @@ -0,0 +1,3 @@ +target +generated +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_workers/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_workers/Ballerina.toml new file mode 100644 index 000000000000..e5b49f3eae6a --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_workers/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "function_invocation_inside_workers" +version = "0.1.0" +distribution = "2201.8.6" + +[build-options] +observabilityIncluded = true diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_workers/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_workers/Dependencies.toml new file mode 100644 index 000000000000..b6f703c645ef --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_workers/Dependencies.toml @@ -0,0 +1,45 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.3" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + +[[package]] +org = "thushara_piyasekara" +name = "function_invocation_inside_workers" +version = "0.1.0" +dependencies = [ + {org = "ballerinai", name = "observe"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "function_invocation_inside_workers", moduleName = "function_invocation_inside_workers"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_workers/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_workers/main.bal new file mode 100644 index 000000000000..907aaa54d9b1 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_invocation_inside_workers/main.bal @@ -0,0 +1,34 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function main() { + worker A { + foo(); + } + + worker B { + bar(); + } +} + +function foo() { +} + +function bar() { +} + +function baz() { +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_from_imported_module/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_from_imported_module/.devcontainer.json new file mode 100644 index 000000000000..8a0177271a49 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_from_imported_module/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.8.6", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_from_imported_module/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_from_imported_module/.gitignore new file mode 100644 index 000000000000..7512ebe2325f --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_from_imported_module/.gitignore @@ -0,0 +1,3 @@ +target +generated +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_from_imported_module/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_from_imported_module/Ballerina.toml new file mode 100644 index 000000000000..70d618f81658 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_from_imported_module/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "function_pointer_invocation_from_imported_module" +version = "0.1.0" +distribution = "2201.8.6" + +[build-options] +observabilityIncluded = true diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_from_imported_module/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_from_imported_module/Dependencies.toml new file mode 100644 index 000000000000..44051974c7d4 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_from_imported_module/Dependencies.toml @@ -0,0 +1,46 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.3" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + +[[package]] +org = "thushara_piyasekara" +name = "function_pointer_invocation_from_imported_module" +version = "0.1.0" +dependencies = [ + {org = "ballerinai", name = "observe"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "function_pointer_invocation_from_imported_module", moduleName = "function_pointer_invocation_from_imported_module"}, + {org = "thushara_piyasekara", packageName = "function_pointer_invocation_from_imported_module", moduleName = "function_pointer_invocation_from_imported_module.subModule_1"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_from_imported_module/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_from_imported_module/main.bal new file mode 100644 index 000000000000..7caa362466c2 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_from_imported_module/main.bal @@ -0,0 +1,20 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +import function_pointer_invocation_from_imported_module.subModule_1; + +public function main() { + _ = subModule_1:globalFp(22); +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_from_imported_module/modules/subModule_1/subModule_1.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_from_imported_module/modules/subModule_1/subModule_1.bal new file mode 100644 index 000000000000..c0d07bfa2519 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_from_imported_module/modules/subModule_1/subModule_1.bal @@ -0,0 +1,10 @@ +public function (int) returns string globalFp = foo; +public function (int) returns string globalFpUnused = bar; + +function foo(int num) returns string { + return "Hello, World!"; +} + +function bar(int num) returns string { + return "Hello, World!"; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inisde_different_bb/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inisde_different_bb/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inisde_different_bb/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inisde_different_bb/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inisde_different_bb/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inisde_different_bb/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inisde_different_bb/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inisde_different_bb/Ballerina.toml new file mode 100644 index 000000000000..702ab942957a --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inisde_different_bb/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "function_pointer_invocation_inisde_different_bb" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inisde_different_bb/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inisde_different_bb/Dependencies.toml new file mode 100644 index 000000000000..9d5b04af2955 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inisde_different_bb/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "function_pointer_invocation_inisde_different_bb" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "function_pointer_invocation_inisde_different_bb", moduleName = "function_pointer_invocation_inisde_different_bb"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inisde_different_bb/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inisde_different_bb/main.bal new file mode 100644 index 000000000000..ee83cbd3e36b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inisde_different_bb/main.bal @@ -0,0 +1,25 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function main() { + function () fp = foo; + if true { + fp(); + } +} + +function foo() { +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inside_lock/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inside_lock/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inside_lock/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inside_lock/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inside_lock/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inside_lock/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inside_lock/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inside_lock/Ballerina.toml new file mode 100644 index 000000000000..cd83454e1a8c --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inside_lock/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "function_pointer_invocation_inside_lock" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inside_lock/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inside_lock/Dependencies.toml new file mode 100644 index 000000000000..90b5ce78d226 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inside_lock/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "function_pointer_invocation_inside_lock" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "function_pointer_invocation_inside_lock", moduleName = "function_pointer_invocation_inside_lock"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inside_lock/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inside_lock/main.bal new file mode 100644 index 000000000000..139ebf8e08a5 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointer_invocation_inside_lock/main.bal @@ -0,0 +1,33 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function main() { + className obj = new className(); + obj.bar(); +} + +isolated class className { + isolated function foo() { + } + + isolated function bar() { + isolated function () bar; + bar = self.foo; + lock { + bar(); + } + } +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_as_arguments/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_as_arguments/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_as_arguments/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_as_arguments/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_as_arguments/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_as_arguments/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_as_arguments/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_as_arguments/Ballerina.toml new file mode 100644 index 000000000000..cc5cf6483dc9 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_as_arguments/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "function_pointers_as_arguments" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_as_arguments/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_as_arguments/Dependencies.toml new file mode 100644 index 000000000000..265e2af38f46 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_as_arguments/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "function_pointers_as_arguments" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "function_pointers_as_arguments", moduleName = "function_pointers_as_arguments"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_as_arguments/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_as_arguments/main.bal new file mode 100644 index 000000000000..fb5282ae1819 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_as_arguments/main.bal @@ -0,0 +1,46 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type ReturnsIntFunction function () returns int; + +ReturnsIntFunction globalFP1 = foo; +ReturnsIntFunction globalFP2 = baz; +ReturnsIntFunction globalFPUnused = bar; + +public function main() { + // Passing the fp directly + fpEater(globalFP1); + // Passing the fp indirectly + ReturnsIntFunction localFP1 = globalFP2; + ReturnsIntFunction localFP2 = localFP1; + fpEater(localFP2); +} + +public function fpEater(ReturnsIntFunction fp) { + _ = fp(); +} + +public function foo() returns int { + return 2; +} + +public function bar() returns int { + return 2; +} + +public function baz() returns int { + return 2; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_global_assignment/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_global_assignment/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_global_assignment/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_global_assignment/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_global_assignment/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_global_assignment/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_global_assignment/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_global_assignment/Ballerina.toml new file mode 100644 index 000000000000..90d13b532d2f --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_global_assignment/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "function_pointers_global_assignment" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_global_assignment/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_global_assignment/Dependencies.toml new file mode 100644 index 000000000000..263689e18b64 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_global_assignment/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "function_pointers_global_assignment" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "function_pointers_global_assignment", moduleName = "function_pointers_global_assignment"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_global_assignment/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_global_assignment/main.bal new file mode 100644 index 000000000000..f2689632377a --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_global_assignment/main.bal @@ -0,0 +1,32 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type ReturnsIntFunction function () returns int; + +ReturnsIntFunction globalFP = foo; +ReturnsIntFunction globalFPUnused = bar; + +public function main() { + _ = globalFP(); +} + +public function foo() returns int { + return 2; +} + +public function bar() returns int { + return 2; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_array/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_array/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_array/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_array/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_array/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_array/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_array/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_array/Ballerina.toml new file mode 100644 index 000000000000..36279aee8313 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_array/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "function_pointers_inside_array" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_array/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_array/Dependencies.toml new file mode 100644 index 000000000000..8d4f37cc304c --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_array/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "function_pointers_inside_array" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "function_pointers_inside_array", moduleName = "function_pointers_inside_array"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_array/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_array/main.bal new file mode 100644 index 000000000000..e5c7954b62e0 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_array/main.bal @@ -0,0 +1,32 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type ReturnsIntFunction function () returns int; + +ReturnsIntFunction[] globalFPArr = [foo, bar]; + +public function main() { + ReturnsIntFunction localFP = globalFPArr[1]; + _ = localFP(); +} + +public function foo() returns int { + return 2; +} + +public function bar() returns int { + return 2; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_lock/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_lock/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_lock/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_lock/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_lock/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_lock/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_lock/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_lock/Ballerina.toml new file mode 100644 index 000000000000..4445be0f7974 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_lock/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "function_pointers_inside_lock" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_lock/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_lock/Dependencies.toml new file mode 100644 index 000000000000..8ff6daba639e --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_lock/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "function_pointers_inside_lock" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "function_pointers_inside_lock", moduleName = "function_pointers_inside_lock"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_lock/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_lock/main.bal new file mode 100644 index 000000000000..c6f3cebf8f72 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_lock/main.bal @@ -0,0 +1,33 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function main() { + className obj = new className(); + obj.execute2(); +} + +isolated class className { + isolated function foo() { + } + + isolated function execute2() { + isolated function () bar; + lock { + bar = self.foo; + } + bar(); + } +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_record/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_record/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_record/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_record/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_record/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_record/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_record/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_record/Ballerina.toml new file mode 100644 index 000000000000..fa283f824107 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_record/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "function_pointers_inside_record" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_record/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_record/Dependencies.toml new file mode 100644 index 000000000000..109bc133e420 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_record/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "function_pointers_inside_record" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "function_pointers_inside_record", moduleName = "function_pointers_inside_record"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_record/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_record/main.bal new file mode 100644 index 000000000000..9158750c0f68 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_inside_record/main.bal @@ -0,0 +1,37 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type ReturnsIntFunction function () returns int; + +type FPRecord record { + ReturnsIntFunction fpField; +}; + +public function main() { + FPRecord rec = { + fpField: foo + }; + ReturnsIntFunction localFP = rec.fpField; + _ = localFP(); +} + +public function foo() returns int { + return 2; +} + +public function bar() returns int { + return 2; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_invocation_inside_record/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_invocation_inside_record/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_invocation_inside_record/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_invocation_inside_record/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_invocation_inside_record/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_invocation_inside_record/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_invocation_inside_record/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_invocation_inside_record/Ballerina.toml new file mode 100644 index 000000000000..c9c3b6565c79 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_invocation_inside_record/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "function_pointers_invocation_inside_record" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_invocation_inside_record/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_invocation_inside_record/Dependencies.toml new file mode 100644 index 000000000000..56e236cbbb22 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_invocation_inside_record/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "function_pointers_invocation_inside_record" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "function_pointers_invocation_inside_record", moduleName = "function_pointers_invocation_inside_record"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_invocation_inside_record/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_invocation_inside_record/main.bal new file mode 100644 index 000000000000..241773261ac2 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_invocation_inside_record/main.bal @@ -0,0 +1,38 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type ReturnsIntFunction function () returns string; + +ReturnsIntFunction globalFP = foo; +ReturnsIntFunction globalFPUnused = bar; + +type RecA record { + string name; +}; + +public function main() { + RecA rec = { + name: globalFP() + }; +} + +function foo() returns string { + return "Im used"; +} + +function bar() returns string { + return "Im unused"; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_local_assignment/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_local_assignment/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_local_assignment/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_local_assignment/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_local_assignment/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_local_assignment/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_local_assignment/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_local_assignment/Ballerina.toml new file mode 100644 index 000000000000..4a834d7bed5b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_local_assignment/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "function_pointers_local_assignment" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_local_assignment/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_local_assignment/Dependencies.toml new file mode 100644 index 000000000000..2c76efc06f5c --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_local_assignment/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "function_pointers_local_assignment" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "function_pointers_local_assignment", moduleName = "function_pointers_local_assignment"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_local_assignment/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_local_assignment/main.bal new file mode 100644 index 000000000000..765b9a8e5d3d --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_local_assignment/main.bal @@ -0,0 +1,30 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type ReturnsIntFunction function () returns int; + +public function main() { + ReturnsIntFunction localFP = foo; + _ = localFP(); +} + +public function foo() returns int { + return 2; +} + +public function fooUnused() returns int { + return 2; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_transitive_assignment/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_transitive_assignment/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_transitive_assignment/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_transitive_assignment/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_transitive_assignment/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_transitive_assignment/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_transitive_assignment/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_transitive_assignment/Ballerina.toml new file mode 100644 index 000000000000..fa4b60f4b6c8 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_transitive_assignment/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "function_pointers_transitive_assignment" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_transitive_assignment/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_transitive_assignment/Dependencies.toml new file mode 100644 index 000000000000..a0ca3a05af48 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_transitive_assignment/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "function_pointers_transitive_assignment" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "function_pointers_transitive_assignment", moduleName = "function_pointers_transitive_assignment"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_transitive_assignment/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_transitive_assignment/main.bal new file mode 100644 index 000000000000..0e72a0e5d994 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/function_pointers_transitive_assignment/main.bal @@ -0,0 +1,34 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type ReturnsIntFunction function () returns int; + +ReturnsIntFunction globalFP = foo; +ReturnsIntFunction globalFPUnused = bar; + +public function main() { + ReturnsIntFunction localFP1 = globalFP; + ReturnsIntFunction localFP2 = localFP1; + _ = localFP2(); +} + +public function foo() returns int { + return 2; +} + +public function bar() returns int { + return 2; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/imported_closure_invocation/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/imported_closure_invocation/.devcontainer.json new file mode 100644 index 000000000000..8a0177271a49 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/imported_closure_invocation/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.8.6", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/imported_closure_invocation/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/imported_closure_invocation/.gitignore new file mode 100644 index 000000000000..7512ebe2325f --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/imported_closure_invocation/.gitignore @@ -0,0 +1,3 @@ +target +generated +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/imported_closure_invocation/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/imported_closure_invocation/Ballerina.toml new file mode 100644 index 000000000000..61e072dd6f5b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/imported_closure_invocation/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "imported_closure_invocation" +version = "0.1.0" +distribution = "2201.8.6" + +[build-options] +observabilityIncluded = true diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/imported_closure_invocation/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/imported_closure_invocation/Dependencies.toml new file mode 100644 index 000000000000..90df12296de2 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/imported_closure_invocation/Dependencies.toml @@ -0,0 +1,46 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.3" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + +[[package]] +org = "thushara_piyasekara" +name = "imported_closure_invocation" +version = "0.1.0" +dependencies = [ + {org = "ballerinai", name = "observe"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "imported_closure_invocation", moduleName = "imported_closure_invocation"}, + {org = "thushara_piyasekara", packageName = "imported_closure_invocation", moduleName = "imported_closure_invocation.subModule"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/imported_closure_invocation/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/imported_closure_invocation/main.bal new file mode 100644 index 000000000000..740f010591d5 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/imported_closure_invocation/main.bal @@ -0,0 +1,20 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +import imported_closure_invocation.subModule; + +public function main() { + function () returns string closureFunc = subModule:closureReturn(); +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/imported_closure_invocation/modules/subModule/subModule.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/imported_closure_invocation/modules/subModule/subModule.bal new file mode 100644 index 000000000000..97b16a0b068a --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/imported_closure_invocation/modules/subModule/subModule.bal @@ -0,0 +1,34 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function closureReturn() returns (function () returns string) { + var closureUsed = function() returns string { + return foo(); + }; + + var closureUnused = function() returns string { + return bar(); + }; + return closureUsed; +} + +function foo() returns string { + return "Foo"; +} + +function bar() returns string { + return "Bar"; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_1/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_1/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_1/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_1/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_1/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_1/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_1/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_1/Ballerina.toml new file mode 100644 index 000000000000..1c9d91ac2a66 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_1/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "tranistive_functions_1" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_1/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_1/Dependencies.toml new file mode 100644 index 000000000000..a631040a9e43 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_1/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "tranistive_functions_1" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "tranistive_functions_1", moduleName = "tranistive_functions_1"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_1/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_1/main.bal new file mode 100644 index 000000000000..baf828231de3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_1/main.bal @@ -0,0 +1,31 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function main() { + foo(); +} + +function foo() { + bar(); +} + +function bar() { + +} + +function baz() { + +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_2/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_2/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_2/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_2/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_2/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_2/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_2/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_2/Ballerina.toml new file mode 100644 index 000000000000..05b40db2583a --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_2/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "thushara_piyasekara" +name = "tranistive_functions_2" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" \ No newline at end of file diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_2/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_2/Dependencies.toml new file mode 100644 index 000000000000..df402c6c9da3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_2/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "tranistive_functions_2" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "tranistive_functions_2", moduleName = "tranistive_functions_2"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_2/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_2/main.bal new file mode 100644 index 000000000000..ef3299af0b5d --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/tranistive_functions_2/main.bal @@ -0,0 +1,31 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function main() { + foo(bar()); +} + +function foo(int a) { + +} + +function bar() returns int { + return 1; +} + +function baz() { + +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_function_in_imported_module/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_function_in_imported_module/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_function_in_imported_module/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_function_in_imported_module/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_function_in_imported_module/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_function_in_imported_module/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_function_in_imported_module/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_function_in_imported_module/Ballerina.toml new file mode 100644 index 000000000000..010a4623101d --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_function_in_imported_module/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "thushara_piyasekara" +name = "transitive_function_in_imported_module" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_function_in_imported_module/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_function_in_imported_module/Dependencies.toml new file mode 100644 index 000000000000..b81953d3b161 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_function_in_imported_module/Dependencies.toml @@ -0,0 +1,18 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "transitive_function_in_imported_module" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "transitive_function_in_imported_module", moduleName = "transitive_function_in_imported_module"}, + {org = "thushara_piyasekara", packageName = "transitive_function_in_imported_module", moduleName = "transitive_function_in_imported_module.subModule"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_function_in_imported_module/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_function_in_imported_module/main.bal new file mode 100644 index 000000000000..2880b6208261 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_function_in_imported_module/main.bal @@ -0,0 +1,20 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +import transitive_function_in_imported_module.subModule; + +public function main() { + subModule:subModuleFunction(); +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_function_in_imported_module/modules/subModule/subModule.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_function_in_imported_module/modules/subModule/subModule.bal new file mode 100644 index 000000000000..465c6311a2ba --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_function_in_imported_module/modules/subModule/subModule.bal @@ -0,0 +1,27 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function subModuleFunction() { + foo(); +} + +function foo() { + +} + +function bar() { + +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_module_imports/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_module_imports/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_module_imports/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_module_imports/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_module_imports/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_module_imports/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_module_imports/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_module_imports/Ballerina.toml new file mode 100644 index 000000000000..3642e01534cd --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_module_imports/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "thushara_piyasekara" +name = "transitive_module_imports" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_module_imports/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_module_imports/Dependencies.toml new file mode 100644 index 000000000000..b4b351a1c15e --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_module_imports/Dependencies.toml @@ -0,0 +1,19 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "transitive_module_imports" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "transitive_module_imports", moduleName = "transitive_module_imports"}, + {org = "thushara_piyasekara", packageName = "transitive_module_imports", moduleName = "transitive_module_imports.subModule_1"}, + {org = "thushara_piyasekara", packageName = "transitive_module_imports", moduleName = "transitive_module_imports.subModule_2"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_module_imports/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_module_imports/main.bal new file mode 100644 index 000000000000..afabc5d4d3ca --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_module_imports/main.bal @@ -0,0 +1,20 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +import transitive_module_imports.subModule_1; + +public function main() { + subModule_1:subModuleFunction(); +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_module_imports/modules/subModule_1/subModule_1.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_module_imports/modules/subModule_1/subModule_1.bal new file mode 100644 index 000000000000..62b83037e383 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_module_imports/modules/subModule_1/subModule_1.bal @@ -0,0 +1,21 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +import transitive_module_imports.subModule_2; + +public function subModuleFunction() { + subModule_2:foo(); +} + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_module_imports/modules/subModule_2/subModule_2.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_module_imports/modules/subModule_2/subModule_2.bal new file mode 100644 index 000000000000..749ab00c5945 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/transitive_module_imports/modules/subModule_2/subModule_2.bal @@ -0,0 +1,21 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +public function foo() { +} + +function bar() { + +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/unused_anonymous_function/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/unused_anonymous_function/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/unused_anonymous_function/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/unused_anonymous_function/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/unused_anonymous_function/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/unused_anonymous_function/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/unused_anonymous_function/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/unused_anonymous_function/Ballerina.toml new file mode 100644 index 000000000000..fbf2636b4c7d --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/unused_anonymous_function/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "unused_anonymous_function" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/unused_anonymous_function/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/unused_anonymous_function/Dependencies.toml new file mode 100644 index 000000000000..f7cf4f26bd13 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/unused_anonymous_function/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "arrow_functions_2" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "arrow_functions_2", moduleName = "arrow_functions_2"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/unused_anonymous_function/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/unused_anonymous_function/main.bal new file mode 100644 index 000000000000..7c48e598e5d5 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/unused_anonymous_function/main.bal @@ -0,0 +1,40 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function main() { + _ = foo(20); + _ = bar(); + _ = baz(); +} + +function foo(int value) returns int { + function (int) returns int increment_1 = x => x + 1; + function (int, int) returns int add_1 = (x, y) => x + y; + return increment_1(value); +} + +function bar() returns (function (int) returns int) { + function (int) returns int increment_2 = x => x + 1; + function (int, int) returns int add_2 = (x, y) => x + y; + return increment_2; +} + +function baz() returns (function (int, int) returns int) { + function (int) returns int increment_3 = x => x + 1; + function (int) returns int increment_4 = x => x + 1; + function (int, int) returns int add_3 = (x, y) => increment_3(x) - 1 + y; + return add_3; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/vanilla_functions/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/vanilla_functions/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/vanilla_functions/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/vanilla_functions/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/vanilla_functions/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/vanilla_functions/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/vanilla_functions/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/vanilla_functions/Ballerina.toml new file mode 100644 index 000000000000..eaa94216eaf7 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/vanilla_functions/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "vanilla_functions" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/vanilla_functions/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/vanilla_functions/Dependencies.toml new file mode 100644 index 000000000000..c50d96e263be --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/vanilla_functions/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "vanilla_functions" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "vanilla_functions", moduleName = "vanilla_functions"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/vanilla_functions/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/vanilla_functions/main.bal new file mode 100644 index 000000000000..560b8a612815 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/vanilla_functions/main.bal @@ -0,0 +1,27 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function main() { + foo(); +} + +function foo() { + +} + +function bar() { + +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/worker_derived_lambda_functions/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/worker_derived_lambda_functions/.devcontainer.json new file mode 100644 index 000000000000..8a0177271a49 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/worker_derived_lambda_functions/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.8.6", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/worker_derived_lambda_functions/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/worker_derived_lambda_functions/.gitignore new file mode 100644 index 000000000000..7512ebe2325f --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/worker_derived_lambda_functions/.gitignore @@ -0,0 +1,3 @@ +target +generated +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/worker_derived_lambda_functions/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/worker_derived_lambda_functions/Ballerina.toml new file mode 100644 index 000000000000..83ee5be9785c --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/worker_derived_lambda_functions/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "worker_derived_lambda_functions" +version = "0.1.0" +distribution = "2201.8.6" + +[build-options] +observabilityIncluded = true diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/worker_derived_lambda_functions/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/worker_derived_lambda_functions/Dependencies.toml new file mode 100644 index 000000000000..711388cc4832 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/worker_derived_lambda_functions/Dependencies.toml @@ -0,0 +1,45 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.3" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + +[[package]] +org = "thushara_piyasekara" +name = "worker_derived_lambda_functions" +version = "0.1.0" +dependencies = [ + {org = "ballerinai", name = "observe"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "worker_derived_lambda_functions", moduleName = "worker_derived_lambda_functions"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/worker_derived_lambda_functions/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/worker_derived_lambda_functions/main.bal new file mode 100644 index 000000000000..186daa26a1c5 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/Functions/worker_derived_lambda_functions/main.bal @@ -0,0 +1,33 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function main() { + worker A { + foo(); + } +} + +function foo() { +} + +function bar() { + worker B { + baz(); + } +} + +function baz() { +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/class_inclusion/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/class_inclusion/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/class_inclusion/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/class_inclusion/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/class_inclusion/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/class_inclusion/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/class_inclusion/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/class_inclusion/Ballerina.toml new file mode 100644 index 000000000000..b2f311a1c12a --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/class_inclusion/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "class_inclusion" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/class_inclusion/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/class_inclusion/Dependencies.toml new file mode 100644 index 000000000000..bb05af7241b2 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/class_inclusion/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "class_inclusion" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "class_inclusion", moduleName = "class_inclusion"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/class_inclusion/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/class_inclusion/main.bal new file mode 100644 index 000000000000..93fb748f7468 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/class_inclusion/main.bal @@ -0,0 +1,31 @@ + +type Cloneable object { + function clone() returns Cloneable; +}; + +type Person object { + *Cloneable; + string name; + + function getName() returns string; +}; + +class Engineer { + *Person; + + function init(string name) { + self.name = name; + } + + function clone() returns Engineer { + return new (self.name); + } + + function getName() returns string { + return self.name; + } +} + +public function main() { + Engineer e1 = new ("Alice"); +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/client_class_usage/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/client_class_usage/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/client_class_usage/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/client_class_usage/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/client_class_usage/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/client_class_usage/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/client_class_usage/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/client_class_usage/Ballerina.toml new file mode 100644 index 000000000000..7e24c479099a --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/client_class_usage/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "client_class_usage" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + +[build-options] +observabilityIncluded = true diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/client_class_usage/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/client_class_usage/Dependencies.toml new file mode 100644 index 000000000000..e9f1c5278b7c --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/client_class_usage/Dependencies.toml @@ -0,0 +1,45 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.3" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + +[[package]] +org = "thushara_piyasekara" +name = "client_class_usage" +version = "0.1.0" +dependencies = [ + {org = "ballerinai", name = "observe"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "client_class_usage", moduleName = "client_class_usage"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/client_class_usage/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/client_class_usage/main.bal new file mode 100644 index 000000000000..d483a04593bc --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/client_class_usage/main.bal @@ -0,0 +1,37 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +isolated client class ClientUsed { + function init(string url) returns error? { + } + + resource function get [string path]() returns int|error { + return 0; + } +} + +isolated client class ClientUnused { + function init(string url) returns error? { + } + + resource function get [string path]() returns int|error { + return 0; + } +} + +public function main() returns error? { + ClientUsed client_1 = check new (""); +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_value_initialization/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_value_initialization/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_value_initialization/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_value_initialization/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_value_initialization/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_value_initialization/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_value_initialization/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_value_initialization/Ballerina.toml new file mode 100644 index 000000000000..f65b3cd3cdab --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_value_initialization/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "global_value_initialization" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_value_initialization/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_value_initialization/Dependencies.toml new file mode 100644 index 000000000000..277e65e7a4dc --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_value_initialization/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "global_value_initialization" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "global_value_initialization", moduleName = "global_value_initialization"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_value_initialization/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_value_initialization/main.bal new file mode 100644 index 000000000000..d1d9578a5d73 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_value_initialization/main.bal @@ -0,0 +1,24 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type A int|string; + +type B boolean; + +A a = "im used"; + +public function main() { +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_var_from_imported_module/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_var_from_imported_module/.devcontainer.json new file mode 100644 index 000000000000..e5f0b2be80d7 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_var_from_imported_module/.devcontainer.json @@ -0,0 +1,8 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.10.0-SNAPSHOT", + "customizations": { + "vscode": { + "extensions": ["WSO2.ballerina"] + } + } +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_var_from_imported_module/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_var_from_imported_module/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_var_from_imported_module/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_var_from_imported_module/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_var_from_imported_module/Ballerina.toml new file mode 100644 index 000000000000..954c90da716f --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_var_from_imported_module/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "global_var_from_imported_module" +version = "0.1.0" +distribution = "2201.10.0-SNAPSHOT" + +[build-options] +observabilityIncluded = true diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_var_from_imported_module/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_var_from_imported_module/Dependencies.toml new file mode 100644 index 000000000000..0074054b7098 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_var_from_imported_module/Dependencies.toml @@ -0,0 +1,18 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.10.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "global_var_from_imported_module" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "global_var_from_imported_module", moduleName = "global_var_from_imported_module"}, + {org = "thushara_piyasekara", packageName = "global_var_from_imported_module", moduleName = "global_var_from_imported_module.subModule_1"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_var_from_imported_module/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_var_from_imported_module/main.bal new file mode 100644 index 000000000000..27f33b084498 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_var_from_imported_module/main.bal @@ -0,0 +1,5 @@ +import global_var_from_imported_module.subModule_1; + +public function main() { + string b = subModule_1:hello; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_var_from_imported_module/modules/subModule_1/subModule_1.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_var_from_imported_module/modules/subModule_1/subModule_1.bal new file mode 100644 index 000000000000..e669e894965f --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/global_var_from_imported_module/modules/subModule_1/subModule_1.bal @@ -0,0 +1 @@ +public string hello = "hello"; diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/intersection_types/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/intersection_types/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/intersection_types/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/intersection_types/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/intersection_types/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/intersection_types/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/intersection_types/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/intersection_types/Ballerina.toml new file mode 100644 index 000000000000..2bfc75936043 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/intersection_types/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "intersection_types" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/intersection_types/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/intersection_types/Dependencies.toml new file mode 100644 index 000000000000..b2dd8ba2c218 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/intersection_types/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "intersection_types" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "intersection_types", moduleName = "intersection_types"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/intersection_types/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/intersection_types/main.bal new file mode 100644 index 000000000000..1d3f425db2aa --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/intersection_types/main.bal @@ -0,0 +1,25 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type XErr distinct error; + +type YErr distinct error; + +type BigErr XErr & YErr; + +public function main() { + BigErr err = error(""); +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/parameters_via_record_field_mapping/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/parameters_via_record_field_mapping/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/parameters_via_record_field_mapping/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/parameters_via_record_field_mapping/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/parameters_via_record_field_mapping/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/parameters_via_record_field_mapping/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/parameters_via_record_field_mapping/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/parameters_via_record_field_mapping/Ballerina.toml new file mode 100644 index 000000000000..6ae0d47ccf4d --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/parameters_via_record_field_mapping/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "parameters_via_record_field_mapping" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/parameters_via_record_field_mapping/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/parameters_via_record_field_mapping/Dependencies.toml new file mode 100644 index 000000000000..3434bab815f8 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/parameters_via_record_field_mapping/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "parameters_via_record_field_mapping" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "parameters_via_record_field_mapping", moduleName = "parameters_via_record_field_mapping"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/parameters_via_record_field_mapping/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/parameters_via_record_field_mapping/main.bal new file mode 100644 index 000000000000..680411ea1cdf --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/parameters_via_record_field_mapping/main.bal @@ -0,0 +1,39 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type RecA record { + B fieldB; + C fieldC; +}; + +type B boolean|int; + +type C string; + +type D decimal; + +type RecE record { + int fieldInt; + D fieldD; + +}; + +public function main() { + foo(fieldB = true, fieldC = "hello"); +} + +function foo(*RecA rec) { +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/query_expression_type_usage/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/query_expression_type_usage/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/query_expression_type_usage/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/query_expression_type_usage/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/query_expression_type_usage/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/query_expression_type_usage/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/query_expression_type_usage/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/query_expression_type_usage/Ballerina.toml new file mode 100644 index 000000000000..ab7aa7dc803f --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/query_expression_type_usage/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "query_expression_type_usage" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/query_expression_type_usage/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/query_expression_type_usage/Dependencies.toml new file mode 100644 index 000000000000..7364d54dcec1 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/query_expression_type_usage/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "query_expression_type_usage" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "query_expression_type_usage", moduleName = "query_expression_type_usage"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/query_expression_type_usage/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/query_expression_type_usage/main.bal new file mode 100644 index 000000000000..22142859c70c --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/query_expression_type_usage/main.bal @@ -0,0 +1,29 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type A int|string; + +type B boolean; + +type C float; + +public function main() { + int[] nums = [1, 2, 3, 4]; + + int[] queryResult = from A i in nums + let B j = true + select i * 2; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_dependency/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_dependency/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_dependency/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_dependency/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_dependency/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_dependency/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_dependency/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_dependency/Ballerina.toml new file mode 100644 index 000000000000..e4d35663e0df --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_dependency/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "record_dependency" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_dependency/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_dependency/Dependencies.toml new file mode 100644 index 000000000000..0148667c9151 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_dependency/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "record_dependency" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "record_dependency", moduleName = "record_dependency"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_dependency/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_dependency/main.bal new file mode 100644 index 000000000000..248e714073d7 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_dependency/main.bal @@ -0,0 +1,35 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type RecA record { + B fieldB; +}; + +type B boolean|C; + +type C string; + +type RecD record { + E fieldE; +}; + +type E boolean; + +public function main() { + RecA recordA = { + fieldB: "I am used" + }; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_field_type_from_imported_module/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_field_type_from_imported_module/.devcontainer.json new file mode 100644 index 000000000000..8a0177271a49 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_field_type_from_imported_module/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.8.6", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_field_type_from_imported_module/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_field_type_from_imported_module/.gitignore new file mode 100644 index 000000000000..7512ebe2325f --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_field_type_from_imported_module/.gitignore @@ -0,0 +1,3 @@ +target +generated +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_field_type_from_imported_module/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_field_type_from_imported_module/Ballerina.toml new file mode 100644 index 000000000000..ecf6d90c91cf --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_field_type_from_imported_module/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "record_field_type_from_imported_module" +version = "0.1.0" +distribution = "2201.8.6" + +[build-options] +observabilityIncluded = true diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_field_type_from_imported_module/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_field_type_from_imported_module/Dependencies.toml new file mode 100644 index 000000000000..a9c2a94a5e20 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_field_type_from_imported_module/Dependencies.toml @@ -0,0 +1,46 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.3" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + +[[package]] +org = "thushara_piyasekara" +name = "record_field_type_from_imported_module" +version = "0.1.0" +dependencies = [ + {org = "ballerinai", name = "observe"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "record_field_type_from_imported_module", moduleName = "record_field_type_from_imported_module"}, + {org = "thushara_piyasekara", packageName = "record_field_type_from_imported_module", moduleName = "record_field_type_from_imported_module.subModule_1"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_field_type_from_imported_module/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_field_type_from_imported_module/main.bal new file mode 100644 index 000000000000..6b57cd6f29e4 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_field_type_from_imported_module/main.bal @@ -0,0 +1,15 @@ +import record_field_type_from_imported_module.subModule_1; + +type RecUsed record { + subModule_1:Baz x; +}; + +type RecUnused record { + subModule_1:Corge x; +}; + +public function main() { + RecUsed rec = { + x: 1 + }; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_field_type_from_imported_module/modules/subModule_1/subModule_1.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_field_type_from_imported_module/modules/subModule_1/subModule_1.bal new file mode 100644 index 000000000000..f080ac28f1ee --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_field_type_from_imported_module/modules/subModule_1/subModule_1.bal @@ -0,0 +1,7 @@ +public type Baz decimal|Foo; + +public type Foo int|string; + +public type Bar boolean?; + +public type Corge xml; diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_inclusion/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_inclusion/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_inclusion/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_inclusion/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_inclusion/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_inclusion/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_inclusion/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_inclusion/Ballerina.toml new file mode 100644 index 000000000000..50b51a7d627b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_inclusion/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "record_inclusion" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_inclusion/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_inclusion/Dependencies.toml new file mode 100644 index 000000000000..42ca3110eb95 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_inclusion/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "record_inclusion" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "record_inclusion", moduleName = "record_inclusion"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_inclusion/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_inclusion/main.bal new file mode 100644 index 000000000000..28102c67e253 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/record_inclusion/main.bal @@ -0,0 +1,35 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type RecA record { + B fieldB; + C fieldC; +}; + +type B boolean|int; + +type C string; + +type D decimal; + +type RecE record { + *RecA; + int fieldInt; +}; + +public function main() { + RecE recE = {fieldB: true, fieldC: "hello", fieldInt: 5}; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/transitive_types/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/transitive_types/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/transitive_types/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/transitive_types/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/transitive_types/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/transitive_types/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/transitive_types/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/transitive_types/Ballerina.toml new file mode 100644 index 000000000000..a0097df28f02 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/transitive_types/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "transitive_types" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/transitive_types/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/transitive_types/Dependencies.toml new file mode 100644 index 000000000000..9f22afe2b92d --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/transitive_types/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "transitive_types" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "transitive_types", moduleName = "transitive_types"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/transitive_types/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/transitive_types/main.bal new file mode 100644 index 000000000000..4ea4026911ea --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/transitive_types/main.bal @@ -0,0 +1,25 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type A int|string; + +type B A|boolean; + +type C decimal; + +public function main() { + B a = "im used"; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_cast/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_cast/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_cast/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_cast/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_cast/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_cast/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_cast/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_cast/Ballerina.toml new file mode 100644 index 000000000000..8263d35f76e6 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_cast/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "type_cast" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_cast/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_cast/Dependencies.toml new file mode 100644 index 000000000000..92c99e87cb52 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_cast/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "type_cast" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "type_cast", moduleName = "type_cast"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_cast/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_cast/main.bal new file mode 100644 index 000000000000..d5c211b6c9d1 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_cast/main.bal @@ -0,0 +1,26 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type A string; + +type B int|string; + +type C int|string|boolean; + +public function main() { + A a = "Im A"; + C c = a; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_def_reference_inisde_closure/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_def_reference_inisde_closure/.devcontainer.json new file mode 100644 index 000000000000..8a0177271a49 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_def_reference_inisde_closure/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.8.6", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_def_reference_inisde_closure/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_def_reference_inisde_closure/.gitignore new file mode 100644 index 000000000000..7512ebe2325f --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_def_reference_inisde_closure/.gitignore @@ -0,0 +1,3 @@ +target +generated +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_def_reference_inisde_closure/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_def_reference_inisde_closure/Ballerina.toml new file mode 100644 index 000000000000..ceed2b7b32f2 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_def_reference_inisde_closure/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "type_def_reference_inisde_closure" +version = "0.1.0" +distribution = "2201.8.6" + +[build-options] +observabilityIncluded = true diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_def_reference_inisde_closure/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_def_reference_inisde_closure/Dependencies.toml new file mode 100644 index 000000000000..1d447ffca11b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_def_reference_inisde_closure/Dependencies.toml @@ -0,0 +1,45 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.3" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + +[[package]] +org = "thushara_piyasekara" +name = "type_def_reference_inisde_closure" +version = "0.1.0" +dependencies = [ + {org = "ballerinai", name = "observe"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "type_def_reference_inisde_closure", moduleName = "type_def_reference_inisde_closure"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_def_reference_inisde_closure/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_def_reference_inisde_closure/main.bal new file mode 100644 index 000000000000..d1b510fbb165 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_def_reference_inisde_closure/main.bal @@ -0,0 +1,26 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type CustomType int|float|string; + +public function main() { + var addName = function(string value) returns string { + CustomType name = "John"; + return "hello"; + }; + + _ = addName("John"); +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_from_imported_module/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_from_imported_module/.devcontainer.json new file mode 100644 index 000000000000..8a0177271a49 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_from_imported_module/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.8.6", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_from_imported_module/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_from_imported_module/.gitignore new file mode 100644 index 000000000000..7512ebe2325f --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_from_imported_module/.gitignore @@ -0,0 +1,3 @@ +target +generated +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_from_imported_module/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_from_imported_module/Ballerina.toml new file mode 100644 index 000000000000..e7baa075b477 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_from_imported_module/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "type_definition_from_imported_module" +version = "0.1.0" +distribution = "2201.8.6" + +[build-options] +observabilityIncluded = true diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_from_imported_module/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_from_imported_module/Dependencies.toml new file mode 100644 index 000000000000..843de4d70d28 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_from_imported_module/Dependencies.toml @@ -0,0 +1,46 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.3" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + +[[package]] +org = "thushara_piyasekara" +name = "type_definition_from_imported_module" +version = "0.1.0" +dependencies = [ + {org = "ballerinai", name = "observe"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "type_definition_from_imported_module", moduleName = "type_definition_from_imported_module"}, + {org = "thushara_piyasekara", packageName = "type_definition_from_imported_module", moduleName = "type_definition_from_imported_module.subModule_1"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_from_imported_module/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_from_imported_module/main.bal new file mode 100644 index 000000000000..f7a401cdf267 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_from_imported_module/main.bal @@ -0,0 +1,5 @@ +import type_definition_from_imported_module.subModule_1; + +public function main() { + subModule_1:Baz baz = 12; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_from_imported_module/modules/subModule_1/subModule_1.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_from_imported_module/modules/subModule_1/subModule_1.bal new file mode 100644 index 000000000000..de3456d531c5 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_from_imported_module/modules/subModule_1/subModule_1.bal @@ -0,0 +1,6 @@ +public type Baz decimal|Foo; + +public type Foo int|string; + +public type Bar boolean?; + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_listener/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_listener/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_listener/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_listener/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_listener/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_listener/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_listener/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_listener/Ballerina.toml new file mode 100644 index 000000000000..c8dc41157dc2 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_listener/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "type_definition_inside_listener" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + +[build-options] +observabilityIncluded = true diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_listener/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_listener/Dependencies.toml new file mode 100644 index 000000000000..8102848df421 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_listener/Dependencies.toml @@ -0,0 +1,45 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.3" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + +[[package]] +org = "thushara_piyasekara" +name = "type_definition_inside_listener" +version = "0.1.0" +dependencies = [ + {org = "ballerinai", name = "observe"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "type_definition_inside_listener", moduleName = "type_definition_inside_listener"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_listener/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_listener/main.bal new file mode 100644 index 000000000000..13cda105c0fb --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_listener/main.bal @@ -0,0 +1,48 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public isolated class Listener { + private int port; + public function 'start() returns error? { + } + + public function gracefulStop() returns error? { + } + + public function immediateStop() returns error? { + } + + public function detach(service object {} s) returns error? { + } + + public function attach(service object {} s, string[]? name = ()) returns error? { + } + + public function init(int port) { + self.port = port; + } +} + +type UsedTypeDef int|string; + +type UnusedTypeDef int|string; + +service / on new Listener(1000) { + UsedTypeDef customValue = "Hello"; + resource function get albums() returns string|int|error { + return self.customValue; + } +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_body/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_body/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_body/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_body/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_body/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_body/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_body/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_body/Ballerina.toml new file mode 100644 index 000000000000..1aa625d57ab7 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_body/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "type_definition_inside_remote_function_body" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + +[build-options] +observabilityIncluded = true diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_body/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_body/Dependencies.toml new file mode 100644 index 000000000000..3d763acae6df --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_body/Dependencies.toml @@ -0,0 +1,45 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.3" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + +[[package]] +org = "thushara_piyasekara" +name = "type_definition_inside_remote_function_body" +version = "0.1.0" +dependencies = [ + {org = "ballerinai", name = "observe"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "type_definition_inside_remote_function_body", moduleName = "type_definition_inside_remote_function_body"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_body/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_body/main.bal new file mode 100644 index 000000000000..ef5335863b88 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_body/main.bal @@ -0,0 +1,48 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public isolated class Listener { + private int port; + public function 'start() returns error? { + } + + public function gracefulStop() returns error? { + } + + public function immediateStop() returns error? { + } + + public function detach(service object {} s) returns error? { + } + + public function attach(service object {} s, string[]? name = ()) returns error? { + } + + public function init(int port) { + self.port = port; + } +} + +type UsedTypeDef int|string; + +type UnusedTypeDef int|string; + +service / on new Listener(1000) { + remote function albums() returns string|int|error { + UsedTypeDef customValue = "Hello"; + return customValue; + } +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_param/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_param/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_param/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_param/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_param/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_param/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_param/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_param/Ballerina.toml new file mode 100644 index 000000000000..4d7053162003 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_param/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "type_definition_inside_remote_function_param" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + +[build-options] +observabilityIncluded = true diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_param/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_param/Dependencies.toml new file mode 100644 index 000000000000..32936e339aa5 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_param/Dependencies.toml @@ -0,0 +1,45 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.3" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + +[[package]] +org = "thushara_piyasekara" +name = "type_definition_inside_remote_function_param" +version = "0.1.0" +dependencies = [ + {org = "ballerinai", name = "observe"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "type_definition_inside_remote_function_param", moduleName = "type_definition_inside_remote_function_param"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_param/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_param/main.bal new file mode 100644 index 000000000000..851d37e9e618 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_remote_function_param/main.bal @@ -0,0 +1,47 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public isolated class Listener { + private int port; + public function 'start() returns error? { + } + + public function gracefulStop() returns error? { + } + + public function immediateStop() returns error? { + } + + public function detach(service object {} s) returns error? { + } + + public function attach(service object {} s, string[]? name = ()) returns error? { + } + + public function init(int port) { + self.port = port; + } +} + +type UsedTypeDef int|string; + +type UnusedTypeDef int|string; + +service / on new Listener(1000) { + remote function albums() returns UsedTypeDef|error { + return "Hello"; + } +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_body/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_body/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_body/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_body/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_body/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_body/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_body/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_body/Ballerina.toml new file mode 100644 index 000000000000..a843ffb09e5d --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_body/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "type_definition_inside_resource_function_body" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + +[build-options] +observabilityIncluded = true diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_body/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_body/Dependencies.toml new file mode 100644 index 000000000000..eb12ffb64569 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_body/Dependencies.toml @@ -0,0 +1,45 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.3" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + +[[package]] +org = "thushara_piyasekara" +name = "type_definition_inside_resource_function_body" +version = "0.1.0" +dependencies = [ + {org = "ballerinai", name = "observe"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "type_definition_inside_resource_function_body", moduleName = "type_definition_inside_resource_function_body"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_body/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_body/main.bal new file mode 100644 index 000000000000..9c463da7523f --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_body/main.bal @@ -0,0 +1,48 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public isolated class Listener { + private int port; + public function 'start() returns error? { + } + + public function gracefulStop() returns error? { + } + + public function immediateStop() returns error? { + } + + public function detach(service object {} s) returns error? { + } + + public function attach(service object {} s, string[]? name = ()) returns error? { + } + + public function init(int port) { + self.port = port; + } +} + +type UsedTypeDef int|string; + +type UnusedTypeDef int|string; + +service / on new Listener(1000) { + resource function get albums() returns string|int|error { + UsedTypeDef customValue = "Hello"; + return customValue; + } +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_param/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_param/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_param/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_param/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_param/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_param/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_param/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_param/Ballerina.toml new file mode 100644 index 000000000000..448f57acb821 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_param/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "type_definition_inside_resource_function_param" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + +[build-options] +observabilityIncluded = true diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_param/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_param/Dependencies.toml new file mode 100644 index 000000000000..763225a64fd0 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_param/Dependencies.toml @@ -0,0 +1,45 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.3" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + +[[package]] +org = "thushara_piyasekara" +name = "type_definition_inside_resource_function_param" +version = "0.1.0" +dependencies = [ + {org = "ballerinai", name = "observe"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "type_definition_inside_resource_function_param", moduleName = "type_definition_inside_resource_function_param"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_param/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_param/main.bal new file mode 100644 index 000000000000..d41c5fe50c4d --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_resource_function_param/main.bal @@ -0,0 +1,47 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public isolated class Listener { + private int port; + public function 'start() returns error? { + } + + public function gracefulStop() returns error? { + } + + public function immediateStop() returns error? { + } + + public function detach(service object {} s) returns error? { + } + + public function attach(service object {} s, string[]? name = ()) returns error? { + } + + public function init(int port) { + self.port = port; + } +} + +type UsedTypeDef int|string; + +type UnusedTypeDef int|string; + +service / on new Listener(1000) { + resource function get albums() returns UsedTypeDef|error { + return "Hello"; + } +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker/.devcontainer.json new file mode 100644 index 000000000000..8a0177271a49 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.8.6", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker/.gitignore new file mode 100644 index 000000000000..7512ebe2325f --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker/.gitignore @@ -0,0 +1,3 @@ +target +generated +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker/Ballerina.toml new file mode 100644 index 000000000000..e440fd964a73 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "type_definition_inside_worker" +version = "0.1.0" +distribution = "2201.8.6" + +[build-options] +observabilityIncluded = true diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker/Dependencies.toml new file mode 100644 index 000000000000..d7256fea83a5 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker/Dependencies.toml @@ -0,0 +1,45 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.3" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + +[[package]] +org = "thushara_piyasekara" +name = "type_definition_inside_worker" +version = "0.1.0" +dependencies = [ + {org = "ballerinai", name = "observe"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "type_definition_inside_worker", moduleName = "type_definition_inside_worker"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker/main.bal new file mode 100644 index 000000000000..a246173de744 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker/main.bal @@ -0,0 +1,25 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type UsedTypeDef int|string & readonly; + +type UnusedTypeDef float|boolean; + +public function main() returns error? { + worker A { + UsedTypeDef a = 5; + } +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker_with_return/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker_with_return/.devcontainer.json new file mode 100644 index 000000000000..8a0177271a49 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker_with_return/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.8.6", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker_with_return/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker_with_return/.gitignore new file mode 100644 index 000000000000..7512ebe2325f --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker_with_return/.gitignore @@ -0,0 +1,3 @@ +target +generated +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker_with_return/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker_with_return/Ballerina.toml new file mode 100644 index 000000000000..b74a94718014 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker_with_return/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "thushara_piyasekara" +name = "type_definition_inside_worker_with_return" +version = "0.1.0" +distribution = "2201.8.6" + +[build-options] +observabilityIncluded = true diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker_with_return/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker_with_return/Dependencies.toml new file mode 100644 index 000000000000..bc5bb53fe8c4 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker_with_return/Dependencies.toml @@ -0,0 +1,45 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.3" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + +[[package]] +org = "thushara_piyasekara" +name = "type_definition_inside_worker_with_return" +version = "0.1.0" +dependencies = [ + {org = "ballerinai", name = "observe"} +] +modules = [ + {org = "thushara_piyasekara", packageName = "type_definition_inside_worker_with_return", moduleName = "type_definition_inside_worker_with_return"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker_with_return/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker_with_return/main.bal new file mode 100644 index 000000000000..56928bf974b4 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_definition_inside_worker_with_return/main.bal @@ -0,0 +1,27 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type UsedTypeDef int|string & readonly; + +type UnusedTypeDef float|boolean; + +public function main() returns error? { + worker A returns UsedTypeDef { + return "foo"; + } + + anydata s = check wait A; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_narrowing/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_narrowing/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_narrowing/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_narrowing/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_narrowing/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_narrowing/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_narrowing/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_narrowing/Ballerina.toml new file mode 100644 index 000000000000..7f3e2ae5337b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_narrowing/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "type_narrowing" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_narrowing/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_narrowing/Dependencies.toml new file mode 100644 index 000000000000..8733d491241b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_narrowing/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "type_narrowing" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "type_narrowing", moduleName = "type_narrowing"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_narrowing/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_narrowing/main.bal new file mode 100644 index 000000000000..11d144f5268d --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_narrowing/main.bal @@ -0,0 +1,26 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type A int|string; + +type B string; + +public function main() { + A a = "Im A"; + if a is B { + string b = a; + } +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_varargs/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_varargs/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_varargs/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_varargs/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_varargs/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_varargs/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_varargs/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_varargs/Ballerina.toml new file mode 100644 index 000000000000..f9514194dc48 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_varargs/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "type_varargs" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_varargs/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_varargs/Dependencies.toml new file mode 100644 index 000000000000..0dded01a81b0 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_varargs/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "type_varargs" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "type_varargs", moduleName = "type_varargs"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_varargs/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_varargs/main.bal new file mode 100644 index 000000000000..be5a128c4306 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/type_varargs/main.bal @@ -0,0 +1,27 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type A int|string; + +type B string; + +public function main() { + foo(2, "bar"); +} + +function foo(A... varargs) { + +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_classes/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_classes/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_classes/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_classes/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_classes/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_classes/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_classes/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_classes/Ballerina.toml new file mode 100644 index 000000000000..5e1efc96a7ae --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_classes/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "vanilla_classes" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_classes/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_classes/Dependencies.toml new file mode 100644 index 000000000000..fac64f24f192 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_classes/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "vanilla_classes" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "vanilla_classes", moduleName = "vanilla_classes"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_classes/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_classes/main.bal new file mode 100644 index 000000000000..b9241d84ee7d --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_classes/main.bal @@ -0,0 +1,37 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type A int|string; + +type B boolean; + +type C decimal; + +class CKlass { + A attributeA; + B attributeB; + decimal attributeDecimal; + + function init(A attributeA, B attributeB, C attributeDecimal) { + self.attributeA = attributeA; + self.attributeB = attributeB; + self.attributeDecimal = attributeDecimal; + } +} + +public function main() { + CKlass c = new ("A", true, 2.0); +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_types/.devcontainer.json b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_types/.devcontainer.json new file mode 100644 index 000000000000..506ba05e294b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_types/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.9.0-SNAPSHOT", + "extensions": ["WSO2.ballerina"], +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_types/.gitignore b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_types/.gitignore new file mode 100644 index 000000000000..d5fc29aba3c3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_types/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_types/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_types/Ballerina.toml new file mode 100644 index 000000000000..698fd49e7746 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_types/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "thushara_piyasekara" +name = "vanilla_types" +version = "0.1.0" +distribution = "2201.9.0-SNAPSHOT" + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_types/Dependencies.toml b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_types/Dependencies.toml new file mode 100644 index 000000000000..5ff1cf28558e --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_types/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "thushara_piyasekara" +name = "vanilla_types" +version = "0.1.0" +modules = [ + {org = "thushara_piyasekara", packageName = "vanilla_types", moduleName = "vanilla_types"} +] + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_types/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_types/main.bal new file mode 100644 index 000000000000..b16593721189 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/build-projects/TypeDefinitions/vanilla_types/main.bal @@ -0,0 +1,23 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type A int|string; + +type B boolean; + +public function main() { + A a = "im used"; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/arrow_functions_1.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/arrow_functions_1.bal new file mode 100644 index 000000000000..a0ce59557473 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/arrow_functions_1.bal @@ -0,0 +1,24 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type ReturnsIntFunction function (int) returns int; + +ReturnsIntFunction globalFP = (val) => val * 2; +ReturnsIntFunction globalFPUnused = (val) => val * 3; + +public function main() { + _ = globalFP(4); +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/arrow_functions_2.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/arrow_functions_2.bal new file mode 100644 index 000000000000..fa47c9a75005 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/arrow_functions_2.bal @@ -0,0 +1,26 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type ReturnsIntFunction function (int) returns int; + +ReturnsIntFunction globalFP = (val) => val * 2; +ReturnsIntFunction globalFPUnused = (val) => val * 3; + +public function main() { + ReturnsIntFunction localFP1 = globalFP; + ReturnsIntFunction localFP2 = localFP1; + _ = localFP2(2); +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/class_level_functions.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/class_level_functions.bal new file mode 100644 index 000000000000..cd681b95b5d9 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/class_level_functions.bal @@ -0,0 +1,34 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +class CKlass { + function foo() { + + } + + function bar() { + + } +} + +public function main() { + CKlass c = new (); + c.foo(); +} + +function foo() { + +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_invocation_as_default_value.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_invocation_as_default_value.bal new file mode 100644 index 000000000000..2068b16827c8 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_invocation_as_default_value.bal @@ -0,0 +1,43 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type UsedRec record { + string name = foo(); +}; + +type UnusedRec record { + string name = bar(); +}; + +public function main() { + UsedRec rec = {}; + corge(); +} + +public function corge(string defaultParam = baz()) { +} + +isolated function foo() returns string { + return "Im used"; +} + +isolated function baz() returns string { + return "Im used"; +} + +isolated function bar() returns string { + return "Im unused"; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_invocation_inside_closure.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_invocation_inside_closure.bal new file mode 100644 index 000000000000..dd2050b5a0df --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_invocation_inside_closure.bal @@ -0,0 +1,27 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function main() { + var addName = function() returns string { + return foo(); + }; + + _ = addName(); +} + +function foo() returns string { + return "John"; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_invocation_inside_global_closure.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_invocation_inside_global_closure.bal new file mode 100644 index 000000000000..6e6b2281bae7 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_invocation_inside_global_closure.bal @@ -0,0 +1,27 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +var addName = function() returns string { + return foo(); +}; + +public function main() { + _ = addName(); +} + +function foo() returns string { + return "John"; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_invocation_inside_match_statement.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_invocation_inside_match_statement.bal new file mode 100644 index 000000000000..a11fb86fba34 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_invocation_inside_match_statement.bal @@ -0,0 +1,33 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function main() { + int val = 0; + match val { + 0 => { + foo(); + } + 1 => { + + } + } +} + +function foo() { +} + +function bar() { +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_invocation_inside_match_statement_obstruction.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_invocation_inside_match_statement_obstruction.bal new file mode 100644 index 000000000000..eaa5eeeff7e0 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_invocation_inside_match_statement_obstruction.bal @@ -0,0 +1,37 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function main() { + int val = 0; + match val { + 0 if baz() => { + foo(); + } + 1 => { + + } + } +} + +function foo() { +} + +function bar() { +} + +function baz() returns boolean { + return true; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_invocation_inside_record.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_invocation_inside_record.bal new file mode 100644 index 000000000000..a3bbade7bac2 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_invocation_inside_record.bal @@ -0,0 +1,33 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type RecA record { + string name; +}; + +public function main() { + RecA rec = { + name: foo() + }; +} + +function foo() returns string { + return "Im used"; +} + +function bar() returns string { + return "Im unused"; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointer_invocation_inisde_different_bb.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointer_invocation_inisde_different_bb.bal new file mode 100644 index 000000000000..ee83cbd3e36b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointer_invocation_inisde_different_bb.bal @@ -0,0 +1,25 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function main() { + function () fp = foo; + if true { + fp(); + } +} + +function foo() { +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointer_invocation_inside_lock.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointer_invocation_inside_lock.bal new file mode 100644 index 000000000000..139ebf8e08a5 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointer_invocation_inside_lock.bal @@ -0,0 +1,33 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function main() { + className obj = new className(); + obj.bar(); +} + +isolated class className { + isolated function foo() { + } + + isolated function bar() { + isolated function () bar; + bar = self.foo; + lock { + bar(); + } + } +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointers_as_arguments.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointers_as_arguments.bal new file mode 100644 index 000000000000..fb5282ae1819 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointers_as_arguments.bal @@ -0,0 +1,46 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type ReturnsIntFunction function () returns int; + +ReturnsIntFunction globalFP1 = foo; +ReturnsIntFunction globalFP2 = baz; +ReturnsIntFunction globalFPUnused = bar; + +public function main() { + // Passing the fp directly + fpEater(globalFP1); + // Passing the fp indirectly + ReturnsIntFunction localFP1 = globalFP2; + ReturnsIntFunction localFP2 = localFP1; + fpEater(localFP2); +} + +public function fpEater(ReturnsIntFunction fp) { + _ = fp(); +} + +public function foo() returns int { + return 2; +} + +public function bar() returns int { + return 2; +} + +public function baz() returns int { + return 2; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointers_global_assignment.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointers_global_assignment.bal new file mode 100644 index 000000000000..f2689632377a --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointers_global_assignment.bal @@ -0,0 +1,32 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type ReturnsIntFunction function () returns int; + +ReturnsIntFunction globalFP = foo; +ReturnsIntFunction globalFPUnused = bar; + +public function main() { + _ = globalFP(); +} + +public function foo() returns int { + return 2; +} + +public function bar() returns int { + return 2; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointers_inside_array.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointers_inside_array.bal new file mode 100644 index 000000000000..e5c7954b62e0 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointers_inside_array.bal @@ -0,0 +1,32 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type ReturnsIntFunction function () returns int; + +ReturnsIntFunction[] globalFPArr = [foo, bar]; + +public function main() { + ReturnsIntFunction localFP = globalFPArr[1]; + _ = localFP(); +} + +public function foo() returns int { + return 2; +} + +public function bar() returns int { + return 2; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointers_inside_lock.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointers_inside_lock.bal new file mode 100644 index 000000000000..c6f3cebf8f72 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointers_inside_lock.bal @@ -0,0 +1,33 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function main() { + className obj = new className(); + obj.execute2(); +} + +isolated class className { + isolated function foo() { + } + + isolated function execute2() { + isolated function () bar; + lock { + bar = self.foo; + } + bar(); + } +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointers_inside_record.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointers_inside_record.bal new file mode 100644 index 000000000000..9158750c0f68 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointers_inside_record.bal @@ -0,0 +1,37 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type ReturnsIntFunction function () returns int; + +type FPRecord record { + ReturnsIntFunction fpField; +}; + +public function main() { + FPRecord rec = { + fpField: foo + }; + ReturnsIntFunction localFP = rec.fpField; + _ = localFP(); +} + +public function foo() returns int { + return 2; +} + +public function bar() returns int { + return 2; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointers_invocation_inside_record.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointers_invocation_inside_record.bal new file mode 100644 index 000000000000..241773261ac2 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointers_invocation_inside_record.bal @@ -0,0 +1,38 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type ReturnsIntFunction function () returns string; + +ReturnsIntFunction globalFP = foo; +ReturnsIntFunction globalFPUnused = bar; + +type RecA record { + string name; +}; + +public function main() { + RecA rec = { + name: globalFP() + }; +} + +function foo() returns string { + return "Im used"; +} + +function bar() returns string { + return "Im unused"; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointers_local_assignment.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointers_local_assignment.bal new file mode 100644 index 000000000000..765b9a8e5d3d --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointers_local_assignment.bal @@ -0,0 +1,30 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type ReturnsIntFunction function () returns int; + +public function main() { + ReturnsIntFunction localFP = foo; + _ = localFP(); +} + +public function foo() returns int { + return 2; +} + +public function fooUnused() returns int { + return 2; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointers_transitive_assignment.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointers_transitive_assignment.bal new file mode 100644 index 000000000000..0e72a0e5d994 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/function_pointers_transitive_assignment.bal @@ -0,0 +1,34 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type ReturnsIntFunction function () returns int; + +ReturnsIntFunction globalFP = foo; +ReturnsIntFunction globalFPUnused = bar; + +public function main() { + ReturnsIntFunction localFP1 = globalFP; + ReturnsIntFunction localFP2 = localFP1; + _ = localFP2(); +} + +public function foo() returns int { + return 2; +} + +public function bar() returns int { + return 2; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/tranistive_functions_1.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/tranistive_functions_1.bal new file mode 100644 index 000000000000..baf828231de3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/tranistive_functions_1.bal @@ -0,0 +1,31 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function main() { + foo(); +} + +function foo() { + bar(); +} + +function bar() { + +} + +function baz() { + +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/tranistive_functions_2.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/tranistive_functions_2.bal new file mode 100644 index 000000000000..ef3299af0b5d --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/tranistive_functions_2.bal @@ -0,0 +1,31 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function main() { + foo(bar()); +} + +function foo(int a) { + +} + +function bar() returns int { + return 1; +} + +function baz() { + +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/vanilla_functions.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/vanilla_functions.bal new file mode 100644 index 000000000000..560b8a612815 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/Functions/vanilla_functions.bal @@ -0,0 +1,27 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function main() { + foo(); +} + +function foo() { + +} + +function bar() { + +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/class_inclusion.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/class_inclusion.bal new file mode 100644 index 000000000000..93fb748f7468 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/class_inclusion.bal @@ -0,0 +1,31 @@ + +type Cloneable object { + function clone() returns Cloneable; +}; + +type Person object { + *Cloneable; + string name; + + function getName() returns string; +}; + +class Engineer { + *Person; + + function init(string name) { + self.name = name; + } + + function clone() returns Engineer { + return new (self.name); + } + + function getName() returns string { + return self.name; + } +} + +public function main() { + Engineer e1 = new ("Alice"); +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/global_value_initialization.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/global_value_initialization.bal new file mode 100644 index 000000000000..d1d9578a5d73 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/global_value_initialization.bal @@ -0,0 +1,24 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type A int|string; + +type B boolean; + +A a = "im used"; + +public function main() { +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/intersection_types.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/intersection_types.bal new file mode 100644 index 000000000000..1d3f425db2aa --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/intersection_types.bal @@ -0,0 +1,25 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type XErr distinct error; + +type YErr distinct error; + +type BigErr XErr & YErr; + +public function main() { + BigErr err = error(""); +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/parameters_via_record_field_mapping.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/parameters_via_record_field_mapping.bal new file mode 100644 index 000000000000..680411ea1cdf --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/parameters_via_record_field_mapping.bal @@ -0,0 +1,39 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type RecA record { + B fieldB; + C fieldC; +}; + +type B boolean|int; + +type C string; + +type D decimal; + +type RecE record { + int fieldInt; + D fieldD; + +}; + +public function main() { + foo(fieldB = true, fieldC = "hello"); +} + +function foo(*RecA rec) { +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/query_expression_type_usage.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/query_expression_type_usage.bal new file mode 100644 index 000000000000..22142859c70c --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/query_expression_type_usage.bal @@ -0,0 +1,29 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type A int|string; + +type B boolean; + +type C float; + +public function main() { + int[] nums = [1, 2, 3, 4]; + + int[] queryResult = from A i in nums + let B j = true + select i * 2; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/record_dependency.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/record_dependency.bal new file mode 100644 index 000000000000..248e714073d7 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/record_dependency.bal @@ -0,0 +1,35 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type RecA record { + B fieldB; +}; + +type B boolean|C; + +type C string; + +type RecD record { + E fieldE; +}; + +type E boolean; + +public function main() { + RecA recordA = { + fieldB: "I am used" + }; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/record_inclusion.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/record_inclusion.bal new file mode 100644 index 000000000000..28102c67e253 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/record_inclusion.bal @@ -0,0 +1,35 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type RecA record { + B fieldB; + C fieldC; +}; + +type B boolean|int; + +type C string; + +type D decimal; + +type RecE record { + *RecA; + int fieldInt; +}; + +public function main() { + RecE recE = {fieldB: true, fieldC: "hello", fieldInt: 5}; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/transitive_types.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/transitive_types.bal new file mode 100644 index 000000000000..4ea4026911ea --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/transitive_types.bal @@ -0,0 +1,25 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type A int|string; + +type B A|boolean; + +type C decimal; + +public function main() { + B a = "im used"; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/type_cast.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/type_cast.bal new file mode 100644 index 000000000000..d5c211b6c9d1 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/type_cast.bal @@ -0,0 +1,26 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type A string; + +type B int|string; + +type C int|string|boolean; + +public function main() { + A a = "Im A"; + C c = a; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/type_def_reference_inisde_closure.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/type_def_reference_inisde_closure.bal new file mode 100644 index 000000000000..d1b510fbb165 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/type_def_reference_inisde_closure.bal @@ -0,0 +1,26 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type CustomType int|float|string; + +public function main() { + var addName = function(string value) returns string { + CustomType name = "John"; + return "hello"; + }; + + _ = addName("John"); +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/type_inside_query_expression.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/type_inside_query_expression.bal new file mode 100644 index 000000000000..23c8c0f20207 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/type_inside_query_expression.bal @@ -0,0 +1,26 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type A int|string; + +type B boolean; + +public function main() { + int[] nums = [1, 2, 3, 4]; + + int[] queryResult = from A i in nums + select i * 2; +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/type_narrowing.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/type_narrowing.bal new file mode 100644 index 000000000000..11d144f5268d --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/type_narrowing.bal @@ -0,0 +1,26 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type A int|string; + +type B string; + +public function main() { + A a = "Im A"; + if a is B { + string b = a; + } +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/type_varargs.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/type_varargs.bal new file mode 100644 index 000000000000..be5a128c4306 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/type_varargs.bal @@ -0,0 +1,27 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type A int|string; + +type B string; + +public function main() { + foo(2, "bar"); +} + +function foo(A... varargs) { + +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/vanilla_classes.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/vanilla_classes.bal new file mode 100644 index 000000000000..b9241d84ee7d --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/vanilla_classes.bal @@ -0,0 +1,37 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type A int|string; + +type B boolean; + +type C decimal; + +class CKlass { + A attributeA; + B attributeB; + decimal attributeDecimal; + + function init(A attributeA, B attributeB, C attributeDecimal) { + self.attributeA = attributeA; + self.attributeB = attributeB; + self.attributeDecimal = attributeDecimal; + } +} + +public function main() { + CKlass c = new ("A", true, 2.0); +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/vanilla_types.bal b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/vanilla_types.bal new file mode 100644 index 000000000000..b16593721189 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/codegen-optimizer/projects/single-file-projects/TypeDefinitions/vanilla_types.bal @@ -0,0 +1,23 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +type A int|string; + +type B boolean; + +public function main() { + A a = "im used"; +} diff --git a/tests/jballerina-unit-test/src/test/resources/testng.xml b/tests/jballerina-unit-test/src/test/resources/testng.xml index 45455c0569c8..2eb6d5e905a6 100644 --- a/tests/jballerina-unit-test/src/test/resources/testng.xml +++ b/tests/jballerina-unit-test/src/test/resources/testng.xml @@ -31,6 +31,7 @@ + diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/OptimizedExecutableTestingTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/OptimizedExecutableTestingTest.java new file mode 100644 index 000000000000..37074b37e2e3 --- /dev/null +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/OptimizedExecutableTestingTest.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.ballerinalang.testerina.test; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.ballerinalang.test.context.BMainInstance; +import org.ballerinalang.test.context.BallerinaTestException; +import org.ballerinalang.testerina.test.utils.AssertionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; + +/** + * Test cases to verify optimized BIRNodes from `bal test --optimize` command. + * + * @since 2201.10.0 + */ +public class OptimizedExecutableTestingTest extends BaseTestCase { + + private static final Logger LOGGER = LoggerFactory.getLogger(OptimizedExecutableTestingTest.class); + private BMainInstance balClient; + private String projectPath; + private static final String TARGET = "target"; + private static final String PROJECT_NAME = "optimized_test_run_test"; + private static final String OPTIMIZATION_REPORT_JSON = "codegen_optimization_report.json"; + private static final Path EXPECTED_CODEGEN_OPTIMIZATION_REPORTS_DIR = + Paths.get("src", "test", "resources", "codegen-optimization-reports", PROJECT_NAME); + + @BeforeClass + public void setup() throws BallerinaTestException { + balClient = new BMainInstance(balServer); + projectPath = projectBasedTestsPath.resolve(PROJECT_NAME).toString(); + } + + @Test() + public void testWithCommonDependencies() throws BallerinaTestException, IOException { + String output = + balClient.runMainAndReadStdOut("test", new String[]{"--optimize", "--optimize-report"}, new HashMap<>(), + projectPath, true); + AssertionUtils.assertOutput("OptimizedExecutableTestingTest-testWithCommonDependencies.txt", + AssertionUtils.replaceBIRNodeAnalysisTime(output)); + assertBuildProjectJsonReportsAreSimilar(Path.of(projectPath)); + } + + private void assertBuildProjectJsonReportsAreSimilar(Path buildProjectPath) { + Path actualJsonPath = buildProjectPath.resolve(TARGET).resolve(OPTIMIZATION_REPORT_JSON); + JsonObject expectedJsonObject = + fileContentAsObject(EXPECTED_CODEGEN_OPTIMIZATION_REPORTS_DIR.resolve(OPTIMIZATION_REPORT_JSON)); + JsonObject actualJsonObject = fileContentAsObject(actualJsonPath); + Assert.assertEquals(actualJsonObject, expectedJsonObject); + } + + private static JsonObject fileContentAsObject(Path filePath) { + String contentAsString = ""; + try { + contentAsString = new String(Files.readAllBytes(filePath)); + } catch (IOException ex) { + LOGGER.error(ex.getMessage()); + } + return JsonParser.parseString(contentAsString).getAsJsonObject(); + } +} diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/utils/AssertionUtils.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/utils/AssertionUtils.java index 484856c16ac3..70aa5180a534 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/utils/AssertionUtils.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/utils/AssertionUtils.java @@ -46,6 +46,16 @@ public static void assertForTestFailures(String programOutput, String errMessage } } + public static String replaceBIRNodeAnalysisTime(String content) { + return removeStringBlock("Duration for unused BIR node analysis :", "Running Tests", content); + } + + public static String removeStringBlock(String firstString, String endString, String content) { + int firstPos = content.indexOf(firstString); + int lastPos = content.indexOf(endString); + return content.substring(0, firstPos) + content.substring(lastPos); + } + public static void assertOutput(String outputFileName, String output) throws IOException { if (isWindows) { output = CommonUtils.replaceExecutionTime(output); diff --git a/tests/testerina-integration-test/src/test/resources/codegen-optimization-reports/optimized_test_run_test/codegen_optimization_report.json b/tests/testerina-integration-test/src/test/resources/codegen-optimization-reports/optimized_test_run_test/codegen_optimization_report.json new file mode 100644 index 000000000000..68156d824990 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/codegen-optimization-reports/optimized_test_run_test/codegen_optimization_report.json @@ -0,0 +1,91 @@ +{ + "test_org/optimized_test_run_test:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "foo", + "main", + "bar" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [ + "corge" + ], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "RecA", + "TupleB" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "RecC" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + }, + "test_org/optimized_test_run_test.subModuleB:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "test_org/optimized_test_run_test.subModuleB:0.1.0:publicClass.foo" + ], + "virtualFunctions": [ + ".", + ".", + ".", + "test_org/optimized_test_run_test.subModuleB:0.1.0:publicClass.$init$" + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [ + "publicClass" + ], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + }, + "test_org/optimized_test_run_test.subModuleA:0.1.0": { + "usedFunctionNames": { + "sourceFunctions": [ + "publicFunction" + ], + "virtualFunctions": [ + ".", + ".", + "." + ] + }, + "unusedFunctionNames": { + "sourceFunctions": [], + "virtualFunctions": [] + }, + "usedTypeDefNames": { + "sourceTypeDefinitions": [], + "virtualTypeDefinitions": [] + }, + "unusedTypeDefNames": { + "sourceTypeDefinitions": [ + "PublicTypeDef" + ], + "virtualTypeDefinitions": [] + }, + "usedNativeClassPaths": [] + } +} \ No newline at end of file diff --git a/tests/testerina-integration-test/src/test/resources/command-outputs/unix/OptimizedExecutableTestingTest-testWithCommonDependencies.txt b/tests/testerina-integration-test/src/test/resources/command-outputs/unix/OptimizedExecutableTestingTest-testWithCommonDependencies.txt new file mode 100644 index 000000000000..b72f2c4845fa --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/command-outputs/unix/OptimizedExecutableTestingTest-testWithCommonDependencies.txt @@ -0,0 +1,14 @@ +Compiling source + test_org/optimized_test_run_test:0.1.0 +Running Tests + + optimized_test_run_test + [pass] importUsageTest + [pass] simpleTest + + + 2 passing + 0 failing + 0 skipped + + Test execution time :*****s diff --git a/tests/testerina-integration-test/src/test/resources/command-outputs/windows/OptimizedExecutableTestingTest-testWithCommonDependencies.txt b/tests/testerina-integration-test/src/test/resources/command-outputs/windows/OptimizedExecutableTestingTest-testWithCommonDependencies.txt new file mode 100644 index 000000000000..b72f2c4845fa --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/command-outputs/windows/OptimizedExecutableTestingTest-testWithCommonDependencies.txt @@ -0,0 +1,14 @@ +Compiling source + test_org/optimized_test_run_test:0.1.0 +Running Tests + + optimized_test_run_test + [pass] importUsageTest + [pass] simpleTest + + + 2 passing + 0 failing + 0 skipped + + Test execution time :*****s diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/optimized_test_run_test/Ballerina.toml b/tests/testerina-integration-test/src/test/resources/project-based-tests/optimized_test_run_test/Ballerina.toml new file mode 100644 index 000000000000..cf2f1cce491b --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/optimized_test_run_test/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "test_org" +name = "optimized_test_run_test" +version = "0.1.0" diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/optimized_test_run_test/main.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/optimized_test_run_test/main.bal new file mode 100644 index 000000000000..9802e6f0ad2b --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/optimized_test_run_test/main.bal @@ -0,0 +1,47 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import optimized_test_run_test.subModuleA; +import optimized_test_run_test.subModuleB; + +public function main() { + subModuleA:publicFunction(); + subModuleB:publicClass? importedClass = (); + bar(); + TupleB tupB = [2, "hello"]; +} + +function bar() { + +} + +function foo() returns string { + return "hello"; +} + +function corge() { + +} + +type RecA record { + string name; +}; + +type TupleB [int, string]; + +type RecC record { + int num; +}; diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/optimized_test_run_test/modules/subModuleA/subModuleA.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/optimized_test_run_test/modules/subModuleA/subModuleA.bal new file mode 100644 index 000000000000..58a7d2d3a3bc --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/optimized_test_run_test/modules/subModuleA/subModuleA.bal @@ -0,0 +1,24 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function publicFunction() { + +} + +public type PublicTypeDef record { + string name; + int num; +}; diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/optimized_test_run_test/modules/subModuleB/subModuleB.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/optimized_test_run_test/modules/subModuleB/subModuleB.bal new file mode 100644 index 000000000000..6441d9b7d18d --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/optimized_test_run_test/modules/subModuleB/subModuleB.bal @@ -0,0 +1,21 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public class publicClass { + function foo() { + + } +} diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/optimized_test_run_test/modules/subModuleC/subModuleC.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/optimized_test_run_test/modules/subModuleC/subModuleC.bal new file mode 100644 index 000000000000..53f6489e2248 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/optimized_test_run_test/modules/subModuleC/subModuleC.bal @@ -0,0 +1,22 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function hello(string? name) returns string { + if name !is () { + return string `Hello, ${name}`; + } + return "Hello, World!"; +} diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/optimized_test_run_test/tests/test.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/optimized_test_run_test/tests/test.bal new file mode 100644 index 000000000000..d386562345a4 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/optimized_test_run_test/tests/test.bal @@ -0,0 +1,36 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import optimized_test_run_test.subModuleA; +import optimized_test_run_test.subModuleC; + +import ballerina/test; + +@test:Config {} +function simpleTest() { + subModuleA:PublicTypeDef? importedTypeDef = (); + _ = subModuleC:hello(()); + test:assertEquals(foo(), utilFunc().name); +} + +@test:Config {} +function importUsageTest() { + +} + +function utilFunc() returns RecA { + return {name: "hello"}; +} diff --git a/tests/testerina-integration-test/src/test/resources/testng.xml b/tests/testerina-integration-test/src/test/resources/testng.xml index 3c731b522f9a..df0127693587 100644 --- a/tests/testerina-integration-test/src/test/resources/testng.xml +++ b/tests/testerina-integration-test/src/test/resources/testng.xml @@ -61,6 +61,7 @@ under the License. +