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

Side by Side Diff: src/typing.cc

Issue 132493002: [Sheriff] Revert "Templatise type representation" and "Fix Mac warnings". (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 11 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 | « src/types.cc ('k') | test/cctest/test-types.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 if (scope->is_function_scope() && scope->function() != NULL) { 64 if (scope->is_function_scope() && scope->function() != NULL) {
65 RECURSE(visitor->VisitVariableDeclaration(scope->function())); 65 RECURSE(visitor->VisitVariableDeclaration(scope->function()));
66 } 66 }
67 RECURSE(visitor->VisitDeclarations(scope->declarations())); 67 RECURSE(visitor->VisitDeclarations(scope->declarations()));
68 RECURSE(visitor->VisitStatements(info->function()->body())); 68 RECURSE(visitor->VisitStatements(info->function()->body()));
69 } 69 }
70 70
71 #undef RECURSE 71 #undef RECURSE
72 72
73 73
74 Effect AstTyper::ObservedOnStack(Object* value) {
75 Type* lower = Type::OfCurrently(Handle<Object>(value, isolate()));
76 return Effect(Bounds(lower, Type::Any(), isolate()));
77 }
78
79
74 #ifdef OBJECT_PRINT 80 #ifdef OBJECT_PRINT
75 static void PrintObserved(Variable* var, Object* value, Handle<Type> type) { 81 static void PrintObserved(Variable* var, Object* value, Handle<Type> type) {
76 PrintF(" observed %s ", var->IsParameter() ? "param" : "local"); 82 PrintF(" observed %s ", var->IsParameter() ? "param" : "local");
77 var->name()->Print(); 83 var->name()->Print();
78 PrintF(" : "); 84 PrintF(" : ");
79 value->ShortPrint(); 85 value->ShortPrint();
80 PrintF(" -> "); 86 PrintF(" -> ");
81 type->TypePrint(); 87 type->TypePrint();
82 } 88 }
83 #endif // OBJECT_PRINT 89 #endif // OBJECT_PRINT
84 90
85 91
86 Effect AstTyper::ObservedOnStack(Object* value) {
87 Handle<Type> lower = Type::OfCurrently(handle(value, isolate()), isolate());
88 return Effect(Bounds(lower, Type::Any(isolate())));
89 }
90
91
92 void AstTyper::ObserveTypesAtOsrEntry(IterationStatement* stmt) { 92 void AstTyper::ObserveTypesAtOsrEntry(IterationStatement* stmt) {
93 if (stmt->OsrEntryId() != info_->osr_ast_id()) return; 93 if (stmt->OsrEntryId() != info_->osr_ast_id()) return;
94 94
95 DisallowHeapAllocation no_gc; 95 DisallowHeapAllocation no_gc;
96 JavaScriptFrameIterator it(isolate()); 96 JavaScriptFrameIterator it(isolate());
97 JavaScriptFrame* frame = it.frame(); 97 JavaScriptFrame* frame = it.frame();
98 Scope* scope = info_->scope(); 98 Scope* scope = info_->scope();
99 99
100 // Assert that the frame on the stack belongs to the function we want to OSR. 100 // Assert that the frame on the stack belongs to the function we want to OSR.
101 ASSERT_EQ(*info_->closure(), frame->function()); 101 ASSERT_EQ(*info_->closure(), frame->function());
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 398
399 void AstTyper::VisitVariableProxy(VariableProxy* expr) { 399 void AstTyper::VisitVariableProxy(VariableProxy* expr) {
400 Variable* var = expr->var(); 400 Variable* var = expr->var();
401 if (var->IsStackAllocated()) { 401 if (var->IsStackAllocated()) {
402 NarrowType(expr, store_.LookupBounds(variable_index(var))); 402 NarrowType(expr, store_.LookupBounds(variable_index(var)));
403 } 403 }
404 } 404 }
405 405
406 406
407 void AstTyper::VisitLiteral(Literal* expr) { 407 void AstTyper::VisitLiteral(Literal* expr) {
408 Handle<Type> type = Type::Constant(expr->value(), isolate_); 408 Type* type = Type::Constant(expr->value(), isolate_);
409 NarrowType(expr, Bounds(type)); 409 NarrowType(expr, Bounds(type, isolate_));
410 } 410 }
411 411
412 412
413 void AstTyper::VisitRegExpLiteral(RegExpLiteral* expr) { 413 void AstTyper::VisitRegExpLiteral(RegExpLiteral* expr) {
414 NarrowType(expr, Bounds(Type::RegExp(isolate_))); 414 NarrowType(expr, Bounds(Type::RegExp(), isolate_));
415 } 415 }
416 416
417 417
418 void AstTyper::VisitObjectLiteral(ObjectLiteral* expr) { 418 void AstTyper::VisitObjectLiteral(ObjectLiteral* expr) {
419 ZoneList<ObjectLiteral::Property*>* properties = expr->properties(); 419 ZoneList<ObjectLiteral::Property*>* properties = expr->properties();
420 for (int i = 0; i < properties->length(); ++i) { 420 for (int i = 0; i < properties->length(); ++i) {
421 ObjectLiteral::Property* prop = properties->at(i); 421 ObjectLiteral::Property* prop = properties->at(i);
422 422
423 // Collect type feedback. 423 // Collect type feedback.
424 if ((prop->kind() == ObjectLiteral::Property::MATERIALIZED_LITERAL && 424 if ((prop->kind() == ObjectLiteral::Property::MATERIALIZED_LITERAL &&
425 !CompileTimeValue::IsCompileTimeValue(prop->value())) || 425 !CompileTimeValue::IsCompileTimeValue(prop->value())) ||
426 prop->kind() == ObjectLiteral::Property::COMPUTED) { 426 prop->kind() == ObjectLiteral::Property::COMPUTED) {
427 if (prop->key()->value()->IsInternalizedString() && prop->emit_store()) { 427 if (prop->key()->value()->IsInternalizedString() && prop->emit_store()) {
428 prop->RecordTypeFeedback(oracle()); 428 prop->RecordTypeFeedback(oracle());
429 } 429 }
430 } 430 }
431 431
432 RECURSE(Visit(prop->value())); 432 RECURSE(Visit(prop->value()));
433 } 433 }
434 434
435 NarrowType(expr, Bounds(Type::Object(isolate_))); 435 NarrowType(expr, Bounds(Type::Object(), isolate_));
436 } 436 }
437 437
438 438
439 void AstTyper::VisitArrayLiteral(ArrayLiteral* expr) { 439 void AstTyper::VisitArrayLiteral(ArrayLiteral* expr) {
440 ZoneList<Expression*>* values = expr->values(); 440 ZoneList<Expression*>* values = expr->values();
441 for (int i = 0; i < values->length(); ++i) { 441 for (int i = 0; i < values->length(); ++i) {
442 Expression* value = values->at(i); 442 Expression* value = values->at(i);
443 RECURSE(Visit(value)); 443 RECURSE(Visit(value));
444 } 444 }
445 445
446 NarrowType(expr, Bounds(Type::Array(isolate_))); 446 NarrowType(expr, Bounds(Type::Array(), isolate_));
447 } 447 }
448 448
449 449
450 void AstTyper::VisitAssignment(Assignment* expr) { 450 void AstTyper::VisitAssignment(Assignment* expr) {
451 // Collect type feedback. 451 // Collect type feedback.
452 Property* prop = expr->target()->AsProperty(); 452 Property* prop = expr->target()->AsProperty();
453 if (prop != NULL) { 453 if (prop != NULL) {
454 TypeFeedbackId id = expr->AssignmentFeedbackId(); 454 TypeFeedbackId id = expr->AssignmentFeedbackId();
455 expr->set_is_uninitialized(oracle()->StoreIsUninitialized(id)); 455 expr->set_is_uninitialized(oracle()->StoreIsUninitialized(id));
456 if (!expr->IsUninitialized()) { 456 if (!expr->IsUninitialized()) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 RECURSE(Visit(expr->expression())); 488 RECURSE(Visit(expr->expression()));
489 489
490 // We don't know anything about the result type. 490 // We don't know anything about the result type.
491 } 491 }
492 492
493 493
494 void AstTyper::VisitThrow(Throw* expr) { 494 void AstTyper::VisitThrow(Throw* expr) {
495 RECURSE(Visit(expr->exception())); 495 RECURSE(Visit(expr->exception()));
496 // TODO(rossberg): is it worth having a non-termination effect? 496 // TODO(rossberg): is it worth having a non-termination effect?
497 497
498 NarrowType(expr, Bounds(Type::None(isolate_))); 498 NarrowType(expr, Bounds(Type::None(), isolate_));
499 } 499 }
500 500
501 501
502 void AstTyper::VisitProperty(Property* expr) { 502 void AstTyper::VisitProperty(Property* expr) {
503 // Collect type feedback. 503 // Collect type feedback.
504 TypeFeedbackId id = expr->PropertyFeedbackId(); 504 TypeFeedbackId id = expr->PropertyFeedbackId();
505 expr->set_is_uninitialized(oracle()->LoadIsUninitialized(id)); 505 expr->set_is_uninitialized(oracle()->LoadIsUninitialized(id));
506 if (!expr->IsUninitialized()) { 506 if (!expr->IsUninitialized()) {
507 expr->set_is_pre_monomorphic(oracle()->LoadIsPreMonomorphic(id)); 507 expr->set_is_pre_monomorphic(oracle()->LoadIsPreMonomorphic(id));
508 if (expr->key()->IsPropertyName()) { 508 if (expr->key()->IsPropertyName()) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 if (expr->op() == Token::NOT) { 586 if (expr->op() == Token::NOT) {
587 // TODO(rossberg): only do in test or value context. 587 // TODO(rossberg): only do in test or value context.
588 expr->expression()->RecordToBooleanTypeFeedback(oracle()); 588 expr->expression()->RecordToBooleanTypeFeedback(oracle());
589 } 589 }
590 590
591 RECURSE(Visit(expr->expression())); 591 RECURSE(Visit(expr->expression()));
592 592
593 switch (expr->op()) { 593 switch (expr->op()) {
594 case Token::NOT: 594 case Token::NOT:
595 case Token::DELETE: 595 case Token::DELETE:
596 NarrowType(expr, Bounds(Type::Boolean(isolate_))); 596 NarrowType(expr, Bounds(Type::Boolean(), isolate_));
597 break; 597 break;
598 case Token::VOID: 598 case Token::VOID:
599 NarrowType(expr, Bounds(Type::Undefined(isolate_))); 599 NarrowType(expr, Bounds(Type::Undefined(), isolate_));
600 break; 600 break;
601 case Token::TYPEOF: 601 case Token::TYPEOF:
602 NarrowType(expr, Bounds(Type::InternalizedString(isolate_))); 602 NarrowType(expr, Bounds(Type::InternalizedString(), isolate_));
603 break; 603 break;
604 default: 604 default:
605 UNREACHABLE(); 605 UNREACHABLE();
606 } 606 }
607 } 607 }
608 608
609 609
610 void AstTyper::VisitCountOperation(CountOperation* expr) { 610 void AstTyper::VisitCountOperation(CountOperation* expr) {
611 // Collect type feedback. 611 // Collect type feedback.
612 TypeFeedbackId store_id = expr->CountStoreFeedbackId(); 612 TypeFeedbackId store_id = expr->CountStoreFeedbackId();
613 expr->set_store_mode(oracle()->GetStoreMode(store_id)); 613 expr->set_store_mode(oracle()->GetStoreMode(store_id));
614 oracle()->CountReceiverTypes(store_id, expr->GetReceiverTypes()); 614 oracle()->CountReceiverTypes(store_id, expr->GetReceiverTypes());
615 expr->set_type(oracle()->CountType(expr->CountBinOpFeedbackId())); 615 expr->set_type(oracle()->CountType(expr->CountBinOpFeedbackId()));
616 // TODO(rossberg): merge the count type with the generic expression type. 616 // TODO(rossberg): merge the count type with the generic expression type.
617 617
618 RECURSE(Visit(expr->expression())); 618 RECURSE(Visit(expr->expression()));
619 619
620 NarrowType(expr, Bounds(Type::Smi(isolate_), Type::Number(isolate_))); 620 NarrowType(expr, Bounds(Type::Smi(), Type::Number(), isolate_));
621 621
622 VariableProxy* proxy = expr->expression()->AsVariableProxy(); 622 VariableProxy* proxy = expr->expression()->AsVariableProxy();
623 if (proxy != NULL && proxy->var()->IsStackAllocated()) { 623 if (proxy != NULL && proxy->var()->IsStackAllocated()) {
624 store_.Seq(variable_index(proxy->var()), Effect(expr->bounds())); 624 store_.Seq(variable_index(proxy->var()), Effect(expr->bounds()));
625 } 625 }
626 } 626 }
627 627
628 628
629 void AstTyper::VisitBinaryOperation(BinaryOperation* expr) { 629 void AstTyper::VisitBinaryOperation(BinaryOperation* expr) {
630 // Collect type feedback. 630 // Collect type feedback.
(...skipping 30 matching lines...) Expand all
661 store_.Seq(left_effects); 661 store_.Seq(left_effects);
662 662
663 NarrowType(expr, Bounds::Either( 663 NarrowType(expr, Bounds::Either(
664 expr->left()->bounds(), expr->right()->bounds(), isolate_)); 664 expr->left()->bounds(), expr->right()->bounds(), isolate_));
665 break; 665 break;
666 } 666 }
667 case Token::BIT_OR: 667 case Token::BIT_OR:
668 case Token::BIT_AND: { 668 case Token::BIT_AND: {
669 RECURSE(Visit(expr->left())); 669 RECURSE(Visit(expr->left()));
670 RECURSE(Visit(expr->right())); 670 RECURSE(Visit(expr->right()));
671 Handle<Type> upper = Type::Union( 671 Handle<Type> upper(
672 expr->left()->bounds().upper, expr->right()->bounds().upper, 672 Type::Union(
673 expr->left()->bounds().upper, expr->right()->bounds().upper),
673 isolate_); 674 isolate_);
674 if (!upper->Is(Type::Signed32())) 675 if (!upper->Is(Type::Signed32()))
675 upper = Type::Signed32(isolate_); 676 upper = handle(Type::Signed32(), isolate_);
676 Handle<Type> lower = 677 Handle<Type> lower(Type::Intersect(
677 Type::Intersect(Type::Smi(isolate_), upper, isolate_); 678 handle(Type::Smi(), isolate_), upper), isolate_);
678 NarrowType(expr, Bounds(lower, upper)); 679 NarrowType(expr, Bounds(lower, upper));
679 break; 680 break;
680 } 681 }
681 case Token::BIT_XOR: 682 case Token::BIT_XOR:
682 case Token::SHL: 683 case Token::SHL:
683 case Token::SAR: 684 case Token::SAR:
684 RECURSE(Visit(expr->left())); 685 RECURSE(Visit(expr->left()));
685 RECURSE(Visit(expr->right())); 686 RECURSE(Visit(expr->right()));
686 NarrowType(expr, Bounds(Type::Smi(isolate_), Type::Signed32(isolate_))); 687 NarrowType(expr, Bounds(Type::Smi(), Type::Signed32(), isolate_));
687 break; 688 break;
688 case Token::SHR: 689 case Token::SHR:
689 RECURSE(Visit(expr->left())); 690 RECURSE(Visit(expr->left()));
690 RECURSE(Visit(expr->right())); 691 RECURSE(Visit(expr->right()));
691 // TODO(rossberg): The upper bound would be Unsigned32, but since there 692 // TODO(rossberg): The upper bound would be Unsigned32, but since there
692 // is no 'positive Smi' type for the lower bound, we use the smallest 693 // is no 'positive Smi' type for the lower bound, we use the smallest
693 // union of Smi and Unsigned32 as upper bound instead. 694 // union of Smi and Unsigned32 as upper bound instead.
694 NarrowType(expr, Bounds(Type::Smi(isolate_), Type::Number(isolate_))); 695 NarrowType(expr, Bounds(Type::Smi(), Type::Number(), isolate_));
695 break; 696 break;
696 case Token::ADD: { 697 case Token::ADD: {
697 RECURSE(Visit(expr->left())); 698 RECURSE(Visit(expr->left()));
698 RECURSE(Visit(expr->right())); 699 RECURSE(Visit(expr->right()));
699 Bounds l = expr->left()->bounds(); 700 Bounds l = expr->left()->bounds();
700 Bounds r = expr->right()->bounds(); 701 Bounds r = expr->right()->bounds();
701 Handle<Type> lower = 702 Type* lower =
702 l.lower->Is(Type::None()) || r.lower->Is(Type::None()) ? 703 l.lower->Is(Type::None()) || r.lower->Is(Type::None()) ?
703 Type::None(isolate_) : 704 Type::None() :
704 l.lower->Is(Type::String()) || r.lower->Is(Type::String()) ? 705 l.lower->Is(Type::String()) || r.lower->Is(Type::String()) ?
705 Type::String(isolate_) : 706 Type::String() :
706 l.lower->Is(Type::Number()) && r.lower->Is(Type::Number()) ? 707 l.lower->Is(Type::Number()) && r.lower->Is(Type::Number()) ?
707 Type::Smi(isolate_) : Type::None(isolate_); 708 Type::Smi() : Type::None();
708 Handle<Type> upper = 709 Type* upper =
709 l.upper->Is(Type::String()) || r.upper->Is(Type::String()) ? 710 l.upper->Is(Type::String()) || r.upper->Is(Type::String()) ?
710 Type::String(isolate_) : 711 Type::String() :
711 l.upper->Is(Type::Number()) && r.upper->Is(Type::Number()) ? 712 l.upper->Is(Type::Number()) && r.upper->Is(Type::Number()) ?
712 Type::Number(isolate_) : Type::NumberOrString(isolate_); 713 Type::Number() : Type::NumberOrString();
713 NarrowType(expr, Bounds(lower, upper)); 714 NarrowType(expr, Bounds(lower, upper, isolate_));
714 break; 715 break;
715 } 716 }
716 case Token::SUB: 717 case Token::SUB:
717 case Token::MUL: 718 case Token::MUL:
718 case Token::DIV: 719 case Token::DIV:
719 case Token::MOD: 720 case Token::MOD:
720 RECURSE(Visit(expr->left())); 721 RECURSE(Visit(expr->left()));
721 RECURSE(Visit(expr->right())); 722 RECURSE(Visit(expr->right()));
722 NarrowType(expr, Bounds(Type::Smi(isolate_), Type::Number(isolate_))); 723 NarrowType(expr, Bounds(Type::Smi(), Type::Number(), isolate_));
723 break; 724 break;
724 default: 725 default:
725 UNREACHABLE(); 726 UNREACHABLE();
726 } 727 }
727 } 728 }
728 729
729 730
730 void AstTyper::VisitCompareOperation(CompareOperation* expr) { 731 void AstTyper::VisitCompareOperation(CompareOperation* expr) {
731 // Collect type feedback. 732 // Collect type feedback.
732 Handle<Type> left_type, right_type, combined_type; 733 Handle<Type> left_type, right_type, combined_type;
733 oracle()->CompareType(expr->CompareOperationFeedbackId(), 734 oracle()->CompareType(expr->CompareOperationFeedbackId(),
734 &left_type, &right_type, &combined_type); 735 &left_type, &right_type, &combined_type);
735 NarrowLowerType(expr->left(), left_type); 736 NarrowLowerType(expr->left(), left_type);
736 NarrowLowerType(expr->right(), right_type); 737 NarrowLowerType(expr->right(), right_type);
737 expr->set_combined_type(combined_type); 738 expr->set_combined_type(combined_type);
738 739
739 RECURSE(Visit(expr->left())); 740 RECURSE(Visit(expr->left()));
740 RECURSE(Visit(expr->right())); 741 RECURSE(Visit(expr->right()));
741 742
742 NarrowType(expr, Bounds(Type::Boolean(isolate_))); 743 NarrowType(expr, Bounds(Type::Boolean(), isolate_));
743 } 744 }
744 745
745 746
746 void AstTyper::VisitThisFunction(ThisFunction* expr) { 747 void AstTyper::VisitThisFunction(ThisFunction* expr) {
747 } 748 }
748 749
749 750
750 void AstTyper::VisitDeclarations(ZoneList<Declaration*>* decls) { 751 void AstTyper::VisitDeclarations(ZoneList<Declaration*>* decls) {
751 for (int i = 0; i < decls->length(); ++i) { 752 for (int i = 0; i < decls->length(); ++i) {
752 Declaration* decl = decls->at(i); 753 Declaration* decl = decls->at(i);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 void AstTyper::VisitModuleUrl(ModuleUrl* module) { 796 void AstTyper::VisitModuleUrl(ModuleUrl* module) {
796 } 797 }
797 798
798 799
799 void AstTyper::VisitModuleStatement(ModuleStatement* stmt) { 800 void AstTyper::VisitModuleStatement(ModuleStatement* stmt) {
800 RECURSE(Visit(stmt->body())); 801 RECURSE(Visit(stmt->body()));
801 } 802 }
802 803
803 804
804 } } // namespace v8::internal 805 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/types.cc ('k') | test/cctest/test-types.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698