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

Unified Diff: tests/compiler/dart2js/call_site_type_inferer_test.dart

Issue 10827181: Collect call site information and use that for estimating parameter types (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments from ahe@ Created 8 years, 4 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: tests/compiler/dart2js/call_site_type_inferer_test.dart
diff --git a/tests/compiler/dart2js/call_site_type_inferer_test.dart b/tests/compiler/dart2js/call_site_type_inferer_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..418948dbc2487cdf82bc9610dcd6fc1cd6a32cde
--- /dev/null
+++ b/tests/compiler/dart2js/call_site_type_inferer_test.dart
@@ -0,0 +1,151 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// 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.
+
+#import("dart:uri");
+
+#import("../../../lib/compiler/implementation/ssa/ssa.dart");
+
+#import('compiler_helper.dart');
+#import('parser_helper.dart');
+
+findElement(var compiler, String name) {
+ var element = compiler.mainApp.find(buildSourceString(name));
+ Expect.isNotNull(element, 'Could not locate $name.');
+ return element;
+}
+
+void compileAndFind(String code,
+ String className,
+ String memberName,
+ check(compiler, element)) {
+ Uri uri = new Uri.fromComponents(scheme: 'source');
+ var compiler = compilerFor(code, uri);
+ compiler.runCompiler(uri);
+ var cls = findElement(compiler, className);
+ var member = cls.lookupLocalMember(buildSourceString(memberName));
+ return check(compiler.backend, member);
+}
+
+final String TEST_ONE = @"""
+ class A {
+ x(p) => p;
+ }
+ main() { new A().x("s"); }
+""";
+
+final String TEST_TWO = @"""
+ class A {
+ x(p) => p;
+ }
+ main() { new A().x(1); }
+""";
+
+final String TEST_THREE = @"""
+ class A {
+ x(p) => x(p - 1);
+ }
+ main() { new A().x(1); }
+""";
+
+final String TEST_FOUR = @"""
+ class A {
+ x(p) => x(p - 1);
+ }
+ main() { new A().x(1.0); }
+""";
+
+final String TEST_FIVE = @"""
+ class A {
+ x(p) => p;
+ }
+ main() {
+ new A().x(1);
+ new A().x(1.0);
+ }
+""";
+
+final String TEST_SIX = @"""
+ class A {
+ x(p) => p;
+ }
+ main() {
+ new A().x(1.0);
+ new A().x(1);
+ }
+""";
+
+final String TEST_SEVEN = @"""
+ class A {
+ x(p) => x("x");
+ }
+ main() {
+ new A().x(1);
+ }
+""";
+
+final String TEST_EIGHT = @"""
+ class A {
+ x(p1, p2) => x(p1, "x");
+ }
+ main() {
+ new A().x(1, 2);
+ }
+""";
+
+final String TEST_NINE = @"""
+ class A {
+ x(p1, p2) => x(p1, p2);
+ }
+ void f(p) {
+ p.x("x", "y");
+ }
+ main() {
+ new A().x(1, 2);
+ }
+""";
+
+final String TEST_TEN = @"""
+ class A {
+ x(p1, p2) => x(p1, p2);
+ }
+ void f(p) {
+ p.x("x", "y");
+ }
+ main() {
+ f(null);
+ new A().x(1, 2);
+ }
+""";
+
+void runTest(String test, [List<HType> expectedTypes = null]) {
+ compileAndFind(
+ test,
+ 'A',
+ 'x',
+ (backend, x) {
+ List<HType> types =
+ backend.optimisticParameterTypesWithRecompilationOnTypeChange(x);
+ if (expectedTypes != null) {
+ Expect.listEquals(expectedTypes, types);
+ } else {
+ Expect.isNull(types);
+ }
+ });
+}
+
+void test() {
+ runTest(TEST_ONE, [HType.STRING]);
+ runTest(TEST_TWO, [HType.INTEGER]);
+ runTest(TEST_THREE, [HType.INTEGER]);
+ runTest(TEST_FOUR, [HType.DOUBLE]);
+ runTest(TEST_FIVE, [HType.NUMBER]);
+ runTest(TEST_SIX, [HType.NUMBER]);
+ runTest(TEST_SEVEN);
+ runTest(TEST_EIGHT, [HType.INTEGER, HType.UNKNOWN]);
+ runTest(TEST_TEN);
+}
+
+void main() {
+ test();
+}

Powered by Google App Engine
This is Rietveld 408576698