Skip to content

Commit

Permalink
Split methods for stage 1 and stage 2 compilation.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=155572139
  • Loading branch information
brad4d authored and dimvar committed May 10, 2017
1 parent 72db3fc commit 389dec8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
10 changes: 8 additions & 2 deletions src/com/google/javascript/jscomp/AbstractCommandLineRunner.java
Expand Up @@ -1138,7 +1138,10 @@ private Result performFullCompilationWithModules(
if (options.getInstrumentForCoverageOnly()) { if (options.getInstrumentForCoverageOnly()) {
compiler.instrumentForCoverage(); compiler.instrumentForCoverage();
} else { } else {
compiler.stage1AndStage2Passes(); compiler.stage1Passes();
if (!compiler.hasErrors()) {
compiler.stage2Passes();
}
} }
compiler.completeCompilation(); compiler.completeCompilation();
} }
Expand All @@ -1161,7 +1164,10 @@ private Result performFullCompilation(
if (options.getInstrumentForCoverageOnly()) { if (options.getInstrumentForCoverageOnly()) {
compiler.instrumentForCoverage(); compiler.instrumentForCoverage();
} else { } else {
compiler.stage1AndStage2Passes(); compiler.stage1Passes();
if (!compiler.hasErrors()) {
compiler.stage2Passes();
}
} }
compiler.completeCompilation(); compiler.completeCompilation();
} }
Expand Down
48 changes: 39 additions & 9 deletions src/com/google/javascript/jscomp/Compiler.java
Expand Up @@ -760,7 +760,10 @@ public <T1 extends SourceFile, T2 extends SourceFile> Result compile(
// runner, not the compiler. // runner, not the compiler.
instrumentForCoverage(); instrumentForCoverage();
} else { } else {
stage1AndStage2Passes(); stage1Passes();
if (!hasErrors()) {
stage2Passes();
}
} }
completeCompilation(); completeCompilation();
} }
Expand Down Expand Up @@ -809,7 +812,10 @@ public <T extends SourceFile> Result compileModules(
if (options.getInstrumentForCoverageOnly()) { if (options.getInstrumentForCoverageOnly()) {
instrumentForCoverage(); instrumentForCoverage();
} else { } else {
stage1AndStage2Passes(); stage1Passes();
if (!hasErrors()) {
stage2Passes();
}
} }
completeCompilation(); completeCompilation();
} }
Expand All @@ -820,16 +826,16 @@ public <T extends SourceFile> Result compileModules(
} }


/** /**
* Perform checks transpilation and optimization. * Perform compiler passes for stage 1 of compilation.
*
* <p>Stage 1 consists primarily of error and type checking passes.
* *
* <p>{@code parseForCompilation()} must be called before this method is called. * <p>{@code parseForCompilation()} must be called before this method is called.
* *
* <p>The caller is responsible for also calling {@code generateReport()} to generate a report of * <p>The caller is responsible for also calling {@code generateReport()} to generate a report of
* warnings and errors to stderr. See the invocation in {@link #compile} for a good example. * warnings and errors to stderr. See the invocation in {@link #compile} for a good example.
*
* <p>TODO(bradfordcsmith): Break this up into stage1Passes() and stage2Passes().
*/ */
public void stage1AndStage2Passes() { public void stage1Passes() {
checkState( checkState(
inputs != null && !inputs.isEmpty(), "No inputs. Did you call init() or initModules()?"); inputs != null && !inputs.isEmpty(), "No inputs. Did you call init() or initModules()?");
checkState(!hasErrors()); checkState(!hasErrors());
Expand All @@ -839,7 +845,31 @@ public void stage1AndStage2Passes() {
@Override @Override
public Void call() throws Exception { public Void call() throws Exception {
performChecksAndTranspilation(); performChecksAndTranspilation();
if (!hasErrors() && options.shouldOptimize()) { return null;
}
});
}

/**
* Perform compiler passes for stage 2 of compilation.
*
* <p>Stage 2 consists primarily of optimization passes.
*
* <p>{@code stage1Passes()} must be called before this method is called.
*
* <p>The caller is responsible for also calling {@code generateReport()} to generate a report of
* warnings and errors to stderr. See the invocation in {@link #compile} for a good example.
*/
public void stage2Passes() {
checkState(
inputs != null && !inputs.isEmpty(), "No inputs. Did you call init() or initModules()?");
checkState(!hasErrors());
checkState(!options.getInstrumentForCoverageOnly());
runInCompilerThread(
new Callable<Void>() {
@Override
public Void call() throws Exception {
if (options.shouldOptimize()) {
performOptimizations(); performOptimizations();
} }
return null; return null;
Expand Down Expand Up @@ -929,8 +959,8 @@ private void completeCompilationInternal() {
* <p>The caller is responsible for also calling {@code generateReport()} to generate a report of * <p>The caller is responsible for also calling {@code generateReport()} to generate a report of
* warnings and errors to stderr. See the invocation in {@link #compile} for a good example. * warnings and errors to stderr. See the invocation in {@link #compile} for a good example.
* *
* <p>Do not call both this and stage1AndStage2Passes(). They should be considered mutually * <p>This method is mutually exclusive with stage1Passes() and stage2Passes().
* exclusive. * Either call those two methods or this one, but not both.
*/ */
public void instrumentForCoverage() { public void instrumentForCoverage() {
checkState( checkState(
Expand Down

0 comments on commit 389dec8

Please sign in to comment.