Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid duplicate calls in ReferenceBinding::superInterfaces #3601 #3622

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,7 @@ public ReferenceBinding superclass() {
return LambdaExpression.this.scope.getJavaLangObject();
}
@Override
public ReferenceBinding[] superInterfaces() {
protected ReferenceBinding[] superInterfacesRecursive(Map<ReferenceBinding, Object> visited) {
return new ReferenceBinding[] { (ReferenceBinding) LambdaExpression.this.resolvedType };
}
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2524,10 +2524,12 @@ private void detectCircularHierarchy() {

// NOTE: superInterfaces of binary types are resolved when needed
@Override
public ReferenceBinding[] superInterfaces() {

protected ReferenceBinding[] superInterfacesRecursive(Map<ReferenceBinding, Object> visited) {
if (visited.put(this, this) != null) { // do not evaluate the same type twice
return this.superInterfaces;
}
if (!isPrototype()) {
return this.superInterfaces = this.prototype.superInterfaces();
return this.superInterfaces = this.prototype.superInterfacesRecursive(visited); // TODO (visjee) protect from duplicated calls
}
if ((this.tagBits & TagBits.HasUnresolvedSuperinterfaces) == 0)
return this.superInterfaces;
Expand All @@ -2541,15 +2543,15 @@ public ReferenceBinding[] superInterfaces() {
boolean wasToleratingMissingTypeProcessingAnnotations = this.environment.mayTolerateMissingType;
this.environment.mayTolerateMissingType = true; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=360164
try {
this.superInterfaces[i].superclass();
this.superInterfaces[i].superclass(); // TODO (visjee) do I need to prevent duplicated calls here too? Probably NOT.
if (this.superInterfaces[i].isParameterizedType()) {
ReferenceBinding superType = this.superInterfaces[i].actualType();
if (TypeBinding.equalsEquals(superType, this)) {
this.tagBits |= TagBits.HierarchyHasProblems;
continue;
}
}
this.superInterfaces[i].superInterfaces();
this.superInterfaces[i].superInterfacesRecursive(visited); // TODO (visjee) protect from duplicated calls
} finally {
this.environment.mayTolerateMissingType = wasToleratingMissingTypeProcessingAnnotations;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void collectInferenceVariables(Set<InferenceVariable> variables) {
}

@Override
public ReferenceBinding[] superInterfaces() {
protected ReferenceBinding[] superInterfacesRecursive(Map<ReferenceBinding, Object> visited) {
return Binding.NO_SUPERINTERFACES;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

package org.eclipse.jdt.internal.compiler.lookup;

import java.util.Map;
import java.util.Set;
import org.eclipse.jdt.internal.compiler.ast.Wildcard;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
Expand Down Expand Up @@ -153,7 +154,7 @@ public ReferenceBinding superclass() {
}

@Override
public ReferenceBinding [] superInterfaces() {
protected ReferenceBinding[] superInterfacesRecursive(Map<ReferenceBinding, Object> visited) {
if (this.intersectingTypes[0].isClass()) {
ReferenceBinding [] superInterfaces = new ReferenceBinding[this.length - 1];
System.arraycopy(this.intersectingTypes, 1, superInterfaces, 0, this.length - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1551,11 +1551,12 @@ public ReferenceBinding superclass() {
* @see org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding#superInterfaces()
*/
@Override
public ReferenceBinding[] superInterfaces() {
if (this.superInterfaces == null) {
protected ReferenceBinding[] superInterfacesRecursive(Map<ReferenceBinding, Object> visited) {
// TODO (visjee) protect from duplicated calls
if (this.superInterfaces == null && visited.put(this, this) == null) {
if (this.type.isHierarchyBeingConnected())
return Binding.NO_SUPERINTERFACES; // prevent superinterfaces from being assigned before they are connected
this.superInterfaces = Scope.substitute(this, this.type.superInterfaces());
this.superInterfaces = Scope.substitute(this, this.type.superInterfacesRecursive(visited));
if (this.superInterfaces != null) {
for (int i = this.superInterfaces.length; --i >= 0;) {
this.typeBits |= (this.superInterfaces[i].typeBits & TypeIds.InheritableBits);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.eclipse.jdt.internal.compiler.lookup;

import java.lang.reflect.Field;
import java.util.Map;
import org.eclipse.jdt.core.compiler.CharOperation;

@SuppressWarnings("rawtypes")
Expand Down Expand Up @@ -60,10 +61,10 @@ public ReferenceBinding superclass() {
}

@Override
public ReferenceBinding[] superInterfaces() {
protected ReferenceBinding[] superInterfacesRecursive(Map<ReferenceBinding, Object> visited) {
if (this.closestMatch != null)
return this.closestMatch.superInterfaces();
return super.superInterfaces();
return this.closestMatch.superInterfacesRecursive(visited); // TODO (visjee) protect from duplicated calls
return super.superInterfacesRecursive(visited);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -2098,7 +2099,11 @@ public ReferenceBinding superclass() {
}

@Override
public ReferenceBinding[] superInterfaces() {
public final ReferenceBinding[] superInterfaces() {
return superInterfacesRecursive(new IdentityHashMap<>());
}

protected ReferenceBinding[] superInterfacesRecursive(Map<ReferenceBinding, Object> visited) {
return Binding.NO_SUPERINTERFACES;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3178,9 +3178,9 @@ public ReferenceBinding superclass() {
}

@Override
public ReferenceBinding[] superInterfaces() {
if (!isPrototype())
return this.superInterfaces = this.prototype.superInterfaces();
protected ReferenceBinding[] superInterfacesRecursive(Map<ReferenceBinding, Object> visited) {
if (!isPrototype() && visited.put(this, this) == null)
return this.superInterfaces = this.prototype.superInterfacesRecursive(visited); // TODO (visjee) protect from duplicated calls
return this.superInterfaces != null ? this.superInterfaces : isAnnotationType() ? this.superInterfaces = new ReferenceBinding [] { this.scope.getJavaLangAnnotationAnnotation() } : null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,17 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.Annotation;
import org.eclipse.jdt.internal.compiler.ast.NullAnnotationMatching;
import org.eclipse.jdt.internal.compiler.ast.NullAnnotationMatching.CheckMode;
import org.eclipse.jdt.internal.compiler.ast.TypeParameter;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
import org.eclipse.jdt.internal.compiler.ast.Wildcard;
import org.eclipse.jdt.internal.compiler.ast.NullAnnotationMatching.CheckMode;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants.BoundCheckStatus;
Expand Down Expand Up @@ -935,7 +936,7 @@ public ReferenceBinding superclass() {
}

@Override
public ReferenceBinding[] superInterfaces() {
protected ReferenceBinding[] superInterfacesRecursive(Map<ReferenceBinding, Object> visited) {
return this.superInterfaces;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
package org.eclipse.jdt.internal.compiler.lookup;

import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.ast.Annotation;
Expand Down Expand Up @@ -927,10 +928,10 @@ public ReferenceBinding superclass() {
}

@Override
public ReferenceBinding[] superInterfaces() {
if (this.superInterfaces == null) {
protected ReferenceBinding[] superInterfacesRecursive(Map<ReferenceBinding, Object> visited) {
if (this.superInterfaces == null && visited.put(this, this) == null) {
if (typeVariable() != null) {
this.superInterfaces = this.typeVariable.superInterfaces();
this.superInterfaces = this.typeVariable.superInterfacesRecursive(visited);// TODO (visjee) protect from duplicated calls
} else {
this.superInterfaces = Binding.NO_SUPERINTERFACES;
}
Expand Down
Loading