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

Side by Side Diff: tests/compiler/dart2js/expect_annotations_test.dart

Issue 875163004: Support [AssumeDynamic] and [TrustTypeAnnotations] in the inferrer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/expect/lib/expect.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:io'; 5 import 'dart:io';
6 import 'package:expect/expect.dart'; 6 import 'package:expect/expect.dart';
7 import 'package:async_helper/async_helper.dart'; 7 import 'package:async_helper/async_helper.dart';
8 import 'package:compiler/src/dart2jslib.dart'; 8 import 'package:compiler/src/dart2jslib.dart';
9 import 'package:compiler/src/elements/elements.dart'; 9 import 'package:compiler/src/elements/elements.dart';
10 import 'package:compiler/src/js_backend/js_backend.dart'; 10 import 'package:compiler/src/js_backend/js_backend.dart';
11 import 'package:compiler/src/types/types.dart';
12 import 'type_mask_test_helper.dart';
11 import 'memory_compiler.dart'; 13 import 'memory_compiler.dart';
12 14
13 const Map MEMORY_SOURCE_FILES = const { 15 const Map MEMORY_SOURCE_FILES = const {
14 'main.dart': r""" 16 'main.dart': r"""
15 import 'package:expect/expect.dart'; 17 import 'package:expect/expect.dart';
16 18
17 int method(String arg) => arg.length; 19 int method(String arg) => arg.length;
18 20
19 @AssumeDynamic() 21 @AssumeDynamic()
20 int methodAssumeDynamic(String arg) => arg.length; 22 int methodAssumeDynamic(String arg) => arg.length;
21 23
22 @TrustTypeAnnotations() 24 @TrustTypeAnnotations()
23 int methodTrustTypeAnnotations(String arg) => arg.length; 25 int methodTrustTypeAnnotations(String arg) => arg.length;
24 26
25 @NoInlining() 27 @NoInlining()
26 int methodNoInlining(String arg) => arg.length; 28 int methodNoInlining(String arg) => arg.length;
27 29
28 @NoInlining() @TrustTypeAnnotations() 30 @NoInlining() @TrustTypeAnnotations()
29 int methodNoInliningTrustTypeAnnotations(String arg) => arg.length; 31 int methodNoInliningTrustTypeAnnotations(String arg) => arg.length;
30 32
33 @AssumeDynamic() @TrustTypeAnnotations()
34 int methodAssumeDynamicTrustTypeAnnotations(String arg) => arg.length;
35
36
31 void main(List<String> args) { 37 void main(List<String> args) {
32 print(method(args[0])); 38 print(method(args[0]));
33 print(methodAssumeDynamic('foo')); 39 print(methodAssumeDynamic('foo'));
34 print(methodTrustTypeAnnotations(null)); 40 print(methodTrustTypeAnnotations(42));
41 print(methodTrustTypeAnnotations("fourtyTwo"));
35 print(methodNoInlining('bar')); 42 print(methodNoInlining('bar'));
36 print(methodNoInliningTrustTypeAnnotations(null)); 43 print(methodNoInliningTrustTypeAnnotations(42));
44 print(methodNoInliningTrustTypeAnnotations("fourtyTwo"));
45 print(methodAssumeDynamicTrustTypeAnnotations(null));
37 } 46 }
38 """ 47 """
39 }; 48 };
40 49
41 main() { 50 main() {
42 Compiler compiler = compilerFor(MEMORY_SOURCE_FILES); 51 Compiler compiler = compilerFor(MEMORY_SOURCE_FILES);
43 asyncTest(() => compiler.runCompiler(Uri.parse('memory:main.dart')).then((_) { 52 asyncTest(() => compiler.runCompiler(Uri.parse('memory:main.dart')).then((_) {
44 Expect.isFalse(compiler.compilationFailed, 'Unsuccessful compilation'); 53 Expect.isFalse(compiler.compilationFailed, 'Unsuccessful compilation');
45 JavaScriptBackend backend = compiler.backend; 54 JavaScriptBackend backend = compiler.backend;
46 Expect.isNotNull(backend.annotations.expectNoInliningClass, 55 Expect.isNotNull(backend.annotations.expectNoInliningClass,
47 'NoInliningClass is unresolved.'); 56 'NoInliningClass is unresolved.');
48 Expect.isNotNull(backend.annotations.expectTrustTypeAnnotationsClass, 57 Expect.isNotNull(backend.annotations.expectTrustTypeAnnotationsClass,
49 'TrustTypeAnnotations is unresolved.'); 58 'TrustTypeAnnotations is unresolved.');
50 Expect.isNotNull(backend.annotations.expectAssumeDynamicClass, 59 Expect.isNotNull(backend.annotations.expectAssumeDynamicClass,
51 'AssumeDynamicClass is unresolved.'); 60 'AssumeDynamicClass is unresolved.');
52 61
62 void testTypeMatch(FunctionElement function, TypeMask expectedType,
63 TypesInferrer inferrer) {
64 for (ParameterElement parameter in function.parameters) {
65 TypeMask type = inferrer.getTypeOfElement(parameter);
66 print("$parameter $type");
Johnni Winther 2015/02/06 10:49:39 Move this to the [reason] (third) argument of Expe
floitsch 2015/02/06 10:54:56 debug print.
herhut 2015/02/06 11:37:53 Acknowledged.
herhut 2015/02/06 11:37:53 Done.
67 Expect.equals(expectedType, simplify(type, compiler));
68 }
69 }
70
53 void test(String name, 71 void test(String name,
54 {bool expectNoInlining: false, 72 {bool expectNoInlining: false,
55 bool expectTrustTypeAnnotations: false, 73 bool expectTrustTypeAnnotations: false,
74 TypeMask expectedType: null,
56 bool expectAssumeDynamic: false}) { 75 bool expectAssumeDynamic: false}) {
57 Element method = compiler.mainApp.find(name); 76 Element method = compiler.mainApp.find(name);
58 Expect.isNotNull(method); 77 Expect.isNotNull(method);
59 Expect.equals( 78 Expect.equals(
60 expectNoInlining, 79 expectNoInlining,
61 backend.annotations.noInlining(method), 80 backend.annotations.noInlining(method),
62 "Unexpected annotation of @NoInlining on '$method'."); 81 "Unexpected annotation of @NoInlining on '$method'.");
63 Expect.equals( 82 Expect.equals(
64 expectTrustTypeAnnotations, 83 expectTrustTypeAnnotations,
65 backend.annotations.trustTypeAnnotations(method), 84 backend.annotations.trustTypeAnnotations(method),
66 "Unexpected annotation of @TrustTypeAnnotations on '$method'."); 85 "Unexpected annotation of @TrustTypeAnnotations on '$method'.");
67 Expect.equals( 86 Expect.equals(
68 expectAssumeDynamic, 87 expectAssumeDynamic,
69 backend.annotations.assumeDynamic(method), 88 backend.annotations.assumeDynamic(method),
70 "Unexpected annotation of @AssumeDynamic on '$method'."); 89 "Unexpected annotation of @AssumeDynamic on '$method'.");
90 TypesInferrer inferrer = compiler.typesTask.typesInferrer;
91 if (expectTrustTypeAnnotations && expectedType != null) {
92 testTypeMatch(method, expectedType, inferrer);
93 } else if (expectAssumeDynamic) {
94 testTypeMatch(method, compiler.typesTask.dynamicType, inferrer);
95 }
71 } 96 }
72 97
98 TypeMask stringType = compiler.typesTask.stringType;
Johnni Winther 2015/02/06 10:49:39 Maybe [jsStringType]
herhut 2015/02/06 11:37:53 Done.
99 TypeMask genericStringType = new TypeMask.subtype(compiler.stringClass,
Johnni Winther 2015/02/06 10:49:39 and [coreStringType] ?
herhut 2015/02/06 11:37:52 Done.
100 compiler.world);
101
73 test('method'); 102 test('method');
74 test('methodAssumeDynamic', expectAssumeDynamic: true); 103 test('methodAssumeDynamic', expectAssumeDynamic: true);
75 test('methodTrustTypeAnnotations', expectTrustTypeAnnotations: true); 104 test('methodTrustTypeAnnotations',
105 expectTrustTypeAnnotations: true,
106 expectedType: stringType);
76 test('methodNoInlining', expectNoInlining: true); 107 test('methodNoInlining', expectNoInlining: true);
77 test('methodNoInliningTrustTypeAnnotations', 108 test('methodNoInliningTrustTypeAnnotations',
78 expectNoInlining: true, 109 expectNoInlining: true,
79 expectTrustTypeAnnotations: true); 110 expectTrustTypeAnnotations: true,
111 expectedType: stringType);
112 test('methodAssumeDynamicTrustTypeAnnotations',
113 expectAssumeDynamic: true,
114 expectTrustTypeAnnotations: true,
115 expectedType: genericStringType);
116
80 })); 117 }));
81 } 118 }
OLDNEW
« no previous file with comments | « pkg/expect/lib/expect.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698