Skip to content

Commit aa34de3

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Flow analysis: adjust _variableInfosEqual to do a shallow comparison.
Previously we were doing a deep comparison, but this wasn't sustainable. The reason _variableInfosEqual exists is to verify the logic used by FlowModel.restrict() to determine whether to re-use a previous variableInfo structure. Since that logic is based on a shallow comparison, the logic in _variableInfosEqual needs to do a shallow comparison as well. Change-Id: Id0f48a3f450a9210d4f6e6d919bb7a3e311ad458 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/115621 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent ea35690 commit aa34de3

File tree

2 files changed

+8
-29
lines changed

2 files changed

+8
-29
lines changed

pkg/front_end/lib/src/fasta/flow_analysis/flow_analysis.dart

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -942,10 +942,9 @@ class FlowModel<Variable, Type> {
942942
if (!identical(restricted, otherModel)) variableInfoMatchesOther = false;
943943
}
944944
assert(variableInfoMatchesThis ==
945-
_variableInfosEqual(typeOperations, newVariableInfo, variableInfo));
945+
_variableInfosEqual(newVariableInfo, variableInfo));
946946
assert(variableInfoMatchesOther ==
947-
_variableInfosEqual(
948-
typeOperations, newVariableInfo, other.variableInfo));
947+
_variableInfosEqual(newVariableInfo, other.variableInfo));
949948
if (variableInfoMatchesThis) {
950949
newVariableInfo = variableInfo;
951950
} else if (variableInfoMatchesOther) {
@@ -1072,23 +1071,19 @@ class FlowModel<Variable, Type> {
10721071
}
10731072

10741073
/// Determines whether the given "variableInfo" maps are equivalent.
1074+
///
1075+
/// The equivalence check is shallow; if two variables' models are not
1076+
/// identical, we return `false`.
10751077
static bool _variableInfosEqual<Variable, Type>(
1076-
TypeOperations<Variable, Type> typeOperations,
10771078
Map<Variable, VariableModel<Type>> p1,
10781079
Map<Variable, VariableModel<Type>> p2) {
10791080
if (p1.length != p2.length) return false;
10801081
if (!p1.keys.toSet().containsAll(p2.keys)) return false;
10811082
for (MapEntry<Variable, VariableModel<Type>> entry in p1.entries) {
10821083
VariableModel<Type> p1Value = entry.value;
10831084
VariableModel<Type> p2Value = p2[entry.key];
1084-
if (p1Value == null) {
1085-
if (p2Value != null) return false;
1086-
} else {
1087-
if (p2Value == null) return false;
1088-
if (!VariableModel._variableModelsEqual<Type>(
1089-
typeOperations, p1Value, p2Value)) {
1090-
return false;
1091-
}
1085+
if (!identical(p1Value, p2Value)) {
1086+
return false;
10921087
}
10931088
}
10941089
return true;
@@ -1223,21 +1218,4 @@ class VariableModel<Type> {
12231218
return new VariableModel<Type>(newPromotedType, newAssigned);
12241219
}
12251220
}
1226-
1227-
/// Determines whether the given variable models are equivalent.
1228-
static bool _variableModelsEqual<Type>(
1229-
TypeOperations<Object, Type> typeOperations,
1230-
VariableModel<Type> model1,
1231-
VariableModel<Type> model2) {
1232-
Type p1Type = model1.promotedType;
1233-
Type p2Type = model2.promotedType;
1234-
if (p1Type == null) {
1235-
if (p2Type != null) return false;
1236-
} else {
1237-
if (p2Type == null) return false;
1238-
if (!typeOperations.isSameType(p1Type, p2Type)) return false;
1239-
}
1240-
if (model1.assigned != model2.assigned) return false;
1241-
return true;
1242-
}
12431221
}

pkg/front_end/test/spell_checking_list_common.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,7 @@ environment
902902
equal
903903
equality
904904
equals
905+
equivalence
905906
equivalent
906907
equivalents
907908
erroneous

0 commit comments

Comments
 (0)