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

Unified Diff: pkg/compiler/lib/src/cps_ir/type_propagation.dart

Issue 1395333004: dart2js cps_ir: Use JSNumber_methods where possible (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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
Index: pkg/compiler/lib/src/cps_ir/type_propagation.dart
diff --git a/pkg/compiler/lib/src/cps_ir/type_propagation.dart b/pkg/compiler/lib/src/cps_ir/type_propagation.dart
index b397a423677cc64cad0e42136bd039ecabcf2728..f36a38712d0dde4b3a9ad10056ca080e66b3cef9 100644
--- a/pkg/compiler/lib/src/cps_ir/type_propagation.dart
+++ b/pkg/compiler/lib/src/cps_ir/type_propagation.dart
@@ -2130,6 +2130,10 @@ class TransformingVisitor extends DeepRecursiveVisitor {
// Classes like JSUInt31 and JSUInt32 do not exist at runtime, so ensure
// all the int classes get mapped tor their runtime class.
singleClass = backend.jsIntClass;
+ } else if (lattice.isDefinitelyNum(value)) {
+ if (jsNumberClassSuffices(node)) {
+ singleClass = backend.jsNumberClass;
+ }
} else if (lattice.isDefinitelyNativeList(value)) {
// Ensure all the array subclasses get mapped to the array class.
singleClass = backend.jsArrayClass;
@@ -2155,6 +2159,27 @@ class TransformingVisitor extends DeepRecursiveVisitor {
}
return null;
}
+
+ bool jsNumberClassSuffices(Interceptor node) {
+ // No methods on JSNumber call 'down' to methods on JSInt or JSDouble. If
+ // all uses of the interceptor are for methods is defined only on JSNumber
+ // then JSNumber will suffice in place of choosing between JSInt or
+ // JSDouble.
+ for (Reference ref = node.firstRef; ref != null; ref = ref.next) {
+ if (ref.parent is InvokeMethod) {
+ InvokeMethod invoke = ref.parent;
+ if (invoke.receiver != ref) return false;
+ var interceptedClasses =
+ functionCompiler.glue.getInterceptedClassesOn(invoke.selector);
+ if (interceptedClasses.contains(backend.jsDoubleClass)) return false;
+ if (interceptedClasses.contains(backend.jsIntClass)) return false;
+ continue;
+ }
+ // Other uses need full distinction.
+ return false;
+ }
+ return true;
+ }
}
/**

Powered by Google App Engine
This is Rietveld 408576698