Skip to content

Commit 8939d1e

Browse files
natebiggsCommit Queue
authored and
Commit Queue
committed
[dart2js] Migrate iterable tracers in inferrer.
Change-Id: I0a9eba5a65cb6dd1b8db5aef53c3a2caed9530b9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/260803 Commit-Queue: Nate Biggs <[email protected]> Reviewed-by: Mayank Patke <[email protected]>
1 parent dd63e54 commit 8939d1e

File tree

6 files changed

+56
-64
lines changed

6 files changed

+56
-64
lines changed

pkg/compiler/lib/src/inferrer/list_tracer.dart

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.10
6-
75
library compiler.src.inferrer.list_tracer;
86

97
import '../common/names.dart';
108
import '../elements/entities.dart';
119
import '../native/behavior.dart';
12-
import '../universe/selector.dart' show Selector;
1310
import '../util/util.dart' show Setlet;
1411
import 'node_tracer.dart';
1512
import 'type_graph_nodes.dart';
@@ -136,14 +133,14 @@ class ListTracerVisitor extends TracerVisitor {
136133
Set<TypeInformation> inputs = Setlet<TypeInformation>();
137134
bool callsGrowableMethod = false;
138135

139-
ListTracerVisitor(tracedType, inferrer) : super(tracedType, inferrer);
136+
ListTracerVisitor(super.tracedType, super.inferrer);
140137

141138
/// Returns [true] if the analysis completed successfully, [false] if it
142139
/// bailed out. In the former case, [inputs] holds a list of
143140
/// [TypeInformation] nodes that flow into the element type of this list.
144141
bool run() {
145142
analyze();
146-
ListTypeInformation list = tracedType;
143+
final list = tracedType as ListTypeInformation;
147144
if (continueAnalyzing) {
148145
if (!callsGrowableMethod && list.inferredLength == null) {
149146
list.inferredLength = list.originalLength;
@@ -152,7 +149,7 @@ class ListTracerVisitor extends TracerVisitor {
152149
return true;
153150
} else {
154151
callsGrowableMethod = true;
155-
inputs = null;
152+
inputs.clear();
156153
return false;
157154
}
158155
}
@@ -181,26 +178,27 @@ class ListTracerVisitor extends TracerVisitor {
181178
@override
182179
visitDynamicCallSiteTypeInformation(DynamicCallSiteTypeInformation info) {
183180
super.visitDynamicCallSiteTypeInformation(info);
184-
Selector selector = info.selector;
181+
final selector = info.selector!;
185182
String selectorName = selector.name;
183+
final arguments = info.arguments;
186184
if (currentUser == info.receiver) {
187185
if (!okListSelectorsSet.contains(selectorName)) {
188186
if (selector.isCall) {
189-
int positionalLength = info.arguments.positional.length;
187+
int positionalLength = arguments!.positional.length;
190188
if (selectorName == 'add') {
191189
if (positionalLength == 1) {
192-
inputs.add(info.arguments.positional[0]);
190+
inputs.add(arguments.positional[0]);
193191
}
194192
} else if (selectorName == 'insert') {
195193
if (positionalLength == 2) {
196-
inputs.add(info.arguments.positional[1]);
194+
inputs.add(arguments.positional[1]);
197195
}
198196
} else {
199197
bailout('Used in a not-ok selector');
200198
return;
201199
}
202200
} else if (selector.isIndexSet) {
203-
inputs.add(info.arguments.positional[1]);
201+
inputs.add(arguments!.positional[1]);
204202
} else if (!selector.isIndex) {
205203
bailout('Used in a not-ok selector');
206204
return;

pkg/compiler/lib/src/inferrer/map_tracer.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.10
6-
75
library compiler.src.inferrer.map_tracer;
86

97
import '../common/names.dart';
108
import '../elements/entities.dart';
11-
import '../universe/selector.dart' show Selector;
129
import 'node_tracer.dart';
1310
import 'type_graph_nodes.dart';
1411

@@ -43,20 +40,22 @@ class MapTracerVisitor extends TracerVisitor {
4340
// this map.
4441
List<MapTypeInformation> mapInputs = <MapTypeInformation>[];
4542

46-
MapTracerVisitor(tracedType, inferrer) : super(tracedType, inferrer);
43+
MapTracerVisitor(super.tracedType, super.inferrer);
4744

4845
/// Returns [true] if the analysis completed successfully, [false]
4946
/// if it bailed out. In the former case, [keyInputs] and
5047
/// [valueInputs] hold a list of [TypeInformation] nodes that
5148
/// flow into the key and value types of this map.
5249
bool run() {
5350
analyze();
54-
MapTypeInformation map = tracedType;
51+
final map = tracedType as MapTypeInformation;
5552
if (continueAnalyzing) {
5653
map.addFlowsIntoTargets(flowsInto);
5754
return true;
5855
}
59-
keyInputs = valueInputs = mapInputs = null;
56+
keyInputs.clear();
57+
valueInputs.clear();
58+
mapInputs.clear();
6059
return false;
6160
}
6261

@@ -78,15 +77,16 @@ class MapTracerVisitor extends TracerVisitor {
7877
@override
7978
visitDynamicCallSiteTypeInformation(DynamicCallSiteTypeInformation info) {
8079
super.visitDynamicCallSiteTypeInformation(info);
81-
Selector selector = info.selector;
82-
String selectorName = selector.name;
80+
final selector = info.selector!;
81+
final selectorName = selector.name;
82+
final arguments = info.arguments;
8383
if (currentUser == info.receiver) {
8484
if (!okMapSelectorsSet.contains(selectorName)) {
8585
if (selector.isCall) {
8686
if (selectorName == 'addAll') {
8787
// All keys and values from the argument flow into
8888
// the map.
89-
TypeInformation map = info.arguments.positional[0];
89+
TypeInformation map = arguments!.positional[0];
9090
if (map is MapTypeInformation) {
9191
inferrer.analyzeMapAndEnqueue(map);
9292
mapInputs.add(map);
@@ -105,7 +105,7 @@ class MapTracerVisitor extends TracerVisitor {
105105
// to go to dynamic.
106106
// TODO(herhut,16507): Use return type of closure in
107107
// Map.putIfAbsent.
108-
keyInputs.add(info.arguments.positional[0]);
108+
keyInputs.add(arguments!.positional[0]);
109109
valueInputs.add(inferrer.types.dynamicType);
110110
} else {
111111
// It would be nice to handle [Map.keys] and [Map.values], too.
@@ -117,8 +117,8 @@ class MapTracerVisitor extends TracerVisitor {
117117
return;
118118
}
119119
} else if (selector.isIndexSet) {
120-
keyInputs.add(info.arguments.positional[0]);
121-
valueInputs.add(info.arguments.positional[1]);
120+
keyInputs.add(arguments!.positional[0]);
121+
valueInputs.add(arguments.positional[1]);
122122
} else if (!selector.isIndex) {
123123
bailout('Map used in a not-ok selector [$selectorName]');
124124
return;

pkg/compiler/lib/src/inferrer/set_tracer.dart

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.10
6-
75
library compiler.src.inferrer.set_tracer;
86

97
import '../common/names.dart';
108
import '../elements/entities.dart';
11-
import '../universe/selector.dart' show Selector;
129
import 'node_tracer.dart';
1310
import 'type_graph_nodes.dart';
1411

@@ -69,19 +66,19 @@ Set<String> okSetSelectorSet = Set<String>.from(const <String>[
6966
class SetTracerVisitor extends TracerVisitor {
7067
List<TypeInformation> inputs = <TypeInformation>[];
7168

72-
SetTracerVisitor(tracedType, inferrer) : super(tracedType, inferrer);
69+
SetTracerVisitor(super.tracedType, super.inferrer);
7370

7471
/// Returns [true] if the analysis completed successfully, [false] if it
7572
/// bailed out. In the former case, [inputs] holds a list of
7673
/// [TypeInformation] nodes that flow into the element type of this set.
7774
bool run() {
7875
analyze();
79-
SetTypeInformation set = tracedType;
76+
final set = tracedType as SetTypeInformation;
8077
if (continueAnalyzing) {
8178
set.addFlowsIntoTargets(flowsInto);
8279
return true;
8380
}
84-
inputs = null;
81+
inputs.clear();
8582
return false;
8683
}
8784

@@ -103,14 +100,15 @@ class SetTracerVisitor extends TracerVisitor {
103100
@override
104101
visitDynamicCallSiteTypeInformation(DynamicCallSiteTypeInformation info) {
105102
super.visitDynamicCallSiteTypeInformation(info);
106-
Selector selector = info.selector;
107-
String selectorName = selector.name;
103+
final selector = info.selector!;
104+
final selectorName = selector.name;
105+
final arguments = info.arguments;
108106
if (currentUser == info.receiver) {
109107
if (!okSetSelectorSet.contains(selectorName)) {
110108
if (selector.isCall) {
111109
switch (selectorName) {
112110
case 'add':
113-
inputs.add(info.arguments.positional[0]);
111+
inputs.add(arguments!.positional[0]);
114112
break;
115113
case 'addAll':
116114
// TODO(fishythefish): Extract type argument from type

pkg/compiler/lib/src/inferrer_experimental/list_tracer.dart

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.10
6-
75
library compiler.src.inferrer.list_tracer;
86

97
import '../common/names.dart';
108
import '../elements/entities.dart';
119
import '../native/behavior.dart';
12-
import '../universe/selector.dart' show Selector;
1310
import '../util/util.dart' show Setlet;
1411
import 'node_tracer.dart';
1512
import 'type_graph_nodes.dart';
@@ -136,14 +133,14 @@ class ListTracerVisitor extends TracerVisitor {
136133
Set<TypeInformation> inputs = Setlet<TypeInformation>();
137134
bool callsGrowableMethod = false;
138135

139-
ListTracerVisitor(tracedType, inferrer) : super(tracedType, inferrer);
136+
ListTracerVisitor(super.tracedType, super.inferrer);
140137

141138
/// Returns [true] if the analysis completed successfully, [false] if it
142139
/// bailed out. In the former case, [inputs] holds a list of
143140
/// [TypeInformation] nodes that flow into the element type of this list.
144141
bool run() {
145142
analyze();
146-
ListTypeInformation list = tracedType;
143+
final list = tracedType as ListTypeInformation;
147144
if (continueAnalyzing) {
148145
if (!callsGrowableMethod && list.inferredLength == null) {
149146
list.inferredLength = list.originalLength;
@@ -152,7 +149,7 @@ class ListTracerVisitor extends TracerVisitor {
152149
return true;
153150
} else {
154151
callsGrowableMethod = true;
155-
inputs = null;
152+
inputs.clear();
156153
return false;
157154
}
158155
}
@@ -181,26 +178,27 @@ class ListTracerVisitor extends TracerVisitor {
181178
@override
182179
visitDynamicCallSiteTypeInformation(DynamicCallSiteTypeInformation info) {
183180
super.visitDynamicCallSiteTypeInformation(info);
184-
Selector selector = info.selector;
181+
final selector = info.selector!;
185182
String selectorName = selector.name;
183+
final arguments = info.arguments;
186184
if (currentUser == info.receiver) {
187185
if (!okListSelectorsSet.contains(selectorName)) {
188186
if (selector.isCall) {
189-
int positionalLength = info.arguments.positional.length;
187+
int positionalLength = arguments!.positional.length;
190188
if (selectorName == 'add') {
191189
if (positionalLength == 1) {
192-
inputs.add(info.arguments.positional[0]);
190+
inputs.add(arguments.positional[0]);
193191
}
194192
} else if (selectorName == 'insert') {
195193
if (positionalLength == 2) {
196-
inputs.add(info.arguments.positional[1]);
194+
inputs.add(arguments.positional[1]);
197195
}
198196
} else {
199197
bailout('Used in a not-ok selector');
200198
return;
201199
}
202200
} else if (selector.isIndexSet) {
203-
inputs.add(info.arguments.positional[1]);
201+
inputs.add(arguments!.positional[1]);
204202
} else if (!selector.isIndex) {
205203
bailout('Used in a not-ok selector');
206204
return;

pkg/compiler/lib/src/inferrer_experimental/map_tracer.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.10
6-
75
library compiler.src.inferrer.map_tracer;
86

97
import '../common/names.dart';
108
import '../elements/entities.dart';
11-
import '../universe/selector.dart' show Selector;
129
import 'node_tracer.dart';
1310
import 'type_graph_nodes.dart';
1411

@@ -43,20 +40,22 @@ class MapTracerVisitor extends TracerVisitor {
4340
// this map.
4441
List<MapTypeInformation> mapInputs = <MapTypeInformation>[];
4542

46-
MapTracerVisitor(tracedType, inferrer) : super(tracedType, inferrer);
43+
MapTracerVisitor(super.tracedType, super.inferrer);
4744

4845
/// Returns [true] if the analysis completed successfully, [false]
4946
/// if it bailed out. In the former case, [keyInputs] and
5047
/// [valueInputs] hold a list of [TypeInformation] nodes that
5148
/// flow into the key and value types of this map.
5249
bool run() {
5350
analyze();
54-
MapTypeInformation map = tracedType;
51+
final map = tracedType as MapTypeInformation;
5552
if (continueAnalyzing) {
5653
map.addFlowsIntoTargets(flowsInto);
5754
return true;
5855
}
59-
keyInputs = valueInputs = mapInputs = null;
56+
keyInputs.clear();
57+
valueInputs.clear();
58+
mapInputs.clear();
6059
return false;
6160
}
6261

@@ -78,15 +77,16 @@ class MapTracerVisitor extends TracerVisitor {
7877
@override
7978
visitDynamicCallSiteTypeInformation(DynamicCallSiteTypeInformation info) {
8079
super.visitDynamicCallSiteTypeInformation(info);
81-
Selector selector = info.selector;
82-
String selectorName = selector.name;
80+
final selector = info.selector!;
81+
final selectorName = selector.name;
82+
final arguments = info.arguments;
8383
if (currentUser == info.receiver) {
8484
if (!okMapSelectorsSet.contains(selectorName)) {
8585
if (selector.isCall) {
8686
if (selectorName == 'addAll') {
8787
// All keys and values from the argument flow into
8888
// the map.
89-
TypeInformation map = info.arguments.positional[0];
89+
TypeInformation map = arguments!.positional[0];
9090
if (map is MapTypeInformation) {
9191
inferrer.analyzeMapAndEnqueue(map);
9292
mapInputs.add(map);
@@ -105,7 +105,7 @@ class MapTracerVisitor extends TracerVisitor {
105105
// to go to dynamic.
106106
// TODO(herhut,16507): Use return type of closure in
107107
// Map.putIfAbsent.
108-
keyInputs.add(info.arguments.positional[0]);
108+
keyInputs.add(arguments!.positional[0]);
109109
valueInputs.add(inferrer.types.dynamicType);
110110
} else {
111111
// It would be nice to handle [Map.keys] and [Map.values], too.
@@ -117,8 +117,8 @@ class MapTracerVisitor extends TracerVisitor {
117117
return;
118118
}
119119
} else if (selector.isIndexSet) {
120-
keyInputs.add(info.arguments.positional[0]);
121-
valueInputs.add(info.arguments.positional[1]);
120+
keyInputs.add(arguments!.positional[0]);
121+
valueInputs.add(arguments.positional[1]);
122122
} else if (!selector.isIndex) {
123123
bailout('Map used in a not-ok selector [$selectorName]');
124124
return;

0 commit comments

Comments
 (0)