Skip to content

Commit

Permalink
[NTI] Convert j2clcheckspass to use TypeI.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=134724323
  • Loading branch information
dimvar authored and blickly committed Sep 30, 2016
1 parent 958f814 commit b0a803c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 15 deletions.
12 changes: 6 additions & 6 deletions src/com/google/javascript/jscomp/DefaultPassConfig.java
Expand Up @@ -489,23 +489,23 @@ protected List<PassFactory> getChecks() {
checks.add(computeFunctionNames); checks.add(computeFunctionNames);
} }


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

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


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

checks.add(createEmptyPass("afterStandardChecks")); checks.add(createEmptyPass("afterStandardChecks"));


assertAllOneTimePasses(checks); assertAllOneTimePasses(checks);
Expand Down
16 changes: 8 additions & 8 deletions src/com/google/javascript/jscomp/J2clChecksPass.java
Expand Up @@ -17,10 +17,10 @@


import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.javascript.jscomp.NodeTraversal.AbstractPostOrderCallback; import com.google.javascript.jscomp.NodeTraversal.AbstractPostOrderCallback;
import com.google.javascript.rhino.FunctionTypeI;
import com.google.javascript.rhino.Node; import com.google.javascript.rhino.Node;
import com.google.javascript.rhino.Token; import com.google.javascript.rhino.Token;
import com.google.javascript.rhino.jstype.FunctionType; import com.google.javascript.rhino.TypeI;
import com.google.javascript.rhino.jstype.JSType;
import java.util.Map; import java.util.Map;


/** /**
Expand Down Expand Up @@ -61,8 +61,8 @@ private void checkReferenceEquality(
|| n.getToken() == Token.EQ || n.getToken() == Token.EQ
|| n.getToken() == Token.SHNE || n.getToken() == Token.SHNE
|| n.getToken() == Token.NE) { || n.getToken() == Token.NE) {
JSType firstJsType = n.getFirstChild().getJSType(); TypeI firstJsType = n.getFirstChild().getTypeI();
JSType lastJsType = n.getLastChild().getJSType(); TypeI lastJsType = n.getLastChild().getTypeI();
boolean hasType = isType(firstJsType, fileName) || isType(lastJsType, fileName); boolean hasType = isType(firstJsType, fileName) || isType(lastJsType, fileName);
boolean hasNullType = isNullType(firstJsType) || isNullType(lastJsType); boolean hasNullType = isNullType(firstJsType) || isNullType(lastJsType);
if (hasType && !hasNullType) { if (hasType && !hasNullType) {
Expand All @@ -71,14 +71,14 @@ private void checkReferenceEquality(
} }
} }


private boolean isNullType(JSType jsType) { private boolean isNullType(TypeI jsType) {
if (jsType == null) { if (jsType == null) {
return false; return false;
} }
return jsType.isNullType() || jsType.isVoidType(); return jsType.isNullType() || jsType.isVoidType();
} }


private boolean isType(JSType jsType, String fileName) { private boolean isType(TypeI jsType, String fileName) {
if (jsType == null) { if (jsType == null) {
return false; return false;
} }
Expand All @@ -90,8 +90,8 @@ private boolean isType(JSType jsType, String fileName) {
return sourceName != null && sourceName.endsWith(fileName); return sourceName != null && sourceName.endsWith(fileName);
} }


private String getSourceName(JSType jsType) { private String getSourceName(TypeI jsType) {
FunctionType constructor = jsType.toMaybeObjectType().getConstructor(); FunctionTypeI constructor = jsType.toMaybeObjectType().getConstructor();
if (constructor == null) { if (constructor == null) {
return ""; return "";
} }
Expand Down
10 changes: 10 additions & 0 deletions src/com/google/javascript/jscomp/newtypes/JSType.java
Expand Up @@ -1586,6 +1586,16 @@ public boolean isVoidable() {
return !isTop() && (getMask() & UNDEFINED_MASK) != 0; return !isTop() && (getMask() & UNDEFINED_MASK) != 0;
} }


@Override
public boolean isNullType() {
return equals(this.commonTypes.NULL);
}

@Override
public boolean isVoidType() {
return equals(this.commonTypes.UNDEFINED);
}

@Override @Override
public TypeI restrictByNotNullOrUndefined() { public TypeI restrictByNotNullOrUndefined() {
return this.removeType(this.commonTypes.NULL_OR_UNDEFINED); return this.removeType(this.commonTypes.NULL_OR_UNDEFINED);
Expand Down
4 changes: 4 additions & 0 deletions src/com/google/javascript/rhino/TypeI.java
Expand Up @@ -82,6 +82,10 @@ public interface TypeI {


boolean isVoidable(); boolean isVoidable();


boolean isNullType();

boolean isVoidType();

boolean isPrototypeObject(); boolean isPrototypeObject();


boolean isInstanceofObject(); boolean isInstanceofObject();
Expand Down
2 changes: 2 additions & 0 deletions src/com/google/javascript/rhino/jstype/JSType.java
Expand Up @@ -249,10 +249,12 @@ public boolean isDateType() {
return false; return false;
} }


@Override
public boolean isNullType() { public boolean isNullType() {
return false; return false;
} }


@Override
public boolean isVoidType() { public boolean isVoidType() {
return false; return false;
} }
Expand Down
3 changes: 2 additions & 1 deletion test/com/google/javascript/jscomp/J2clCheckPassTest.java
Expand Up @@ -18,9 +18,10 @@
import static com.google.javascript.jscomp.J2clChecksPass.J2CL_REFERENCE_EQUALITY; import static com.google.javascript.jscomp.J2clChecksPass.J2CL_REFERENCE_EQUALITY;
import static com.google.javascript.jscomp.J2clChecksPass.REFERENCE_EQUALITY_TYPE_PATTERNS; import static com.google.javascript.jscomp.J2clChecksPass.REFERENCE_EQUALITY_TYPE_PATTERNS;


public class J2clCheckPassTest extends CompilerTestCase { public class J2clCheckPassTest extends TypeICompilerTestCase {


public J2clCheckPassTest() { public J2clCheckPassTest() {
super(DEFAULT_EXTERNS);
enableTypeCheck(); enableTypeCheck();
} }


Expand Down

0 comments on commit b0a803c

Please sign in to comment.