-
Notifications
You must be signed in to change notification settings - Fork 62
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
Performance tests and improvements: LLVM and Type updates #775
Changes from all commits
a8978c2
4c21a7b
1a7e48d
10065d0
640187f
b6a13d6
7ac0cdf
ed92556
3efb0f6
b3a7a1e
c0fa64c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,7 +131,7 @@ public void setModifiers(List<String> modifiers) { | |
} | ||
|
||
@Override | ||
public void typeChanged(HasType src, Collection<HasType> root, Type oldType) { | ||
public void typeChanged(HasType src, List<HasType> root, Type oldType) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to keep Collection in the function signature here? |
||
if (!TypeManager.isTypeSystemActive()) { | ||
return; | ||
} | ||
|
@@ -165,12 +165,11 @@ public void typeChanged(HasType src, Collection<HasType> root, Type oldType) { | |
} | ||
|
||
@Override | ||
public void possibleSubTypesChanged( | ||
HasType src, Collection<HasType> root, Set<Type> oldSubTypes) { | ||
public void possibleSubTypesChanged(HasType src, List<HasType> root) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here as well I guess |
||
if (!TypeManager.isTypeSystemActive()) { | ||
return; | ||
} | ||
Set<Type> subTypes = new HashSet<>(getPossibleSubTypes()); | ||
List<Type> subTypes = new ArrayList<>(getPossibleSubTypes()); | ||
subTypes.addAll(src.getPossibleSubTypes()); | ||
setPossibleSubTypes(subTypes, root); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ public abstract class ValueDeclaration extends Declaration implements HasType { | |
|
||
protected Type type = UnknownType.getUnknownType(); | ||
|
||
protected Set<Type> possibleSubTypes = new HashSet<>(); | ||
protected List<Type> possibleSubTypes = new ArrayList<>(); | ||
|
||
@Transient private final Set<TypeListener> typeListeners = new HashSet<>(); | ||
|
||
|
@@ -59,7 +59,7 @@ public Type getType() { | |
result = | ||
TypeManager.getInstance() | ||
.getTypeCache() | ||
.computeIfAbsent(this, n -> Collections.emptySet()) | ||
.computeIfAbsent(this, n -> Collections.emptyList()) | ||
.stream() | ||
.findAny() | ||
.orElse(UnknownType.getUnknownType()); | ||
|
@@ -83,7 +83,7 @@ public Type getPropagationType() { | |
} | ||
|
||
@Override | ||
public void setType(Type type, Collection<HasType> root) { | ||
public void setType(Type type, List<HasType> root) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. Keep signature and only change the implememation? |
||
if (!TypeManager.isTypeSystemActive()) { | ||
TypeManager.getInstance().cacheType(this, type); | ||
return; | ||
|
@@ -118,7 +118,7 @@ public void setType(Type type, Collection<HasType> root) { | |
TypeManager.getInstance() | ||
.registerType(TypeManager.getInstance().getCommonType(subTypes).orElse(type)); | ||
|
||
Set<Type> newSubtypes = new HashSet<>(); | ||
List<Type> newSubtypes = new ArrayList<>(); | ||
for (var s : subTypes) { | ||
if (TypeManager.getInstance().isSupertypeOf(this.type, s)) { | ||
newSubtypes.add(TypeManager.getInstance().registerType(s)); | ||
|
@@ -142,11 +142,11 @@ public void setType(Type type, Collection<HasType> root) { | |
|
||
@Override | ||
public void resetTypes(Type type) { | ||
Set<Type> oldSubTypes = new HashSet<>(getPossibleSubTypes()); | ||
List<Type> oldSubTypes = getPossibleSubTypes(); | ||
Type oldType = this.type; | ||
|
||
this.type = type; | ||
setPossibleSubTypes(new HashSet<>(List.of(type))); | ||
setPossibleSubTypes(List.of(type)); | ||
|
||
List<HasType> root = new ArrayList<>(List.of(this)); | ||
if (!Objects.equals(oldType, type)) { | ||
|
@@ -157,15 +157,15 @@ public void resetTypes(Type type) { | |
if (oldSubTypes.size() != 1 || !oldSubTypes.contains(type)) | ||
this.typeListeners.stream() | ||
.filter(l -> !l.equals(this)) | ||
.forEach(l -> l.possibleSubTypesChanged(this, root, oldSubTypes)); | ||
.forEach(l -> l.possibleSubTypesChanged(this, root)); | ||
} | ||
|
||
@Override | ||
public void registerTypeListener(TypeListener listener) { | ||
List<HasType> root = new ArrayList<>(List.of(this)); | ||
typeListeners.add(listener); | ||
listener.typeChanged(this, root, this.type); | ||
listener.possibleSubTypesChanged(this, root, this.possibleSubTypes); | ||
listener.possibleSubTypesChanged(this, root); | ||
} | ||
|
||
@Override | ||
|
@@ -179,19 +179,20 @@ public Set<TypeListener> getTypeListeners() { | |
} | ||
|
||
@Override | ||
public Set<Type> getPossibleSubTypes() { | ||
public List<Type> getPossibleSubTypes() { | ||
if (!TypeManager.isTypeSystemActive()) { | ||
return TypeManager.getInstance().getTypeCache().getOrDefault(this, Collections.emptySet()); | ||
return TypeManager.getInstance().getTypeCache().getOrDefault(this, Collections.emptyList()); | ||
} | ||
return possibleSubTypes; | ||
} | ||
|
||
@Override | ||
public void setPossibleSubTypes(Set<Type> possibleSubTypes, @NotNull Collection<HasType> root) { | ||
public void setPossibleSubTypes(List<Type> possibleSubTypes, @NotNull List<HasType> root) { | ||
possibleSubTypes = | ||
possibleSubTypes.stream() | ||
.filter(Predicate.not(TypeManager.getInstance()::isUnknown)) | ||
.collect(Collectors.toSet()); | ||
.distinct() | ||
.collect(Collectors.toList()); | ||
|
||
if (!TypeManager.isTypeSystemActive()) { | ||
possibleSubTypes.forEach(t -> TypeManager.getInstance().cacheType(this, t)); | ||
|
@@ -201,16 +202,19 @@ public void setPossibleSubTypes(Set<Type> possibleSubTypes, @NotNull Collection< | |
if (root.contains(this)) { | ||
return; | ||
} | ||
root.add(this); | ||
|
||
Set<Type> oldSubTypes = this.possibleSubTypes; | ||
List<Type> oldSubTypes = this.possibleSubTypes; | ||
this.possibleSubTypes = possibleSubTypes; | ||
|
||
if (!this.possibleSubTypes.equals(oldSubTypes)) { | ||
for (var listener : this.typeListeners) { | ||
if (!listener.equals(this)) { | ||
listener.possibleSubTypesChanged(this, root, oldSubTypes); | ||
} | ||
if (new HashSet<>(oldSubTypes).containsAll(getPossibleSubTypes())) { | ||
// Nothing changed, so we do not have to notify the listeners. | ||
return; | ||
} | ||
root.add(this); // Add current node to the set of "triggers" to detect potential loops. | ||
// Notify all listeners about the changed type | ||
for (var listener : this.typeListeners) { | ||
if (!listener.equals(this)) { | ||
listener.possibleSubTypesChanged(this, root); | ||
} | ||
} | ||
} | ||
|
@@ -220,7 +224,7 @@ public void refreshType() { | |
List<HasType> root = new ArrayList<>(List.of(this)); | ||
for (var l : this.typeListeners) { | ||
l.typeChanged(this, root, type); | ||
l.possibleSubTypesChanged(this, root, possibleSubTypes); | ||
l.possibleSubTypesChanged(this, root); | ||
} | ||
} | ||
|
||
|
@@ -254,7 +258,7 @@ public void updateType(Type type) { | |
} | ||
|
||
@Override | ||
public void updatePossibleSubtypes(Set<Type> types) { | ||
public void updatePossibleSubtypes(List<Type> types) { | ||
this.possibleSubTypes = types; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this essentially the same as a set does? Not sure this is really faster / better here.