Skip to content

Commit

Permalink
Now, when we can dump just a single module, we can do it synchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Jan 22, 2025
1 parent c89fca2 commit 116b650
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import java.util.HashMap;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import org.enso.compiler.core.ir.Module;
import org.enso.compiler.dump.service.IRDumper;
import org.graalvm.graphio.GraphOutput;
Expand All @@ -24,7 +22,6 @@ public final class IGVDumper implements IRDumper {
private final String moduleName;
private final Path outPath;
private final GraphOutput<EnsoModuleAST, ASTMethod> graphOutput;
private final ExecutorService executor;
private final ConcurrentLinkedQueue<CompletableFuture<Void>> tasks =
new ConcurrentLinkedQueue<>();
private int currGraphId;
Expand All @@ -34,17 +31,13 @@ public final class IGVDumper implements IRDumper {
private int nodesCnt;

private IGVDumper(
String moduleName,
Path outPath,
GraphOutput<EnsoModuleAST, ASTMethod> graphOutput,
ExecutorService executor) {
String moduleName, Path outPath, GraphOutput<EnsoModuleAST, ASTMethod> graphOutput) {
this.moduleName = moduleName;
this.outPath = outPath;
this.graphOutput = graphOutput;
this.executor = executor;
}

static IGVDumper createForModule(String moduleName, ExecutorService executor) {
static IGVDumper createForModule(String moduleName) {
var outPath = outputForModule(moduleName);
var channel = createFileChannel(outPath);
GraphOutput<EnsoModuleAST, ASTMethod> graphOutput;
Expand All @@ -59,15 +52,13 @@ static IGVDumper createForModule(String moduleName, ExecutorService executor) {
LOGGER.error("Failed to create graph output for module {}", moduleName, e);
return null;
}
return new IGVDumper(moduleName, outPath, graphOutput, executor);
return new IGVDumper(moduleName, outPath, graphOutput);
}

@Override
public void dump(Module ir, String moduleName, File srcFile, String afterPass) {
assert moduleName.equals(this.moduleName);
var task =
CompletableFuture.runAsync(() -> dumpTask(ir, moduleName, srcFile, afterPass), executor);
tasks.add(task);
dumpTask(ir, moduleName, srcFile, afterPass);
}

private void dumpTask(Module ir, String moduleName, File srcFile, String afterPass) {
Expand All @@ -93,13 +84,6 @@ private void dumpTask(Module ir, String moduleName, File srcFile, String afterPa

@Override
public void close() {
var tasksArr = tasks.toArray(CompletableFuture[]::new);
var allTasks = CompletableFuture.allOf(tasksArr);
try {
allTasks.get();
} catch (InterruptedException | ExecutionException e) {
LOGGER.error("Failed to wait for all tasks to complete", e);
}
try {
graphOutput.endGroup();
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
package org.enso.compiler.dump.igv;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.enso.compiler.dump.service.IRDumpFactoryService;
import org.enso.compiler.dump.service.IRDumper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class IGVDumperFactory implements IRDumpFactoryService {

private static final Logger LOGGER = LoggerFactory.getLogger(IGVDumperFactory.class);
private final ExecutorService executor;

public IGVDumperFactory() {
this.executor = Executors.newVirtualThreadPerTaskExecutor();
}
public IGVDumperFactory() {}

@Override
public IRDumper create(String moduleName) {
LOGGER.trace("Creating IGV dumper for module {}", moduleName);
return IGVDumper.createForModule(moduleName, executor);
return IGVDumper.createForModule(moduleName);
}

@Override
public void shutdown() {
executor.shutdown();
}
public void shutdown() {}
}

0 comments on commit 116b650

Please sign in to comment.