Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

call close() on compiler in scalacWorker after each job #1504

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/java/io/bazel/rulesscala/scalac/ReportableMainClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,28 @@
import scala.tools.nsc.MainClass;
import scala.tools.nsc.Settings;
import scala.tools.nsc.reporters.Reporter;
import java.lang.AutoCloseable;

public class ReportableMainClass extends MainClass {
private Reporter reporter;
private final CompileOptions ops;
private Global _compiler = null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: uncommon in Java style to prefix private vars with underscore - please rename to compiler

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.


public ReportableMainClass(CompileOptions ops) {
this.ops = ops;
}

public void Close() throws Exception{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style nit: don't start method names with a capital letter. Please rename to close()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if(_compiler != null){

//nsc.Global didn't inherit from Closeable until 2.12.9.
if(_compiler instanceof AutoCloseable){
((AutoCloseable)_compiler).close();
}
_compiler = null;
}
}

@Override
public Global newCompiler() {
createDiagnosticsFile();
Expand All @@ -31,7 +44,8 @@ public Global newCompiler() {

reporter = new DepsTrackingReporter(settings, ops, reporter);

return new Global(settings, reporter);
_compiler = new Global(settings, reporter);
return _compiler;
}

private void createDiagnosticsFile() {
Expand Down
6 changes: 5 additions & 1 deletion src/java/io/bazel/rulesscala/scalac/ScalacWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private static boolean isMacroException(Throwable ex) {
}

private static void compileScalaSources(CompileOptions ops, String[] scalaSources, Path classes)
throws IOException {
throws IOException, Exception {

String[] pluginArgs = buildPluginArgs(ops.plugins);
String[] pluginParams = getPluginParamsFrom(ops);
Expand All @@ -285,7 +285,11 @@ private static void compileScalaSources(CompileOptions ops, String[] scalaSource
} else {
throw ex;
}
}finally {
comp.Close();
}


long stop = System.currentTimeMillis();
if (ops.printCompileTime) {
System.err.println("Compiler runtime: " + (stop - start) + "ms.");
Expand Down