| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/types/types.dart' show TypeMask; | 7 import 'package:compiler/src/types/types.dart' show TypeMask; |
| 8 import 'package:compiler/src/types/masks.dart' show CommonMasks; |
| 9 import 'package:compiler/src/compiler.dart' show Compiler; |
| 8 | 10 |
| 9 import 'compiler_helper.dart'; | 11 import 'compiler_helper.dart'; |
| 10 import 'type_mask_test_helper.dart'; | 12 import 'type_mask_test_helper.dart'; |
| 11 | 13 |
| 12 void compileAndFind(String code, String className, String memberName, | 14 void compileAndFind(String code, String className, String memberName, |
| 13 bool disableInlining, check(compiler, element)) { | 15 bool disableInlining, check(compiler, element)) { |
| 14 Uri uri = new Uri(scheme: 'source'); | 16 Uri uri = new Uri(scheme: 'source'); |
| 15 var compiler = compilerFor(code, uri, disableInlining: disableInlining); | 17 var compiler = compilerFor(code, uri, disableInlining: disableInlining); |
| 16 asyncTest(() => compiler.run(uri).then((_) { | 18 asyncTest(() => compiler.run(uri).then((_) { |
| 17 var cls = findElement(compiler, className); | 19 var cls = findElement(compiler, className); |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 } | 464 } |
| 463 class B extends A { | 465 class B extends A { |
| 464 set f2(value) {} | 466 set f2(value) {} |
| 465 } | 467 } |
| 466 main() { | 468 main() { |
| 467 new A(); | 469 new A(); |
| 468 new B(); | 470 new B(); |
| 469 } | 471 } |
| 470 """; | 472 """; |
| 471 | 473 |
| 472 void doTest(String test, bool disableInlining, Map<String, Function> fields) { | 474 typedef TypeMask TestCallback(Compiler compiler, CommonMasks masks); |
| 473 fields.forEach((String name, Function f) { | 475 |
| 476 void doTest( |
| 477 String test, bool disableInlining, Map<String, TestCallback> fields) { |
| 478 fields.forEach((String name, TestCallback f) { |
| 474 compileAndFind(test, 'A', name, disableInlining, (compiler, field) { | 479 compileAndFind(test, 'A', name, disableInlining, (compiler, field) { |
| 475 TypeMask type = f(compiler.commonMasks); | 480 TypeMask type = f(compiler, compiler.closedWorld.commonMasks); |
| 476 var inferrer = compiler.globalInference.typesInferrer; | 481 var inferrer = compiler.globalInference.typesInferrerInternal; |
| 477 TypeMask inferredType = | 482 TypeMask inferredType = |
| 478 simplify(inferrer.getTypeOfElement(field), inferrer.compiler); | 483 simplify(inferrer.getTypeOfElement(field), inferrer.compiler); |
| 479 Expect.equals(type, inferredType, test); | 484 Expect.equals(type, inferredType, test); |
| 480 }); | 485 }); |
| 481 }); | 486 }); |
| 482 } | 487 } |
| 483 | 488 |
| 484 void runTest(String test, Map<String, Function> fields) { | 489 void runTest(String test, Map<String, TestCallback> fields) { |
| 485 doTest(test, false, fields); | 490 doTest(test, false, fields); |
| 486 doTest(test, true, fields); | 491 doTest(test, true, fields); |
| 487 } | 492 } |
| 488 | 493 |
| 489 void test() { | 494 void test() { |
| 490 subclassOfInterceptor(types) => | 495 TypeMask subclassOfInterceptor(Compiler compiler, CommonMasks types) => |
| 491 findTypeMask(types.compiler, 'Interceptor', 'nonNullSubclass'); | 496 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass'); |
| 492 | 497 |
| 493 runTest(TEST_1, {'f': (types) => types.nullType}); | 498 runTest( |
| 494 runTest(TEST_2, | 499 TEST_1, <String, TestCallback>{'f': (compiler, types) => types.nullType}); |
| 495 {'f1': (types) => types.nullType, 'f2': (types) => types.uint31Type}); | 500 runTest(TEST_2, <String, TestCallback>{ |
| 496 runTest(TEST_3, { | 501 'f1': (compiler, types) => types.nullType, |
| 497 'f1': (types) => types.uint31Type, | 502 'f2': (compiler, types) => types.uint31Type |
| 498 'f2': (types) => types.uint31Type.nullable() | |
| 499 }); | 503 }); |
| 500 runTest(TEST_4, { | 504 runTest(TEST_3, <String, TestCallback>{ |
| 505 'f1': (compiler, types) => types.uint31Type, |
| 506 'f2': (compiler, types) => types.uint31Type.nullable() |
| 507 }); |
| 508 runTest(TEST_4, <String, TestCallback>{ |
| 501 'f1': subclassOfInterceptor, | 509 'f1': subclassOfInterceptor, |
| 502 'f2': (types) => types.stringType.nullable() | 510 'f2': (compiler, types) => types.stringType.nullable() |
| 503 }); | 511 }); |
| 504 | 512 |
| 505 // TODO(ngeoffray): We should try to infer that the initialization | 513 // TODO(ngeoffray): We should try to infer that the initialization |
| 506 // code at the declaration site of the fields does not matter. | 514 // code at the declaration site of the fields does not matter. |
| 507 runTest(TEST_5, {'f1': subclassOfInterceptor, 'f2': subclassOfInterceptor}); | 515 runTest(TEST_5, <String, TestCallback>{ |
| 508 runTest(TEST_6, {'f1': subclassOfInterceptor, 'f2': subclassOfInterceptor}); | 516 'f1': subclassOfInterceptor, |
| 509 runTest(TEST_7, {'f1': subclassOfInterceptor, 'f2': subclassOfInterceptor}); | 517 'f2': subclassOfInterceptor |
| 518 }); |
| 519 runTest(TEST_6, <String, TestCallback>{ |
| 520 'f1': subclassOfInterceptor, |
| 521 'f2': subclassOfInterceptor |
| 522 }); |
| 523 runTest(TEST_7, <String, TestCallback>{ |
| 524 'f1': subclassOfInterceptor, |
| 525 'f2': subclassOfInterceptor |
| 526 }); |
| 510 | 527 |
| 511 runTest(TEST_8, {'f': (types) => types.stringType.nullable()}); | 528 runTest(TEST_8, <String, TestCallback>{ |
| 512 runTest(TEST_9, {'f': (types) => types.stringType.nullable()}); | 529 'f': (compiler, types) => types.stringType.nullable() |
| 513 runTest(TEST_10, {'f': (types) => types.uint31Type}); | 530 }); |
| 514 runTest(TEST_11, {'fs': (types) => types.uint31Type}); | 531 runTest(TEST_9, <String, TestCallback>{ |
| 532 'f': (compiler, types) => types.stringType.nullable() |
| 533 }); |
| 534 runTest(TEST_10, |
| 535 <String, TestCallback>{'f': (compiler, types) => types.uint31Type}); |
| 536 runTest(TEST_11, |
| 537 <String, TestCallback>{'fs': (compiler, types) => types.uint31Type}); |
| 515 | 538 |
| 516 // TODO(ngeoffray): We should try to infer that the initialization | 539 // TODO(ngeoffray): We should try to infer that the initialization |
| 517 // code at the declaration site of the fields does not matter. | 540 // code at the declaration site of the fields does not matter. |
| 518 runTest(TEST_12, {'fs': subclassOfInterceptor}); | 541 runTest(TEST_12, <String, TestCallback>{'fs': subclassOfInterceptor}); |
| 519 | 542 |
| 520 runTest(TEST_13, {'fs': (types) => types.uint31Type}); | 543 runTest(TEST_13, |
| 521 runTest(TEST_14, {'f': (types) => types.uint31Type}); | 544 <String, TestCallback>{'fs': (compiler, types) => types.uint31Type}); |
| 522 runTest(TEST_15, { | 545 runTest(TEST_14, |
| 523 'f': (types) { | 546 <String, TestCallback>{'f': (compiler, types) => types.uint31Type}); |
| 524 ClassElement cls = types.compiler.backend.helpers.jsIndexableClass; | 547 runTest(TEST_15, <String, TestCallback>{ |
| 525 return new TypeMask.nonNullSubtype(cls, types.compiler.closedWorld); | 548 'f': (compiler, types) { |
| 549 ClassElement cls = compiler.backend.helpers.jsIndexableClass; |
| 550 return new TypeMask.nonNullSubtype(cls, compiler.closedWorld); |
| 526 } | 551 } |
| 527 }); | 552 }); |
| 528 runTest(TEST_16, {'f': subclassOfInterceptor}); | 553 runTest(TEST_16, <String, TestCallback>{'f': subclassOfInterceptor}); |
| 529 runTest(TEST_17, {'f': (types) => types.uint31Type.nullable()}); | 554 runTest(TEST_17, <String, TestCallback>{ |
| 530 runTest(TEST_18, { | 555 'f': (compiler, types) => types.uint31Type.nullable() |
| 531 'f1': (types) => types.uint31Type, | |
| 532 'f2': (types) => types.stringType, | |
| 533 'f3': (types) => types.dynamicType | |
| 534 }); | 556 }); |
| 535 runTest(TEST_19, { | 557 runTest(TEST_18, <String, TestCallback>{ |
| 536 'f1': (types) => types.uint31Type, | 558 'f1': (compiler, types) => types.uint31Type, |
| 537 'f2': (types) => types.stringType, | 559 'f2': (compiler, types) => types.stringType, |
| 538 'f3': (types) => types.dynamicType | 560 'f3': (compiler, types) => types.dynamicType |
| 539 }); | 561 }); |
| 540 runTest(TEST_20, {'f': (types) => types.uint31Type.nullable()}); | 562 runTest(TEST_19, <String, TestCallback>{ |
| 541 runTest(TEST_21, {'f': (types) => types.uint31Type.nullable()}); | 563 'f1': (compiler, types) => types.uint31Type, |
| 542 | 564 'f2': (compiler, types) => types.stringType, |
| 543 runTest(TEST_22, { | 565 'f3': (compiler, types) => types.dynamicType |
| 544 'f1': (types) => types.uint31Type, | 566 }); |
| 545 'f2': (types) => types.uint31Type, | 567 runTest(TEST_20, <String, TestCallback>{ |
| 546 'f3': (types) => types.stringType.nullable() | 568 'f': (compiler, types) => types.uint31Type.nullable() |
| 569 }); |
| 570 runTest(TEST_21, <String, TestCallback>{ |
| 571 'f': (compiler, types) => types.uint31Type.nullable() |
| 547 }); | 572 }); |
| 548 | 573 |
| 549 runTest(TEST_23, { | 574 runTest(TEST_22, <String, TestCallback>{ |
| 550 'f1': (types) => types.uint31Type.nullable(), | 575 'f1': (compiler, types) => types.uint31Type, |
| 551 'f2': (types) => types.uint31Type.nullable(), | 576 'f2': (compiler, types) => types.uint31Type, |
| 552 'f3': (types) => types.uint31Type.nullable(), | 577 'f3': (compiler, types) => types.stringType.nullable() |
| 553 'f4': (types) => types.uint31Type.nullable() | |
| 554 }); | 578 }); |
| 555 | 579 |
| 556 runTest(TEST_24, { | 580 runTest(TEST_23, <String, TestCallback>{ |
| 557 'f1': (types) => types.positiveIntType, | 581 'f1': (compiler, types) => types.uint31Type.nullable(), |
| 558 'f2': (types) => types.positiveIntType, | 582 'f2': (compiler, types) => types.uint31Type.nullable(), |
| 559 'f3': (types) => types.uint31Type, | 583 'f3': (compiler, types) => types.uint31Type.nullable(), |
| 560 'f4': (types) => types.uint31Type, | 584 'f4': (compiler, types) => types.uint31Type.nullable() |
| 561 'f5': (types) => types.numType.nullable(), | |
| 562 'f6': (types) => types.stringType.nullable() | |
| 563 }); | 585 }); |
| 564 | 586 |
| 565 runTest(TEST_25, {'f1': (types) => types.uint31Type}); | 587 runTest(TEST_24, <String, TestCallback>{ |
| 566 runTest(TEST_26, {'f1': (types) => types.positiveIntType}); | 588 'f1': (compiler, types) => types.positiveIntType, |
| 567 runTest(TEST_27, { | 589 'f2': (compiler, types) => types.positiveIntType, |
| 568 'f1': (types) => types.uint31Type, | 590 'f3': (compiler, types) => types.uint31Type, |
| 569 'f2': (types) => types.uint31Type.nullable() | 591 'f4': (compiler, types) => types.uint31Type, |
| 592 'f5': (compiler, types) => types.numType.nullable(), |
| 593 'f6': (compiler, types) => types.stringType.nullable() |
| 594 }); |
| 595 |
| 596 runTest(TEST_25, |
| 597 <String, TestCallback>{'f1': (compiler, types) => types.uint31Type}); |
| 598 runTest(TEST_26, |
| 599 <String, TestCallback>{'f1': (compiler, types) => types.positiveIntType}); |
| 600 runTest(TEST_27, <String, TestCallback>{ |
| 601 'f1': (compiler, types) => types.uint31Type, |
| 602 'f2': (compiler, types) => types.uint31Type.nullable() |
| 570 }); | 603 }); |
| 571 } | 604 } |
| 572 | 605 |
| 573 void main() { | 606 void main() { |
| 574 test(); | 607 test(); |
| 575 } | 608 } |
| OLD | NEW |