OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // TODO(jochen): Remove this after the setting is turned on globally. | 5 // TODO(jochen): Remove this after the setting is turned on globally. |
6 #define V8_IMMINENT_DEPRECATION_WARNINGS | 6 #define V8_IMMINENT_DEPRECATION_WARNINGS |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/ast/ast.h" | 10 #include "src/ast/ast.h" |
11 #include "src/ast/ast-expression-visitor.h" | 11 #include "src/ast/ast-expression-visitor.h" |
12 #include "src/ast/scopes.h" | 12 #include "src/ast/scopes.h" |
13 #include "src/parsing/parser.h" | 13 #include "src/parsing/parser.h" |
14 #include "src/parsing/rewriter.h" | 14 #include "src/parsing/rewriter.h" |
15 #include "src/type-cache.h" | 15 #include "src/type-cache.h" |
16 #include "src/typing-asm.h" | 16 #include "src/typing-asm.h" |
17 #include "test/cctest/cctest.h" | 17 #include "test/cctest/cctest.h" |
18 #include "test/cctest/expression-type-collector.h" | 18 #include "test/cctest/expression-type-collector.h" |
19 #include "test/cctest/expression-type-collector-macros.h" | 19 #include "test/cctest/expression-type-collector-macros.h" |
20 | 20 |
21 // Macros for function types. | 21 // Macros for function types. |
22 #define FUNC_V_TYPE Bounds(Type::Function(Type::Undefined(), zone)) | 22 #define FUNC_V_TYPE Bounds(Type::Function(Type::Undefined(zone), zone)) |
23 #define FUNC_I_TYPE Bounds(Type::Function(cache.kAsmSigned, zone)) | 23 #define FUNC_I_TYPE Bounds(Type::Function(cache.kAsmSigned, zone)) |
24 #define FUNC_F_TYPE Bounds(Type::Function(cache.kAsmFloat, zone)) | 24 #define FUNC_F_TYPE Bounds(Type::Function(cache.kAsmFloat, zone)) |
25 #define FUNC_D_TYPE Bounds(Type::Function(cache.kAsmDouble, zone)) | 25 #define FUNC_D_TYPE Bounds(Type::Function(cache.kAsmDouble, zone)) |
26 #define FUNC_D2D_TYPE \ | 26 #define FUNC_D2D_TYPE \ |
27 Bounds(Type::Function(cache.kAsmDouble, cache.kAsmDouble, zone)) | 27 Bounds(Type::Function(cache.kAsmDouble, cache.kAsmDouble, zone)) |
28 #define FUNC_N2F_TYPE \ | 28 #define FUNC_N2F_TYPE \ |
29 Bounds(Type::Function(cache.kAsmFloat, Type::Number(), zone)) | 29 Bounds(Type::Function(cache.kAsmFloat, Type::Number(zone), zone)) |
30 #define FUNC_I2I_TYPE \ | 30 #define FUNC_I2I_TYPE \ |
31 Bounds(Type::Function(cache.kAsmSigned, cache.kAsmInt, zone)) | 31 Bounds(Type::Function(cache.kAsmSigned, cache.kAsmInt, zone)) |
32 #define FUNC_II2D_TYPE \ | 32 #define FUNC_II2D_TYPE \ |
33 Bounds(Type::Function(cache.kAsmDouble, cache.kAsmInt, cache.kAsmInt, zone)) | 33 Bounds(Type::Function(cache.kAsmDouble, cache.kAsmInt, cache.kAsmInt, zone)) |
34 #define FUNC_II2I_TYPE \ | 34 #define FUNC_II2I_TYPE \ |
35 Bounds(Type::Function(cache.kAsmSigned, cache.kAsmInt, cache.kAsmInt, zone)) | 35 Bounds(Type::Function(cache.kAsmSigned, cache.kAsmInt, cache.kAsmInt, zone)) |
36 #define FUNC_DD2D_TYPE \ | 36 #define FUNC_DD2D_TYPE \ |
37 Bounds(Type::Function(cache.kAsmDouble, cache.kAsmDouble, cache.kAsmDouble, \ | 37 Bounds(Type::Function(cache.kAsmDouble, cache.kAsmDouble, cache.kAsmDouble, \ |
38 zone)) | 38 zone)) |
39 #define FUNC_N2N_TYPE \ | 39 #define FUNC_N2N_TYPE \ |
40 Bounds(Type::Function(Type::Number(), Type::Number(), zone)) | 40 Bounds(Type::Function(Type::Number(zone), Type::Number(zone), zone)) |
41 | 41 |
42 // Macros for array types. | 42 // Macros for array types. |
43 #define FLOAT64_ARRAY_TYPE Bounds(Type::Array(cache.kAsmDouble, zone)) | 43 #define FLOAT64_ARRAY_TYPE Bounds(Type::Array(cache.kAsmDouble, zone)) |
44 #define FUNC_I2I_ARRAY_TYPE \ | 44 #define FUNC_I2I_ARRAY_TYPE \ |
45 Bounds(Type::Array(Type::Function(cache.kAsmSigned, cache.kAsmInt, zone), \ | 45 Bounds(Type::Array(Type::Function(cache.kAsmSigned, cache.kAsmInt, zone), \ |
46 zone)) | 46 zone)) |
47 | 47 |
48 using namespace v8::internal; | 48 using namespace v8::internal; |
49 | 49 |
50 namespace { | 50 namespace { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 258 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); |
259 } | 259 } |
260 CHECK_EXPR(Literal, Bounds(cache.kAsmDouble)); | 260 CHECK_EXPR(Literal, Bounds(cache.kAsmDouble)); |
261 } | 261 } |
262 } | 262 } |
263 } | 263 } |
264 CHECK_EXPR(Literal, Bounds(cache.kAsmDouble)); | 264 CHECK_EXPR(Literal, Bounds(cache.kAsmDouble)); |
265 } | 265 } |
266 } | 266 } |
267 // "use asm"; | 267 // "use asm"; |
268 CHECK_EXPR(Literal, Bounds(Type::String())); | 268 CHECK_EXPR(Literal, Bounds(Type::String(zone))); |
269 // var exp = stdlib.Math.exp; | 269 // var exp = stdlib.Math.exp; |
270 CHECK_EXPR(Assignment, FUNC_D2D_TYPE) { | 270 CHECK_EXPR(Assignment, FUNC_D2D_TYPE) { |
271 CHECK_VAR(exp, FUNC_D2D_TYPE); | 271 CHECK_VAR(exp, FUNC_D2D_TYPE); |
272 CHECK_EXPR(Property, FUNC_D2D_TYPE) { | 272 CHECK_EXPR(Property, FUNC_D2D_TYPE) { |
273 CHECK_EXPR(Property, Bounds::Unbounded()) { | 273 CHECK_EXPR(Property, Bounds::Unbounded()) { |
274 CHECK_VAR(stdlib, Bounds::Unbounded()); | 274 CHECK_VAR(stdlib, Bounds::Unbounded()); |
275 CHECK_EXPR(Literal, Bounds::Unbounded()); | 275 CHECK_EXPR(Literal, Bounds::Unbounded()); |
276 } | 276 } |
277 CHECK_EXPR(Literal, Bounds::Unbounded()); | 277 CHECK_EXPR(Literal, Bounds::Unbounded()); |
278 } | 278 } |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 v8::V8::Initialize(); \ | 456 v8::V8::Initialize(); \ |
457 HandleAndZoneScope handles; \ | 457 HandleAndZoneScope handles; \ |
458 Zone* zone = handles.main_zone(); \ | 458 Zone* zone = handles.main_zone(); \ |
459 ZoneVector<ExpressionTypeEntry> types(zone); \ | 459 ZoneVector<ExpressionTypeEntry> types(zone); \ |
460 CHECK_EQ("", Validate(zone, test_function, &types)); \ | 460 CHECK_EQ("", Validate(zone, test_function, &types)); \ |
461 TypeCache cache; \ | 461 TypeCache cache; \ |
462 \ | 462 \ |
463 CHECK_TYPES_BEGIN { \ | 463 CHECK_TYPES_BEGIN { \ |
464 /* Module. */ \ | 464 /* Module. */ \ |
465 CHECK_EXPR(FunctionLiteral, Bounds::Unbounded()) { | 465 CHECK_EXPR(FunctionLiteral, Bounds::Unbounded()) { |
466 #define CHECK_FUNC_TYPES_END_1() \ | 466 #define CHECK_FUNC_TYPES_END_1() \ |
467 /* "use asm"; */ \ | 467 /* "use asm"; */ \ |
468 CHECK_EXPR(Literal, Bounds(Type::String())); \ | 468 CHECK_EXPR(Literal, Bounds(Type::String(zone))); \ |
469 /* stdlib shortcuts. */ \ | 469 /* stdlib shortcuts. */ \ |
470 CheckStdlibShortcuts(zone, types, index, depth, cache); | 470 CheckStdlibShortcuts(zone, types, index, depth, cache); |
471 | 471 |
472 | 472 |
473 #define CHECK_FUNC_TYPES_END_2() \ | 473 #define CHECK_FUNC_TYPES_END_2() \ |
474 /* return { foo: foo }; */ \ | 474 /* return { foo: foo }; */ \ |
475 CHECK_EXPR(ObjectLiteral, Bounds::Unbounded()) { \ | 475 CHECK_EXPR(ObjectLiteral, Bounds::Unbounded()) { \ |
476 CHECK_VAR(foo, FUNC_V_TYPE); \ | 476 CHECK_VAR(foo, FUNC_V_TYPE); \ |
477 } \ | 477 } \ |
478 } \ | 478 } \ |
479 } \ | 479 } \ |
(...skipping 23 matching lines...) Expand all Loading... |
503 CHECK_FUNC_TYPES_END | 503 CHECK_FUNC_TYPES_END |
504 } | 504 } |
505 | 505 |
506 | 506 |
507 TEST(ReturnVoid) { | 507 TEST(ReturnVoid) { |
508 CHECK_FUNC_TYPES_BEGIN( | 508 CHECK_FUNC_TYPES_BEGIN( |
509 "function bar() { return; }\n" | 509 "function bar() { return; }\n" |
510 "function foo() { bar(); }") { | 510 "function foo() { bar(); }") { |
511 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) { | 511 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) { |
512 // return undefined; | 512 // return undefined; |
513 CHECK_EXPR(Literal, Bounds(Type::Undefined())); | 513 CHECK_EXPR(Literal, Bounds(Type::Undefined(zone))); |
514 } | 514 } |
515 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) { | 515 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) { |
516 CHECK_EXPR(Call, Bounds(Type::Undefined())) { | 516 CHECK_EXPR(Call, Bounds(Type::Undefined(zone))) { |
517 CHECK_VAR(bar, FUNC_V_TYPE); | 517 CHECK_VAR(bar, FUNC_V_TYPE); |
518 } | 518 } |
519 } | 519 } |
520 } | 520 } |
521 CHECK_FUNC_TYPES_END | 521 CHECK_FUNC_TYPES_END |
522 } | 522 } |
523 | 523 |
524 | 524 |
525 TEST(EmptyBody) { | 525 TEST(EmptyBody) { |
526 CHECK_FUNC_TYPES_BEGIN( | 526 CHECK_FUNC_TYPES_BEGIN( |
527 "function bar() { }\n" | 527 "function bar() { }\n" |
528 "function foo() { bar(); }") { | 528 "function foo() { bar(); }") { |
529 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE); | 529 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE); |
530 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) { | 530 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) { |
531 CHECK_EXPR(Call, Bounds(Type::Undefined())) { | 531 CHECK_EXPR(Call, Bounds(Type::Undefined(zone))) { |
532 CHECK_VAR(bar, FUNC_V_TYPE); | 532 CHECK_VAR(bar, FUNC_V_TYPE); |
533 } | 533 } |
534 } | 534 } |
535 } | 535 } |
536 CHECK_FUNC_TYPES_END | 536 CHECK_FUNC_TYPES_END |
537 } | 537 } |
538 | 538 |
539 | 539 |
540 TEST(DoesNothing) { | 540 TEST(DoesNothing) { |
541 CHECK_FUNC_TYPES_BEGIN( | 541 CHECK_FUNC_TYPES_BEGIN( |
542 "function bar() { var x = 1.0; }\n" | 542 "function bar() { var x = 1.0; }\n" |
543 "function foo() { bar(); }") { | 543 "function foo() { bar(); }") { |
544 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) { | 544 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) { |
545 CHECK_EXPR(Assignment, Bounds(cache.kAsmDouble)) { | 545 CHECK_EXPR(Assignment, Bounds(cache.kAsmDouble)) { |
546 CHECK_VAR(x, Bounds(cache.kAsmDouble)); | 546 CHECK_VAR(x, Bounds(cache.kAsmDouble)); |
547 CHECK_EXPR(Literal, Bounds(cache.kAsmDouble)); | 547 CHECK_EXPR(Literal, Bounds(cache.kAsmDouble)); |
548 } | 548 } |
549 } | 549 } |
550 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) { | 550 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) { |
551 CHECK_EXPR(Call, Bounds(Type::Undefined())) { | 551 CHECK_EXPR(Call, Bounds(Type::Undefined(zone))) { |
552 CHECK_VAR(bar, FUNC_V_TYPE); | 552 CHECK_VAR(bar, FUNC_V_TYPE); |
553 } | 553 } |
554 } | 554 } |
555 } | 555 } |
556 CHECK_FUNC_TYPES_END | 556 CHECK_FUNC_TYPES_END |
557 } | 557 } |
558 | 558 |
559 | 559 |
560 TEST(ReturnInt32Literal) { | 560 TEST(ReturnInt32Literal) { |
561 CHECK_FUNC_TYPES_BEGIN( | 561 CHECK_FUNC_TYPES_BEGIN( |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1005 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) { | 1005 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) { |
1006 CHECK_EXPR(Assignment, Bounds(cache.kAsmInt)) { | 1006 CHECK_EXPR(Assignment, Bounds(cache.kAsmInt)) { |
1007 CHECK_VAR(x, Bounds(cache.kAsmInt)); | 1007 CHECK_VAR(x, Bounds(cache.kAsmInt)); |
1008 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 1008 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); |
1009 } | 1009 } |
1010 CHECK_EXPR(Assignment, Bounds(cache.kAsmInt)) { | 1010 CHECK_EXPR(Assignment, Bounds(cache.kAsmInt)) { |
1011 CHECK_VAR(y, Bounds(cache.kAsmInt)); | 1011 CHECK_VAR(y, Bounds(cache.kAsmInt)); |
1012 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 1012 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); |
1013 } | 1013 } |
1014 CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) { | 1014 CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) { |
1015 CHECK_EXPR(BinaryOperation, Bounds(Type::None(), Type::Any())) { | 1015 CHECK_EXPR(BinaryOperation, Bounds(Type::None(zone), Type::Any(zone))) { |
1016 CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmUnsigned)) { | 1016 CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmUnsigned)) { |
1017 CHECK_VAR(x, Bounds(cache.kAsmInt)); | 1017 CHECK_VAR(x, Bounds(cache.kAsmInt)); |
1018 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 1018 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); |
1019 } | 1019 } |
1020 CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmUnsigned)) { | 1020 CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmUnsigned)) { |
1021 CHECK_VAR(y, Bounds(cache.kAsmInt)); | 1021 CHECK_VAR(y, Bounds(cache.kAsmInt)); |
1022 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 1022 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); |
1023 } | 1023 } |
1024 } | 1024 } |
1025 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 1025 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1664 | 1664 |
1665 | 1665 |
1666 TEST(ForeignFunction) { | 1666 TEST(ForeignFunction) { |
1667 CHECK_FUNC_TYPES_BEGIN( | 1667 CHECK_FUNC_TYPES_BEGIN( |
1668 "var baz = foreign.baz;\n" | 1668 "var baz = foreign.baz;\n" |
1669 "function bar() { return baz(1, 2)|0; }\n" | 1669 "function bar() { return baz(1, 2)|0; }\n" |
1670 "function foo() { bar(); }") { | 1670 "function foo() { bar(); }") { |
1671 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) { | 1671 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) { |
1672 CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) { | 1672 CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) { |
1673 CHECK_EXPR(Call, Bounds(Type::Number(zone))) { | 1673 CHECK_EXPR(Call, Bounds(Type::Number(zone))) { |
1674 CHECK_VAR(baz, Bounds(Type::Any())); | 1674 CHECK_VAR(baz, Bounds(Type::Any(zone))); |
1675 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 1675 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); |
1676 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 1676 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); |
1677 } | 1677 } |
1678 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 1678 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); |
1679 } | 1679 } |
1680 } | 1680 } |
1681 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) { | 1681 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) { |
1682 CHECK_EXPR(Call, Bounds(cache.kAsmSigned)) { | 1682 CHECK_EXPR(Call, Bounds(cache.kAsmSigned)) { |
1683 CHECK_VAR(bar, FUNC_I_TYPE); | 1683 CHECK_VAR(bar, FUNC_I_TYPE); |
1684 } | 1684 } |
1685 } | 1685 } |
1686 } | 1686 } |
1687 CHECK_FUNC_TYPES_END_1() | 1687 CHECK_FUNC_TYPES_END_1() |
1688 CHECK_EXPR(Assignment, Bounds(Type::Any())) { | 1688 CHECK_EXPR(Assignment, Bounds(Type::Any(zone))) { |
1689 CHECK_VAR(baz, Bounds(Type::Any())); | 1689 CHECK_VAR(baz, Bounds(Type::Any(zone))); |
1690 CHECK_EXPR(Property, Bounds(Type::Any())) { | 1690 CHECK_EXPR(Property, Bounds(Type::Any(zone))) { |
1691 CHECK_VAR(foreign, Bounds::Unbounded()); | 1691 CHECK_VAR(foreign, Bounds::Unbounded()); |
1692 CHECK_EXPR(Literal, Bounds::Unbounded()); | 1692 CHECK_EXPR(Literal, Bounds::Unbounded()); |
1693 } | 1693 } |
1694 } | 1694 } |
1695 CHECK_FUNC_TYPES_END_2() | 1695 CHECK_FUNC_TYPES_END_2() |
1696 } | 1696 } |
1697 | 1697 |
1698 | 1698 |
1699 TEST(BadExports) { | 1699 TEST(BadExports) { |
1700 HARNESS_PREAMBLE() | 1700 HARNESS_PREAMBLE() |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1818 CHECK(!cache.kAsmFloat->Is(cache.kAsmFixnum)); | 1818 CHECK(!cache.kAsmFloat->Is(cache.kAsmFixnum)); |
1819 CHECK(!cache.kAsmFloat->Is(cache.kAsmDouble)); | 1819 CHECK(!cache.kAsmFloat->Is(cache.kAsmDouble)); |
1820 | 1820 |
1821 CHECK(cache.kAsmDouble->Is(cache.kAsmDouble)); | 1821 CHECK(cache.kAsmDouble->Is(cache.kAsmDouble)); |
1822 CHECK(!cache.kAsmDouble->Is(cache.kAsmInt)); | 1822 CHECK(!cache.kAsmDouble->Is(cache.kAsmInt)); |
1823 CHECK(!cache.kAsmDouble->Is(cache.kAsmUnsigned)); | 1823 CHECK(!cache.kAsmDouble->Is(cache.kAsmUnsigned)); |
1824 CHECK(!cache.kAsmDouble->Is(cache.kAsmSigned)); | 1824 CHECK(!cache.kAsmDouble->Is(cache.kAsmSigned)); |
1825 CHECK(!cache.kAsmDouble->Is(cache.kAsmFixnum)); | 1825 CHECK(!cache.kAsmDouble->Is(cache.kAsmFixnum)); |
1826 CHECK(!cache.kAsmDouble->Is(cache.kAsmFloat)); | 1826 CHECK(!cache.kAsmDouble->Is(cache.kAsmFloat)); |
1827 } | 1827 } |
OLD | NEW |