Skip to content

Commit

Permalink
Refactor GlobalTypeInfo into a data class and a separate pass.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=160570502
  • Loading branch information
rluble authored and brad4d committed Jun 30, 2017
1 parent 0084673 commit 9b55459
Show file tree
Hide file tree
Showing 18 changed files with 3,080 additions and 2,942 deletions.
4 changes: 2 additions & 2 deletions src/com/google/javascript/jscomp/AbstractCompiler.java
Expand Up @@ -267,9 +267,9 @@ static enum MostRecentTypechecker {
abstract Iterable<TypeMismatch> getImplicitInterfaceUses(); abstract Iterable<TypeMismatch> getImplicitInterfaceUses();


/** /**
* Used only by the new type inference * Global type registry used by NTI.
*/ */
abstract CompilerPass getSymbolTable(); abstract <T extends TypeIRegistry> T getGlobalTypeInfo();


/** /**
* Used by three passes that run in sequence (optimize-returns, * Used by three passes that run in sequence (optimize-returns,
Expand Down
28 changes: 14 additions & 14 deletions src/com/google/javascript/jscomp/Compiler.java
Expand Up @@ -240,8 +240,8 @@ public SourceFile loadSource(String filename) {
// Types that have been forward declared // Types that have been forward declared
private Set<String> forwardDeclaredTypes = new HashSet<>(); private Set<String> forwardDeclaredTypes = new HashSet<>();


// For use by the new type inference // Type registry used by new type inference.
private GlobalTypeInfo symbolTable; private GlobalTypeInfo globalTypeInfo;


private MostRecentTypechecker mostRecentTypechecker = MostRecentTypechecker.NONE; private MostRecentTypechecker mostRecentTypechecker = MostRecentTypechecker.NONE;


Expand Down Expand Up @@ -1500,11 +1500,11 @@ 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() ? getSymbolTable() : getTypeRegistry(); return options.getNewTypeInference() ? getGlobalTypeInfo() : getTypeRegistry();
case OTI: case OTI:
return getTypeRegistry(); return getTypeRegistry();
case NTI: case NTI:
return getSymbolTable(); return getGlobalTypeInfo();
default: default:
throw new RuntimeException("Unhandled typechecker " + mostRecentTypechecker); throw new RuntimeException("Unhandled typechecker " + mostRecentTypechecker);
} }
Expand All @@ -1517,7 +1517,7 @@ public void clearTypeIRegistry() {
typeRegistry = null; typeRegistry = null;
return; return;
case NTI: case NTI:
symbolTable = null; globalTypeInfo = null;
return; return;
case NONE: case NONE:
return; return;
Expand Down Expand Up @@ -1646,7 +1646,7 @@ Iterable<TypeMismatch> getTypeMismatches() {
case OTI: case OTI:
return getTypeValidator().getMismatches(); return getTypeValidator().getMismatches();
case NTI: case NTI:
return getSymbolTable().getMismatches(); return getGlobalTypeInfo().getMismatches();
default: default:
throw new RuntimeException("Can't ask for type mismatches before type checking."); throw new RuntimeException("Can't ask for type mismatches before type checking.");
} }
Expand All @@ -1658,18 +1658,18 @@ Iterable<TypeMismatch> getImplicitInterfaceUses() {
case OTI: case OTI:
return getTypeValidator().getImplicitInterfaceUses(); return getTypeValidator().getImplicitInterfaceUses();
case NTI: case NTI:
return getSymbolTable().getImplicitInterfaceUses(); return getGlobalTypeInfo().getImplicitInterfaceUses();
default: default:
throw new RuntimeException("Can't ask for type mismatches before type checking."); throw new RuntimeException("Can't ask for type mismatches before type checking.");
} }
} }


@Override @Override
GlobalTypeInfo getSymbolTable() { GlobalTypeInfo getGlobalTypeInfo() {
if (this.symbolTable == null) { if (this.globalTypeInfo == null) {
this.symbolTable = new GlobalTypeInfo(this, forwardDeclaredTypes); this.globalTypeInfo = new GlobalTypeInfo(this, forwardDeclaredTypes);
} }
return this.symbolTable; return this.globalTypeInfo;
} }


@Override @Override
Expand Down Expand Up @@ -3464,7 +3464,7 @@ private static class CompilerState implements Serializable {
private final Map<String, Node> injectedLibraries; private final Map<String, Node> injectedLibraries;
private final Node lastInjectedLibrary; private final Node lastInjectedLibrary;
private final GlobalVarReferenceMap globalRefMap; private final GlobalVarReferenceMap globalRefMap;
private final GlobalTypeInfo symbolTable; private final GlobalTypeInfo globalTypeInfo;
private final boolean hasRegExpGlobalReferences; private final boolean hasRegExpGlobalReferences;
private final LifeCycleStage lifeCycleStage; private final LifeCycleStage lifeCycleStage;
private final Set<String> externProperties; private final Set<String> externProperties;
Expand Down Expand Up @@ -3498,7 +3498,7 @@ private static class CompilerState implements Serializable {
this.injectedLibraries = compiler.injectedLibraries; this.injectedLibraries = compiler.injectedLibraries;
this.globalRefMap = compiler.globalRefMap; this.globalRefMap = compiler.globalRefMap;
this.lastInjectedLibrary = compiler.lastInjectedLibrary; this.lastInjectedLibrary = compiler.lastInjectedLibrary;
this.symbolTable = compiler.symbolTable; this.globalTypeInfo = compiler.globalTypeInfo;
this.hasRegExpGlobalReferences = compiler.hasRegExpGlobalReferences; this.hasRegExpGlobalReferences = compiler.hasRegExpGlobalReferences;
this.typeValidator = compiler.typeValidator; this.typeValidator = compiler.typeValidator;
this.lifeCycleStage = compiler.getLifeCycleStage(); this.lifeCycleStage = compiler.getLifeCycleStage();
Expand Down Expand Up @@ -3571,7 +3571,7 @@ public CompilerState call() throws Exception {
injectedLibraries.putAll(compilerState.injectedLibraries); injectedLibraries.putAll(compilerState.injectedLibraries);
lastInjectedLibrary = compilerState.lastInjectedLibrary; lastInjectedLibrary = compilerState.lastInjectedLibrary;
globalRefMap = compilerState.globalRefMap; globalRefMap = compilerState.globalRefMap;
symbolTable = compilerState.symbolTable; globalTypeInfo = compilerState.globalTypeInfo;
hasRegExpGlobalReferences = compilerState.hasRegExpGlobalReferences; hasRegExpGlobalReferences = compilerState.hasRegExpGlobalReferences;
typeValidator = compilerState.typeValidator; typeValidator = compilerState.typeValidator;
setLifeCycleStage(compilerState.lifeCycleStage); setLifeCycleStage(compilerState.lifeCycleStage);
Expand Down
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/DefaultPassConfig.java
Expand Up @@ -1872,7 +1872,7 @@ public void hotSwapScript(Node scriptRoot, Node originalRoot) {
new PassFactory("GlobalTypeInfo", true) { new PassFactory("GlobalTypeInfo", true) {
@Override @Override
protected CompilerPass create(final AbstractCompiler compiler) { protected CompilerPass create(final AbstractCompiler compiler) {
return compiler.getSymbolTable(); return new GlobalTypeInfoCollector(compiler);
} }
}; };


Expand Down
48 changes: 24 additions & 24 deletions src/com/google/javascript/jscomp/DiagnosticGroups.java
Expand Up @@ -290,13 +290,13 @@ public DiagnosticGroup forName(String name) {
public static final DiagnosticGroup NEW_CHECK_TYPES_COMPATIBILITY_MODE = public static final DiagnosticGroup NEW_CHECK_TYPES_COMPATIBILITY_MODE =
DiagnosticGroups.registerGroup("newCheckTypesCompatibility", // undocumented DiagnosticGroups.registerGroup("newCheckTypesCompatibility", // undocumented
JSTypeCreatorFromJSDoc.COMPATIBLE_DIAGNOSTICS, JSTypeCreatorFromJSDoc.COMPATIBLE_DIAGNOSTICS,
GlobalTypeInfo.COMPATIBLE_DIAGNOSTICS, GlobalTypeInfoCollector.COMPATIBLE_DIAGNOSTICS,
NewTypeInference.COMPATIBLE_DIAGNOSTICS); NewTypeInference.COMPATIBLE_DIAGNOSTICS);


public static final DiagnosticGroup NEW_CHECK_TYPES_EXTRA_CHECKS = public static final DiagnosticGroup NEW_CHECK_TYPES_EXTRA_CHECKS =
DiagnosticGroups.registerGroup("newCheckTypesExtraChecks", // undocumented DiagnosticGroups.registerGroup("newCheckTypesExtraChecks", // undocumented
JSTypeCreatorFromJSDoc.NEW_DIAGNOSTICS, JSTypeCreatorFromJSDoc.NEW_DIAGNOSTICS,
GlobalTypeInfo.NEW_DIAGNOSTICS, GlobalTypeInfoCollector.NEW_DIAGNOSTICS,
NewTypeInference.NEW_DIAGNOSTICS); NewTypeInference.NEW_DIAGNOSTICS);


// Part of the new type inference // Part of the new type inference
Expand Down Expand Up @@ -325,30 +325,30 @@ public DiagnosticGroup forName(String name) {
JSTypeCreatorFromJSDoc.IMPLEMENTS_WITHOUT_CONSTRUCTOR, JSTypeCreatorFromJSDoc.IMPLEMENTS_WITHOUT_CONSTRUCTOR,
JSTypeCreatorFromJSDoc.INHERITANCE_CYCLE, JSTypeCreatorFromJSDoc.INHERITANCE_CYCLE,
JSTypeCreatorFromJSDoc.UNION_IS_UNINHABITABLE, JSTypeCreatorFromJSDoc.UNION_IS_UNINHABITABLE,
GlobalTypeInfo.ABSTRACT_METHOD_IN_CONCRETE_CLASS, GlobalTypeInfoCollector.ABSTRACT_METHOD_IN_CONCRETE_CLASS,
GlobalTypeInfo.ANONYMOUS_NOMINAL_TYPE, GlobalTypeInfoCollector.ANONYMOUS_NOMINAL_TYPE,
GlobalTypeInfo.CANNOT_INIT_TYPEDEF, GlobalTypeInfoCollector.CANNOT_INIT_TYPEDEF,
GlobalTypeInfo.CANNOT_OVERRIDE_FINAL_METHOD, GlobalTypeInfoCollector.CANNOT_OVERRIDE_FINAL_METHOD,
GlobalTypeInfo.CONST_WITHOUT_INITIALIZER, GlobalTypeInfoCollector.CONST_WITHOUT_INITIALIZER,
// GlobalTypeInfo.COULD_NOT_INFER_CONST_TYPE, // GlobalTypeInfo.COULD_NOT_INFER_CONST_TYPE,
GlobalTypeInfo.CTOR_IN_DIFFERENT_SCOPE, GlobalTypeInfoCollector.CTOR_IN_DIFFERENT_SCOPE,
GlobalTypeInfo.DICT_WITHOUT_CTOR, GlobalTypeInfoCollector.DICT_WITHOUT_CTOR,
GlobalTypeInfo.DUPLICATE_JSDOC, GlobalTypeInfoCollector.DUPLICATE_JSDOC,
GlobalTypeInfo.DUPLICATE_PROP_IN_ENUM, GlobalTypeInfoCollector.DUPLICATE_PROP_IN_ENUM,
GlobalTypeInfo.EXPECTED_CONSTRUCTOR, GlobalTypeInfoCollector.EXPECTED_CONSTRUCTOR,
GlobalTypeInfo.EXPECTED_INTERFACE, GlobalTypeInfoCollector.EXPECTED_INTERFACE,
GlobalTypeInfo.INEXISTENT_PARAM, GlobalTypeInfoCollector.INEXISTENT_PARAM,
GlobalTypeInfo.INTERFACE_METHOD_NOT_IMPLEMENTED, GlobalTypeInfoCollector.INTERFACE_METHOD_NOT_IMPLEMENTED,
// GlobalTypeInfo.INVALID_PROP_OVERRIDE, // GlobalTypeInfo.INVALID_PROP_OVERRIDE,
GlobalTypeInfo.LENDS_ON_BAD_TYPE, GlobalTypeInfoCollector.LENDS_ON_BAD_TYPE,
GlobalTypeInfo.MALFORMED_ENUM, GlobalTypeInfoCollector.MALFORMED_ENUM,
GlobalTypeInfo.MISPLACED_CONST_ANNOTATION, GlobalTypeInfoCollector.MISPLACED_CONST_ANNOTATION,
GlobalTypeInfo.ONE_TYPE_FOR_MANY_VARS, GlobalTypeInfoCollector.ONE_TYPE_FOR_MANY_VARS,
// GlobalTypeInfo.REDECLARED_PROPERTY, // GlobalTypeInfo.REDECLARED_PROPERTY,
GlobalTypeInfo.STRUCT_WITHOUT_CTOR_OR_INTERF, GlobalTypeInfoCollector.STRUCT_WITHOUT_CTOR_OR_INTERF,
GlobalTypeInfo.SUPER_INTERFACES_HAVE_INCOMPATIBLE_PROPERTIES, GlobalTypeInfoCollector.SUPER_INTERFACES_HAVE_INCOMPATIBLE_PROPERTIES,
GlobalTypeInfo.UNKNOWN_OVERRIDE, GlobalTypeInfoCollector.UNKNOWN_OVERRIDE,
GlobalTypeInfo.UNRECOGNIZED_TYPE_NAME, GlobalTypeInfoCollector.UNRECOGNIZED_TYPE_NAME,
NewTypeInference.ABSTRACT_SUPER_METHOD_NOT_CALLABLE, NewTypeInference.ABSTRACT_SUPER_METHOD_NOT_CALLABLE,
NewTypeInference.ASSERT_FALSE, NewTypeInference.ASSERT_FALSE,
NewTypeInference.CANNOT_BIND_CTOR, NewTypeInference.CANNOT_BIND_CTOR,
Expand Down Expand Up @@ -449,7 +449,7 @@ public DiagnosticGroup forName(String name) {
TypeValidator.DUP_VAR_DECLARATION, TypeValidator.DUP_VAR_DECLARATION,
TypeValidator.DUP_VAR_DECLARATION_TYPE_MISMATCH, TypeValidator.DUP_VAR_DECLARATION_TYPE_MISMATCH,
VariableReferenceCheck.REDECLARED_VARIABLE, VariableReferenceCheck.REDECLARED_VARIABLE,
GlobalTypeInfo.REDECLARED_PROPERTY); GlobalTypeInfoCollector.REDECLARED_PROPERTY);


public static final DiagnosticGroup ES3 = public static final DiagnosticGroup ES3 =
DiagnosticGroups.registerGroup("es3", DiagnosticGroups.registerGroup("es3",
Expand Down

0 comments on commit 9b55459

Please sign in to comment.