From 0197beaa8e034acf2e57f169f8395166aa23fbd6 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Mon, 2 Dec 2024 18:54:24 +0000 Subject: [PATCH] [flow analysis] Remove _typeContains method. It wasn't necessary; `List.contains` does the same thing. Also, remove the plumbing for `typeOperations`, a parameter of `_typeContains` that was not used. Change-Id: I688835512e58cb7a24336318b2006c9913c77888 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/398300 Auto-Submit: Paul Berry Reviewed-by: Kallen Tu Commit-Queue: Kallen Tu --- .../lib/src/flow_analysis/flow_analysis.dart | 48 +++++++------------ .../flow_analysis/flow_analysis_test.dart | 16 +++---- 2 files changed, 25 insertions(+), 39 deletions(-) diff --git a/pkg/_fe_analyzer_shared/lib/src/flow_analysis/flow_analysis.dart b/pkg/_fe_analyzer_shared/lib/src/flow_analysis/flow_analysis.dart index e71f2f70f13..7911e71c96a 100644 --- a/pkg/_fe_analyzer_shared/lib/src/flow_analysis/flow_analysis.dart +++ b/pkg/_fe_analyzer_shared/lib/src/flow_analysis/flow_analysis.dart @@ -2400,8 +2400,8 @@ class FlowModel { PromotionModel? otherPromotionModel = right?.model; PromotionModel newPromotionModel = otherPromotionModel == null ? promotionModel - : PromotionModel.inheritTested(helper.typeOperations, promotionModel, - otherPromotionModel.tested); + : PromotionModel.inheritTested( + promotionModel, otherPromotionModel.tested); if (!identical(newPromotionModel, promotionModel)) { result = result.updatePromotionInfo(helper, promotionKey, newPromotionModel); @@ -2496,8 +2496,8 @@ class FlowModel { } // Tests are kept regardless of whether they are in `this` model or the // new base model. - List newTested = PromotionModel.joinTested( - thisModel.tested, baseModel.tested, helper.typeOperations); + List newTested = + PromotionModel.joinTested(thisModel.tested, baseModel.tested); // The variable is definitely assigned if it was definitely assigned // either in `this` model or the new base model. bool newAssigned = thisModel.assigned || baseModel.assigned; @@ -2720,8 +2720,7 @@ class FlowModel { Type? promotedType) { List newTested = info.tested; if (testedType != null) { - newTested = PromotionModel._addTypeToUniqueList( - info.tested, testedType, helper.typeOperations); + newTested = PromotionModel._addTypeToUniqueList(info.tested, testedType); } List? newPromotedTypes = info.promotedTypes; @@ -3321,7 +3320,7 @@ class PromotionModel { } // Add only unique candidates. - if (!_typeListContains(typeOperations, candidates!, type)) { + if (!candidates!.contains(type)) { candidates!.add(type); return; } @@ -3390,10 +3389,8 @@ class PromotionModel { /// regardless of the type of loop. @visibleForTesting static PromotionModel inheritTested( - FlowAnalysisTypeOperations typeOperations, - PromotionModel model, - List tested) { - List newTested = joinTested(tested, model.tested, typeOperations); + PromotionModel model, List tested) { + List newTested = joinTested(tested, model.tested); if (identical(newTested, model.tested)) return model; return new PromotionModel( promotedTypes: model.promotedTypes, @@ -3429,9 +3426,8 @@ class PromotionModel { bool newAssigned = first.assigned && second.assigned; bool newUnassigned = first.unassigned && second.unassigned; bool newWriteCaptured = first.writeCaptured || second.writeCaptured; - List newTested = newWriteCaptured - ? const [] - : joinTested(first.tested, second.tested, typeOperations); + List newTested = + newWriteCaptured ? const [] : joinTested(first.tested, second.tested); SsaNode? newSsaNode = propertySsaNode; if (newSsaNode == null && !newWriteCaptured) { (newSsaNode, newFlowModel) = SsaNode._join( @@ -3500,8 +3496,8 @@ class PromotionModel { /// small in real-world cases) /// - The sense of equality for the union operation is determined by `==`. /// - The types of interests lists are considered immutable. - static List joinTested(List types1, - List types2, FlowAnalysisTypeOperations typeOperations) { + static List joinTested( + List types1, List types2) { // Ensure that types1 is the shorter list. if (types1.length > types2.length) { List tmp = types1; @@ -3517,11 +3513,11 @@ class PromotionModel { // not present in it. for (int i = shared; i < types1.length; i++) { Type typeToAdd = types1[i]; - if (_typeListContains(typeOperations, types2, typeToAdd)) continue; + if (types2.contains(typeToAdd)) continue; List result = types2.toList()..add(typeToAdd); for (i++; i < types1.length; i++) { typeToAdd = types1[i]; - if (_typeListContains(typeOperations, types2, typeToAdd)) continue; + if (types2.contains(typeToAdd)) continue; result.add(typeToAdd); } return result; @@ -3575,9 +3571,9 @@ class PromotionModel { ? [promoted] : (promotedTypes.toList()..add(promoted)); - static List _addTypeToUniqueList(List types, - Type newType, FlowAnalysisTypeOperations typeOperations) { - if (_typeListContains(typeOperations, types, newType)) return types; + static List _addTypeToUniqueList( + List types, Type newType) { + if (types.contains(newType)) return types; return new List.of(types)..add(newType); } @@ -3612,16 +3608,6 @@ class PromotionModel { ssaNode: newSsaNode); } } - - static bool _typeListContains( - FlowAnalysisTypeOperations typeOperations, - List list, - Type searchType) { - for (Type type in list) { - if (type == searchType) return true; - } - return false; - } } /// Non-promotion reason describing the situation where an expression was not diff --git a/pkg/_fe_analyzer_shared/test/flow_analysis/flow_analysis_test.dart b/pkg/_fe_analyzer_shared/test/flow_analysis/flow_analysis_test.dart index d4467029df5..97f1aa49852 100644 --- a/pkg/_fe_analyzer_shared/test/flow_analysis/flow_analysis_test.dart +++ b/pkg/_fe_analyzer_shared/test/flow_analysis/flow_analysis_test.dart @@ -4846,24 +4846,24 @@ main() { var s1 = _makeTypes(['double', 'int']); var s2 = _makeTypes(['double', 'int', 'bool']); var expected = _matchOfInterestSet(['double', 'int', 'bool']); - expect(PromotionModel.joinTested(s1, s2, h.typeOperations), expected); - expect(PromotionModel.joinTested(s2, s1, h.typeOperations), expected); + expect(PromotionModel.joinTested(s1, s2), expected); + expect(PromotionModel.joinTested(s2, s1), expected); }); test('common prefix', () { var s1 = _makeTypes(['double', 'int', 'String']); var s2 = _makeTypes(['double', 'int', 'bool']); var expected = _matchOfInterestSet(['double', 'int', 'String', 'bool']); - expect(PromotionModel.joinTested(s1, s2, h.typeOperations), expected); - expect(PromotionModel.joinTested(s2, s1, h.typeOperations), expected); + expect(PromotionModel.joinTested(s1, s2), expected); + expect(PromotionModel.joinTested(s2, s1), expected); }); test('order mismatch', () { var s1 = _makeTypes(['double', 'int']); var s2 = _makeTypes(['int', 'double']); var expected = _matchOfInterestSet(['double', 'int']); - expect(PromotionModel.joinTested(s1, s2, h.typeOperations), expected); - expect(PromotionModel.joinTested(s2, s1, h.typeOperations), expected); + expect(PromotionModel.joinTested(s1, s2), expected); + expect(PromotionModel.joinTested(s2, s1), expected); }); test('small common prefix', () { @@ -4871,8 +4871,8 @@ main() { var s2 = _makeTypes(['int', 'List', 'bool', 'Future']); var expected = _matchOfInterestSet( ['int', 'double', 'String', 'bool', 'List', 'Future']); - expect(PromotionModel.joinTested(s1, s2, h.typeOperations), expected); - expect(PromotionModel.joinTested(s2, s1, h.typeOperations), expected); + expect(PromotionModel.joinTested(s1, s2), expected); + expect(PromotionModel.joinTested(s2, s1), expected); }); });