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

Side by Side Diff: tests/compiler/dart2js/kernel/impact_test.dart

Issue 2392863002: Roll kernel to latest (Closed)
Patch Set: Reinsert code Created 4 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 library dart2js.kernel.impact_test; 5 library dart2js.kernel.impact_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'package:async_helper/async_helper.dart'; 8 import 'package:async_helper/async_helper.dart';
9 import 'package:compiler/src/commandline_options.dart'; 9 import 'package:compiler/src/commandline_options.dart';
10 import 'package:compiler/src/common.dart'; 10 import 'package:compiler/src/common.dart';
11 import 'package:compiler/src/common/names.dart'; 11 import 'package:compiler/src/common/names.dart';
12 import 'package:compiler/src/common/resolution.dart'; 12 import 'package:compiler/src/common/resolution.dart';
13 import 'package:compiler/src/compiler.dart'; 13 import 'package:compiler/src/compiler.dart';
14 import 'package:compiler/src/elements/elements.dart'; 14 import 'package:compiler/src/elements/elements.dart';
15 import 'package:compiler/src/resolution/registry.dart'; 15 import 'package:compiler/src/resolution/registry.dart';
16 import 'package:compiler/src/ssa/kernel_impact.dart'; 16 import 'package:compiler/src/ssa/kernel_impact.dart';
17 import 'package:compiler/src/serialization/equivalence.dart'; 17 import 'package:compiler/src/serialization/equivalence.dart';
18 import 'package:compiler/src/universe/call_structure.dart';
18 import 'package:compiler/src/universe/feature.dart'; 19 import 'package:compiler/src/universe/feature.dart';
19 import 'package:compiler/src/universe/use.dart'; 20 import 'package:compiler/src/universe/use.dart';
20 import 'package:expect/expect.dart'; 21 import 'package:expect/expect.dart';
21 import '../memory_compiler.dart'; 22 import '../memory_compiler.dart';
22 import '../serialization/test_helper.dart'; 23 import '../serialization/test_helper.dart';
23 24
24 const Map<String, String> SOURCE = const <String, String>{ 25 const Map<String, String> SOURCE = const <String, String>{
25 'main.dart': r''' 26 'main.dart': r'''
26 import 'helper.dart'; 27 import 'helper.dart';
27 28
(...skipping 27 matching lines...) Expand all
55 testPreInc(null); 56 testPreInc(null);
56 testPreDec(null); 57 testPreDec(null);
57 testIs(null); 58 testIs(null);
58 testIsGeneric(null); 59 testIsGeneric(null);
59 testIsGenericRaw(null); 60 testIsGenericRaw(null);
60 testIsGenericDynamic(null); 61 testIsGenericDynamic(null);
61 testIsNot(null); 62 testIsNot(null);
62 testIsNotGeneric(null); 63 testIsNotGeneric(null);
63 testIsNotGenericRaw(null); 64 testIsNotGenericRaw(null);
64 testIsNotGenericDynamic(null); 65 testIsNotGenericDynamic(null);
66 testIsTypedef(null);
67 testIsTypedefGeneric(null);
68 testIsTypedefGenericRaw(null);
69 testIsTypedefGenericDynamic(null);
65 testAs(null); 70 testAs(null);
66 testAsGeneric(null); 71 testAsGeneric(null);
67 testAsGenericRaw(null); 72 testAsGenericRaw(null);
68 testAsGenericDynamic(null); 73 testAsGenericDynamic(null);
69 testThrow(); 74 testThrow();
70 testSyncStar(); 75 testSyncStar();
71 testAsync(); 76 testAsync();
72 testAsyncStar(); 77 testAsyncStar();
73 testIfThen(); 78 testIfThen();
74 testIfThenElse(); 79 testIfThenElse();
75 testForIn(null); 80 testForIn(null);
76 testForInTyped(null); 81 testForInTyped(null);
77 testAsyncForIn(null); 82 testAsyncForIn(null);
78 testAsyncForInTyped(null); 83 testAsyncForInTyped(null);
79 testTryCatch(); 84 testTryCatch();
80 testTryCatchOn(); 85 testTryCatchOn();
81 testTryCatchStackTrace(); 86 testTryCatchStackTrace();
82 testTryFinally(); 87 testTryFinally();
88 testSwitchWithoutFallthrough(null);
89 testSwitchWithFallthrough(null);
83 testTopLevelInvoke(); 90 testTopLevelInvoke();
84 testTopLevelInvokeTyped(); 91 testTopLevelInvokeTyped();
85 testTopLevelFunctionTyped(); 92 testTopLevelFunctionTyped();
86 testTopLevelFunctionGet(); 93 testTopLevelFunctionGet();
87 testTopLevelGetterGet(); 94 testTopLevelGetterGet();
88 testTopLevelGetterGetTyped(); 95 testTopLevelGetterGetTyped();
89 testTopLevelSetterSet(); 96 testTopLevelSetterSet();
90 testTopLevelSetterSetTyped(); 97 testTopLevelSetterSetTyped();
91 testTopLevelField(); 98 testTopLevelField();
92 testTopLevelFieldLazy(); 99 testTopLevelFieldLazy();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 testPreDec(o) => --o; 166 testPreDec(o) => --o;
160 167
161 testIs(o) => o is Class; 168 testIs(o) => o is Class;
162 testIsGeneric(o) => o is GenericClass<int, String>; 169 testIsGeneric(o) => o is GenericClass<int, String>;
163 testIsGenericRaw(o) => o is GenericClass; 170 testIsGenericRaw(o) => o is GenericClass;
164 testIsGenericDynamic(o) => o is GenericClass<dynamic, dynamic>; 171 testIsGenericDynamic(o) => o is GenericClass<dynamic, dynamic>;
165 testIsNot(o) => o is! Class; 172 testIsNot(o) => o is! Class;
166 testIsNotGeneric(o) => o is! GenericClass<int, String>; 173 testIsNotGeneric(o) => o is! GenericClass<int, String>;
167 testIsNotGenericRaw(o) => o is! GenericClass; 174 testIsNotGenericRaw(o) => o is! GenericClass;
168 testIsNotGenericDynamic(o) => o is! GenericClass<dynamic, dynamic>; 175 testIsNotGenericDynamic(o) => o is! GenericClass<dynamic, dynamic>;
176 testIsTypedef(o) => o is Typedef;
177 testIsTypedefGeneric(o) => o is GenericTypedef<int, String>;
178 testIsTypedefGenericRaw(o) => o is GenericTypedef;
179 testIsTypedefGenericDynamic(o) => o is GenericTypedef<dynamic, dynamic>;
169 testAs(o) => o as Class; 180 testAs(o) => o as Class;
170 testAsGeneric(o) => o as GenericClass<int, String>; 181 testAsGeneric(o) => o as GenericClass<int, String>;
171 testAsGenericRaw(o) => o as GenericClass; 182 testAsGenericRaw(o) => o as GenericClass;
172 testAsGenericDynamic(o) => o as GenericClass<dynamic, dynamic>; 183 testAsGenericDynamic(o) => o as GenericClass<dynamic, dynamic>;
173 testThrow() => throw ''; 184 testThrow() => throw '';
174 185
175 testSyncStar() sync* {} 186 testSyncStar() sync* {}
176 testAsync() async {} 187 testAsync() async {}
177 testAsyncStar() async* {} 188 testAsyncStar() async* {}
178 testIfThen() { 189 testIfThen() {
(...skipping 24 matching lines...) Expand all
203 } 214 }
204 testTryCatchOn() { 215 testTryCatchOn() {
205 try {} on String catch (e) {} 216 try {} on String catch (e) {}
206 } 217 }
207 testTryCatchStackTrace() { 218 testTryCatchStackTrace() {
208 try {} catch (e, s) {} 219 try {} catch (e, s) {}
209 } 220 }
210 testTryFinally() { 221 testTryFinally() {
211 try {} finally {} 222 try {} finally {}
212 } 223 }
224 testSwitchWithoutFallthrough(o) {
225 switch (o) {
226 case 0:
227 case 1:
228 o = 2;
229 break;
230 case 2:
231 o = 3;
232 return;
233 case 3:
234 default:
235 }
236 }
237 testSwitchWithFallthrough(o) {
238 switch (o) {
239 case 0:
240 case 1:
241 o = 2;
242 case 2:
243 o = 3;
244 return;
245 case 3:
246 default:
247 }
248 }
213 topLevelFunction1(a) {} 249 topLevelFunction1(a) {}
214 topLevelFunction2(a, [b, c]) {} 250 topLevelFunction2(a, [b, c]) {}
215 topLevelFunction3(a, {b, c}) {} 251 topLevelFunction3(a, {b, c}) {}
216 testTopLevelInvoke() { 252 testTopLevelInvoke() {
217 topLevelFunction1(0); 253 topLevelFunction1(0);
218 topLevelFunction2(1); 254 topLevelFunction2(1);
219 topLevelFunction2(2, 3); 255 topLevelFunction2(2, 3);
220 topLevelFunction2(4, 5, 6); 256 topLevelFunction2(4, 5, 6);
221 topLevelFunction3(7); 257 topLevelFunction3(7);
222 topLevelFunction3(8, b: 9); 258 topLevelFunction3(8, b: 9);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 class Class { 405 class Class {
370 Class.generative(); 406 Class.generative();
371 factory Class.fact() => null; 407 factory Class.fact() => null;
372 factory Class.redirect() = Class.generative; 408 factory Class.redirect() = Class.generative;
373 } 409 }
374 class GenericClass<X, Y> { 410 class GenericClass<X, Y> {
375 GenericClass.generative(); 411 GenericClass.generative();
376 factory GenericClass.fact() => null; 412 factory GenericClass.fact() => null;
377 factory GenericClass.redirect() = GenericClass.generative; 413 factory GenericClass.redirect() = GenericClass.generative;
378 } 414 }
415 typedef Typedef();
416 typedef X GenericTypedef<X, Y>(Y y);
379 ''', 417 ''',
380 }; 418 };
381 419
382 main(List<String> args) { 420 main(List<String> args) {
383 asyncTest(() async { 421 asyncTest(() async {
384 enableDebugMode(); 422 enableDebugMode();
385 Uri entryPoint = Uri.parse('memory:main.dart'); 423 Uri entryPoint = Uri.parse('memory:main.dart');
386 Compiler compiler = compilerFor( 424 Compiler compiler = compilerFor(
387 entryPoint: entryPoint, 425 entryPoint: entryPoint,
388 memorySourceFiles: SOURCE, 426 memorySourceFiles: SOURCE,
(...skipping 15 matching lines...) Expand all
404 } else if (element.isTypedef) { 442 } else if (element.isTypedef) {
405 // Skip typedefs. 443 // Skip typedefs.
406 } else { 444 } else {
407 checkElement(compiler, element); 445 checkElement(compiler, element);
408 } 446 }
409 }); 447 });
410 } 448 }
411 449
412 void checkElement(Compiler compiler, AstElement element) { 450 void checkElement(Compiler compiler, AstElement element) {
413 ResolutionImpact astImpact = compiler.resolution.getResolutionImpact(element); 451 ResolutionImpact astImpact = compiler.resolution.getResolutionImpact(element);
414 astImpact = laxImpact(element, astImpact); 452 astImpact = laxImpact(compiler, element, astImpact);
415 ResolutionImpact kernelImpact = build(compiler, element.resolvedAst); 453 ResolutionImpact kernelImpact = build(compiler, element.resolvedAst);
416 Expect.isNotNull(kernelImpact, 'No impact computed for $element'); 454 Expect.isNotNull(kernelImpact, 'No impact computed for $element');
417 testResolutionImpactEquivalence( 455 testResolutionImpactEquivalence(
418 astImpact, kernelImpact, const CheckStrategy()); 456 astImpact, kernelImpact, const CheckStrategy());
419 } 457 }
420 458
421 /// Lax the precision of [impact] to meet expectancy of the corresponding impact 459 /// Lax the precision of [impact] to meet expectancy of the corresponding impact
422 /// generated from kernel. 460 /// generated from kernel.
423 ResolutionImpact laxImpact(AstElement element, ResolutionImpact impact) { 461 ResolutionImpact laxImpact(
462 Compiler compiler, AstElement element, ResolutionImpact impact) {
424 ResolutionWorldImpactBuilder builder = 463 ResolutionWorldImpactBuilder builder =
425 new ResolutionWorldImpactBuilder('Lax impact of ${element}'); 464 new ResolutionWorldImpactBuilder('Lax impact of ${element}');
426 impact.staticUses.forEach(builder.registerStaticUse); 465 impact.staticUses.forEach(builder.registerStaticUse);
427 impact.dynamicUses.forEach(builder.registerDynamicUse); 466 impact.dynamicUses.forEach(builder.registerDynamicUse);
428 impact.typeUses.forEach(builder.registerTypeUse); 467 for (TypeUse typeUse in impact.typeUses) {
468 if (typeUse.type.isTypedef) {
469 typeUse = new TypeUse.internal(typeUse.type.unaliased, typeUse.kind);
470 }
471 builder.registerTypeUse(typeUse);
472 }
429 impact.constantLiterals.forEach(builder.registerConstantLiteral); 473 impact.constantLiterals.forEach(builder.registerConstantLiteral);
430 impact.constSymbolNames.forEach(builder.registerConstSymbolName); 474 impact.constSymbolNames.forEach(builder.registerConstSymbolName);
431 impact.listLiterals.forEach(builder.registerListLiteral); 475 impact.listLiterals.forEach(builder.registerListLiteral);
432 impact.mapLiterals.forEach(builder.registerMapLiteral); 476 impact.mapLiterals.forEach(builder.registerMapLiteral);
433 for (Feature feature in impact.features) { 477 for (Feature feature in impact.features) {
434 builder.registerFeature(feature);
435 switch (feature) { 478 switch (feature) {
436 case Feature.STRING_INTERPOLATION: 479 case Feature.STRING_INTERPOLATION:
437 case Feature.STRING_JUXTAPOSITION: 480 case Feature.STRING_JUXTAPOSITION:
438 // These are both converted into a string concatenation in kernel so 481 // These are both converted into a string concatenation in kernel so
439 // we cannot tell the diferrence. 482 // we cannot tell the diferrence.
440 builder.registerFeature(Feature.STRING_INTERPOLATION); 483 builder.registerFeature(Feature.STRING_INTERPOLATION);
441 builder.registerFeature(Feature.STRING_JUXTAPOSITION); 484 builder.registerFeature(Feature.STRING_JUXTAPOSITION);
442 break; 485 break;
486 case Feature.FALL_THROUGH_ERROR:
487 LibraryElement library =
488 compiler.libraryLoader.lookupLibrary(Uris.dart_core);
489 ClassElement cls =
490 library.implementation.localLookup('FallThroughError');
491 ConstructorElement constructor = cls.lookupConstructor('');
492 builder.registerTypeUse(new TypeUse.instantiation(cls.thisType));
493 builder.registerStaticUse(new StaticUse.constructorInvoke(
494 constructor, CallStructure.NO_ARGS));
495 builder.registerFeature(Feature.THROW_EXPRESSION);
496 break;
443 default: 497 default:
498 builder.registerFeature(feature);
499 break;
444 } 500 }
445 } 501 }
446 impact.nativeData.forEach(builder.registerNativeData); 502 impact.nativeData.forEach(builder.registerNativeData);
447 return builder; 503 return builder;
448 } 504 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/resolution/members.dart ('k') | tests/compiler/dart2js/kernel/visitor_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698