From 1ebbd8a4eb99449f445382c0a1d9d39767e22fdb Mon Sep 17 00:00:00 2001 From: Jaden Peterson Date: Thu, 12 Dec 2024 19:09:16 -0500 Subject: [PATCH 1/4] Avoid unnecessary copying and heap allocation in CommonArguments#apply --- .../rules_scala/workers/common/CommonArguments.scala | 10 +++++----- .../rules_scala/workers/zinc/compile/ZincRunner.scala | 10 ++++------ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/main/scala/higherkindness/rules_scala/workers/common/CommonArguments.scala b/src/main/scala/higherkindness/rules_scala/workers/common/CommonArguments.scala index 037d7d1b..171c69d0 100644 --- a/src/main/scala/higherkindness/rules_scala/workers/common/CommonArguments.scala +++ b/src/main/scala/higherkindness/rules_scala/workers/common/CommonArguments.scala @@ -17,7 +17,7 @@ class CommonArguments private ( val analyses: List[Analysis], val compilerBridge: Path, val compilerClasspath: List[Path], - val compilerOptions: List[String], + val compilerOptions: Array[String], /** * With [[https://bazel.build/remote/multiplex#multiplex_sandboxing multiplex sandboxing]], Bazel generates a separate @@ -32,7 +32,7 @@ class CommonArguments private ( val compilerOptionsReferencingPaths: List[String], val classpath: List[Path], val debug: Boolean, - val javaCompilerOptions: List[String], + val javaCompilerOptions: Array[String], val label: String, val logLevel: LogLevel, val mainManifest: Path, @@ -215,8 +215,8 @@ object CommonArguments { compilerBridge = SandboxUtil.getSandboxPath(workDir, namespace.get[Path]("compiler_bridge")), compilerClasspath = SandboxUtil.getSandboxPaths(workDir, namespace.getList[Path]("compiler_classpath")), compilerOptions = Option(namespace.getList[String]("compiler_option")) - .map(_.asScala.toList) - .getOrElse(List.empty), + .map(_.asScala.toArray) + .getOrElse(Array.empty), compilerOptionsReferencingPaths = adjustCompilerOptions( workDir, Option(namespace.getList[String]("compiler_option_referencing_path")) @@ -225,7 +225,7 @@ object CommonArguments { ), classpath = SandboxUtil.getSandboxPaths(workDir, namespace.getList[Path]("classpath")), debug = namespace.getBoolean("debug"), - javaCompilerOptions = namespace.getList[String]("java_compiler_option").asScala.toList, + javaCompilerOptions = namespace.getList[String]("java_compiler_option").asScala.toArray, label = namespace.getString("label"), logLevel = LogLevel(namespace.getString("log_level")), mainManifest = SandboxUtil.getSandboxPath(workDir, namespace.get[Path]("main_manifest")), diff --git a/src/main/scala/higherkindness/rules_scala/workers/zinc/compile/ZincRunner.scala b/src/main/scala/higherkindness/rules_scala/workers/zinc/compile/ZincRunner.scala index 98fac434..a82bf92e 100644 --- a/src/main/scala/higherkindness/rules_scala/workers/zinc/compile/ZincRunner.scala +++ b/src/main/scala/higherkindness/rules_scala/workers/zinc/compile/ZincRunner.scala @@ -212,13 +212,11 @@ object ZincRunner extends WorkerMain[ZincRunnerWorkerConfig] { .withSources(sources.map(source => PlainVirtualFile(source.toAbsolutePath().normalize())).toArray) .withClasspath((classesOutputDir +: deps.map(_.classpath)).map(path => PlainVirtualFile(path)).toArray) .withClassesDirectory(classesOutputDir) - .withJavacOptions(workRequest.javaCompilerOptions.toArray) + .withJavacOptions(workRequest.javaCompilerOptions) .withScalacOptions( - ( - workRequest.plugins.map(p => s"-Xplugin:$p") ++ - workRequest.compilerOptions ++ - workRequest.compilerOptionsReferencingPaths - ).toArray, + workRequest.plugins.view.map(p => s"-Xplugin:$p").toArray ++ + workRequest.compilerOptions ++ + workRequest.compilerOptionsReferencingPaths.toArray, ) val compilers = { From 2269602b003062beb9abbdea564ba86758c350d4 Mon Sep 17 00:00:00 2001 From: Jaden Peterson Date: Thu, 12 Dec 2024 19:10:04 -0500 Subject: [PATCH 2/4] Only write the debug analysis file if --worker_verbosity is set --- rules/private/phases/phase_zinc_compile.bzl | 2 -- .../workers/zinc/compile/ZincRunner.scala | 18 ++++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/rules/private/phases/phase_zinc_compile.bzl b/rules/private/phases/phase_zinc_compile.bzl index e1e9922a..a973906b 100644 --- a/rules/private/phases/phase_zinc_compile.bzl +++ b/rules/private/phases/phase_zinc_compile.bzl @@ -19,7 +19,6 @@ load( def phase_zinc_compile(ctx, g): toolchain = ctx.toolchains["//rules/scala:toolchain_type"] analysis_store = ctx.actions.declare_file("{}/analysis_store.gz".format(ctx.label.name)) - analysis_store_text = ctx.actions.declare_file("{}/analysis_store.text.gz".format(ctx.label.name)) mains_file = ctx.actions.declare_file("{}.jar.mains.txt".format(ctx.label.name)) used = ctx.actions.declare_file("{}/deps_used.txt".format(ctx.label.name)) tmp = ctx.actions.declare_directory("{}/tmp".format(ctx.label.name)) @@ -77,7 +76,6 @@ def phase_zinc_compile(ctx, g): g.classpaths.jar, mains_file, analysis_store, - analysis_store_text, used, tmp, ] + g.semanticdb.outputs diff --git a/src/main/scala/higherkindness/rules_scala/workers/zinc/compile/ZincRunner.scala b/src/main/scala/higherkindness/rules_scala/workers/zinc/compile/ZincRunner.scala index a82bf92e..a88606d2 100644 --- a/src/main/scala/higherkindness/rules_scala/workers/zinc/compile/ZincRunner.scala +++ b/src/main/scala/higherkindness/rules_scala/workers/zinc/compile/ZincRunner.scala @@ -302,11 +302,6 @@ object ZincRunner extends WorkerMain[ZincRunnerWorkerConfig] { // create analyses val pathString = analysisStorePath.toAbsolutePath().normalize().toString() - val analysisStoreText = AnalysisUtil.getAnalysisStore( - new File(pathString.substring(0, pathString.length() - 3) + ".text.gz"), - true, - readWriteMappers, - ) // Filter out libraryClassNames from the analysis because it is non-deterministic. // Can stop doing this once the bug in Zinc is fixed. Check the comment on FilteredRelations // for more info. @@ -317,7 +312,18 @@ object ZincRunner extends WorkerMain[ZincRunnerWorkerConfig] { infos = FilteredInfos.getFilteredInfos(originalResultAnalysis.infos), ) } - analysisStoreText.set(AnalysisContents.create(resultAnalysis, compileResult.setup)) + + // This will be true if the `--worker_verbose` Bazel flag is set + if (verbosity >= 10) { + val analysisStoreText = AnalysisUtil.getAnalysisStore( + new File(pathString.substring(0, pathString.length() - 3) + ".text.gz"), + true, + readWriteMappers, + ) + + analysisStoreText.set(AnalysisContents.create(resultAnalysis, compileResult.setup)) + } + analysisStore.set(AnalysisContents.create(resultAnalysis, compileResult.setup)) // create used deps From e58569bcf463dfd66678cb1df131ece25e237b6d Mon Sep 17 00:00:00 2001 From: Jaden Peterson Date: Thu, 19 Dec 2024 13:10:25 -0500 Subject: [PATCH 3/4] Use .view where appropriate --- .../rules_scala/workers/zinc/compile/ZincRunner.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/scala/higherkindness/rules_scala/workers/zinc/compile/ZincRunner.scala b/src/main/scala/higherkindness/rules_scala/workers/zinc/compile/ZincRunner.scala index a88606d2..871d41f1 100644 --- a/src/main/scala/higherkindness/rules_scala/workers/zinc/compile/ZincRunner.scala +++ b/src/main/scala/higherkindness/rules_scala/workers/zinc/compile/ZincRunner.scala @@ -209,8 +209,8 @@ object ZincRunner extends WorkerMain[ZincRunnerWorkerConfig] { val compileOptions = CompileOptions.create - .withSources(sources.map(source => PlainVirtualFile(source.toAbsolutePath().normalize())).toArray) - .withClasspath((classesOutputDir +: deps.map(_.classpath)).map(path => PlainVirtualFile(path)).toArray) + .withSources(sources.view.map(source => PlainVirtualFile(source.toAbsolutePath().normalize())).toArray) + .withClasspath((classesOutputDir +: deps.view.map(_.classpath)).map(path => PlainVirtualFile(path)).toArray) .withClassesDirectory(classesOutputDir) .withJavacOptions(workRequest.javaCompilerOptions) .withScalacOptions( @@ -333,7 +333,7 @@ object ZincRunner extends WorkerMain[ZincRunnerWorkerConfig] { deps.filter(Dep.used(deps, resultAnalysis.relations, lookup)).filterNot { dep => val filteredDepFileName = FileUtil.getNameWithoutRulesJvmExternalStampPrefix(dep.file) - scalaInstance.libraryJars + scalaInstance.libraryJars.view .map(FileUtil.getNameWithoutRulesJvmExternalStampPrefix) .contains(filteredDepFileName) } From 4f8c6d13b7bf6d2189cebfa9932788b5e7987a74 Mon Sep 17 00:00:00 2001 From: Jaden Peterson Date: Fri, 20 Dec 2024 10:27:25 -0500 Subject: [PATCH 4/4] Added a .bazelversion to tests --- tests/.bazelversion | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/.bazelversion diff --git a/tests/.bazelversion b/tests/.bazelversion new file mode 100644 index 00000000..815da58b --- /dev/null +++ b/tests/.bazelversion @@ -0,0 +1 @@ +7.4.1