Skip to content

Commit

Permalink
Remove more references to NTI from the parts of the compiler.
Browse files Browse the repository at this point in the history
NOTE: This leave the NTI unit tests in place and functional.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=194712468
  • Loading branch information
concavelenz authored and lauraharker committed Apr 30, 2018
1 parent 54afcbb commit 4dc239e
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 150 deletions.
Expand Up @@ -449,7 +449,6 @@ protected void setRunOptions(CompilerOptions options) throws IOException {
options.processCommonJSModules = config.processCommonJSModules; options.processCommonJSModules = config.processCommonJSModules;
options.moduleRoots = config.moduleRoots; options.moduleRoots = config.moduleRoots;
options.angularPass = config.angularPass; options.angularPass = config.angularPass;
options.setNewTypeInference(config.useNewTypeInference);
options.instrumentationTemplateFile = config.instrumentationTemplateFile; options.instrumentationTemplateFile = config.instrumentationTemplateFile;


if (config.errorFormat == CommandLineConfig.ErrorFormatOption.JSON) { if (config.errorFormat == CommandLineConfig.ErrorFormatOption.JSON) {
Expand Down Expand Up @@ -2694,13 +2693,6 @@ public CommandLineConfig setAngularPass(boolean angularPass) {
return this; return this;
} }


private boolean useNewTypeInference = false;

public CommandLineConfig setNewTypeInference(boolean useNewTypeInference) {
this.useNewTypeInference = useNewTypeInference;
return this;
}

private String instrumentationTemplateFile = ""; private String instrumentationTemplateFile = "";


public CommandLineConfig setInstrumentationTemplateFile(String fileName) { public CommandLineConfig setInstrumentationTemplateFile(String fileName) {
Expand Down
1 change: 0 additions & 1 deletion src/com/google/javascript/jscomp/CommandLineRunner.java
Expand Up @@ -1622,7 +1622,6 @@ private void initConfigFromFlags(String[] args, PrintStream out, PrintStream err
.setHideWarningsFor(flags.hideWarningsFor) .setHideWarningsFor(flags.hideWarningsFor)
.setAngularPass(flags.angularPass) .setAngularPass(flags.angularPass)
.setInstrumentationTemplateFile(flags.instrumentationFile) .setInstrumentationTemplateFile(flags.instrumentationFile)
.setNewTypeInference(false)
.setJsonStreamMode(flags.jsonStreamMode) .setJsonStreamMode(flags.jsonStreamMode)
.setErrorFormat(flags.errorFormat); .setErrorFormat(flags.errorFormat);
} }
Expand Down
4 changes: 2 additions & 2 deletions src/com/google/javascript/jscomp/Compiler.java
Expand Up @@ -419,7 +419,7 @@ protected void reconcileOptionsWithGuards() {
options.checkTypes = false; options.checkTypes = false;
} else if (!options.checkTypes) { } else if (!options.checkTypes) {
// If DiagnosticGroups did not override the plain checkTypes // If DiagnosticGroups did not override the plain checkTypes
// option, and checkTypes is enabled, then turn off the // option, and checkTypes is disabled, then turn off the
// parser type warnings. // parser type warnings.
options.setWarningLevel( options.setWarningLevel(
DiagnosticGroup.forType( DiagnosticGroup.forType(
Expand Down Expand Up @@ -1498,7 +1498,7 @@ public TypeIRegistry getTypeIRegistry() {
// the constructor asks for a type registry, and this may happen before type checking // the constructor asks for a type registry, and this may happen before type checking
// runs. So, in the NONE case, if NTI is enabled, return a new registry, since NTI is // runs. So, in the NONE case, if NTI is enabled, return a new registry, since NTI is
// the relevant type checker. If NTI is not enabled, return an old registry. // the relevant type checker. If NTI is not enabled, return an old registry.
return options.getNewTypeInference() ? getGlobalTypeInfo() : getTypeRegistry(); return getTypeRegistry();
case OTI: case OTI:
return getTypeRegistry(); return getTypeRegistry();
case NTI: case NTI:
Expand Down
25 changes: 2 additions & 23 deletions src/com/google/javascript/jscomp/CompilerOptions.java
Expand Up @@ -222,17 +222,6 @@ boolean shouldPrintExterns() {
*/ */
boolean inferTypes; boolean inferTypes;


private final boolean useNewTypeInference = false;

/**
* Relevant only when {@link #useNewTypeInference} is true, where we normally disable OTI errors.
* If you want both NTI and OTI errors in this case, set to true.
* E.g. if using using a warnings guard to filter NTI or OTI warnings in new or legacy code,
* respectively.
* This will be removed when NTI entirely replaces OTI.
*/
boolean reportOTIErrorsUnderNTI = false;

/** /**
* Run type checking natively on the subset of ES6 features that we are able to typecheck * Run type checking natively on the subset of ES6 features that we are able to typecheck
* natively, and then transpile them after NTI. * natively, and then transpile them after NTI.
Expand Down Expand Up @@ -2000,11 +1989,7 @@ public boolean getInferTypes() {
return inferTypes; return inferTypes;
} }


public boolean getNewTypeInference() { /** @deprecated This is a no-op. */
return false;
}

/** @deprecated no-op */
@Deprecated @Deprecated
public void setNewTypeInference(boolean enable) { public void setNewTypeInference(boolean enable) {
} }
Expand All @@ -2013,12 +1998,7 @@ public void setNewTypeInference(boolean enable) {
* @return true if either typechecker is ON. * @return true if either typechecker is ON.
*/ */
public boolean isTypecheckingEnabled() { public boolean isTypecheckingEnabled() {
return this.checkTypes || this.useNewTypeInference; return this.checkTypes;
}

// Not dead code; used by the open-source users of the compiler.
public void setReportOTIErrorsUnderNTI(boolean enable) {
this.reportOTIErrorsUnderNTI = enable;
} }


public boolean getTypeCheckEs6Natively() { public boolean getTypeCheckEs6Natively() {
Expand Down Expand Up @@ -2994,7 +2974,6 @@ public String toString() {
.add("replaceStringsInputMap", replaceStringsInputMap) .add("replaceStringsInputMap", replaceStringsInputMap)
.add("replaceStringsPlaceholderToken", replaceStringsPlaceholderToken) .add("replaceStringsPlaceholderToken", replaceStringsPlaceholderToken)
.add("replaceStringsReservedStrings", replaceStringsReservedStrings) .add("replaceStringsReservedStrings", replaceStringsReservedStrings)
.add("reportOTIErrorsUnderNTI", reportOTIErrorsUnderNTI)
.add("reserveRawExports", reserveRawExports) .add("reserveRawExports", reserveRawExports)
.add("rewriteFunctionExpressions", rewriteFunctionExpressions) .add("rewriteFunctionExpressions", rewriteFunctionExpressions)
.add("rewritePolyfills", rewritePolyfills) .add("rewritePolyfills", rewritePolyfills)
Expand Down
Expand Up @@ -55,10 +55,6 @@ static void preprocess(CompilerOptions options) {
"max_function_size_after_inlining has no effect if inlining is disabled."); "max_function_size_after_inlining has no effect if inlining is disabled.");
} }


if (options.getNewTypeInference()) {
options.checkGlobalThisLevel = CheckLevel.OFF;
}

if (options.dartPass) { if (options.dartPass) {
if (!options.getLanguageOut().toFeatureSet().contains(FeatureSet.ES5)) { if (!options.getLanguageOut().toFeatureSet().contains(FeatureSet.ES5)) {
throw new InvalidOptionsException("Dart requires --language_out=ES5 or higher."); throw new InvalidOptionsException("Dart requires --language_out=ES5 or higher.");
Expand Down
119 changes: 26 additions & 93 deletions src/com/google/javascript/jscomp/DefaultPassConfig.java
Expand Up @@ -220,7 +220,7 @@ protected List<PassFactory> getWhitespaceOnlyPasses() {
return passes; return passes;
} }


private void addOldTypeCheckerPasses(List<PassFactory> checks, CompilerOptions options) { private void addTypeCheckerPasses(List<PassFactory> checks, CompilerOptions options) {
if (!options.allowsHotswapReplaceScript()) { if (!options.allowsHotswapReplaceScript()) {
checks.add(inlineTypeAliases); checks.add(inlineTypeAliases);
} }
Expand Down Expand Up @@ -415,25 +415,14 @@ protected List<PassFactory> getChecks() {
} else { } else {
checks.add(createEmptyPass(PassNames.BEFORE_TYPE_CHECKING)); checks.add(createEmptyPass(PassNames.BEFORE_TYPE_CHECKING));


if (options.getNewTypeInference()) { addTypeCheckerPasses(checks, options);
// We will not be updating NTI to understand any more new features,
// so transpile those features before running it.
if (options.needsTranspilationFrom(ES6)) {
TranspilationPasses.addEs6PostTypecheckPasses(checks);
}
checks.add(symbolTableForNewTypeInference);
checks.add(newTypeInference);
} else {
addOldTypeCheckerPasses(checks, options);
}


if (options.j2clPassMode.shouldAddJ2clPasses()) { if (options.j2clPassMode.shouldAddJ2clPasses()) {
checks.add(j2clSourceFileChecker); checks.add(j2clSourceFileChecker);
} }


if (!options.disables(DiagnosticGroups.CHECK_USELESS_CODE) if (!options.disables(DiagnosticGroups.CHECK_USELESS_CODE)
|| (!options.getNewTypeInference() || !options.disables(DiagnosticGroups.MISSING_RETURN)) {
&& !options.disables(DiagnosticGroups.MISSING_RETURN))) {
checks.add(checkControlFlow); checks.add(checkControlFlow);
} }


Expand All @@ -444,10 +433,7 @@ protected List<PassFactory> getChecks() {
checks.add(checkAccessControls); checks.add(checkAccessControls);
} }


if (!options.getNewTypeInference()) { checks.add(checkConsts);
// NTI performs this check already
checks.add(checkConsts);
}


// Analyzer checks must be run after typechecking. // Analyzer checks must be run after typechecking.
if (options.enables(DiagnosticGroups.ANALYZER_CHECKS) && options.isTypecheckingEnabled()) { if (options.enables(DiagnosticGroups.ANALYZER_CHECKS) && options.isTypecheckingEnabled()) {
Expand Down Expand Up @@ -494,18 +480,8 @@ protected List<PassFactory> getChecks() {
} }
} }


// NOTE(dimvar): Tried to move this into the optimizations, but had to back off
// because the very first pass, normalization, rewrites the code in a way that
// causes loss of type information.
// So, I will convert the remaining optimizations to use TypeI and test that only
// in unit tests, not full builds. Once all passes are converted, then
// drop the OTI-after-NTI altogether.
// In addition, I will probably have a local edit of the repo that retains both
// types on Nodes, so I can test full builds on my machine. We can't check in such
// a change because it would greatly increase memory usage.
if (options.getNewTypeInference()) {
addOldTypeCheckerPasses(checks, options);
}


// When options.generateExportsAfterTypeChecking is true, run GenerateExports after // When options.generateExportsAfterTypeChecking is true, run GenerateExports after
// both type checkers, not just after NTI. // both type checkers, not just after NTI.
Expand All @@ -519,11 +495,7 @@ protected List<PassFactory> getChecks() {
// At this point all checks have been done. // At this point all checks have been done.
// There's no need to complete transpilation if we're only running checks. // There's no need to complete transpilation if we're only running checks.


if (!options.getNewTypeInference()) { TranspilationPasses.addEs6PostTypecheckPasses(checks);
// Note that TranspilationPasses.addEs6PostTypecheckPasses is really only "post typecheck"
// for OTI. The code path for NTI includes an earlier call to addEs6PostTypecheckPasses.
TranspilationPasses.addEs6PostTypecheckPasses(checks);
}
TranspilationPasses.addEs6PostCheckPasses(checks); TranspilationPasses.addEs6PostCheckPasses(checks);
} }


Expand Down Expand Up @@ -585,9 +557,7 @@ protected List<PassFactory> getOptimizations() {
passes.add(j2clUtilGetDefineRewriterPass); passes.add(j2clUtilGetDefineRewriterPass);
} }


// TODO(dimvar): convert this pass to use NTI. Low priority since it's if (options.runtimeTypeCheck) {
// mostly unused. Converting it shouldn't block switching to NTI.
if (options.runtimeTypeCheck && !options.getNewTypeInference()) {
passes.add(runtimeTypeCheck); passes.add(runtimeTypeCheck);
} }


Expand Down Expand Up @@ -1928,32 +1898,6 @@ protected FeatureSet featureSet() {
} }
}; };


private final PassFactory symbolTableForNewTypeInference =
new PassFactory("GlobalTypeInfo", true) {
@Override
protected CompilerPass create(final AbstractCompiler compiler) {
return new GlobalTypeInfoCollector(compiler);
}

@Override
protected FeatureSet featureSet() {
return FeatureSet.NTI_SUPPORTED;
}
};

private final PassFactory newTypeInference =
new PassFactory("NewTypeInference", true) {
@Override
protected CompilerPass create(final AbstractCompiler compiler) {
return new NewTypeInference(compiler);
}

@Override
protected FeatureSet featureSet() {
return FeatureSet.NTI_SUPPORTED;
}
};

private final HotSwapPassFactory inferJsDocInfo = private final HotSwapPassFactory inferJsDocInfo =
new HotSwapPassFactory("inferJsDocInfo") { new HotSwapPassFactory("inferJsDocInfo") {
@Override @Override
Expand Down Expand Up @@ -2010,28 +1954,28 @@ protected FeatureSet featureSet() {
}; };


/** /**
* Checks possible execution paths of the program for problems: missing return * Checks possible execution paths of the program for problems: missing return statements and dead
* statements and dead code. * code.
*/ */
private final HotSwapPassFactory checkControlFlow = private final HotSwapPassFactory checkControlFlow =
new HotSwapPassFactory("checkControlFlow") { new HotSwapPassFactory("checkControlFlow") {
@Override @Override
protected HotSwapCompilerPass create(AbstractCompiler compiler) { protected HotSwapCompilerPass create(AbstractCompiler compiler) {
List<Callback> callbacks = new ArrayList<>(); List<Callback> callbacks = new ArrayList<>();
if (!options.disables(DiagnosticGroups.CHECK_USELESS_CODE)) { if (!options.disables(DiagnosticGroups.CHECK_USELESS_CODE)) {
callbacks.add(new CheckUnreachableCode(compiler)); callbacks.add(new CheckUnreachableCode(compiler));
} }
if (!options.getNewTypeInference() && !options.disables(DiagnosticGroups.MISSING_RETURN)) { if (!options.disables(DiagnosticGroups.MISSING_RETURN)) {
callbacks.add(new CheckMissingReturn(compiler)); callbacks.add(new CheckMissingReturn(compiler));
} }
return combineChecks(compiler, callbacks); return combineChecks(compiler, callbacks);
} }


@Override @Override
public FeatureSet featureSet() { public FeatureSet featureSet() {
return ES8_MODULES; return ES8_MODULES;
} }
}; };


/** Checks access controls. Depends on type-inference. */ /** Checks access controls. Depends on type-inference. */
private final HotSwapPassFactory checkAccessControls = private final HotSwapPassFactory checkAccessControls =
Expand Down Expand Up @@ -2130,17 +2074,6 @@ class GlobalTypeResolver implements HotSwapCompilerPass {


@Override @Override
public void process(Node externs, Node root) { public void process(Node externs, Node root) {
// If NTI is enabled, erase the NTI types from the AST before adding the old types.
if (this.compiler.getOptions().getNewTypeInference()) {
NodeTraversal.traversePostOrder(
this.compiler,
root,
(NodeTraversal t, Node n, Node parent) -> {
n.setTypeI(null);
});
this.compiler.clearTypeIRegistry();
}

this.compiler.setMostRecentTypechecker(MostRecentTypechecker.OTI); this.compiler.setMostRecentTypechecker(MostRecentTypechecker.OTI);
if (topScope == null) { if (topScope == null) {
regenerateGlobalTypedScope(compiler, root.getParent()); regenerateGlobalTypedScope(compiler, root.getParent());
Expand Down
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/Es6ForOfConverter.java
Expand Up @@ -53,7 +53,7 @@ public final class Es6ForOfConverter implements NodeTraversal.Callback, HotSwapC
public Es6ForOfConverter(AbstractCompiler compiler) { public Es6ForOfConverter(AbstractCompiler compiler) {
this.compiler = compiler; this.compiler = compiler;
// Only add type information if NTI has been run. // Only add type information if NTI has been run.
this.addTypes = MostRecentTypechecker.NTI.equals(compiler.getMostRecentTypechecker()); this.addTypes = MostRecentTypechecker.OTI.equals(compiler.getMostRecentTypechecker());
this.registry = compiler.getTypeIRegistry(); this.registry = compiler.getTypeIRegistry();
this.unknownType = createType(addTypes, registry, JSTypeNative.UNKNOWN_TYPE); this.unknownType = createType(addTypes, registry, JSTypeNative.UNKNOWN_TYPE);
this.stringType = createType(addTypes, registry, JSTypeNative.STRING_TYPE); this.stringType = createType(addTypes, registry, JSTypeNative.STRING_TYPE);
Expand Down
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/Es7ToEs6Converter.java
Expand Up @@ -42,7 +42,7 @@ public final class Es7ToEs6Converter implements NodeTraversal.Callback, HotSwapC


public Es7ToEs6Converter(AbstractCompiler compiler) { public Es7ToEs6Converter(AbstractCompiler compiler) {
this.compiler = compiler; this.compiler = compiler;
this.addTypes = MostRecentTypechecker.NTI.equals(compiler.getMostRecentTypechecker()); this.addTypes = MostRecentTypechecker.OTI.equals(compiler.getMostRecentTypechecker());
} }


@Override @Override
Expand Down
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/EsNextToEs8Converter.java
Expand Up @@ -52,7 +52,7 @@ public final class EsNextToEs8Converter implements NodeTraversal.Callback, HotSw


public EsNextToEs8Converter(AbstractCompiler compiler) { public EsNextToEs8Converter(AbstractCompiler compiler) {
this.compiler = compiler; this.compiler = compiler;
this.addTypes = MostRecentTypechecker.NTI.equals(compiler.getMostRecentTypechecker()); this.addTypes = MostRecentTypechecker.OTI.equals(compiler.getMostRecentTypechecker());
} }


@Override @Override
Expand Down
Expand Up @@ -64,7 +64,7 @@ public final class LateEs6ToEs3Converter implements NodeTraversal.Callback, HotS
public LateEs6ToEs3Converter(AbstractCompiler compiler) { public LateEs6ToEs3Converter(AbstractCompiler compiler) {
this.compiler = compiler; this.compiler = compiler;
// Only add type information if NTI has been run. // Only add type information if NTI has been run.
this.addTypes = MostRecentTypechecker.NTI.equals(compiler.getMostRecentTypechecker()); this.addTypes = MostRecentTypechecker.OTI.equals(compiler.getMostRecentTypechecker());
this.registry = compiler.getTypeIRegistry(); this.registry = compiler.getTypeIRegistry();
this.unknownType = createType(addTypes, registry, JSTypeNative.UNKNOWN_TYPE); this.unknownType = createType(addTypes, registry, JSTypeNative.UNKNOWN_TYPE);
} }
Expand Down
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/TranspilationPasses.java
Expand Up @@ -100,7 +100,7 @@ public static void addEs6PreTypecheckPasses(List<PassFactory> passes, CompilerOp
passes.add(es6ForOf); passes.add(es6ForOf);
passes.add(rewriteBlockScopedFunctionDeclaration); passes.add(rewriteBlockScopedFunctionDeclaration);
passes.add(rewriteBlockScopedDeclaration); passes.add(rewriteBlockScopedDeclaration);
if (!options.checksOnly || options.getNewTypeInference()) { if (!options.checksOnly) {
// Don't run these passes in checksOnly mode since all the OTI typechecking & checks passes // Don't run these passes in checksOnly mode since all the OTI typechecking & checks passes
// support the transpiled features. // support the transpiled features.
passes.add(rewriteBlockScopedDeclaration); passes.add(rewriteBlockScopedDeclaration);
Expand Down
13 changes: 3 additions & 10 deletions src/com/google/javascript/jscomp/TypedScopeCreator.java
Expand Up @@ -64,7 +64,6 @@
import com.google.javascript.jscomp.FunctionTypeBuilder.AstFunctionContents; import com.google.javascript.jscomp.FunctionTypeBuilder.AstFunctionContents;
import com.google.javascript.jscomp.NodeTraversal.AbstractScopedCallback; import com.google.javascript.jscomp.NodeTraversal.AbstractScopedCallback;
import com.google.javascript.jscomp.NodeTraversal.AbstractShallowStatementCallback; import com.google.javascript.jscomp.NodeTraversal.AbstractShallowStatementCallback;
import com.google.javascript.jscomp.parsing.NullErrorReporter;
import com.google.javascript.rhino.ErrorReporter; import com.google.javascript.rhino.ErrorReporter;
import com.google.javascript.rhino.InputId; import com.google.javascript.rhino.InputId;
import com.google.javascript.rhino.JSDocInfo; import com.google.javascript.rhino.JSDocInfo;
Expand Down Expand Up @@ -169,7 +168,6 @@ final class TypedScopeCreator implements ScopeCreator, StaticSymbolTable<TypedVa
private final List<FunctionType> delegateProxyCtors = new ArrayList<>(); private final List<FunctionType> delegateProxyCtors = new ArrayList<>();
private final Map<String, String> delegateCallingConventions = new HashMap<>(); private final Map<String, String> delegateCallingConventions = new HashMap<>();
private final Map<Node, TypedScope> memoized = new LinkedHashMap<>(); private final Map<Node, TypedScope> memoized = new LinkedHashMap<>();
private final boolean runsAfterNTI;


// Set of functions with non-empty returns, for passing to FunctionTypeBuilder. // Set of functions with non-empty returns, for passing to FunctionTypeBuilder.
private final Set<Node> functionsWithNonEmptyReturns = new HashSet<>(); private final Set<Node> functionsWithNonEmptyReturns = new HashSet<>();
Expand Down Expand Up @@ -205,22 +203,17 @@ void resolve() {
this(compiler, compiler.getCodingConvention()); this(compiler, compiler.getCodingConvention());
} }


TypedScopeCreator(AbstractCompiler compiler, TypedScopeCreator(AbstractCompiler compiler, CodingConvention codingConvention) {
CodingConvention codingConvention) {
this.compiler = compiler; this.compiler = compiler;
this.runsAfterNTI = compiler.getOptions().getNewTypeInference();
this.validator = compiler.getTypeValidator(); this.validator = compiler.getTypeValidator();
this.codingConvention = codingConvention; this.codingConvention = codingConvention;
this.typeRegistry = compiler.getTypeRegistry(); this.typeRegistry = compiler.getTypeRegistry();
this.typeParsingErrorReporter = this.runsAfterNTI this.typeParsingErrorReporter = typeRegistry.getErrorReporter();
? NullErrorReporter.forOldRhino() : typeRegistry.getErrorReporter();
this.unknownType = typeRegistry.getNativeObjectType(UNKNOWN_TYPE); this.unknownType = typeRegistry.getNativeObjectType(UNKNOWN_TYPE);
} }


private void report(JSError error) { private void report(JSError error) {
if (!this.runsAfterNTI || compiler.getOptions().reportOTIErrorsUnderNTI) { compiler.report(error);
compiler.report(error);
}
} }


@Override @Override
Expand Down
1 change: 0 additions & 1 deletion src/com/google/javascript/jscomp/gwt/client/GwtRunner.java
Expand Up @@ -413,7 +413,6 @@ private static void applyOptionsFromFlags(CompilerOptions options, Flags flags)
options.setDartPass(flags.dartPass); options.setDartPass(flags.dartPass);
options.setExportLocalPropertyDefinitions(flags.exportLocalPropertyDefinitions); options.setExportLocalPropertyDefinitions(flags.exportLocalPropertyDefinitions);
options.setGenerateExports(flags.generateExports); options.setGenerateExports(flags.generateExports);
options.setNewTypeInference(flags.newTypeInf);
if (flags.polymerPass) { if (flags.polymerPass) {
options.setPolymerVersion(1); options.setPolymerVersion(1);
} else if (flags.polymerVersion != null) { } else if (flags.polymerVersion != null) {
Expand Down

0 comments on commit 4dc239e

Please sign in to comment.