Fix & optimize DataFlowInfo.or()
Get complete nullability & type info before creating a new data flow info. Don't create unnecessary data flow infos
This commit is contained in:
+18
-19
@@ -171,13 +171,6 @@ import static org.jetbrains.jet.lang.resolve.calls.autocasts.Nullability.NOT_NUL
|
|||||||
return new DelegatingDataFlowInfo(this, newNullabilityInfo, newTypeInfo);
|
return new DelegatingDataFlowInfo(this, newNullabilityInfo, newTypeInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private ListMultimap<DataFlowValue, JetType> copyTypeInfo() {
|
|
||||||
ListMultimap<DataFlowValue, JetType> newTypeInfo = newTypeInfo();
|
|
||||||
newTypeInfo.putAll(typeInfo);
|
|
||||||
return newTypeInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public DataFlowInfo and(@NotNull DataFlowInfo otherInfo) {
|
public DataFlowInfo and(@NotNull DataFlowInfo otherInfo) {
|
||||||
@@ -211,28 +204,30 @@ import static org.jetbrains.jet.lang.resolve.calls.autocasts.Nullability.NOT_NUL
|
|||||||
@Override
|
@Override
|
||||||
public DataFlowInfo or(@NotNull DataFlowInfo otherInfo) {
|
public DataFlowInfo or(@NotNull DataFlowInfo otherInfo) {
|
||||||
if (otherInfo == EMPTY) return EMPTY;
|
if (otherInfo == EMPTY) return EMPTY;
|
||||||
|
if (this == EMPTY) return EMPTY;
|
||||||
|
if (this == otherInfo) return this;
|
||||||
|
|
||||||
assert otherInfo instanceof DelegatingDataFlowInfo : "Unknown DataFlowInfo type: " + otherInfo;
|
assert otherInfo instanceof DelegatingDataFlowInfo : "Unknown DataFlowInfo type: " + otherInfo;
|
||||||
DelegatingDataFlowInfo other = (DelegatingDataFlowInfo) otherInfo;
|
DelegatingDataFlowInfo other = (DelegatingDataFlowInfo) otherInfo;
|
||||||
|
|
||||||
Map<DataFlowValue, Nullability> builder = Maps.newHashMap(nullabilityInfo);
|
Map<DataFlowValue, Nullability> nullabilityMapBuilder = Maps.newHashMap();
|
||||||
builder.keySet().retainAll(other.nullabilityInfo.keySet());
|
for (Map.Entry<DataFlowValue, Nullability> entry : other.getCompleteNullabilityInfo().entrySet()) {
|
||||||
for (Map.Entry<DataFlowValue, Nullability> entry : builder.entrySet()) {
|
|
||||||
DataFlowValue key = entry.getKey();
|
DataFlowValue key = entry.getKey();
|
||||||
Nullability thisFlags = entry.getValue();
|
Nullability otherFlags = entry.getValue();
|
||||||
Nullability otherFlags = other.nullabilityInfo.get(key);
|
Nullability thisFlags = getNullability(key);
|
||||||
assert (otherFlags != null);
|
nullabilityMapBuilder.put(key, thisFlags.or(otherFlags));
|
||||||
builder.put(key, thisFlags.or(otherFlags));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ListMultimap<DataFlowValue, JetType> myTypeInfo = getCompleteTypeInfo();
|
||||||
|
ListMultimap<DataFlowValue, JetType> otherTypeInfo = other.getCompleteTypeInfo();
|
||||||
ListMultimap<DataFlowValue, JetType> newTypeInfo = newTypeInfo();
|
ListMultimap<DataFlowValue, JetType> newTypeInfo = newTypeInfo();
|
||||||
|
|
||||||
Set<DataFlowValue> keys = Sets.newHashSet(typeInfo.keySet());
|
Set<DataFlowValue> keys = Sets.newHashSet(myTypeInfo.keySet());
|
||||||
keys.retainAll(other.typeInfo.keySet());
|
keys.retainAll(otherTypeInfo.keySet());
|
||||||
|
|
||||||
for (DataFlowValue key : keys) {
|
for (DataFlowValue key : keys) {
|
||||||
Collection<JetType> thisTypes = typeInfo.get(key);
|
Collection<JetType> thisTypes = myTypeInfo.get(key);
|
||||||
Collection<JetType> otherTypes = other.typeInfo.get(key);
|
Collection<JetType> otherTypes = otherTypeInfo.get(key);
|
||||||
|
|
||||||
Collection<JetType> newTypes = Sets.newHashSet(thisTypes);
|
Collection<JetType> newTypes = Sets.newHashSet(thisTypes);
|
||||||
newTypes.retainAll(otherTypes);
|
newTypes.retainAll(otherTypes);
|
||||||
@@ -240,7 +235,11 @@ import static org.jetbrains.jet.lang.resolve.calls.autocasts.Nullability.NOT_NUL
|
|||||||
newTypeInfo.putAll(key, newTypes);
|
newTypeInfo.putAll(key, newTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new DelegatingDataFlowInfo(null, ImmutableMap.copyOf(builder), newTypeInfo);
|
if (nullabilityMapBuilder.isEmpty() && newTypeInfo.isEmpty()) {
|
||||||
|
return EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new DelegatingDataFlowInfo(null, ImmutableMap.copyOf(nullabilityMapBuilder), newTypeInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
Reference in New Issue
Block a user