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

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

Issue 2577423002: Further reduce use of Compiler.closedWorld. (Closed)
Patch Set: Created 4 years 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
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 'package:expect/expect.dart'; 5 import 'package:expect/expect.dart';
6 import 'package:async_helper/async_helper.dart'; 6 import 'package:async_helper/async_helper.dart';
7 import 'package:compiler/src/compiler.dart'; 7 import 'package:compiler/src/compiler.dart';
8 import 'package:compiler/src/elements/elements.dart'; 8 import 'package:compiler/src/elements/elements.dart';
9 import 'package:compiler/src/js_backend/js_backend.dart'; 9 import 'package:compiler/src/js_backend/js_backend.dart';
10 import 'package:compiler/src/types/types.dart'; 10 import 'package:compiler/src/types/types.dart';
11 import 'package:compiler/src/world.dart' show ClosedWorld;
11 import 'type_mask_test_helper.dart'; 12 import 'type_mask_test_helper.dart';
12 import 'memory_compiler.dart'; 13 import 'memory_compiler.dart';
13 14
14 const Map MEMORY_SOURCE_FILES = const { 15 const Map MEMORY_SOURCE_FILES = const {
15 'main.dart': r""" 16 'main.dart': r"""
16 import 'package:expect/expect.dart'; 17 import 'package:expect/expect.dart';
17 18
18 int method(String arg) => arg.length; 19 int method(String arg) => arg.length;
19 20
20 @AssumeDynamic() 21 @AssumeDynamic()
(...skipping 23 matching lines...) Expand all
44 print(methodAssumeDynamicTrustTypeAnnotations(null)); 45 print(methodAssumeDynamicTrustTypeAnnotations(null));
45 } 46 }
46 """ 47 """
47 }; 48 };
48 49
49 main() { 50 main() {
50 asyncTest(() async { 51 asyncTest(() async {
51 CompilationResult result = 52 CompilationResult result =
52 await runCompiler(memorySourceFiles: MEMORY_SOURCE_FILES); 53 await runCompiler(memorySourceFiles: MEMORY_SOURCE_FILES);
53 Compiler compiler = result.compiler; 54 Compiler compiler = result.compiler;
55 ClosedWorld closedWorld = compiler.closedWorld;
54 Expect.isFalse(compiler.compilationFailed, 'Unsuccessful compilation'); 56 Expect.isFalse(compiler.compilationFailed, 'Unsuccessful compilation');
55 JavaScriptBackend backend = compiler.backend; 57 JavaScriptBackend backend = compiler.backend;
56 Expect.isNotNull(backend.annotations.expectNoInlineClass, 58 Expect.isNotNull(backend.annotations.expectNoInlineClass,
57 'NoInlineClass is unresolved.'); 59 'NoInlineClass is unresolved.');
58 Expect.isNotNull(backend.annotations.expectTrustTypeAnnotationsClass, 60 Expect.isNotNull(backend.annotations.expectTrustTypeAnnotationsClass,
59 'TrustTypeAnnotations is unresolved.'); 61 'TrustTypeAnnotations is unresolved.');
60 Expect.isNotNull(backend.annotations.expectAssumeDynamicClass, 62 Expect.isNotNull(backend.annotations.expectAssumeDynamicClass,
61 'AssumeDynamicClass is unresolved.'); 63 'AssumeDynamicClass is unresolved.');
62 64
63 void testTypeMatch(FunctionElement function, TypeMask expectedParameterType, 65 void testTypeMatch(FunctionElement function, TypeMask expectedParameterType,
64 TypeMask expectedReturnType, TypesInferrer inferrer) { 66 TypeMask expectedReturnType, TypesInferrer inferrer) {
65 for (ParameterElement parameter in function.parameters) { 67 for (ParameterElement parameter in function.parameters) {
66 TypeMask type = inferrer.getTypeOfElement(parameter); 68 TypeMask type = inferrer.getTypeOfElement(parameter);
67 Expect.equals( 69 Expect.equals(
68 expectedParameterType, simplify(type, compiler), "$parameter"); 70 expectedParameterType, simplify(type, closedWorld), "$parameter");
69 } 71 }
70 if (expectedReturnType != null) { 72 if (expectedReturnType != null) {
71 TypeMask type = inferrer.getReturnTypeOfElement(function); 73 TypeMask type = inferrer.getReturnTypeOfElement(function);
72 Expect.equals( 74 Expect.equals(
73 expectedReturnType, simplify(type, compiler), "$function"); 75 expectedReturnType, simplify(type, closedWorld), "$function");
74 } 76 }
75 } 77 }
76 78
77 void test(String name, 79 void test(String name,
78 {bool expectNoInline: false, 80 {bool expectNoInline: false,
79 bool expectTrustTypeAnnotations: false, 81 bool expectTrustTypeAnnotations: false,
80 TypeMask expectedParameterType: null, 82 TypeMask expectedParameterType: null,
81 TypeMask expectedReturnType: null, 83 TypeMask expectedReturnType: null,
82 bool expectAssumeDynamic: false}) { 84 bool expectAssumeDynamic: false}) {
83 Element method = compiler.mainApp.find(name); 85 Element method = compiler.mainApp.find(name);
84 Expect.isNotNull(method); 86 Expect.isNotNull(method);
85 Expect.equals(expectNoInline, backend.annotations.noInline(method), 87 Expect.equals(expectNoInline, backend.annotations.noInline(method),
86 "Unexpected annotation of @NoInline on '$method'."); 88 "Unexpected annotation of @NoInline on '$method'.");
87 Expect.equals( 89 Expect.equals(
88 expectTrustTypeAnnotations, 90 expectTrustTypeAnnotations,
89 backend.annotations.trustTypeAnnotations(method), 91 backend.annotations.trustTypeAnnotations(method),
90 "Unexpected annotation of @TrustTypeAnnotations on '$method'."); 92 "Unexpected annotation of @TrustTypeAnnotations on '$method'.");
91 Expect.equals( 93 Expect.equals(
92 expectAssumeDynamic, 94 expectAssumeDynamic,
93 backend.annotations.assumeDynamic(method), 95 backend.annotations.assumeDynamic(method),
94 "Unexpected annotation of @AssumeDynamic on '$method'."); 96 "Unexpected annotation of @AssumeDynamic on '$method'.");
95 TypesInferrer inferrer = compiler.globalInference.typesInferrerInternal; 97 TypesInferrer inferrer = compiler.globalInference.typesInferrerInternal;
96 if (expectTrustTypeAnnotations && expectedParameterType != null) { 98 if (expectTrustTypeAnnotations && expectedParameterType != null) {
97 testTypeMatch( 99 testTypeMatch(
98 method, expectedParameterType, expectedReturnType, inferrer); 100 method, expectedParameterType, expectedReturnType, inferrer);
99 } else if (expectAssumeDynamic) { 101 } else if (expectAssumeDynamic) {
100 testTypeMatch(method, compiler.closedWorld.commonMasks.dynamicType, 102 testTypeMatch(
101 null, inferrer); 103 method, closedWorld.commonMasks.dynamicType, null, inferrer);
102 } 104 }
103 } 105 }
104 106
105 TypeMask jsStringType = compiler.closedWorld.commonMasks.stringType; 107 TypeMask jsStringType = closedWorld.commonMasks.stringType;
106 TypeMask jsIntType = compiler.closedWorld.commonMasks.intType; 108 TypeMask jsIntType = closedWorld.commonMasks.intType;
107 TypeMask coreStringType = new TypeMask.subtype( 109 TypeMask coreStringType =
108 compiler.coreClasses.stringClass, compiler.closedWorld); 110 new TypeMask.subtype(compiler.coreClasses.stringClass, closedWorld);
109 111
110 test('method'); 112 test('method');
111 test('methodAssumeDynamic', expectAssumeDynamic: true); 113 test('methodAssumeDynamic', expectAssumeDynamic: true);
112 test('methodTrustTypeAnnotations', 114 test('methodTrustTypeAnnotations',
113 expectTrustTypeAnnotations: true, expectedParameterType: jsStringType); 115 expectTrustTypeAnnotations: true, expectedParameterType: jsStringType);
114 test('methodNoInline', expectNoInline: true); 116 test('methodNoInline', expectNoInline: true);
115 test('methodNoInlineTrustTypeAnnotations', 117 test('methodNoInlineTrustTypeAnnotations',
116 expectNoInline: true, 118 expectNoInline: true,
117 expectTrustTypeAnnotations: true, 119 expectTrustTypeAnnotations: true,
118 expectedParameterType: jsStringType, 120 expectedParameterType: jsStringType,
119 expectedReturnType: jsIntType); 121 expectedReturnType: jsIntType);
120 test('methodAssumeDynamicTrustTypeAnnotations', 122 test('methodAssumeDynamicTrustTypeAnnotations',
121 expectAssumeDynamic: true, 123 expectAssumeDynamic: true,
122 expectTrustTypeAnnotations: true, 124 expectTrustTypeAnnotations: true,
123 expectedParameterType: coreStringType); 125 expectedParameterType: coreStringType);
124 }); 126 });
125 } 127 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/dictionary_types_test.dart ('k') | tests/compiler/dart2js/field_type_simple_inferer_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698