Skip to content

Commit cd9beb1

Browse files
lauraharkercopybara-github
authored andcommitted
Make CompilerOptions.customPasses private instead of protected
PiperOrigin-RevId: 853481799
1 parent 7ef9d2d commit cd9beb1

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

src/com/google/javascript/jscomp/Compiler.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,15 +1418,14 @@ private void runValidityCheck() {
14181418

14191419
/** Runs custom passes that are designated to run at a particular time. */
14201420
private void runCustomPasses(CustomPassExecutionTime executionTime) {
1421-
if (options.customPasses != null) {
1422-
Tracer t = newTracer("runCustomPasses");
1423-
try {
1424-
for (CompilerPass p : options.customPasses.get(executionTime)) {
1425-
process(p);
1426-
}
1427-
} finally {
1428-
stopTracer(t, "runCustomPasses");
1421+
ImmutableList<CompilerPass> customPasses = options.getCustomPassesAt(executionTime);
1422+
Tracer t = newTracer("runCustomPasses");
1423+
try {
1424+
for (CompilerPass p : customPasses) {
1425+
process(p);
14291426
}
1427+
} finally {
1428+
stopTracer(t, "runCustomPasses");
14301429
}
14311430
}
14321431

src/com/google/javascript/jscomp/CompilerOptions.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import com.google.common.collect.ImmutableMap;
3030
import com.google.common.collect.ImmutableSet;
3131
import com.google.common.collect.LinkedHashMultimap;
32-
import com.google.common.collect.Multimap;
32+
import com.google.common.collect.SetMultimap;
3333
import com.google.common.primitives.Chars;
3434
import com.google.errorprone.annotations.CanIgnoreReturnValue;
3535
import com.google.errorprone.annotations.RestrictedApi;
@@ -802,7 +802,7 @@ public boolean shouldRunReplaceMessagesForChrome() {
802802
ImmutableSet<String> stripNamePrefixes;
803803

804804
/** Custom passes */
805-
protected transient @Nullable Multimap<CustomPassExecutionTime, CompilerPass> customPasses;
805+
private transient @Nullable SetMultimap<CustomPassExecutionTime, CompilerPass> customPasses;
806806

807807
/** Replacements for @defines. Will be Boolean, Numbers, or Strings */
808808
private final LinkedHashMap<String, Object> defineReplacements;
@@ -2844,6 +2844,12 @@ public void addCustomPass(CustomPassExecutionTime time, CompilerPass customPass)
28442844
customPasses.put(time, customPass);
28452845
}
28462846

2847+
ImmutableList<CompilerPass> getCustomPassesAt(CustomPassExecutionTime executionTime) {
2848+
return this.customPasses == null
2849+
? ImmutableList.of()
2850+
: ImmutableList.copyOf(this.customPasses.get(executionTime));
2851+
}
2852+
28472853
public void setDefineReplacements(Map<String, Object> defineReplacements) {
28482854
this.defineReplacements.clear();
28492855
this.defineReplacements.putAll(defineReplacements);

src/com/google/javascript/jscomp/DefaultPassConfig.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,9 +1059,7 @@ private PassListBuilder getLateOptimizationPasses() {
10591059
passes.maybeAdd(devirtualizeMethods);
10601060
}
10611061

1062-
if (options.customPasses != null) {
1063-
passes.maybeAdd(getCustomPasses(CustomPassExecutionTime.BEFORE_OPTIMIZATION_LOOP));
1064-
}
1062+
passes.maybeAdd(getCustomPasses(CustomPassExecutionTime.BEFORE_OPTIMIZATION_LOOP));
10651063

10661064
passes.maybeAdd(createEmptyPass(PassNames.BEFORE_MAIN_OPTIMIZATIONS));
10671065

@@ -1077,9 +1075,7 @@ private PassListBuilder getLateOptimizationPasses() {
10771075

10781076
// Some optimizations belong outside the loop because running them more
10791077
// than once would either have no benefit or be incorrect.
1080-
if (options.customPasses != null) {
1081-
passes.maybeAdd(getCustomPasses(CustomPassExecutionTime.AFTER_OPTIMIZATION_LOOP));
1082-
}
1078+
passes.maybeAdd(getCustomPasses(CustomPassExecutionTime.AFTER_OPTIMIZATION_LOOP));
10831079

10841080
assertValidOrderForOptimizations(passes);
10851081
return passes;
@@ -2709,7 +2705,7 @@ private final PassFactory createGatherExternProperties(GatherExternProperties.Mo
27092705
private PassFactory getCustomPasses(final CustomPassExecutionTime executionTime) {
27102706
return PassFactory.builder()
27112707
.setName("runCustomPasses")
2712-
.setInternalFactory((compiler) -> runInSerial(options.customPasses.get(executionTime)))
2708+
.setInternalFactory((compiler) -> runInSerial(options.getCustomPassesAt(executionTime)))
27132709
.build();
27142710
}
27152711

0 commit comments

Comments
 (0)