[dart2js] Migrate iterable tracers in inferrer.

Change-Id: I0a9eba5a65cb6dd1b8db5aef53c3a2caed9530b9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/260803
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
This commit is contained in:
Nate Biggs 2022-09-27 19:19:25 +00:00 committed by Commit Queue
parent dd63e54e2c
commit 8939d1e0f0
6 changed files with 56 additions and 64 deletions

View file

@ -2,14 +2,11 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.10
library compiler.src.inferrer.list_tracer;
import '../common/names.dart';
import '../elements/entities.dart';
import '../native/behavior.dart';
import '../universe/selector.dart' show Selector;
import '../util/util.dart' show Setlet;
import 'node_tracer.dart';
import 'type_graph_nodes.dart';
@ -136,14 +133,14 @@ class ListTracerVisitor extends TracerVisitor {
Set<TypeInformation> inputs = Setlet<TypeInformation>();
bool callsGrowableMethod = false;
ListTracerVisitor(tracedType, inferrer) : super(tracedType, inferrer);
ListTracerVisitor(super.tracedType, super.inferrer);
/// Returns [true] if the analysis completed successfully, [false] if it
/// bailed out. In the former case, [inputs] holds a list of
/// [TypeInformation] nodes that flow into the element type of this list.
bool run() {
analyze();
ListTypeInformation list = tracedType;
final list = tracedType as ListTypeInformation;
if (continueAnalyzing) {
if (!callsGrowableMethod && list.inferredLength == null) {
list.inferredLength = list.originalLength;
@ -152,7 +149,7 @@ class ListTracerVisitor extends TracerVisitor {
return true;
} else {
callsGrowableMethod = true;
inputs = null;
inputs.clear();
return false;
}
}
@ -181,26 +178,27 @@ class ListTracerVisitor extends TracerVisitor {
@override
visitDynamicCallSiteTypeInformation(DynamicCallSiteTypeInformation info) {
super.visitDynamicCallSiteTypeInformation(info);
Selector selector = info.selector;
final selector = info.selector!;
String selectorName = selector.name;
final arguments = info.arguments;
if (currentUser == info.receiver) {
if (!okListSelectorsSet.contains(selectorName)) {
if (selector.isCall) {
int positionalLength = info.arguments.positional.length;
int positionalLength = arguments!.positional.length;
if (selectorName == 'add') {
if (positionalLength == 1) {
inputs.add(info.arguments.positional[0]);
inputs.add(arguments.positional[0]);
}
} else if (selectorName == 'insert') {
if (positionalLength == 2) {
inputs.add(info.arguments.positional[1]);
inputs.add(arguments.positional[1]);
}
} else {
bailout('Used in a not-ok selector');
return;
}
} else if (selector.isIndexSet) {
inputs.add(info.arguments.positional[1]);
inputs.add(arguments!.positional[1]);
} else if (!selector.isIndex) {
bailout('Used in a not-ok selector');
return;

View file

@ -2,13 +2,10 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.10
library compiler.src.inferrer.map_tracer;
import '../common/names.dart';
import '../elements/entities.dart';
import '../universe/selector.dart' show Selector;
import 'node_tracer.dart';
import 'type_graph_nodes.dart';
@ -43,7 +40,7 @@ class MapTracerVisitor extends TracerVisitor {
// this map.
List<MapTypeInformation> mapInputs = <MapTypeInformation>[];
MapTracerVisitor(tracedType, inferrer) : super(tracedType, inferrer);
MapTracerVisitor(super.tracedType, super.inferrer);
/// Returns [true] if the analysis completed successfully, [false]
/// if it bailed out. In the former case, [keyInputs] and
@ -51,12 +48,14 @@ class MapTracerVisitor extends TracerVisitor {
/// flow into the key and value types of this map.
bool run() {
analyze();
MapTypeInformation map = tracedType;
final map = tracedType as MapTypeInformation;
if (continueAnalyzing) {
map.addFlowsIntoTargets(flowsInto);
return true;
}
keyInputs = valueInputs = mapInputs = null;
keyInputs.clear();
valueInputs.clear();
mapInputs.clear();
return false;
}
@ -78,15 +77,16 @@ class MapTracerVisitor extends TracerVisitor {
@override
visitDynamicCallSiteTypeInformation(DynamicCallSiteTypeInformation info) {
super.visitDynamicCallSiteTypeInformation(info);
Selector selector = info.selector;
String selectorName = selector.name;
final selector = info.selector!;
final selectorName = selector.name;
final arguments = info.arguments;
if (currentUser == info.receiver) {
if (!okMapSelectorsSet.contains(selectorName)) {
if (selector.isCall) {
if (selectorName == 'addAll') {
// All keys and values from the argument flow into
// the map.
TypeInformation map = info.arguments.positional[0];
TypeInformation map = arguments!.positional[0];
if (map is MapTypeInformation) {
inferrer.analyzeMapAndEnqueue(map);
mapInputs.add(map);
@ -105,7 +105,7 @@ class MapTracerVisitor extends TracerVisitor {
// to go to dynamic.
// TODO(herhut,16507): Use return type of closure in
// Map.putIfAbsent.
keyInputs.add(info.arguments.positional[0]);
keyInputs.add(arguments!.positional[0]);
valueInputs.add(inferrer.types.dynamicType);
} else {
// It would be nice to handle [Map.keys] and [Map.values], too.
@ -117,8 +117,8 @@ class MapTracerVisitor extends TracerVisitor {
return;
}
} else if (selector.isIndexSet) {
keyInputs.add(info.arguments.positional[0]);
valueInputs.add(info.arguments.positional[1]);
keyInputs.add(arguments!.positional[0]);
valueInputs.add(arguments.positional[1]);
} else if (!selector.isIndex) {
bailout('Map used in a not-ok selector [$selectorName]');
return;

View file

@ -2,13 +2,10 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.10
library compiler.src.inferrer.set_tracer;
import '../common/names.dart';
import '../elements/entities.dart';
import '../universe/selector.dart' show Selector;
import 'node_tracer.dart';
import 'type_graph_nodes.dart';
@ -69,19 +66,19 @@ Set<String> okSetSelectorSet = Set<String>.from(const <String>[
class SetTracerVisitor extends TracerVisitor {
List<TypeInformation> inputs = <TypeInformation>[];
SetTracerVisitor(tracedType, inferrer) : super(tracedType, inferrer);
SetTracerVisitor(super.tracedType, super.inferrer);
/// Returns [true] if the analysis completed successfully, [false] if it
/// bailed out. In the former case, [inputs] holds a list of
/// [TypeInformation] nodes that flow into the element type of this set.
bool run() {
analyze();
SetTypeInformation set = tracedType;
final set = tracedType as SetTypeInformation;
if (continueAnalyzing) {
set.addFlowsIntoTargets(flowsInto);
return true;
}
inputs = null;
inputs.clear();
return false;
}
@ -103,14 +100,15 @@ class SetTracerVisitor extends TracerVisitor {
@override
visitDynamicCallSiteTypeInformation(DynamicCallSiteTypeInformation info) {
super.visitDynamicCallSiteTypeInformation(info);
Selector selector = info.selector;
String selectorName = selector.name;
final selector = info.selector!;
final selectorName = selector.name;
final arguments = info.arguments;
if (currentUser == info.receiver) {
if (!okSetSelectorSet.contains(selectorName)) {
if (selector.isCall) {
switch (selectorName) {
case 'add':
inputs.add(info.arguments.positional[0]);
inputs.add(arguments!.positional[0]);
break;
case 'addAll':
// TODO(fishythefish): Extract type argument from type

View file

@ -2,14 +2,11 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.10
library compiler.src.inferrer.list_tracer;
import '../common/names.dart';
import '../elements/entities.dart';
import '../native/behavior.dart';
import '../universe/selector.dart' show Selector;
import '../util/util.dart' show Setlet;
import 'node_tracer.dart';
import 'type_graph_nodes.dart';
@ -136,14 +133,14 @@ class ListTracerVisitor extends TracerVisitor {
Set<TypeInformation> inputs = Setlet<TypeInformation>();
bool callsGrowableMethod = false;
ListTracerVisitor(tracedType, inferrer) : super(tracedType, inferrer);
ListTracerVisitor(super.tracedType, super.inferrer);
/// Returns [true] if the analysis completed successfully, [false] if it
/// bailed out. In the former case, [inputs] holds a list of
/// [TypeInformation] nodes that flow into the element type of this list.
bool run() {
analyze();
ListTypeInformation list = tracedType;
final list = tracedType as ListTypeInformation;
if (continueAnalyzing) {
if (!callsGrowableMethod && list.inferredLength == null) {
list.inferredLength = list.originalLength;
@ -152,7 +149,7 @@ class ListTracerVisitor extends TracerVisitor {
return true;
} else {
callsGrowableMethod = true;
inputs = null;
inputs.clear();
return false;
}
}
@ -181,26 +178,27 @@ class ListTracerVisitor extends TracerVisitor {
@override
visitDynamicCallSiteTypeInformation(DynamicCallSiteTypeInformation info) {
super.visitDynamicCallSiteTypeInformation(info);
Selector selector = info.selector;
final selector = info.selector!;
String selectorName = selector.name;
final arguments = info.arguments;
if (currentUser == info.receiver) {
if (!okListSelectorsSet.contains(selectorName)) {
if (selector.isCall) {
int positionalLength = info.arguments.positional.length;
int positionalLength = arguments!.positional.length;
if (selectorName == 'add') {
if (positionalLength == 1) {
inputs.add(info.arguments.positional[0]);
inputs.add(arguments.positional[0]);
}
} else if (selectorName == 'insert') {
if (positionalLength == 2) {
inputs.add(info.arguments.positional[1]);
inputs.add(arguments.positional[1]);
}
} else {
bailout('Used in a not-ok selector');
return;
}
} else if (selector.isIndexSet) {
inputs.add(info.arguments.positional[1]);
inputs.add(arguments!.positional[1]);
} else if (!selector.isIndex) {
bailout('Used in a not-ok selector');
return;

View file

@ -2,13 +2,10 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.10
library compiler.src.inferrer.map_tracer;
import '../common/names.dart';
import '../elements/entities.dart';
import '../universe/selector.dart' show Selector;
import 'node_tracer.dart';
import 'type_graph_nodes.dart';
@ -43,7 +40,7 @@ class MapTracerVisitor extends TracerVisitor {
// this map.
List<MapTypeInformation> mapInputs = <MapTypeInformation>[];
MapTracerVisitor(tracedType, inferrer) : super(tracedType, inferrer);
MapTracerVisitor(super.tracedType, super.inferrer);
/// Returns [true] if the analysis completed successfully, [false]
/// if it bailed out. In the former case, [keyInputs] and
@ -51,12 +48,14 @@ class MapTracerVisitor extends TracerVisitor {
/// flow into the key and value types of this map.
bool run() {
analyze();
MapTypeInformation map = tracedType;
final map = tracedType as MapTypeInformation;
if (continueAnalyzing) {
map.addFlowsIntoTargets(flowsInto);
return true;
}
keyInputs = valueInputs = mapInputs = null;
keyInputs.clear();
valueInputs.clear();
mapInputs.clear();
return false;
}
@ -78,15 +77,16 @@ class MapTracerVisitor extends TracerVisitor {
@override
visitDynamicCallSiteTypeInformation(DynamicCallSiteTypeInformation info) {
super.visitDynamicCallSiteTypeInformation(info);
Selector selector = info.selector;
String selectorName = selector.name;
final selector = info.selector!;
final selectorName = selector.name;
final arguments = info.arguments;
if (currentUser == info.receiver) {
if (!okMapSelectorsSet.contains(selectorName)) {
if (selector.isCall) {
if (selectorName == 'addAll') {
// All keys and values from the argument flow into
// the map.
TypeInformation map = info.arguments.positional[0];
TypeInformation map = arguments!.positional[0];
if (map is MapTypeInformation) {
inferrer.analyzeMapAndEnqueue(map);
mapInputs.add(map);
@ -105,7 +105,7 @@ class MapTracerVisitor extends TracerVisitor {
// to go to dynamic.
// TODO(herhut,16507): Use return type of closure in
// Map.putIfAbsent.
keyInputs.add(info.arguments.positional[0]);
keyInputs.add(arguments!.positional[0]);
valueInputs.add(inferrer.types.dynamicType);
} else {
// It would be nice to handle [Map.keys] and [Map.values], too.
@ -117,8 +117,8 @@ class MapTracerVisitor extends TracerVisitor {
return;
}
} else if (selector.isIndexSet) {
keyInputs.add(info.arguments.positional[0]);
valueInputs.add(info.arguments.positional[1]);
keyInputs.add(arguments!.positional[0]);
valueInputs.add(arguments.positional[1]);
} else if (!selector.isIndex) {
bailout('Map used in a not-ok selector [$selectorName]');
return;

View file

@ -2,13 +2,10 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.10
library compiler.src.inferrer.set_tracer;
import '../common/names.dart';
import '../elements/entities.dart';
import '../universe/selector.dart' show Selector;
import 'node_tracer.dart';
import 'type_graph_nodes.dart';
@ -69,19 +66,19 @@ Set<String> okSetSelectorSet = Set<String>.from(const <String>[
class SetTracerVisitor extends TracerVisitor {
List<TypeInformation> inputs = <TypeInformation>[];
SetTracerVisitor(tracedType, inferrer) : super(tracedType, inferrer);
SetTracerVisitor(super.tracedType, super.inferrer);
/// Returns [true] if the analysis completed successfully, [false] if it
/// bailed out. In the former case, [inputs] holds a list of
/// [TypeInformation] nodes that flow into the element type of this set.
bool run() {
analyze();
SetTypeInformation set = tracedType;
final set = tracedType as SetTypeInformation;
if (continueAnalyzing) {
set.addFlowsIntoTargets(flowsInto);
return true;
}
inputs = null;
inputs.clear();
return false;
}
@ -103,14 +100,15 @@ class SetTracerVisitor extends TracerVisitor {
@override
visitDynamicCallSiteTypeInformation(DynamicCallSiteTypeInformation info) {
super.visitDynamicCallSiteTypeInformation(info);
Selector selector = info.selector;
String selectorName = selector.name;
final selector = info.selector!;
final selectorName = selector.name;
final arguments = info.arguments;
if (currentUser == info.receiver) {
if (!okSetSelectorSet.contains(selectorName)) {
if (selector.isCall) {
switch (selectorName) {
case 'add':
inputs.add(info.arguments.positional[0]);
inputs.add(arguments!.positional[0]);
break;
case 'addAll':
// TODO(fishythefish): Extract type argument from type