public boolean checkEquivalenceHelper(TemplateTypeMap that, EquivalenceMethod eqMethod, EqCache eqCache) { boolean result = false; if (!this.inRecursiveEquivalenceCheck && !that.inRecursiveEquivalenceCheck) { this.inRecursiveEquivalenceCheck = true; that.inRecursiveEquivalenceCheck = true; result = checkEquivalenceHelper(eqMethod, this, that, eqCache) && checkEquivalenceHelper(eqMethod, that, this, eqCache); this.inRecursiveEquivalenceCheck = false; that.inRecursiveEquivalenceCheck = false; } return result; }
/** * Determines if this map and the specified map have equivalent template * types. */ public boolean checkEquivalenceHelper( TemplateTypeMap that, EquivalenceMethod eqMethod) { return checkEquivalenceHelper(that, eqMethod, EqCache.create()); }
/** * Determines if this map and the specified map have equivalent template * types. */ public boolean checkEquivalenceHelper( TemplateTypeMap that, EquivalenceMethod eqMethod, SubtypingMode subtypingMode) { return checkEquivalenceHelper(that, eqMethod, EqCache.create(), subtypingMode); }
public boolean checkEquivalenceHelper(TemplateTypeMap that, EquivalenceMethod eqMethod, EqCache eqCache, SubtypingMode subtypingMode) { @Nullable MatchStatus status = eqCache.checkCache(this, that); if (status == null) { boolean result = checkEquivalenceHelper(eqMethod, this, that, eqCache, subtypingMode) && checkEquivalenceHelper(eqMethod, that, this, eqCache, subtypingMode); eqCache.updateCache(this, that, result ? MatchStatus.MATCH : MatchStatus.NOT_MATCH); return result; } else { return status.subtypeValue(); } }
/** * Computes the greatest subtype of two related templatized types. * @return The greatest subtype. */ JSType getGreatestSubtypeHelper(JSType rawThat) { checkNotNull(rawThat); if (!wrapsSameRawType(rawThat)) { if (!rawThat.isTemplatizedType()) { if (this.isSubtype(rawThat)) { return this; } else if (rawThat.isSubtypeOf(this)) { return filterNoResolvedType(rawThat); } } if (this.isObject() && rawThat.isObject()) { return this.getNativeType(JSTypeNative.NO_OBJECT_TYPE); } return this.getNativeType(JSTypeNative.NO_TYPE); } TemplatizedType that = rawThat.toMaybeTemplatizedType(); checkNotNull(that); if (getTemplateTypeMap().checkEquivalenceHelper( that.getTemplateTypeMap(), EquivalenceMethod.INVARIANT, SubtypingMode.NORMAL)) { return this; } // For types that have the same raw type but different type parameters, // we simply create a type has a "unknown" type parameter. This is // equivalent to the raw type. return getReferencedObjTypeInternal(); }
/** * Computes the greatest subtype of two related templatized types. * @return The greatest subtype. */ JSType getGreatestSubtypeHelper(JSType rawThat) { Preconditions.checkNotNull(rawThat); if (!wrapsSameRawType(rawThat)) { if (!rawThat.isTemplatizedType()) { if (this.isSubtype(rawThat)) { return this; } else if (rawThat.isSubtype(this)) { return filterNoResolvedType(rawThat); } } if (this.isObject() && rawThat.isObject()) { return this.getNativeType(JSTypeNative.NO_OBJECT_TYPE); } return this.getNativeType(JSTypeNative.NO_TYPE); } TemplatizedType that = rawThat.toMaybeTemplatizedType(); Preconditions.checkNotNull(that); if (getTemplateTypeMap().checkEquivalenceHelper( that.getTemplateTypeMap(), EquivalenceMethod.INVARIANT)) { return this; } // For types that have the same raw type but different type parameters, // we simply create a type has a "unknown" type parameter. This is // equivalent to the raw type. return getReferencedObjTypeInternal(); }
if (alternate.getTemplateTypeMap().checkEquivalenceHelper( current.getTemplateTypeMap(), EquivalenceMethod.IDENTITY,
if (alternate.getTemplateTypeMap().checkEquivalenceHelper( current.getTemplateTypeMap(), EquivalenceMethod.IDENTITY)) {
/** * Check for structural equivalence with {@code that}. * (e.g. two @record types with the same prototype properties) */ final boolean checkStructuralEquivalenceHelper( ObjectType otherObject, EquivalenceMethod eqMethod, EqCache eqCache) { if (this.isTemplatizedType() && this.toMaybeTemplatizedType().wrapsSameRawType(otherObject)) { return this.getTemplateTypeMap().checkEquivalenceHelper( otherObject.getTemplateTypeMap(), eqMethod, eqCache, SubtypingMode.NORMAL); } MatchStatus result = eqCache.checkCache(this, otherObject); if (result != null) { return result.subtypeValue(); } Set<String> keySet = getPropertyNames(); Set<String> otherKeySet = otherObject.getPropertyNames(); if (!otherKeySet.equals(keySet)) { eqCache.updateCache(this, otherObject, MatchStatus.NOT_MATCH); return false; } for (String key : keySet) { if (!otherObject.getPropertyType(key).checkEquivalenceHelper( getPropertyType(key), eqMethod, eqCache)) { eqCache.updateCache(this, otherObject, MatchStatus.NOT_MATCH); return false; } } eqCache.updateCache(this, otherObject, MatchStatus.MATCH); return true; }
/** * Check for structural equivalence with {@code that}. * (e.g. two @record types with the same prototype properties) */ boolean checkStructuralEquivalenceHelper( ObjectType otherObject, EquivalenceMethod eqMethod, EqCache eqCache) { if (this.isTemplatizedType() && this.toMaybeTemplatizedType().wrapsSameRawType(otherObject)) { return this.getTemplateTypeMap().checkEquivalenceHelper( otherObject.getTemplateTypeMap(), eqMethod, eqCache); } MatchStatus result = eqCache.checkCache(this, otherObject); if (result != null) { return result.subtypeValue(); } Set<String> keySet = getPropertyNames(); Set<String> otherKeySet = otherObject.getPropertyNames(); if (!otherKeySet.equals(keySet)) { eqCache.updateCache(this, otherObject, MatchStatus.NOT_MATCH); return false; } for (String key : keySet) { if (!otherObject.getPropertyType(key).checkEquivalenceHelper( getPropertyType(key), eqMethod, eqCache)) { eqCache.updateCache(this, otherObject, MatchStatus.NOT_MATCH); return false; } } eqCache.updateCache(this, otherObject, MatchStatus.MATCH); return true; }
if (!getTemplateTypeMap().checkEquivalenceHelper( that.getTemplateTypeMap(), eqMethod, eqCache, SubtypingMode.NORMAL)) { return false;
templateMatch = thisTypeParams.checkEquivalenceHelper( thatTypeParams, EquivalenceMethod.INVARIANT, subtypingMode);
if (!getTemplateTypeMap().checkEquivalenceHelper( that.getTemplateTypeMap(), eqMethod, eqCache)) { return false;
|| thatElement.isSubtype(thisElement, implicitImplCache); } else { templateMatch = thisTypeParams.checkEquivalenceHelper( thatTypeParams, EquivalenceMethod.INVARIANT);