Skip to content

Commit

Permalink
Rollback "Support partial compilation/analysis of programs using JSCo…
Browse files Browse the repository at this point in the history
…mpiler."

It broke lots of projects.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=144847925
  • Loading branch information
brad4d authored and blickly committed Jan 19, 2017
1 parent 8f2c127 commit 6ccbc2f
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 373 deletions.
29 changes: 1 addition & 28 deletions src/com/google/javascript/jscomp/Compiler.java
Expand Up @@ -51,12 +51,10 @@
import java.io.IOException;
import java.io.PrintStream;
import java.nio.file.FileSystems;
import java.util.AbstractSet;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -219,7 +217,7 @@ public SourceFile apply(String filename) {
private DefinitionUseSiteFinder defFinder = null;

// Types that have been forward declared
private Set<String> forwardDeclaredTypes = new HashSet<>();
private final Set<String> forwardDeclaredTypes = new HashSet<>();

// For use by the new type inference
private GlobalTypeInfo symbolTable;
Expand Down Expand Up @@ -347,31 +345,6 @@ public void initOptions(CompilerOptions options) {
options.useNonStrictWarningsGuard();
}

if (options.assumeForwardDeclaredForMissingTypes) {
this.forwardDeclaredTypes =
new AbstractSet<String>() {
@Override
public boolean contains(Object o) {
return true; // Report all types as forward declared types.
}

@Override
public boolean add(String e) {
return false;
}

@Override
public Iterator<String> iterator() {
return Collections.<String>emptySet().iterator();
}

@Override
public int size() {
return 0;
}
};
}

initWarningsGuard(options.getWarningsGuard());
}

