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

Unified Diff: sdk/lib/_internal/compiler/implementation/types/simple_types_inferrer.dart

Issue 14120008: Add special rules in the inferrer that some int operations return an int. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 months 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
« no previous file with comments | « no previous file | tests/compiler/dart2js/mock_compiler.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/implementation/types/simple_types_inferrer.dart
===================================================================
--- sdk/lib/_internal/compiler/implementation/types/simple_types_inferrer.dart (revision 21800)
+++ sdk/lib/_internal/compiler/implementation/types/simple_types_inferrer.dart (working copy)
@@ -902,6 +902,33 @@
if (changed) enqueueAgain(element);
}
+ TypeMask handleIntrisifiedSelector(Selector selector,
+ ArgumentsTypes arguments) {
+ if (selector.mask != intType) return null;
+ if (!selector.isCall() && !selector.isOperator()) return null;
+ if (!arguments.named.isEmpty) return null;
+ if (arguments.positional.length > 1) return null;
+
+ switch (selector.name) {
+ case const SourceString('*'):
+ case const SourceString('+'):
+ case const SourceString('%'):
+ case const SourceString('remainder'):
+ return arguments.hasOnePositionalArgumentWithType(intType)
+ ? intType
+ : null;
+
+ case const SourceString('-'):
+ if (arguments.hasNoArguments()) return intType;
+ if (arguments.hasOnePositionalArgumentWithType(intType)) return intType;
+ return null;
+
+ case const SourceString('abs'):
+ return arguments.hasNoArguments() ? intType : null;
+ }
+ return null;
+ }
+
/**
* Registers that [caller] calls an element matching [selector]
* with the given [arguments].
@@ -927,7 +954,8 @@
unregisterCalledElement(node, selector.asUntyped, caller, element);
}
if (!selector.isSetter()) {
- TypeMask type = typeOfElementWithSelector(element, selector);
+ TypeMask type = handleIntrisifiedSelector(selector, arguments);
+ if (type == null) type = typeOfElementWithSelector(element, selector);
result = computeLUB(result, type);
}
return true;
@@ -1113,8 +1141,11 @@
final Map<SourceString, TypeMask> named;
ArgumentsTypes(this.positional, named)
: this.named = (named == null) ? new Map<SourceString, TypeMask>() : named;
+
int get length => positional.length + named.length;
+
String toString() => "{ positional = $positional, named = $named }";
+
bool operator==(other) {
if (positional.length != other.positional.length) return false;
if (named.length != other.named.length) return false;
@@ -1126,6 +1157,12 @@
});
return true;
}
+
+ bool hasNoArguments() => positional.isEmpty && named.isEmpty;
+
+ bool hasOnePositionalArgumentWithType(TypeMask type) {
+ return named.isEmpty && positional.length == 1 && positional[0] == type;
+ }
}
/**
« no previous file with comments | « no previous file | tests/compiler/dart2js/mock_compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698