Skip to content

Commit

Permalink
Rename SanityCheck to ValidityCheck
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=171729614
  • Loading branch information
tbreisacher committed Oct 11, 2017
1 parent e4118f3 commit dee15e7
Show file tree
Hide file tree
Showing 23 changed files with 83 additions and 95 deletions.
3 changes: 0 additions & 3 deletions src/com/google/debugging/sourcemap/SourceMapConsumerV3.java
Expand Up @@ -291,9 +291,6 @@ private void completeLine(ArrayList<Entry> entries) {
previousCol = 0;
}

/**
* Sanity check the entry.
*/
private void validateEntry(Entry entry) {
Preconditions.checkState((lineCount < 0) || (line < lineCount),
"line=%s, lineCount=%s", line, lineCount);
Expand Down
Expand Up @@ -2095,7 +2095,7 @@ public CommandLineConfig setPrintPassGraph(boolean printPassGraph) {

private CompilerOptions.DevMode jscompDevMode = CompilerOptions.DevMode.OFF;

/** Turns on extra sanity checks */
/** Turns on extra validity checks */
public CommandLineConfig setJscompDevMode(CompilerOptions.DevMode jscompDevMode) {
this.jscompDevMode = jscompDevMode;
return this;
Expand Down
5 changes: 2 additions & 3 deletions src/com/google/javascript/jscomp/CodeGenerator.java
Expand Up @@ -334,9 +334,8 @@ protected void add(Node n, Context context) {
{
checkState(childCount == 1);

// It's important to our sanity checker that the code
// we print produces the same AST as the code we parse back.
// NEG is a weird case because Rhino parses "- -2" as "2".
// It's important to our validity checker that the code we print produces the same AST as
// the code we parse back. NEG is a weird case because Rhino parses "- -2" as "2".
if (n.getFirstChild().isNumber()) {
cc.addNumber(-n.getFirstChild().getDouble(), n.getFirstChild());
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/com/google/javascript/jscomp/CommandLineRunner.java
Expand Up @@ -177,8 +177,7 @@ private static class Flags {
usage = "Assume input sources are to run in strict mode.")
private boolean strictModeInput = true;

// Turn on (very slow) extra sanity checks for use when modifying the
// compiler.
// Turn on (very slow) extra validity checks for use when modifying the compiler.
@Option(
name = "--jscomp_dev_mode",
hidden = true,
Expand Down
21 changes: 10 additions & 11 deletions src/com/google/javascript/jscomp/Compiler.java
Expand Up @@ -902,7 +902,7 @@ private void performPostCompilationTasksInternal() {
}

if (options.devMode == DevMode.START_AND_END) {
runSanityCheck();
runValidityCheck();
}
setProgress(1.0, "recordFunctionInformation");

Expand Down Expand Up @@ -1055,7 +1055,7 @@ public void transpileAndDontCheck() {
private PhaseOptimizer createPhaseOptimizer() {
PhaseOptimizer phaseOptimizer = new PhaseOptimizer(this, tracker);
if (options.devMode == DevMode.EVERY_PASS) {
phaseOptimizer.setSanityCheck(sanityCheck);
phaseOptimizer.setValidityCheck(validityCheck);
}
if (options.getCheckDeterminism()) {
phaseOptimizer.setPrintAstHashcodes(true);
Expand Down Expand Up @@ -1090,22 +1090,21 @@ void process(CompilerPass p) {
p.process(externsRoot, jsRoot);
}

private final PassFactory sanityCheck =
new PassFactory("sanityCheck", false) {
private final PassFactory validityCheck = new PassFactory("validityCheck", false) {
@Override
protected CompilerPass create(AbstractCompiler compiler) {
return new SanityCheck(compiler);
return new ValidityCheck(compiler);
}
};

private void maybeSanityCheck() {
private void maybeRunValidityCheck() {
if (options.devMode == DevMode.EVERY_PASS) {
runSanityCheck();
runValidityCheck();
}
}

private void runSanityCheck() {
sanityCheck.create(this).process(externsRoot, jsRoot);
private void runValidityCheck() {
validityCheck.create(this).process(externsRoot, jsRoot);
}

/**
Expand Down Expand Up @@ -1147,7 +1146,7 @@ void endPass(String passName) {
currentPassName = null;
currentTracer = null;

maybeSanityCheck();
maybeRunValidityCheck();
}

@Override
Expand Down Expand Up @@ -1811,7 +1810,7 @@ Node parseInputs() {
}

if (devMode) {
runSanityCheck();
runValidityCheck();
if (hasErrors()) {
return null;
}
Expand Down
6 changes: 3 additions & 3 deletions src/com/google/javascript/jscomp/CompilerOptions.java
Expand Up @@ -252,7 +252,7 @@ boolean shouldPrintExterns() {
boolean skipNonTranspilationPasses;

/**
* Configures the compiler to run expensive sanity checks after
* Configures the compiler to run expensive validity checks after
* every pass. Only intended for internal development.
*/
DevMode devMode;
Expand Down Expand Up @@ -3145,10 +3145,10 @@ FeatureSet toFeatureSet() {
}
}

/** When to do the extra sanity checks */
/** When to do the extra validity checks */
public static enum DevMode {
/**
* Don't do any extra sanity checks.
* Don't do any extra checks.
*/
OFF,

Expand Down
13 changes: 6 additions & 7 deletions src/com/google/javascript/jscomp/DefaultPassConfig.java
Expand Up @@ -940,8 +940,8 @@ protected List<PassFactory> getOptimizations() {
}

// Safety checks
passes.add(sanityCheckAst);
passes.add(sanityCheckVars);
passes.add(checkAstValidity);
passes.add(varCheckValidity);

// Raise to ES6, if allowed
if (options.getLanguageOut().toFeatureSet().contains(FeatureSet.ES6)) {
Expand Down Expand Up @@ -3140,9 +3140,8 @@ protected FeatureSet featureSet() {
}
};

/** Checks that all variables are defined. */
private final PassFactory sanityCheckAst =
new PassFactory("sanityCheckAst", true) {
private final PassFactory checkAstValidity =
new PassFactory("checkAstValidity", true) {
@Override
protected CompilerPass create(AbstractCompiler compiler) {
return new AstValidator(compiler);
Expand All @@ -3155,8 +3154,8 @@ protected FeatureSet featureSet() {
};

/** Checks that all variables are defined. */
private final PassFactory sanityCheckVars =
new PassFactory("sanityCheckVars", true) {
private final PassFactory varCheckValidity =
new PassFactory("varCheckValidity", true) {
@Override
protected CompilerPass create(AbstractCompiler compiler) {
return new VarCheck(compiler, true);
Expand Down
5 changes: 3 additions & 2 deletions src/com/google/javascript/jscomp/Es6RewriteGenerators.java
Expand Up @@ -905,7 +905,8 @@ private void visitLoop(String label) {
guard = currentStatement.removeFirstChild();
}

Node condition, prestatement;
Node condition;
Node prestatement;

if (guard.isNormalBlock()) {
prestatement = guard.removeFirstChild();
Expand Down Expand Up @@ -1375,7 +1376,7 @@ static Node preloadGeneratorSkeletonAndReportChange(AbstractCompiler compiler) {
* If the skeleton is already preloaded, does not do anything, just returns the node.
* reportChange tells the function whether to report a code change in the enclosing scope.
*
* Because sanity checks happen between passes, we need to report the change if the generator
* Because validity checks happen between passes, we need to report the change if the generator
* was preloaded in the {@link EarlyEs6ToEs3Converter} class.
* However, if the generator was preloaded in this {@link Es6RewriteGenerators} class, we do not
* want to report the change since it will be removed by {@link #cleanUpGeneratorSkeleton}
Expand Down
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/InlineFunctions.java
Expand Up @@ -853,7 +853,7 @@ void removeInlinedFunctions() {
}
}

/** Sanity check to verify, that expression rewriting didn't make a call inaccessible. */
/** Check to verify that expression rewriting didn't make a call inaccessible. */
void verifyAllReferencesInlined(FunctionState functionState) {
for (Reference ref : functionState.getReferences()) {
if (!ref.inlined) {
Expand Down
Expand Up @@ -138,7 +138,6 @@ private void hoistConstantLikeField(Node clinitAssignment, Node declarationAssig
}
declarationInClass.putBooleanProp(Node.IS_CONSTANT_VAR, true);

// Sanity check
checkState(NodeUtil.isLiteralValue(declarationAssignedValue, false /* includeFunctions */));
}

Expand Down
28 changes: 14 additions & 14 deletions src/com/google/javascript/jscomp/PhaseOptimizer.java
Expand Up @@ -43,7 +43,7 @@ class PhaseOptimizer implements CompilerPass {
private final PerformanceTracker tracker;
private final List<CompilerPass> passes;
private boolean inLoop;
private PassFactory sanityCheck;
private PassFactory validityCheck;
private boolean printAstHashcodes = false;

private double progress = 0.0;
Expand All @@ -64,7 +64,7 @@ class PhaseOptimizer implements CompilerPass {

private final boolean useSizeHeuristicToStopOptimizationLoop;

// Used for sanity checking passes
// Checks that passes have reported code changes correctly.
private ChangeVerifier changeVerifier;

/**
Expand Down Expand Up @@ -191,10 +191,10 @@ Loop addFixedPointLoop() {
}

/**
* Adds a sanity checker to be run after every pass. Intended for development.
* Adds a checker to be run after every pass. Intended for development.
*/
void setSanityCheck(PassFactory sanityCheck) {
this.sanityCheck = sanityCheck;
void setValidityCheck(PassFactory validityCheck) {
this.validityCheck = validityCheck;
this.changeVerifier = new ChangeVerifier(compiler).snapshot(jsRoot);
}

Expand Down Expand Up @@ -244,17 +244,17 @@ private void maybePrintAstHashcodes(String passName, Node root) {
}

/**
* Runs the sanity check if it is available.
* Runs the validity check if it is available.
*/
private void maybeSanityCheck(String passName, Node externs, Node root) {
if (sanityCheck == null) {
private void maybeRunValidityCheck(String passName, Node externs, Node root) {
if (validityCheck == null) {
return;
}
try {
sanityCheck.create(compiler).process(externs, root);
validityCheck.create(compiler).process(externs, root);
changeVerifier.checkRecordedChanges(passName, jsRoot);
} catch (Exception e) {
throw new IllegalStateException("Sanity check failed for pass: " + passName, e);
throw new IllegalStateException("Validity checks failed for pass: " + passName, e);
}
}

Expand Down Expand Up @@ -286,8 +286,8 @@ public void process(Node externs, Node root) {
}

logger.fine("Running pass " + name);
if (sanityCheck != null) {
// Before running the pass, clone the AST so you can sanity-check the
if (validityCheck != null) {
// Before running the pass, clone the AST so you can check the
// changed AST against the clone after the pass finishes.
changeVerifier = new ChangeVerifier(compiler).snapshot(jsRoot);
}
Expand Down Expand Up @@ -320,11 +320,11 @@ public void process(Node externs, Node root) {
tracker.recordPassStop(name, traceRuntime);
}
maybePrintAstHashcodes(name, root);
maybeSanityCheck(name, externs, root);
maybeRunValidityCheck(name, externs, root);
} catch (IllegalStateException e) {
// TODO(johnlenz): Remove this once the normalization checks report
// errors instead of exceptions.
throw new RuntimeException("Sanity check failed for " + name, e);
throw new RuntimeException("Validity check failed for " + name, e);
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/com/google/javascript/jscomp/PrepareAst.java
Expand Up @@ -57,9 +57,8 @@ public void process(Node externs, Node root) {
normalizeNodeTypes(root);
} else {
// Don't perform "PrepareAnnotations" when doing checks as
// they currently aren't valid during sanity checks. In particular,
// they DIRECT_EVAL shouldn't be applied after inlining has been
// performed.
// they currently aren't valid during validity checks. In particular,
// they DIRECT_EVAL shouldn't be applied after inlining has been performed.
if (externs != null) {
NodeTraversal.traverseEs6(
compiler, externs, new PrepareAnnotations());
Expand Down
Expand Up @@ -42,18 +42,18 @@
class SourceInformationAnnotator extends
NodeTraversal.AbstractPostOrderCallback {
private final String sourceFile;
private final boolean doSanityChecks;
private final boolean checkAnnotated;

public SourceInformationAnnotator(
String sourceFile, boolean doSanityChecks) {
String sourceFile, boolean checkAnnotated) {
this.sourceFile = sourceFile;
this.doSanityChecks = doSanityChecks;
this.checkAnnotated = checkAnnotated;
}

@Override
public void visit(NodeTraversal t, Node n, Node parent) {
// Verify the source file is annotated.
if (doSanityChecks && sourceFile != null) {
if (checkAnnotated && sourceFile != null) {
checkState(sourceFile.equals(n.getSourceFileName()));
}

Expand Down
Expand Up @@ -25,7 +25,7 @@
*
* @author nicksantos@google.com (Nick Santos)
*/
class SanityCheck implements CompilerPass {
class ValidityCheck implements CompilerPass {

static final DiagnosticType CANNOT_PARSE_GENERATED_CODE =
DiagnosticType.error("JSC_CANNOT_PARSE_GENERATED_CODE",
Expand All @@ -47,29 +47,29 @@ class SanityCheck implements CompilerPass {
private final AbstractCompiler compiler;
private final AstValidator astValidator;

SanityCheck(AbstractCompiler compiler) {
ValidityCheck(AbstractCompiler compiler) {
this.compiler = compiler;
this.astValidator = new AstValidator(compiler);
}

@Override
public void process(Node externs, Node root) {
sanityCheckAst(externs, root);
sanityCheckNormalization(externs, root);
sanityCheckCodeGeneration(root);
sanityCheckVars(externs, root);
sanityCheckExternProperties(externs);
checkAst(externs, root);
checkNormalization(externs, root);
checkCodeGeneration(root);
checkVars(externs, root);
checkExternProperties(externs);
}

/**
* Sanity check the AST is structurally accurate.
* Check that the AST is structurally accurate.
*/
private void sanityCheckAst(Node externs, Node root) {
private void checkAst(Node externs, Node root) {
astValidator.validateCodeRoot(externs);
astValidator.validateCodeRoot(root);
}

private void sanityCheckVars(Node externs, Node root) {
private void checkVars(Node externs, Node root) {
if (compiler.getLifeCycleStage().isNormalized()) {
(new VarCheck(compiler, true)).process(externs, root);
}
Expand All @@ -82,15 +82,15 @@ private void sanityCheckVars(Node externs, Node root) {
*
* @return The regenerated parse tree. Null on error.
*/
private Node sanityCheckCodeGeneration(Node root) {
private Node checkCodeGeneration(Node root) {
if (compiler.hasHaltingErrors()) {
// Don't even bother checking code generation if we already know the
// the code is bad.
return null;
}

String source = compiler.toSource(root);
Node root2 = compiler.parseSyntheticCode("<SanityCheck.java>", source);
Node root2 = compiler.parseSyntheticCode("<ValidityCheck.java>", source);
if (compiler.hasHaltingErrors()) {
compiler.report(JSError.make(CANNOT_PARSE_GENERATED_CODE,
Strings.truncateAtMaxLength(source, 100, true)));
Expand All @@ -116,7 +116,7 @@ private Node sanityCheckCodeGeneration(Node root) {
* Sanity checks the AST. This is by verifying the normalization passes do
* nothing.
*/
private void sanityCheckNormalization(Node externs, Node root) {
private void checkNormalization(Node externs, Node root) {
// Verify nothing has inappropriately denormalize the AST.
CodeChangeHandler handler = new ForbiddenChange();
compiler.addChangeHandler(handler);
Expand All @@ -138,7 +138,7 @@ private void sanityCheckNormalization(Node externs, Node root) {
compiler.removeChangeHandler(handler);
}

private void sanityCheckExternProperties(Node externs) {
private void checkExternProperties(Node externs) {
Set<String> externProperties = compiler.getExternProperties();
if (externProperties == null) {
// GatherExternProperties hasn't run yet. Don't report a violation.
Expand Down

0 comments on commit dee15e7

Please sign in to comment.