InlineAndCollapseProperties: move decisions log creation
Create the decisions log in the process method of the outer class, so all the
inner classes can share it.
@@ -109,6 +109,14 @@ class InlineAndCollapseProperties implements CompilerPass {
*/
private final Optional<Consumer<GlobalNamespace>> optionalGlobalNamespaceTester;
+ /**
+ * Records decisions made by this class and related logic.
+ *
+ * <p>This field is allocated and cleaned up by process(). It's a class field to avoid having to
+ * pass it as an extra argument through a lot of methods.
+ */
+ private LogFile decisionsLog = null;
+
private InlineAndCollapseProperties(Builder builder) {
this.compiler = builder.compiler;
this.propertyCollapseLevel = builder.propertyCollapseLevel;
@@ -174,6 +182,10 @@ class InlineAndCollapseProperties implements CompilerPass {
!testAggressiveInliningOnly || propertyCollapseLevel == PropertyCollapseLevel.ALL,
"testAggressiveInlining is invalid for: %s",
propertyCollapseLevel);
+ try (LogFile logFile = compiler.createOrReopenIndexedLog(this.getClass(), "decisions.log")) {
+ // NOTE: decisionsLog will be a do-nothing proxy object unless the compiler
+ // was given an option telling it to generate log files and where to put them.
+ decisionsLog = logFile;
switch (propertyCollapseLevel) {
case NONE:
performMinimalInliningAndNoCollapsing(externs, root);
@@ -189,6 +201,9 @@ class InlineAndCollapseProperties implements CompilerPass {
}
break;
}
+ } finally {
+ decisionsLog = null;
+ }
}
private void performMinimalInliningAndNoCollapsing(Node externs, Node root) {
@@ -1172,21 +1187,8 @@ class InlineAndCollapseProperties implements CompilerPass {
private final HashSet<String> dynamicallyImportedModules = new HashSet<>();
- /**
- * Records decisions made by this class.
- *
- * <p>This field is allocated and cleaned up by process(). It's a class field to avoid having to
- * pass it as an extra argument through a lot of methods.
- */
- private LogFile decisionsLog = null;
-
@Override
public void process(Node externs, Node root) {
- try (LogFile decisionsLog =
- compiler.createOrReopenIndexedLog(this.getClass(), "decisions.log")) {
- // NOTE: decisionsLog will be a do-nothing proxy object unless the compiler
- // was given an option telling it to generate log files and where to put them.
- this.decisionsLog = decisionsLog;
if (propertyCollapseLevel == PropertyCollapseLevel.MODULE_EXPORT
|| chunkOutputType == ChunkOutputType.ES_MODULES) {
NodeTraversal.traverse(
@@ -1211,9 +1213,6 @@ class InlineAndCollapseProperties implements CompilerPass {
// constant.
// TODO(b/64256754): Investigate.
new PropagateConstantAnnotationsOverVars(compiler, false).process(externs, root);
- } finally {
- decisionsLog = null;
- }
}
private boolean canCollapse(Name name) {
