Skip to content

Commit

Permalink
Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrodriguez committed Jun 2, 2022
1 parent ba1608e commit a6a1664
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public Apply(StructuredGraph graph, CoreProviders context, CanonicalizerPhase ca
public void close(Throwable throwable) {
scope.close();
if (throwable == null) {
// Perform the canonicalization if the main work completed without an exception.
if (!listener.getNodes().isEmpty()) {
canonicalizer.applyIncremental(graph, context, listener.getNodes());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,20 @@ protected boolean shouldDumpAfterAtBasicLevel() {
return false;
}

/**
* Similar to a {@link DebugCloseable} but the {@link #close} operation gets a {@link Throwable}
* argument indicating whether the call to {@link #run} completed normally or with an exception.
*/
public interface ApplyScope {
void close(Throwable t);
}

/**
* An extension point for subclasses, called at the start of
* {@link BasePhase#apply(StructuredGraph, Object, boolean)}. The return value is a
* {@link DebugCloseable scope} which will surround all the work performed by the
* {@link #apply}. This allows subclaseses to inject work which will performed before and after
* the application of this phase.
* {@link ApplyScope} which will surround all the work performed by the {@link #apply}. This
* allows subclaseses to inject work which will performed before and after the application of
* this phase.
*/
@SuppressWarnings("unused")
protected ApplyScope applyScope(StructuredGraph graph, C context) {
Expand Down Expand Up @@ -251,6 +255,8 @@ public final void apply(final StructuredGraph graph, final C context, final bool
}
inputNodesCount.add(debug, graph.getNodeCount());

// This is a manual version of a try/resource pattern since the close operation might
// want to know whether the run call completed with an exception or not.
ApplyScope applyScope = applyScope(graph, context);
Throwable throwable = null;
try {
Expand Down

0 comments on commit a6a1664

Please sign in to comment.