Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(848)

Unified Diff: sdk/lib/_internal/compiler/implementation/inferrer/type_graph_nodes.dart

Issue 94303002: Add another type JSPositiveInt to show a range analysis in the inferrer would be very beneficial :-… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/inferrer/type_graph_nodes.dart
===================================================================
--- sdk/lib/_internal/compiler/implementation/inferrer/type_graph_nodes.dart (revision 30754)
+++ sdk/lib/_internal/compiler/implementation/inferrer/type_graph_nodes.dart (working copy)
@@ -532,14 +532,22 @@
bool isUInt31(info) {
return info.type.satisfies(uint31Implementation, compiler);
}
+ bool isPositiveInt(info) {
+ return info.type.satisfies(
+ compiler.backend.positiveIntImplementation, compiler);
+ }
String name = selector.name;
// We are optimizing for the cases that are not expressed in the
// Dart code, for example:
// int + int -> int
// uint31 | uint31 -> uint31
- if (name == '*' || name == '+' || name == '%' || name == 'remainder') {
- if (arguments.hasOnePositionalArgumentThatMatches(isInt)) {
+ if (name == '*' || name == '+' || name == '%' || name == 'remainder'
+ || name == '~/') {
+ if (isPositiveInt(receiver)
+ && arguments.hasOnePositionalArgumentThatMatches(isPositiveInt)) {
+ return inferrer.types.positiveIntType;
+ } else if (arguments.hasOnePositionalArgumentThatMatches(isInt)) {
return inferrer.types.intType;
} else if (arguments.hasOnePositionalArgumentThatMatches(isEmpty)) {
return inferrer.types.nonNullEmptyType;
@@ -560,8 +568,11 @@
|| arguments.hasOnePositionalArgumentThatMatches(isUInt31)) {
return inferrer.types.uint31Type;
}
+ } else if (name == 'unary-') {
+ // The receiver being an int, the return value will also be an
+ // int.
+ return inferrer.types.intType;
} else if (name == '-') {
- if (arguments.hasNoArguments()) return inferrer.types.intType;
if (arguments.hasOnePositionalArgumentThatMatches(isInt)) {
return inferrer.types.intType;
} else if (arguments.hasOnePositionalArgumentThatMatches(isEmpty)) {
@@ -569,7 +580,7 @@
}
return null;
} else if (name == 'abs') {
- return arguments.hasNoArguments() ? inferrer.types.intType : null;
+ return arguments.hasNoArguments() ? inferrer.types.positiveIntType : null;
}
return null;
}

Powered by Google App Engine
This is Rietveld 408576698