Expand Down
10 changes: 0 additions & 10 deletions src/com/google/javascript/jscomp/CompilerOptions.java
Expand Up @@ -863,16 +863,6 @@ static enum OutputJs {
/** Runtime libraries to never inject. */
boolean preventLibraryInjection = false;

boolean assumeForwardDeclaredForMissingTypes = false;

/**
* If {@code true}, considers all missing types to be forward declared (useful for partial
* compilation).
*/
public void setAssumeForwardDeclaredForMissingTypes(
boolean assumeForwardDeclaredForMissingTypes) {
this.assumeForwardDeclaredForMissingTypes = assumeForwardDeclaredForMissingTypes;
}

//--------------------------------
// Output options
Expand Down
23 changes: 1 addition & 22 deletions src/com/google/javascript/jscomp/DiagnosticGroups.java
Expand Up @@ -47,7 +47,7 @@ public class DiagnosticGroups {
DiagnosticType.warning("JSC_UNUSED", "{0}");

public static final Set<String> wildcardExcludedGroups = ImmutableSet.of(
"reportUnknownTypes", "analyzerChecks", "oldReportUnknownTypes", "missingSourcesWarnings");
"reportUnknownTypes", "analyzerChecks", "oldReportUnknownTypes");

public DiagnosticGroups() {}

Expand Down Expand Up @@ -127,7 +127,6 @@ public DiagnosticGroup forName(String name) {
+ "msgDescriptions, "
+ "newCheckTypes, "
+ "nonStandardJsDocs, "
+ "missingSourcesWarnings, "
+ "reportUnknownTypes, "
+ "suspiciousCode, "
+ "strictModuleDepCheck, "
Expand Down Expand Up @@ -475,26 +474,6 @@ public DiagnosticGroup forName(String name) {
DiagnosticGroups.registerGroup("missingRequire",
CheckRequiresForConstructors.MISSING_REQUIRE_WARNING);

/**
* A set of diagnostics expected when parsing and type checking partial programs.
* Useful for clutz (tool that extracts TypeScript definitions from JS code).
*/
public static final DiagnosticGroup MISSING_SOURCES_WARNINGS =
DiagnosticGroups.registerGroup(
"missingSourcesWarnings",
REPORT_UNKNOWN_TYPES,
UNDEFINED_NAMES,
UNDEFINED_VARIABLES,
MISSING_PROVIDE,
DiagnosticGroup.forType(FunctionTypeBuilder.RESOLVED_TAG_EMPTY),
DiagnosticGroup.forType(ProcessClosurePrimitives.MISSING_PROVIDE_ERROR),
MISSING_PROPERTIES,
// triggered by typedefs with missing types
DUPLICATE_VARS,
// caused by a define depending on another define that's missing
DiagnosticGroup.forType(ProcessDefines.INVALID_DEFINE_INIT_ERROR),
DiagnosticGroup.forType(Es6ExternsCheck.MISSING_ES6_EXTERNS));

public static final DiagnosticGroup STRICT_MISSING_REQUIRE =
DiagnosticGroups.registerGroup("strictMissingRequire",
CheckRequiresForConstructors.MISSING_REQUIRE_WARNING,
Expand Down
79 changes: 18 additions & 61 deletions src/com/google/javascript/rhino/jstype/JSTypeRegistry.java
Expand Up @@ -1113,21 +1113,6 @@ public FunctionType getNativeFunctionType(JSTypeNative typeId) {
*/
public JSType getType(StaticTypedScope<JSType> scope, String jsTypeName,
String sourceName, int lineno, int charno) {
return getType(scope, jsTypeName, sourceName, lineno, charno, true);
}

/**
* @param recordUnresolvedTypes record unresolved named types and resolve
* them later. Set to false if types should be ignored for backwards
* compatibility (i.e. previously unparsed template type args).
*/
private JSType getType(
StaticTypedScope<JSType> scope,
String jsTypeName,
String sourceName,
int lineno,
int charno,
boolean recordUnresolvedTypes) {
switch (jsTypeName) {
case "boolean":
return getNativeType(JSTypeNative.BOOLEAN_TYPE);
Expand Down Expand Up @@ -1158,10 +1143,7 @@ private JSType getType(
// TODO(user): Each instance should support named type creation using
// interning.
NamedType namedType = createNamedType(jsTypeName, sourceName, lineno, charno);
if (recordUnresolvedTypes) {
// Only record unresolved named types
unresolvedNamedTypes.put(scope, namedType);
}
unresolvedNamedTypes.put(scope, namedType);
type = namedType;
}
return type;
Expand Down Expand Up @@ -1665,19 +1647,19 @@ public JSType createTypeFromCommentNode(Node n) {
*/
public JSType createTypeFromCommentNode(
Node n, String sourceName, StaticTypedScope<? extends TypeI> scope) {
return createFromTypeNodesInternal(n, sourceName, (StaticTypedScope<JSType>) scope, true);
return createFromTypeNodesInternal(n, sourceName, (StaticTypedScope<JSType>) scope);
}

private JSType createFromTypeNodesInternal(Node n, String sourceName,
StaticTypedScope<JSType> scope, boolean recordUnresolvedTypes) {
StaticTypedScope<JSType> scope) {
switch (n.getToken()) {
case LC: // Record type.
return createRecordTypeFromNodes(
n.getFirstChild(), sourceName, scope);

case BANG: // Not nullable
return createFromTypeNodesInternal(
n.getFirstChild(), sourceName, scope, recordUnresolvedTypes)
n.getFirstChild(), sourceName, scope)
.restrictByNotNullOrUndefined();

case QMARK: // Nullable or unknown
Expand All @@ -1687,17 +1669,17 @@ private JSType createFromTypeNodesInternal(Node n, String sourceName,
}
return createNullableType(
createFromTypeNodesInternal(
firstChild, sourceName, scope, recordUnresolvedTypes));
firstChild, sourceName, scope));

case EQUALS: // Optional
return createOptionalType(
createFromTypeNodesInternal(
n.getFirstChild(), sourceName, scope, recordUnresolvedTypes));
n.getFirstChild(), sourceName, scope));

case ELLIPSIS: // Var args
return createOptionalType(
createFromTypeNodesInternal(
n.getFirstChild(), sourceName, scope, recordUnresolvedTypes));
n.getFirstChild(), sourceName, scope));

case STAR: // The AllType
return getNativeType(ALL_TYPE);
Expand All @@ -1707,7 +1689,7 @@ private JSType createFromTypeNodesInternal(Node n, String sourceName,
for (Node child = n.getFirstChild(); child != null;
child = child.getNext()) {
builder.addAlternate(
createFromTypeNodesInternal(child, sourceName, scope, recordUnresolvedTypes));
createFromTypeNodesInternal(child, sourceName, scope));
}
return builder.build();

Expand All @@ -1721,21 +1703,12 @@ private JSType createFromTypeNodesInternal(Node n, String sourceName,
// TODO(martinprobst): The new type syntax resolution should be separate.
// Remove the NAME case then.
case NAME:
JSType namedType =
getType(
scope,
n.getString(),
sourceName,
n.getLineno(),
n.getCharno(),
recordUnresolvedTypes);
JSType namedType = getType(scope, n.getString(), sourceName, n.getLineno(), n.getCharno());
if ((namedType instanceof ObjectType)
&& !(namedType instanceof NamespaceType)
&& !(nonNullableTypeNames.contains(n.getString()))) {
Node typeList = n.getFirstChild();
boolean isUnknownForwardDeclared =
namedType.isUnknownType() && isForwardDeclaredType(n.getString());
if ((!namedType.isUnknownType() || isUnknownForwardDeclared) && typeList != null) {
if (!namedType.isUnknownType() && typeList != null) {
// Templatized types.
ImmutableList.Builder<JSType> templateTypes = ImmutableList.builder();

Expand All @@ -1745,11 +1718,7 @@ private JSType createFromTypeNodesInternal(Node n, String sourceName,
templateTypes.add(getNativeType(UNKNOWN_TYPE));
}

int nAllowedTypes =
isUnknownForwardDeclared
? Integer.MAX_VALUE
: namedType.getTemplateTypeMap().numUnfilledTemplateKeys();
boolean recordTemplateArgs = recordUnresolvedTypes && !isUnknownForwardDeclared;
int nAllowedTypes = namedType.getTemplateTypeMap().numUnfilledTemplateKeys();
int templateNodeIndex = 0;
for (Node templateNode : typeList.children()) {
// Don't parse more templatized type nodes than the type can
Expand All @@ -1768,21 +1737,9 @@ private JSType createFromTypeNodesInternal(Node n, String sourceName,
sourceName, templateNode.getLineno(), templateNode.getCharno());
break;
}
templateTypes.add(
createFromTypeNodesInternal(templateNode, sourceName, scope, recordTemplateArgs));
}
if (isUnknownForwardDeclared) {
// For backwards compatibility, construct a TemplatizedType but "hide" the template
// arguments from further resolution.
namedType =
new TemplatizedType(
this,
(ObjectType) namedType,
ImmutableList.<JSType>of(),
templateTypes.build());
} else {
namedType = createTemplatizedType((ObjectType) namedType, templateTypes.build());
templateTypes.add(createFromTypeNodesInternal(templateNode, sourceName, scope));
}
namedType = createTemplatizedType((ObjectType) namedType, templateTypes.build());
Preconditions.checkNotNull(namedType);
}
return createDefaultObjectUnion(namedType);
Expand All @@ -1798,7 +1755,7 @@ private JSType createFromTypeNodesInternal(Node n, String sourceName,
Node contextNode = current.getFirstChild();

JSType candidateThisType = createFromTypeNodesInternal(
contextNode, sourceName, scope, recordUnresolvedTypes);
contextNode, sourceName, scope);

// Allow null/undefined 'this' types to indicate that
// the function is not called in a deliberate context,
Expand Down Expand Up @@ -1835,11 +1792,11 @@ private JSType createFromTypeNodesInternal(Node n, String sourceName,
} else {
paramBuilder.addVarArgs(
createFromTypeNodesInternal(
arg.getFirstChild(), sourceName, scope, recordUnresolvedTypes));
arg.getFirstChild(), sourceName, scope));
}
} else {
JSType type = createFromTypeNodesInternal(
arg, sourceName, scope, recordUnresolvedTypes);
arg, sourceName, scope);
if (arg.getToken() == Token.EQUALS) {
boolean addSuccess = paramBuilder.addOptionalParams(type);
if (!addSuccess) {
Expand All @@ -1857,7 +1814,7 @@ private JSType createFromTypeNodesInternal(Node n, String sourceName,
}

JSType returnType =
createFromTypeNodesInternal(current, sourceName, scope, recordUnresolvedTypes);
createFromTypeNodesInternal(current, sourceName, scope);

return new FunctionBuilder(this)
.withParamsNode(paramBuilder.build())
Expand Down Expand Up @@ -1912,7 +1869,7 @@ private JSType createRecordTypeFromNodes(Node n, String sourceName,
if (hasType) {
// We have a declared type.
fieldType = createFromTypeNodesInternal(
fieldTypeNode.getLastChild(), sourceName, scope, true);
fieldTypeNode.getLastChild(), sourceName, scope);
} else {
// Otherwise, the type is UNKNOWN.
fieldType = getNativeType(JSTypeNative.UNKNOWN_TYPE);
Expand Down
4 changes: 3 additions & 1 deletion src/com/google/javascript/rhino/jstype/NamedType.java
Expand Up @@ -336,7 +336,9 @@ private void handleUnresolvedType(
if (!isForwardDeclared) {
warning(t, "Bad type annotation. Unknown type " + reference);
} else {
setReferencedType(new NoResolvedType(registry, getReferenceName()));
setReferencedType(
registry.getNativeObjectType(
JSTypeNative.NO_RESOLVED_TYPE));

if (validator != null) {
validator.apply(getReferencedType());
Expand Down
12 changes: 0 additions & 12 deletions src/com/google/javascript/rhino/jstype/NoResolvedType.java
Expand Up @@ -53,23 +53,11 @@
*/
class NoResolvedType extends NoType {
private static final long serialVersionUID = 1L;
/** The name originally used to reference this type, or {@code null} if none. */
private String referenceName;

NoResolvedType(JSTypeRegistry registry) {
super(registry);
}

NoResolvedType(JSTypeRegistry registry, String referenceName) {
this(registry);
this.referenceName = referenceName;
}

@Override
public String getReferenceName() {
return referenceName;
}

@Override
public boolean isNoResolvedType() {
return true;
Expand Down
8 changes: 0 additions & 8 deletions src/com/google/javascript/rhino/jstype/ProxyObjectType.java
Expand Up @@ -40,7 +40,6 @@
package com.google.javascript.rhino.jstype;

import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.javascript.rhino.ErrorReporter;
import com.google.javascript.rhino.JSDocInfo;
Expand Down Expand Up @@ -93,13 +92,6 @@ void setReferencedType(JSType referencedType) {
}
}

@Override
public boolean setValidator(Predicate<JSType> validator) {
// The referenced type might have specialized behavior for validation, e.g. {@link NamedType}
// defers validation until after named type resolution.
return referencedType.setValidator(validator);
}

@Override
public String getReferenceName() {
return referencedObjType == null ?
Expand Down

0 comments on commit 6ccbc2f

Please sign in to comment.